[PATCH] slab: remove SLAB_KERNEL
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / x86_64 / ia32 / syscall32.c
CommitLineData
1da177e4
LT
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>
1e014410 12#include <linux/security.h>
1da177e4
LT
13#include <asm/proto.h>
14#include <asm/tlbflush.h>
15#include <asm/ia32_unistd.h>
16
1da177e4
LT
17extern unsigned char syscall32_syscall[], syscall32_syscall_end[];
18extern unsigned char syscall32_sysenter[], syscall32_sysenter_end[];
19extern int sysctl_vsyscall32;
20
21char *syscall32_page;
22static int use_sysenter = -1;
23
1e014410
AK
24static struct page *
25syscall32_nopage(struct vm_area_struct *vma, unsigned long adr, int *type)
26{
27 struct page *p = virt_to_page(adr - vma->vm_start + syscall32_page);
28 get_page(p);
29 return p;
1da177e4
LT
30}
31
1e014410
AK
32/* Prevent VMA merging */
33static void syscall32_vma_close(struct vm_area_struct *vma)
1da177e4 34{
1e014410
AK
35}
36
37static struct vm_operations_struct syscall32_vm_ops = {
38 .close = syscall32_vma_close,
39 .nopage = syscall32_nopage,
40};
41
42struct linux_binprm;
43
44/* Setup a VMA at program startup for the vsyscall page */
45int syscall32_setup_pages(struct linux_binprm *bprm, int exstack)
46{
47 int npages = (VSYSCALL32_END - VSYSCALL32_BASE) >> PAGE_SHIFT;
48 struct vm_area_struct *vma;
49 struct mm_struct *mm = current->mm;
9fb1759a 50 int ret;
1e014410 51
e94b1766 52 vma = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
1e014410
AK
53 if (!vma)
54 return -ENOMEM;
1e014410
AK
55
56 memset(vma, 0, sizeof(struct vm_area_struct));
57 /* Could randomize here */
58 vma->vm_start = VSYSCALL32_BASE;
59 vma->vm_end = VSYSCALL32_END;
60 /* MAYWRITE to allow gdb to COW and set breakpoints */
2fd4ef85 61 vma->vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC|VM_MAYWRITE;
1e014410
AK
62 vma->vm_flags |= mm->def_flags;
63 vma->vm_page_prot = protection_map[vma->vm_flags & 7];
64 vma->vm_ops = &syscall32_vm_ops;
65 vma->vm_mm = mm;
66
67 down_write(&mm->mmap_sem);
9fb1759a
SS
68 if ((ret = insert_vm_struct(mm, vma))) {
69 up_write(&mm->mmap_sem);
70 kmem_cache_free(vm_area_cachep, vma);
71 return ret;
72 }
1e014410
AK
73 mm->total_vm += npages;
74 up_write(&mm->mmap_sem);
75 return 0;
1da177e4
LT
76}
77
78static int __init init_syscall32(void)
79{
80 syscall32_page = (void *)get_zeroed_page(GFP_KERNEL);
81 if (!syscall32_page)
82 panic("Cannot allocate syscall32 page");
1da177e4
LT
83 if (use_sysenter > 0) {
84 memcpy(syscall32_page, syscall32_sysenter,
85 syscall32_sysenter_end - syscall32_sysenter);
86 } else {
87 memcpy(syscall32_page, syscall32_syscall,
88 syscall32_syscall_end - syscall32_syscall);
89 }
90 return 0;
91}
92
93__initcall(init_syscall32);
94
95/* May not be __init: called during resume */
96void syscall32_cpu_init(void)
97{
98 if (use_sysenter < 0)
99 use_sysenter = (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL);
100
101 /* Load these always in case some future AMD CPU supports
102 SYSENTER from compat mode too. */
103 checking_wrmsrl(MSR_IA32_SYSENTER_CS, (u64)__KERNEL_CS);
104 checking_wrmsrl(MSR_IA32_SYSENTER_ESP, 0ULL);
105 checking_wrmsrl(MSR_IA32_SYSENTER_EIP, (u64)ia32_sysenter_target);
106
107 wrmsrl(MSR_CSTAR, ia32_cstar_target);
108}