Revised as per the feedback to D22549: this abstracts cache/disable_counter/current_thread_tid (stored in TLS_SLOT_TSAN on Android, THREADLOCAL variables otherwise) into GetCurrentThread().
Details
Diff Detail
Event Timeline
lsan_allocator.cc | ||
---|---|---|
31 ↗ | (On Diff #64913) | Get rid of this; always go though LsanThread. See how ASan does it (AsanThread, AsanThreadLocalMallocStorage). |
49 ↗ | (On Diff #64913) | remove the printf, or make it a vprintf |
55 ↗ | (On Diff #64913) | why?? |
lsan_allocator.h | ||
27 ↗ | (On Diff #64913) | Move this to sanitizer_common.h, smth like void **AndroidGetTls() { return &__get_tls()[TLS_SLOT_TSAN];} |
36 ↗ | (On Diff #64913) | function, not a macro |
73 ↗ | (On Diff #64913) | Call this LsanThread, use it on all platforms. |
lsan_common.cc | ||
38 ↗ | (On Diff #64913) | get rid of this; always go through LsanThread |
54 ↗ | (On Diff #64913) | replace with getCurrentThread()->disable_counter |
lsan_thread.cc | ||
29 ↗ | (On Diff #64913) | LsanThread |
There's now an LsanThread struct containing all the thread-local variables. A pointer to the struct is returned from lsan_thread.cc::getCurrentTLS(), which is the single point where we distinguish between Android (use AndroidGetTls()) and non-Android (use THREADLOCAL).
lsan/lsan_allocator.h | ||
---|---|---|
20 ↗ | (On Diff #65178) | looks unnecessary |
lsan/lsan_common.h | ||
130 | unnecessary | |
132 | Please move this to lsan_thread.h | |
135 | just "tid" | |
lsan/lsan_flags.inc | ||
34 ↗ | (On Diff #65178) | this could be written as LSAN_FLAG(bool, use_tls, !SANITIZER_ANDROID, but on the second thought, don't we need to handle pthread_setspecific storage on android? did you test that it works? I think this flag still makes sense for android, and instead of defaulting to false we should modify the code to do the right thing for the platform, i.e. scan TSD and not DTLS. |
lsan/lsan_thread.cc | ||
15 | no system headers here | |
43 | merge this into #if SANITIZER_ANDROID .. #else below (line 70). | |
49 | rename this to GetCurrentThread for consistency with asan; | |
sanitizer_common/sanitizer_common.cc | ||
494 ↗ | (On Diff #65178) | move this to the header so it can be inlined |
sanitizer_common/sanitizer_common.h | ||
845 | this will break asan on arm |
This addresses all the previous comments
(use_tls is not overridden for Android, GetTls() updated instead to return the bionic TLS slots;
GetCurrentThread() changed to GetCurrentThread()->id, getCurrentTLS() changed to GetCurrentThread();
SIG_SETMASK copied from signal.h;
removed some unnecessary code and moved some code around)
lsan/lsan_allocator.cc | ||
---|---|---|
37 | () unnecessary | |
lsan/lsan_common.cc | ||
248 | Is the special case for android needed because allocator cache is not inside tls limits? | |
lsan/lsan_thread.cc | ||
26 | this should be moved to sanitizer_platform_limits_posix, see __sanitizer::sig_dfl | |
sanitizer_common/sanitizer_common.h | ||
848 | Are you sure this does not break asan on arm still? |
sanitizer_common/sanitizer_linux_libcdep.cc | ||
---|---|---|
373 ↗ | (On Diff #65610) | this is super scary btw, but I don't see a better way. |
Addresses previous comments
N.B. Some changes in sanitizer_common overlap with changes proposed for msan
sanitizer_common/sanitizer_common.h | ||
---|---|---|
848 | By next revision, do you mean something that's not yet uploaded? |
sanitizer_common/sanitizer_common.h | ||
---|---|---|
848 | My comment is wrong. I ended up taking an alternative approach: if __get_tls is not defined, then define AndroidGetTls to return nullptr (line 850). This lets sanitizer_common compile on 32-bit with SANITIZER_ANDROID, even though AndroidGetTls won't actually be used (since it is only called by lsan or msan, which won't run on 32-bit). |
Add back the sanitizer_common/sanitizer_linux_libcdep.cc TLS changes from diff 3 - I accidentally omitted them.
All other files are the same as per diff 4.
sanitizer_common/sanitizer_common.h | ||
---|---|---|
848 | Oops - in revision 3 I'd been missing sanitizer_common/sanitizer_linux_libcdep.cc TLS changes so this compiled, but having added them back, since GetTls in that file directly uses get_tls (not AndroidGetTls), I still need to define get_tls. |
On 32-bit Android, GetTls() won't use __get_tls() (which is undefined)
Defines sig_setmask
() unnecessary