[PATCH] D17832: Retrieve command line arguments and environment correctly on FreeBSD
Dimitry Andric via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 4 13:37:43 PST 2016
dim updated this revision to Diff 49850.
dim added a comment.
Add an explanatory comment. Also, ping. :-)
http://reviews.llvm.org/D17832
Files:
lib/sanitizer_common/sanitizer_linux.cc
Index: lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux.cc
+++ lib/sanitizer_common/sanitizer_linux.cc
@@ -60,7 +60,10 @@
#include <unistd.h>
#if SANITIZER_FREEBSD
+#include <sys/exec.h>
#include <sys/sysctl.h>
+#include <vm/vm_param.h>
+#include <vm/pmap.h>
#include <machine/atomic.h>
extern "C" {
// <sys/umtx.h> must be included after <errno.h> and <sys/types.h> on
@@ -395,11 +398,13 @@
#endif
}
+#if !SANITIZER_FREEBSD
extern "C" {
SANITIZER_WEAK_ATTRIBUTE extern void *__libc_stack_end;
}
+#endif
-#if !SANITIZER_GO
+#if !SANITIZER_GO && !SANITIZER_FREEBSD
static void ReadNullSepFileToArray(const char *path, char ***arr,
int arr_size) {
char *buff;
@@ -425,6 +430,7 @@
#endif
static void GetArgsAndEnv(char ***argv, char ***envp) {
+#if !SANITIZER_FREEBSD
#if !SANITIZER_GO
if (&__libc_stack_end) {
#endif
@@ -439,6 +445,18 @@
ReadNullSepFileToArray("/proc/self/environ", envp, kMaxEnvp);
}
#endif
+#else
+ // On FreeBSD, retrieving the argument and environment arrays is done via the
+ // kern.ps_strings sysctl, which returns a pointer to a structure containing
+ // this information. If the sysctl is not available, a "hardcoded" address,
+ // PS_STRINGS, must be used instead. See also <sys/exec.h>.
+ ps_strings *pss;
+ size_t sz = sizeof(pss);
+ if (sysctlbyname("kern.ps_strings", &pss, &sz, NULL, 0) == -1)
+ pss = (ps_strings*)PS_STRINGS;
+ *argv = pss->ps_argvstr;
+ *envp = pss->ps_envstr;
+#endif
}
char **GetArgv() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17832.49850.patch
Type: text/x-patch
Size: 1634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160304/c27d2a98/attachment.bin>
More information about the llvm-commits
mailing list