[PATCH] Support getting executable's name for sanitizers needs on FreeBSD

Viktor Kutuzov vkutuzov at accesssoftek.com
Wed May 28 06:53:25 PDT 2014


Hi kcc, samsonov,

http://reviews.llvm.org/D3938

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
@@ -49,6 +49,7 @@
 #include <unwind.h>
 
 #if SANITIZER_FREEBSD
+#include <sys/sysctl.h>
 #include <machine/atomic.h>
 extern "C" {
 // <sys/umtx.h> must be included after <errno.h> and <sys/types.h> on
@@ -655,10 +656,19 @@
 static uptr proc_self_exe_cache_len = 0;
 
 uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) {
+#if SANITIZER_FREEBSD
+  const int Mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+  size_t Size = buf_len;
+  bool IsErr = (sysctl(Mib, 4, buf, &Size, NULL, 0) != 0);
+  int readlink_error = IsErr ? errno : 0;
+  uptr module_name_len = Size;
+#else
   uptr module_name_len = internal_readlink(
       "/proc/self/exe", buf, buf_len);
   int readlink_error;
-  if (internal_iserror(module_name_len, &readlink_error)) {
+  bool IsErr = internal_iserror(module_name_len, &readlink_error);
+#endif
+  if (IsErr) {
     if (proc_self_exe_cache_len) {
       // If available, use the cached module name.
       CHECK_LE(proc_self_exe_cache_len, buf_len);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3938.9877.patch
Type: text/x-patch
Size: 1189 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140528/3c03ecc1/attachment.bin>


More information about the llvm-commits mailing list