Changeset bbdbf86 in mainline
- Timestamp:
- 2009-06-03T18:46:29Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 215abc1
- Parents:
- bf1fb9f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loader/main.c
rbf1fb9f rbbdbf86 54 54 #include <ipc/loader.h> 55 55 #include <loader/pcb.h> 56 #include <console.h>57 56 #include <errno.h> 58 57 #include <async.h> 58 #include <string.h> 59 59 #include <as.h> 60 60 … … 77 77 static char *arg_buf = NULL; 78 78 79 /** Number of preset files */ 80 static int filc = 0; 81 /** Preset files vector */ 82 static char **filv = NULL; 83 /** Buffer holding all preset files */ 84 static fs_node_t *fil_buf = NULL; 85 79 86 static elf_info_t prog_info; 80 87 static elf_info_t interp_info; … … 85 92 static bool connected; 86 93 87 static void l oader_get_taskid(ipc_callid_t rid, ipc_call_t *request)94 static void ldr_get_taskid(ipc_callid_t rid, ipc_call_t *request) 88 95 { 89 96 ipc_callid_t callid; … … 112 119 * @param request 113 120 */ 114 static void l oader_set_pathname(ipc_callid_t rid, ipc_call_t *request)121 static void ldr_set_pathname(ipc_callid_t rid, ipc_call_t *request) 115 122 { 116 123 ipc_callid_t callid; … … 148 155 * @param request 149 156 */ 150 static void l oader_set_args(ipc_callid_t rid, ipc_call_t *request)157 static void ldr_set_args(ipc_callid_t rid, ipc_call_t *request) 151 158 { 152 159 ipc_callid_t callid; … … 221 228 } 222 229 230 /** Receive a call setting preset files of the program to execute. 231 * 232 * @param rid 233 * @param request 234 */ 235 static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request) 236 { 237 ipc_callid_t callid; 238 size_t buf_size; 239 if (!ipc_data_write_receive(&callid, &buf_size)) { 240 ipc_answer_0(callid, EINVAL); 241 ipc_answer_0(rid, EINVAL); 242 return; 243 } 244 245 if ((buf_size % sizeof(fs_node_t)) != 0) { 246 ipc_answer_0(callid, EINVAL); 247 ipc_answer_0(rid, EINVAL); 248 return; 249 } 250 251 if (fil_buf != NULL) { 252 free(fil_buf); 253 fil_buf = NULL; 254 } 255 256 if (filv != NULL) { 257 free(filv); 258 filv = NULL; 259 } 260 261 fil_buf = malloc(buf_size); 262 if (!fil_buf) { 263 ipc_answer_0(callid, ENOMEM); 264 ipc_answer_0(rid, ENOMEM); 265 return; 266 } 267 268 ipc_data_write_finalize(callid, fil_buf, buf_size); 269 270 int count = buf_size / sizeof(fs_node_t); 271 272 /* Allocate filvv */ 273 filv = malloc((count + 1) * sizeof(fs_node_t *)); 274 275 if (filv == NULL) { 276 free(fil_buf); 277 ipc_answer_0(rid, ENOMEM); 278 return; 279 } 280 281 /* 282 * Fill filv with argument pointers 283 */ 284 int i; 285 for (i = 0; i < count; i++) 286 filv[i] = &fil_buf[i]; 287 288 filc = count; 289 filv[count] = NULL; 290 291 ipc_answer_0(rid, EOK); 292 } 293 223 294 /** Load the previously selected program. 224 295 * … … 227 298 * @return 0 on success, !0 on error. 228 299 */ 229 static int l oader_load(ipc_callid_t rid, ipc_call_t *request)300 static int ldr_load(ipc_callid_t rid, ipc_call_t *request) 230 301 { 231 302 int rc; … … 242 313 pcb.argc = argc; 243 314 pcb.argv = argv; 315 316 pcb.filc = filc; 317 pcb.filv = filv; 244 318 245 319 if (prog_info.interp == NULL) { … … 271 345 * @return 0 on success, !0 on error. 272 346 */ 273 static void l oader_run(ipc_callid_t rid, ipc_call_t *request)347 static void ldr_run(ipc_callid_t rid, ipc_call_t *request) 274 348 { 275 349 const char *cp; … … 284 358 DPRINTF("Run ELF interpreter.\n"); 285 359 DPRINTF("Entry point: 0x%lx\n", interp_info.entry); 286 console_close();287 360 288 361 ipc_answer_0(rid, EOK); … … 290 363 } else { 291 364 /* Statically linked program */ 292 console_close();293 365 ipc_answer_0(rid, EOK); 294 366 elf_run(&prog_info, &pcb); 295 } 296 367 } 368 297 369 /* Not reached */ 298 370 } … … 303 375 * to execute the loaded program). 304 376 */ 305 static void l oader_connection(ipc_callid_t iid, ipc_call_t *icall)377 static void ldr_connection(ipc_callid_t iid, ipc_call_t *icall) 306 378 { 307 379 ipc_callid_t callid; … … 331 403 exit(0); 332 404 case LOADER_GET_TASKID: 333 l oader_get_taskid(callid, &call);405 ldr_get_taskid(callid, &call); 334 406 continue; 335 407 case LOADER_SET_PATHNAME: 336 l oader_set_pathname(callid, &call);408 ldr_set_pathname(callid, &call); 337 409 continue; 338 410 case LOADER_SET_ARGS: 339 loader_set_args(callid, &call); 411 ldr_set_args(callid, &call); 412 continue; 413 case LOADER_SET_FILES: 414 ldr_set_files(callid, &call); 340 415 continue; 341 416 case LOADER_LOAD: 342 l oader_load(callid, &call);417 ldr_load(callid, &call); 343 418 continue; 344 419 case LOADER_RUN: 345 l oader_run(callid, &call);420 ldr_run(callid, &call); 346 421 /* Not reached */ 347 422 default: … … 367 442 368 443 /* Set a handler of incomming connections. */ 369 async_set_client_connection(l oader_connection);444 async_set_client_connection(ldr_connection); 370 445 371 446 /* Register at naming service. */
Note:
See TracChangeset
for help on using the changeset viewer.