xref: /freebsd/contrib/llvm-project/lldb/source/Plugins/Process/Utility/AuxVector.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1 //===-- AuxVector.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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_AUXVECTOR_H
10 #define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_AUXVECTOR_H
11 
12 #include "lldb/Utility/DataExtractor.h"
13 #include "lldb/Utility/Log.h"
14 #include <optional>
15 #include <unordered_map>
16 
17 class AuxVector {
18 
19 public:
20   AuxVector(const lldb_private::DataExtractor &data);
21 
22   /// Constants describing the type of entry.
23   /// On Linux, running "LD_SHOW_AUXV=1 ./executable" will spew AUX
24   /// information. Added AUXV prefix to avoid potential conflicts with system-
25   /// defined macros
26   enum EntryType {
27     AUXV_AT_NULL = 0,      ///< End of auxv.
28     AUXV_AT_IGNORE = 1,    ///< Ignore entry.
29     AUXV_AT_EXECFD = 2,    ///< File descriptor of program.
30     AUXV_AT_PHDR = 3,      ///< Program headers.
31     AUXV_AT_PHENT = 4,     ///< Size of program header.
32     AUXV_AT_PHNUM = 5,     ///< Number of program headers.
33     AUXV_AT_PAGESZ = 6,    ///< Page size.
34     AUXV_AT_BASE = 7,      ///< Interpreter base address.
35     AUXV_AT_FLAGS = 8,     ///< Flags.
36     AUXV_AT_ENTRY = 9,     ///< Program entry point.
37     AUXV_AT_NOTELF = 10,   ///< Set if program is not an ELF.
38     AUXV_AT_UID = 11,      ///< UID.
39     AUXV_AT_EUID = 12,     ///< Effective UID.
40     AUXV_AT_GID = 13,      ///< GID.
41     AUXV_AT_EGID = 14,     ///< Effective GID.
42     AUXV_AT_CLKTCK = 17,   ///< Clock frequency (e.g. times(2)).
43     AUXV_AT_PLATFORM = 15, ///< String identifying platform.
44     AUXV_AT_HWCAP =
45         16, ///< Machine dependent hints about processor capabilities.
46     AUXV_AT_FPUCW = 18,         ///< Used FPU control word.
47     AUXV_AT_DCACHEBSIZE = 19,   ///< Data cache block size.
48     AUXV_AT_ICACHEBSIZE = 20,   ///< Instruction cache block size.
49     AUXV_AT_UCACHEBSIZE = 21,   ///< Unified cache block size.
50     AUXV_AT_IGNOREPPC = 22,     ///< Entry should be ignored.
51     AUXV_AT_SECURE = 23,        ///< Boolean, was exec setuid-like?
52     AUXV_AT_BASE_PLATFORM = 24, ///< String identifying real platforms.
53     AUXV_AT_RANDOM = 25,        ///< Address of 16 random bytes.
54     AUXV_AT_HWCAP2 = 26,        ///< Extension of AT_HWCAP.
55     AUXV_AT_EXECFN = 31,        ///< Filename of executable.
56     AUXV_AT_SYSINFO = 32, ///< Pointer to the global system page used for system
57                           /// calls and other nice things.
58     AUXV_AT_SYSINFO_EHDR = 33,
59     AUXV_AT_L1I_CACHESHAPE = 34, ///< Shapes of the caches.
60     AUXV_AT_L1D_CACHESHAPE = 35,
61     AUXV_AT_L2_CACHESHAPE = 36,
62     AUXV_AT_L3_CACHESHAPE = 37,
63   };
64 
65   std::optional<uint64_t> GetAuxValue(enum EntryType entry_type) const;
66   void DumpToLog(lldb_private::Log *log) const;
67   const char *GetEntryName(EntryType type) const;
68 
69 private:
70   void ParseAuxv(const lldb_private::DataExtractor &data);
71 
72   std::unordered_map<uint64_t, uint64_t> m_auxv_entries;
73 };
74 
75 #endif
76