* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / elksemu / binfmt_elks.c
blobcf408194bd574c5b48c76d5a15b6ca791e7506a9
1 /*
2 * linux/fs/binfmt_elks.c
4 * Copyright (C) 1996 Martin von Löwis
5 * original #!-checking implemented by tytso.
6 * ELKS hack added by Chad Page...
7 * Cleaned up some more by Robert de Bath
8 */
10 #include <linux/module.h>
11 #ifndef LINUX_VERSION_CODE
12 #include <linux/version.h>
13 #endif
14 #include <linux/string.h>
15 #include <linux/stat.h>
16 #include <linux/malloc.h>
17 #include <linux/binfmts.h>
19 static int do_load_elksaout(struct linux_binprm *bprm,struct pt_regs *regs)
21 char *cp, *interp, *i_name, *i_arg;
22 int retval;
24 /* What a horrible hack! :-) */
25 if ((bprm->buf[0] != 1) || (bprm->buf[1] != 3) ||
26 (bprm->buf[2] != 0x20 && bprm->buf[2] != 0x10) ||
27 (bprm->buf[3] != 4) || bprm->sh_bang)
28 return -ENOEXEC;
30 bprm->sh_bang++;
31 iput(bprm->inode);
32 #if LINUX_VERSION_CODE >= 0x010300
33 bprm->dont_iput=1;
34 #endif
36 interp = "/lib/elksemu";
37 i_name = interp;
38 i_arg = 0;
40 for (cp=i_name; *cp && (*cp != ' ') && (*cp != '\t'); cp++) {
41 if (*cp == '/')
42 i_name = cp+1;
46 * OK, we've parsed out the interpreter name and
47 * (optional) argument.
48 * Splice in (1) the interpreter's name for argv[0]
49 * (2) (optional) argument to interpreter
50 * (3) filename of shell script (replace argv[0])
52 * This is done in reverse order, because of how the
53 * user environment and arguments are stored.
55 remove_arg_zero(bprm);
56 bprm->p = copy_strings(1, &bprm->filename, bprm->page, bprm->p, 2);
57 bprm->argc++;
58 if (i_arg) {
59 bprm->p = copy_strings(1, &i_arg, bprm->page, bprm->p, 2);
60 bprm->argc++;
62 bprm->p = copy_strings(1, &i_name, bprm->page, bprm->p, 2);
63 bprm->argc++;
64 if (!bprm->p)
65 return -E2BIG;
67 * OK, now restart the process with the interpreter's inode.
68 * Note that we use open_namei() as the name is now in kernel
69 * space, and we don't need to copy it.
71 retval = open_namei(interp, 0, 0, &bprm->inode, NULL);
72 if (retval)
73 return retval;
74 #if LINUX_VERSION_CODE >= 0x010300
75 bprm->dont_iput=0;
76 #endif
77 retval=prepare_binprm(bprm);
78 if(retval<0)
79 return retval;
80 return search_binary_handler(bprm,regs);
83 static int load_elksaout(struct linux_binprm *bprm,struct pt_regs *regs)
85 int retval;
86 MOD_INC_USE_COUNT;
87 retval = do_load_elksaout(bprm,regs);
88 MOD_DEC_USE_COUNT;
89 return retval;
92 struct linux_binfmt elksaout_format = {
93 #ifndef MODULE
94 NULL, 0, load_elksaout, NULL, NULL
95 #else
96 NULL, &mod_use_count_, load_elksaout, NULL, NULL
97 #endif
100 int init_elksaout_binfmt(void) {
101 return register_binfmt(&elksaout_format);
104 #ifdef MODULE
105 #if LINUX_VERSION_CODE < 0x010300
106 char kernel_version[] = UTS_RELEASE;
107 #endif
108 int init_module(void)
110 return init_elksaout_binfmt();
113 void cleanup_module( void) {
114 unregister_binfmt(&elksaout_format);
116 #endif