[llvm-commits] [compiler-rt] r147321 - /compiler-rt/trunk/lib/asan/asan_thread.cc
Kostya Serebryany
kcc at google.com
Wed Dec 28 12:34:30 PST 2011
Author: kcc
Date: Wed Dec 28 14:34:30 2011
New Revision: 147321
URL: http://llvm.org/viewvc/llvm-project?rev=147321&view=rev
Log:
[asan] discover main thread stack limits without pthread. patch by eugeni.stepanov at gmail.com
Modified:
compiler-rt/trunk/lib/asan/asan_thread.cc
Modified: compiler-rt/trunk/lib/asan/asan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.cc?rev=147321&r1=147320&r2=147321&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.cc Wed Dec 28 14:34:30 2011
@@ -17,7 +17,13 @@
#include "asan_thread_registry.h"
#include "asan_mapping.h"
+#if ASAN_USE_SYSINFO == 1
+#include "sysinfo/sysinfo.h"
+#endif
+
#include <sys/mman.h>
+#include <sys/time.h>
+#include <sys/resource.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
@@ -121,6 +127,36 @@
int local;
CHECK(AddrIsInStack((uintptr_t)&local));
#else
+#if ASAN_USE_SYSINFO == 1
+ if (tid() == 0) {
+ // This is the main thread. Libpthread may not be initialized yet.
+ struct rlimit rl;
+ CHECK(getrlimit(RLIMIT_STACK, &rl) == 0);
+
+ // Find the mapping that contains a stack variable.
+ ProcMapsIterator it(0);
+ uint64_t start, end;
+ uint64_t prev_end = 0;
+ while (it.Next(&start, &end, NULL, NULL, NULL, NULL)) {
+ if ((uintptr_t)&rl < end)
+ break;
+ prev_end = end;
+ }
+ CHECK((uintptr_t)&rl >= start && (uintptr_t)&rl < end);
+
+ // Get stacksize from rlimit, but clip it so that it does not overlap
+ // with other mappings.
+ size_t stacksize = rl.rlim_cur;
+ if (stacksize > end - prev_end)
+ stacksize = end - prev_end;
+ if (stacksize > kMaxThreadStackSize)
+ stacksize = kMaxThreadStackSize;
+ stack_top_ = end;
+ stack_bottom_ = end - stacksize;
+ CHECK(AddrIsInStack((uintptr_t)&rl));
+ return;
+ }
+#endif
pthread_attr_t attr;
CHECK(pthread_getattr_np(pthread_self(), &attr) == 0);
size_t stacksize = 0;
More information about the llvm-commits
mailing list