m68knommu: remove local gettimeofday code
[wrt350n-kernel.git] / fs / binfmt_em86.c
blobf95ae9789c913d81d0df5d17250bced9c5479855
1 /*
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
9 */
11 #include <linux/module.h>
12 #include <linux/string.h>
13 #include <linux/stat.h>
14 #include <linux/slab.h>
15 #include <linux/binfmts.h>
16 #include <linux/elf.h>
17 #include <linux/init.h>
18 #include <linux/fs.h>
19 #include <linux/file.h>
20 #include <linux/errno.h>
23 #define EM86_INTERP "/usr/bin/em86"
24 #define EM86_I_NAME "em86"
26 static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs)
28 char *interp, *i_name, *i_arg;
29 struct file * file;
30 int retval;
31 struct elfhdr elf_ex;
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)
37 return -ENOEXEC;
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 || !bprm->file->f_op->mmap)) {
43 return -ENOEXEC;
46 bprm->sh_bang++; /* Well, the bang-shell is implicit... */
47 allow_write_access(bprm->file);
48 fput(bprm->file);
49 bprm->file = NULL;
51 /* Unlike in the script case, we don't have to do any hairy
52 * parsing to find our interpreter... it's hardcoded!
54 interp = EM86_INTERP;
55 i_name = EM86_I_NAME;
56 i_arg = NULL; /* We reserve the right to add an arg later */
59 * Splice in (1) the interpreter's name for argv[0]
60 * (2) (optional) argument to interpreter
61 * (3) filename of emulated file (replace argv[0])
63 * This is done in reverse order, because of how the
64 * user environment and arguments are stored.
66 remove_arg_zero(bprm);
67 retval = copy_strings_kernel(1, &bprm->filename, bprm);
68 if (retval < 0) return retval;
69 bprm->argc++;
70 if (i_arg) {
71 retval = copy_strings_kernel(1, &i_arg, bprm);
72 if (retval < 0) return retval;
73 bprm->argc++;
75 retval = copy_strings_kernel(1, &i_name, bprm);
76 if (retval < 0) return retval;
77 bprm->argc++;
80 * OK, now restart the process with the interpreter's inode.
81 * Note that we use open_exec() as the name is now in kernel
82 * space, and we don't need to copy it.
84 file = open_exec(interp);
85 if (IS_ERR(file))
86 return PTR_ERR(file);
88 bprm->file = file;
90 retval = prepare_binprm(bprm);
91 if (retval < 0)
92 return retval;
94 return search_binary_handler(bprm, regs);
97 static struct linux_binfmt em86_format = {
98 .module = THIS_MODULE,
99 .load_binary = load_em86,
102 static int __init init_em86_binfmt(void)
104 return register_binfmt(&em86_format);
107 static void __exit exit_em86_binfmt(void)
109 unregister_binfmt(&em86_format);
112 core_initcall(init_em86_binfmt);
113 module_exit(exit_em86_binfmt);
114 MODULE_LICENSE("GPL");