Home | History | Annotate | Download | only in POSIX-DYLD
      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 // C Includes
     14 // C++ Includes
     15 #include <vector>
     16 
     17 // Other libraries and framework includes
     18 #include "lldb/lldb-forward.h"
     19 
     20 namespace lldb_private {
     21 class DataExtractor;
     22 }
     23 
     24 /// @class AuxVector
     25 /// @brief Represents a processes auxiliary vector.
     26 ///
     27 /// When a process is loaded on Linux a vector of values is placed onto the
     28 /// stack communicating operating system specific information.  On construction
     29 /// this class locates and parses this information and provides a simple
     30 /// read-only interface to the entries found.
     31 class AuxVector {
     32 
     33 public:
     34     AuxVector(lldb_private::Process *process);
     35 
     36     struct Entry {
     37         uint64_t type;
     38         uint64_t value;
     39 
     40         Entry() : type(0), value(0) { }
     41     };
     42 
     43     /// Constants describing the type of entry.
     44     /// On Linux, running "LD_SHOW_AUXV=1 ./executable" will spew AUX information.
     45     enum EntryType {
     46         AT_NULL           = 0,   ///< End of auxv.
     47         AT_IGNORE         = 1,   ///< Ignore entry.
     48         AT_EXECFD         = 2,   ///< File descriptor of program.
     49         AT_PHDR           = 3,   ///< Program headers.
     50         AT_PHENT          = 4,   ///< Size of program header.
     51         AT_PHNUM          = 5,   ///< Number of program headers.
     52         AT_PAGESZ         = 6,   ///< Page size.
     53         AT_BASE           = 7,   ///< Interpreter base address.
     54         AT_FLAGS          = 8,   ///< Flags.
     55         AT_ENTRY          = 9,   ///< Program entry point.
     56         AT_NOTELF         = 10,  ///< Set if program is not an ELF.
     57         AT_UID            = 11,  ///< UID.
     58         AT_EUID           = 12,  ///< Effective UID.
     59         AT_GID            = 13,  ///< GID.
     60         AT_EGID           = 14,  ///< Effective GID.
     61         AT_CLKTCK         = 17,  ///< Clock frequency (e.g. times(2)).
     62         AT_PLATFORM       = 15,  ///< String identifying platform.
     63         AT_HWCAP          = 16,  ///< Machine dependent hints about processor capabilities.
     64         AT_FPUCW          = 18,  ///< Used FPU control word.
     65         AT_DCACHEBSIZE    = 19,  ///< Data cache block size.
     66         AT_ICACHEBSIZE    = 20,  ///< Instruction cache block size.
     67         AT_UCACHEBSIZE    = 21,  ///< Unified cache block size.
     68         AT_IGNOREPPC      = 22,  ///< Entry should be ignored.
     69         AT_SECURE         = 23,  ///< Boolean, was exec setuid-like?
     70         AT_BASE_PLATFORM  = 24,  ///< String identifying real platforms.
     71         AT_RANDOM         = 25,  ///< Address of 16 random bytes.
     72         AT_EXECFN         = 31,  ///< Filename of executable.
     73         AT_SYSINFO        = 32,  ///< Pointer to the global system page used for system calls and other nice things.
     74         AT_SYSINFO_EHDR   = 33,
     75         AT_L1I_CACHESHAPE = 34,  ///< Shapes of the caches.
     76         AT_L1D_CACHESHAPE = 35,
     77         AT_L2_CACHESHAPE  = 36,
     78         AT_L3_CACHESHAPE  = 37,
     79     };
     80 
     81 private:
     82     typedef std::vector<Entry> EntryVector;
     83 
     84 public:
     85     typedef EntryVector::const_iterator iterator;
     86 
     87     iterator begin() const { return m_auxv.begin(); }
     88     iterator end() const { return m_auxv.end(); }
     89 
     90     iterator
     91     FindEntry(EntryType type) const;
     92 
     93     static const char *
     94     GetEntryName(const Entry &entry) {
     95         return GetEntryName(static_cast<EntryType>(entry.type));
     96     }
     97 
     98     static const char *
     99     GetEntryName(EntryType type);
    100 
    101     void
    102     DumpToLog(lldb_private::Log *log) const;
    103 
    104 private:
    105     lldb_private::Process *m_process;
    106     EntryVector m_auxv;
    107 
    108     lldb::DataBufferSP
    109     GetAuxvData();
    110 
    111     void
    112     ParseAuxv(lldb_private::DataExtractor &data);
    113 };
    114 
    115 #endif
    116