explicit ElfFile(const char* name, bool readOnly=true);
// Open the ELF file.
- // Returns 0 on success, -1 (and sets errno) on failure and (if msg is not
- // NULL) sets *msg to a static string indicating what failed.
+ // Returns 0 on success, kSystemError (guaranteed to be -1) (and sets errno)
+ // on IO error, kInvalidElfFile (and sets errno to EINVAL) for an invalid
+ // Elf file. On error, if msg is not NULL, sets *msg to a static string
+ // indicating what failed.
+ enum {
+ kSuccess = 0,
+ kSystemError = -1,
+ kInvalidElfFile = -2,
+ };
int openNoThrow(const char* name, bool readOnly=true,
const char** msg=nullptr) noexcept;
~ElfFile();
- ElfFile(ElfFile&& other);
+ ElfFile(ElfFile&& other) noexcept;
ElfFile& operator=(ElfFile&& other);
/** Retrieve the ELF header */
const ElfW(Shdr)* getSectionContainingAddress(ElfW(Addr) addr) const;
private:
- void init();
+ bool init(const char** msg);
void destroy();
ElfFile(const ElfFile&) = delete;
ElfFile& operator=(const ElfFile&) = delete;