[compiler-rt] r317946 - [tsan] Move out more types to sanitizer_common
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 10 14:41:52 PST 2017
Author: vitalybuka
Date: Fri Nov 10 14:41:52 2017
New Revision: 317946
URL: http://llvm.org/viewvc/llvm-project?rev=317946&view=rev
Log:
[tsan] Move out more types to sanitizer_common
https://github.com/google/sanitizers/issues/637
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_signal_interceptors.inc
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc?rev=317946&r1=317945&r2=317946&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc Fri Nov 10 14:41:52 2017
@@ -105,9 +105,10 @@ unsigned struct_msqid_ds_sz = sizeof(str
unsigned struct_mq_attr_sz = sizeof(struct mq_attr);
unsigned struct_statvfs_sz = sizeof(struct statvfs);
-uptr sig_ign = (uptr)SIG_IGN;
-uptr sig_dfl = (uptr)SIG_DFL;
-uptr sa_siginfo = (uptr)SA_SIGINFO;
+const uptr sig_ign = SIG_IGN;
+const uptr sig_dfl = (uptr)SIG_DFL;
+const uptr sig_err = (uptr)SIG_ERR;
+const uptr sa_siginfo = (uptr)SA_SIGINFO;
int shmctl_ipc_stat = (int)IPC_STAT;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h?rev=317946&r1=317945&r2=317946&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h Fri Nov 10 14:41:52 2017
@@ -226,10 +226,15 @@ struct __sanitizer_siginfo {
u64 opaque[128 / sizeof(u64)];
};
+using __sanitizer_sighandler_ptr = void (*)(int sig);
+using __sanitizer_sigactionhandler_ptr = void (*)(int sig,
+ __sanitizer_siginfo *siginfo,
+ void *uctx);
+
struct __sanitizer_sigaction {
union {
- void (*handler)(int sig);
- void (*sigaction)(int sig, __sanitizer_siginfo *siginfo, void *uctx);
+ __sanitizer_sighandler_ptr handler;
+ __sanitizer_sigactionhandler_ptr sigaction;
};
__sanitizer_sigset_t sa_mask;
int sa_flags;
@@ -247,9 +252,10 @@ struct __sanitizer_kernel_sigaction_t {
__sanitizer_kernel_sigset_t sa_mask;
};
-extern uptr sig_ign;
-extern uptr sig_dfl;
-extern uptr sa_siginfo;
+extern const uptr sig_ign;
+extern const uptr sig_dfl;
+extern const uptr sig_err;
+extern const uptr sa_siginfo;
extern int af_inet;
extern int af_inet6;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=317946&r1=317945&r2=317946&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Fri Nov 10 14:41:52 2017
@@ -264,9 +264,10 @@ namespace __sanitizer {
unsigned struct_statvfs_sz = sizeof(struct statvfs);
#endif // (SANITIZER_LINUX || SANITIZER_FREEBSD) && !SANITIZER_ANDROID
- uptr sig_ign = (uptr)SIG_IGN;
- uptr sig_dfl = (uptr)SIG_DFL;
- uptr sa_siginfo = (uptr)SA_SIGINFO;
+ const uptr sig_ign = (uptr)SIG_IGN;
+ const uptr sig_dfl = (uptr)SIG_DFL;
+ const uptr sig_err = (uptr)SIG_ERR;
+ const uptr sa_siginfo = (uptr)SA_SIGINFO;
#if SANITIZER_LINUX
int e_tabsz = (int)E_TABSZ;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=317946&r1=317945&r2=317946&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Fri Nov 10 14:41:52 2017
@@ -599,13 +599,17 @@ namespace __sanitizer {
u64 opaque[128 / sizeof(u64)];
};
+ using __sanitizer_sighandler_ptr = void (*)(int sig);
+ using __sanitizer_sigactionhandler_ptr =
+ void (*)(int sig, __sanitizer_siginfo *siginfo, void *uctx);
+
// Linux system headers define the 'sa_handler' and 'sa_sigaction' macros.
#if SANITIZER_ANDROID && (SANITIZER_WORDSIZE == 64)
struct __sanitizer_sigaction {
unsigned sa_flags;
union {
- void (*sigaction)(int sig, __sanitizer_siginfo *siginfo, void *uctx);
- void (*handler)(int sig);
+ __sanitizer_sigactionhandler_ptr sigaction;
+ __sanitizer_sighandler_ptr handler;
};
__sanitizer_sigset_t sa_mask;
void (*sa_restorer)();
@@ -614,16 +618,16 @@ namespace __sanitizer {
struct __sanitizer_sigaction {
unsigned sa_flags;
union {
- void (*sigaction)(int sig, __sanitizer_siginfo *siginfo, void *uctx);
- void (*handler)(int sig);
+ __sanitizer_sigactionhandler_ptr sigaction;
+ __sanitizer_sighandler_ptr handler;
};
__sanitizer_sigset_t sa_mask;
};
#elif SANITIZER_ANDROID && (SANITIZER_WORDSIZE == 32)
struct __sanitizer_sigaction {
union {
- void (*sigaction)(int sig, __sanitizer_siginfo *siginfo, void *uctx);
- void (*handler)(int sig);
+ __sanitizer_sigactionhandler_ptr sigaction;
+ __sanitizer_sighandler_ptr handler;
};
__sanitizer_sigset_t sa_mask;
uptr sa_flags;
@@ -635,8 +639,8 @@ namespace __sanitizer {
unsigned int sa_flags;
#endif
union {
- void (*sigaction)(int sig, __sanitizer_siginfo *siginfo, void *uctx);
- void (*handler)(int sig);
+ __sanitizer_sigactionhandler_ptr sigaction;
+ __sanitizer_sighandler_ptr handler;
};
#if SANITIZER_FREEBSD
int sa_flags;
@@ -712,9 +716,10 @@ namespace __sanitizer {
};
#endif
- extern uptr sig_ign;
- extern uptr sig_dfl;
- extern uptr sa_siginfo;
+ extern const uptr sig_ign;
+ extern const uptr sig_dfl;
+ extern const uptr sig_err;
+ extern const uptr sa_siginfo;
#if SANITIZER_LINUX
extern int e_tabsz;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_signal_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_signal_interceptors.inc?rev=317946&r1=317945&r2=317946&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_signal_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_signal_interceptors.inc Fri Nov 10 14:41:52 2017
@@ -29,7 +29,7 @@ using namespace __sanitizer;
#endif
#if SANITIZER_INTERCEPT_BSD_SIGNAL
-INTERCEPTOR(void *, bsd_signal, int signum, uptr handler) {
+INTERCEPTOR(uptr, bsd_signal, int signum, uptr handler) {
if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return 0;
SIGNAL_INTERCEPTOR_SIGNAL_IMPL(bsd_signal, signum, handler);
}
@@ -39,8 +39,9 @@ INTERCEPTOR(void *, bsd_signal, int sign
#endif // SANITIZER_INTERCEPT_BSD_SIGNAL
#if SANITIZER_INTERCEPT_SIGNAL_AND_SIGACTION
-INTERCEPTOR(void *, signal, int signum, uptr handler) {
- if (GetHandleSignalMode(signum) == kHandleSignalExclusive) return nullptr;
+INTERCEPTOR(uptr, signal, int signum, uptr handler) {
+ if (GetHandleSignalMode(signum) == kHandleSignalExclusive)
+ return (uptr) nullptr;
SIGNAL_INTERCEPTOR_SIGNAL_IMPL(signal, signum, handler);
}
#define INIT_SIGNAL COMMON_INTERCEPT_FUNCTION(signal)
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=317946&r1=317945&r2=317946&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Fri Nov 10 14:41:52 2017
@@ -144,13 +144,6 @@ typedef long long_t; // NOLINT
# define F_TLOCK 2 /* Test and lock a region for exclusive use. */
# define F_TEST 3 /* Test a region for other processes locks. */
-typedef void (*sighandler_t)(int sig);
-typedef void (*sigactionhandler_t)(int sig, __sanitizer_siginfo *siginfo,
- void *uctx);
-
-const sighandler_t SIG_DFL = (sighandler_t)0;
-const sighandler_t SIG_IGN = (sighandler_t)1;
-const sighandler_t SIG_ERR = (sighandler_t)-1;
#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD
const int SA_SIGINFO = 0x40;
const int SIG_SETMASK = 3;
@@ -1827,11 +1820,11 @@ static void CallUserSignalHandler(Thread
// because the handler can reset it.
volatile uptr pc =
sigact ? (uptr)sigactions[sig].sigaction : (uptr)sigactions[sig].handler;
- if (pc != (uptr)SIG_DFL && pc != (uptr)SIG_IGN) {
+ if (pc != sig_dfl && pc != sig_ign) {
if (sigact)
- ((sigactionhandler_t)pc)(sig, info, uctx);
+ ((__sanitizer_sigactionhandler_ptr)pc)(sig, info, uctx);
else
- ((sighandler_t)pc)(sig);
+ ((__sanitizer_sighandler_ptr)pc)(sig);
}
if (!ctx->after_multithreaded_fork) {
thr->ignore_reads_and_writes = ignore_reads_and_writes;
@@ -1952,14 +1945,16 @@ static void rtl_sigaction(int sig, __san
static int sigaction_impl(int sig, __sanitizer_sigaction *act,
__sanitizer_sigaction *old);
-static sighandler_t signal_impl(int sig, sighandler_t h);
+static __sanitizer_sighandler_ptr signal_impl(int sig,
+ __sanitizer_sighandler_ptr h);
TSAN_INTERCEPTOR(int, sigaction, int sig, __sanitizer_sigaction *act,
__sanitizer_sigaction *old) {
return sigaction_impl(sig, act, old);
}
-TSAN_INTERCEPTOR(sighandler_t, signal, int sig, sighandler_t h) {
+TSAN_INTERCEPTOR(__sanitizer_sighandler_ptr, signal, int sig,
+ __sanitizer_sighandler_ptr h) {
return signal_impl(sig, h);
}
@@ -2293,7 +2288,8 @@ int sigaction_impl(int sig, __sanitizer_
// and signal handler reads the handler concurrently. It it can read
// some bytes from old value and some bytes from new value.
// Use volatile to prevent insertion of memcpy.
- sigactions[sig].handler = *(volatile sighandler_t *)&act->handler;
+ sigactions[sig].handler =
+ *(volatile __sanitizer_sighandler_ptr *)&act->handler;
sigactions[sig].sa_flags = *(volatile int *)&act->sa_flags;
internal_memcpy(&sigactions[sig].sa_mask, &act->sa_mask,
sizeof(sigactions[sig].sa_mask));
@@ -2303,7 +2299,7 @@ int sigaction_impl(int sig, __sanitizer_
__sanitizer_sigaction newact;
internal_memcpy(&newact, act, sizeof(newact));
internal_sigfillset(&newact.sa_mask);
- if (act->handler != SIG_IGN && act->handler != SIG_DFL) {
+ if ((uptr)act->handler != sig_ign && (uptr)act->handler != sig_dfl) {
if (newact.sa_flags & SA_SIGINFO)
newact.sigaction = rtl_sigaction;
else
@@ -2314,14 +2310,15 @@ int sigaction_impl(int sig, __sanitizer_
return res;
}
-static sighandler_t signal_impl(int sig, sighandler_t h) {
+static __sanitizer_sighandler_ptr signal_impl(int sig,
+ __sanitizer_sighandler_ptr h) {
__sanitizer_sigaction act;
act.handler = h;
internal_memset(&act.sa_mask, -1, sizeof(act.sa_mask));
act.sa_flags = 0;
__sanitizer_sigaction old;
int res = sigaction(sig, &act, &old);
- if (res) return SIG_ERR;
+ if (res) return (__sanitizer_sighandler_ptr)sig_err;
return old.handler;
}
More information about the llvm-commits
mailing list