OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [fs/] [binfmt_java.c] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *  linux/fs/binfmt_java.c
3
 *
4
 *  Copyright (C) 1996  Brian A. Lantz
5
 *  derived from binfmt_script.c
6
 */
7
 
8
#include <linux/module.h>
9
#include <linux/string.h>
10
#include <linux/stat.h>
11
#include <linux/malloc.h>
12
#include <linux/binfmts.h>
13
 
14
#define _PATH_JAVA      "/usr/bin/java"
15
#define _PATH_APPLET    "/usr/bin/appletviewer"
16
#define _PATH_SH        "/bin/bash"
17
 
18
char binfmt_java_interpreter[65] = _PATH_JAVA;
19
char binfmt_java_appletviewer[65] = _PATH_APPLET;
20
 
21
static int do_load_script(struct linux_binprm *bprm,struct pt_regs *regs)
22
{
23
        char *cp, *interp, *i_name;
24
        int retval;
25
        unsigned char *ucp = (unsigned char *) bprm->buf;
26
        if ((ucp[0] != 0xca) || (ucp[1] != 0xfe) || (ucp[2] != 0xba) || (ucp[3] != 0xbe))
27
                return -ENOEXEC;
28
 
29
        iput(bprm->inode);
30
        bprm->dont_iput=1;
31
 
32
        /*
33
         * OK, we've set the interpreter name
34
         * Splice in (1) the interpreter's name for argv[0] (_PATH_SH)
35
         *           (2) the name of the java wrapper for argv[1] (_PATH_JAVA)
36
         *           (3) filename of Java class (replace argv[0])
37
         *               without leading path or trailing '.class'
38
         *
39
         * This is done in reverse order, because of how the
40
         * user environment and arguments are stored.
41
         */
42
        remove_arg_zero(bprm);
43
        if ((cp = strstr (bprm->filename, ".class")) != NULL)
44
                *cp = 0;
45
        if ((i_name = strrchr (bprm->filename, '/')) != NULL)
46
                i_name++;
47
        else
48
                i_name = bprm->filename;
49
        bprm->p = copy_strings(1, &i_name, bprm->page, bprm->p, 2);
50
        bprm->argc++;
51
 
52
        strcpy (bprm->buf, binfmt_java_interpreter);
53
        cp = bprm->buf;
54
        bprm->p = copy_strings(1, &cp, bprm->page, bprm->p, 2);
55
        bprm->argc++;
56
 
57
        strcpy (bprm->buf, _PATH_SH);
58
        interp = bprm->buf;
59
        if ((i_name = strrchr (bprm->buf, '/')) != NULL)
60
                i_name++;
61
        else
62
                i_name = bprm->buf;
63
        bprm->p = copy_strings(1, &i_name, bprm->page, bprm->p, 2);
64
        bprm->argc++;
65
        if (!bprm->p)
66
                return -E2BIG;
67
        /*
68
         * OK, now restart the process with the interpreter's inode.
69
         * Note that we use open_namei() as the name is now in kernel
70
         * space, and we don't need to copy it.
71
         */
72
        retval = open_namei(interp, 0, 0, &bprm->inode, NULL);
73
        if (retval)
74
                return retval;
75
        bprm->dont_iput=0;
76
        retval=prepare_binprm(bprm);
77
        if(retval<0)
78
                return retval;
79
 
80
        return search_binary_handler(bprm,regs);
81
}
82
 
83
static int do_load_applet(struct linux_binprm *bprm,struct pt_regs *regs)
84
{
85
        char *cp, *interp, *i_name;
86
        int retval;
87
        if (strncmp (bprm->buf, "<!--applet", 10))
88
                return -ENOEXEC;
89
 
90
        iput(bprm->inode);
91
        bprm->dont_iput=1;
92
 
93
        /*
94
         * OK, we've set the interpreter name
95
         * Splice in (1) the interpreter's name for argv[0] (_PATH_SH)
96
         *           (2) the name of the appletviewer wrapper for argv[1] (_PATH_APPLET)
97
         *           (3) filename of html file (replace argv[0])
98
         *
99
         * This is done in reverse order, because of how the
100
         * user environment and arguments are stored.
101
         */
102
        remove_arg_zero(bprm);
103
        i_name = bprm->filename;
104
        bprm->p = copy_strings(1, &i_name, bprm->page, bprm->p, 2);
105
        bprm->argc++;
106
 
107
        strcpy (bprm->buf, binfmt_java_appletviewer);
108
        cp = bprm->buf;
109
        bprm->p = copy_strings(1, &cp, bprm->page, bprm->p, 2);
110
        bprm->argc++;
111
 
112
        strcpy (bprm->buf, _PATH_SH);
113
        interp = bprm->buf;
114
        if ((i_name = strrchr (bprm->buf, '/')) != NULL)
115
                i_name++;
116
        else
117
                i_name = bprm->buf;
118
        bprm->p = copy_strings(1, &i_name, bprm->page, bprm->p, 2);
119
        bprm->argc++;
120
        if (!bprm->p)
121
                return -E2BIG;
122
        /*
123
         * OK, now restart the process with the interpreter's inode.
124
         * Note that we use open_namei() as the name is now in kernel
125
         * space, and we don't need to copy it.
126
         */
127
        retval = open_namei(interp, 0, 0, &bprm->inode, NULL);
128
        if (retval)
129
                return retval;
130
        bprm->dont_iput=0;
131
        retval=prepare_binprm(bprm);
132
        if(retval<0)
133
                return retval;
134
 
135
        return search_binary_handler(bprm,regs);
136
}
137
 
138
static int load_script(struct linux_binprm *bprm,struct pt_regs *regs)
139
{
140
        int retval;
141
        MOD_INC_USE_COUNT;
142
        retval = do_load_script(bprm,regs);
143
        MOD_DEC_USE_COUNT;
144
        return retval;
145
}
146
 
147
struct linux_binfmt java_format = {
148
#ifndef MODULE
149
        NULL, 0, load_script, NULL, NULL
150
#else
151
        NULL, &mod_use_count_, load_script, NULL, NULL
152
#endif
153
};
154
 
155
static int load_applet(struct linux_binprm *bprm,struct pt_regs *regs)
156
{
157
        int retval;
158
        MOD_INC_USE_COUNT;
159
        retval = do_load_applet(bprm,regs);
160
        MOD_DEC_USE_COUNT;
161
        return retval;
162
}
163
 
164
struct linux_binfmt applet_format = {
165
#ifndef MODULE
166
        NULL, 0, load_applet, NULL, NULL
167
#else
168
        NULL, &mod_use_count_, load_applet, NULL, NULL
169
#endif
170
};
171
 
172
int init_java_binfmt(void) {
173
        printk(KERN_INFO "JAVA Binary support v1.01 for Linux 1.3.98 (C)1996 Brian A. Lantz\n");
174
        register_binfmt(&java_format);
175
        return register_binfmt(&applet_format);
176
}
177
 
178
#ifdef MODULE
179
int init_module(void)
180
{
181
        return init_java_binfmt();
182
}
183
 
184
void cleanup_module( void) {
185
        printk(KERN_INFO "Removing JAVA Binary support...\n");
186
        unregister_binfmt(&java_format);
187
        unregister_binfmt(&applet_format);
188
}
189
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.