blob: 568ff0df89e7800412017c349e3e138aba5218fb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Copyright 2002,2003 Andi Kleen, SuSE Labs */
2
3/* vsyscall handling for 32bit processes. Map a stub page into it
4 on demand because 32bit cannot reach the kernel's fixmaps */
5
6#include <linux/mm.h>
7#include <linux/string.h>
8#include <linux/kernel.h>
9#include <linux/gfp.h>
10#include <linux/init.h>
11#include <linux/stringify.h>
Andi Kleen1e014412005-04-16 15:24:55 -070012#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/proto.h>
14#include <asm/tlbflush.h>
15#include <asm/ia32_unistd.h>
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017extern unsigned char syscall32_syscall[], syscall32_syscall_end[];
18extern unsigned char syscall32_sysenter[], syscall32_sysenter_end[];
19extern int sysctl_vsyscall32;
20
Roland McGrathdc5882b2007-02-08 14:20:43 -080021static struct page *syscall32_pages[1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static int use_sysenter = -1;
23
Andi Kleen1e014412005-04-16 15:24:55 -070024struct linux_binprm;
25
26/* Setup a VMA at program startup for the vsyscall page */
27int syscall32_setup_pages(struct linux_binprm *bprm, int exstack)
28{
Andi Kleen1e014412005-04-16 15:24:55 -070029 struct mm_struct *mm = current->mm;
Siddha, Suresh B9fb17592005-07-15 19:17:44 -070030 int ret;
Andi Kleen1e014412005-04-16 15:24:55 -070031
Roland McGrathdc5882b2007-02-08 14:20:43 -080032 down_write(&mm->mmap_sem);
Roland McGrathe03f0ca2007-01-26 00:56:50 -080033 /*
Roland McGrathdc5882b2007-02-08 14:20:43 -080034 * MAYWRITE to allow gdb to COW and set breakpoints
35 *
Roland McGrathe03f0ca2007-01-26 00:56:50 -080036 * 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.
40 */
Roland McGrathdc5882b2007-02-08 14:20:43 -080041 /* Could randomize here */
42 ret = install_special_mapping(mm, VSYSCALL32_BASE, PAGE_SIZE,
43 VM_READ|VM_EXEC|
44 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
45 VM_ALWAYSDUMP,
46 syscall32_pages);
Andi Kleen1e014412005-04-16 15:24:55 -070047 up_write(&mm->mmap_sem);
Roland McGrathdc5882b2007-02-08 14:20:43 -080048 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Roland McGrathc6330902007-01-26 00:56:52 -080051const char *arch_vma_name(struct vm_area_struct *vma)
52{
53 if (vma->vm_start == VSYSCALL32_BASE &&
54 vma->vm_mm && vma->vm_mm->task_size == IA32_PAGE_OFFSET)
55 return "[vdso]";
56 return NULL;
57}
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059static int __init init_syscall32(void)
60{
Roland McGrathdc5882b2007-02-08 14:20:43 -080061 char *syscall32_page = (void *)get_zeroed_page(GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 if (!syscall32_page)
63 panic("Cannot allocate syscall32 page");
Roland McGrathdc5882b2007-02-08 14:20:43 -080064 syscall32_pages[0] = virt_to_page(syscall32_page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 if (use_sysenter > 0) {
66 memcpy(syscall32_page, syscall32_sysenter,
67 syscall32_sysenter_end - syscall32_sysenter);
68 } else {
69 memcpy(syscall32_page, syscall32_syscall,
70 syscall32_syscall_end - syscall32_syscall);
71 }
72 return 0;
73}
74
75__initcall(init_syscall32);
76
77/* May not be __init: called during resume */
78void syscall32_cpu_init(void)
79{
80 if (use_sysenter < 0)
81 use_sysenter = (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL);
82
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);
88
89 wrmsrl(MSR_CSTAR, ia32_cstar_target);
90}