aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sanitizer_common/sanitizer_getauxval.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sanitizer_common/sanitizer_getauxval.h')
-rw-r--r--lib/sanitizer_common/sanitizer_getauxval.h30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/sanitizer_common/sanitizer_getauxval.h b/lib/sanitizer_common/sanitizer_getauxval.h
index cbd1af12c04f..86ad3a5e2c2a 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.
//
//===----------------------------------------------------------------------===//
@@ -16,15 +17,10 @@
#define SANITIZER_GETAUXVAL_H
#include "sanitizer_platform.h"
+#include "sanitizer_glibc_version.h"
#if SANITIZER_LINUX || SANITIZER_FUCHSIA
-# include <features.h>
-
-# ifndef __GLIBC_PREREQ
-# define __GLIBC_PREREQ(x, y) 0
-# endif
-
# if __GLIBC_PREREQ(2, 16) || (SANITIZER_ANDROID && __ANDROID_API__ >= 21) || \
SANITIZER_FUCHSIA
# define SANITIZER_USE_GETAUXVAL 1
@@ -38,10 +34,26 @@
// The weak getauxval definition allows to check for the function at runtime.
// This is useful for Android, when compiled at a lower API level yet running
// on a more recent platform that offers the function.
-extern "C" SANITIZER_WEAK_ATTRIBUTE
-unsigned long getauxval(unsigned long type); // NOLINT
+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