Changeset 47b7006 in mainline for uspace/lib/c/generic/libc.c


Ignore:
Timestamp:
2011-01-29T23:02:39Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
197ef43
Parents:
fd483ce
Message:

improve run-time termination

  • get rid of exit()
  • get rid of _exit(), use the common exit()
  • get rid of core(), use the common abort()
  • make main() more fail-safe (call abort() on unhealthy conditions), call async_sess_init() explicitly
  • add several libc-private headers for cleaner environment
  • use SYS_TASK_EXIT in exit() and abort()
File:
1 edited

Legend:

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

    rfd483ce r47b7006  
    4343#include <stdio.h>
    4444#include <unistd.h>
     45#include <stdlib.h>
    4546#include <malloc.h>
    4647#include <tls.h>
    47 #include <thread.h>
    4848#include <fibril.h>
    49 #include <as.h>
     49#include <task.h>
    5050#include <loader/pcb.h>
    5151#include "private/libc.h"
    5252#include "private/async.h"
     53#include "private/async_sess.h"
     54#include "private/malloc.h"
     55#include "private/io.h"
    5356
    54 void _exit(int status)
    55 {
    56         thread_exit(status);
    57 }
     57static bool env_setup = false;
    5858
    5959void __main(void *pcb_ptr)
    6060{
    6161        /* Initialize user task run-time environment */
    62         __heap_init();
     62        __malloc_init();
    6363        __async_init();
     64        __async_sess_init();
     65       
    6466        fibril_t *fibril = fibril_setup();
     67        if (fibril == NULL)
     68                abort();
     69       
    6570        __tcb_set(fibril->tcb);
    6671       
     
    6873        __pcb = (pcb_t *) pcb_ptr;
    6974       
     75        /* The basic run-time environment is setup */
     76        env_setup = true;
     77       
    7078        int argc;
    7179        char **argv;
    7280       
    73         /* Get command line arguments and initialize
    74            standard input and output */
     81        /*
     82         * Get command line arguments and initialize
     83         * standard input and output
     84         */
    7585        if (__pcb == NULL) {
    7686                argc = 0;
     
    8494        }
    8595       
    86         /* Run main() and set task return value
    87            according the result */
    88         (void) task_retval(main(argc, argv));
     96        /*
     97         * Run main() and set task return value
     98         * according the result
     99         */
     100        int retval = main(argc, argv);
     101        exit(retval);
    89102}
    90103
    91 void __exit(void)
     104void exit(int status)
    92105{
    93         __stdio_done();
    94         fibril_teardown(__tcb_get()->fibril_data);
    95         _exit(0);
     106        if (env_setup) {
     107                __stdio_done();
     108                task_retval(status);
     109                fibril_teardown(__tcb_get()->fibril_data);
     110        }
     111       
     112        __SYSCALL1(SYS_TASK_EXIT, false);
     113       
     114        /* Unreachable */
     115        while (1);
     116}
     117
     118void abort(void)
     119{
     120        __SYSCALL1(SYS_TASK_EXIT, true);
     121       
     122        /* Unreachable */
     123        while (1);
    96124}
    97125
Note: See TracChangeset for help on using the changeset viewer.