[compiler-rt] [scudo] Add two missing locks to enable/disable. (PR #79670)

Evgenii Stepanov via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 29 10:04:48 PST 2024


================
@@ -136,6 +136,14 @@ class StackDepot {
   u64 operator[](uptr RingPos) const {
     return atomic_load_relaxed(&Ring[RingPos & RingMask]);
   }
+
+  void disable() NO_THREAD_SAFETY_ANALYSIS {
+    RingEndMu.lock();
+  }
+
+  void enable() NO_THREAD_SAFETY_ANALYSIS {
+    RingEndMu.unlock();
+  }
----------------
eugenis wrote:

Right, StackDepot is not actually being disabled here. The idea is grab all allocator locks in a pthread_atfork before the fork, and release them after. This allows malloc to be used in a fork child of a multithreaded process, which is expressly forbidden by the standard, but very widely used. For example, Android's `init` uses `std::string` after fork when spawning services, for example in `android::init::EnterNamespaces`.

Any lock that is necessary to serve an allocator call must be handled this way. Otherwise there is a possibility that the lock is held during the call to fork, which results in it being held forever in the child process, and the next operation that needs it deadlocks.


https://github.com/llvm/llvm-project/pull/79670


More information about the llvm-commits mailing list