1//===-- sanitizer_posix_libcdep.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 shared between AddressSanitizer and ThreadSanitizer
10// run-time libraries and implements libc-dependent POSIX-specific functions
11// from sanitizer_libc.h.
12//===----------------------------------------------------------------------===//
13
14#include "sanitizer_platform.h"
15
16#if SANITIZER_POSIX
17
18#include "sanitizer_common.h"
19#include "sanitizer_flags.h"
20#include "sanitizer_platform_limits_netbsd.h"
21#include "sanitizer_platform_limits_posix.h"
22#include "sanitizer_platform_limits_solaris.h"
23#include "sanitizer_posix.h"
24#include "sanitizer_procmaps.h"
25
26#include <errno.h>
27#include <fcntl.h>
28#include <pthread.h>
29#include <signal.h>
30#include <stdlib.h>
31#include <sys/mman.h>
32#include <sys/resource.h>
33#include <sys/stat.h>
34#include <sys/time.h>
35#include <sys/types.h>
36#include <sys/wait.h>
37#include <unistd.h>
38
39#if SANITIZER_FREEBSD
40// The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before
41// that, it was never implemented. So just define it to zero.
42#undef MAP_NORESERVE
43#define MAP_NORESERVE 0
44#endif
45
46typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
47
48namespace __sanitizer {
49
50[[maybe_unused]] static atomic_uint8_t signal_handler_is_from_sanitizer[64];
51
52u32 GetUid() {
53 return getuid();
54}
55
56uptr GetThreadSelf() {
57 return (uptr)pthread_self();
58}
59
60void ReleaseMemoryPagesToOS(uptr beg, uptr end) {
61 uptr page_size = GetPageSizeCached();
62 uptr beg_aligned = RoundUpTo(size: beg, boundary: page_size);
63 uptr end_aligned = RoundDownTo(x: end, boundary: page_size);
64 if (beg_aligned < end_aligned)
65 internal_madvise(addr: beg_aligned, length: end_aligned - beg_aligned,
66 SANITIZER_MADVISE_DONTNEED);
67}
68
69void SetShadowRegionHugePageMode(uptr addr, uptr size) {
70#ifdef MADV_NOHUGEPAGE // May not be defined on old systems.
71 if (common_flags()->no_huge_pages_for_shadow)
72 internal_madvise(addr, length: size, MADV_NOHUGEPAGE);
73 else
74 internal_madvise(addr, length: size, MADV_HUGEPAGE);
75#endif // MADV_NOHUGEPAGE
76}
77
78bool DontDumpShadowMemory(uptr addr, uptr length) {
79#if defined(MADV_DONTDUMP)
80 return internal_madvise(addr, length, MADV_DONTDUMP) == 0;
81#elif defined(MADV_NOCORE)
82 return internal_madvise(addr, length, MADV_NOCORE) == 0;
83#else
84 return true;
85#endif // MADV_DONTDUMP
86}
87
88static rlim_t getlim(int res) {
89 rlimit rlim;
90 CHECK_EQ(0, getrlimit(res, &rlim));
91 return rlim.rlim_cur;
92}
93
94static void setlim(int res, rlim_t lim) {
95 struct rlimit rlim;
96 if (getrlimit(resource: res, rlimits: &rlim)) {
97 Report(format: "ERROR: %s getrlimit() failed %d\n", SanitizerToolName, errno);
98 Die();
99 }
100 rlim.rlim_cur = lim;
101 if (setrlimit(resource: res, rlimits: &rlim)) {
102 Report(format: "ERROR: %s setrlimit() failed %d\n", SanitizerToolName, errno);
103 Die();
104 }
105}
106
107void DisableCoreDumperIfNecessary() {
108 if (common_flags()->disable_coredump) {
109 rlimit rlim;
110 CHECK_EQ(0, getrlimit(RLIMIT_CORE, &rlim));
111 // On Linux, if the kernel.core_pattern sysctl starts with a '|' (i.e. it
112 // is being piped to a coredump handler such as systemd-coredumpd), the
113 // kernel ignores RLIMIT_CORE (since we aren't creating a file in the file
114 // system) except for the magic value of 1, which disables coredumps when
115 // piping. 1 byte is too small for any kind of valid core dump, so it
116 // also disables coredumps if kernel.core_pattern creates files directly.
117 // While most piped coredump handlers do respect the crashing processes'
118 // RLIMIT_CORE, this is notable not the case for Debian's systemd-coredump
119 // due to a local patch that changes sysctl.d/50-coredump.conf to ignore
120 // the specified limit and instead use RLIM_INFINITY.
121 //
122 // The alternative to using RLIMIT_CORE=1 would be to use prctl() with the
123 // PR_SET_DUMPABLE flag, however that also prevents ptrace(), so makes it
124 // impossible to attach a debugger.
125 //
126 // Note: we use rlim_max in the Min() call here since that is the upper
127 // limit for what can be set without getting an EINVAL error.
128 rlim.rlim_cur = Min<rlim_t>(SANITIZER_LINUX ? 1 : 0, b: rlim.rlim_max);
129 CHECK_EQ(0, setrlimit(RLIMIT_CORE, &rlim));
130 }
131}
132
133bool StackSizeIsUnlimited() {
134 rlim_t stack_size = getlim(RLIMIT_STACK);
135 return (stack_size == RLIM_INFINITY);
136}
137
138void SetStackSizeLimitInBytes(uptr limit) {
139 setlim(RLIMIT_STACK, lim: (rlim_t)limit);
140 CHECK(!StackSizeIsUnlimited());
141}
142
143bool AddressSpaceIsUnlimited() {
144 rlim_t as_size = getlim(RLIMIT_AS);
145 return (as_size == RLIM_INFINITY);
146}
147
148void SetAddressSpaceUnlimited() {
149 setlim(RLIMIT_AS, RLIM_INFINITY);
150 CHECK(AddressSpaceIsUnlimited());
151}
152
153void Abort() {
154#if !SANITIZER_GO
155 // If we are handling SIGABRT, unhandle it first.
156 // TODO(vitalybuka): Check if handler belongs to sanitizer.
157 if (GetHandleSignalMode(SIGABRT) != kHandleSignalNo) {
158 struct sigaction sigact;
159 internal_memset(s: &sigact, c: 0, n: sizeof(sigact));
160 sigact.sa_handler = SIG_DFL;
161 internal_sigaction(SIGABRT, act: &sigact, oldact: nullptr);
162 }
163#endif
164
165 abort();
166}
167
168int Atexit(void (*function)(void)) {
169#if !SANITIZER_GO
170 return atexit(func: function);
171#else
172 return 0;
173#endif
174}
175
176bool CreateDir(const char *pathname) { return mkdir(path: pathname, mode: 0755) == 0; }
177
178bool SupportsColoredOutput(fd_t fd) {
179 return isatty(fd: fd) != 0;
180}
181
182#if !SANITIZER_GO
183// TODO(glider): different tools may require different altstack size.
184static uptr GetAltStackSize() {
185 // Note: since GLIBC_2.31, SIGSTKSZ may be a function call, so this may be
186 // more costly that you think. However GetAltStackSize is only call 2-3 times
187 // per thread so don't cache the evaluation.
188 return SIGSTKSZ * 4;
189}
190
191void* SetAlternateSignalStack() {
192 stack_t altstack, oldstack;
193 CHECK_EQ(0, sigaltstack(nullptr, &oldstack));
194 // If the alternate stack is already in place, do nothing.
195 // Android always sets an alternate stack, but it's too small for us.
196 if (!SANITIZER_ANDROID && !(oldstack.ss_flags & SS_DISABLE))
197 return nullptr;
198 // TODO(glider): the mapped stack should have the MAP_STACK flag in the
199 // future. It is not required by man 2 sigaltstack now (they're using
200 // malloc()).
201 altstack.ss_size = GetAltStackSize();
202 altstack.ss_sp = (char *)MmapOrDie(size: altstack.ss_size, mem_type: __func__);
203 altstack.ss_flags = 0;
204 CHECK_EQ(0, sigaltstack(&altstack, nullptr));
205 return altstack.ss_sp;
206}
207
208void UnsetAlternateSignalStack(void* altstack_base) {
209 stack_t altstack, oldstack;
210 altstack.ss_sp = nullptr;
211 altstack.ss_flags = SS_DISABLE;
212 altstack.ss_size = GetAltStackSize(); // Some sane value required on Darwin.
213 CHECK_EQ(0, sigaltstack(&altstack, &oldstack));
214 if (altstack_base && altstack_base == oldstack.ss_sp) {
215 UnmapOrDie(addr: oldstack.ss_sp, size: oldstack.ss_size);
216 }
217}
218
219bool IsSignalHandlerFromSanitizer(int signum) {
220 return atomic_load(a: &signal_handler_is_from_sanitizer[signum],
221 mo: memory_order_relaxed);
222}
223
224bool SetSignalHandlerFromSanitizer(int signum, bool new_state) {
225 if (signum < 0 || static_cast<unsigned>(signum) >=
226 ARRAY_SIZE(signal_handler_is_from_sanitizer))
227 return false;
228
229 return atomic_exchange(a: &signal_handler_is_from_sanitizer[signum], v: new_state,
230 mo: memory_order_relaxed);
231}
232
233static void MaybeInstallSigaction(int signum,
234 SignalHandlerType handler) {
235 if (GetHandleSignalMode(signum) == kHandleSignalNo) return;
236
237 struct sigaction sigact;
238 internal_memset(s: &sigact, c: 0, n: sizeof(sigact));
239 sigact.sa_sigaction = (sa_sigaction_t)handler;
240 // Do not block the signal from being received in that signal's handler.
241 // Clients are responsible for handling this correctly.
242 sigact.sa_flags = SA_SIGINFO | SA_NODEFER;
243 if (common_flags()->use_sigaltstack) sigact.sa_flags |= SA_ONSTACK;
244 CHECK_EQ(0, internal_sigaction(signum, &sigact, nullptr));
245 VReport(1, "Installed the sigaction for signal %d\n", signum);
246
247 if (common_flags()->cloak_sanitizer_signal_handlers)
248 SetSignalHandlerFromSanitizer(signum, new_state: true);
249}
250
251void InstallDeadlySignalHandlers(SignalHandlerType handler) {
252 // Set the alternate signal stack for the main thread.
253 // This will cause SetAlternateSignalStack to be called twice, but the stack
254 // will be actually set only once.
255 if (common_flags()->use_sigaltstack) SetAlternateSignalStack();
256 MaybeInstallSigaction(SIGSEGV, handler);
257 MaybeInstallSigaction(SIGBUS, handler);
258 MaybeInstallSigaction(SIGABRT, handler);
259 MaybeInstallSigaction(SIGFPE, handler);
260 MaybeInstallSigaction(SIGILL, handler);
261 MaybeInstallSigaction(SIGTRAP, handler);
262}
263
264bool SignalContext::IsStackOverflow() const {
265 // Access at a reasonable offset above SP, or slightly below it (to account
266 // for x86_64 or PowerPC redzone, ARM push of multiple registers, etc) is
267 // probably a stack overflow.
268#ifdef __s390__
269 // On s390, the fault address in siginfo points to start of the page, not
270 // to the precise word that was accessed. Mask off the low bits of sp to
271 // take it into account.
272 bool IsStackAccess = addr >= (sp & ~0xFFF) && addr < sp + 0xFFFF;
273#else
274 // Let's accept up to a page size away from top of stack. Things like stack
275 // probing can trigger accesses with such large offsets.
276 bool IsStackAccess = addr + GetPageSizeCached() > sp && addr < sp + 0xFFFF;
277#endif
278
279#if __powerpc__
280 // Large stack frames can be allocated with e.g.
281 // lis r0,-10000
282 // stdux r1,r1,r0 # store sp to [sp-10000] and update sp by -10000
283 // If the store faults then sp will not have been updated, so test above
284 // will not work, because the fault address will be more than just "slightly"
285 // below sp.
286 if (!IsStackAccess && IsAccessibleMemoryRange(pc, 4)) {
287 u32 inst = *(unsigned *)pc;
288 u32 ra = (inst >> 16) & 0x1F;
289 u32 opcd = inst >> 26;
290 u32 xo = (inst >> 1) & 0x3FF;
291 // Check for store-with-update to sp. The instructions we accept are:
292 // stbu rs,d(ra) stbux rs,ra,rb
293 // sthu rs,d(ra) sthux rs,ra,rb
294 // stwu rs,d(ra) stwux rs,ra,rb
295 // stdu rs,ds(ra) stdux rs,ra,rb
296 // where ra is r1 (the stack pointer).
297 if (ra == 1 &&
298 (opcd == 39 || opcd == 45 || opcd == 37 || opcd == 62 ||
299 (opcd == 31 && (xo == 247 || xo == 439 || xo == 183 || xo == 181))))
300 IsStackAccess = true;
301 }
302#endif // __powerpc__
303
304 // We also check si_code to filter out SEGV caused by something else other
305 // then hitting the guard page or unmapped memory, like, for example,
306 // unaligned memory access.
307 auto si = static_cast<const siginfo_t *>(siginfo);
308 return IsStackAccess &&
309 (si->si_code == si_SEGV_MAPERR || si->si_code == si_SEGV_ACCERR);
310}
311
312#endif // SANITIZER_GO
313
314static void SetNonBlock(int fd) {
315 int res = fcntl(fd: fd, F_GETFL, 0);
316 CHECK(!internal_iserror(res, nullptr));
317
318 res |= O_NONBLOCK;
319 res = fcntl(fd: fd, F_SETFL, res);
320 CHECK(!internal_iserror(res, nullptr));
321}
322
323bool IsAccessibleMemoryRange(uptr beg, uptr size) {
324 while (size) {
325 // `read` from `fds[0]` into a dummy buffer to free up the pipe buffer for
326 // more `write` is slower than just recreating a pipe.
327 int fds[2];
328 CHECK_EQ(0, pipe(fds));
329
330 auto cleanup = at_scope_exit(fn: [&]() {
331 internal_close(fd: fds[0]);
332 internal_close(fd: fds[1]);
333 });
334
335 SetNonBlock(fds[1]);
336
337 int write_errno;
338 uptr w = internal_write(fd: fds[1], buf: reinterpret_cast<char *>(beg), count: size);
339 if (internal_iserror(retval: w, rverrno: &write_errno)) {
340 if (write_errno == EINTR)
341 continue;
342 CHECK_EQ(EFAULT, write_errno);
343 return false;
344 }
345 size -= w;
346 beg += w;
347 }
348
349 return true;
350}
351
352bool TryMemCpy(void *dest, const void *src, uptr n) {
353 if (!n)
354 return true;
355 int fds[2];
356 CHECK_EQ(0, pipe(fds));
357
358 auto cleanup = at_scope_exit(fn: [&]() {
359 internal_close(fd: fds[0]);
360 internal_close(fd: fds[1]);
361 });
362
363 SetNonBlock(fds[0]);
364 SetNonBlock(fds[1]);
365
366 char *d = static_cast<char *>(dest);
367 const char *s = static_cast<const char *>(src);
368
369 while (n) {
370 int e;
371 uptr w = internal_write(fd: fds[1], buf: s, count: n);
372 if (internal_iserror(retval: w, rverrno: &e)) {
373 if (e == EINTR)
374 continue;
375 CHECK_EQ(EFAULT, e);
376 return false;
377 }
378 s += w;
379 n -= w;
380
381 while (w) {
382 uptr r = internal_read(fd: fds[0], buf: d, count: w);
383 if (internal_iserror(retval: r, rverrno: &e)) {
384 CHECK_EQ(EINTR, e);
385 continue;
386 }
387
388 d += r;
389 w -= r;
390 }
391 }
392
393 return true;
394}
395
396void PlatformPrepareForSandboxing(void *args) {
397 // Some kinds of sandboxes may forbid filesystem access, so we won't be able
398 // to read the file mappings from /proc/self/maps. Luckily, neither the
399 // process will be able to load additional libraries, so it's fine to use the
400 // cached mappings.
401 MemoryMappingLayout::CacheMemoryMappings();
402}
403
404static bool MmapFixed(uptr fixed_addr, uptr size, int additional_flags,
405 const char *name) {
406 size = RoundUpTo(size, boundary: GetPageSizeCached());
407 fixed_addr = RoundDownTo(x: fixed_addr, boundary: GetPageSizeCached());
408 uptr p =
409 MmapNamed(addr: (void *)fixed_addr, length: size, PROT_READ | PROT_WRITE,
410 MAP_PRIVATE | MAP_FIXED | additional_flags | MAP_ANON, name);
411 int reserrno;
412 if (internal_iserror(retval: p, rverrno: &reserrno)) {
413 Report(
414 format: "ERROR: %s failed to "
415 "allocate 0x%zx (%zd) bytes at address %p (errno: %d)\n",
416 SanitizerToolName, size, size, (void *)fixed_addr, reserrno);
417 return false;
418 }
419 IncreaseTotalMmap(size);
420 return true;
421}
422
423bool MmapFixedNoReserve(uptr fixed_addr, uptr size, const char *name) {
424 return MmapFixed(fixed_addr, size, MAP_NORESERVE, name);
425}
426
427bool MmapFixedSuperNoReserve(uptr fixed_addr, uptr size, const char *name) {
428#if SANITIZER_FREEBSD
429 if (common_flags()->no_huge_pages_for_shadow)
430 return MmapFixedNoReserve(fixed_addr, size, name);
431 // MAP_NORESERVE is implicit with FreeBSD
432 return MmapFixed(fixed_addr, size, MAP_ALIGNED_SUPER, name);
433#else
434 bool r = MmapFixedNoReserve(fixed_addr, size, name);
435 if (r)
436 SetShadowRegionHugePageMode(addr: fixed_addr, size);
437 return r;
438#endif
439}
440
441uptr ReservedAddressRange::Init(uptr size, const char *name, uptr fixed_addr) {
442 base_ = fixed_addr ? MmapFixedNoAccess(fixed_addr, size, name)
443 : MmapNoAccess(size);
444 size_ = size;
445 name_ = name;
446 (void)os_handle_; // unsupported
447 return reinterpret_cast<uptr>(base_);
448}
449
450// Uses fixed_addr for now.
451// Will use offset instead once we've implemented this function for real.
452uptr ReservedAddressRange::Map(uptr fixed_addr, uptr size, const char *name) {
453 return reinterpret_cast<uptr>(
454 MmapFixedOrDieOnFatalError(fixed_addr, size, name));
455}
456
457uptr ReservedAddressRange::MapOrDie(uptr fixed_addr, uptr size,
458 const char *name) {
459 return reinterpret_cast<uptr>(MmapFixedOrDie(fixed_addr, size, name));
460}
461
462void ReservedAddressRange::Unmap(uptr addr, uptr size) {
463 CHECK_LE(size, size_);
464 if (addr == reinterpret_cast<uptr>(base_))
465 // If we unmap the whole range, just null out the base.
466 base_ = (size == size_) ? nullptr : reinterpret_cast<void*>(addr + size);
467 else
468 CHECK_EQ(addr + size, reinterpret_cast<uptr>(base_) + size_);
469 size_ -= size;
470 UnmapOrDie(addr: reinterpret_cast<void*>(addr), size);
471}
472
473void *MmapFixedNoAccess(uptr fixed_addr, uptr size, const char *name) {
474 return (void *)MmapNamed(addr: (void *)fixed_addr, length: size, PROT_NONE,
475 MAP_PRIVATE | MAP_FIXED | MAP_NORESERVE | MAP_ANON,
476 name);
477}
478
479void *MmapNoAccess(uptr size) {
480 unsigned flags = MAP_PRIVATE | MAP_ANON | MAP_NORESERVE;
481 return (void *)internal_mmap(addr: nullptr, length: size, PROT_NONE, flags, fd: -1, offset: 0);
482}
483
484// This function is defined elsewhere if we intercepted pthread_attr_getstack.
485extern "C" {
486SANITIZER_WEAK_ATTRIBUTE int
487real_pthread_attr_getstack(void *attr, void **addr, size_t *size);
488} // extern "C"
489
490int internal_pthread_attr_getstack(void *attr, void **addr, uptr *size) {
491#if !SANITIZER_GO && !SANITIZER_APPLE
492 if (&real_pthread_attr_getstack)
493 return real_pthread_attr_getstack(attr: (pthread_attr_t *)attr, addr,
494 size: (size_t *)size);
495#endif
496 return pthread_attr_getstack(attr: (pthread_attr_t *)attr, stackaddr: addr, stacksize: (size_t *)size);
497}
498
499#if !SANITIZER_GO
500void AdjustStackSize(void *attr_) {
501 pthread_attr_t *attr = (pthread_attr_t *)attr_;
502 uptr stackaddr = 0;
503 uptr stacksize = 0;
504 internal_pthread_attr_getstack(attr, addr: (void **)&stackaddr, size: &stacksize);
505 // GLibC will return (0 - stacksize) as the stack address in the case when
506 // stacksize is set, but stackaddr is not.
507 bool stack_set = (stackaddr != 0) && (stackaddr + stacksize != 0);
508 // We place a lot of tool data into TLS, account for that.
509 const uptr minstacksize = GetTlsSize() + 128*1024;
510 if (stacksize < minstacksize) {
511 if (!stack_set) {
512 if (stacksize != 0) {
513 VPrintf(1, "Sanitizer: increasing stacksize %zu->%zu\n", stacksize,
514 minstacksize);
515 pthread_attr_setstacksize(attr: attr, stacksize: minstacksize);
516 }
517 } else {
518 Printf(format: "Sanitizer: pre-allocated stack size is insufficient: "
519 "%zu < %zu\n", stacksize, minstacksize);
520 Printf(format: "Sanitizer: pthread_create is likely to fail.\n");
521 }
522 }
523}
524#endif // !SANITIZER_GO
525
526pid_t StartSubprocess(const char *program, const char *const argv[],
527 const char *const envp[], fd_t stdin_fd, fd_t stdout_fd,
528 fd_t stderr_fd) {
529 auto file_closer = at_scope_exit(fn: [&] {
530 if (stdin_fd != kInvalidFd) {
531 internal_close(fd: stdin_fd);
532 }
533 if (stdout_fd != kInvalidFd) {
534 internal_close(fd: stdout_fd);
535 }
536 if (stderr_fd != kInvalidFd) {
537 internal_close(fd: stderr_fd);
538 }
539 });
540
541 int pid = internal_fork();
542
543 if (pid < 0) {
544 int rverrno;
545 if (internal_iserror(retval: pid, rverrno: &rverrno)) {
546 Report(format: "WARNING: failed to fork (errno %d)\n", rverrno);
547 }
548 return pid;
549 }
550
551 if (pid == 0) {
552 // Child subprocess
553 if (stdin_fd != kInvalidFd) {
554 internal_close(STDIN_FILENO);
555 internal_dup2(oldfd: stdin_fd, STDIN_FILENO);
556 internal_close(fd: stdin_fd);
557 }
558 if (stdout_fd != kInvalidFd) {
559 internal_close(STDOUT_FILENO);
560 internal_dup2(oldfd: stdout_fd, STDOUT_FILENO);
561 internal_close(fd: stdout_fd);
562 }
563 if (stderr_fd != kInvalidFd) {
564 internal_close(STDERR_FILENO);
565 internal_dup2(oldfd: stderr_fd, STDERR_FILENO);
566 internal_close(fd: stderr_fd);
567 }
568
569 // Close all fds except stdin/stdout/stderr before exec.
570 // Fallback to the loop if close_range is not supported.
571 if (internal_close_range(lowfd: 3, highfd: ~static_cast<fd_t>(0), flags: 0) != 0)
572 for (int fd = sysconf(_SC_OPEN_MAX); fd > 2; fd--) internal_close(fd);
573
574 internal_execve(filename: program, argv: const_cast<char **>(&argv[0]),
575 envp: const_cast<char *const *>(envp));
576 internal__exit(exitcode: 1);
577 }
578
579 return pid;
580}
581
582bool IsProcessRunning(pid_t pid) {
583 int process_status;
584 uptr waitpid_status = internal_waitpid(pid, status: &process_status, WNOHANG);
585 int local_errno;
586 if (internal_iserror(retval: waitpid_status, rverrno: &local_errno)) {
587 VReport(1, "Waiting on the process failed (errno %d).\n", local_errno);
588 return false;
589 }
590 return waitpid_status == 0;
591}
592
593int WaitForProcess(pid_t pid) {
594 int process_status;
595 uptr waitpid_status = internal_waitpid(pid, status: &process_status, options: 0);
596 int local_errno;
597 if (internal_iserror(retval: waitpid_status, rverrno: &local_errno)) {
598 VReport(1, "Waiting on the process failed (errno %d).\n", local_errno);
599 return -1;
600 }
601 return process_status;
602}
603
604bool IsStateDetached(int state) {
605 return state == PTHREAD_CREATE_DETACHED;
606}
607
608} // namespace __sanitizer
609
610#endif // SANITIZER_POSIX
611