Import 2.3.52pre3
[davej-history.git] / fs / binfmt_em86.c
blob189d130cafabf9dc7df4ab044370a799b8e0d66f
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/malloc.h>
15 #include <linux/binfmts.h>
16 #include <linux/elf.h>
17 #include <linux/init.h>
20 #define EM86_INTERP "/usr/bin/em86"
21 #define EM86_I_NAME "em86"
23 static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs)
25 char *interp, *i_name, *i_arg;
26 struct dentry * dentry;
27 int retval;
28 struct elfhdr elf_ex;
30 /* Make sure this is a Linux/Intel ELF executable... */
31 elf_ex = *((struct elfhdr *)bprm->buf);
33 if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
34 return -ENOEXEC;
36 /* First of all, some simple consistency checks */
37 if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
38 (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) ||
39 (!bprm->dentry->d_inode->i_fop ||
40 !bprm->dentry->d_inode->i_fop->mmap)) {
41 return -ENOEXEC;
44 bprm->sh_bang++; /* Well, the bang-shell is implicit... */
45 lock_kernel();
46 dput(bprm->dentry);
47 unlock_kernel();
48 bprm->dentry = NULL;
50 /* Unlike in the script case, we don't have to do any hairy
51 * parsing to find our interpreter... it's hardcoded!
53 interp = EM86_INTERP;
54 i_name = EM86_I_NAME;
55 i_arg = NULL; /* We reserve the right to add an arg later */
58 * Splice in (1) the interpreter's name for argv[0]
59 * (2) (optional) argument to interpreter
60 * (3) filename of emulated file (replace argv[0])
62 * This is done in reverse order, because of how the
63 * user environment and arguments are stored.
65 remove_arg_zero(bprm);
66 retval = copy_strings_kernel(1, &bprm->filename, bprm);
67 if (retval < 0) return retval;
68 bprm->argc++;
69 if (i_arg) {
70 retval = copy_strings_kernel(1, &i_arg, bprm);
71 if (retval < 0) return retval;
72 bprm->argc++;
74 retval = copy_strings_kernel(1, &i_name, bprm);
75 if (retval < 0) return retval;
76 bprm->argc++;
79 * OK, now restart the process with the interpreter's inode.
80 * Note that we use open_namei() as the name is now in kernel
81 * space, and we don't need to copy it.
83 lock_kernel();
84 dentry = open_namei(interp, 0, 0);
85 unlock_kernel();
86 if (IS_ERR(dentry))
87 return PTR_ERR(dentry);
89 bprm->dentry = dentry;
91 retval = prepare_binprm(bprm);
92 if (retval < 0)
93 return retval;
95 return search_binary_handler(bprm, regs);
98 struct linux_binfmt em86_format = {
99 NULL, THIS_MODULE, load_em86, NULL, NULL, 0
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 module_init(init_em86_binfmt)
113 module_exit(exit_em86_binfmt)