Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common Do not ...



details:   https://anonhg.NetBSD.org/src/rev/a1279af3fc00
branches:  trunk
changeset: 944518:a1279af3fc00
user:      kamil <kamil%NetBSD.org@localhost>
date:      Fri Oct 02 14:36:54 2020 +0000

description:
Do not assume that _lwp_getprivate() returns unbiased private pointer

Cherry-pick and adapt:

>From 2a9ce60de98e53198047daaeeec3cf09ece4e693 Mon Sep 17 00:00:00 2001
From: Kamil Rytarowski <n54%gmx.com@localhost>
Date: Fri, 2 Oct 2020 16:13:09 +0200
Subject: [PATCH] [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.

diffstat:

 external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc |  12 +++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diffs (29 lines):

diff -r 087fe2317ba2 -r a1279af3fc00 external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
--- a/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc   Fri Oct 02 13:08:07 2020 +0000
+++ b/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc   Fri Oct 02 14:36:54 2020 +0000
@@ -25,6 +25,10 @@
 #include "sanitizer_placement_new.h"
 #include "sanitizer_procmaps.h"
 
+#if SANITIZER_NETBSD
+#define _RTLD_SOURCE  // for __lwp_gettcb_fast() / __lwp_getprivate_fast()
+#endif
+
 #include <dlfcn.h>  // for dlsym()
 #include <link.h>
 #include <pthread.h>
@@ -418,7 +422,13 @@
 
 #if SANITIZER_NETBSD
 static struct tls_tcb * ThreadSelfTlsTcb() {
-  return (struct tls_tcb *)_lwp_getprivate();
+  struct tls_tcb *tcb = nullptr;
+#ifdef __HAVE___LWP_GETTCB_FAST
+  tcb = (struct tls_tcb *)__lwp_gettcb_fast();
+#elif defined(__HAVE___LWP_GETPRIVATE_FAST)
+  tcb = (struct tls_tcb *)__lwp_getprivate_fast();
+#endif
+  return tcb;
 }
 
 uptr ThreadSelf() {



Home | Main Index | Thread Index | Old Index