1 //===-- sanitizer_posix_libcdep.cc ----------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
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"
23 #include <sys/resource.h>
25 #include <sys/types.h>
28 namespace __sanitizer
{
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() {
46 setrlimit(RLIMIT_CORE
, &nocore
);
49 bool StackSizeIsUnlimited() {
51 CHECK_EQ(0, getrlimit(RLIMIT_STACK
, &rlim
));
52 return (rlim
.rlim_cur
== (uptr
)-1);
55 void SetStackSizeLimitInBytes(uptr limit
) {
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
);
63 CHECK(!StackSizeIsUnlimited());
66 void SleepForSeconds(int seconds
) {
70 void SleepForMillis(int millis
) {
71 usleep(millis
* 1000);
78 int Atexit(void (*function
)(void)) {
80 return atexit(function
);
86 int internal_isatty(fd_t fd
) {
90 } // namespace __sanitizer