Changeset 17aca1c in mainline for uspace/lib/c/generic/libc.c


Ignore:
Timestamp:
2011-02-04T20:56:52Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0397e5a4, e29e09cf
Parents:
e778543 (diff), 0b37882 (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

File:
1 edited

Legend:

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

    re778543 r17aca1c  
    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
    55 extern int main(int argc, char *argv[]);
    56 
    57 void _exit(int status)
    58 {
    59         thread_exit(status);
    60 }
     55static bool env_setup = false;
    6156
    6257void __main(void *pcb_ptr)
    6358{
    6459        /* Initialize user task run-time environment */
    65         __heap_init();
     60        __malloc_init();
    6661        __async_init();
     62        __async_sess_init();
     63       
    6764        fibril_t *fibril = fibril_setup();
     65        if (fibril == NULL)
     66                abort();
     67       
    6868        __tcb_set(fibril->tcb);
    6969       
     
    7171        __pcb = (pcb_t *) pcb_ptr;
    7272       
     73        /* The basic run-time environment is setup */
     74        env_setup = true;
     75       
    7376        int argc;
    7477        char **argv;
    7578       
    76         /* Get command line arguments and initialize
    77            standard input and output */
     79        /*
     80         * Get command line arguments and initialize
     81         * standard input and output
     82         */
    7883        if (__pcb == NULL) {
    7984                argc = 0;
     
    8792        }
    8893       
    89         /* Run main() and set task return value
    90            according the result */
    91         (void) task_retval(main(argc, argv));
     94        /*
     95         * Run main() and set task return value
     96         * according the result
     97         */
     98        int retval = main(argc, argv);
     99        exit(retval);
    92100}
    93101
    94 void __exit(void)
     102void exit(int status)
    95103{
    96         __stdio_done();
    97         fibril_teardown(__tcb_get()->fibril_data);
    98         _exit(0);
     104        if (env_setup) {
     105                __stdio_done();
     106                task_retval(status);
     107                fibril_teardown(__tcb_get()->fibril_data);
     108        }
     109       
     110        __SYSCALL1(SYS_TASK_EXIT, false);
     111       
     112        /* Unreachable */
     113        while (1);
     114}
     115
     116void abort(void)
     117{
     118        __SYSCALL1(SYS_TASK_EXIT, true);
     119       
     120        /* Unreachable */
     121        while (1);
    99122}
    100123
Note: See TracChangeset for help on using the changeset viewer.