1279377Simp//===-- AuxVector.h ---------------------------------------------*- C++ -*-===//
2279377Simp//
3279377Simp//                     The LLVM Compiler Infrastructure
4279377Simp//
5279377Simp// This file is distributed under the University of Illinois Open Source
6279377Simp// License. See LICENSE.TXT for details.
7279377Simp//
8279377Simp//===----------------------------------------------------------------------===//
9279377Simp
10279377Simp#ifndef liblldb_AuxVector_H_
11279377Simp#define liblldb_AuxVector_H_
12279377Simp
13279377Simp// C Includes
14279377Simp// C++ Includes
15279377Simp#include <vector>
16279377Simp
17279377Simp// Other libraries and framework includes
18279377Simp#include "lldb/lldb-forward.h"
19279377Simp
20279377Simpnamespace lldb_private {
21279377Simpclass DataExtractor;
22279377Simp}
23279377Simp
24279377Simp/// @class AuxVector
25279377Simp/// @brief Represents a processes auxiliary vector.
26279377Simp///
27279377Simp/// When a process is loaded on Linux a vector of values is placed onto the
28279377Simp/// stack communicating operating system specific information.  On construction
29279377Simp/// this class locates and parses this information and provides a simple
30279377Simp/// read-only interface to the entries found.
31279377Simpclass AuxVector {
32279377Simp
33279377Simppublic:
34279377Simp    AuxVector(lldb_private::Process *process);
35279377Simp
36279377Simp    struct Entry {
37279377Simp        uint64_t type;
38279377Simp        uint64_t value;
39279377Simp
40279377Simp        Entry() : type(0), value(0) { }
41279377Simp    };
42279377Simp
43279377Simp    /// Constants describing the type of entry.
44279377Simp    /// On Linux, running "LD_SHOW_AUXV=1 ./executable" will spew AUX information.
45279377Simp    enum EntryType {
46279377Simp        AT_NULL           = 0,   ///< End of auxv.
47279377Simp        AT_IGNORE         = 1,   ///< Ignore entry.
48279377Simp        AT_EXECFD         = 2,   ///< File descriptor of program.
49279377Simp        AT_PHDR           = 3,   ///< Program headers.
50279377Simp        AT_PHENT          = 4,   ///< Size of program header.
51279377Simp        AT_PHNUM          = 5,   ///< Number of program headers.
52279377Simp        AT_PAGESZ         = 6,   ///< Page size.
53279377Simp        AT_BASE           = 7,   ///< Interpreter base address.
54279377Simp        AT_FLAGS          = 8,   ///< Flags.
55279377Simp        AT_ENTRY          = 9,   ///< Program entry point.
56279377Simp        AT_NOTELF         = 10,  ///< Set if program is not an ELF.
57279377Simp        AT_UID            = 11,  ///< UID.
58279377Simp        AT_EUID           = 12,  ///< Effective UID.
59279377Simp        AT_GID            = 13,  ///< GID.
60279377Simp        AT_EGID           = 14,  ///< Effective GID.
61279377Simp        AT_CLKTCK         = 17,  ///< Clock frequency (e.g. times(2)).
62279377Simp        AT_PLATFORM       = 15,  ///< String identifying platform.
63279377Simp        AT_HWCAP          = 16,  ///< Machine dependent hints about processor capabilities.
64279377Simp        AT_FPUCW          = 18,  ///< Used FPU control word.
65279377Simp        AT_DCACHEBSIZE    = 19,  ///< Data cache block size.
66279377Simp        AT_ICACHEBSIZE    = 20,  ///< Instruction cache block size.
67279377Simp        AT_UCACHEBSIZE    = 21,  ///< Unified cache block size.
68279377Simp        AT_IGNOREPPC      = 22,  ///< Entry should be ignored.
69279377Simp        AT_SECURE         = 23,  ///< Boolean, was exec setuid-like?
70279377Simp        AT_BASE_PLATFORM  = 24,  ///< String identifying real platforms.
71279377Simp        AT_RANDOM         = 25,  ///< Address of 16 random bytes.
72279377Simp        AT_EXECFN         = 31,  ///< Filename of executable.
73279377Simp        AT_SYSINFO        = 32,  ///< Pointer to the global system page used for system calls and other nice things.
74279377Simp        AT_SYSINFO_EHDR   = 33,
75279377Simp        AT_L1I_CACHESHAPE = 34,  ///< Shapes of the caches.
76279377Simp        AT_L1D_CACHESHAPE = 35,
77279377Simp        AT_L2_CACHESHAPE  = 36,
78279377Simp        AT_L3_CACHESHAPE  = 37,
79279377Simp    };
80279377Simp
81279377Simpprivate:
82279377Simp    typedef std::vector<Entry> EntryVector;
83279377Simp
84279377Simppublic:
85279377Simp    typedef EntryVector::const_iterator iterator;
86279377Simp
87279377Simp    iterator begin() const { return m_auxv.begin(); }
88279377Simp    iterator end() const { return m_auxv.end(); }
89279377Simp
90279377Simp    iterator
91279377Simp    FindEntry(EntryType type) const;
92279377Simp
93279377Simp    static const char *
94279377Simp    GetEntryName(const Entry &entry) {
95279377Simp        return GetEntryName(static_cast<EntryType>(entry.type));
96279377Simp    }
97279377Simp
98279377Simp    static const char *
99279377Simp    GetEntryName(EntryType type);
100279377Simp
101279377Simp    void
102279377Simp    DumpToLog(lldb_private::Log *log) const;
103279377Simp
104279377Simpprivate:
105279377Simp    lldb_private::Process *m_process;
106279377Simp    EntryVector m_auxv;
107279377Simp
108279377Simp    lldb::DataBufferSP
109279377Simp    GetAuxvData();
110279377Simp
111279377Simp    void
112279377Simp    ParseAuxv(lldb_private::DataExtractor &data);
113279377Simp};
114279377Simp
115279377Simp#endif
116279377Simp