~jsvoboda/helenos/initbin

« back to all changes in this revision

Viewing changes to kernel/generic/src/proc/program.c

  • Committer: Jiri Svoboda
  • Date: 2010-11-17 21:45:46 UTC
  • Revision ID: jiri@wiwaxia-20101117214546-yt46xsohd2zsqn0y
Isolate processing of init binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include <ipc/ipc.h>
48
48
#include <ipc/ipcrsc.h>
49
49
#include <security/cap.h>
50
 
#include <lib/elf.h>
 
50
#include <lib/elfld.h>
51
51
#include <errno.h>
52
52
#include <print.h>
53
53
#include <syscall/copy.h>
63
63
 */
64
64
void *program_loader = NULL;
65
65
 
 
66
static void program_ready(program_t *prg);
 
67
 
66
68
/** Create a program using an existing address space.
67
69
 *
68
70
 * @param as         Address space containing a binary program image.
73
75
 * @return EOK on success or negative error code.
74
76
 *
75
77
 */
76
 
int program_create(as_t *as, uintptr_t entry_addr, char *name, program_t *prg)
 
78
static int program_create(as_t *as, uintptr_t entry_addr, char *name,
 
79
    program_t *prg)
77
80
{
78
81
        uspace_arg_t *kernel_uarg;
79
82
        
111
114
 
112
115
/** Parse an executable image in the kernel memory.
113
116
 *
114
 
 * If the image belongs to a program loader, it is registered as such,
115
 
 * (and *task is set to NULL). Otherwise a task is created from the
116
 
 * executable image. The task is returned in *task.
117
 
 *
118
117
 * @param image_addr Address of an executable program image.
119
118
 * @param name       Name to set for the program's task.
120
 
 * @param prg        Buffer for storing program info. If image_addr
121
 
 *                   points to a loader image, p->task will be set to
122
 
 *                   NULL and EOK will be returned.
 
119
 * @param prg        Buffer for storing program info.
123
120
 *
124
121
 * @return EOK on success or negative error code.
125
 
 *
126
122
 */
127
 
int program_create_from_image(void *image_addr, char *name, program_t *prg)
 
123
static int program_create_from_image(void *image_addr, char *name,
 
124
    program_t *prg)
128
125
{
129
126
        as_t *as = as_create(0);
130
127
        if (!as)
136
133
                prg->task = NULL;
137
134
                prg->main_thread = NULL;
138
135
                
139
 
                if (rc != EE_LOADER)
140
 
                        return ENOTSUP;
141
 
                
142
 
                /* Register image as the program loader */
143
 
                if (program_loader != NULL)
144
 
                        return ELIMIT;
145
 
                
146
 
                program_loader = image_addr;
147
 
                LOG("Registered program loader at 0x%" PRIp,
148
 
                    image_addr);
149
 
                
150
 
                return EOK;
 
136
                return ENOTSUP;
151
137
        }
152
138
        
153
139
        return program_create(as, ((elf_header_t *) image_addr)->e_entry,
154
140
            name, prg);
155
141
}
156
142
 
 
143
/** Launch program from an executable image in memory.
 
144
 *
 
145
 * @param image_addr Address of an executable program image.
 
146
 * @param name       Name to set for the program's task.
 
147
 *
 
148
 * @return EOK on success or negative error code.
 
149
 */
 
150
int program_spawn_image(void *image, char *name)
 
151
{
 
152
        program_t prg;
 
153
        int rc;
 
154
 
 
155
        rc = program_create_from_image(image, name, &prg);
 
156
        if (rc != EOK)
 
157
                return rc;
 
158
 
 
159
        /*
 
160
         * Set capabilities to initial userspace task.
 
161
         */
 
162
        cap_set(prg.task, CAP_CAP | CAP_MEM_MANAGER | CAP_IO_MANAGER |
 
163
            CAP_IRQ_REG);
 
164
        if (!ipc_phone_0)
 
165
                ipc_phone_0 = &prg.task->answerbox;
 
166
 
 
167
        program_ready(&prg);
 
168
 
 
169
        return EOK;
 
170
}
 
171
 
 
172
/** Register program loader image.
 
173
 *
 
174
 * Store pointer to program loader image. Later instances of the loader
 
175
 * are created via sys_program_spawn_loader().
 
176
 */
 
177
void program_register_loader(void *image)
 
178
{
 
179
        program_loader = image;
 
180
}
 
181
 
157
182
/** Create a task from the program loader image.
158
183
 *
159
184
 * @param prg  Buffer for storing program info.
162
187
 * @return EOK on success or negative error code.
163
188
 *
164
189
 */
165
 
int program_create_loader(program_t *prg, char *name)
 
190
static int program_create_loader(program_t *prg, char *name)
166
191
{
167
192
        as_t *as = as_create(0);
168
193
        if (!as)
192
217
 * @param prg Program to make ready.
193
218
 *
194
219
 */
195
 
void program_ready(program_t *prg)
 
220
static void program_ready(program_t *prg)
196
221
{
197
222
        thread_ready(prg->main_thread);
198
223
}