[compiler-rt] r175163 - [sanitizer] Get full argv and envp on glibc.
Reid Kleckner
rnk at google.com
Thu Feb 14 07:18:27 PST 2013
LGTM
This is probably more reliable than /proc, even though it relies on a
glibc-only __libc_* symbol.
On Thu, Feb 14, 2013 at 9:40 AM, Evgeniy Stepanov <eugeni.stepanov at gmail.com
> wrote:
> 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);
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130214/5dae6d6b/attachment.html>
More information about the llvm-commits
mailing list