[compiler-rt] r209805 - Support getting executable's name for sanitizers needs on FreeBSD
Viktor Kutuzov
vkutuzov at accesssoftek.com
Thu May 29 05:12:42 PDT 2014
Author: vkutuzov
Date: Thu May 29 07:12:42 2014
New Revision: 209805
URL: http://llvm.org/viewvc/llvm-project?rev=209805&view=rev
Log:
Support getting executable's name for sanitizers needs on FreeBSD
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=209805&r1=209804&r2=209805&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc Thu May 29 07:12:42 2014
@@ -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
@@ -674,10 +675,19 @@ uptr ReadBinaryName(/*out*/char *buf, up
CHECK_LT(module_name_len, buf_len);
return module_name_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) {
// We can't read /proc/self/exe for some reason, assume the name of the
// binary is unknown.
Report("WARNING: readlink(\"/proc/self/exe\") failed with errno %d, "
More information about the llvm-commits
mailing list