diff options
author | Kamil Rytarowski <n54@gmx.com> | 2019-09-12 18:57:58 +0000 |
---|---|---|
committer | Kamil Rytarowski <n54@gmx.com> | 2019-09-12 18:57:58 +0000 |
commit | bc49d718b9851eca202bac795867859647574cc2 (patch) | |
tree | 01eaa7e19920fcab917d4f98c52fdac3bd93a4c3 | |
parent | e7b48cc7d4882d588fee90cd86cfa8524b9c116d (diff) | |
download | compiler-rt-bc49d718b9851eca202bac795867859647574cc2.tar.gz |
Add getauxval() compat for NetBSD
Summary:
getauxval() is not available on NetBSD and there is no a direct equivalent.
Add a function that implements the same semantics with NetBSD internals.
Reorder the GetPageSize() functions to prefer the sysctl approach for NetBSD.
It no longer makes a difference which approach is better. Avoid changing
conditional code path.
Reviewers: vitalybuka, dvyukov, mgorny, joerg
Reviewed By: vitalybuka
Subscribers: llvm-commits, #sanitizers
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D67329
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@371758 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/sanitizer_common/sanitizer_getauxval.h | 20 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_linux.cpp | 4 |
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/sanitizer_common/sanitizer_getauxval.h b/lib/sanitizer_common/sanitizer_getauxval.h index f1ca0be43..777b1212d 100644 --- a/lib/sanitizer_common/sanitizer_getauxval.h +++ b/lib/sanitizer_common/sanitizer_getauxval.h @@ -9,6 +9,7 @@ // Common getauxval() guards and definitions. // getauxval() is not defined until glibc version 2.16, or until API level 21 // for Android. +// Implement the getauxval() compat function for NetBSD. // //===----------------------------------------------------------------------===// @@ -41,6 +42,23 @@ extern "C" SANITIZER_WEAK_ATTRIBUTE unsigned long getauxval(unsigned long type); # endif -#endif // SANITIZER_LINUX || SANITIZER_FUCHSIA +#elif SANITIZER_NETBSD + +#define SANITIZER_USE_GETAUXVAL 1 + +#include <dlfcn.h> +#include <elf.h> + +static inline decltype(AuxInfo::a_v) getauxval(decltype(AuxInfo::a_type) type) { + for (const AuxInfo *aux = (const AuxInfo *)_dlauxinfo(); + aux->a_type != AT_NULL; ++aux) { + if (type == aux->a_type) + return aux->a_v; + } + + return 0; +} + +#endif #endif // SANITIZER_GETAUXVAL_H diff --git a/lib/sanitizer_common/sanitizer_linux.cpp b/lib/sanitizer_common/sanitizer_linux.cpp index e666290fc..d23009075 100644 --- a/lib/sanitizer_common/sanitizer_linux.cpp +++ b/lib/sanitizer_common/sanitizer_linux.cpp @@ -1062,8 +1062,6 @@ uptr GetMaxUserVirtualAddress() { uptr GetPageSize() { #if SANITIZER_LINUX && (defined(__x86_64__) || defined(__i386__)) return EXEC_PAGESIZE; -#elif SANITIZER_USE_GETAUXVAL - return getauxval(AT_PAGESZ); #elif SANITIZER_FREEBSD || SANITIZER_NETBSD // Use sysctl as sysconf can trigger interceptors internally. int pz = 0; @@ -1072,6 +1070,8 @@ uptr GetPageSize() { int rv = internal_sysctl(mib, 2, &pz, &pzl, nullptr, 0); CHECK_EQ(rv, 0); return (uptr)pz; +#elif SANITIZER_USE_GETAUXVAL + return getauxval(AT_PAGESZ); #else return sysconf(_SC_PAGESIZE); // EXEC_PAGESIZE may not be trustworthy. #endif |