1254721Semaste//===-- AuxVector.h ---------------------------------------------*- C++ -*-===//
2254721Semaste//
3254721Semaste//                     The LLVM Compiler Infrastructure
4254721Semaste//
5254721Semaste// This file is distributed under the University of Illinois Open Source
6254721Semaste// License. See LICENSE.TXT for details.
7254721Semaste//
8254721Semaste//===----------------------------------------------------------------------===//
9254721Semaste
10254721Semaste#ifndef liblldb_AuxVector_H_
11254721Semaste#define liblldb_AuxVector_H_
12254721Semaste
13254721Semaste// C Includes
14254721Semaste// C++ Includes
15254721Semaste#include <vector>
16254721Semaste
17254721Semaste// Other libraries and framework includes
18254721Semaste#include "lldb/lldb-forward.h"
19254721Semaste
20254721Semastenamespace lldb_private {
21254721Semasteclass DataExtractor;
22254721Semaste}
23254721Semaste
24254721Semaste/// @class AuxVector
25254721Semaste/// @brief Represents a processes auxiliary vector.
26254721Semaste///
27254721Semaste/// When a process is loaded on Linux a vector of values is placed onto the
28254721Semaste/// stack communicating operating system specific information.  On construction
29254721Semaste/// this class locates and parses this information and provides a simple
30254721Semaste/// read-only interface to the entries found.
31254721Semasteclass AuxVector {
32254721Semaste
33254721Semastepublic:
34254721Semaste    AuxVector(lldb_private::Process *process);
35254721Semaste
36254721Semaste    struct Entry {
37254721Semaste        uint64_t type;
38254721Semaste        uint64_t value;
39254721Semaste
40254721Semaste        Entry() : type(0), value(0) { }
41254721Semaste    };
42254721Semaste
43254721Semaste    /// Constants describing the type of entry.
44254721Semaste    /// On Linux, running "LD_SHOW_AUXV=1 ./executable" will spew AUX information.
45254721Semaste    enum EntryType {
46254721Semaste        AT_NULL           = 0,   ///< End of auxv.
47254721Semaste        AT_IGNORE         = 1,   ///< Ignore entry.
48254721Semaste        AT_EXECFD         = 2,   ///< File descriptor of program.
49254721Semaste        AT_PHDR           = 3,   ///< Program headers.
50254721Semaste        AT_PHENT          = 4,   ///< Size of program header.
51254721Semaste        AT_PHNUM          = 5,   ///< Number of program headers.
52254721Semaste        AT_PAGESZ         = 6,   ///< Page size.
53254721Semaste        AT_BASE           = 7,   ///< Interpreter base address.
54254721Semaste        AT_FLAGS          = 8,   ///< Flags.
55254721Semaste        AT_ENTRY          = 9,   ///< Program entry point.
56254721Semaste        AT_NOTELF         = 10,  ///< Set if program is not an ELF.
57254721Semaste        AT_UID            = 11,  ///< UID.
58254721Semaste        AT_EUID           = 12,  ///< Effective UID.
59254721Semaste        AT_GID            = 13,  ///< GID.
60254721Semaste        AT_EGID           = 14,  ///< Effective GID.
61254721Semaste        AT_CLKTCK         = 17,  ///< Clock frequency (e.g. times(2)).
62254721Semaste        AT_PLATFORM       = 15,  ///< String identifying platform.
63254721Semaste        AT_HWCAP          = 16,  ///< Machine dependent hints about processor capabilities.
64254721Semaste        AT_FPUCW          = 18,  ///< Used FPU control word.
65254721Semaste        AT_DCACHEBSIZE    = 19,  ///< Data cache block size.
66254721Semaste        AT_ICACHEBSIZE    = 20,  ///< Instruction cache block size.
67254721Semaste        AT_UCACHEBSIZE    = 21,  ///< Unified cache block size.
68254721Semaste        AT_IGNOREPPC      = 22,  ///< Entry should be ignored.
69254721Semaste        AT_SECURE         = 23,  ///< Boolean, was exec setuid-like?
70254721Semaste        AT_BASE_PLATFORM  = 24,  ///< String identifying real platforms.
71254721Semaste        AT_RANDOM         = 25,  ///< Address of 16 random bytes.
72254721Semaste        AT_EXECFN         = 31,  ///< Filename of executable.
73254721Semaste        AT_SYSINFO        = 32,  ///< Pointer to the global system page used for system calls and other nice things.
74254721Semaste        AT_SYSINFO_EHDR   = 33,
75254721Semaste        AT_L1I_CACHESHAPE = 34,  ///< Shapes of the caches.
76254721Semaste        AT_L1D_CACHESHAPE = 35,
77254721Semaste        AT_L2_CACHESHAPE  = 36,
78254721Semaste        AT_L3_CACHESHAPE  = 37,
79254721Semaste    };
80254721Semaste
81254721Semasteprivate:
82254721Semaste    typedef std::vector<Entry> EntryVector;
83254721Semaste
84254721Semastepublic:
85254721Semaste    typedef EntryVector::const_iterator iterator;
86254721Semaste
87254721Semaste    iterator begin() const { return m_auxv.begin(); }
88254721Semaste    iterator end() const { return m_auxv.end(); }
89254721Semaste
90254721Semaste    iterator
91254721Semaste    FindEntry(EntryType type) const;
92254721Semaste
93254721Semaste    static const char *
94254721Semaste    GetEntryName(const Entry &entry) {
95254721Semaste        return GetEntryName(static_cast<EntryType>(entry.type));
96254721Semaste    }
97254721Semaste
98254721Semaste    static const char *
99254721Semaste    GetEntryName(EntryType type);
100254721Semaste
101254721Semaste    void
102254721Semaste    DumpToLog(lldb_private::Log *log) const;
103254721Semaste
104254721Semasteprivate:
105254721Semaste    lldb_private::Process *m_process;
106254721Semaste    EntryVector m_auxv;
107254721Semaste
108254721Semaste    lldb::DataBufferSP
109254721Semaste    GetAuxvData();
110254721Semaste
111254721Semaste    void
112254721Semaste    ParseAuxv(lldb_private::DataExtractor &data);
113254721Semaste};
114254721Semaste
115254721Semaste#endif
116