[PATCH] D72470: [scudo][standalone] Fork support

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 11:48:21 PST 2020


cryptoad created this revision.
Herald added subscribers: llvm-commits, Sanitizers, jfb.
Herald added projects: Sanitizers, LLVM.

fork() wasn't well (or at all) supported in Scudo. This materialized
in deadlocks in children.

In order to properly support fork, we will lock the allocator pre-fork
and unlock it post-fork in parent and child. This is done via a
`pthread_atfork` call installing the necessary handlers.

A couple of things suck here: this function allocates - so this has to
be done post initialization as our init path is not reentrance, and it
doesn't allow for an extra pointer - so we can't pass the allocator we
are currently working with.

In order to work around this, I added a post-init template parameter
that gets executed once the allocator is initialized for the current
thread. Its job for the C wrappers is to install the atfork handlers.

I reorganized a bit the impacted area and added some tests, courtesy
of cferris@ that were deadlocking prior to this fix.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72470

Files:
  compiler-rt/lib/scudo/standalone/combined.h
  compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp
  compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
  compiler-rt/lib/scudo/standalone/tests/wrappers_cpp_test.cpp
  compiler-rt/lib/scudo/standalone/tsd_exclusive.h
  compiler-rt/lib/scudo/standalone/tsd_shared.h
  compiler-rt/lib/scudo/standalone/wrappers_c.cpp
  compiler-rt/lib/scudo/standalone/wrappers_c.inc
  compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp
  compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72470.237141.patch
Type: text/x-patch
Size: 11644 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200109/03c85bce/attachment-0001.bin>


More information about the llvm-commits mailing list