Changeset 4470e26 in mainline


Ignore:
Timestamp:
2008-09-24T10:57:21Z (16 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0993087
Parents:
45454e9b
Message:

Separate load and run commands for loader. Update tracer - no events get missed on startup anymore.

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/trace/trace.c

    r45454e9b r4470e26  
    4343#include <async.h>
    4444#include <task.h>
     45#include <loader/loader.h>
    4546
    4647// Temporary: service and method names
     
    7172static proto_t *proto_console;
    7273static task_id_t task_id;
     74static loader_t *task_ldr;
    7375
    7476/** Combination of events/data to print. */
    7577display_mask_t display_mask;
    7678
    77 static int task_connect(task_id_t task_id)
     79static int program_run_fibril(void *arg);
     80
     81static 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
     94static 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
     116static int connect_task(task_id_t task_id)
    78117{
    79118        int rc;
     
    149188
    150189        case V_HASH:
     190        case V_PTR:
    151191                printf("0x%08lx", val);
    152192                break;
     
    469509}
    470510
    471 static void trace_active_task(task_id_t task_id)
     511static 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 */
     546error:
     547        loader_abort(ldr);
     548        free(ldr);
     549        return NULL;
     550}
     551
     552static void trace_task(task_id_t task_id)
    472553{
    473554        int i;
    474555        int rc;
    475556        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);
    484557
    485558        ipcp_init();
     
    657730                                --argc; ++argv;
    658731                                task_id = strtol(*argv, &err_p, 10);
     732                                task_ldr = NULL;
    659733                                if (*err_p) {
    660734                                        printf("Task ID syntax error\n");
     
    687761        }
    688762
    689         /* Execute the specified command and trace the new task. */
     763        /* Preload the specified program file. */
    690764        printf("Spawning '%s' with arguments:\n", *argv);
    691765        {
     
    693767                while (*cp) printf("'%s'\n", *cp++);
    694768        }
    695         task_id = task_spawn(*argv, argv);
     769        task_ldr = preload_task(*argv, argv, &task_id);
    696770
    697771        return 0;
     
    700774int main(int argc, char *argv[])
    701775{
     776        int rc;
     777
    702778        printf("System Call / IPC Tracer\n");
    703779
     
    708784
    709785        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);
    711800
    712801        return 0;
  • uspace/lib/libc/generic/loader.c

    r45454e9b r4470e26  
    206206}
    207207
     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 */
     216int 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
    208227/** 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.
    209232 *
    210233 * After using this function, no further operations must be performed
     
    214237 * @return              Zero on success or negative error code.
    215238 */
    216 int loader_start_program(loader_t *ldr)
     239int loader_run(loader_t *ldr)
    217240{
    218241        int rc;
     
    222245                return rc;
    223246
    224         ipc_hangup(ldr->phone_id);
    225247        return EOK;
    226248}
  • uspace/lib/libc/generic/task.c

    r45454e9b r4470e26  
    6464        int rc;
    6565
    66         /* Spawn a program loader */   
     66        /* Spawn a program loader. */   
    6767        ldr = loader_spawn();
    6868        if (ldr == NULL)
     
    7474                goto error;
    7575
    76         /* Send program pathname */
     76        /* Send program pathname. */
    7777        rc = loader_set_pathname(ldr, path);
    7878        if (rc != EOK)
    7979                goto error;
    8080
    81         /* Send arguments */
     81        /* Send arguments. */
    8282        rc = loader_set_args(ldr, argv);
    8383        if (rc != EOK)
    8484                goto error;
    8585
    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);
    8894        if (rc != EOK)
    8995                goto error;
    9096
    9197        /* Success */
     98
     99        free(ldr);
    92100        return task_id;
    93101
     
    95103error:
    96104        loader_abort(ldr);
     105        free(ldr);
     106
    97107        return 0;
    98108}
  • uspace/lib/libc/include/ipc/loader.h

    r45454e9b r4470e26  
    4343        LOADER_SET_PATHNAME,
    4444        LOADER_SET_ARGS,
     45        LOADER_LOAD,
    4546        LOADER_RUN
    4647} fb_request_t;
  • uspace/lib/libc/include/loader/loader.h

    r45454e9b r4470e26  
    4747extern int loader_set_pathname(loader_t *, const char *);
    4848extern int loader_set_args(loader_t *, char *const []);
    49 extern int loader_start_program(loader_t *);
     49extern int loader_load_program(loader_t *);
     50extern int loader_run(loader_t *);
    5051extern void loader_abort(loader_t *);
    5152
  • uspace/srv/loader/main.c

    r45454e9b r4470e26  
    4747#include <stdlib.h>
    4848#include <unistd.h>
     49#include <bool.h>
    4950#include <fcntl.h>
    5051#include <sys/types.h>
     
    7879static char *arg_buf = NULL;
    7980
    80 static int loader_get_taskid(ipc_callid_t rid, ipc_call_t *request)
     81static elf_info_t prog_info;
     82static elf_info_t interp_info;
     83
     84static bool is_dyn_linked;
     85
     86
     87static void loader_get_taskid(ipc_callid_t rid, ipc_call_t *request)
    8188{
    8289        ipc_callid_t callid;
     
    213220}
    214221
    215 
    216 /** Load and run the previously selected program.
     222/** Load the previously selected program.
    217223 *
    218224 * @param rid
     
    220226 * @return 0 on success, !0 on error.
    221227 */
    222 static int loader_run(ipc_callid_t rid, ipc_call_t *request)
     228static int loader_load(ipc_callid_t rid, ipc_call_t *request)
    223229{
    224230        int rc;
    225 
    226         elf_info_t prog_info;
    227         elf_info_t interp_info;
    228231
    229232//      printf("Load program '%s'\n", pathname);
     
    246249//              printf("Run statically linked program\n");
    247250//              printf("entry point: 0x%llx\n", prog_info.entry);
     251                is_dyn_linked = false;
    248252                ipc_answer_0(rid, EOK);
    249                 close_console();
    250                 elf_run(&prog_info, &pcb);
    251253                return 0;
    252254        }
     
    266268        pcb.rtld_bias = RTLD_BIAS;
    267269
    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;
    272271        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 */
     283static 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        }
    274300
    275301        /* Not reached */
    276         return 0;
    277302}
    278303
     
    293318        while (1) {
    294319                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
    297321                switch (IPC_GET_METHOD(call)) {
    298322                case LOADER_GET_TASKID:
     
    304328                case LOADER_SET_ARGS:
    305329                        loader_set_args(callid, &call);
     330                        continue;
     331                case LOADER_LOAD:
     332                        loader_load(callid, &call);
     333                        continue;
    306334                case LOADER_RUN:
    307335                        loader_run(callid, &call);
    308                         exit(0);
    309                         continue;
     336                        /* Not reached */
    310337                default:
    311338                        retval = ENOENT;
Note: See TracChangeset for help on using the changeset viewer.