Skip to content

Commit 8b4d79e

Browse files
committed
[TSan] Add support for Android
1 parent 5482ef7 commit 8b4d79e

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,22 @@ INTERCEPTOR(int, puts, char *s) {
12871287
#if SANITIZER_INTERCEPT_PRCTL
12881288
INTERCEPTOR(int, prctl, int option, unsigned long arg2, unsigned long arg3,
12891289
unsigned long arg4, unsigned long arg5) {
1290+
# if SANITIZER_ANDROID
1291+
// This is a workaround to avoid the crash by leveraging compiler
1292+
// optimizations, which convert the code into a tail call so that
1293+
// no PAC-related instructions are generated.
1294+
// The root cause of the crash is that PR_PAC_RESET_KEYS generates
1295+
// a new PAC key. As a result, paciasp and autiasp use different
1296+
// keys, leading to the crash.
1297+
// However, this workaround does not prevent the crash in debug
1298+
// builds, since compiler optimizations are disabled and the
1299+
// function is not converted into a tail call.
1300+
static const int PR_PAC_RESET_KEYS = 54;
1301+
if (option == PR_PAC_RESET_KEYS) {
1302+
return REAL(prctl)(option, arg2, arg3, arg4, arg5);
1303+
}
1304+
# endif
1305+
12901306
void *ctx;
12911307
COMMON_INTERCEPTOR_ENTER(ctx, prctl, option, arg2, arg3, arg4, arg5);
12921308
static const int PR_SET_NAME = 15;

compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,7 +2411,7 @@ TSAN_INTERCEPTOR(int, vfork, int fake) {
24112411
}
24122412
#endif
24132413

2414-
#if SANITIZER_LINUX
2414+
#if SANITIZER_LINUX && !SANITIZER_ANDROID
24152415
TSAN_INTERCEPTOR(int, clone, int (*fn)(void *), void *stack, int flags,
24162416
void *arg, int *parent_tid, void *tls, pid_t *child_tid) {
24172417
SCOPED_INTERCEPTOR_RAW(clone, fn, stack, flags, arg, parent_tid, tls,
@@ -3120,7 +3120,7 @@ void InitializeInterceptors() {
31203120

31213121
TSAN_INTERCEPT(fork);
31223122
TSAN_INTERCEPT(vfork);
3123-
#if SANITIZER_LINUX
3123+
#if SANITIZER_LINUX && !SANITIZER_ANDROID
31243124
TSAN_INTERCEPT(clone);
31253125
#endif
31263126
#if !SANITIZER_ANDROID

compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,14 @@ void ThreadStart(ThreadState *thr, Tid tid, ThreadID os_id,
188188
}
189189
#endif
190190

191-
#if !SANITIZER_GO
191+
#if !SANITIZER_GO && !SANITIZER_ANDROID
192192
// Don't imitate stack/TLS writes for the main thread,
193193
// because its initialization is synchronized with all
194194
// subsequent threads anyway.
195+
// Because thr is created by MmapOrDie, the thr object
196+
// is not in tls, the pointer of thr object is in
197+
// TLS_SLOT_SANITIZER slot. So skip this check on
198+
// Android platform.
195199
if (tid != kMainTid) {
196200
if (stk_addr && stk_size) {
197201
const uptr pc = StackTrace::GetNextInstructionPc(

0 commit comments

Comments
 (0)