diff options
author | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-09-04 10:36:14 +0000 |
---|---|---|
committer | Evgeniy Stepanov <eugeni.stepanov@gmail.com> | 2014-09-04 10:36:14 +0000 |
commit | a8f5a36445cb4e264c4d650c2e40e638b1270e9a (patch) | |
tree | afbb90907969aace870eca9bf19f58962cbda4c1 /lib/sanitizer_common/sanitizer_stackdepotbase.h | |
parent | 3482b7ad38e8fcd0262d109c6e8c130696837972 (diff) | |
download | compiler-rt-a8f5a36445cb4e264c4d650c2e40e638b1270e9a.tar.gz |
[msan] Make origin tracking fork-safe.
Chained origins make plain memory stores async-signal-unsafe.
We already disable it inside signal handlers.
This change grabs all origin-related locks before fork() and releases
them after fork() to avoid a deadlock in the child process.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@217140 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_stackdepotbase.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_stackdepotbase.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_stackdepotbase.h b/lib/sanitizer_common/sanitizer_stackdepotbase.h index b4fa87509..d2d3d3498 100644 --- a/lib/sanitizer_common/sanitizer_stackdepotbase.h +++ b/lib/sanitizer_common/sanitizer_stackdepotbase.h @@ -32,6 +32,9 @@ class StackDepotBase { StackDepotStats *GetStats() { return &stats; } + void LockAll(); + void UnlockAll(); + private: static Node *find(Node *s, args_type args, u32 hash); static Node *lock(atomic_uintptr_t *p); @@ -153,5 +156,21 @@ StackDepotBase<Node, kReservedBits, kTabSizeLog>::Get(u32 id) { return args_type(); } +template <class Node, int kReservedBits, int kTabSizeLog> +void StackDepotBase<Node, kReservedBits, kTabSizeLog>::LockAll() { + for (int i = 0; i < kTabSize; ++i) { + lock(&tab[i]); + } +} + +template <class Node, int kReservedBits, int kTabSizeLog> +void StackDepotBase<Node, kReservedBits, kTabSizeLog>::UnlockAll() { + for (int i = 0; i < kTabSize; ++i) { + atomic_uintptr_t *p = &tab[i]; + uptr s = atomic_load(p, memory_order_relaxed); + unlock(p, (Node *)(s & ~1UL)); + } +} + } // namespace __sanitizer #endif // SANITIZER_STACKDEPOTBASE_H |