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/cpufeature.h>
20 #include <asm/pgtable.h>
21 #include <asm/unistd.h>
23 extern asmlinkage void sysenter_entry(void);
25 void enable_sep_cpu(void *info)
28 struct tss_struct *tss = &per_cpu(init_tss, cpu);
30 tss->ss1 = __KERNEL_CS;
31 tss->esp1 = sizeof(struct tss_struct) + (unsigned long) tss;
32 wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
33 wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp1, 0);
34 wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
39 * These symbols are defined by vsyscall.o to mark the bounds
40 * of the ELF DSO images included therein.
42 extern const char vsyscall_int80_start, vsyscall_int80_end;
43 extern const char vsyscall_sysenter_start, vsyscall_sysenter_end;
45 struct page *sysenter_page;
47 static int __init sysenter_setup(void)
49 void *page = (void *)get_zeroed_page(GFP_ATOMIC);
51 __set_fixmap(FIX_VSYSCALL, __pa(page), PAGE_KERNEL_RO);
52 sysenter_page = virt_to_page(page);
54 if (!boot_cpu_has(X86_FEATURE_SEP)) {
56 &vsyscall_int80_start,
57 &vsyscall_int80_end - &vsyscall_int80_start);
62 &vsyscall_sysenter_start,
63 &vsyscall_sysenter_end - &vsyscall_sysenter_start);
65 on_each_cpu(enable_sep_cpu, NULL, 1, 1);
70 __initcall(sysenter_setup);
72 extern void SYSENTER_RETURN_OFFSET;
74 unsigned int vdso_enabled = 0;
76 void map_vsyscall(void)
78 struct thread_info *ti = current_thread_info();
79 struct vm_area_struct *vma;
82 if (unlikely(!vdso_enabled)) {
83 current->mm->context.vdso = NULL;
88 * Map the vDSO (it will be randomized):
90 down_write(¤t->mm->mmap_sem);
91 addr = do_mmap(NULL, 0, 4096, PROT_READ | PROT_EXEC, MAP_PRIVATE, 0);
92 current->mm->context.vdso = (void *)addr;
93 ti->sysenter_return = (void *)addr + (long)&SYSENTER_RETURN_OFFSET;
95 vma = find_vma(current->mm, addr);
97 pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
98 get_page(sysenter_page);
99 install_page(current->mm, vma, addr,
100 sysenter_page, vma->vm_page_prot);
104 up_write(¤t->mm->mmap_sem);
107 static int __init vdso_setup(char *str)
109 vdso_enabled = simple_strtoul(str, NULL, 0);
112 __setup("vdso=", vdso_setup);