blob: 2aa9438361bcb99a75ac7369dd0c1c2ea8ba5997 [file] [log] [blame]
Paul Mundt19f9a342006-09-27 18:33:49 +09001/*
Uwe Kleine-König58862692007-05-09 07:51:49 +02002 * arch/sh/kernel/vsyscall/vsyscall.c
Paul Mundt19f9a342006-09-27 18:33:49 +09003 *
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>
Manuel Laussf75522c2007-05-31 13:44:55 +090020#include <linux/sched.h>
Paul Mundt19f9a342006-09-27 18:33:49 +090021
22/*
23 * Should the kernel map a VDSO page into processes and pass its
24 * address down to glibc upon exec()?
25 */
26unsigned int __read_mostly vdso_enabled = 1;
27EXPORT_SYMBOL_GPL(vdso_enabled);
28
29static 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 */
40extern const char vsyscall_trapa_start, vsyscall_trapa_end;
Paul Mundt2affc852007-02-08 14:20:44 -080041static struct page *syscall_pages[1];
Paul Mundt19f9a342006-09-27 18:33:49 +090042
43int __init vsyscall_init(void)
44{
Paul Mundt2affc852007-02-08 14:20:44 -080045 void *syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
46 syscall_pages[0] = virt_to_page(syscall_page);
Paul Mundt19f9a342006-09-27 18:33:49 +090047
48 /*
49 * XXX: Map this page to a fixmap entry if we get around
50 * to adding the page to ELF core dumps
51 */
52
53 memcpy(syscall_page,
54 &vsyscall_trapa_start,
55 &vsyscall_trapa_end - &vsyscall_trapa_start);
56
57 return 0;
58}
59
Paul Mundt19f9a342006-09-27 18:33:49 +090060/* Setup a VMA at program startup for the vsyscall page */
61int arch_setup_additional_pages(struct linux_binprm *bprm,
62 int executable_stack)
63{
Paul Mundt19f9a342006-09-27 18:33:49 +090064 struct mm_struct *mm = current->mm;
65 unsigned long addr;
66 int ret;
67
68 down_write(&mm->mmap_sem);
69 addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
70 if (IS_ERR_VALUE(addr)) {
71 ret = addr;
72 goto up_fail;
73 }
74
Paul Mundt2affc852007-02-08 14:20:44 -080075 ret = install_special_mapping(mm, addr, PAGE_SIZE,
76 VM_READ | VM_EXEC |
77 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC |
78 VM_ALWAYSDUMP,
79 syscall_pages);
80 if (unlikely(ret))
Paul Mundt19f9a342006-09-27 18:33:49 +090081 goto up_fail;
Paul Mundt19f9a342006-09-27 18:33:49 +090082
83 current->mm->context.vdso = (void *)addr;
84
Paul Mundt19f9a342006-09-27 18:33:49 +090085up_fail:
86 up_write(&mm->mmap_sem);
87 return ret;
88}
89
90const char *arch_vma_name(struct vm_area_struct *vma)
91{
92 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
93 return "[vdso]";
94
95 return NULL;
96}
97
98struct vm_area_struct *get_gate_vma(struct task_struct *task)
99{
100 return NULL;
101}
102
103int in_gate_area(struct task_struct *task, unsigned long address)
104{
105 return 0;
106}
107
108int in_gate_area_no_task(unsigned long address)
109{
110 return 0;
111}