[llvm-commits] PATCH: AddressSanitizer: move interceptor of pthread_create to asan_posix.cc (issue 5648047)
samsonov at google.com
samsonov at google.com
Thu Feb 9 04:18:08 PST 2012
Reviewers: ramosian.glider, kcc,
Description:
AddressSanitizer: move interceptor of pthread_create to asan_posix.cc
Please review this at http://codereview.appspot.com/5648047/
Affected files:
M asan_interceptors.cc
M asan_internal.h
M asan_posix.cc
-------------- next part --------------
Index: asan_posix.cc
===================================================================
--- asan_posix.cc (revision 150171)
+++ asan_posix.cc (working copy)
@@ -16,6 +16,7 @@
#include "asan_internal.h"
#include "asan_interceptors.h"
#include "asan_stack.h"
+#include "asan_thread.h"
#include "asan_thread_registry.h"
#include <pthread.h>
@@ -113,6 +114,27 @@
pthread_setspecific(tsd_key, tsd);
}
+// ---------------------- Interceptors ---------------- {{{1
+static void *asan_thread_start(void *arg) {
+ AsanThread *t = (AsanThread*)arg;
+ asanThreadRegistry().SetCurrent(t);
+ return t->ThreadStart();
+}
+
+INTERCEPTOR(int, pthread_create, pthread_t *thread,
+ const pthread_attr_t *attr,
+ void *(*start_routine)(void*), void *arg) {
+ GET_STACK_TRACE_HERE(kStackTraceMax);
+ int current_tid = asanThreadRegistry().GetCurrentTidOrMinusOne();
+ AsanThread *t = AsanThread::Create(current_tid, start_routine, arg, &stack);
+ asanThreadRegistry().RegisterThread(t);
+ return REAL(pthread_create)(thread, attr, asan_thread_start, t);
+}
+
+void AsanInterceptThreadingRoutines() {
+ CHECK(INTERCEPT_FUNCTION(pthread_create));
+}
+
} // namespace __asan
#endif // __linux__ || __APPLE_
Index: asan_internal.h
===================================================================
--- asan_internal.h (revision 150171)
+++ asan_internal.h (working copy)
@@ -150,6 +150,9 @@
int SScanf(const char *str, const char *format, ...);
void Report(const char *format, ...);
+// Interception.
+void AsanInterceptThreadingRoutines();
+
// Don't use std::min and std::max, to minimize dependency on libstdc++.
template<class T> T Min(T a, T b) { return a < b ? a : b; }
template<class T> T Max(T a, T b) { return a > b ? a : b; }
Index: asan_interceptors.cc
===================================================================
--- asan_interceptors.cc (revision 150171)
+++ asan_interceptors.cc (working copy)
@@ -26,10 +26,6 @@
#include <new>
#include <ctype.h>
-#ifndef _WIN32
-#include <pthread.h>
-#endif // _WIN32
-
#if defined(__APPLE__)
// FIXME(samsonov): Gradually replace system headers with declarations of
// intercepted functions.
@@ -198,23 +194,7 @@
void operator delete[](void *ptr, std::nothrow_t const&) throw()
{ OPERATOR_DELETE_BODY;}
-static void *asan_thread_start(void *arg) {
- AsanThread *t = (AsanThread*)arg;
- asanThreadRegistry().SetCurrent(t);
- return t->ThreadStart();
-}
-
#ifndef _WIN32
-INTERCEPTOR(int, pthread_create, pthread_t *thread,
- const pthread_attr_t *attr,
- void *(*start_routine)(void*), void *arg) {
- GET_STACK_TRACE_HERE(kStackTraceMax);
- int current_tid = asanThreadRegistry().GetCurrentTidOrMinusOne();
- AsanThread *t = AsanThread::Create(current_tid, start_routine, arg, &stack);
- asanThreadRegistry().RegisterThread(t);
- return REAL(pthread_create)(thread, attr, asan_thread_start, t);
-}
-
INTERCEPTOR(void*, signal, int signum, void *handler) {
if (!AsanInterceptsSignal(signum)) {
return REAL(signal)(signum, handler);
@@ -557,8 +537,9 @@
CHECK(INTERCEPT_FUNCTION(longjmp));
CHECK(INTERCEPT_FUNCTION(_longjmp));
INTERCEPT_FUNCTION(__cxa_throw);
- CHECK(INTERCEPT_FUNCTION(pthread_create));
+ AsanInterceptThreadingRoutines();
+
#ifdef __APPLE__
CHECK(INTERCEPT_FUNCTION(dispatch_async_f));
CHECK(INTERCEPT_FUNCTION(dispatch_sync_f));
More information about the llvm-commits
mailing list