Subversion Repositories HelenOS

Rev

Rev 4347 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4347 Rev 4348
Line 150... Line 150...
150
 * @param request
150
 * @param request
151
 */
151
 */
152
static void loader_set_args(ipc_callid_t rid, ipc_call_t *request)
152
static void loader_set_args(ipc_callid_t rid, ipc_call_t *request)
153
{
153
{
154
    ipc_callid_t callid;
154
    ipc_callid_t callid;
155
    size_t buf_len, arg_len;
155
    size_t buf_size, arg_size;
156
    char *p;
156
    char *p;
157
    int n;
157
    int n;
158
   
158
   
159
    if (!ipc_data_write_receive(&callid, &buf_len)) {
159
    if (!ipc_data_write_receive(&callid, &buf_size)) {
160
        ipc_answer_0(callid, EINVAL);
160
        ipc_answer_0(callid, EINVAL);
161
        ipc_answer_0(rid, EINVAL);
161
        ipc_answer_0(rid, EINVAL);
162
        return;
162
        return;
163
    }
163
    }
164
   
164
   
Line 170... Line 170...
170
    if (argv != NULL) {
170
    if (argv != NULL) {
171
        free(argv);
171
        free(argv);
172
        argv = NULL;
172
        argv = NULL;
173
    }
173
    }
174
   
174
   
175
    arg_buf = malloc(buf_len + 1);
175
    arg_buf = malloc(buf_size + 1);
176
    if (!arg_buf) {
176
    if (!arg_buf) {
177
        ipc_answer_0(callid, ENOMEM);
177
        ipc_answer_0(callid, ENOMEM);
178
        ipc_answer_0(rid, ENOMEM);
178
        ipc_answer_0(rid, ENOMEM);
179
        return;
179
        return;
180
    }
180
    }
181
   
181
   
182
    ipc_data_write_finalize(callid, arg_buf, buf_len);
182
    ipc_data_write_finalize(callid, arg_buf, buf_size);
183
    ipc_answer_0(rid, EOK);
-
 
184
   
183
   
185
    arg_buf[buf_len] = '\0';
184
    arg_buf[buf_size] = '\0';
186
   
185
   
187
    /*
186
    /*
188
     * Count number of arguments
187
     * Count number of arguments
189
     */
188
     */
190
    p = arg_buf;
189
    p = arg_buf;
191
    n = 0;
190
    n = 0;
192
    while (p < arg_buf + buf_len) {
191
    while (p < arg_buf + buf_size) {
193
        arg_len = strlen(p);
192
        arg_size = str_size(p);
194
        p = p + arg_len + 1;
193
        p = p + arg_size + 1;
195
        ++n;
194
        ++n;
196
    }
195
    }
197
   
196
   
198
    /* Allocate argv */
197
    /* Allocate argv */
199
    argv = malloc((n + 1) * sizeof(char *));
198
    argv = malloc((n + 1) * sizeof(char *));
200
   
199
   
201
    if (argv == NULL) {
200
    if (argv == NULL) {
202
        free(arg_buf);
201
        free(arg_buf);
203
        ipc_answer_0(callid, ENOMEM);
-
 
204
        ipc_answer_0(rid, ENOMEM);
202
        ipc_answer_0(rid, ENOMEM);
205
        return;
203
        return;
206
    }
204
    }
207
   
205
 
208
    /*
206
    /*
209
     * Fill argv with argument pointers
207
     * Fill argv with argument pointers
210
     */
208
     */
211
    p = arg_buf;
209
    p = arg_buf;
212
    n = 0;
210
    n = 0;
213
    while (p < arg_buf + buf_len) {
211
    while (p < arg_buf + buf_size) {
214
        argv[n] = p;
212
        argv[n] = p;
215
       
213
       
216
        arg_len = strlen(p);
214
        arg_size = str_size(p);
217
        p = p + arg_len + 1;
215
        p = p + arg_size + 1;
218
        ++n;
216
        ++n;
219
    }
217
    }
220
   
218
   
221
    argc = n;
219
    argc = n;
222
    argv[n] = NULL;
220
    argv[n] = NULL;
-
 
221
 
-
 
222
    ipc_answer_0(rid, EOK);
223
}
223
}
224
 
224
 
225
/** Load the previously selected program.
225
/** Load the previously selected program.
226
 *
226
 *
227
 * @param rid
227
 * @param rid
Line 231... Line 231...
231
static int loader_load(ipc_callid_t rid, ipc_call_t *request)
231
static int loader_load(ipc_callid_t rid, ipc_call_t *request)
232
{
232
{
233
    int rc;
233
    int rc;
234
   
234
   
235
    rc = elf_load_file(pathname, 0, 0, &prog_info);
235
    rc = elf_load_file(pathname, 0, 0, &prog_info);
236
    if (rc < 0) {
236
    if (rc != EE_OK) {
237
        DPRINTF("Failed to load executable '%s'.\n", pathname);
237
        DPRINTF("Failed to load executable '%s'.\n", pathname);
238
        ipc_answer_0(rid, EINVAL);
238
        ipc_answer_0(rid, EINVAL);
239
        return 1;
239
        return 1;
240
    }
240
    }
241
   
241
   
Line 251... Line 251...
251
        return 0;
251
        return 0;
252
    }
252
    }
253
   
253
   
254
    printf("Load ELF interpreter '%s'\n", prog_info.interp);
254
    printf("Load ELF interpreter '%s'\n", prog_info.interp);
255
    rc = elf_load_file(prog_info.interp, 0, 0, &interp_info);
255
    rc = elf_load_file(prog_info.interp, 0, 0, &interp_info);
256
    if (rc < 0) {
256
    if (rc != EE_OK) {
257
        DPRINTF("Failed to load interpreter '%s.'\n",
257
        DPRINTF("Failed to load interpreter '%s.'\n",
258
            prog_info.interp);
258
            prog_info.interp);
259
        ipc_answer_0(rid, EINVAL);
259
        ipc_answer_0(rid, EINVAL);
260
        return 1;
260
        return 1;
261
    }
261
    }
Line 281... Line 281...
281
static void loader_run(ipc_callid_t rid, ipc_call_t *request)
281
static void loader_run(ipc_callid_t rid, ipc_call_t *request)
282
{
282
{
283
    const char *cp;
283
    const char *cp;
284
   
284
   
285
    /* Set the task name. */
285
    /* Set the task name. */
286
    cp = strrchr(pathname, '/');
286
    cp = str_rchr(pathname, '/');
287
    cp = (cp == NULL) ? pathname : (cp + 1);
287
    cp = (cp == NULL) ? pathname : (cp + 1);
288
    task_set_name(cp);
288
    task_set_name(cp);
289
   
289
   
290
    if (is_dyn_linked == true) {
290
    if (is_dyn_linked == true) {
291
        /* Dynamically linked program */
291
        /* Dynamically linked program */