2010-02-19 08:13:04 +08:00
|
|
|
/*
|
2015-10-21 16:54:38 +08:00
|
|
|
* Copyright (C) 2015 Imagination Technologies
|
|
|
|
* Author: Alex Smith <alex.smith@imgtec.com>
|
2010-02-19 08:13:04 +08:00
|
|
|
*
|
2015-10-21 16:54:38 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2010-02-19 08:13:04 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/binfmts.h>
|
|
|
|
#include <linux/elf.h>
|
2015-10-21 16:54:38 +08:00
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
2010-02-19 08:13:04 +08:00
|
|
|
|
2015-10-21 16:54:38 +08:00
|
|
|
#include <asm/abi.h>
|
2010-02-19 08:13:04 +08:00
|
|
|
#include <asm/vdso.h>
|
2015-10-21 16:54:38 +08:00
|
|
|
|
|
|
|
/* Kernel-provided data used by the VDSO. */
|
|
|
|
static union mips_vdso_data vdso_data __page_aligned_data;
|
2010-02-19 08:13:04 +08:00
|
|
|
|
|
|
|
/*
|
2015-10-21 16:54:38 +08:00
|
|
|
* Mapping for the VDSO data pages. The real pages are mapped manually, as
|
|
|
|
* what we map and where within the area they are mapped is determined at
|
|
|
|
* runtime.
|
2010-02-19 08:13:04 +08:00
|
|
|
*/
|
2015-10-21 16:54:38 +08:00
|
|
|
static struct page *no_pages[] = { NULL };
|
|
|
|
static struct vm_special_mapping vdso_vvar_mapping = {
|
|
|
|
.name = "[vvar]",
|
|
|
|
.pages = no_pages,
|
|
|
|
};
|
2010-02-19 08:13:04 +08:00
|
|
|
|
2015-10-21 16:54:38 +08:00
|
|
|
static void __init init_vdso_image(struct mips_vdso_image *image)
|
2010-02-19 08:13:04 +08:00
|
|
|
{
|
2015-10-21 16:54:38 +08:00
|
|
|
unsigned long num_pages, i;
|
|
|
|
|
|
|
|
BUG_ON(!PAGE_ALIGNED(image->data));
|
|
|
|
BUG_ON(!PAGE_ALIGNED(image->size));
|
|
|
|
|
|
|
|
num_pages = image->size / PAGE_SIZE;
|
|
|
|
|
|
|
|
for (i = 0; i < num_pages; i++) {
|
|
|
|
image->mapping.pages[i] =
|
|
|
|
virt_to_page(image->data + (i * PAGE_SIZE));
|
|
|
|
}
|
2010-02-19 08:13:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init init_vdso(void)
|
|
|
|
{
|
2015-10-21 16:54:38 +08:00
|
|
|
init_vdso_image(&vdso_image);
|
|
|
|
|
|
|
|
#ifdef CONFIG_MIPS32_O32
|
|
|
|
init_vdso_image(&vdso_image_o32);
|
2010-02-19 08:13:04 +08:00
|
|
|
#endif
|
|
|
|
|
2015-10-21 16:54:38 +08:00
|
|
|
#ifdef CONFIG_MIPS32_N32
|
|
|
|
init_vdso_image(&vdso_image_n32);
|
|
|
|
#endif
|
2010-02-19 08:13:04 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-06-17 06:00:28 +08:00
|
|
|
subsys_initcall(init_vdso);
|
2010-02-19 08:13:04 +08:00
|
|
|
|
|
|
|
int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
|
|
|
{
|
2015-10-21 16:54:38 +08:00
|
|
|
struct mips_vdso_image *image = current->thread.abi->vdso;
|
2010-02-19 08:13:04 +08:00
|
|
|
struct mm_struct *mm = current->mm;
|
2015-10-21 16:54:38 +08:00
|
|
|
unsigned long base, vdso_addr;
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
int ret;
|
2010-02-19 08:13:04 +08:00
|
|
|
|
|
|
|
down_write(&mm->mmap_sem);
|
|
|
|
|
2015-10-21 16:54:38 +08:00
|
|
|
base = get_unmapped_area(NULL, 0, PAGE_SIZE + image->size, 0, 0);
|
|
|
|
if (IS_ERR_VALUE(base)) {
|
|
|
|
ret = base;
|
|
|
|
goto out;
|
2010-02-19 08:13:04 +08:00
|
|
|
}
|
|
|
|
|
2015-10-21 16:54:38 +08:00
|
|
|
vdso_addr = base + PAGE_SIZE;
|
|
|
|
|
|
|
|
vma = _install_special_mapping(mm, base, PAGE_SIZE,
|
|
|
|
VM_READ | VM_MAYREAD,
|
|
|
|
&vdso_vvar_mapping);
|
|
|
|
if (IS_ERR(vma)) {
|
|
|
|
ret = PTR_ERR(vma);
|
|
|
|
goto out;
|
|
|
|
}
|
2010-02-19 08:13:04 +08:00
|
|
|
|
2015-10-21 16:54:38 +08:00
|
|
|
/* Map data page. */
|
|
|
|
ret = remap_pfn_range(vma, base,
|
|
|
|
virt_to_phys(&vdso_data) >> PAGE_SHIFT,
|
|
|
|
PAGE_SIZE, PAGE_READONLY);
|
2010-02-19 08:13:04 +08:00
|
|
|
if (ret)
|
2015-10-21 16:54:38 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Map VDSO image. */
|
|
|
|
vma = _install_special_mapping(mm, vdso_addr, image->size,
|
|
|
|
VM_READ | VM_EXEC |
|
|
|
|
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
|
|
|
|
&image->mapping);
|
|
|
|
if (IS_ERR(vma)) {
|
|
|
|
ret = PTR_ERR(vma);
|
|
|
|
goto out;
|
|
|
|
}
|
2010-02-19 08:13:04 +08:00
|
|
|
|
2015-10-21 16:54:38 +08:00
|
|
|
mm->context.vdso = (void *)vdso_addr;
|
|
|
|
ret = 0;
|
2010-02-19 08:13:04 +08:00
|
|
|
|
2015-10-21 16:54:38 +08:00
|
|
|
out:
|
2010-02-19 08:13:04 +08:00
|
|
|
up_write(&mm->mmap_sem);
|
|
|
|
return ret;
|
|
|
|
}
|