Root/
Source at commit cdde9cf73945d547acd3e96f9508c79e84ad0bf1 created 12 years 9 months ago. By Maarten ter Huurne, MMC: JZ4740: Added support for CPU frequency changing | |
---|---|
1 | /* |
2 | * linux/fs/binfmt_em86.c |
3 | * |
4 | * Based on linux/fs/binfmt_script.c |
5 | * Copyright (C) 1996 Martin von Löwis |
6 | * original #!-checking implemented by tytso. |
7 | * |
8 | * em86 changes Copyright (C) 1997 Jim Paradis |
9 | */ |
10 | |
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> |
17 | #include <linux/fs.h> |
18 | #include <linux/file.h> |
19 | #include <linux/errno.h> |
20 | |
21 | |
22 | #define EM86_INTERP "/usr/bin/em86" |
23 | #define EM86_I_NAME "em86" |
24 | |
25 | static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs) |
26 | { |
27 | char *interp, *i_name, *i_arg; |
28 | struct file * file; |
29 | int retval; |
30 | struct elfhdr elf_ex; |
31 | |
32 | /* Make sure this is a Linux/Intel ELF executable... */ |
33 | elf_ex = *((struct elfhdr *)bprm->buf); |
34 | |
35 | if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0) |
36 | return -ENOEXEC; |
37 | |
38 | /* First of all, some simple consistency checks */ |
39 | if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) || |
40 | (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) || |
41 | (!bprm->file->f_op || !bprm->file->f_op->mmap)) { |
42 | return -ENOEXEC; |
43 | } |
44 | |
45 | bprm->recursion_depth++; /* Well, the bang-shell is implicit... */ |
46 | allow_write_access(bprm->file); |
47 | fput(bprm->file); |
48 | bprm->file = NULL; |
49 | |
50 | /* Unlike in the script case, we don't have to do any hairy |
51 | * parsing to find our interpreter... it's hardcoded! |
52 | */ |
53 | interp = EM86_INTERP; |
54 | i_name = EM86_I_NAME; |
55 | i_arg = NULL; /* We reserve the right to add an arg later */ |
56 | |
57 | /* |
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]) |
61 | * |
62 | * This is done in reverse order, because of how the |
63 | * user environment and arguments are stored. |
64 | */ |
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++; |
73 | } |
74 | retval = copy_strings_kernel(1, &i_name, bprm); |
75 | if (retval < 0) return retval; |
76 | bprm->argc++; |
77 | |
78 | /* |
79 | * OK, now restart the process with the interpreter's inode. |
80 | * Note that we use open_exec() as the name is now in kernel |
81 | * space, and we don't need to copy it. |
82 | */ |
83 | file = open_exec(interp); |
84 | if (IS_ERR(file)) |
85 | return PTR_ERR(file); |
86 | |
87 | bprm->file = file; |
88 | |
89 | retval = prepare_binprm(bprm); |
90 | if (retval < 0) |
91 | return retval; |
92 | |
93 | return search_binary_handler(bprm, regs); |
94 | } |
95 | |
96 | static struct linux_binfmt em86_format = { |
97 | .module = THIS_MODULE, |
98 | .load_binary = load_em86, |
99 | }; |
100 | |
101 | static int __init init_em86_binfmt(void) |
102 | { |
103 | register_binfmt(&em86_format); |
104 | return 0; |
105 | } |
106 | |
107 | static void __exit exit_em86_binfmt(void) |
108 | { |
109 | unregister_binfmt(&em86_format); |
110 | } |
111 | |
112 | core_initcall(init_em86_binfmt); |
113 | module_exit(exit_em86_binfmt); |
114 | MODULE_LICENSE("GPL"); |
115 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9