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