Changeset 4470e26 in mainline
- Timestamp:
- 2008-09-24T10:57:21Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0993087
- Parents:
- 45454e9b
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/trace/trace.c
r45454e9b r4470e26 43 43 #include <async.h> 44 44 #include <task.h> 45 #include <loader/loader.h> 45 46 46 47 // Temporary: service and method names … … 71 72 static proto_t *proto_console; 72 73 static task_id_t task_id; 74 static loader_t *task_ldr; 73 75 74 76 /** Combination of events/data to print. */ 75 77 display_mask_t display_mask; 76 78 77 static int task_connect(task_id_t task_id) 79 static int program_run_fibril(void *arg); 80 81 static void program_run(void) 82 { 83 fid_t fid; 84 85 fid = fibril_create(program_run_fibril, NULL); 86 if (fid == 0) { 87 printf("Error creating fibril\n"); 88 exit(1); 89 } 90 91 fibril_add_ready(fid); 92 } 93 94 static int program_run_fibril(void *arg) 95 { 96 int rc; 97 98 /* 99 * This must be done in background as it will block until 100 * we let the task reply to this call. 101 */ 102 rc = loader_run(task_ldr); 103 if (rc != 0) { 104 printf("Error running program\n"); 105 exit(1); 106 } 107 108 free(task_ldr); 109 task_ldr = NULL; 110 111 printf("program_run_fibril exiting\n"); 112 return 0; 113 } 114 115 116 static int connect_task(task_id_t task_id) 78 117 { 79 118 int rc; … … 149 188 150 189 case V_HASH: 190 case V_PTR: 151 191 printf("0x%08lx", val); 152 192 break; … … 469 509 } 470 510 471 static void trace_active_task(task_id_t task_id) 511 static loader_t *preload_task(const char *path, char *const argv[], 512 task_id_t *task_id) 513 { 514 loader_t *ldr; 515 int rc; 516 517 /* Spawn a program loader */ 518 ldr = loader_spawn(); 519 if (ldr == NULL) 520 return 0; 521 522 /* Get task ID. */ 523 rc = loader_get_task_id(ldr, task_id); 524 if (rc != EOK) 525 goto error; 526 527 /* Send program pathname */ 528 rc = loader_set_pathname(ldr, path); 529 if (rc != EOK) 530 goto error; 531 532 /* Send arguments */ 533 rc = loader_set_args(ldr, argv); 534 if (rc != EOK) 535 goto error; 536 537 /* Load the program. */ 538 rc = loader_load_program(ldr); 539 if (rc != EOK) 540 goto error; 541 542 /* Success */ 543 return ldr; 544 545 /* Error exit */ 546 error: 547 loader_abort(ldr); 548 free(ldr); 549 return NULL; 550 } 551 552 static void trace_task(task_id_t task_id) 472 553 { 473 554 int i; 474 555 int rc; 475 556 int c; 476 477 rc = task_connect(task_id);478 if (rc < 0) {479 printf("Failed to connect to task %lld\n", task_id);480 return;481 }482 483 printf("Connected to task %lld\n", task_id);484 557 485 558 ipcp_init(); … … 657 730 --argc; ++argv; 658 731 task_id = strtol(*argv, &err_p, 10); 732 task_ldr = NULL; 659 733 if (*err_p) { 660 734 printf("Task ID syntax error\n"); … … 687 761 } 688 762 689 /* Execute the specified command and trace the new task. */763 /* Preload the specified program file. */ 690 764 printf("Spawning '%s' with arguments:\n", *argv); 691 765 { … … 693 767 while (*cp) printf("'%s'\n", *cp++); 694 768 } 695 task_ id = task_spawn(*argv, argv);769 task_ldr = preload_task(*argv, argv, &task_id); 696 770 697 771 return 0; … … 700 774 int main(int argc, char *argv[]) 701 775 { 776 int rc; 777 702 778 printf("System Call / IPC Tracer\n"); 703 779 … … 708 784 709 785 main_init(); 710 trace_active_task(task_id); 786 787 rc = connect_task(task_id); 788 if (rc < 0) { 789 printf("Failed connecting to task %lld\n", task_id); 790 return 1; 791 } 792 793 printf("Connected to task %lld\n", task_id); 794 795 if (task_ldr != NULL) { 796 program_run(); 797 } 798 799 trace_task(task_id); 711 800 712 801 return 0; -
uspace/lib/libc/generic/loader.c
r45454e9b r4470e26 206 206 } 207 207 208 /** Instruct loader to load the program. 209 * 210 * If this function succeeds, the program has been successfully loaded 211 * and is ready to be executed. 212 * 213 * @param ldr Loader connection structure. 214 * @return Zero on success or negative error code. 215 */ 216 int loader_load_program(loader_t *ldr) 217 { 218 int rc; 219 220 rc = async_req_0_0(ldr->phone_id, LOADER_LOAD); 221 if (rc != EOK) 222 return rc; 223 224 return EOK; 225 } 226 208 227 /** Instruct loader to execute the program. 228 * 229 * Note that this function blocks until the loader actually replies 230 * so you cannot expect this function to return if you are debugging 231 * the task and its thread is stopped. 209 232 * 210 233 * After using this function, no further operations must be performed … … 214 237 * @return Zero on success or negative error code. 215 238 */ 216 int loader_ start_program(loader_t *ldr)239 int loader_run(loader_t *ldr) 217 240 { 218 241 int rc; … … 222 245 return rc; 223 246 224 ipc_hangup(ldr->phone_id);225 247 return EOK; 226 248 } -
uspace/lib/libc/generic/task.c
r45454e9b r4470e26 64 64 int rc; 65 65 66 /* Spawn a program loader */66 /* Spawn a program loader. */ 67 67 ldr = loader_spawn(); 68 68 if (ldr == NULL) … … 74 74 goto error; 75 75 76 /* Send program pathname */76 /* Send program pathname. */ 77 77 rc = loader_set_pathname(ldr, path); 78 78 if (rc != EOK) 79 79 goto error; 80 80 81 /* Send arguments */81 /* Send arguments. */ 82 82 rc = loader_set_args(ldr, argv); 83 83 if (rc != EOK) 84 84 goto error; 85 85 86 /* Request loader to start the program */ 87 rc = loader_start_program(ldr); 86 /* Load the program. */ 87 rc = loader_load_program(ldr); 88 if (rc != EOK) 89 goto error; 90 91 /* Run it. */ 92 /* Load the program. */ 93 rc = loader_run(ldr); 88 94 if (rc != EOK) 89 95 goto error; 90 96 91 97 /* Success */ 98 99 free(ldr); 92 100 return task_id; 93 101 … … 95 103 error: 96 104 loader_abort(ldr); 105 free(ldr); 106 97 107 return 0; 98 108 } -
uspace/lib/libc/include/ipc/loader.h
r45454e9b r4470e26 43 43 LOADER_SET_PATHNAME, 44 44 LOADER_SET_ARGS, 45 LOADER_LOAD, 45 46 LOADER_RUN 46 47 } fb_request_t; -
uspace/lib/libc/include/loader/loader.h
r45454e9b r4470e26 47 47 extern int loader_set_pathname(loader_t *, const char *); 48 48 extern int loader_set_args(loader_t *, char *const []); 49 extern int loader_start_program(loader_t *); 49 extern int loader_load_program(loader_t *); 50 extern int loader_run(loader_t *); 50 51 extern void loader_abort(loader_t *); 51 52 -
uspace/srv/loader/main.c
r45454e9b r4470e26 47 47 #include <stdlib.h> 48 48 #include <unistd.h> 49 #include <bool.h> 49 50 #include <fcntl.h> 50 51 #include <sys/types.h> … … 78 79 static char *arg_buf = NULL; 79 80 80 static int loader_get_taskid(ipc_callid_t rid, ipc_call_t *request) 81 static elf_info_t prog_info; 82 static elf_info_t interp_info; 83 84 static bool is_dyn_linked; 85 86 87 static void loader_get_taskid(ipc_callid_t rid, ipc_call_t *request) 81 88 { 82 89 ipc_callid_t callid; … … 213 220 } 214 221 215 216 /** Load and run the previously selected program. 222 /** Load the previously selected program. 217 223 * 218 224 * @param rid … … 220 226 * @return 0 on success, !0 on error. 221 227 */ 222 static int loader_ run(ipc_callid_t rid, ipc_call_t *request)228 static int loader_load(ipc_callid_t rid, ipc_call_t *request) 223 229 { 224 230 int rc; 225 226 elf_info_t prog_info;227 elf_info_t interp_info;228 231 229 232 // printf("Load program '%s'\n", pathname); … … 246 249 // printf("Run statically linked program\n"); 247 250 // printf("entry point: 0x%llx\n", prog_info.entry); 251 is_dyn_linked = false; 248 252 ipc_answer_0(rid, EOK); 249 close_console();250 elf_run(&prog_info, &pcb);251 253 return 0; 252 254 } … … 266 268 pcb.rtld_bias = RTLD_BIAS; 267 269 268 printf("run dynamic linker\n"); 269 printf("entry point: 0x%llx\n", interp_info.entry); 270 close_console(); 271 270 is_dyn_linked = true; 272 271 ipc_answer_0(rid, EOK); 273 elf_run(&interp_info, &pcb); 272 273 return 0; 274 } 275 276 277 /** Run the previously loaded program. 278 * 279 * @param rid 280 * @param request 281 * @return 0 on success, !0 on error. 282 */ 283 static void loader_run(ipc_callid_t rid, ipc_call_t *request) 284 { 285 if (is_dyn_linked == true) { 286 /* Dynamically linked program */ 287 printf("run dynamic linker\n"); 288 printf("entry point: 0x%llx\n", interp_info.entry); 289 close_console(); 290 291 ipc_answer_0(rid, EOK); 292 elf_run(&interp_info, &pcb); 293 294 } else { 295 /* Statically linked program */ 296 close_console(); 297 ipc_answer_0(rid, EOK); 298 elf_run(&prog_info, &pcb); 299 } 274 300 275 301 /* Not reached */ 276 return 0;277 302 } 278 303 … … 293 318 while (1) { 294 319 callid = async_get_call(&call); 295 // printf("received call from phone %d, method=%d\n", 296 // call.in_phone_hash, IPC_GET_METHOD(call)); 320 297 321 switch (IPC_GET_METHOD(call)) { 298 322 case LOADER_GET_TASKID: … … 304 328 case LOADER_SET_ARGS: 305 329 loader_set_args(callid, &call); 330 continue; 331 case LOADER_LOAD: 332 loader_load(callid, &call); 333 continue; 306 334 case LOADER_RUN: 307 335 loader_run(callid, &call); 308 exit(0); 309 continue; 336 /* Not reached */ 310 337 default: 311 338 retval = ENOENT;
Note:
See TracChangeset
for help on using the changeset viewer.