2 * Copyright (C) 2015 Imagination Technologies
3 * Author: Alex Smith <alex.smith@imgtec.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
11 #include <linux/binfmts.h>
12 #include <linux/elf.h>
13 #include <linux/err.h>
14 #include <linux/init.h>
16 #include <linux/sched.h>
17 #include <linux/slab.h>
22 /* Kernel-provided data used by the VDSO. */
23 static union mips_vdso_data vdso_data __page_aligned_data;
26 * Mapping for the VDSO data pages. The real pages are mapped manually, as
27 * what we map and where within the area they are mapped is determined at
30 static struct page *no_pages[] = { NULL };
31 static struct vm_special_mapping vdso_vvar_mapping = {
36 static void __init init_vdso_image(struct mips_vdso_image *image)
38 unsigned long num_pages, i;
40 BUG_ON(!PAGE_ALIGNED(image->data));
41 BUG_ON(!PAGE_ALIGNED(image->size));
43 num_pages = image->size / PAGE_SIZE;
45 for (i = 0; i < num_pages; i++) {
46 image->mapping.pages[i] =
47 virt_to_page(image->data + (i * PAGE_SIZE));
51 static int __init init_vdso(void)
53 init_vdso_image(&vdso_image);
55 #ifdef CONFIG_MIPS32_O32
56 init_vdso_image(&vdso_image_o32);
59 #ifdef CONFIG_MIPS32_N32
60 init_vdso_image(&vdso_image_n32);
65 subsys_initcall(init_vdso);
67 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
69 struct mips_vdso_image *image = current->thread.abi->vdso;
70 struct mm_struct *mm = current->mm;
71 unsigned long base, vdso_addr;
72 struct vm_area_struct *vma;
75 down_write(&mm->mmap_sem);
77 base = get_unmapped_area(NULL, 0, PAGE_SIZE + image->size, 0, 0);
78 if (IS_ERR_VALUE(base)) {
83 vdso_addr = base + PAGE_SIZE;
85 vma = _install_special_mapping(mm, base, PAGE_SIZE,
94 ret = remap_pfn_range(vma, base,
95 virt_to_phys(&vdso_data) >> PAGE_SHIFT,
96 PAGE_SIZE, PAGE_READONLY);
100 /* Map VDSO image. */
101 vma = _install_special_mapping(mm, vdso_addr, image->size,
103 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
110 mm->context.vdso = (void *)vdso_addr;
114 up_write(&mm->mmap_sem);