[lsan][Darwin] Scan libdispatch and Foundation memory regions
authorLeonard Grey <lgrey@chromium.org>
Wed, 7 Sep 2022 17:21:09 +0000 (13:21 -0400)
committerLeonard Grey <lgrey@chromium.org>
Wed, 14 Sep 2022 20:46:40 +0000 (16:46 -0400)
commited2c3f46f5a74de9965c424a3a8ca99546b2c939
treeec466072a6fcb44bc222ce5e5aca338e7836cc1e
parentc69b26911168cdcf49c7c7162d7b44ce4ed40c37
[lsan][Darwin] Scan libdispatch and Foundation memory regions

libdispatch uses its own heap (_dispatch_main_heap) for some allocations, including the dispatch_continuation_t that holds a dispatch source's event handler.
Objective-C block trampolines (creating methods at runtime with a block as the implementations) use the VM_MEMORY_FOUNDATION region (see https://github.com/apple-oss-distributions/objc4/blob/8701d5672d3fd3cd817aeb84db1077aafe1a1604/runtime/objc-block-trampolines.mm#L371).

This change scans both regions to fix false positives. See tests for details; unfortunately I was unable to reduce the trampoline example with imp_implementationWithBlock on a new class, so I'm resorting to something close to the bug as seen in the wild.

Differential Revision: https://reviews.llvm.org/D129385
compiler-rt/lib/lsan/lsan_common_mac.cpp
compiler-rt/test/lsan/TestCases/Darwin/dispatch_continuations.mm [new file with mode: 0644]
compiler-rt/test/lsan/TestCases/Darwin/trampoline.mm [new file with mode: 0644]