blob: 237c6831e0957fb69f76aa2aa1c61b9968917904 [file] [log] [blame]
Richard Weinbergerf1c2bb82011-07-25 17:12:54 -07001/*
2 * Copyright (C) 2011 Richard Weinberger <richrd@nod.at>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/slab.h>
10#include <linux/sched.h>
11#include <linux/mm.h>
12#include <asm/page.h>
Richard Weinberger9b46e212015-05-12 00:09:52 +020013#include <asm/elf.h>
Richard Weinbergerf1c2bb82011-07-25 17:12:54 -070014#include <linux/init.h>
15
Andy Lutomirski3d7ee962014-05-05 12:19:32 -070016static unsigned int __read_mostly vdso_enabled = 1;
Richard Weinbergerf1c2bb82011-07-25 17:12:54 -070017unsigned long um_vdso_addr;
18
19extern unsigned long task_size;
20extern char vdso_start[], vdso_end[];
21
22static struct page **vdsop;
23
24static int __init init_vdso(void)
25{
26 struct page *um_vdso;
27
28 BUG_ON(vdso_end - vdso_start > PAGE_SIZE);
29
30 um_vdso_addr = task_size - PAGE_SIZE;
31
Dave Jones0d65ede2011-10-24 18:15:32 -040032 vdsop = kmalloc(sizeof(struct page *), GFP_KERNEL);
Richard Weinbergerf1c2bb82011-07-25 17:12:54 -070033 if (!vdsop)
34 goto oom;
35
36 um_vdso = alloc_page(GFP_KERNEL);
37 if (!um_vdso) {
38 kfree(vdsop);
39
40 goto oom;
41 }
42
43 copy_page(page_address(um_vdso), vdso_start);
44 *vdsop = um_vdso;
45
46 return 0;
47
48oom:
49 printk(KERN_ERR "Cannot allocate vdso\n");
50 vdso_enabled = 0;
51
52 return -ENOMEM;
53}
54subsys_initcall(init_vdso);
55
56int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
57{
58 int err;
59 struct mm_struct *mm = current->mm;
60
61 if (!vdso_enabled)
62 return 0;
63
64 down_write(&mm->mmap_sem);
65
66 err = install_special_mapping(mm, um_vdso_addr, PAGE_SIZE,
67 VM_READ|VM_EXEC|
Jason Baron909af762012-03-23 15:02:51 -070068 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
Richard Weinbergerf1c2bb82011-07-25 17:12:54 -070069 vdsop);
70
71 up_write(&mm->mmap_sem);
72
73 return err;
74}