2 * linux/arch/i386/kernel/sysenter.c
4 * (C) Copyright 2002 Linus Torvalds
5 * Portions based on the vdso-randomization code from exec-shield:
6 * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar
8 * This file contains the needed initializations to support sysenter.
11 #include <linux/init.h>
12 #include <linux/smp.h>
13 #include <linux/thread_info.h>
14 #include <linux/sched.h>
15 #include <linux/gfp.h>
16 #include <linux/string.h>
17 #include <linux/elf.h>
19 #include <linux/module.h>
21 #include <asm/cpufeature.h>
23 #include <asm/pgtable.h>
24 #include <asm/unistd.h>
27 * Should the kernel map a VDSO page into processes and pass its
28 * address down to glibc upon exec()?
30 #ifdef CONFIG_PARAVIRT
31 unsigned int __read_mostly vdso_enabled = 0;
33 unsigned int __read_mostly vdso_enabled = 1;
36 EXPORT_SYMBOL_GPL(vdso_enabled);
38 static int __init vdso_setup(char *s)
40 vdso_enabled = simple_strtoul(s, NULL, 0);
45 __setup("vdso=", vdso_setup);
47 extern asmlinkage void sysenter_entry(void);
49 void enable_sep_cpu(void)
52 struct tss_struct *tss = &per_cpu(init_tss, cpu);
54 if (!boot_cpu_has(X86_FEATURE_SEP)) {
59 tss->ss1 = __KERNEL_CS;
60 tss->esp1 = sizeof(struct tss_struct) + (unsigned long) tss;
61 wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
62 wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp1, 0);
63 wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
68 * These symbols are defined by vsyscall.o to mark the bounds
69 * of the ELF DSO images included therein.
71 extern const char vsyscall_int80_start, vsyscall_int80_end;
72 extern const char vsyscall_sysenter_start, vsyscall_sysenter_end;
73 static struct page *syscall_pages[1];
75 int __init sysenter_setup(void)
77 void *syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
78 syscall_pages[0] = virt_to_page(syscall_page);
80 #ifdef CONFIG_COMPAT_VDSO
81 __set_fixmap(FIX_VDSO, __pa(syscall_page), PAGE_READONLY_EXEC);
82 printk("Compat vDSO mapped to %08lx.\n", __fix_to_virt(FIX_VDSO));
85 if (!boot_cpu_has(X86_FEATURE_SEP)) {
87 &vsyscall_int80_start,
88 &vsyscall_int80_end - &vsyscall_int80_start);
93 &vsyscall_sysenter_start,
94 &vsyscall_sysenter_end - &vsyscall_sysenter_start);
99 #ifndef CONFIG_COMPAT_VDSO
100 /* Defined in vsyscall-sysenter.S */
101 extern void SYSENTER_RETURN;
103 /* Setup a VMA at program startup for the vsyscall page */
104 int arch_setup_additional_pages(struct linux_binprm *bprm, int exstack)
106 struct mm_struct *mm = current->mm;
110 down_write(&mm->mmap_sem);
111 addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
112 if (IS_ERR_VALUE(addr)) {
118 * MAYWRITE to allow gdb to COW and set breakpoints
120 * Make sure the vDSO gets into every core dump.
121 * Dumping its contents makes post-mortem fully interpretable later
122 * without matching up the same kernel and hardware config to see
123 * what PC values meant.
125 ret = install_special_mapping(mm, addr, PAGE_SIZE,
127 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
133 current->mm->context.vdso = (void *)addr;
134 current_thread_info()->sysenter_return =
135 (void *)VDSO_SYM(&SYSENTER_RETURN);
137 up_write(&mm->mmap_sem);
141 const char *arch_vma_name(struct vm_area_struct *vma)
143 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
148 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
153 int in_gate_area(struct task_struct *task, unsigned long addr)
158 int in_gate_area_no_task(unsigned long addr)