- Updated to 2.6.22-rc2-git7:
[linux-flexiantxendom0-3.2.10.git] / arch / x86_64 / ia32 / syscall32-xen.c
1 /* 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>
12 #include <linux/security.h>
13 #include <asm/proto.h>
14 #include <asm/tlbflush.h>
15 #include <asm/ia32_unistd.h>
16
17 #ifdef USE_INT80
18 extern unsigned char syscall32_int80[], syscall32_int80_end[];
19 #endif
20 extern unsigned char syscall32_syscall[], syscall32_syscall_end[];
21 extern unsigned char syscall32_sysenter[], syscall32_sysenter_end[];
22 extern int sysctl_vsyscall32;
23
24 static struct page *syscall32_pages[1];
25 #ifndef USE_INT80
26 static int use_sysenter = -1;
27 #endif
28
29 struct linux_binprm;
30
31 /* Setup a VMA at program startup for the vsyscall page */
32 int syscall32_setup_pages(struct linux_binprm *bprm, int exstack)
33 {
34         struct mm_struct *mm = current->mm;
35         int ret;
36
37         down_write(&mm->mmap_sem);
38         /*
39          * MAYWRITE to allow gdb to COW and set breakpoints
40          *
41          * Make sure the vDSO gets into every core dump.
42          * Dumping its contents makes post-mortem fully interpretable later
43          * without matching up the same kernel and hardware config to see
44          * what PC values meant.
45          */
46         /* Could randomize here */
47         ret = install_special_mapping(mm, VSYSCALL32_BASE, PAGE_SIZE,
48                                       VM_READ|VM_EXEC|
49                                       VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
50                                       VM_ALWAYSDUMP,
51                                       syscall32_pages);
52         up_write(&mm->mmap_sem);
53         return ret;
54 }
55
56 const char *arch_vma_name(struct vm_area_struct *vma)
57 {
58         if (vma->vm_start == VSYSCALL32_BASE &&
59             vma->vm_mm && vma->vm_mm->task_size == IA32_PAGE_OFFSET)
60                 return "[vdso]";
61         return NULL;
62 }
63
64 static int __init init_syscall32(void)
65
66         char *syscall32_page = (void *)get_zeroed_page(GFP_KERNEL);
67         if (!syscall32_page) 
68                 panic("Cannot allocate syscall32 page"); 
69
70         syscall32_pages[0] = virt_to_page(syscall32_page);
71 #ifdef USE_INT80
72         /*
73          * At this point we use int 0x80.
74          */
75         memcpy(syscall32_page, syscall32_int80,
76                syscall32_int80_end - syscall32_int80);
77 #else
78         if (use_sysenter > 0) {
79                 memcpy(syscall32_page, syscall32_sysenter,
80                        syscall32_sysenter_end - syscall32_sysenter);
81         } else {
82                 memcpy(syscall32_page, syscall32_syscall,
83                        syscall32_syscall_end - syscall32_syscall);
84         }       
85 #endif
86         return 0;
87
88
89 /*
90  * This must be done early in case we have an initrd containing 32-bit
91  * binaries (e.g., hotplug). This could be pushed upstream to arch/x86_64.
92  */     
93 core_initcall(init_syscall32); 
94
95 /* May not be __init: called during resume */
96 void syscall32_cpu_init(void)
97 {
98 #ifndef USE_INT80
99         if (use_sysenter < 0)
100                 use_sysenter = (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL);
101
102         /* Load these always in case some future AMD CPU supports
103            SYSENTER from compat mode too. */
104         checking_wrmsrl(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
105         checking_wrmsrl(MSR_IA32_SYSENTER_ESP, 0ULL);
106         checking_wrmsrl(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
107
108         wrmsrl(MSR_CSTAR, ia32_cstar_target);
109 #endif
110 }