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
10 #include <linux/module.h>
11 #ifndef LINUX_VERSION_CODE
12 #include <linux/version.h>
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
;
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
)
32 #if LINUX_VERSION_CODE >= 0x010300
36 interp
= "/lib/elksemu";
40 for (cp
=i_name
; *cp
&& (*cp
!= ' ') && (*cp
!= '\t'); cp
++) {
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);
59 bprm
->p
= copy_strings(1, &i_arg
, bprm
->page
, bprm
->p
, 2);
62 bprm
->p
= copy_strings(1, &i_name
, bprm
->page
, bprm
->p
, 2);
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
);
74 #if LINUX_VERSION_CODE >= 0x010300
77 retval
=prepare_binprm(bprm
);
80 return search_binary_handler(bprm
,regs
);
83 static int load_elksaout(struct linux_binprm
*bprm
,struct pt_regs
*regs
)
87 retval
= do_load_elksaout(bprm
,regs
);
92 struct linux_binfmt elksaout_format
= {
94 NULL
, 0, load_elksaout
, NULL
, NULL
96 NULL
, &mod_use_count_
, load_elksaout
, NULL
, NULL
100 int init_elksaout_binfmt(void) {
101 return register_binfmt(&elksaout_format
);
105 #if LINUX_VERSION_CODE < 0x010300
106 char kernel_version
[] = UTS_RELEASE
;
108 int init_module(void)
110 return init_elksaout_binfmt();
113 void cleanup_module( void) {
114 unregister_binfmt(&elksaout_format
);