Bug 475650 - DRD does not work with C11 threads
Summary: DRD does not work with C11 threads
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: drd (show other bugs)
Version: unspecified
Platform: Arch Linux Linux
: NOR crash
Target Milestone: ---
Assignee: Paul Floyd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-15 08:26 UTC by Dale Weiler
Modified: 2023-10-16 13:42 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dale Weiler 2023-10-15 08:26:33 UTC
SUMMARY
DRD does not appear to support C11 threads.

STEPS TO REPRODUCE
Just create a thread in C with `thrd_create`

OBSERVED RESULT
==2451066== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==2451066==  Access not within mapped region at address 0x7
==2451066==    at 0x4934634: pthread_attr_getdetachstate (pthread_attr_getdetachstate.c:29)
==2451066==    by 0x484ED7D: pthread_create_intercept (drd_pthread_intercepts.c:609)
==2451066==    by 0x484ED7D: pthread_create@* (drd_pthread_intercepts.c:640)
==2451066==    by 0x493F689: thrd_create@@GLIBC_2.34 (thrd_create.c:28)

EXPECTED RESULT
Should not crash

ADDITIONAL INFORMATION
I did some digging and it appears glibcs ntpl implements thrd_create by calling __pthread_create with an attr of ATTR_C11_THREAD which is just a macro for  ((void*)(uintptr_t)-1). Since this is not a null pointer, the check inside DRD's pthread_create_intercept succeeds then calls pthread_attr_getdetachstate with ((void*)(uintptr_t)-1) as the address of a valid attr struct.
Comment 1 Paul Floyd 2023-10-15 09:27:37 UTC
For reference

https://en.cppreference.com/w/c/thread/thrd_create
Comment 2 Bart Van Assche 2023-10-15 15:41:05 UTC
Does commit 6cea271f436d help?
Comment 3 Paul Floyd 2023-10-15 18:33:57 UTC
The code fix looks OK, but I think that the configure test and regtest should use C11 rather than C++.
Comment 4 Paul Floyd 2023-10-15 19:05:06 UTC
It's OK now on FreeBSD and I've also checked with musl and Illumos.
Comment 5 Bart Van Assche 2023-10-16 13:42:38 UTC
The following two additional commits have been pushed:
* 45590cee742b ("drd/tests/thrd_create: Convert from C++ to C")
* a9d065c48d35 ("configure.ac: Convert the thrd_create() test from C++ to C")