[sanitizer] Fix nolibc unittests broken by r346215

Subscribers: kubamracek, krytarowski, fedor.sergeev, llvm-commits

Differential Revision: https://reviews.llvm.org/D54163

llvm-svn: 346258
This commit is contained in:
Vitaly Buka 2018-11-06 19:23:22 +00:00
parent ecb2eb46bc
commit bcee83da3e
2 changed files with 36 additions and 30 deletions

View File

@ -19,7 +19,6 @@
#include "sanitizer_common.h"
#include "sanitizer_flags.h"
#include "sanitizer_getauxval.h"
#include "sanitizer_internal_defs.h"
#include "sanitizer_libc.h"
#include "sanitizer_linux.h"
@ -629,35 +628,7 @@ char **GetEnviron() {
return envp;
}
void ReExec() {
const char *pathname = "/proc/self/exe";
#if SANITIZER_NETBSD
static const int name[] = {
CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME,
};
char path[400];
uptr len;
len = sizeof(path);
if (internal_sysctl(name, ARRAY_SIZE(name), path, &len, NULL, 0) != -1)
pathname = path;
#elif SANITIZER_SOLARIS
pathname = getexecname();
CHECK_NE(pathname, NULL);
#elif SANITIZER_USE_GETAUXVAL
// Calling execve with /proc/self/exe sets that as $EXEC_ORIGIN. Binaries that
// rely on that will fail to load shared libraries. Query AT_EXECFN instead.
pathname = reinterpret_cast<const char *>(getauxval(AT_EXECFN));
#endif
uptr rv = internal_execve(pathname, GetArgv(), GetEnviron());
int rverrno;
CHECK_EQ(internal_iserror(rv, &rverrno), true);
Printf("execve failed, errno %d\n", rverrno);
Die();
}
#endif
#endif // !SANITIZER_OPENBSD
#if !SANITIZER_SOLARIS
enum MutexState {

View File

@ -23,6 +23,7 @@
#include "sanitizer_file.h"
#include "sanitizer_flags.h"
#include "sanitizer_freebsd.h"
#include "sanitizer_getauxval.h"
#include "sanitizer_linux.h"
#include "sanitizer_placement_new.h"
#include "sanitizer_procmaps.h"
@ -806,6 +807,40 @@ u64 MonotonicNanoTime() {
}
#endif // SANITIZER_LINUX && !SANITIZER_GO
#if !SANITIZER_OPENBSD
void ReExec() {
const char *pathname = "/proc/self/exe";
#if SANITIZER_NETBSD
static const int name[] = {
CTL_KERN,
KERN_PROC_ARGS,
-1,
KERN_PROC_PATHNAME,
};
char path[400];
uptr len;
len = sizeof(path);
if (internal_sysctl(name, ARRAY_SIZE(name), path, &len, NULL, 0) != -1)
pathname = path;
#elif SANITIZER_SOLARIS
pathname = getexecname();
CHECK_NE(pathname, NULL);
#elif SANITIZER_USE_GETAUXVAL
// Calling execve with /proc/self/exe sets that as $EXEC_ORIGIN. Binaries that
// rely on that will fail to load shared libraries. Query AT_EXECFN instead.
pathname = reinterpret_cast<const char *>(getauxval(AT_EXECFN));
#endif
uptr rv = internal_execve(pathname, GetArgv(), GetEnviron());
int rverrno;
CHECK_EQ(internal_iserror(rv, &rverrno), true);
Printf("execve failed, errno %d\n", rverrno);
Die();
}
#endif // !SANITIZER_OPENBSD
} // namespace __sanitizer
#endif