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) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <linux/mm_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/binfmts.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/a.out.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) static int load_binary(struct linux_binprm *bprm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 	struct exec *eh = (struct exec *)bprm->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) 	unsigned long loader;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 	struct file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 	if (eh->fh.f_magic != 0x183 || (eh->fh.f_flags & 0x3000) != 0x3000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	if (bprm->loader)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	loader = bprm->vma->vm_end - sizeof(void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	file = open_exec("/sbin/loader");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	retval = PTR_ERR(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	if (IS_ERR(file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	/* Remember if the application is TASO.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	bprm->taso = eh->ah.entry < 0x100000000UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	bprm->interpreter = file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	bprm->loader = loader;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static struct linux_binfmt loader_format = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	.load_binary	= load_binary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static int __init init_loader_binfmt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	insert_binfmt(&loader_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) arch_initcall(init_loader_binfmt);