Skip to content
15 changes: 15 additions & 0 deletions system/lib/compiler-rt/lib/lsan/lsan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,32 @@ INTERCEPTOR(int, pthread_create, void *th, void *attr,
ENSURE_LSAN_INITED;
EnsureMainThreadIDIsCorrect();

#if !SANITIZER_EMSCRIPTEN
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if could just have a single if at the top of this function?

#if !SANITIZER_EMSCRIPTEN
// Treat __ATTRP_C11_THREAD like the null attr
if (attr == __ATTRP_C11_THREAD) attr = nullptr;
#endif

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. Btw you meant #if SANITIZER_EMSCRIPTEN (without !), right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup

bool detached = [attr]() {
int d = 0;
return attr && !pthread_attr_getdetachstate(attr, &d) && IsStateDetached(d);
}();
#endif

__sanitizer_pthread_attr_t myattr;
#if SANITIZER_EMSCRIPTEN
if (!attr || attr == __ATTRP_C11_THREAD) {
#else
if (!attr) {
#endif
pthread_attr_init(&myattr);
attr = &myattr;
}
AdjustStackSize(attr);
#if SANITIZER_EMSCRIPTEN
// In Emscripten sanitizer, attr can be nonzero but __ATTRP_C11_THREAD, in
// which case pthread_attr_getdetachstate needs to run after pthread_attr_init
// above.
bool detached = [attr]() {
int d = 0;
return attr && !pthread_attr_getdetachstate(attr, &d) && IsStateDetached(d);
}();
#endif
uptr this_tid = GetCurrentThreadId();
int result;
{
Expand Down