123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /*
- * Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
- * <benh@kernel.crashing.org>
- * Copyright (C) 2012 ARM Limited
- * Copyright (C) 2015 Regents of the University of California
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include <linux/mm.h>
- #include <linux/slab.h>
- #include <linux/binfmts.h>
- #include <linux/err.h>
- #include <asm/vdso.h>
- extern char vdso_start[], vdso_end[];
- static unsigned int vdso_pages;
- static struct page **vdso_pagelist;
- /*
- * The vDSO data page.
- */
- static union {
- struct vdso_data data;
- u8 page[PAGE_SIZE];
- } vdso_data_store __page_aligned_data;
- struct vdso_data *vdso_data = &vdso_data_store.data;
- static int __init vdso_init(void)
- {
- unsigned int i;
- vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
- vdso_pagelist =
- kcalloc(vdso_pages + 1, sizeof(struct page *), GFP_KERNEL);
- if (unlikely(vdso_pagelist == NULL)) {
- pr_err("vdso: pagelist allocation failed\n");
- return -ENOMEM;
- }
- for (i = 0; i < vdso_pages; i++) {
- struct page *pg;
- pg = virt_to_page(vdso_start + (i << PAGE_SHIFT));
- ClearPageReserved(pg);
- vdso_pagelist[i] = pg;
- }
- vdso_pagelist[i] = virt_to_page(vdso_data);
- return 0;
- }
- arch_initcall(vdso_init);
- int arch_setup_additional_pages(struct linux_binprm *bprm,
- int uses_interp)
- {
- struct mm_struct *mm = current->mm;
- unsigned long vdso_base, vdso_len;
- int ret;
- vdso_len = (vdso_pages + 1) << PAGE_SHIFT;
- down_write(&mm->mmap_sem);
- vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
- if (IS_ERR_VALUE(vdso_base)) {
- ret = vdso_base;
- goto end;
- }
- /*
- * Put vDSO base into mm struct. We need to do this before calling
- * install_special_mapping or the perf counter mmap tracking code
- * will fail to recognise it as a vDSO (since arch_vma_name fails).
- */
- mm->context.vdso = (void *)vdso_base;
- ret = install_special_mapping(mm, vdso_base, vdso_len,
- (VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
- vdso_pagelist);
- if (unlikely(ret))
- mm->context.vdso = NULL;
- end:
- up_write(&mm->mmap_sem);
- return ret;
- }
- const char *arch_vma_name(struct vm_area_struct *vma)
- {
- if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso))
- return "[vdso]";
- return NULL;
- }
- /*
- * Function stubs to prevent linker errors when AT_SYSINFO_EHDR is defined
- */
- int in_gate_area_no_mm(unsigned long addr)
- {
- return 0;
- }
- int in_gate_area(struct mm_struct *mm, unsigned long addr)
- {
- return 0;
- }
- struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
- {
- return NULL;
- }
|