Skip to content

Commit

Permalink
[compiler-rt] simplifying ::ReExec for freebsd. (#79711)
Browse files Browse the repository at this point in the history
taking the getauxval route since elf_aux_info is available since FBSD
12.
  • Loading branch information
devnexen committed Feb 16, 2024
1 parent bfbd0da commit 691b12a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 14 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ static inline decltype(AuxInfo::a_v) getauxval(decltype(AuxInfo::a_type) type) {
return 0;
}

#elif SANITIZER_FREEBSD
# include <sys/auxv.h>

# define SANITIZER_USE_GETAUXVAL 1
# define AT_EXECFN AT_EXECPATH

static inline unsigned long getauxval(unsigned long type) {
unsigned long buf = 0ul;

if (elf_aux_info(static_cast<int>(type), &buf, sizeof(buf)))
return 0ul;
return buf;
}

#endif

#endif // SANITIZER_GETAUXVAL_H
9 changes: 1 addition & 8 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,14 +934,7 @@ u64 MonotonicNanoTime() {
void ReExec() {
const char *pathname = "/proc/self/exe";

# if SANITIZER_FREEBSD
for (const auto *aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) {
if (aux->a_type == AT_EXECPATH) {
pathname = static_cast<const char *>(aux->a_un.a_ptr);
break;
}
}
# elif SANITIZER_NETBSD
# if SANITIZER_NETBSD
static const int name[] = {
CTL_KERN,
KERN_PROC_ARGS,
Expand Down

0 comments on commit 691b12a

Please sign in to comment.