From efd30c61c3836402346cb686146c0092c8160ea8 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Wed, 2 Mar 2005 07:59:06 +0000 Subject: [PATCH] Use namespace. committer: mfx 1109750346 +0000 --- src/p_elf.h | 158 +++++++++++++++++++++++++++------------------------- 1 file changed, 81 insertions(+), 77 deletions(-) diff --git a/src/p_elf.h b/src/p_elf.h index 3b04f91b..4953ce11 100644 --- a/src/p_elf.h +++ b/src/p_elf.h @@ -34,9 +34,11 @@ // Some ELF type definitinons **************************************************************************/ +namespace TT_Elf32 { + // The ELF file header. This appears at the start of every ELF file. -template -struct TT_Elf32_Ehdr +template +struct Ehdr { unsigned char e_ident[16]; /* Magic number and other info */ TT16 e_type; /* Object file type */ @@ -53,45 +55,45 @@ struct TT_Elf32_Ehdr TT16 e_shnum; /* Section header table entry count */ TT16 e_shstrndx; /* Section header string table index */ - enum { // e_ident - EI_CLASS = 4, - EI_DATA = 5, - EI_VERSION = 6, - EI_OSABI = 7, - EI_ABIVERSION = 8 + enum { // e_ident + EI_CLASS = 4, + EI_DATA = 5, + EI_VERSION = 6, + EI_OSABI = 7, + EI_ABIVERSION = 8, }; enum { // EI_CLASS - ELFCLASS32 = 1, /* 32-bit objects */ - ELFCLASS64 = 2 /* 64-bit objects */ + ELFCLASS32 = 1, /* 32-bit objects */ + ELFCLASS64 = 2, /* 64-bit objects */ }; enum { // EI_DATA - ELFDATA2LSB = 1, /* 2's complement, little endian */ - ELFDATA2MSB = 2 /* 2's complement, big endian */ + ELFDATA2LSB = 1, /* 2's complement, little endian */ + ELFDATA2MSB = 2 /* 2's complement, big endian */ }; enum { // EI_OSABI ELFOSABI_LINUX = 3 }; - enum { // e_type - ET_NONE = 0, /* No file type */ - ET_REL = 1, /* Relocatable file */ - ET_EXEC = 2, /* Executable file */ - ET_DYN = 3, /* Shared object file */ - ET_CORE = 4 /* Core file */ + enum { // e_type + ET_NONE = 0, /* No file type */ + ET_REL = 1, /* Relocatable file */ + ET_EXEC = 2, /* Executable file */ + ET_DYN = 3, /* Shared object file */ + ET_CORE = 4, /* Core file */ }; - enum { // e_machine + enum { // e_machine EM_386 = 3, - EM_PPC = 20 + EM_PPC = 20, }; - enum { // e_version - EV_CURRENT = 1 + enum { // e_version + EV_CURRENT = 1, }; } __attribute_packed; // Program segment header. -template -struct TT_Elf32_Phdr +template +struct Phdr { TT32 p_type; /* Segment type */ TT32 p_offset; /* Segment file offset */ @@ -102,59 +104,59 @@ struct TT_Elf32_Phdr TT32 p_flags; /* Segment flags */ TT32 p_align; /* Segment alignment */ - // Values for p_type - enum { - PT_LOAD = 1, /* Loadable program segment */ - PT_DYNAMIC = 2, /* Dynamic linking information */ - PT_INTERP = 3, /* Name of program interpreter */ - PT_PHDR = 6 /* Entry for header table itself */ + enum { // p_type + PT_LOAD = 1, /* Loadable program segment */ + PT_DYNAMIC = 2, /* Dynamic linking information */ + PT_INTERP = 3, /* Name of program interpreter */ + PT_PHDR = 6, /* Entry for header table itself */ }; - // Values for p_flags - enum { PF_X = (1 << 0) }; /* Segment is executable */ - enum { PF_W = (1 << 1) }; /* Segment is writable */ - enum { PF_R = (1 << 2) }; /* Segment is readable */ + enum { // p_flags + PF_X = 1, /* Segment is executable */ + PF_W = 2, /* Segment is writable */ + PF_R = 4, /* Segment is readable */ + }; } __attribute_packed; -template -struct TT_Elf32_Shdr +template +struct Shdr { - TT32 sh_name; /* Section name (string tbl index) */ - TT32 sh_type; /* Section type */ - TT32 sh_flags; /* Section flags */ - TT32 sh_addr; /* Section virtual addr at execution */ - TT32 sh_offset; /* Section file offset */ - TT32 sh_size; /* Section size in bytes */ - TT32 sh_link; /* Link to another section */ - TT32 sh_info; /* Additional section information */ - TT32 sh_addralign; /* Section alignment */ - TT32 sh_entsize; /* Entry size if section holds table */ + TT32 sh_name; /* Section name (string tbl index) */ + TT32 sh_type; /* Section type */ + TT32 sh_flags; /* Section flags */ + TT32 sh_addr; /* Section virtual addr at execution */ + TT32 sh_offset; /* Section file offset */ + TT32 sh_size; /* Section size in bytes */ + TT32 sh_link; /* Link to another section */ + TT32 sh_info; /* Additional section information */ + TT32 sh_addralign; /* Section alignment */ + TT32 sh_entsize; /* Entry size if section holds table */ - enum { // values for sh_type - SHT_NULL = 0, /* Section header table entry unused */ - SHT_PROGBITS = 1,/* Program data */ - SHT_SYMTAB = 2, /* Symbol table */ - SHT_STRTAB = 3, /* String table */ - SHT_RELA = 4, /* Relocation entries with addends */ - SHT_HASH = 5, /* Symbol hash table */ - SHT_DYNAMIC = 6, /* Dynamic linking information */ - SHT_NOTE = 7, /* Notes */ - SHT_NOBITS = 8, /* Program space with no data (bss) */ - SHT_REL = 9, /* Relocation entries, no addends */ - SHT_SHLIB = 10, /* Reserved */ - SHT_DYNSYM = 11, /* Dynamic linker symbol table */ + enum { // sh_type + SHT_NULL = 0, /* Section header table entry unused */ + SHT_PROGBITS = 1, /* Program data */ + SHT_SYMTAB = 2, /* Symbol table */ + SHT_STRTAB = 3, /* String table */ + SHT_RELA = 4, /* Relocation entries with addends */ + SHT_HASH = 5, /* Symbol hash table */ + SHT_DYNAMIC = 6, /* Dynamic linking information */ + SHT_NOTE = 7, /* Notes */ + SHT_NOBITS = 8, /* Program space with no data (bss) */ + SHT_REL = 9, /* Relocation entries, no addends */ + SHT_SHLIB = 10, /* Reserved */ + SHT_DYNSYM = 11, /* Dynamic linker symbol table */ /* 12, 13 hole */ SHT_INIT_ARRAY = 14, /* Array of constructors */ SHT_FINI_ARRAY = 15, /* Array of destructors */ SHT_PREINIT_ARRAY = 16, /* Array of pre-constructors */ - SHT_GROUP = 17, /* Section group */ + SHT_GROUP = 17, /* Section group */ SHT_SYMTAB_SHNDX = 18, /* Extended section indeces */ - SHT_NUM = 19 /* Number of defined types. */ + SHT_NUM = 19, /* Number of defined types. */ }; - enum { // values for sh_flags + enum { // sh_flags SHF_WRITE = (1 << 0), /* Writable */ SHF_ALLOC = (1 << 1), /* Occupies memory during execution */ SHF_EXECINSTR = (1 << 2), /* Executable */ @@ -167,35 +169,37 @@ struct TT_Elf32_Shdr __attribute_packed; -template -struct TT_Elf32_Dyn +template +struct Dyn { TT32 d_tag; TT32 d_val; - enum { // tags - DT_NULL = 0, /* End flag */ - DT_NEEDED = 1, /* Name of needed library */ - DT_STRTAB = 5, /* String table */ - DT_STRSZ = 10 /* Sizeof string table */ + enum { // d_tag + DT_NULL = 0, /* End flag */ + DT_NEEDED = 1, /* Name of needed library */ + DT_STRTAB = 5, /* String table */ + DT_STRSZ = 10, /* Sizeof string table */ }; } __attribute_packed; +} // namespace + /************************************************************************* // now for the actual types **************************************************************************/ -typedef TT_Elf32_Ehdr Elf_LE32_Ehdr; -typedef TT_Elf32_Phdr Elf_LE32_Phdr; -typedef TT_Elf32_Shdr Elf_LE32_Shdr; -typedef TT_Elf32_Dyn Elf_LE32_Dyn; +typedef TT_Elf32::Ehdr Elf_LE32_Ehdr; +typedef TT_Elf32::Phdr Elf_LE32_Phdr; +typedef TT_Elf32::Shdr Elf_LE32_Shdr; +typedef TT_Elf32::Dyn Elf_LE32_Dyn; -typedef TT_Elf32_Ehdr Elf32_Ehdr; -typedef TT_Elf32_Phdr Elf32_Phdr; -typedef TT_Elf32_Shdr Elf32_Shdr; -typedef TT_Elf32_Dyn Elf32_Dyn; +typedef TT_Elf32::Ehdr Elf32_Ehdr; +typedef TT_Elf32::Phdr Elf32_Phdr; +typedef TT_Elf32::Shdr Elf32_Shdr; +typedef TT_Elf32::Dyn Elf32_Dyn; #endif /* already included */