[nolibc] Move libc-dependent sanitizer_posix.cc code to sanitizer_posix_libcdep.cc.

llvm-svn: 182366
This commit is contained in:
Peter Collingbourne 2013-05-21 10:27:07 +00:00
parent 3677b18388
commit 8575195772
4 changed files with 118 additions and 92 deletions

View File

@ -26,6 +26,7 @@ set(SANITIZER_SOURCES
set(SANITIZER_LIBCDEP_SOURCES
sanitizer_common_libcdep.cc
sanitizer_linux_libcdep.cc
sanitizer_posix_libcdep.cc
)
# Explicitly list all sanitizer_common headers. Not all of these are

View File

@ -20,17 +20,7 @@
#include "sanitizer_procmaps.h"
#include "sanitizer_stacktrace.h"
#include <errno.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
namespace __sanitizer {
@ -39,14 +29,6 @@ uptr GetMmapGranularity() {
return GetPageSize();
}
u32 GetUid() {
return getuid();
}
uptr GetThreadSelf() {
return (uptr)pthread_self();
}
void *MmapOrDie(uptr size, const char *mem_type) {
size = RoundUpTo(size, GetPageSizeCached());
uptr res = internal_mmap(0, size,
@ -119,10 +101,6 @@ void *Mprotect(uptr fixed_addr, uptr size) {
MAP_NORESERVE, -1, 0);
}
void FlushUnneededShadowMemory(uptr addr, uptr size) {
madvise((void*)addr, size, MADV_DONTNEED);
}
void *MapFileToMemory(const char *file_name, uptr *buff_size) {
uptr openrv = OpenFile(file_name, false);
CHECK(!internal_iserror(openrv));
@ -177,76 +155,6 @@ const char *GetPwd() {
return GetEnv("PWD");
}
void DisableCoreDumper() {
struct rlimit nocore;
nocore.rlim_cur = 0;
nocore.rlim_max = 0;
setrlimit(RLIMIT_CORE, &nocore);
}
bool StackSizeIsUnlimited() {
struct rlimit rlim;
CHECK_EQ(0, getrlimit(RLIMIT_STACK, &rlim));
return (rlim.rlim_cur == (uptr)-1);
}
void SetStackSizeLimitInBytes(uptr limit) {
struct rlimit rlim;
rlim.rlim_cur = limit;
rlim.rlim_max = limit;
if (setrlimit(RLIMIT_STACK, &rlim)) {
Report("ERROR: %s setrlimit() failed %d\n", SanitizerToolName, errno);
Die();
}
CHECK(!StackSizeIsUnlimited());
}
void SleepForSeconds(int seconds) {
sleep(seconds);
}
void SleepForMillis(int millis) {
usleep(millis * 1000);
}
void Abort() {
abort();
}
int Atexit(void (*function)(void)) {
#ifndef SANITIZER_GO
return atexit(function);
#else
return 0;
#endif
}
int internal_isatty(fd_t fd) {
return isatty(fd);
}
#ifndef SANITIZER_GO
void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp,
uptr stack_top, uptr stack_bottom, bool fast) {
#if !SANITIZER_CAN_FAST_UNWIND
fast = false;
#endif
#if SANITIZER_MAC
// Always unwind fast on Mac.
(void)fast;
#else
if (!fast || (stack_top == stack_bottom))
return stack->SlowUnwindStack(pc, max_s);
#endif // SANITIZER_MAC
stack->size = 0;
stack->trace[0] = pc;
if (max_s > 1) {
stack->max_size = max_s;
stack->FastUnwindStack(pc, bp, stack_top, stack_bottom);
}
}
#endif // SANITIZER_GO
} // namespace __sanitizer
#endif // SANITIZER_LINUX || SANITIZER_MAC

View File

@ -0,0 +1,116 @@
//===-- sanitizer_posix_libcdep.cc ----------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is shared between AddressSanitizer and ThreadSanitizer
// run-time libraries and implements libc-dependent POSIX-specific functions
// from sanitizer_libc.h.
//===----------------------------------------------------------------------===//
#include "sanitizer_platform.h"
#if SANITIZER_LINUX || SANITIZER_MAC
#include "sanitizer_common.h"
#include "sanitizer_stacktrace.h"
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
namespace __sanitizer {
u32 GetUid() {
return getuid();
}
uptr GetThreadSelf() {
return (uptr)pthread_self();
}
void FlushUnneededShadowMemory(uptr addr, uptr size) {
madvise((void*)addr, size, MADV_DONTNEED);
}
void DisableCoreDumper() {
struct rlimit nocore;
nocore.rlim_cur = 0;
nocore.rlim_max = 0;
setrlimit(RLIMIT_CORE, &nocore);
}
bool StackSizeIsUnlimited() {
struct rlimit rlim;
CHECK_EQ(0, getrlimit(RLIMIT_STACK, &rlim));
return (rlim.rlim_cur == (uptr)-1);
}
void SetStackSizeLimitInBytes(uptr limit) {
struct rlimit rlim;
rlim.rlim_cur = limit;
rlim.rlim_max = limit;
if (setrlimit(RLIMIT_STACK, &rlim)) {
Report("ERROR: %s setrlimit() failed %d\n", SanitizerToolName, errno);
Die();
}
CHECK(!StackSizeIsUnlimited());
}
void SleepForSeconds(int seconds) {
sleep(seconds);
}
void SleepForMillis(int millis) {
usleep(millis * 1000);
}
void Abort() {
abort();
}
int Atexit(void (*function)(void)) {
#ifndef SANITIZER_GO
return atexit(function);
#else
return 0;
#endif
}
int internal_isatty(fd_t fd) {
return isatty(fd);
}
#ifndef SANITIZER_GO
void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp,
uptr stack_top, uptr stack_bottom, bool fast) {
#if !SANITIZER_CAN_FAST_UNWIND
fast = false;
#endif
#if SANITIZER_MAC
// Always unwind fast on Mac.
(void)fast;
#else
if (!fast || (stack_top == stack_bottom))
return stack->SlowUnwindStack(pc, max_s);
#endif // SANITIZER_MAC
stack->size = 0;
stack->trace[0] = pc;
if (max_s > 1) {
stack->max_size = max_s;
stack->FastUnwindStack(pc, bp, stack_top, stack_bottom);
}
}
#endif // SANITIZER_GO
} // namespace __sanitizer
#endif

View File

@ -30,6 +30,7 @@ if [ "`uname -a | grep Linux`" != "" ]; then
SRCS+="
../rtl/tsan_platform_linux.cc
../../sanitizer_common/sanitizer_posix.cc
../../sanitizer_common/sanitizer_posix_libcdep.cc
../../sanitizer_common/sanitizer_linux.cc
../../sanitizer_common/sanitizer_linux_libcdep.cc
"