4 * Copyright (C) 1999 Arun Sharma <arun.sharma@intel.com>
5 * Copyright (C) 2001 Hewlett-Packard Co
6 * David Mosberger-Tang <davidm@hpl.hp.com>
8 * 06/16/00 A. Mallick initialize csd/ssd/tssd/cflg for ia32_load_state
9 * 04/13/01 D. Mosberger dropped saving tssd in ar.k1---it's not needed
10 * 09/14/01 D. Mosberger fixed memory management for gdt/tss page
13 #include <linux/types.h>
15 #include <linux/security.h>
17 #include <asm/param.h>
18 #include <asm/signal.h>
21 #include "elfcore32.h"
23 /* Override some function names */
25 #define start_thread ia32_start_thread
26 #define elf_format elf32_format
27 #define init_elf_binfmt init_elf32_binfmt
28 #define exit_elf_binfmt exit_elf32_binfmt
31 #define CLOCKS_PER_SEC IA32_CLOCKS_PER_SEC
33 extern void ia64_elf32_init (struct pt_regs
*regs
);
35 static void elf32_set_personality (void);
37 static unsigned long __attribute ((unused
))
38 randomize_stack_top(unsigned long stack_top
);
40 #define setup_arg_pages(bprm,tos,exec) ia32_setup_arg_pages(bprm,exec)
41 #define elf_map elf32_map
43 #undef SET_PERSONALITY
44 #define SET_PERSONALITY(ex, ibcs2) elf32_set_personality()
46 #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
48 /* Ugly but avoids duplication */
49 #include "../../../fs/binfmt_elf.c"
51 extern struct page
*ia32_shared_page
[];
52 extern unsigned long *ia32_gdt
;
53 extern struct page
*ia32_gate_page
;
56 ia32_install_shared_page (struct vm_area_struct
*vma
, unsigned long address
, int *type
)
58 struct page
*pg
= ia32_shared_page
[smp_processor_id()];
61 *type
= VM_FAULT_MINOR
;
66 ia32_install_gate_page (struct vm_area_struct
*vma
, unsigned long address
, int *type
)
68 struct page
*pg
= ia32_gate_page
;
71 *type
= VM_FAULT_MINOR
;
76 static struct vm_operations_struct ia32_shared_page_vm_ops
= {
77 .nopage
= ia32_install_shared_page
80 static struct vm_operations_struct ia32_gate_page_vm_ops
= {
81 .nopage
= ia32_install_gate_page
85 ia64_elf32_init (struct pt_regs
*regs
)
87 struct vm_area_struct
*vma
;
90 * Map GDT below 4GB, where the processor can find it. We need to map
91 * it with privilege level 3 because the IVE uses non-privileged accesses to these
92 * tables. IA-32 segmentation is used to protect against IA-32 accesses to them.
94 vma
= kmem_cache_zalloc(vm_area_cachep
, GFP_KERNEL
);
96 vma
->vm_mm
= current
->mm
;
97 vma
->vm_start
= IA32_GDT_OFFSET
;
98 vma
->vm_end
= vma
->vm_start
+ PAGE_SIZE
;
99 vma
->vm_page_prot
= PAGE_SHARED
;
100 vma
->vm_flags
= VM_READ
|VM_MAYREAD
|VM_RESERVED
;
101 vma
->vm_ops
= &ia32_shared_page_vm_ops
;
102 down_write(¤t
->mm
->mmap_sem
);
104 if (insert_vm_struct(current
->mm
, vma
)) {
105 kmem_cache_free(vm_area_cachep
, vma
);
106 up_write(¤t
->mm
->mmap_sem
);
110 up_write(¤t
->mm
->mmap_sem
);
114 * When user stack is not executable, push sigreturn code to stack makes
115 * segmentation fault raised when returning to kernel. So now sigreturn
116 * code is locked in specific gate page, which is pointed by pretcode
117 * when setup_frame_ia32
119 vma
= kmem_cache_zalloc(vm_area_cachep
, GFP_KERNEL
);
121 vma
->vm_mm
= current
->mm
;
122 vma
->vm_start
= IA32_GATE_OFFSET
;
123 vma
->vm_end
= vma
->vm_start
+ PAGE_SIZE
;
124 vma
->vm_page_prot
= PAGE_COPY_EXEC
;
125 vma
->vm_flags
= VM_READ
| VM_MAYREAD
| VM_EXEC
126 | VM_MAYEXEC
| VM_RESERVED
;
127 vma
->vm_ops
= &ia32_gate_page_vm_ops
;
128 down_write(¤t
->mm
->mmap_sem
);
130 if (insert_vm_struct(current
->mm
, vma
)) {
131 kmem_cache_free(vm_area_cachep
, vma
);
132 up_write(¤t
->mm
->mmap_sem
);
136 up_write(¤t
->mm
->mmap_sem
);
140 * Install LDT as anonymous memory. This gives us all-zero segment descriptors
141 * until a task modifies them via modify_ldt().
143 vma
= kmem_cache_zalloc(vm_area_cachep
, GFP_KERNEL
);
145 vma
->vm_mm
= current
->mm
;
146 vma
->vm_start
= IA32_LDT_OFFSET
;
147 vma
->vm_end
= vma
->vm_start
+ PAGE_ALIGN(IA32_LDT_ENTRIES
*IA32_LDT_ENTRY_SIZE
);
148 vma
->vm_page_prot
= PAGE_SHARED
;
149 vma
->vm_flags
= VM_READ
|VM_WRITE
|VM_MAYREAD
|VM_MAYWRITE
;
150 down_write(¤t
->mm
->mmap_sem
);
152 if (insert_vm_struct(current
->mm
, vma
)) {
153 kmem_cache_free(vm_area_cachep
, vma
);
154 up_write(¤t
->mm
->mmap_sem
);
158 up_write(¤t
->mm
->mmap_sem
);
161 ia64_psr(regs
)->ac
= 0; /* turn off alignment checking */
164 * According to the ABI %edx points to an `atexit' handler. Since we don't have
165 * one we'll set it to 0 and initialize all the other registers just to make
166 * things more deterministic, ala the i386 implementation.
168 regs
->r8
= 0; /* %eax */
169 regs
->r11
= 0; /* %ebx */
170 regs
->r9
= 0; /* %ecx */
171 regs
->r10
= 0; /* %edx */
172 regs
->r13
= 0; /* %ebp */
173 regs
->r14
= 0; /* %esi */
174 regs
->r15
= 0; /* %edi */
176 current
->thread
.eflag
= IA32_EFLAG
;
177 current
->thread
.fsr
= IA32_FSR_DEFAULT
;
178 current
->thread
.fcr
= IA32_FCR_DEFAULT
;
179 current
->thread
.fir
= 0;
180 current
->thread
.fdr
= 0;
183 * Setup GDTD. Note: GDTD is the descrambled version of the pseudo-descriptor
184 * format defined by Figure 3-11 "Pseudo-Descriptor Format" in the IA-32
185 * architecture manual. Also note that the only fields that are not ignored are
186 * `base', `limit', 'G', `P' (must be 1) and `S' (must be 0).
188 regs
->r31
= IA32_SEG_UNSCRAMBLE(IA32_SEG_DESCRIPTOR(IA32_GDT_OFFSET
, IA32_PAGE_SIZE
- 1,
189 0, 0, 0, 1, 0, 0, 0));
190 /* Setup the segment selectors */
191 regs
->r16
= (__USER_DS
<< 16) | __USER_DS
; /* ES == DS, GS, FS are zero */
192 regs
->r17
= (__USER_DS
<< 16) | __USER_CS
; /* SS, CS; ia32_load_state() sets TSS and LDT */
194 ia32_load_segment_descriptors(current
);
195 ia32_load_state(current
);
199 * Undo the override of setup_arg_pages() without this ia32_setup_arg_pages()
200 * will suffer infinite self recursion.
202 #undef setup_arg_pages
205 ia32_setup_arg_pages (struct linux_binprm
*bprm
, int executable_stack
)
209 ret
= setup_arg_pages(bprm
, IA32_STACK_TOP
, executable_stack
);
212 * Can't do it in ia64_elf32_init(). Needs to be done before
213 * calls to elf32_map()
215 current
->thread
.ppl
= ia32_init_pp_list();
222 elf32_set_personality (void)
224 set_personality(PER_LINUX32
);
225 current
->thread
.map_base
= IA32_PAGE_OFFSET
/3;
229 elf32_map (struct file
*filep
, unsigned long addr
, struct elf_phdr
*eppnt
, int prot
, int type
)
231 unsigned long pgoff
= (eppnt
->p_vaddr
) & ~IA32_PAGE_MASK
;
233 return ia32_do_mmap(filep
, (addr
& IA32_PAGE_MASK
), eppnt
->p_filesz
+ pgoff
, prot
, type
,
234 eppnt
->p_offset
- pgoff
);
237 #define cpu_uses_ia32el() (local_cpu_data->family > 0x1f)
239 static int __init
check_elf32_binfmt(void)
241 if (cpu_uses_ia32el()) {
242 printk("Please use IA-32 EL for executing IA-32 binaries\n");
243 unregister_binfmt(&elf_format
);
248 module_init(check_elf32_binfmt
)