[compiler-rt] r175163 - [sanitizer] Get full argv and envp on glibc.
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Thu Feb 14 06:40:03 PST 2013
Author: eugenis
Date: Thu Feb 14 08:40:03 2013
New Revision: 175163
URL: http://llvm.org/viewvc/llvm-project?rev=175163&view=rev
Log:
[sanitizer] Get full argv and envp on glibc.
/proc/$PID/cmdline is clipped to 4Kb.
Locate argv and envp on the main thread stack.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
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=175163&r1=175162&r2=175163&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu Feb 14 08:40:03 2013
@@ -234,6 +234,21 @@ const char *GetEnv(const char *name) {
return 0; // Not found.
}
+#ifdef __GLIBC__
+
+extern "C" {
+ extern void *__libc_stack_end;
+}
+
+static void GetArgsAndEnv(char ***argv, char ***envp) {
+ uptr *stack_end = (uptr *)__libc_stack_end;
+ int argc = *stack_end;
+ *argv = (char**)(stack_end + 1);
+ *envp = (char**)(stack_end + argc + 2);
+}
+
+#else // __GLIBC__
+
static void ReadNullSepFileToArray(const char *path, char ***arr,
int arr_size) {
char *buff;
@@ -253,11 +268,17 @@ static void ReadNullSepFileToArray(const
(*arr)[count] = 0;
}
-void ReExec() {
+static void GetArgsAndEnv(char ***argv, char ***envp) {
static const int kMaxArgv = 2000, kMaxEnvp = 2000;
+ ReadNullSepFileToArray("/proc/self/cmdline", argv, kMaxArgv);
+ ReadNullSepFileToArray("/proc/self/environ", envp, kMaxEnvp);
+}
+
+#endif // __GLIBC__
+
+void ReExec() {
char **argv, **envp;
- ReadNullSepFileToArray("/proc/self/cmdline", &argv, kMaxArgv);
- ReadNullSepFileToArray("/proc/self/environ", &envp, kMaxEnvp);
+ GetArgsAndEnv(&argv, &envp);
execve(argv[0], argv, envp);
}
More information about the llvm-commits
mailing list