blob: 3ea968415539f3d0244b0da2d257dd0bda686a1a [file] [log] [blame]
Richard Kuocd5b61d2011-10-31 18:41:21 -05001/*
2 * vDSO implementation for Hexagon
3 *
Richard Kuoe1858b22012-09-19 16:22:02 -05004 * Copyright (c) 2011, The Linux Foundation. All rights reserved.
Richard Kuocd5b61d2011-10-31 18:41:21 -05005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
19 */
20
21#include <linux/err.h>
22#include <linux/mm.h>
23#include <linux/vmalloc.h>
Richard Kuo6bbbc302011-11-15 16:58:11 -060024#include <linux/binfmts.h>
Richard Kuocd5b61d2011-10-31 18:41:21 -050025
26#include <asm/vdso.h>
27
28static struct page *vdso_page;
29
30/* Create a vDSO page holding the signal trampoline.
31 * We want this for a non-executable stack.
32 */
33static int __init vdso_init(void)
34{
35 struct hexagon_vdso *vdso;
36
37 vdso_page = alloc_page(GFP_KERNEL);
38 if (!vdso_page)
39 panic("Cannot allocate vdso");
40
41 vdso = vmap(&vdso_page, 1, 0, PAGE_KERNEL);
42 if (!vdso)
43 panic("Cannot map vdso");
44 clear_page(vdso);
45
46 /* Install the signal trampoline; currently looks like this:
47 * r6 = #__NR_rt_sigreturn;
48 * trap0(#1);
49 */
50 vdso->rt_signal_trampoline[0] = __rt_sigtramp_template[0];
51 vdso->rt_signal_trampoline[1] = __rt_sigtramp_template[1];
52
53 vunmap(vdso);
54
55 return 0;
56}
57arch_initcall(vdso_init);
58
59/*
60 * Called from binfmt_elf. Create a VMA for the vDSO page.
61 */
62int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
63{
64 int ret;
65 unsigned long vdso_base;
66 struct mm_struct *mm = current->mm;
67
Michal Hocko69048172016-05-23 16:25:54 -070068 if (down_write_killable(&mm->mmap_sem))
69 return -EINTR;
Richard Kuocd5b61d2011-10-31 18:41:21 -050070
71 /* Try to get it loaded right near ld.so/glibc. */
72 vdso_base = STACK_TOP;
73
74 vdso_base = get_unmapped_area(NULL, vdso_base, PAGE_SIZE, 0, 0);
75 if (IS_ERR_VALUE(vdso_base)) {
76 ret = vdso_base;
77 goto up_fail;
78 }
79
80 /* MAYWRITE to allow gdb to COW and set breakpoints. */
81 ret = install_special_mapping(mm, vdso_base, PAGE_SIZE,
82 VM_READ|VM_EXEC|
Jason Baron909af762012-03-23 15:02:51 -070083 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
Richard Kuocd5b61d2011-10-31 18:41:21 -050084 &vdso_page);
85
86 if (ret)
87 goto up_fail;
88
89 mm->context.vdso = (void *)vdso_base;
90
91up_fail:
92 up_write(&mm->mmap_sem);
93 return ret;
94}
95
96const char *arch_vma_name(struct vm_area_struct *vma)
97{
98 if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
99 return "[vdso]";
100 return NULL;
101}