Changeset 197ef43 in mainline for uspace/lib/c/generic/libc.c


Ignore:
Timestamp:
2011-01-29T23:52:07Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
12573db, 40fb017
Parents:
6aef742 (diff), 47b7006 (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 various cosmetic run-time support improvements

  • coding style cleanups, comments cleanups, unsigned types for bit flags, indentation, etc.
  • SYS_TASK_EXIT for proper termination of a task (optionally with udebug notification)
    • get rid of exit(), _exit(), core()
    • reimplement robust main(), exit() and abort()
    • call abort() if some part of libc initialization fails
  • add more private libc headers to reduce the namespace pollution
File:
1 edited

Legend:

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

    r6aef742 r197ef43  
    4141 */
    4242
    43 #include <stdio.h>
    44 #include <unistd.h>
    45 #include <malloc.h>
     43#include <libc.h>
     44#include <stdlib.h>
    4645#include <tls.h>
    47 #include <thread.h>
    4846#include <fibril.h>
    49 #include <async.h>
    50 #include <as.h>
     47#include <task.h>
    5148#include <loader/pcb.h>
    5249#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"
    5354
    54 void _exit(int status)
    55 {
    56         thread_exit(status);
    57 }
     55static bool env_setup = false;
    5856
    5957void __main(void *pcb_ptr)
    6058{
    6159        /* Initialize user task run-time environment */
    62         __heap_init();
     60        __malloc_init();
    6361        __async_init();
     62        __async_sess_init();
     63       
    6464        fibril_t *fibril = fibril_setup();
     65        if (fibril == NULL)
     66                abort();
     67       
    6568        __tcb_set(fibril->tcb);
    6669       
     
    6871        __pcb = (pcb_t *) pcb_ptr;
    6972       
     73        /* The basic run-time environment is setup */
     74        env_setup = true;
     75       
    7076        int argc;
    7177        char **argv;
    7278       
    73         /* Get command line arguments and initialize
    74            standard input and output */
     79        /*
     80         * Get command line arguments and initialize
     81         * standard input and output
     82         */
    7583        if (__pcb == NULL) {
    7684                argc = 0;
     
    8492        }
    8593       
    86         /* Run main() and set task return value
    87            according the result */
    88         (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);
    89100}
    90101
    91 void __exit(void)
     102void exit(int status)
    92103{
    93         __stdio_done();
    94         fibril_teardown(__tcb_get()->fibril_data);
    95         _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);
    96122}
    97123
Note: See TracChangeset for help on using the changeset viewer.