Skip to content

Commit 2a9ce60

Browse files
committed
[compiler-rt] [netbsd] Improve the portability of ThreadSelfTlsTcb
Use __lwp_gettcb_fast() and __lwp_getprivate_fast(), as _lwp_getprivate() can be a biased pointer and invalid for use in this function on all CPUs.
1 parent d9e3972 commit 2a9ce60

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include "sanitizer_placement_new.h"
2929
#include "sanitizer_procmaps.h"
3030

31+
#if SANITIZER_NETBSD
32+
#define _RTLD_SOURCE // for __lwp_gettcb_fast() / __lwp_getprivate_fast()
33+
#endif
34+
3135
#include <dlfcn.h> // for dlsym()
3236
#include <link.h>
3337
#include <pthread.h>
@@ -412,7 +416,13 @@ uptr ThreadSelf() {
412416

413417
#if SANITIZER_NETBSD
414418
static struct tls_tcb * ThreadSelfTlsTcb() {
415-
return (struct tls_tcb *)_lwp_getprivate();
419+
struct tls_tcb *tcb = nullptr;
420+
#ifdef __HAVE___LWP_GETTCB_FAST
421+
tcb = (struct tls_tcb *)__lwp_gettcb_fast();
422+
#elif defined(__HAVE___LWP_GETPRIVATE_FAST)
423+
tcb = (struct tls_tcb *)__lwp_getprivate_fast();
424+
#endif
425+
return tcb;
416426
}
417427

418428
uptr ThreadSelf() {

0 commit comments

Comments
 (0)