Skip to content

Commit

Permalink
[NFC][HWASAN] Use InternalAlloc for ThreadStartArg
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalybuka committed May 8, 2023
1 parent 1559361 commit 6fe4621
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compiler-rt/lib/hwasan/hwasan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,26 @@ static void *HwasanThreadStartFunc(void *arg) {
__hwasan_thread_enter();
ThreadStartArg A = *reinterpret_cast<ThreadStartArg *>(arg);
SetSigProcMask(&A.starting_sigset_, nullptr);
UnmapOrDie(arg, GetPageSizeCached());
InternalFree(arg);
return A.callback(A.param);
}

INTERCEPTOR(int, pthread_create, void *th, void *attr,
void *(*callback)(void *), void *param) {
EnsureMainThreadIDIsCorrect();
ScopedTaggingDisabler tagging_disabler;
ThreadStartArg *A = reinterpret_cast<ThreadStartArg *>(
MmapOrDie(GetPageSizeCached(), "pthread_create"));
ThreadStartArg *A = (ThreadStartArg *)InternalAlloc(sizeof(ThreadStartArg));
A->callback = callback;
A->param = param;
ScopedBlockSignals block(&A->starting_sigset_);
// ASAN uses the same approach to disable leaks from pthread_create.
# if CAN_SANITIZE_LEAKS
__lsan::ScopedInterceptorDisabler lsan_disabler;
# endif
return REAL(pthread_create)(th, attr, &HwasanThreadStartFunc, A);
int result = REAL(pthread_create)(th, attr, &HwasanThreadStartFunc, A);
if (result != 0)
InternalFree(A);
return result;
}

INTERCEPTOR(int, pthread_join, void *t, void **arg) {
Expand Down

0 comments on commit 6fe4621

Please sign in to comment.