1 //===-- sanitizer_getauxval.h -----------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Common getauxval() guards and definitions.
10 // getauxval() is not defined until glibc version 2.16, or until API level 21
12 // Implement the getauxval() compat function for NetBSD.
14 //===----------------------------------------------------------------------===//
16 #ifndef SANITIZER_GETAUXVAL_H
17 #define SANITIZER_GETAUXVAL_H
19 #include "sanitizer_platform.h"
20 #include "sanitizer_glibc_version.h"
22 #if SANITIZER_LINUX || SANITIZER_FUCHSIA
24 # if (__GLIBC_PREREQ(2, 16) || (SANITIZER_ANDROID && __ANDROID_API__ >= 21) || \
25 SANITIZER_FUCHSIA) && \
27 # define SANITIZER_USE_GETAUXVAL 1
29 # define SANITIZER_USE_GETAUXVAL 0
32 # if SANITIZER_USE_GETAUXVAL
33 # include <sys/auxv.h>
35 // The weak getauxval definition allows to check for the function at runtime.
36 // This is useful for Android, when compiled at a lower API level yet running
37 // on a more recent platform that offers the function.
38 extern "C" SANITIZER_WEAK_ATTRIBUTE
unsigned long getauxval(unsigned long type
);
41 #elif SANITIZER_NETBSD
43 #define SANITIZER_USE_GETAUXVAL 1
48 static inline decltype(AuxInfo::a_v
) getauxval(decltype(AuxInfo::a_type
) type
) {
49 for (const AuxInfo
*aux
= (const AuxInfo
*)_dlauxinfo();
50 aux
->a_type
!= AT_NULL
; ++aux
) {
51 if (type
== aux
->a_type
)
60 #endif // SANITIZER_GETAUXVAL_H