2 * linux/fs/binfmt_em86.c
4 * Based on linux/fs/binfmt_script.c
5 * Copyright (C) 1996 Martin von Löwis
6 * original #!-checking implemented by tytso.
8 * em86 changes Copyright (C) 1997 Jim Paradis
11 #include <linux/module.h>
12 #include <linux/string.h>
13 #include <linux/stat.h>
14 #include <linux/binfmts.h>
15 #include <linux/elf.h>
16 #include <linux/init.h>
18 #include <linux/file.h>
19 #include <linux/errno.h>
22 #define EM86_INTERP "/usr/bin/em86"
23 #define EM86_I_NAME "em86"
25 static int load_em86(struct linux_binprm *bprm)
27 const char *i_name, *i_arg;
33 /* Make sure this is a Linux/Intel ELF executable... */
34 elf_ex = *((struct elfhdr *)bprm->buf);
36 if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
39 /* First of all, some simple consistency checks */
40 if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
41 (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) ||
42 !bprm->file->f_op->mmap) {
46 /* Need to be able to load the file after exec */
47 if (bprm->interp_flags & BINPRM_FLAGS_PATH_INACCESSIBLE)
50 allow_write_access(bprm->file);
54 /* Unlike in the script case, we don't have to do any hairy
55 * parsing to find our interpreter... it's hardcoded!
59 i_arg = NULL; /* We reserve the right to add an arg later */
62 * Splice in (1) the interpreter's name for argv[0]
63 * (2) (optional) argument to interpreter
64 * (3) filename of emulated file (replace argv[0])
66 * This is done in reverse order, because of how the
67 * user environment and arguments are stored.
69 remove_arg_zero(bprm);
70 retval = copy_strings_kernel(1, &bprm->filename, bprm);
71 if (retval < 0) return retval;
74 retval = copy_strings_kernel(1, &i_arg, bprm);
75 if (retval < 0) return retval;
78 retval = copy_strings_kernel(1, &i_name, bprm);
79 if (retval < 0) return retval;
83 * OK, now restart the process with the interpreter's inode.
84 * Note that we use open_exec() as the name is now in kernel
85 * space, and we don't need to copy it.
87 file = open_exec(interp);
93 retval = prepare_binprm(bprm);
97 return search_binary_handler(bprm);
100 static struct linux_binfmt em86_format = {
101 .module = THIS_MODULE,
102 .load_binary = load_em86,
105 static int __init init_em86_binfmt(void)
107 register_binfmt(&em86_format);
111 static void __exit exit_em86_binfmt(void)
113 unregister_binfmt(&em86_format);
116 core_initcall(init_em86_binfmt);
117 module_exit(exit_em86_binfmt);
118 MODULE_LICENSE("GPL");