root / Whitix / branches / hybrid / include / elf.h

Revision 487, 3.5 kB (checked in by mwhitworth, 4 months ago)

Add to and tidy up various header files.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#ifndef ELF_H
20#define ELF_H
21
22#include <typedefs.h>
23
24#define PUSH_AUX_ENT(stackP,id,value) \
25        do { \
26        STACK_PUSH((stackP),(value)); \
27        STACK_PUSH((stackP),(id)); \
28        }while(0)
29
30#define AT_NULL         0
31#define AT_IGNORE       1
32#define AT_EXECFD       2
33#define AT_PHDR         3
34#define AT_PHENT        4
35#define AT_PHNUM        5
36#define AT_PAGESZ       6
37#define AT_BASE         7
38#define AT_FLAGS        8
39#define AT_ENTRY        9
40#define AT_NOTELF       10
41#define AT_UID          11
42#define AT_EUID         12
43#define AT_GID          13
44#define AT_EGID         14
45
46#define ELF_HEAD_CHECK(header) ((header)->elfMagic[0] == 0x7F && (header)->elfMagic[1] == 'E' && (header)->elfMagic[2] == 'L' \
47                && (header)->elfMagic[3] == 'F')
48
49/* ELF file types */
50#define ELF_REL         1
51#define ELF_EXEC        2
52#define ELF_DYN         3
53
54/* ELF segment types */
55#define ELF_TYPE_LOAD   1
56#define ELF_TYPE_DYN    2
57#define ELF_TYPE_INTERP 3
58
59/* ELF permissions */
60#define ELF_PERMS_RW    2
61
62/* ElfCheckHeader - sanity checks the ELF header */
63#define ElfCheckHeader(header, type) \
64        (!ELF_HEAD_CHECK(header) || !((header)->fileType & (type)) || header->phEntrySize != sizeof(struct ElfSegmentHeader))
65
66struct ElfHeader
67{
68        char elfMagic[4];
69        BYTE bitness,endian,elfVer,reserved;
70        DWORD reserved2[2];
71        WORD fileType,machine;
72        DWORD elfVer2;
73        DWORD entryPoint;
74        DWORD phOffset;
75        DWORD shOffset;
76        DWORD flags;
77        WORD thisSize,phEntrySize;
78        WORD phEntries,shEntrySize;
79        WORD shEntries,strTabSectionIndex;
80}PACKED;
81
82struct ElfSegmentHeader
83{
84        DWORD type;
85        DWORD fileOffset;
86        DWORD virtualAddr;
87        DWORD physAddr;
88        DWORD fileSize;
89        DWORD memSize;
90        DWORD segFlags;
91        DWORD segAlign;
92}PACKED;
93
94/* Section types. */
95#define SEC_TYPE_SYMTAB         2
96#define SEC_TYPE_STRTAB         3
97#define SEC_TYPE_NOBITS         8
98#define SEC_TYPE_REL            9
99
100/* Section flags. */
101#define SEC_FLAGS_ALLOC         2
102#define SEC_FLAGS_EXEC          4
103
104struct ElfSectionHeader
105{
106        DWORD shName;
107        DWORD shType;
108        DWORD shFlags;
109        DWORD shAddr;
110        DWORD shOffset;
111        DWORD shSize;
112        DWORD shLink;
113        DWORD shInfo;
114        DWORD shAddrAlign;
115        DWORD shEntSize;
116}PACKED;
117
118#define STN_UNDEF       0
119#define STN_ABS         0xFFF1
120#define STN_COMMON      0xFFF2
121
122#define ELF_ST_TYPE(val) ((val) & 0xF)
123
124#define STT_FUNC        2
125
126struct ElfSymbol
127{
128        DWORD symName;
129        DWORD symValue;
130        DWORD symSize;
131        BYTE symInfo;
132        BYTE symOther;
133        WORD symIndex;
134}PACKED;
135
136#define ELF_R_SYM(sym) ((sym) >> 8)
137#define ELF_R_TYPE(sym) ((sym) & 0xFF)
138
139/* Relocation types. */
140#define R_386_NONE      0
141#define R_386_32        1
142#define R_386_PC32      2
143#define R_386_GOT32     3
144#define R_386_PLT32     4
145#define R_386_COPY      5
146#define R_386_GLOB_DAT  6
147#define R_386_JMP_SLOT  7
148#define R_386_RELATIVE  8
149#define R_386_GOTOFF    9
150#define R_386_GOTPC     10
151#define R_386_NUM       11
152
153struct ElfReloc
154{
155        DWORD addr;
156        DWORD info;
157}PACKED;
158
159#endif
Note: See TracBrowser for help on using the browser.