summaryrefslogtreecommitdiff
path: root/bolt/runtime
diff options
context:
space:
mode:
authorVladislav Khmelevsky <Vladislav.Khmelevskyi@huawei.com>2021-06-04 19:51:06 +0300
committerMaksim Panchenko <maks@fb.com>2021-06-04 19:51:06 +0300
commit2cf9008a60a7d29e643fe13fa3c9e45171c76170 (patch)
tree2585924d10efcb22032ab162b03ca09bda88b74d /bolt/runtime
parent1efadeedf26ac2b6dff511a1379e478483bdd9c5 (diff)
downloadllvm-2cf9008a60a7d29e643fe13fa3c9e45171c76170.tar.gz
[PR] Instrumentation: Disable signals on mutex lock
Summary: When indirect call is instrmented it locks SimpleHashTable's mutex on get() call. If while locked we we receive a signal and signal handler also will call indirect function we will end up with deadlock. PR facebookincubator/BOLT#167 Vladislav Khmelevsky, Advanced Software Technology Lab, Huawei (cherry picked from FBD28909921)
Diffstat (limited to 'bolt/runtime')
-rw-r--r--bolt/runtime/common.h30
1 files changed, 29 insertions, 1 deletions
diff --git a/bolt/runtime/common.h b/bolt/runtime/common.h
index 0d6b8de23d5e..90d1c5d3a8fa 100644
--- a/bolt/runtime/common.h
+++ b/bolt/runtime/common.h
@@ -151,6 +151,28 @@ uint64_t __munmap(void *addr, uint64_t size) {
return ret;
}
+#define SIG_BLOCK 0
+#define SIG_UNBLOCK 1
+#define SIG_SETMASK 2
+
+static const uint64_t MaskAllSignals[] = {-1ULL};
+
+uint64_t __sigprocmask(int how, const void *set, void *oldset) {
+#if defined(__APPLE__)
+#define SIGPROCMASK_SYSCALL 0x2000030
+#else
+#define SIGPROCMASK_SYSCALL 14
+#endif
+ uint64_t ret;
+ register long r10 asm("r10") = sizeof(uint64_t);
+ __asm__ __volatile__("movq $" STRINGIFY(SIGPROCMASK_SYSCALL) ", %%rax\n"
+ "syscall\n"
+ : "=a"(ret)
+ : "D"(how), "S"(set), "d"(oldset), "r"(r10)
+ : "cc", "rcx", "r11", "memory");
+ return ret;
+}
+
uint64_t __exit(uint64_t code) {
#if defined(__APPLE__)
#define EXIT_SYSCALL 0x2000001
@@ -409,13 +431,19 @@ public:
/// RAII wrapper for Mutex
class Lock {
Mutex &M;
+ uint64_t SignalMask[1] = {};
public:
Lock(Mutex &M) : M(M) {
+ __sigprocmask(SIG_BLOCK, MaskAllSignals, SignalMask);
while (!M.acquire()) {
}
}
- ~Lock() { M.release(); }
+
+ ~Lock() {
+ M.release();
+ __sigprocmask(SIG_SETMASK, SignalMask, nullptr);
+ }
};
inline uint64_t alignTo(uint64_t Value, uint64_t Align) {