summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-06-15 06:37:34 +0000
committerAlexey Samsonov <samsonov@google.com>2012-06-15 06:37:34 +0000
commitfa3daaf1d66314658e7c05bf63dc825d179f2faf (patch)
tree86095d8bcdf4f5dc78408116b3cc928e576bff89 /lib
parentbe7420cc79d8580eb354666eef638d39ee9cff80 (diff)
downloadcompiler-rt-fa3daaf1d66314658e7c05bf63dc825d179f2faf.tar.gz
[Sanitizer] move more portability wrappers to common runtime: sleep, _exit, abort, atexit, pthread_self
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@158493 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/asan/asan_internal.h6
-rw-r--r--lib/asan/asan_posix.cc20
-rw-r--r--lib/asan/asan_thread_registry.cc1
-rw-r--r--lib/asan/asan_win.cc21
-rw-r--r--lib/sanitizer_common/sanitizer_common.h5
-rw-r--r--lib/sanitizer_common/sanitizer_posix.cc22
-rw-r--r--lib/sanitizer_common/sanitizer_win.cc21
7 files changed, 49 insertions, 47 deletions
diff --git a/lib/asan/asan_internal.h b/lib/asan/asan_internal.h
index f2663f0cd..128c83d85 100644
--- a/lib/asan/asan_internal.h
+++ b/lib/asan/asan_internal.h
@@ -129,7 +129,6 @@ bool AsanInterceptsSignal(int signum);
void SetAlternateSignalStack();
void UnsetAlternateSignalStack();
void InstallSignalHandlers();
-uptr GetThreadSelf();
int AtomicInc(int *a);
u16 AtomicExchange(u16 *a, u16 new_val);
u8 AtomicExchange(u8 *a, u8 new_val);
@@ -200,11 +199,6 @@ extern void (*death_callback)(void);
enum LinkerInitialized { LINKER_INITIALIZED = 0 };
-void SleepForSeconds(int seconds);
-void NORETURN Exit(int exitcode);
-void NORETURN Abort();
-int Atexit(void (*function)(void));
-
#define ASAN_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
#if !defined(_WIN32) || defined(__clang__)
diff --git a/lib/asan/asan_posix.cc b/lib/asan/asan_posix.cc
index 429f58a75..06161c23f 100644
--- a/lib/asan/asan_posix.cc
+++ b/lib/asan/asan_posix.cc
@@ -134,26 +134,6 @@ void InstallSignalHandlers() {
MaybeInstallSigaction(SIGBUS, ASAN_OnSIGSEGV);
}
-uptr GetThreadSelf() {
- return (uptr)pthread_self();
-}
-
-void SleepForSeconds(int seconds) {
- sleep(seconds);
-}
-
-void Exit(int exitcode) {
- _exit(exitcode);
-}
-
-void Abort() {
- abort();
-}
-
-int Atexit(void (*function)(void)) {
- return atexit(function);
-}
-
int AtomicInc(int *a) {
#ifdef ANDROID
return __atomic_inc(a) + 1;
diff --git a/lib/asan/asan_thread_registry.cc b/lib/asan/asan_thread_registry.cc
index 817f15d86..444900d42 100644
--- a/lib/asan/asan_thread_registry.cc
+++ b/lib/asan/asan_thread_registry.cc
@@ -16,6 +16,7 @@
#include "asan_stack.h"
#include "asan_thread.h"
#include "asan_thread_registry.h"
+#include "sanitizer_common/sanitizer_common.h"
namespace __asan {
diff --git a/lib/asan/asan_win.cc b/lib/asan/asan_win.cc
index b9034ca09..83bd0f4e5 100644
--- a/lib/asan/asan_win.cc
+++ b/lib/asan/asan_win.cc
@@ -192,10 +192,6 @@ u8 AtomicExchange(u8 *a, u8 new_val) {
return t;
}
-uptr GetThreadSelf() {
- return GetCurrentThreadId();
-}
-
void SetAlternateSignalStack() {
// FIXME: Decide what to do on Windows.
}
@@ -208,23 +204,6 @@ void InstallSignalHandlers() {
// FIXME: Decide what to do on Windows.
}
-void SleepForSeconds(int seconds) {
- Sleep(seconds * 1000);
-}
-
-void Exit(int exitcode) {
- _exit(exitcode);
-}
-
-void Abort() {
- abort();
- _exit(-1); // abort is not NORETURN on Windows.
-}
-
-int Atexit(void (*function)(void)) {
- return atexit(function);
-}
-
void SortArray(uptr *array, uptr size) {
std::sort(array, array + size);
}
diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h
index 0b40424c7..2f913a9aa 100644
--- a/lib/sanitizer_common/sanitizer_common.h
+++ b/lib/sanitizer_common/sanitizer_common.h
@@ -28,6 +28,7 @@ const uptr kPageSize = 1UL << kPageSizeBits;
// Threads
int GetPid();
+uptr GetThreadSelf();
void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
uptr *stack_bottom);
@@ -58,6 +59,10 @@ const char *GetEnv(const char *name);
// Other
void DisableCoreDumper();
void DumpProcessMap();
+void SleepForSeconds(int seconds);
+void NORETURN Exit(int exitcode);
+void NORETURN Abort();
+int Atexit(void (*function)(void));
// Bit twiddling.
inline bool IsPowerOfTwo(uptr x) {
diff --git a/lib/sanitizer_common/sanitizer_posix.cc b/lib/sanitizer_common/sanitizer_posix.cc
index 8d6ec336a..a72d3bdec 100644
--- a/lib/sanitizer_common/sanitizer_posix.cc
+++ b/lib/sanitizer_common/sanitizer_posix.cc
@@ -17,8 +17,10 @@
#include "sanitizer_libc.h"
#include "sanitizer_procmaps.h"
+#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/time.h>
@@ -33,6 +35,10 @@ int GetPid() {
return getpid();
}
+uptr GetThreadSelf() {
+ return (uptr)pthread_self();
+}
+
void *MmapOrDie(uptr size, const char *mem_type) {
size = RoundUpTo(size, kPageSize);
void *res = internal_mmap(0, size,
@@ -90,6 +96,22 @@ void DisableCoreDumper() {
setrlimit(RLIMIT_CORE, &nocore);
}
+void SleepForSeconds(int seconds) {
+ sleep(seconds);
+}
+
+void Exit(int exitcode) {
+ _exit(exitcode);
+}
+
+void Abort() {
+ abort();
+}
+
+int Atexit(void (*function)(void)) {
+ return atexit(function);
+}
+
// -------------- sanitizer_libc.h
int internal_sscanf(const char *str, const char *format, ...) {
diff --git a/lib/sanitizer_common/sanitizer_win.cc b/lib/sanitizer_common/sanitizer_win.cc
index a8c43ca4a..465a78da4 100644
--- a/lib/sanitizer_common/sanitizer_win.cc
+++ b/lib/sanitizer_common/sanitizer_win.cc
@@ -24,6 +24,10 @@ int GetPid() {
return GetProcessId(GetCurrentProcess());
}
+uptr GetThreadSelf() {
+ return GetCurrentThreadId();
+}
+
void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
uptr *stack_bottom) {
CHECK(stack_top);
@@ -90,6 +94,23 @@ void DisableCoreDumper() {
UNIMPLEMENTED();
}
+void SleepForSeconds(int seconds) {
+ Sleep(seconds * 1000);
+}
+
+void Exit(int exitcode) {
+ _exit(exitcode);
+}
+
+void Abort() {
+ abort();
+ _exit(-1); // abort is not NORETURN on Windows.
+}
+
+int Atexit(void (*function)(void)) {
+ return atexit(function);
+}
+
// ------------------ sanitizer_libc.h
void *internal_mmap(void *addr, uptr length, int prot, int flags,
int fd, u64 offset) {