Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 1 | /* |
Uwe Kleine-König | 5886269 | 2007-05-09 07:51:49 +0200 | [diff] [blame] | 2 | * arch/sh/kernel/vsyscall/vsyscall.c |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 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> |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/gfp.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/elf.h> |
Manuel Lauss | f75522c | 2007-05-31 13:44:55 +0900 | [diff] [blame] | 19 | #include <linux/sched.h> |
Paul Mundt | e06c4e5 | 2007-07-31 13:01:43 +0900 | [diff] [blame] | 20 | #include <linux/err.h> |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 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; |
Paul Mundt | 2affc85 | 2007-02-08 14:20:44 -0800 | [diff] [blame] | 41 | static struct page *syscall_pages[1]; |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 42 | |
| 43 | int __init vsyscall_init(void) |
| 44 | { |
Paul Mundt | 2affc85 | 2007-02-08 14:20:44 -0800 | [diff] [blame] | 45 | void *syscall_page = (void *)get_zeroed_page(GFP_ATOMIC); |
| 46 | syscall_pages[0] = virt_to_page(syscall_page); |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 47 | |
| 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 Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 60 | /* Setup a VMA at program startup for the vsyscall page */ |
Martin Schwidefsky | fc5243d | 2008-12-25 13:38:35 +0100 | [diff] [blame] | 61 | int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 62 | { |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 63 | struct mm_struct *mm = current->mm; |
| 64 | unsigned long addr; |
| 65 | int ret; |
| 66 | |
| 67 | down_write(&mm->mmap_sem); |
| 68 | addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0); |
| 69 | if (IS_ERR_VALUE(addr)) { |
| 70 | ret = addr; |
| 71 | goto up_fail; |
| 72 | } |
| 73 | |
Paul Mundt | 2affc85 | 2007-02-08 14:20:44 -0800 | [diff] [blame] | 74 | ret = install_special_mapping(mm, addr, PAGE_SIZE, |
| 75 | VM_READ | VM_EXEC | |
Jason Baron | 909af76 | 2012-03-23 15:02:51 -0700 | [diff] [blame] | 76 | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC, |
Paul Mundt | 2affc85 | 2007-02-08 14:20:44 -0800 | [diff] [blame] | 77 | syscall_pages); |
| 78 | if (unlikely(ret)) |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 79 | goto up_fail; |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 80 | |
| 81 | current->mm->context.vdso = (void *)addr; |
| 82 | |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 83 | up_fail: |
| 84 | up_write(&mm->mmap_sem); |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | const char *arch_vma_name(struct vm_area_struct *vma) |
| 89 | { |
| 90 | if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso) |
| 91 | return "[vdso]"; |
| 92 | |
| 93 | return NULL; |
| 94 | } |
| 95 | |
Stephen Wilson | 31db58b | 2011-03-13 15:49:15 -0400 | [diff] [blame] | 96 | struct vm_area_struct *get_gate_vma(struct mm_struct *mm) |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 97 | { |
| 98 | return NULL; |
| 99 | } |
| 100 | |
Stephen Wilson | 83b964b | 2011-03-13 15:49:16 -0400 | [diff] [blame] | 101 | int in_gate_area(struct mm_struct *mm, unsigned long address) |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 102 | { |
| 103 | return 0; |
| 104 | } |
| 105 | |
Stephen Wilson | cae5d39 | 2011-03-13 15:49:17 -0400 | [diff] [blame] | 106 | int in_gate_area_no_mm(unsigned long address) |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 107 | { |
| 108 | return 0; |
| 109 | } |