Changeset 04803bf in mainline for uspace/lib/c/generic/libc.c


Ignore:
Timestamp:
2011-03-21T22:00:17Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
143932e
Parents:
b50b5af2 (diff), 7308e84 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes (needs fixes).

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/libc.c

    rb50b5af2 r04803bf  
    4242
    4343#include <libc.h>
    44 #include <stdio.h>
    45 #include <unistd.h>
    46 #include <malloc.h>
     44#include <stdlib.h>
    4745#include <tls.h>
    48 #include <thread.h>
    4946#include <fibril.h>
    50 #include <ipc/ipc.h>
    51 #include <async.h>
    52 #include <as.h>
     47#include <task.h>
    5348#include <loader/pcb.h>
     49#include "private/libc.h"
     50#include "private/async.h"
     51#include "private/async_sess.h"
     52#include "private/malloc.h"
     53#include "private/io.h"
    5454
    5555/* From librtld. */
    5656#include <rtld.h>
    57 #include <string.h>
     57//#include <string.h>
    5858
    59 extern int main(int argc, char *argv[]);
    60 
    61 void _exit(int status)
    62 {
    63         thread_exit(status);
    64 }
     59static bool env_setup = false;
    6560
    6661void __main(void *pcb_ptr)
    6762{
    68         int retval;
    69 
    70         __heap_init();
     63        /* Initialize user task run-time environment */
     64        __malloc_init();
    7165        __async_init();
     66        __async_sess_init();
     67       
    7268        fibril_t *fibril = fibril_setup();
     69        if (fibril == NULL)
     70                abort();
     71       
    7372        __tcb_set(fibril->tcb);
    7473       
    7574        /* Save the PCB pointer */
    7675        __pcb = (pcb_t *) pcb_ptr;
     76       
     77        /* The basic run-time environment is setup */
     78        env_setup = true;
    7779       
    7880        int argc;
     
    8486        }
    8587#endif
    86 
     88        /*
     89         * Get command line arguments and initialize
     90         * standard input and output
     91         */
    8792        if (__pcb == NULL) {
    8893                argc = 0;
     
    9398                argv = __pcb->argv;
    9499                __stdio_init(__pcb->filc, __pcb->filv);
     100                (void) chdir(__pcb->cwd);
    95101        }
    96102       
    97         retval = main(argc, argv);
    98 
    99         __stdio_done();
    100         (void) task_retval(retval);
     103        /*
     104         * Run main() and set task return value
     105         * according the result
     106         */
     107        int retval = main(argc, argv);
     108        exit(retval);
    101109}
    102110
    103 void __exit(void)
     111void exit(int status)
    104112{
    105         fibril_teardown(__tcb_get()->fibril_data);
    106         _exit(0);
     113        if (env_setup) {
     114                __stdio_done();
     115                task_retval(status);
     116                fibril_teardown(__tcb_get()->fibril_data);
     117        }
     118       
     119        __SYSCALL1(SYS_TASK_EXIT, false);
     120       
     121        /* Unreachable */
     122        while (1);
     123}
     124
     125void abort(void)
     126{
     127        __SYSCALL1(SYS_TASK_EXIT, true);
     128       
     129        /* Unreachable */
     130        while (1);
    107131}
    108132
Note: See TracChangeset for help on using the changeset viewer.