2 * Copyright 2002,2003 Andi Kleen, SuSE Labs
4 * vsyscall handling for 32bit processes. Map a stub page into it on
5 * demand because 32bit cannot reach the kernel's fixmaps
8 #include <linux/string.h>
9 #include <linux/kernel.h>
10 #include <linux/gfp.h>
11 #include <linux/init.h>
12 #include <linux/stringify.h>
13 #include <linux/security.h>
14 #include <asm/proto.h>
15 #include <asm/tlbflush.h>
16 #include <asm/ia32_unistd.h>
17 #include <asm/vsyscall32.h>
19 extern unsigned char syscall32_syscall[], syscall32_syscall_end[];
20 extern unsigned char syscall32_sysenter[], syscall32_sysenter_end[];
21 extern int sysctl_vsyscall32;
23 static struct page *syscall32_pages[1];
24 static int use_sysenter = -1;
28 /* Setup a VMA at program startup for the vsyscall page */
29 int syscall32_setup_pages(struct linux_binprm *bprm, int exstack)
31 struct mm_struct *mm = current->mm;
34 down_write(&mm->mmap_sem);
36 * MAYWRITE to allow gdb to COW and set breakpoints
38 * Make sure the vDSO gets into every core dump.
39 * Dumping its contents makes post-mortem fully interpretable later
40 * without matching up the same kernel and hardware config to see
41 * what PC values meant.
43 /* Could randomize here */
44 ret = install_special_mapping(mm, VSYSCALL32_BASE, PAGE_SIZE,
46 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
49 up_write(&mm->mmap_sem);
53 static int __init init_syscall32(void)
55 char *syscall32_page = (void *)get_zeroed_page(GFP_KERNEL);
58 panic("Cannot allocate syscall32 page");
59 syscall32_pages[0] = virt_to_page(syscall32_page);
60 if (use_sysenter > 0) {
61 memcpy(syscall32_page, syscall32_sysenter,
62 syscall32_sysenter_end - syscall32_sysenter);
64 memcpy(syscall32_page, syscall32_syscall,
65 syscall32_syscall_end - syscall32_syscall);
69 __initcall(init_syscall32);
71 /* May not be __init: called during resume */
72 void syscall32_cpu_init(void)
75 use_sysenter = (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL);
78 * Load these always in case some future AMD CPU supports
79 * SYSENTER from compat mode too.
81 checking_wrmsrl(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
82 checking_wrmsrl(MSR_IA32_SYSENTER_ESP, 0ULL);
83 checking_wrmsrl(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
85 wrmsrl(MSR_CSTAR, ia32_cstar_target);