This stack check implementation leverages the compiler's profiling (gcc -p)
[linux-2.6.git] / include / asm-i386 / elf.h
1 #ifndef __ASMi386_ELF_H
2 #define __ASMi386_ELF_H
3
4 /*
5  * ELF register definitions..
6  */
7
8 #include <asm/ptrace.h>
9 #include <asm/user.h>
10 #include <asm/processor.h>
11 #include <asm/system.h>         /* for savesegment */
12 #include <asm/desc.h>
13
14 #include <linux/utsname.h>
15
16 #define R_386_NONE      0
17 #define R_386_32        1
18 #define R_386_PC32      2
19 #define R_386_GOT32     3
20 #define R_386_PLT32     4
21 #define R_386_COPY      5
22 #define R_386_GLOB_DAT  6
23 #define R_386_JMP_SLOT  7
24 #define R_386_RELATIVE  8
25 #define R_386_GOTOFF    9
26 #define R_386_GOTPC     10
27 #define R_386_NUM       11
28
29 typedef unsigned long elf_greg_t;
30
31 #define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof(elf_greg_t))
32 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
33
34 typedef struct user_i387_struct elf_fpregset_t;
35 typedef struct user_fxsr_struct elf_fpxregset_t;
36
37 /*
38  * This is used to ensure we don't load something for the wrong architecture.
39  */
40 #define elf_check_arch(x) \
41         (((x)->e_machine == EM_386) || ((x)->e_machine == EM_486))
42
43 /*
44  * These are used to set parameters in the core dumps.
45  */
46 #define ELF_CLASS       ELFCLASS32
47 #define ELF_DATA        ELFDATA2LSB
48 #define ELF_ARCH        EM_386
49
50 /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts %edx
51    contains a pointer to a function which might be registered using `atexit'.
52    This provides a mean for the dynamic linker to call DT_FINI functions for
53    shared libraries that have been loaded before the code runs.
54
55    A value of 0 tells we have no such handler. 
56
57    We might as well make sure everything else is cleared too (except for %esp),
58    just to make things more deterministic.
59  */
60 #define ELF_PLAT_INIT(_r, load_addr)    do { \
61         _r->ebx = 0; _r->ecx = 0; _r->edx = 0; \
62         _r->esi = 0; _r->edi = 0; _r->ebp = 0; \
63         _r->eax = 0; \
64 } while (0)
65
66 #define USE_ELF_CORE_DUMP
67 #define ELF_EXEC_PAGESIZE       4096
68
69 /* This is the location that an ET_DYN program is loaded if exec'ed.  Typical
70    use of this is to invoke "./ld.so someprog" to test out a new version of
71    the loader.  We need to make sure that it is out of the way of the program
72    that it will "exec", and that there is sufficient room for the brk.  */
73
74 #define ELF_ET_DYN_BASE         (TASK_SIZE / 3 * 2)
75
76 /* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
77    now struct_user_regs, they are different) */
78
79 #define ELF_CORE_COPY_REGS(pr_reg, regs)                \
80         pr_reg[0] = regs->ebx;                          \
81         pr_reg[1] = regs->ecx;                          \
82         pr_reg[2] = regs->edx;                          \
83         pr_reg[3] = regs->esi;                          \
84         pr_reg[4] = regs->edi;                          \
85         pr_reg[5] = regs->ebp;                          \
86         pr_reg[6] = regs->eax;                          \
87         pr_reg[7] = regs->xds;                          \
88         pr_reg[8] = regs->xes;                          \
89         savesegment(fs,pr_reg[9]);                      \
90         savesegment(gs,pr_reg[10]);                     \
91         pr_reg[11] = regs->orig_eax;                    \
92         pr_reg[12] = regs->eip;                         \
93         pr_reg[13] = regs->xcs;                         \
94         pr_reg[14] = regs->eflags;                      \
95         pr_reg[15] = regs->esp;                         \
96         pr_reg[16] = regs->xss;
97
98 /* This yields a mask that user programs can use to figure out what
99    instruction set this CPU supports.  This could be done in user space,
100    but it's not easy, and we've already done it here.  */
101
102 #define ELF_HWCAP       (boot_cpu_data.x86_capability[0])
103
104 /* This yields a string that ld.so will use to load implementation
105    specific libraries for optimization.  This is more specific in
106    intent than poking at uname or /proc/cpuinfo.
107
108    For the moment, we have only optimizations for the Intel generations,
109    but that could change... */
110
111 #define ELF_PLATFORM  (system_utsname.machine)
112
113 /*
114  * Architecture-neutral AT_ values in 0-17, leave some room
115  * for more of them, start the x86-specific ones at 32.
116  */
117 #define AT_SYSINFO              32
118 #define AT_SYSINFO_EHDR         33
119
120 #ifdef __KERNEL__
121 #define SET_PERSONALITY(ex, ibcs2) do { } while (0)
122
123 /*
124  * An executable for which elf_read_implies_exec() returns TRUE will
125  * have the READ_IMPLIES_EXEC personality flag set automatically.
126  */
127 #define elf_read_implies_exec_binary(ex, have_pt_gnu_stack)     (!(have_pt_gnu_stack))
128
129 extern int dump_task_regs (struct task_struct *, elf_gregset_t *);
130 extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *);
131 extern int dump_task_extended_fpu (struct task_struct *, struct user_fxsr_struct *);
132
133 #define ELF_CORE_COPY_TASK_REGS(tsk, elf_regs) dump_task_regs(tsk, elf_regs)
134 #define ELF_CORE_COPY_FPREGS(tsk, elf_fpregs) dump_task_fpu(tsk, elf_fpregs)
135 #define ELF_CORE_COPY_XFPREGS(tsk, elf_xfpregs) dump_task_extended_fpu(tsk, elf_xfpregs)
136
137 extern void __kernel_vsyscall;
138 #define VSYSCALL_BASE   ((unsigned long)current->mm->context.vdso)
139 #define VSYSCALL_EHDR   ((const struct elfhdr *) VSYSCALL_BASE)
140 #define VSYSCALL_OFFSET ((unsigned long) &__kernel_vsyscall)
141 #define VSYSCALL_ENTRY  (VSYSCALL_BASE + VSYSCALL_OFFSET)
142
143 /* kernel-internal fixmap address: */
144 #define __VSYSCALL_BASE (__fix_to_virt(FIX_VSYSCALL))
145 #define __VSYSCALL_EHDR ((const struct elfhdr *) __VSYSCALL_BASE)
146
147 #define ARCH_DLINFO                                                     \
148 do {                                                                    \
149         if (VSYSCALL_BASE) {                                            \
150                 NEW_AUX_ENT(AT_SYSINFO, VSYSCALL_ENTRY);                \
151                 NEW_AUX_ENT(AT_SYSINFO_EHDR, VSYSCALL_BASE);            \
152         }                                                               \
153 } while (0)
154
155 /*
156  * These macros parameterize elf_core_dump in fs/binfmt_elf.c to write out
157  * extra segments containing the vsyscall DSO contents.  Dumping its
158  * contents makes post-mortem fully interpretable later without matching up
159  * the same kernel and hardware config to see what PC values meant.
160  * Dumping its extra ELF program headers includes all the other information
161  * a debugger needs to easily find how the vsyscall DSO was being used.
162  */
163 #define ELF_CORE_EXTRA_PHDRS            (__VSYSCALL_EHDR->e_phnum)
164 #define ELF_CORE_WRITE_EXTRA_PHDRS                                            \
165 do {                                                                          \
166         const struct elf_phdr *const vsyscall_phdrs =                         \
167                 (const struct elf_phdr *) (__VSYSCALL_BASE                    \
168                                            + __VSYSCALL_EHDR->e_phoff);       \
169         int i;                                                                \
170         Elf32_Off ofs = 0;                                                    \
171         for (i = 0; i < __VSYSCALL_EHDR->e_phnum; ++i) {                      \
172                 struct elf_phdr phdr = vsyscall_phdrs[i];                     \
173                 if (phdr.p_type == PT_LOAD) {                                 \
174                         BUG_ON(ofs != 0);                                     \
175                         ofs = phdr.p_offset = offset;                         \
176                         phdr.p_memsz = PAGE_ALIGN(phdr.p_memsz);              \
177                         phdr.p_filesz = phdr.p_memsz;                         \
178                         offset += phdr.p_filesz;                              \
179                 }                                                             \
180                 else                                                          \
181                         phdr.p_offset += ofs;                                 \
182                 phdr.p_paddr = 0; /* match other core phdrs */                \
183                 DUMP_WRITE(&phdr, sizeof(phdr));                              \
184         }                                                                     \
185 } while (0)
186 #define ELF_CORE_WRITE_EXTRA_DATA                                             \
187 do {                                                                          \
188         const struct elf_phdr *const vsyscall_phdrs =                         \
189                 (const struct elf_phdr *) (__VSYSCALL_BASE                    \
190                                            + __VSYSCALL_EHDR->e_phoff);       \
191         int i;                                                                \
192         for (i = 0; i < __VSYSCALL_EHDR->e_phnum; ++i) {                      \
193                 if (vsyscall_phdrs[i].p_type == PT_LOAD)                      \
194                         DUMP_WRITE((void *) vsyscall_phdrs[i].p_vaddr,        \
195                                    PAGE_ALIGN(vsyscall_phdrs[i].p_memsz));    \
196         }                                                                     \
197 } while (0)
198
199 #endif
200
201 #define __HAVE_ARCH_RANDOMIZE_BRK
202 extern void randomize_brk(unsigned long old_brk);
203
204 #define __HAVE_ARCH_VSYSCALL
205 extern void map_vsyscall(void);
206
207 #endif