brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 910590b Raw
60 lines · c
1//===-- sanitizer_getauxval.h -----------------------------------*- C++ -*-===//2//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-exception6//7//===----------------------------------------------------------------------===//8//9// Common getauxval() guards and definitions.10// getauxval() is not defined until glibc version 2.16, or until API level 2111// for Android.12// Implement the getauxval() compat function for NetBSD.13//14//===----------------------------------------------------------------------===//15 16#ifndef SANITIZER_GETAUXVAL_H17#define SANITIZER_GETAUXVAL_H18 19#include "sanitizer_platform.h"20#include "sanitizer_glibc_version.h"21 22#if SANITIZER_LINUX || SANITIZER_FUCHSIA23 24#  if (__GLIBC_PREREQ(2, 16) || SANITIZER_ANDROID || SANITIZER_FUCHSIA) && \25      !SANITIZER_GO26#    define SANITIZER_USE_GETAUXVAL 127#  else28#    define SANITIZER_USE_GETAUXVAL 029#  endif30 31#  if SANITIZER_USE_GETAUXVAL32#    include <sys/auxv.h>33#  else34// The weak getauxval definition allows to check for the function at runtime.35// This is useful for Android, when compiled at a lower API level yet running36// on a more recent platform that offers the function.37extern "C" SANITIZER_WEAK_ATTRIBUTE unsigned long getauxval(unsigned long type);38#  endif39 40#elif SANITIZER_NETBSD41 42#define SANITIZER_USE_GETAUXVAL 143 44#include <dlfcn.h>45#include <elf.h>46 47static inline decltype(AuxInfo::a_v) getauxval(decltype(AuxInfo::a_type) type) {48  for (const AuxInfo *aux = (const AuxInfo *)_dlauxinfo();49       aux->a_type != AT_NULL; ++aux) {50    if (type == aux->a_type)51      return aux->a_v;52  }53 54  return 0;55}56 57#endif58 59#endif // SANITIZER_GETAUXVAL_H60