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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [fs/] [binfmt_em86.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_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/malloc.h>
15
#include <linux/binfmts.h>
16
#include <linux/elf.h>
17
 
18
#define EM86_INTERP     "/usr/bin/em86"
19
#define EM86_I_NAME     "em86"
20
 
21
static int do_load_em86(struct linux_binprm *bprm,struct pt_regs *regs)
22
{
23
        char *cp, *interp, *i_name, *i_arg;
24
        int retval;
25
        struct elfhdr   elf_ex;
26
        uid_t           x86_uid;
27
        gid_t           x86_gid;
28
 
29
        /* Make sure this is a Linux/Intel ELF executable... */
30
        elf_ex = *((struct elfhdr *)bprm->buf);
31
 
32
        if (elf_ex.e_ident[0] != 0x7f ||
33
            strncmp(&elf_ex.e_ident[1], "ELF",3) != 0) {
34
                return  -ENOEXEC;
35
        }
36
 
37
 
38
        /* First of all, some simple consistency checks */
39
        if ((elf_ex.e_type != ET_EXEC &&
40
            elf_ex.e_type != ET_DYN) ||
41
           (!((elf_ex.e_machine == EM_386) || (elf_ex.e_machine == EM_486))) ||
42
           (!bprm->inode->i_op || !bprm->inode->i_op->default_file_ops ||
43
            !bprm->inode->i_op->default_file_ops->mmap)){
44
                return -ENOEXEC;
45
        }
46
 
47
        bprm->sh_bang++;        /* Well, the bang-shell is implicit... */
48
        iput(bprm->inode);
49
        bprm->dont_iput = 1;
50
 
51
        /* Unlike in the script case, we don't have to do any hairy
52
         * parsing to find our interpreter... it's hardcoded!
53
         */
54
        interp = EM86_INTERP;
55
        i_name = EM86_I_NAME;
56
        i_arg = NULL;           /* We reserve the right to add an arg later */
57
 
58
        /*
59
         * Splice in (1) the interpreter's name for argv[0]
60
         *           (2) (optional) argument to interpreter
61
         *           (3) filename of emulated file (replace argv[0])
62
         *
63
         * This is done in reverse order, because of how the
64
         * user environment and arguments are stored.
65
         */
66
        remove_arg_zero(bprm);
67
        bprm->p = copy_strings(1, &bprm->filename, bprm->page, bprm->p, 2);
68
        bprm->argc++;
69
        if (i_arg) {
70
                bprm->p = copy_strings(1, &i_arg, bprm->page, bprm->p, 2);
71
                bprm->argc++;
72
        }
73
        bprm->p = copy_strings(1, &i_name, bprm->page, bprm->p, 2);
74
        bprm->argc++;
75
        if (!bprm->p)
76
                return -E2BIG;
77
        /*
78
         * OK, now restart the process with the interpreter's inode.
79
         * Note that we use open_namei() as the name is now in kernel
80
         * space, and we don't need to copy it.
81
         */
82
        retval = open_namei(interp, 0, 0, &bprm->inode, NULL);
83
        if (retval)
84
                return retval;
85
        bprm->dont_iput=0;
86
 
87
        /* Remember the uid/gid that was set by this executable */
88
        x86_uid = bprm->e_uid;
89
        x86_gid = bprm->e_gid;
90
        retval=prepare_binprm(bprm);
91
        if(retval<0)
92
                return retval;
93
 
94
        /* ...so that we may propagate them to em86 */
95
        bprm->e_uid = x86_uid;
96
        bprm->e_gid = x86_gid;
97
        current->personality = PER_LINUX_EM86;
98
        return search_binary_handler(bprm,regs);
99
}
100
 
101
static int load_em86(struct linux_binprm *bprm,struct pt_regs *regs)
102
{
103
        int retval;
104
        MOD_INC_USE_COUNT;
105
        retval = do_load_em86(bprm,regs);
106
        MOD_DEC_USE_COUNT;
107
        return retval;
108
}
109
 
110
struct linux_binfmt em86_format = {
111
#ifndef MODULE
112
        NULL, 0, load_em86, NULL, NULL
113
#else
114
        NULL, &mod_use_count_, load_em86, NULL, NULL
115
#endif
116
};
117
 
118
int init_em86_binfmt(void) {
119
        return register_binfmt(&em86_format);
120
}
121
 
122
#ifdef MODULE
123
int init_module(void)
124
{
125
        return init_em86_binfmt();
126
}
127
 
128
void cleanup_module( void) {
129
        unregister_binfmt(&em86_format);
130
}
131
#endif

powered by: WebSVN 2.1.0

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