1 //===-- AuxVector.h ---------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_AuxVector_H_
11 #define liblldb_AuxVector_H_
12 
13 #include <vector>
14 
15 #include "lldb/lldb-forward.h"
16 
17 namespace lldb_private {
18 class DataExtractor;
19 }
20 
21 /// @class AuxVector
22 /// Represents a processes auxiliary vector.
23 ///
24 /// When a process is loaded on Linux a vector of values is placed onto the
25 /// stack communicating operating system specific information.  On
26 /// construction this class locates and parses this information and provides a
27 /// simple read-only interface to the entries found.
28 class AuxVector {
29 
30 public:
31   AuxVector(lldb_private::Process *process);
32 
33   struct Entry {
34     uint64_t type;
35     uint64_t value;
36 
EntryEntry37     Entry() : type(0), value(0) {}
38   };
39 
40   /// Constants describing the type of entry.
41   /// On Linux, running "LD_SHOW_AUXV=1 ./executable" will spew AUX
42   /// information. Added AUXV prefix to avoid potential conflicts with system-
43   /// defined macros
44   enum EntryType {
45     AUXV_AT_NULL = 0,            ///< End of auxv.
46     AUXV_AT_IGNORE = 1,          ///< Ignore entry.
47     AUXV_AT_EXECFD = 2,          ///< File descriptor of program.
48     AUXV_AT_PHDR = 3,            ///< Program headers.
49     AUXV_AT_PHENT = 4,           ///< Size of program header.
50     AUXV_AT_PHNUM = 5,           ///< Number of program headers.
51     AUXV_AT_PAGESZ = 6,          ///< Page size.
52     AUXV_AT_BASE = 7,            ///< Interpreter base address.
53     AUXV_AT_FLAGS = 8,           ///< Flags.
54     AUXV_AT_ENTRY = 9,           ///< Program entry point.
55     AUXV_AT_NOTELF = 10,         ///< Set if program is not an ELF.
56     AUXV_AT_UID = 11,            ///< UID.
57     AUXV_AT_EUID = 12,           ///< Effective UID.
58     AUXV_AT_GID = 13,            ///< GID.
59     AUXV_AT_EGID = 14,           ///< Effective GID.
60     AUXV_AT_CLKTCK = 17,         ///< Clock frequency (e.g. times(2)).
61     AUXV_AT_PLATFORM = 15,       ///< String identifying platform.
62     AUXV_AT_HWCAP = 16,          ///< Machine dependent hints about processor capabilities.
63     AUXV_AT_FPUCW = 18,          ///< Used FPU control word.
64     AUXV_AT_DCACHEBSIZE = 19,    ///< Data cache block size.
65     AUXV_AT_ICACHEBSIZE = 20,    ///< Instruction cache block size.
66     AUXV_AT_UCACHEBSIZE = 21,    ///< Unified cache block size.
67     AUXV_AT_IGNOREPPC = 22,      ///< Entry should be ignored.
68     AUXV_AT_SECURE = 23,         ///< Boolean, was exec setuid-like?
69     AUXV_AT_BASE_PLATFORM = 24,  ///< String identifying real platforms.
70     AUXV_AT_RANDOM = 25,         ///< Address of 16 random bytes.
71     AUXV_AT_EXECFN = 31,         ///< Filename of executable.
72     AUXV_AT_SYSINFO = 32,        ///< Pointer to the global system page used for system
73                                  ///calls and other nice things.
74     AUXV_AT_SYSINFO_EHDR = 33,
75     AUXV_AT_L1I_CACHESHAPE = 34, ///< Shapes of the caches.
76     AUXV_AT_L1D_CACHESHAPE = 35,
77     AUXV_AT_L2_CACHESHAPE = 36,
78     AUXV_AT_L3_CACHESHAPE = 37,
79   };
80 
81 private:
82   typedef std::vector<Entry> EntryVector;
83 
84 public:
85   typedef EntryVector::const_iterator iterator;
86 
begin()87   iterator begin() const { return m_auxv.begin(); }
end()88   iterator end() const { return m_auxv.end(); }
89 
90   iterator FindEntry(EntryType type) const;
91 
GetEntryName(const Entry & entry)92   static const char *GetEntryName(const Entry &entry) {
93     return GetEntryName(static_cast<EntryType>(entry.type));
94   }
95 
96   static const char *GetEntryName(EntryType type);
97 
98   void DumpToLog(lldb_private::Log *log) const;
99 
100 private:
101   lldb_private::Process *m_process;
102   EntryVector m_auxv;
103 
104   lldb::DataBufferSP GetAuxvData();
105 
106   void ParseAuxv(lldb_private::DataExtractor &data);
107 };
108 
109 #endif
110