This patch splits up hwasan thread creation between __sanitizer_before_thread_create_hook, __sanitizer_thread_create_hook, and __sanitizer_thread_start_hook. The linux implementation creates the hwasan thread object inside the new thread. On Fuchsia, we know the stack bounds before thread creation, so we can initialize part of the thread object in __sanitizer_before_thread_create_hook, then initialize the stack ring buffer in __sanitizer_thread_start_hook once we enter the thread.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
The non-fuchsia stuff can be split up in a separate patch when ready, but I'll keep it here for now until we're set on the thread handling.
Usually we like to split changes up into separate small changes for the pure refactoring, and then changes that purely add new Fuchsia-specific code.
I'll do an initial review round of the Fuchsia code here since you've sent it. But then I think this review should be tightened to just the pure refactoring, and we should have a separate review thread for the Fuchsia parts.
compiler-rt/lib/hwasan/hwasan_fuchsia.cpp | ||
---|---|---|
26 | Specifically call out here that the compiler generates direct TLS references to this and that's why it has a public C ABI name. For Fuchsia the hwasan will always be in a DSO that is a dependency of libc.so and so always loaded at startup. Hence we can use [[gnu::tls_model("initial-exec")]] here. | |
32–33 | department of redundancy department | |
34 | Nit: I'd call it something more like InitState. | |
41 | What depends on this alignment? I'm not aware of anything that does in the compiler ABI we're using on Fuchsia. | |
84–88 | Actually we could do all of the allocation and setup except for storing the uptr in __hwasan_tls. | |
137 | Most of what's happening in this function is common with the Linux code. | |
compiler-rt/lib/hwasan/hwasan_thread.cpp | ||
42–45 | This is stuff that could be done either in the before-create hook or in the on-start hook. But it's probably not especially worthwhile to move it to before-create as long as we have on-start doing any allocation at all. So to avoid a whole lot more refactoring to move the ringbuffer setup and such, might as well just leave this in on-start too. | |
58–63 | This is probably the only part that actually needs to be different between Linux and Fuchsia. | |
compiler-rt/lib/hwasan/hwasan_thread.h | ||
85 | I think these need to be left uniformly uninitialized to guarantee they can be "linker-initialized". |
Rebased against recent refactoring commits and addressed some comments.
I think I can omit some functions like GetCurrentThread or GetRingBufferSize which are small enough to merit their own changes .
compiler-rt/lib/hwasan/hwasan_fuchsia.cpp | ||
---|---|---|
41 | Added. | |
137 | Updated such that this just calls InitStackRingBuffer which handles the stack ring buffer initialization. | |
compiler-rt/lib/hwasan/hwasan_thread.cpp | ||
42–45 | With the refactoring from D104248, this bit will be done in the before-create hook without any changes to this code. | |
58–63 | This is done in D104248. |
Let me know if this should be split up also. I think this might be small and and simple enough for one patch.
clang-format: please reformat the code