2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2009, 2010 Cavium Networks, Inc.
10 #include <linux/kernel.h>
11 #include <linux/err.h>
12 #include <linux/sched.h>
14 #include <linux/init.h>
15 #include <linux/binfmts.h>
16 #include <linux/elf.h>
17 #include <linux/vmalloc.h>
18 #include <linux/unistd.h>
19 #include <linux/random.h>
23 #include <asm/processor.h>
26 * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
28 #define __NR_O32_sigreturn 4119
29 #define __NR_O32_rt_sigreturn 4193
30 #define __NR_N32_rt_sigreturn 6211
32 static struct page *vdso_page;
34 static void __init install_trampoline(u32 *tramp, unsigned int sigreturn)
36 uasm_i_addiu(&tramp, 2, 0, sigreturn); /* li v0, sigreturn */
37 uasm_i_syscall(&tramp, 0);
40 static int __init init_vdso(void)
42 struct mips_vdso *vdso;
44 vdso_page = alloc_page(GFP_KERNEL);
46 panic("Cannot allocate vdso");
48 vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
50 panic("Cannot map vdso");
53 install_trampoline(vdso->rt_signal_trampoline, __NR_rt_sigreturn);
55 install_trampoline(vdso->signal_trampoline, __NR_sigreturn);
57 install_trampoline(vdso->n32_rt_signal_trampoline,
58 __NR_N32_rt_sigreturn);
59 install_trampoline(vdso->o32_signal_trampoline, __NR_O32_sigreturn);
60 install_trampoline(vdso->o32_rt_signal_trampoline,
61 __NR_O32_rt_sigreturn);
68 subsys_initcall(init_vdso);
70 static unsigned long vdso_addr(unsigned long start)
72 unsigned long offset = 0UL;
74 if (current->flags & PF_RANDOMIZE) {
75 offset = get_random_int();
76 offset <<= PAGE_SHIFT;
77 if (TASK_IS_32BIT_ADDR)
80 offset &= 0xffffffful;
83 return STACK_TOP + offset;
86 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
90 struct mm_struct *mm = current->mm;
92 down_write(&mm->mmap_sem);
94 addr = vdso_addr(mm->start_stack);
96 addr = get_unmapped_area(NULL, addr, PAGE_SIZE, 0, 0);
97 if (IS_ERR_VALUE(addr)) {
102 ret = install_special_mapping(mm, addr, PAGE_SIZE,
104 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
110 mm->context.vdso = (void *)addr;
113 up_write(&mm->mmap_sem);
117 const char *arch_vma_name(struct vm_area_struct *vma)
119 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)