2 * linux/arch/i386/kernel/sysenter.c
4 * (C) Copyright 2002 Linus Torvalds
6 * This file contains the needed initializations to support sysenter.
9 #include <linux/init.h>
10 #include <linux/smp.h>
11 #include <linux/thread_info.h>
12 #include <linux/sched.h>
13 #include <linux/gfp.h>
14 #include <linux/string.h>
15 #include <linux/elf.h>
16 #include <linux/mman.h>
18 #include <asm/a.out.h>
19 #include <asm/cpufeature.h>
21 #include <asm/pgtable.h>
22 #include <asm/unistd.h>
24 extern asmlinkage void sysenter_entry(void);
26 void enable_sep_cpu(void)
29 struct tss_struct *tss = &per_cpu(init_tss, cpu);
31 if (!boot_cpu_has(X86_FEATURE_SEP)) {
36 tss->ss1 = __KERNEL_CS;
37 tss->esp1 = sizeof(struct tss_struct) + (unsigned long) tss;
38 wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
39 wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp1, 0);
40 wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
45 * These symbols are defined by vsyscall.o to mark the bounds
46 * of the ELF DSO images included therein.
48 extern const char vsyscall_int80_start, vsyscall_int80_end;
49 extern const char vsyscall_sysenter_start, vsyscall_sysenter_end;
51 static struct page *sysenter_pages[2];
53 int __init sysenter_setup(void)
55 void *page = (void *)get_zeroed_page(GFP_ATOMIC);
57 sysenter_pages[0] = virt_to_page(page);
59 if (!boot_cpu_has(X86_FEATURE_SEP)) {
61 &vsyscall_int80_start,
62 &vsyscall_int80_end - &vsyscall_int80_start);
67 &vsyscall_sysenter_start,
68 &vsyscall_sysenter_end - &vsyscall_sysenter_start);
73 extern void SYSENTER_RETURN_OFFSET;
75 unsigned int vdso_enabled = 1;
78 * This is called from binfmt_elf, we create the special vma for the
79 * vDSO and insert it into the mm struct tree.
81 int arch_setup_additional_pages(struct linux_binprm *bprm,
82 int executable_stack, unsigned long start_code,
83 unsigned long interp_map_address)
85 struct thread_info *ti = current_thread_info();
86 unsigned long addr = 0, len;
87 unsigned flags = MAP_PRIVATE;
90 current->mm->context.vdso = NULL;
91 if (unlikely(!vdso_enabled) || unlikely(!sysenter_pages[0]))
95 * Map the vDSO (it will be randomized):
97 down_write(¤t->mm->mmap_sem);
98 len = PAGE_SIZE > ELF_EXEC_PAGESIZE ? PAGE_SIZE : ELF_EXEC_PAGESIZE;
99 if (0==exec_shield) { /* off; %cs limit off */
100 addr = STACK_TOP; /* minimal interference with anybody */
101 flags = MAP_PRIVATE | MAP_FIXED;
103 else if ((3<<2) & exec_shield) { /* vdso just below .text */
104 addr = (((2<<2) & exec_shield) && interp_map_address) ?
105 interp_map_address : start_code;
106 /* 1MB for vm86; 64K for vm86 himem */
107 if ((0x110000 + len) <= addr) {
108 addr = (PAGE_MASK & addr) - len;
110 else { /* start_code is too low */
114 addr = get_unmapped_area_prot(NULL, addr, len, 0,
115 flags, PROT_READ | PROT_EXEC);
116 if (unlikely(addr & ~PAGE_MASK)) {
117 up_write(¤t->mm->mmap_sem);
120 err = install_special_mapping(current->mm, addr, len,
121 VM_DONTEXPAND | VM_READ | VM_EXEC |
122 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
125 if (likely(err == 0)) {
126 current->mm->context.vdso = (void *)addr;
127 ti->sysenter_return = &SYSENTER_RETURN_OFFSET + addr;
129 up_write(¤t->mm->mmap_sem);
133 int in_gate_area_no_task(unsigned long addr)
138 int in_gate_area(struct task_struct *task, unsigned long addr)
143 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)