xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp (revision 297eecfb02bb25902531dbb5c3b9a88caf8adf29)
1 //===-- tsan_platform_linux.cpp -------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 //
11 // Linux- and BSD-specific code.
12 //===----------------------------------------------------------------------===//
13 
14 #include "sanitizer_common/sanitizer_platform.h"
15 #if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
16 
17 #include "sanitizer_common/sanitizer_common.h"
18 #include "sanitizer_common/sanitizer_libc.h"
19 #include "sanitizer_common/sanitizer_linux.h"
20 #include "sanitizer_common/sanitizer_platform_limits_netbsd.h"
21 #include "sanitizer_common/sanitizer_platform_limits_posix.h"
22 #include "sanitizer_common/sanitizer_posix.h"
23 #include "sanitizer_common/sanitizer_procmaps.h"
24 #include "sanitizer_common/sanitizer_stackdepot.h"
25 #include "sanitizer_common/sanitizer_stoptheworld.h"
26 #include "tsan_flags.h"
27 #include "tsan_platform.h"
28 #include "tsan_rtl.h"
29 
30 #include <fcntl.h>
31 #include <pthread.h>
32 #include <signal.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdarg.h>
37 #include <sys/mman.h>
38 #if SANITIZER_LINUX
39 #include <sys/personality.h>
40 #include <setjmp.h>
41 #endif
42 #include <sys/syscall.h>
43 #include <sys/socket.h>
44 #include <sys/time.h>
45 #include <sys/types.h>
46 #include <sys/resource.h>
47 #include <sys/stat.h>
48 #include <unistd.h>
49 #include <sched.h>
50 #include <dlfcn.h>
51 #if SANITIZER_LINUX
52 #define __need_res_state
53 #include <resolv.h>
54 #endif
55 
56 #ifdef sa_handler
57 # undef sa_handler
58 #endif
59 
60 #ifdef sa_sigaction
61 # undef sa_sigaction
62 #endif
63 
64 #if SANITIZER_FREEBSD
65 extern "C" void *__libc_stack_end;
66 void *__libc_stack_end = 0;
67 #endif
68 
69 #if SANITIZER_LINUX && (defined(__aarch64__) || defined(__loongarch_lp64)) && \
70     !SANITIZER_GO
71 # define INIT_LONGJMP_XOR_KEY 1
72 #else
73 # define INIT_LONGJMP_XOR_KEY 0
74 #endif
75 
76 #if INIT_LONGJMP_XOR_KEY
77 #include "interception/interception.h"
78 // Must be declared outside of other namespaces.
79 DECLARE_REAL(int, _setjmp, void *env)
80 #endif
81 
82 namespace __tsan {
83 
84 #if INIT_LONGJMP_XOR_KEY
85 static void InitializeLongjmpXorKey();
86 static uptr longjmp_xor_key;
87 #endif
88 
89 // Runtime detected VMA size.
90 uptr vmaSize;
91 
92 enum {
93   MemTotal,
94   MemShadow,
95   MemMeta,
96   MemFile,
97   MemMmap,
98   MemHeap,
99   MemOther,
100   MemCount,
101 };
102 
103 void FillProfileCallback(uptr p, uptr rss, bool file, uptr *mem) {
104   mem[MemTotal] += rss;
105   if (p >= ShadowBeg() && p < ShadowEnd())
106     mem[MemShadow] += rss;
107   else if (p >= MetaShadowBeg() && p < MetaShadowEnd())
108     mem[MemMeta] += rss;
109   else if ((p >= LoAppMemBeg() && p < LoAppMemEnd()) ||
110            (p >= MidAppMemBeg() && p < MidAppMemEnd()) ||
111            (p >= HiAppMemBeg() && p < HiAppMemEnd()))
112     mem[file ? MemFile : MemMmap] += rss;
113   else if (p >= HeapMemBeg() && p < HeapMemEnd())
114     mem[MemHeap] += rss;
115   else
116     mem[MemOther] += rss;
117 }
118 
119 void WriteMemoryProfile(char *buf, uptr buf_size, u64 uptime_ns) {
120   uptr mem[MemCount];
121   internal_memset(mem, 0, sizeof(mem));
122   GetMemoryProfile(FillProfileCallback, mem);
123   auto meta = ctx->metamap.GetMemoryStats();
124   StackDepotStats stacks = StackDepotGetStats();
125   uptr nthread, nlive;
126   ctx->thread_registry.GetNumberOfThreads(&nthread, &nlive);
127   uptr trace_mem;
128   {
129     Lock l(&ctx->slot_mtx);
130     trace_mem = ctx->trace_part_total_allocated * sizeof(TracePart);
131   }
132   uptr internal_stats[AllocatorStatCount];
133   internal_allocator()->GetStats(internal_stats);
134   // All these are allocated from the common mmap region.
135   mem[MemMmap] -= meta.mem_block + meta.sync_obj + trace_mem +
136                   stacks.allocated + internal_stats[AllocatorStatMapped];
137   if (s64(mem[MemMmap]) < 0)
138     mem[MemMmap] = 0;
139   internal_snprintf(
140       buf, buf_size,
141       "==%zu== %llus [%zu]: RSS %zd MB: shadow:%zd meta:%zd file:%zd"
142       " mmap:%zd heap:%zd other:%zd intalloc:%zd memblocks:%zd syncobj:%zu"
143       " trace:%zu stacks=%zd threads=%zu/%zu\n",
144       internal_getpid(), uptime_ns / (1000 * 1000 * 1000), ctx->global_epoch,
145       mem[MemTotal] >> 20, mem[MemShadow] >> 20, mem[MemMeta] >> 20,
146       mem[MemFile] >> 20, mem[MemMmap] >> 20, mem[MemHeap] >> 20,
147       mem[MemOther] >> 20, internal_stats[AllocatorStatMapped] >> 20,
148       meta.mem_block >> 20, meta.sync_obj >> 20, trace_mem >> 20,
149       stacks.allocated >> 20, nlive, nthread);
150 }
151 
152 #if !SANITIZER_GO
153 // Mark shadow for .rodata sections with the special Shadow::kRodata marker.
154 // Accesses to .rodata can't race, so this saves time, memory and trace space.
155 static NOINLINE void MapRodata(char* buffer, uptr size) {
156   // First create temp file.
157   const char *tmpdir = GetEnv("TMPDIR");
158   if (tmpdir == 0)
159     tmpdir = GetEnv("TEST_TMPDIR");
160 #ifdef P_tmpdir
161   if (tmpdir == 0)
162     tmpdir = P_tmpdir;
163 #endif
164   if (tmpdir == 0)
165     return;
166   internal_snprintf(buffer, size, "%s/tsan.rodata.%d",
167                     tmpdir, (int)internal_getpid());
168   uptr openrv = internal_open(buffer, O_RDWR | O_CREAT | O_EXCL, 0600);
169   if (internal_iserror(openrv))
170     return;
171   internal_unlink(buffer);  // Unlink it now, so that we can reuse the buffer.
172   fd_t fd = openrv;
173   // Fill the file with Shadow::kRodata.
174   const uptr kMarkerSize = 512 * 1024 / sizeof(RawShadow);
175   InternalMmapVector<RawShadow> marker(kMarkerSize);
176   // volatile to prevent insertion of memset
177   for (volatile RawShadow *p = marker.data(); p < marker.data() + kMarkerSize;
178        p++)
179     *p = Shadow::kRodata;
180   internal_write(fd, marker.data(), marker.size() * sizeof(RawShadow));
181   // Map the file into memory.
182   uptr page = internal_mmap(0, GetPageSizeCached(), PROT_READ | PROT_WRITE,
183                             MAP_PRIVATE | MAP_ANONYMOUS, fd, 0);
184   if (internal_iserror(page)) {
185     internal_close(fd);
186     return;
187   }
188   // Map the file into shadow of .rodata sections.
189   MemoryMappingLayout proc_maps(/*cache_enabled*/true);
190   // Reusing the buffer 'buffer'.
191   MemoryMappedSegment segment(buffer, size);
192   while (proc_maps.Next(&segment)) {
193     if (segment.filename[0] != 0 && segment.filename[0] != '[' &&
194         segment.IsReadable() && segment.IsExecutable() &&
195         !segment.IsWritable() && IsAppMem(segment.start)) {
196       // Assume it's .rodata
197       char *shadow_start = (char *)MemToShadow(segment.start);
198       char *shadow_end = (char *)MemToShadow(segment.end);
199       for (char *p = shadow_start; p < shadow_end;
200            p += marker.size() * sizeof(RawShadow)) {
201         internal_mmap(
202             p, Min<uptr>(marker.size() * sizeof(RawShadow), shadow_end - p),
203             PROT_READ, MAP_PRIVATE | MAP_FIXED, fd, 0);
204       }
205     }
206   }
207   internal_close(fd);
208 }
209 
210 void InitializeShadowMemoryPlatform() {
211   char buffer[256];  // Keep in a different frame.
212   MapRodata(buffer, sizeof(buffer));
213 }
214 
215 #endif  // #if !SANITIZER_GO
216 
217 void InitializePlatformEarly() {
218   vmaSize =
219     (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1);
220 #if defined(__aarch64__)
221 # if !SANITIZER_GO
222   if (vmaSize != 39 && vmaSize != 42 && vmaSize != 48) {
223     Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
224     Printf("FATAL: Found %zd - Supported 39, 42 and 48\n", vmaSize);
225     Die();
226   }
227 #else
228   if (vmaSize != 48) {
229     Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
230     Printf("FATAL: Found %zd - Supported 48\n", vmaSize);
231     Die();
232   }
233 #endif
234 #elif SANITIZER_LOONGARCH64
235 # if !SANITIZER_GO
236   if (vmaSize != 47) {
237     Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
238     Printf("FATAL: Found %zd - Supported 47\n", vmaSize);
239     Die();
240   }
241 #    else
242   if (vmaSize != 47) {
243     Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
244     Printf("FATAL: Found %zd - Supported 47\n", vmaSize);
245     Die();
246   }
247 #    endif
248 #elif defined(__powerpc64__)
249 # if !SANITIZER_GO
250   if (vmaSize != 44 && vmaSize != 46 && vmaSize != 47) {
251     Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
252     Printf("FATAL: Found %zd - Supported 44, 46, and 47\n", vmaSize);
253     Die();
254   }
255 # else
256   if (vmaSize != 46 && vmaSize != 47) {
257     Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
258     Printf("FATAL: Found %zd - Supported 46, and 47\n", vmaSize);
259     Die();
260   }
261 # endif
262 #elif defined(__mips64)
263 # if !SANITIZER_GO
264   if (vmaSize != 40) {
265     Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
266     Printf("FATAL: Found %zd - Supported 40\n", vmaSize);
267     Die();
268   }
269 # else
270   if (vmaSize != 47) {
271     Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
272     Printf("FATAL: Found %zd - Supported 47\n", vmaSize);
273     Die();
274   }
275 # endif
276 #  elif SANITIZER_RISCV64
277   // the bottom half of vma is allocated for userspace
278   vmaSize = vmaSize + 1;
279 #    if !SANITIZER_GO
280   if (vmaSize != 39 && vmaSize != 48) {
281     Printf("FATAL: ThreadSanitizer: unsupported VMA range\n");
282     Printf("FATAL: Found %zd - Supported 39 and 48\n", vmaSize);
283     Die();
284   }
285 #    endif
286 #  endif
287 }
288 
289 void InitializePlatform() {
290   DisableCoreDumperIfNecessary();
291 
292   // Go maps shadow memory lazily and works fine with limited address space.
293   // Unlimited stack is not a problem as well, because the executable
294   // is not compiled with -pie.
295 #if !SANITIZER_GO
296   {
297     bool reexec = false;
298     // TSan doesn't play well with unlimited stack size (as stack
299     // overlaps with shadow memory). If we detect unlimited stack size,
300     // we re-exec the program with limited stack size as a best effort.
301     if (StackSizeIsUnlimited()) {
302       const uptr kMaxStackSize = 32 * 1024 * 1024;
303       VReport(1, "Program is run with unlimited stack size, which wouldn't "
304                  "work with ThreadSanitizer.\n"
305                  "Re-execing with stack size limited to %zd bytes.\n",
306               kMaxStackSize);
307       SetStackSizeLimitInBytes(kMaxStackSize);
308       reexec = true;
309     }
310 
311     if (!AddressSpaceIsUnlimited()) {
312       Report("WARNING: Program is run with limited virtual address space,"
313              " which wouldn't work with ThreadSanitizer.\n");
314       Report("Re-execing with unlimited virtual address space.\n");
315       SetAddressSpaceUnlimited();
316       reexec = true;
317     }
318 #if SANITIZER_ANDROID && (defined(__aarch64__) || defined(__x86_64__))
319     // After patch "arm64: mm: support ARCH_MMAP_RND_BITS." is introduced in
320     // linux kernel, the random gap between stack and mapped area is increased
321     // from 128M to 36G on 39-bit aarch64. As it is almost impossible to cover
322     // this big range, we should disable randomized virtual space on aarch64.
323     // ASLR personality check.
324     int old_personality = personality(0xffffffff);
325     if (old_personality != -1 && (old_personality & ADDR_NO_RANDOMIZE) == 0) {
326       VReport(1, "WARNING: Program is run with randomized virtual address "
327               "space, which wouldn't work with ThreadSanitizer.\n"
328               "Re-execing with fixed virtual address space.\n");
329       CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1);
330       reexec = true;
331     }
332 
333 #endif
334 #if SANITIZER_LINUX && (defined(__aarch64__) || defined(__loongarch_lp64))
335     // Initialize the xor key used in {sig}{set,long}jump.
336     InitializeLongjmpXorKey();
337 #endif
338     if (reexec)
339       ReExec();
340   }
341 
342   CheckAndProtect();
343   InitTlsSize();
344 #endif  // !SANITIZER_GO
345 }
346 
347 #if !SANITIZER_GO
348 // Extract file descriptors passed to glibc internal __res_iclose function.
349 // This is required to properly "close" the fds, because we do not see internal
350 // closes within glibc. The code is a pure hack.
351 int ExtractResolvFDs(void *state, int *fds, int nfd) {
352 #if SANITIZER_LINUX && !SANITIZER_ANDROID
353   int cnt = 0;
354   struct __res_state *statp = (struct __res_state*)state;
355   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
356     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
357       fds[cnt++] = statp->_u._ext.nssocks[i];
358   }
359   return cnt;
360 #else
361   return 0;
362 #endif
363 }
364 
365 // Extract file descriptors passed via UNIX domain sockets.
366 // This is required to properly handle "open" of these fds.
367 // see 'man recvmsg' and 'man 3 cmsg'.
368 int ExtractRecvmsgFDs(void *msgp, int *fds, int nfd) {
369   int res = 0;
370   msghdr *msg = (msghdr*)msgp;
371   struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg);
372   for (; cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
373     if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS)
374       continue;
375     int n = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(fds[0]);
376     for (int i = 0; i < n; i++) {
377       fds[res++] = ((int*)CMSG_DATA(cmsg))[i];
378       if (res == nfd)
379         return res;
380     }
381   }
382   return res;
383 }
384 
385 // Reverse operation of libc stack pointer mangling
386 static uptr UnmangleLongJmpSp(uptr mangled_sp) {
387 #if defined(__x86_64__)
388 # if SANITIZER_LINUX
389   // Reverse of:
390   //   xor  %fs:0x30, %rsi
391   //   rol  $0x11, %rsi
392   uptr sp;
393   asm("ror  $0x11,     %0 \n"
394       "xor  %%fs:0x30, %0 \n"
395       : "=r" (sp)
396       : "0" (mangled_sp));
397   return sp;
398 # else
399   return mangled_sp;
400 # endif
401 #elif defined(__aarch64__)
402 # if SANITIZER_LINUX
403   return mangled_sp ^ longjmp_xor_key;
404 # else
405   return mangled_sp;
406 # endif
407 #elif defined(__loongarch_lp64)
408   return mangled_sp ^ longjmp_xor_key;
409 #elif defined(__powerpc64__)
410   // Reverse of:
411   //   ld   r4, -28696(r13)
412   //   xor  r4, r3, r4
413   uptr xor_key;
414   asm("ld  %0, -28696(%%r13)" : "=r" (xor_key));
415   return mangled_sp ^ xor_key;
416 #elif defined(__mips__)
417   return mangled_sp;
418 #    elif SANITIZER_RISCV64
419   return mangled_sp;
420 #    elif defined(__s390x__)
421   // tcbhead_t.stack_guard
422   uptr xor_key = ((uptr *)__builtin_thread_pointer())[5];
423   return mangled_sp ^ xor_key;
424 #    else
425 #      error "Unknown platform"
426 #    endif
427 }
428 
429 #if SANITIZER_NETBSD
430 # ifdef __x86_64__
431 #  define LONG_JMP_SP_ENV_SLOT 6
432 # else
433 #  error unsupported
434 # endif
435 #elif defined(__powerpc__)
436 # define LONG_JMP_SP_ENV_SLOT 0
437 #elif SANITIZER_FREEBSD
438 # ifdef __aarch64__
439 #  define LONG_JMP_SP_ENV_SLOT 1
440 # else
441 #  define LONG_JMP_SP_ENV_SLOT 2
442 # endif
443 #elif SANITIZER_LINUX
444 # ifdef __aarch64__
445 #  define LONG_JMP_SP_ENV_SLOT 13
446 # elif defined(__loongarch__)
447 #  define LONG_JMP_SP_ENV_SLOT 1
448 # elif defined(__mips64)
449 #  define LONG_JMP_SP_ENV_SLOT 1
450 #      elif SANITIZER_RISCV64
451 #        define LONG_JMP_SP_ENV_SLOT 13
452 #      elif defined(__s390x__)
453 #        define LONG_JMP_SP_ENV_SLOT 9
454 #      else
455 #        define LONG_JMP_SP_ENV_SLOT 6
456 #      endif
457 #endif
458 
459 uptr ExtractLongJmpSp(uptr *env) {
460   uptr mangled_sp = env[LONG_JMP_SP_ENV_SLOT];
461   return UnmangleLongJmpSp(mangled_sp);
462 }
463 
464 #if INIT_LONGJMP_XOR_KEY
465 // GLIBC mangles the function pointers in jmp_buf (used in {set,long}*jmp
466 // functions) by XORing them with a random key.  For AArch64 it is a global
467 // variable rather than a TCB one (as for x86_64/powerpc).  We obtain the key by
468 // issuing a setjmp and XORing the SP pointer values to derive the key.
469 static void InitializeLongjmpXorKey() {
470   // 1. Call REAL(setjmp), which stores the mangled SP in env.
471   jmp_buf env;
472   REAL(_setjmp)(env);
473 
474   // 2. Retrieve vanilla/mangled SP.
475   uptr sp;
476 #ifdef __loongarch__
477   asm("move  %0, $sp" : "=r" (sp));
478 #else
479   asm("mov  %0, sp" : "=r" (sp));
480 #endif
481   uptr mangled_sp = ((uptr *)&env)[LONG_JMP_SP_ENV_SLOT];
482 
483   // 3. xor SPs to obtain key.
484   longjmp_xor_key = mangled_sp ^ sp;
485 }
486 #endif
487 
488 extern "C" void __tsan_tls_initialization() {}
489 
490 void ImitateTlsWrite(ThreadState *thr, uptr tls_addr, uptr tls_size) {
491   // Check that the thr object is in tls;
492   const uptr thr_beg = (uptr)thr;
493   const uptr thr_end = (uptr)thr + sizeof(*thr);
494   CHECK_GE(thr_beg, tls_addr);
495   CHECK_LE(thr_beg, tls_addr + tls_size);
496   CHECK_GE(thr_end, tls_addr);
497   CHECK_LE(thr_end, tls_addr + tls_size);
498   // Since the thr object is huge, skip it.
499   const uptr pc = StackTrace::GetNextInstructionPc(
500       reinterpret_cast<uptr>(__tsan_tls_initialization));
501   MemoryRangeImitateWrite(thr, pc, tls_addr, thr_beg - tls_addr);
502   MemoryRangeImitateWrite(thr, pc, thr_end, tls_addr + tls_size - thr_end);
503 }
504 
505 // Note: this function runs with async signals enabled,
506 // so it must not touch any tsan state.
507 int call_pthread_cancel_with_cleanup(int (*fn)(void *arg),
508                                      void (*cleanup)(void *arg), void *arg) {
509   // pthread_cleanup_push/pop are hardcore macros mess.
510   // We can't intercept nor call them w/o including pthread.h.
511   int res;
512   pthread_cleanup_push(cleanup, arg);
513   res = fn(arg);
514   pthread_cleanup_pop(0);
515   return res;
516 }
517 #endif  // !SANITIZER_GO
518 
519 #if !SANITIZER_GO
520 void ReplaceSystemMalloc() { }
521 #endif
522 
523 #if !SANITIZER_GO
524 #if SANITIZER_ANDROID
525 // On Android, one thread can call intercepted functions after
526 // DestroyThreadState(), so add a fake thread state for "dead" threads.
527 static ThreadState *dead_thread_state = nullptr;
528 
529 ThreadState *cur_thread() {
530   ThreadState* thr = reinterpret_cast<ThreadState*>(*get_android_tls_ptr());
531   if (thr == nullptr) {
532     __sanitizer_sigset_t emptyset;
533     internal_sigfillset(&emptyset);
534     __sanitizer_sigset_t oldset;
535     CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, &emptyset, &oldset));
536     thr = reinterpret_cast<ThreadState*>(*get_android_tls_ptr());
537     if (thr == nullptr) {
538       thr = reinterpret_cast<ThreadState*>(MmapOrDie(sizeof(ThreadState),
539                                                      "ThreadState"));
540       *get_android_tls_ptr() = reinterpret_cast<uptr>(thr);
541       if (dead_thread_state == nullptr) {
542         dead_thread_state = reinterpret_cast<ThreadState*>(
543             MmapOrDie(sizeof(ThreadState), "ThreadState"));
544         dead_thread_state->fast_state.SetIgnoreBit();
545         dead_thread_state->ignore_interceptors = 1;
546         dead_thread_state->is_dead = true;
547         *const_cast<u32*>(&dead_thread_state->tid) = -1;
548         CHECK_EQ(0, internal_mprotect(dead_thread_state, sizeof(ThreadState),
549                                       PROT_READ));
550       }
551     }
552     CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, &oldset, nullptr));
553   }
554   return thr;
555 }
556 
557 void set_cur_thread(ThreadState *thr) {
558   *get_android_tls_ptr() = reinterpret_cast<uptr>(thr);
559 }
560 
561 void cur_thread_finalize() {
562   __sanitizer_sigset_t emptyset;
563   internal_sigfillset(&emptyset);
564   __sanitizer_sigset_t oldset;
565   CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, &emptyset, &oldset));
566   ThreadState* thr = reinterpret_cast<ThreadState*>(*get_android_tls_ptr());
567   if (thr != dead_thread_state) {
568     *get_android_tls_ptr() = reinterpret_cast<uptr>(dead_thread_state);
569     UnmapOrDie(thr, sizeof(ThreadState));
570   }
571   CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, &oldset, nullptr));
572 }
573 #endif  // SANITIZER_ANDROID
574 #endif  // if !SANITIZER_GO
575 
576 }  // namespace __tsan
577 
578 #endif  // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD
579