From aadd1f2ad65712a974a1c49997c47adb23e3809d Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Wed, 20 Feb 2013 13:54:32 +0000 Subject: [PATCH] [Sanitizer] use raw syscall instead of _exit() function on Linux llvm-svn: 175622 --- compiler-rt/lib/asan/asan_report.cc | 4 ++-- compiler-rt/lib/asan/asan_rtl.cc | 2 +- compiler-rt/lib/sanitizer_common/sanitizer_common.cc | 2 +- compiler-rt/lib/sanitizer_common/sanitizer_common.h | 1 - compiler-rt/lib/sanitizer_common/sanitizer_libc.h | 6 ++++-- compiler-rt/lib/sanitizer_common/sanitizer_linux.cc | 5 +++++ compiler-rt/lib/sanitizer_common/sanitizer_mac.cc | 4 ++++ compiler-rt/lib/sanitizer_common/sanitizer_posix.cc | 4 ---- compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_linux.cc | 2 +- compiler-rt/lib/sanitizer_common/sanitizer_win.cc | 8 ++++---- 10 files changed, 22 insertions(+), 16 deletions(-) diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index 32252cb..8fa42f7 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/lib/asan/asan_report.cc @@ -435,9 +435,9 @@ class ScopedInErrorReport { // an error report will finish doing it. SleepForSeconds(Max(100, flags()->sleep_before_dying + 1)); } - // If we're still not dead for some reason, use raw Exit() instead of + // If we're still not dead for some reason, use raw _exit() instead of // Die() to bypass any additional checks. - Exit(flags()->exitcode); + internal__exit(flags()->exitcode); } ASAN_ON_ERROR(); reporting_thread_tid = asanThreadRegistry().GetCurrentTidOrInvalid(); diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 39b722a..ad97c77 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -51,7 +51,7 @@ static void AsanDie() { death_callback(); if (flags()->abort_on_error) Abort(); - Exit(flags()->exitcode); + internal__exit(flags()->exitcode); } static void AsanCheckFailed(const char *file, int line, const char *cond, diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 8f95d2b..0518f41 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -45,7 +45,7 @@ void NORETURN Die() { if (DieCallback) { DieCallback(); } - Exit(1); + internal__exit(1); } static CheckFailedCallbackType CheckFailedCallback; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 7816306..fafef40 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -140,7 +140,6 @@ void SortArray(uptr *array, uptr size); // Exit void NORETURN Abort(); -void NORETURN Exit(int exitcode); void NORETURN Die(); void NORETURN SANITIZER_INTERFACE_ATTRIBUTE CheckFailed(const char *file, int line, const char *cond, u64 v1, u64 v2); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h index 6bdca3c..d4e954c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h @@ -45,6 +45,7 @@ char *internal_strrchr(const char *s, int c); char *internal_strstr(const char *haystack, const char *needle); // Works only for base=10 and doesn't set errno. s64 internal_simple_strtoll(const char *nptr, char **endptr, int base); +int internal_snprintf(char *buffer, uptr length, const char *format, ...); // Return true if all bytes in [mem, mem+size) are zero. // Optimized for the case when the result is true. @@ -70,14 +71,15 @@ fd_t internal_open(const char *filename, int flags, u32 mode); uptr internal_read(fd_t fd, void *buf, uptr count); uptr internal_write(fd_t fd, const void *buf, uptr count); + +// OS uptr internal_filesize(fd_t fd); // -1 on error. int internal_stat(const char *path, void *buf); int internal_lstat(const char *path, void *buf); int internal_fstat(fd_t fd, void *buf); - int internal_dup2(int oldfd, int newfd); uptr internal_readlink(const char *path, char *buf, uptr bufsize); -int internal_snprintf(char *buffer, uptr length, const char *format, ...); +void NORETURN internal__exit(int exitcode); // Threading int internal_sched_yield(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc index 1f3d68e..11cec22 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc @@ -140,6 +140,11 @@ int internal_sched_yield() { return syscall(__NR_sched_yield); } +void internal__exit(int exitcode) { + syscall(__NR_exit_group, exitcode); + Die(); // Unreachable. +} + // ----------------- sanitizer_common.h bool FileExists(const char *filename) { #if SANITIZER_LINUX_USES_64BIT_SYSCALLS diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc index 2c5bd52..7851721 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc @@ -106,6 +106,10 @@ int internal_sched_yield() { return sched_yield(); } +void internal__exit(int exitcode) { + _exit(exitcode); +} + // ----------------- sanitizer_common.h bool FileExists(const char *filename) { struct stat st; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc index d072025..001ca75 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc @@ -209,10 +209,6 @@ void SleepForMillis(int millis) { usleep(millis * 1000); } -void Exit(int exitcode) { - _exit(exitcode); -} - void Abort() { abort(); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_linux.cc index 4bd3dc8..c068839 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_linux.cc @@ -99,7 +99,7 @@ bool StartSymbolizerSubprocess(const char *path_to_symbolizer, for (int fd = getdtablesize(); fd > 2; fd--) internal_close(fd); execl(path_to_symbolizer, path_to_symbolizer, (char*)0); - Exit(1); + internal__exit(1); } // Continue execution in parent process. diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc index 4fe3ece..40af4e3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc @@ -167,10 +167,6 @@ void SleepForMillis(int millis) { Sleep(millis); } -void Exit(int exitcode) { - _exit(exitcode); -} - void Abort() { abort(); _exit(-1); // abort is not NORETURN on Windows. @@ -257,6 +253,10 @@ int internal_sched_yield() { return 0; } +void internal__exit(int exitcode) { + _exit(exitcode); +} + // ---------------------- BlockingMutex ---------------- {{{1 const uptr LOCK_UNINITIALIZED = 0; const uptr LOCK_READY = (uptr)-1; -- 2.7.4