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 unsigned int __read_mostly vdso_enabled = 1;
32 EXPORT_SYMBOL_GPL(vdso_enabled);
34 static int __init vdso_setup(char *s)
36 vdso_enabled = simple_strtoul(s, NULL, 0);
41 __setup("vdso=", vdso_setup);
43 extern asmlinkage void sysenter_entry(void);
45 void enable_sep_cpu(void)
48 struct tss_struct *tss = &per_cpu(init_tss, cpu);
50 if (!boot_cpu_has(X86_FEATURE_SEP)) {
55 tss->ss1 = __KERNEL_CS;
56 tss->esp1 = sizeof(struct tss_struct) + (unsigned long) tss;
57 wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
58 wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp1, 0);
59 wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
64 * These symbols are defined by vsyscall.o to mark the bounds
65 * of the ELF DSO images included therein.
67 extern const char vsyscall_int80_start, vsyscall_int80_end;
68 extern const char vsyscall_sysenter_start, vsyscall_sysenter_end;
69 static void *syscall_page;
71 int __init sysenter_setup(void)
73 syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
75 #ifdef CONFIG_COMPAT_VDSO
76 __set_fixmap(FIX_VDSO, __pa(syscall_page), PAGE_READONLY);
77 printk("Compat vDSO mapped to %08lx.\n", __fix_to_virt(FIX_VDSO));
80 * In the non-compat case the ELF coredumping code needs the fixmap:
82 __set_fixmap(FIX_VDSO, __pa(syscall_page), PAGE_KERNEL_RO);
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 static struct page *syscall_nopage(struct vm_area_struct *vma,
100 unsigned long adr, int *type)
102 struct page *p = virt_to_page(adr - vma->vm_start + syscall_page);
107 /* Prevent VMA merging */
108 static void syscall_vma_close(struct vm_area_struct *vma)
112 static struct vm_operations_struct syscall_vm_ops = {
113 .close = syscall_vma_close,
114 .nopage = syscall_nopage,
117 /* Defined in vsyscall-sysenter.S */
118 extern void SYSENTER_RETURN;
120 /* Setup a VMA at program startup for the vsyscall page */
121 int arch_setup_additional_pages(struct linux_binprm *bprm, int exstack)
123 struct vm_area_struct *vma;
124 struct mm_struct *mm = current->mm;
128 down_write(&mm->mmap_sem);
129 addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
130 if (IS_ERR_VALUE(addr)) {
135 vma = kmem_cache_zalloc(vm_area_cachep, SLAB_KERNEL);
141 vma->vm_start = addr;
142 vma->vm_end = addr + PAGE_SIZE;
143 /* MAYWRITE to allow gdb to COW and set breakpoints */
144 vma->vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC|VM_MAYWRITE;
145 vma->vm_flags |= mm->def_flags;
146 vma->vm_page_prot = protection_map[vma->vm_flags & 7];
147 vma->vm_ops = &syscall_vm_ops;
150 ret = insert_vm_struct(mm, vma);
152 kmem_cache_free(vm_area_cachep, vma);
156 current->mm->context.vdso = (void *)addr;
157 current_thread_info()->sysenter_return =
158 (void *)VDSO_SYM(&SYSENTER_RETURN);
161 up_write(&mm->mmap_sem);
165 const char *arch_vma_name(struct vm_area_struct *vma)
167 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
172 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
177 int in_gate_area(struct task_struct *task, unsigned long addr)
182 int in_gate_area_no_task(unsigned long addr)