forked from OSchip/llvm-project
[sanitizer] Move GetTlsSize code from TSan to sanitizer_common.
llvm-svn: 176938
This commit is contained in:
parent
24aad9c0cb
commit
5697b58ec4
|
@ -133,6 +133,9 @@ bool StackSizeIsUnlimited();
|
|||
void SetStackSizeLimitInBytes(uptr limit);
|
||||
void PrepareForSandboxing();
|
||||
|
||||
void InitTlsSize();
|
||||
uptr GetTlsSize();
|
||||
|
||||
// Other
|
||||
void SleepForSeconds(int seconds);
|
||||
void SleepForMillis(int millis);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "sanitizer_procmaps.h"
|
||||
#include "sanitizer_stacktrace.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
@ -673,6 +674,34 @@ bool ThreadLister::GetDirectoryEntries() {
|
|||
return true;
|
||||
}
|
||||
|
||||
static uptr g_tls_size;
|
||||
|
||||
#ifdef __i386__
|
||||
# define DL_INTERNAL_FUNCTION __attribute__((regparm(3), stdcall))
|
||||
#else
|
||||
# define DL_INTERNAL_FUNCTION
|
||||
#endif
|
||||
|
||||
void InitTlsSize() {
|
||||
#ifndef SANITIZER_GO
|
||||
typedef void (*get_tls_func)(size_t*, size_t*) DL_INTERNAL_FUNCTION;
|
||||
get_tls_func get_tls;
|
||||
void *get_tls_static_info_ptr = dlsym(RTLD_NEXT, "_dl_get_tls_static_info");
|
||||
CHECK_EQ(sizeof(get_tls), sizeof(get_tls_static_info_ptr));
|
||||
internal_memcpy(&get_tls, &get_tls_static_info_ptr,
|
||||
sizeof(get_tls_static_info_ptr));
|
||||
CHECK_NE(get_tls, 0);
|
||||
size_t tls_size = 0;
|
||||
size_t tls_align = 0;
|
||||
get_tls(&tls_size, &tls_align);
|
||||
g_tls_size = tls_size;
|
||||
#endif
|
||||
}
|
||||
|
||||
uptr GetTlsSize() {
|
||||
return g_tls_size;
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // __linux__
|
||||
|
|
|
@ -326,6 +326,13 @@ void BlockingMutex::CheckLocked() {
|
|||
CHECK_EQ((uptr)pthread_self(), owner_);
|
||||
}
|
||||
|
||||
uptr GetTlsSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InitTlsSize() {
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // __APPLE__
|
||||
|
|
|
@ -295,6 +295,13 @@ void BlockingMutex::CheckLocked() {
|
|||
CHECK_EQ(owner_, GetThreadSelf());
|
||||
}
|
||||
|
||||
uptr GetTlsSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InitTlsSize() {
|
||||
}
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // _WIN32
|
||||
|
|
|
@ -56,7 +56,7 @@ macro(add_sanitizer_tests_for_arch arch)
|
|||
-I${COMPILER_RT_SOURCE_DIR}/lib
|
||||
-I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common
|
||||
-O2 -g -Wall -Werror ${TARGET_FLAGS})
|
||||
set(SANITIZER_TEST_LINK_FLAGS -lstdc++ -lpthread ${TARGET_FLAGS})
|
||||
set(SANITIZER_TEST_LINK_FLAGS -lstdc++ -lpthread -ldl ${TARGET_FLAGS})
|
||||
set(SANITIZER_TEST_OBJECTS)
|
||||
foreach(source ${SANITIZER_TEST_SOURCES})
|
||||
get_filename_component(basename ${source} NAME)
|
||||
|
|
|
@ -148,7 +148,6 @@ void internal_start_thread(void(*func)(void*), void *arg);
|
|||
// Says whether the addr relates to a global var.
|
||||
// Guesses with high probability, may yield both false positives and negatives.
|
||||
bool IsGlobalVar(uptr addr);
|
||||
uptr GetTlsSize();
|
||||
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
|
||||
uptr *tls_addr, uptr *tls_size);
|
||||
int ExtractResolvFDs(void *state, int *fds, int nfd);
|
||||
|
|
|
@ -167,27 +167,6 @@ static void InitDataSeg() {
|
|||
CHECK_LT((uptr)&g_data_start, g_data_end);
|
||||
}
|
||||
|
||||
static uptr g_tls_size;
|
||||
|
||||
#ifdef __i386__
|
||||
# define INTERNAL_FUNCTION __attribute__((regparm(3), stdcall))
|
||||
#else
|
||||
# define INTERNAL_FUNCTION
|
||||
#endif
|
||||
|
||||
static int InitTlsSize() {
|
||||
typedef void (*get_tls_func)(size_t*, size_t*) INTERNAL_FUNCTION;
|
||||
get_tls_func get_tls;
|
||||
void *get_tls_static_info_ptr = dlsym(RTLD_NEXT, "_dl_get_tls_static_info");
|
||||
CHECK_EQ(sizeof(get_tls), sizeof(get_tls_static_info_ptr));
|
||||
internal_memcpy(&get_tls, &get_tls_static_info_ptr,
|
||||
sizeof(get_tls_static_info_ptr));
|
||||
CHECK_NE(get_tls, 0);
|
||||
size_t tls_size = 0;
|
||||
size_t tls_align = 0;
|
||||
get_tls(&tls_size, &tls_align);
|
||||
return tls_size;
|
||||
}
|
||||
#endif // #ifndef TSAN_GO
|
||||
|
||||
static rlim_t getlim(int res) {
|
||||
|
@ -242,7 +221,7 @@ const char *InitializePlatform() {
|
|||
|
||||
#ifndef TSAN_GO
|
||||
CheckPIE();
|
||||
g_tls_size = (uptr)InitTlsSize();
|
||||
InitTlsSize();
|
||||
InitDataSeg();
|
||||
#endif
|
||||
return GetEnv(kTsanOptionsEnv);
|
||||
|
@ -252,20 +231,12 @@ void FinalizePlatform() {
|
|||
fflush(0);
|
||||
}
|
||||
|
||||
uptr GetTlsSize() {
|
||||
#ifndef TSAN_GO
|
||||
return g_tls_size;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
|
||||
uptr *tls_addr, uptr *tls_size) {
|
||||
#ifndef TSAN_GO
|
||||
arch_prctl(ARCH_GET_FS, tls_addr);
|
||||
*tls_addr -= g_tls_size;
|
||||
*tls_size = g_tls_size;
|
||||
*tls_size = GetTlsSize();
|
||||
*tls_addr -= *tls_size;
|
||||
|
||||
uptr stack_top, stack_bottom;
|
||||
GetThreadStackTopAndBottom(main, &stack_top, &stack_bottom);
|
||||
|
|
|
@ -89,10 +89,6 @@ void FinalizePlatform() {
|
|||
fflush(0);
|
||||
}
|
||||
|
||||
uptr GetTlsSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
|
||||
uptr *tls_addr, uptr *tls_size) {
|
||||
*stk_addr = 0;
|
||||
|
|
|
@ -41,10 +41,6 @@ void FinalizePlatform() {
|
|||
fflush(0);
|
||||
}
|
||||
|
||||
uptr GetTlsSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
|
||||
uptr *tls_addr, uptr *tls_size) {
|
||||
*stk_addr = 0;
|
||||
|
|
Loading…
Reference in New Issue