This source file includes following definitions.
- load_em86
- init_em86_binfmt
- exit_em86_binfmt
1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/module.h>
13 #include <linux/string.h>
14 #include <linux/stat.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>
21
22
23 #define EM86_INTERP "/usr/bin/em86"
24 #define EM86_I_NAME "em86"
25
26 static int load_em86(struct linux_binprm *bprm)
27 {
28 const char *i_name, *i_arg;
29 char *interp;
30 struct file * file;
31 int retval;
32 struct elfhdr elf_ex;
33
34
35 elf_ex = *((struct elfhdr *)bprm->buf);
36
37 if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
38 return -ENOEXEC;
39
40
41 if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
42 (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) ||
43 !bprm->file->f_op->mmap) {
44 return -ENOEXEC;
45 }
46
47
48 if (bprm->interp_flags & BINPRM_FLAGS_PATH_INACCESSIBLE)
49 return -ENOENT;
50
51 allow_write_access(bprm->file);
52 fput(bprm->file);
53 bprm->file = NULL;
54
55
56
57
58 interp = EM86_INTERP;
59 i_name = EM86_I_NAME;
60 i_arg = NULL;
61
62
63
64
65
66
67
68
69
70 remove_arg_zero(bprm);
71 retval = copy_strings_kernel(1, &bprm->filename, bprm);
72 if (retval < 0) return retval;
73 bprm->argc++;
74 if (i_arg) {
75 retval = copy_strings_kernel(1, &i_arg, bprm);
76 if (retval < 0) return retval;
77 bprm->argc++;
78 }
79 retval = copy_strings_kernel(1, &i_name, bprm);
80 if (retval < 0) return retval;
81 bprm->argc++;
82
83
84
85
86
87
88 file = open_exec(interp);
89 if (IS_ERR(file))
90 return PTR_ERR(file);
91
92 bprm->file = file;
93
94 retval = prepare_binprm(bprm);
95 if (retval < 0)
96 return retval;
97
98 return search_binary_handler(bprm);
99 }
100
101 static struct linux_binfmt em86_format = {
102 .module = THIS_MODULE,
103 .load_binary = load_em86,
104 };
105
106 static int __init init_em86_binfmt(void)
107 {
108 register_binfmt(&em86_format);
109 return 0;
110 }
111
112 static void __exit exit_em86_binfmt(void)
113 {
114 unregister_binfmt(&em86_format);
115 }
116
117 core_initcall(init_em86_binfmt);
118 module_exit(exit_em86_binfmt);
119 MODULE_LICENSE("GPL");