2 * linux/fs/binfmt_java.c
4 * Copyright (C) 1996 Brian A. Lantz
5 * derived from binfmt_script.c
7 * Simplified and modified to support binary java interpreters
8 * by Tom May <ftom@netcom.com>.
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/init.h>
18 #define _PATH_JAVA "/usr/bin/java"
19 #define _PATH_APPLET "/usr/bin/appletviewer"
21 /* These paths can be modified with sysctl(). */
23 char binfmt_java_interpreter
[65] = _PATH_JAVA
;
24 char binfmt_java_appletviewer
[65] = _PATH_APPLET
;
26 static int do_load_java(struct linux_binprm
*bprm
,struct pt_regs
*regs
)
31 struct dentry
* dentry
;
32 unsigned char *ucp
= (unsigned char *) bprm
->buf
;
34 if ((ucp
[0] != 0xca) || (ucp
[1] != 0xfe) || (ucp
[2] != 0xba) || (ucp
[3] != 0xbe))
38 * Fail if we're called recursively, e.g., the Java interpreter
51 * Set args: [0] the name of the java interpreter
52 * [1] name of java class to execute, which is the
53 * filename without the path and without trailing
54 * ".class". Note that the interpreter will use
55 * its own way to found the class file (typically using
56 * environment variable CLASSPATH), and may in fact
57 * execute a different file from the one we want.
59 * This is done in reverse order, because of how the
60 * user environment and arguments are stored.
62 remove_arg_zero(bprm
);
63 len
= strlen (bprm
->filename
);
64 if (len
>= 6 && !strcmp (bprm
->filename
+ len
- 6, ".class"))
65 bprm
->filename
[len
- 6] = 0;
66 if ((i_name
= strrchr (bprm
->filename
, '/')) != NULL
)
69 i_name
= bprm
->filename
;
70 bprm
->p
= copy_strings(1, &i_name
, bprm
->page
, bprm
->p
, 2);
73 i_name
= binfmt_java_interpreter
;
74 bprm
->p
= copy_strings(1, &i_name
, bprm
->page
, bprm
->p
, 2);
80 * OK, now restart the process with the interpreter's dentry.
82 bprm
->filename
= binfmt_java_interpreter
;
83 dentry
= open_namei(binfmt_java_interpreter
, 0, 0);
84 retval
= PTR_ERR(dentry
);
88 bprm
->dentry
= dentry
;
89 retval
= prepare_binprm(bprm
);
93 return search_binary_handler(bprm
,regs
);
96 static int do_load_applet(struct linux_binprm
*bprm
,struct pt_regs
*regs
)
99 struct dentry
* dentry
;
102 if (strncmp (bprm
->buf
, "<!--applet", 10))
109 * Set args: [0] the name of the appletviewer
110 * [1] filename of html file
112 * This is done in reverse order, because of how the
113 * user environment and arguments are stored.
115 remove_arg_zero(bprm
);
116 i_name
= bprm
->filename
;
117 bprm
->p
= copy_strings(1, &i_name
, bprm
->page
, bprm
->p
, 2);
120 i_name
= binfmt_java_appletviewer
;
121 bprm
->p
= copy_strings(1, &i_name
, bprm
->page
, bprm
->p
, 2);
127 * OK, now restart the process with the interpreter's dentry.
129 bprm
->filename
= binfmt_java_appletviewer
;
130 dentry
= open_namei(binfmt_java_appletviewer
, 0, 0);
131 retval
= PTR_ERR(dentry
);
135 bprm
->dentry
= dentry
;
136 retval
= prepare_binprm(bprm
);
140 return search_binary_handler(bprm
,regs
);
143 static int load_java(struct linux_binprm
*bprm
,struct pt_regs
*regs
)
147 retval
= do_load_java(bprm
,regs
);
152 static struct linux_binfmt java_format
= {
154 NULL
, 0, load_java
, NULL
, NULL
156 NULL
, &__this_module
, load_java
, NULL
, NULL
160 static int load_applet(struct linux_binprm
*bprm
,struct pt_regs
*regs
)
164 retval
= do_load_applet(bprm
,regs
);
169 static struct linux_binfmt applet_format
= {
171 NULL
, 0, load_applet
, NULL
, NULL
173 NULL
, &__this_module
, load_applet
, NULL
, NULL
177 int __init
init_java_binfmt(void)
179 register_binfmt(&java_format
);
180 return register_binfmt(&applet_format
);
184 int init_module(void)
186 return init_java_binfmt();
189 void cleanup_module( void) {
190 unregister_binfmt(&java_format
);
191 unregister_binfmt(&applet_format
);