2 * arch/sh/kernel/vsyscall.c
4 * Copyright (C) 2006 Paul Mundt
7 * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar
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
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>
22 * Should the kernel map a VDSO page into processes and pass its
23 * address down to glibc upon exec()?
25 unsigned int __read_mostly vdso_enabled = 1;
26 EXPORT_SYMBOL_GPL(vdso_enabled);
28 static int __init vdso_setup(char *s)
30 vdso_enabled = simple_strtoul(s, NULL, 0);
33 __setup("vdso=", vdso_setup);
36 * These symbols are defined by vsyscall.o to mark the bounds
37 * of the ELF DSO images included therein.
39 extern const char vsyscall_trapa_start, vsyscall_trapa_end;
40 static void *syscall_page;
42 int __init vsyscall_init(void)
44 syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
47 * XXX: Map this page to a fixmap entry if we get around
48 * to adding the page to ELF core dumps
52 &vsyscall_trapa_start,
53 &vsyscall_trapa_end - &vsyscall_trapa_start);
58 static struct page *syscall_vma_nopage(struct vm_area_struct *vma,
59 unsigned long address, int *type)
61 unsigned long offset = address - vma->vm_start;
64 if (address < vma->vm_start || address > vma->vm_end)
67 page = virt_to_page(syscall_page + offset);
74 /* Prevent VMA merging */
75 static void syscall_vma_close(struct vm_area_struct *vma)
79 static struct vm_operations_struct syscall_vm_ops = {
80 .nopage = syscall_vma_nopage,
81 .close = syscall_vma_close,
84 /* Setup a VMA at program startup for the vsyscall page */
85 int arch_setup_additional_pages(struct linux_binprm *bprm,
88 struct vm_area_struct *vma;
89 struct mm_struct *mm = current->mm;
93 down_write(&mm->mmap_sem);
94 addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
95 if (IS_ERR_VALUE(addr)) {
100 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
106 vma->vm_start = addr;
107 vma->vm_end = addr + PAGE_SIZE;
108 /* MAYWRITE to allow gdb to COW and set breakpoints */
109 vma->vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC|VM_MAYWRITE;
110 vma->vm_flags |= mm->def_flags;
111 vma->vm_page_prot = protection_map[vma->vm_flags & 7];
112 vma->vm_ops = &syscall_vm_ops;
115 ret = insert_vm_struct(mm, vma);
117 kmem_cache_free(vm_area_cachep, vma);
121 current->mm->context.vdso = (void *)addr;
125 up_write(&mm->mmap_sem);
129 const char *arch_vma_name(struct vm_area_struct *vma)
131 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
137 struct vm_area_struct *get_gate_vma(struct task_struct *task)
142 int in_gate_area(struct task_struct *task, unsigned long address)
147 int in_gate_area_no_task(unsigned long address)