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>
17 #include <linux/mman.h>
19 #include <asm/a.out.h>
20 #include <asm/cpufeature.h>
22 #include <asm/pgtable.h>
23 #include <asm/unistd.h>
26 #include <xen/interface/callback.h>
29 extern asmlinkage void sysenter_entry(void);
31 void enable_sep_cpu(void)
33 #ifndef CONFIG_X86_NO_TSS
35 struct tss_struct *tss = &per_cpu(init_tss, cpu);
37 if (!boot_cpu_has(X86_FEATURE_SEP)) {
42 tss->ss1 = __KERNEL_CS;
43 tss->esp1 = sizeof(struct tss_struct) + (unsigned long) tss;
44 wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0);
45 wrmsr(MSR_IA32_SYSENTER_ESP, tss->esp1, 0);
46 wrmsr(MSR_IA32_SYSENTER_EIP, (unsigned long) sysenter_entry, 0);
52 * These symbols are defined by vsyscall.o to mark the bounds
53 * of the ELF DSO images included therein.
55 extern const char vsyscall_int80_start, vsyscall_int80_end;
56 extern const char vsyscall_sysenter_start, vsyscall_sysenter_end;
57 static struct page *sysenter_pages[2];
59 int __init sysenter_setup(void)
61 void *page = (void *)get_zeroed_page(GFP_ATOMIC);
63 sysenter_pages[0] = virt_to_page(page);
66 if (boot_cpu_has(X86_FEATURE_SEP)) {
67 struct callback_register sysenter = {
68 .type = CALLBACKTYPE_sysenter,
69 .address = { __KERNEL_CS, (unsigned long)sysenter_entry },
72 if (HYPERVISOR_callback_op(CALLBACKOP_register, &sysenter) < 0)
73 clear_bit(X86_FEATURE_SEP, boot_cpu_data.x86_capability);
77 if (boot_cpu_has(X86_FEATURE_SEP)) {
79 &vsyscall_sysenter_start,
80 &vsyscall_sysenter_end - &vsyscall_sysenter_start);
85 &vsyscall_int80_start,
86 &vsyscall_int80_end - &vsyscall_int80_start);
91 extern void SYSENTER_RETURN_OFFSET;
93 unsigned int vdso_enabled = 1;
96 * This is called from binfmt_elf, we create the special vma for the
97 * vDSO and insert it into the mm struct tree.
99 int arch_setup_additional_pages(struct linux_binprm *bprm,
100 int executable_stack, unsigned long start_code,
101 unsigned long interp_map_address)
103 struct thread_info *ti = current_thread_info();
104 unsigned long addr = 0, len;
105 unsigned flags = MAP_PRIVATE;
108 current->mm->context.vdso = NULL;
109 if (unlikely(!vdso_enabled) || unlikely(!sysenter_pages[0]))
113 * Map the vDSO (it will be randomized):
115 down_write(¤t->mm->mmap_sem);
116 len = PAGE_SIZE > ELF_EXEC_PAGESIZE ? PAGE_SIZE : ELF_EXEC_PAGESIZE;
117 if (0==exec_shield) { /* off; %cs limit off */
118 addr = STACK_TOP; /* minimal interference with anybody */
119 flags = MAP_PRIVATE | MAP_FIXED;
121 else if ((3<<2) & exec_shield) { /* vdso just below .text */
122 addr = (((2<<2) & exec_shield) && interp_map_address) ?
123 interp_map_address : start_code;
124 /* 1MB for vm86; 64K for vm86 himem */
125 if ((0x110000 + len) <= addr) {
126 addr = (PAGE_MASK & addr) - len;
128 else { /* start_code is too low */
132 addr = get_unmapped_area_prot(NULL, addr, len, 0,
133 flags, PROT_READ | PROT_EXEC);
134 if (unlikely(addr & ~PAGE_MASK)) {
135 up_write(¤t->mm->mmap_sem);
138 err = install_special_mapping(current->mm, addr, len,
139 VM_DONTEXPAND | VM_READ | VM_EXEC |
140 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
143 if (likely(err == 0)) {
144 current->mm->context.vdso = (void *)addr;
145 ti->sysenter_return = &SYSENTER_RETURN_OFFSET + addr;
147 up_write(¤t->mm->mmap_sem);
152 int in_gate_area_no_task(unsigned long addr)
157 int in_gate_area(struct task_struct *task, unsigned long addr)
162 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)