This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / sh / kernel / vsyscall / vsyscall.c
1 /*
2  * arch/sh/kernel/vsyscall.c
3  *
4  *  Copyright (C) 2006 Paul Mundt
5  *
6  * vDSO randomization
7  * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar
8  *
9  * This file is subject to the terms and conditions of the GNU General Public
10  * License.  See the file "COPYING" in the main directory of this archive
11  * for more details.
12  */
13 #include <linux/mm.h>
14 #include <linux/slab.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/gfp.h>
18 #include <linux/module.h>
19 #include <linux/elf.h>
20 #include <linux/vs_memory.h>
21
22 /*
23  * Should the kernel map a VDSO page into processes and pass its
24  * address down to glibc upon exec()?
25  */
26 unsigned int __read_mostly vdso_enabled = 1;
27 EXPORT_SYMBOL_GPL(vdso_enabled);
28
29 static int __init vdso_setup(char *s)
30 {
31         vdso_enabled = simple_strtoul(s, NULL, 0);
32         return 1;
33 }
34 __setup("vdso=", vdso_setup);
35
36 /*
37  * These symbols are defined by vsyscall.o to mark the bounds
38  * of the ELF DSO images included therein.
39  */
40 extern const char vsyscall_trapa_start, vsyscall_trapa_end;
41 static void *syscall_page;
42
43 int __init vsyscall_init(void)
44 {
45         syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
46
47         /*
48          * XXX: Map this page to a fixmap entry if we get around
49          * to adding the page to ELF core dumps
50          */
51
52         memcpy(syscall_page,
53                &vsyscall_trapa_start,
54                &vsyscall_trapa_end - &vsyscall_trapa_start);
55
56         return 0;
57 }
58
59 static struct page *syscall_vma_nopage(struct vm_area_struct *vma,
60                                        unsigned long address, int *type)
61 {
62         unsigned long offset = address - vma->vm_start;
63         struct page *page;
64
65         if (address < vma->vm_start || address > vma->vm_end)
66                 return NOPAGE_SIGBUS;
67
68         page = virt_to_page(syscall_page + offset);
69
70         get_page(page);
71
72         return page;
73 }
74
75 /* Prevent VMA merging */
76 static void syscall_vma_close(struct vm_area_struct *vma)
77 {
78 }
79
80 static struct vm_operations_struct syscall_vm_ops = {
81         .nopage = syscall_vma_nopage,
82         .close  = syscall_vma_close,
83 };
84
85 /* Setup a VMA at program startup for the vsyscall page */
86 int arch_setup_additional_pages(struct linux_binprm *bprm,
87                                 int executable_stack)
88 {
89         struct vm_area_struct *vma;
90         struct mm_struct *mm = current->mm;
91         unsigned long addr;
92         int ret;
93
94         down_write(&mm->mmap_sem);
95         addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
96         if (IS_ERR_VALUE(addr)) {
97                 ret = addr;
98                 goto up_fail;
99         }
100
101         vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
102         if (!vma) {
103                 ret = -ENOMEM;
104                 goto up_fail;
105         }
106
107         vma->vm_start = addr;
108         vma->vm_end = addr + PAGE_SIZE;
109         /* MAYWRITE to allow gdb to COW and set breakpoints */
110         vma->vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC|VM_MAYWRITE;
111         vma->vm_flags |= mm->def_flags;
112         vma->vm_page_prot = protection_map[vma->vm_flags & 7];
113         vma->vm_ops = &syscall_vm_ops;
114         vma->vm_mm = mm;
115
116         ret = insert_vm_struct(mm, vma);
117         if (unlikely(ret)) {
118                 kmem_cache_free(vm_area_cachep, vma);
119                 goto up_fail;
120         }
121
122         current->mm->context.vdso = (void *)addr;
123
124         vx_vmpages_inc(mm);
125 up_fail:
126         up_write(&mm->mmap_sem);
127         return ret;
128 }
129
130 const char *arch_vma_name(struct vm_area_struct *vma)
131 {
132         if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
133                 return "[vdso]";
134
135         return NULL;
136 }
137
138 struct vm_area_struct *get_gate_vma(struct task_struct *task)
139 {
140         return NULL;
141 }
142
143 int in_gate_area(struct task_struct *task, unsigned long address)
144 {
145         return 0;
146 }
147
148 int in_gate_area_no_task(unsigned long address)
149 {
150         return 0;
151 }