This allows for other implementations to define their own version of Thread::Init. This will be the case for Fuchsia where much of the thread initialization can be broken up between different thread hooks (__sanitizer_before_thread_create_hook, __sanitizer_thread_create_hook, __sanitizer_thread_start_hook). Namely, setting up the heap ring buffer and stack info and can be setup before thread creation. The stack ring buffer can also be setup before thread creation, but storing it into __hwasan_tls can only be done on the thread start hook since it's only then we can access __hwasan_tls for that thread correctly.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
compiler-rt/lib/hwasan/hwasan_linux.cpp | ||
---|---|---|
430 | Most of this code can actually be reused for Fuchsia (just not necessarily in Thread::Init). |
compiler-rt/lib/hwasan/hwasan_linux.cpp | ||
---|---|---|
430 | So maybe something like the current patch? Then on Fuchsia we could (1) have a custom implementation of InitStackAndTls, (2) wrap the call to Thread::InitStackRingBuffer in Thread::Init with a #if SANITIZER_FUCHSIA so it's not called before thread creation, then (2) call Thread::InitStackRingBuffer in the __sanitizer_thread_start_hook hook. |
compiler-rt/lib/hwasan/hwasan_linux.cpp | ||
---|---|---|
430 | Sorry. Meant wrapping with a #if !SANITIZER_FUCHSIA. |
compiler-rt/lib/hwasan/hwasan_linux.cpp | ||
---|---|---|
430 |
That's not entirely accurate. AsanThread::SetThreadStackAndTls might be a model here. But asan on Fuchsia also splits up the initialization into pre-creation and on-created-thread portions (AsanThread::Init is called before thread creation, and AsanThreadRegistry::StartThread is called on the created thread). |
Most of this code can actually be reused for Fuchsia (just not necessarily in Thread::Init).
It's probably better to split it up for reuse rather than just moving the whole thing to linux-specific.