Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * arch/sh/kernel/vsyscall/vsyscall.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *  Copyright (C) 2006 Paul Mundt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * vDSO randomization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  * Copyright(C) 2005-2006, Red Hat, Inc., Ingo Molnar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)  * Should the kernel map a VDSO page into processes and pass its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)  * address down to glibc upon exec()?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unsigned int __read_mostly vdso_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) EXPORT_SYMBOL_GPL(vdso_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int __init vdso_setup(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	vdso_enabled = simple_strtoul(s, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) __setup("vdso=", vdso_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)  * These symbols are defined by vsyscall.o to mark the bounds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)  * of the ELF DSO images included therein.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) extern const char vsyscall_trapa_start, vsyscall_trapa_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static struct page *syscall_pages[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int __init vsyscall_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	void *syscall_page = (void *)get_zeroed_page(GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	syscall_pages[0] = virt_to_page(syscall_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	 * XXX: Map this page to a fixmap entry if we get around
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	 * to adding the page to ELF core dumps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	memcpy(syscall_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	       &vsyscall_trapa_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	       &vsyscall_trapa_end - &vsyscall_trapa_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* Setup a VMA at program startup for the vsyscall page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	struct mm_struct *mm = current->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	unsigned long addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	if (mmap_write_lock_killable(mm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	if (IS_ERR_VALUE(addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 		ret = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		goto up_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	ret = install_special_mapping(mm, addr, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 				      VM_READ | VM_EXEC |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 				      VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 				      syscall_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 		goto up_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	current->mm->context.vdso = (void *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) up_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	mmap_write_unlock(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) const char *arch_vma_name(struct vm_area_struct *vma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 	if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) 		return "[vdso]";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }