//===-- Implementation file for getauxval function --------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "src/sys/auxv/getauxval.h" #include "config/app.h" #include "src/__support/common.h" #include "src/__support/macros/config.h" #include "src/errno/libc_errno.h" #include <linux/auxvec.h> // for guarded initialization #include "src/__support/threads/callonce.h" #include "src/__support/threads/linux/futex_word.h" // for mallocing the global auxv #include "src/sys/mman/mmap.h" #include "src/sys/mman/munmap.h" // for reading /proc/self/auxv #include "src/fcntl/open.h" #include "src/sys/prctl/prctl.h" #include "src/unistd/close.h" #include "src/unistd/read.h" // getauxval will work either with or without __cxa_atexit support. // In order to detect if __cxa_atexit is supported, we define a weak symbol. // We prefer __cxa_atexit as it is always defined as a C symbol whileas atexit // may not be created via objcopy yet. Also, for glibc, atexit is provided via // libc_nonshared.a rather than libc.so. So, it is may not be made ready for // overlay builds. extern "C" [[gnu::weak]] int __cxa_atexit(void (*callback)(void *), void *payload, void *); namespace LIBC_NAMESPACE_DECL { constexpr static size_t MAX_AUXV_ENTRIES = …; // Helper to recover or set errno class AuxvErrnoGuard { … }; // Helper to manage the memory static AuxEntry *auxv = …; class AuxvMMapGuard { … }; class AuxvFdGuard { … }; static void initialize_auxv_once(void) { … } static AuxEntry read_entry(int fd) { … } LLVM_LIBC_FUNCTION(unsigned long, getauxval, (unsigned long id)) { … } } // namespace LIBC_NAMESPACE_DECL