* include/bits/allocator.h (operator==, operator!=): Add exception
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_posix_libcdep.cc
blobae782ac39cbc0c673d3d1aa01696329f868562ed
1 //===-- sanitizer_posix_libcdep.cc ----------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is shared between AddressSanitizer and ThreadSanitizer
9 // run-time libraries and implements libc-dependent POSIX-specific functions
10 // from sanitizer_libc.h.
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_platform.h"
15 #if SANITIZER_LINUX || SANITIZER_MAC
16 #include "sanitizer_common.h"
17 #include "sanitizer_stacktrace.h"
19 #include <errno.h>
20 #include <pthread.h>
21 #include <stdlib.h>
22 #include <sys/mman.h>
23 #include <sys/resource.h>
24 #include <sys/time.h>
25 #include <sys/types.h>
26 #include <unistd.h>
28 namespace __sanitizer {
30 u32 GetUid() {
31 return getuid();
34 uptr GetThreadSelf() {
35 return (uptr)pthread_self();
38 void FlushUnneededShadowMemory(uptr addr, uptr size) {
39 madvise((void*)addr, size, MADV_DONTNEED);
42 void DisableCoreDumper() {
43 struct rlimit nocore;
44 nocore.rlim_cur = 0;
45 nocore.rlim_max = 0;
46 setrlimit(RLIMIT_CORE, &nocore);
49 bool StackSizeIsUnlimited() {
50 struct rlimit rlim;
51 CHECK_EQ(0, getrlimit(RLIMIT_STACK, &rlim));
52 return (rlim.rlim_cur == (uptr)-1);
55 void SetStackSizeLimitInBytes(uptr limit) {
56 struct rlimit rlim;
57 rlim.rlim_cur = limit;
58 rlim.rlim_max = limit;
59 if (setrlimit(RLIMIT_STACK, &rlim)) {
60 Report("ERROR: %s setrlimit() failed %d\n", SanitizerToolName, errno);
61 Die();
63 CHECK(!StackSizeIsUnlimited());
66 void SleepForSeconds(int seconds) {
67 sleep(seconds);
70 void SleepForMillis(int millis) {
71 usleep(millis * 1000);
74 void Abort() {
75 abort();
78 int Atexit(void (*function)(void)) {
79 #ifndef SANITIZER_GO
80 return atexit(function);
81 #else
82 return 0;
83 #endif
86 int internal_isatty(fd_t fd) {
87 return isatty(fd);
90 } // namespace __sanitizer
92 #endif