Support getting executable's name for sanitizers needs on FreeBSD

llvm-svn: 209805
This commit is contained in:
Viktor Kutuzov 2014-05-29 12:12:42 +00:00
parent 76d35f47d3
commit 9cd9b4ce0c
1 changed files with 11 additions and 1 deletions

View File

@ -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, uptr buf_len) {
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, "