<div dir="ltr">LGTM<div><br></div><div style>This is probably more reliable than /proc, even though it relies on a glibc-only __libc_* symbol.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 14, 2013 at 9:40 AM, Evgeniy Stepanov <span dir="ltr"><<a href="mailto:eugeni.stepanov@gmail.com" target="_blank">eugeni.stepanov@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: eugenis<br>
Date: Thu Feb 14 08:40:03 2013<br>
New Revision: 175163<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=175163&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=175163&view=rev</a><br>
Log:<br>
[sanitizer] Get full argv and envp on glibc.<br>
<br>
/proc/$PID/cmdline is clipped to 4Kb.<br>
Locate argv and envp on the main thread stack.<br>
<br>
Modified:<br>
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc<br>
<br>
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=175163&r1=175162&r2=175163&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc?rev=175163&r1=175162&r2=175163&view=diff</a><br>

==============================================================================<br>
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)<br>
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu Feb 14 08:40:03 2013<br>
@@ -234,6 +234,21 @@ const char *GetEnv(const char *name) {<br>
   return 0;  // Not found.<br>
 }<br>
<br>
+#ifdef __GLIBC__<br>
+<br>
+extern "C" {<br>
+  extern void *__libc_stack_end;<br>
+}<br>
+<br>
+static void GetArgsAndEnv(char ***argv, char ***envp) {<br>
+  uptr *stack_end = (uptr *)__libc_stack_end;<br>
+  int argc = *stack_end;<br>
+  *argv = (char**)(stack_end + 1);<br>
+  *envp = (char**)(stack_end + argc + 2);<br>
+}<br>
+<br>
+#else  // __GLIBC__<br>
+<br>
 static void ReadNullSepFileToArray(const char *path, char ***arr,<br>
                                    int arr_size) {<br>
   char *buff;<br>
@@ -253,11 +268,17 @@ static void ReadNullSepFileToArray(const<br>
   (*arr)[count] = 0;<br>
 }<br>
<br>
-void ReExec() {<br>
+static void GetArgsAndEnv(char ***argv, char ***envp) {<br>
   static const int kMaxArgv = 2000, kMaxEnvp = 2000;<br>
+  ReadNullSepFileToArray("/proc/self/cmdline", argv, kMaxArgv);<br>
+  ReadNullSepFileToArray("/proc/self/environ", envp, kMaxEnvp);<br>
+}<br>
+<br>
+#endif  // __GLIBC__<br>
+<br>
+void ReExec() {<br>
   char **argv, **envp;<br>
-  ReadNullSepFileToArray("/proc/self/cmdline", &argv, kMaxArgv);<br>
-  ReadNullSepFileToArray("/proc/self/environ", &envp, kMaxEnvp);<br>
+  GetArgsAndEnv(&argv, &envp);<br>
   execve(argv[0], argv, envp);<br>
 }<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>