AddressSanitizer: get rid of stdlib.h and add (smaller) stddef.h instead

llvm-svn: 151162
This commit is contained in:
Alexey Samsonov 2012-02-22 14:07:06 +00:00
parent 36d297d27f
commit d6651509d0
5 changed files with 23 additions and 8 deletions

View File

@ -15,6 +15,10 @@
#ifndef ASAN_INTERFACE_H #ifndef ASAN_INTERFACE_H
#define ASAN_INTERFACE_H #define ASAN_INTERFACE_H
// ----------- ATTENTION -------------
// This header should NOT include any other headers from ASan runtime.
// All functions in this header are extern "C" and start with __asan_.
#if !defined(_WIN32) #if !defined(_WIN32)
#include <stdint.h> // for uintptr_t #include <stdint.h> // for uintptr_t
#define ASAN_INTERFACE_FUNCTION_ATTRIBUTE __attribute__((visibility("default"))) #define ASAN_INTERFACE_FUNCTION_ATTRIBUTE __attribute__((visibility("default")))
@ -22,10 +26,7 @@
// TODO(timurrrr): find out what we need on Windows. __declspec(dllexport) ? // TODO(timurrrr): find out what we need on Windows. __declspec(dllexport) ?
#define ASAN_INTERFACE_FUNCTION_ATTRIBUTE #define ASAN_INTERFACE_FUNCTION_ATTRIBUTE
#endif #endif
#include <stdlib.h> // for size_t #include <stddef.h> // for size_t
// This header should NOT include any other headers from ASan runtime.
// All functions in this header are extern "C" and start with __asan_.
extern "C" { extern "C" {
// This function should be called at the very beginning of the process, // This function should be called at the very beginning of the process,

View File

@ -18,7 +18,7 @@
# error "This operating system is not supported by AddressSanitizer" # error "This operating system is not supported by AddressSanitizer"
#endif #endif
#include <stdlib.h> // for size_t, uintptr_t, etc. #include <stddef.h> // for size_t, uintptr_t, etc.
#if defined(_WIN32) #if defined(_WIN32)
// There's no <stdint.h> in Visual Studio 9, so we have to define [u]int*_t. // There's no <stdint.h> in Visual Studio 9, so we have to define [u]int*_t.
@ -75,6 +75,8 @@ extern "C" void* _ReturnAddress(void);
# define INT64_MAX (__INT64_C(9223372036854775807)) # define INT64_MAX (__INT64_C(9223372036854775807))
# define UINT64_MAX (__UINT64_C(18446744073709551615)) # define UINT64_MAX (__UINT64_C(18446744073709551615))
#define ASAN_DEFAULT_FAILURE_EXITCODE 1
#if defined(__linux__) #if defined(__linux__)
# define ASAN_LINUX 1 # define ASAN_LINUX 1
#else #else
@ -229,6 +231,7 @@ enum LinkerInitialized { LINKER_INITIALIZED = 0 };
void AsanDie(); void AsanDie();
void SleepForSeconds(int seconds); void SleepForSeconds(int seconds);
void Exit(int exitcode); void Exit(int exitcode);
int Atexit(void (*function)(void));
#define CHECK(cond) do { if (!(cond)) { \ #define CHECK(cond) do { if (!(cond)) { \
CheckFailed(#cond, __FILE__, __LINE__); \ CheckFailed(#cond, __FILE__, __LINE__); \

View File

@ -21,6 +21,7 @@
#include <pthread.h> #include <pthread.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <unistd.h> #include <unistd.h>
@ -99,6 +100,10 @@ void Exit(int exitcode) {
return _exit(exitcode); return _exit(exitcode);
} }
int Atexit(void (*function)(void)) {
return atexit(function);
}
int AtomicInc(int *a) { int AtomicInc(int *a) {
#ifdef ANDROID #ifdef ANDROID
return __atomic_inc(a) + 1; return __atomic_inc(a) + 1;

View File

@ -44,7 +44,7 @@ bool FLAG_replace_intrin;
bool FLAG_replace_cfallocator; // Used on Mac only. bool FLAG_replace_cfallocator; // Used on Mac only.
size_t FLAG_max_malloc_fill_size = 0; size_t FLAG_max_malloc_fill_size = 0;
bool FLAG_use_fake_stack; bool FLAG_use_fake_stack;
int FLAG_exitcode = EXIT_FAILURE; int FLAG_exitcode = ASAN_DEFAULT_FAILURE_EXITCODE;
bool FLAG_allow_user_poisoning; bool FLAG_allow_user_poisoning;
int FLAG_sleep_before_dying; int FLAG_sleep_before_dying;
@ -433,13 +433,14 @@ void __asan_init() {
FLAG_replace_str = IntFlagValue(options, "replace_str=", 1); FLAG_replace_str = IntFlagValue(options, "replace_str=", 1);
FLAG_replace_intrin = IntFlagValue(options, "replace_intrin=", 1); FLAG_replace_intrin = IntFlagValue(options, "replace_intrin=", 1);
FLAG_use_fake_stack = IntFlagValue(options, "use_fake_stack=", 1); FLAG_use_fake_stack = IntFlagValue(options, "use_fake_stack=", 1);
FLAG_exitcode = IntFlagValue(options, "exitcode=", EXIT_FAILURE); FLAG_exitcode = IntFlagValue(options, "exitcode=",
ASAN_DEFAULT_FAILURE_EXITCODE);
FLAG_allow_user_poisoning = IntFlagValue(options, FLAG_allow_user_poisoning = IntFlagValue(options,
"allow_user_poisoning=", 1); "allow_user_poisoning=", 1);
FLAG_sleep_before_dying = IntFlagValue(options, "sleep_before_dying=", 0); FLAG_sleep_before_dying = IntFlagValue(options, "sleep_before_dying=", 0);
if (FLAG_atexit) { if (FLAG_atexit) {
atexit(asan_atexit); Atexit(asan_atexit);
} }
// interceptors // interceptors

View File

@ -16,6 +16,7 @@
#include <dbghelp.h> #include <dbghelp.h>
#include <stdio.h> // FIXME: get rid of this. #include <stdio.h> // FIXME: get rid of this.
#include <stdlib.h>
#include <new> // FIXME: temporarily needed for placement new in AsanLock. #include <new> // FIXME: temporarily needed for placement new in AsanLock.
@ -262,6 +263,10 @@ void Exit(int exitcode) {
_exit(exitcode); _exit(exitcode);
} }
int Atexit(void (*function)(void)) {
return atexit(function);
}
} // namespace __asan } // namespace __asan
#endif // _WIN32 #endif // _WIN32