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/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 do_load_em86(struct linux_binprm
*bprm
,struct pt_regs
*regs
)
25 char *interp
, *i_name
, *i_arg
;
26 struct dentry
* dentry
;
30 /* Make sure this is a Linux/Intel ELF executable... */
31 elf_ex
= *((struct elfhdr
*)bprm
->buf
);
33 if (elf_ex
.e_ident
[0] != 0x7f ||
34 strncmp(&elf_ex
.e_ident
[1], "ELF",3) != 0) {
39 /* First of all, some simple consistency checks */
40 if ((elf_ex
.e_type
!= ET_EXEC
&&
41 elf_ex
.e_type
!= ET_DYN
) ||
42 (!((elf_ex
.e_machine
== EM_386
) || (elf_ex
.e_machine
== EM_486
))) ||
43 (!bprm
->dentry
->d_inode
->i_op
|| !bprm
->dentry
->d_inode
->i_op
->default_file_ops
||
44 !bprm
->dentry
->d_inode
->i_op
->default_file_ops
->mmap
)){
48 bprm
->sh_bang
++; /* Well, the bang-shell is implicit... */
52 /* Unlike in the script case, we don't have to do any hairy
53 * parsing to find our interpreter... it's hardcoded!
57 i_arg
= NULL
; /* We reserve the right to add an arg later */
60 * Splice in (1) the interpreter's name for argv[0]
61 * (2) (optional) argument to interpreter
62 * (3) filename of emulated file (replace argv[0])
64 * This is done in reverse order, because of how the
65 * user environment and arguments are stored.
67 remove_arg_zero(bprm
);
68 bprm
->p
= copy_strings(1, &bprm
->filename
, bprm
->page
, bprm
->p
, 2);
71 bprm
->p
= copy_strings(1, &i_arg
, bprm
->page
, bprm
->p
, 2);
74 bprm
->p
= copy_strings(1, &i_name
, bprm
->page
, bprm
->p
, 2);
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 dentry
= open_namei(interp
, 0, 0);
85 return PTR_ERR(dentry
);
87 bprm
->dentry
= dentry
;
89 retval
= prepare_binprm(bprm
);
93 return search_binary_handler(bprm
, regs
);
96 static int load_em86(struct linux_binprm
*bprm
,struct pt_regs
*regs
)
100 retval
= do_load_em86(bprm
,regs
);
105 struct linux_binfmt em86_format
= {
107 NULL
, 0, load_em86
, NULL
, NULL
109 NULL
, &__this_module
, load_em86
, NULL
, NULL
113 int __init
init_em86_binfmt(void)
115 return register_binfmt(&em86_format
);
119 int init_module(void)
121 return init_em86_binfmt();
124 void cleanup_module( void) {
125 unregister_binfmt(&em86_format
);