[llvm-commits] [compiler-rt] r158451 - in /compiler-rt/trunk/lib: asan/asan_internal.h asan/asan_linux.cc asan/asan_mac.cc asan/asan_rtl.cc asan/asan_win.cc sanitizer_common/sanitizer_common.h sanitizer_common/sanitizer_linux.cc sanitizer_common/sanitizer_mac.cc sanitizer_common/sanitizer_win.cc
Alexey Samsonov
samsonov at google.com
Thu Jun 14 07:07:22 PDT 2012
Author: samsonov
Date: Thu Jun 14 09:07:21 2012
New Revision: 158451
URL: http://llvm.org/viewvc/llvm-project?rev=158451&view=rev
Log:
[Sanitizer] move portable GetEnv to common sanitizer runtime
Modified:
compiler-rt/trunk/lib/asan/asan_internal.h
compiler-rt/trunk/lib/asan/asan_linux.cc
compiler-rt/trunk/lib/asan/asan_mac.cc
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/lib/asan/asan_win.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=158451&r1=158450&r2=158451&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Thu Jun 14 09:07:21 2012
@@ -122,7 +122,6 @@
// asan_linux.cc / asan_mac.cc / asan_win.cc
void *AsanDoesNotSupportStaticLinkage();
bool AsanShadowRangeIsAvailable();
-const char *AsanGetEnv(const char *name);
void AsanDumpProcessMap();
void *AsanMmapFixedNoReserve(uptr fixed_addr, uptr size);
Modified: compiler-rt/trunk/lib/asan/asan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_linux.cc?rev=158451&r1=158450&r2=158451&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_linux.cc Thu Jun 14 09:07:21 2012
@@ -86,34 +86,6 @@
0, 0);
}
-// Like getenv, but reads env directly from /proc and does not use libc.
-// This function should be called first inside __asan_init.
-const char* AsanGetEnv(const char* name) {
- static char *environ;
- static uptr len;
- static bool inited;
- if (!inited) {
- inited = true;
- uptr environ_size;
- len = ReadFileToBuffer("/proc/self/environ",
- &environ, &environ_size, 1 << 26);
- }
- if (!environ || len == 0) return 0;
- uptr namelen = internal_strlen(name);
- const char *p = environ;
- while (*p != '\0') { // will happen at the \0\0 that terminates the buffer
- // proc file has the format NAME=value\0NAME=value\0NAME=value\0...
- const char* endp =
- (char*)internal_memchr(p, '\0', len - (p - environ));
- if (endp == 0) // this entry isn't NUL terminated
- return 0;
- else if (!internal_memcmp(p, name, namelen) && p[namelen] == '=') // Match.
- return p + namelen + 1; // point after =
- p = endp + 1;
- }
- return 0; // Not found.
-}
-
AsanLock::AsanLock(LinkerInitialized) {
// We assume that pthread_mutex_t initialized to all zeroes is a valid
// unlocked mutex. We can not use PTHREAD_MUTEX_INITIALIZER as it triggers
Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=158451&r1=158450&r2=158451&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Thu Jun 14 09:07:21 2012
@@ -111,26 +111,6 @@
0, 0);
}
-const char *AsanGetEnv(const char *name) {
- char ***env_ptr = _NSGetEnviron();
- CHECK(env_ptr);
- char **environ = *env_ptr;
- CHECK(environ);
- uptr name_len = internal_strlen(name);
- while (*environ != 0) {
- uptr len = internal_strlen(*environ);
- if (len > name_len) {
- const char *p = *environ;
- if (!internal_memcmp(p, name, name_len) &&
- p[name_len] == '=') { // Match.
- return *environ + name_len + 1; // String starting after =.
- }
- }
- environ++;
- }
- return 0;
-}
-
AsanLock::AsanLock(LinkerInitialized) {
// We assume that OS_SPINLOCK_INIT is zero
}
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=158451&r1=158450&r2=158451&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Thu Jun 14 09:07:21 2012
@@ -493,7 +493,7 @@
}
#endif
// flags
- const char *options = AsanGetEnv("ASAN_OPTIONS");
+ const char *options = GetEnv("ASAN_OPTIONS");
ParseAsanOptions(options);
if (FLAG_v && options) {
Modified: compiler-rt/trunk/lib/asan/asan_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_win.cc?rev=158451&r1=158450&r2=158451&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_win.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_win.cc Thu Jun 14 09:07:21 2012
@@ -203,22 +203,6 @@
return t;
}
-const char* AsanGetEnv(const char* name) {
- static char env_buffer[32767] = {};
-
- // Note: this implementation stores the result in a static buffer so we only
- // allow it to be called just once.
- static bool called_once = false;
- if (called_once)
- UNIMPLEMENTED();
- called_once = true;
-
- DWORD rv = GetEnvironmentVariableA(name, env_buffer, sizeof(env_buffer));
- if (rv > 0 && rv < sizeof(env_buffer))
- return env_buffer;
- return 0;
-}
-
void AsanDumpProcessMap() {
UNIMPLEMENTED();
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=158451&r1=158450&r2=158451&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Thu Jun 14 09:07:21 2012
@@ -48,6 +48,7 @@
// Returns the number of read bytes or 0 if file can not be opened.
uptr ReadFileToBuffer(const char *file_name, char **buff,
uptr *buff_size, uptr max_len);
+const char *GetEnv(const char *name);
// Bit twiddling.
inline bool IsPowerOfTwo(uptr x) {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=158451&r1=158450&r2=158451&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu Jun 14 09:07:21 2012
@@ -120,6 +120,34 @@
CHECK(stacksize < kMaxThreadStackSize); // Sanity check.
}
+// Like getenv, but reads env directly from /proc and does not use libc.
+// This function should be called first inside __asan_init.
+const char *GetEnv(const char *name) {
+ static char *environ;
+ static uptr len;
+ static bool inited;
+ if (!inited) {
+ inited = true;
+ uptr environ_size;
+ len = ReadFileToBuffer("/proc/self/environ",
+ &environ, &environ_size, 1 << 26);
+ }
+ if (!environ || len == 0) return 0;
+ uptr namelen = internal_strlen(name);
+ const char *p = environ;
+ while (*p != '\0') { // will happen at the \0\0 that terminates the buffer
+ // proc file has the format NAME=value\0NAME=value\0NAME=value\0...
+ const char* endp =
+ (char*)internal_memchr(p, '\0', len - (p - environ));
+ if (endp == 0) // this entry isn't NUL terminated
+ return 0;
+ else if (!internal_memcmp(p, name, namelen) && p[namelen] == '=') // Match.
+ return p + namelen + 1; // point after =
+ p = endp + 1;
+ }
+ return 0; // Not found.
+}
+
// ----------------- sanitizer_procmaps.h
ProcessMaps::ProcessMaps() {
proc_self_maps_buff_len_ =
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=158451&r1=158450&r2=158451&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Thu Jun 14 09:07:21 2012
@@ -19,6 +19,7 @@
#include "sanitizer_libc.h"
#include "sanitizer_procmaps.h"
+#include <crt_externs.h> // for _NSGetEnviron
#include <fcntl.h>
#include <mach-o/dyld.h>
#include <mach-o/loader.h>
@@ -80,6 +81,25 @@
*stack_bottom = *stack_top - stacksize;
}
+const char *GetEnv(const char *name) {
+ char ***env_ptr = _NSGetEnviron();
+ CHECK(env_ptr);
+ char **environ = *env_ptr;
+ CHECK(environ);
+ uptr name_len = internal_strlen(name);
+ while (*environ != 0) {
+ uptr len = internal_strlen(*environ);
+ if (len > name_len) {
+ const char *p = *environ;
+ if (!internal_memcmp(p, name, name_len) &&
+ p[name_len] == '=') { // Match.
+ return *environ + name_len + 1; // String starting after =.
+ }
+ }
+ environ++;
+ }
+ return 0;
+}
// ----------------- sanitizer_procmaps.h
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=158451&r1=158450&r2=158451&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Thu Jun 14 09:07:21 2012
@@ -56,6 +56,22 @@
}
}
+const char *GetEnv(const char *name) {
+ static char env_buffer[32767] = {};
+
+ // Note: this implementation stores the result in a static buffer so we only
+ // allow it to be called just once.
+ static bool called_once = false;
+ if (called_once)
+ UNIMPLEMENTED();
+ called_once = true;
+
+ DWORD rv = GetEnvironmentVariableA(name, env_buffer, sizeof(env_buffer));
+ if (rv > 0 && rv < sizeof(env_buffer))
+ return env_buffer;
+ return 0;
+}
+
// ------------------ sanitizer_libc.h
void *internal_mmap(void *addr, uptr length, int prot, int flags,
int fd, u64 offset) {
More information about the llvm-commits
mailing list