Changeset 47b7006 in mainline


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()
Location:
uspace
Files:
4 added
38 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/arch/abs32le/src/entry.c

    rfd483ce r47b7006  
    3737{
    3838        __main(NULL);
    39         __exit();
    4039}
    4140
  • uspace/lib/c/arch/abs32le/src/thread_entry.c

    rfd483ce r47b7006  
    3030 */
    3131
    32 #include <unistd.h>
    33 #include <thread.h>
    34 
    3532void __thread_entry(void)
    3633{
  • uspace/lib/c/arch/amd64/src/entry.s

    rfd483ce r47b7006  
    4747        # Pass PCB pointer to __main (no operation)
    4848        call __main
    49 
    50         call __exit
  • uspace/lib/c/arch/arm32/src/entry.s

    rfd483ce r47b7006  
    4242        ldr r0, =ras_page
    4343        str r2, [r0]
    44 
     44       
    4545        #
    4646        # Create the first stack frame.
     
    5050        push {fp, ip, lr, pc}
    5151        sub fp, ip, #4
    52 
     52       
    5353        # Pass pcb_ptr to __main as the first argument (in r0)
    5454        mov r0, r1
    5555        bl __main
    56 
    57         bl __exit
    5856
    5957.data
     
    6260ras_page:
    6361        .long 0
    64 
  • uspace/lib/c/arch/ia32/src/entry.s

    rfd483ce r47b7006  
    4646        mov %ax, %fs
    4747        # Do not set %gs, it contains descriptor that can see TLS
    48 
     48       
    4949        # Detect the mechanism used for making syscalls
    5050        movl $(INTEL_CPUID_STANDARD), %eax
     
    5858        # Create the first stack frame.
    5959        #
    60         pushl $0 
     60        pushl $0
    6161        movl %esp, %ebp
    62 
     62       
    6363        # Pass the PCB pointer to __main as the first argument
    6464        pushl %edi
    6565        call __main
    66 
    67         call __exit
  • uspace/lib/c/arch/ia64/src/entry.s

    rfd483ce r47b7006  
    4040        alloc loc0 = ar.pfs, 0, 1, 2, 0
    4141        movl gp = _gp
    42 
     42       
    4343        # Pass PCB pointer as the first argument to __main
    4444        mov out0 = r2
    4545        br.call.sptk.many b0 = __main
    46 0:
    47         br.call.sptk.many b0 = __exit
  • uspace/lib/c/arch/mips32/src/entry.s

    rfd483ce r47b7006  
    5656        jal __main
    5757        nop
    58        
    59         jal __exit
    60         nop
    6158.end
    6259
  • uspace/lib/c/arch/ppc32/src/entry.s

    rfd483ce r47b7006  
    4444        stw %r3, 0(%r1)
    4545        stwu %r1, -16(%r1)
    46 
     46       
    4747        # Pass the PCB pointer to __main() as the first argument.
    4848        # The first argument is passed in r3.
    4949        mr %r3, %r6
    5050        bl __main
    51 
    52         bl __exit
  • uspace/lib/c/arch/sparc64/src/entry.s

    rfd483ce r47b7006  
    4545        flushw
    4646        add %g0, -0x7ff, %fp
    47 
     47       
    4848        # Pass pcb_ptr as the first argument to __main()
    4949        mov %i1, %o0
     
    5151        call __main
    5252        or %l7, %lo(_gp), %l7
    53 
    54         call __exit
    55         nop
  • uspace/lib/c/generic/async.c

    rfd483ce r47b7006  
    4242 * You should be able to write very simple multithreaded programs, the async
    4343 * framework will automatically take care of most synchronization problems.
    44  *
    45  * Default semantics:
    46  * - async_send_*(): Send asynchronously. If the kernel refuses to send
    47  *                   more messages, [ try to get responses from kernel, if
    48  *                   nothing found, might try synchronous ]
    4944 *
    5045 * Example of use (pseudo C):
     
    127122
    128123/**
    129  * Structures of this type are used to group information about a call and a
    130  * message queue link.
     124 * Structures of this type are used to group information about
     125 * a call and about a message queue link.
    131126 */
    132127typedef struct {
     
    156151        /** Link to the client tracking structure. */
    157152        client_t *client;
    158 
     153       
    159154        /** Messages that should be delivered to this fibril. */
    160155        link_t msg_queue;
     
    173168
    174169/** Identifier of the incoming connection handled by the current fibril. */
    175 fibril_local connection_t *FIBRIL_connection;
     170static fibril_local connection_t *FIBRIL_connection;
    176171
    177172static void *default_client_data_constructor(void)
     
    202197{
    203198        assert(FIBRIL_connection);
    204 
    205199        return FIBRIL_connection->client->data;
    206200}
    207201
    208 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
    209 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call);
     202/** Default fibril function that gets called to handle new connection.
     203 *
     204 * This function is defined as a weak symbol - to be redefined in user code.
     205 *
     206 * @param callid Hash of the incoming call.
     207 * @param call   Data of the incoming call.
     208 *
     209 */
     210static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
     211{
     212        ipc_answer_0(callid, ENOENT);
     213}
    210214
    211215/**
     
    213217 */
    214218static async_client_conn_t client_connection = default_client_connection;
     219
     220/** Default fibril function that gets called to handle interrupt notifications.
     221 *
     222 * This function is defined as a weak symbol - to be redefined in user code.
     223 *
     224 * @param callid Hash of the incoming call.
     225 * @param call   Data of the incoming call.
     226 *
     227 */
     228static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
     229{
     230}
    215231
    216232/**
     
    224240static LIST_INITIALIZE(timeout_list);
    225241
    226 #define CLIENT_HASH_TABLE_BUCKETS       32
    227 #define CONN_HASH_TABLE_BUCKETS         32
    228 
    229 static hash_index_t client_hash(unsigned long *key)
     242#define CLIENT_HASH_TABLE_BUCKETS  32
     243#define CONN_HASH_TABLE_BUCKETS    32
     244
     245static hash_index_t client_hash(unsigned long key[])
    230246{
    231247        assert(key);
    232         return (((*key) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
     248        return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
    233249}
    234250
    235251static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
    236252{
    237         client_t *cl = hash_table_get_instance(item, client_t, link);
    238         return (key[0] == cl->in_task_hash);
     253        client_t *client = hash_table_get_instance(item, client_t, link);
     254        return (key[0] == client->in_task_hash);
    239255}
    240256
     
    257273 *
    258274 */
    259 static hash_index_t conn_hash(unsigned long *key)
     275static hash_index_t conn_hash(unsigned long key[])
    260276{
    261277        assert(key);
    262         return (((*key) >> 4) % CONN_HASH_TABLE_BUCKETS);
     278        return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
    263279}
    264280
     
    274290static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
    275291{
    276         connection_t *hs = hash_table_get_instance(item, connection_t, link);
    277         return (key[0] == hs->in_phone_hash);
     292        connection_t *conn = hash_table_get_instance(item, connection_t, link);
     293        return (key[0] == conn->in_phone_hash);
    278294}
    279295
     
    290306        free(hash_table_get_instance(item, connection_t, link));
    291307}
    292 
    293308
    294309/** Operations for the connection hash table. */
     
    311326        link_t *tmp = timeout_list.next;
    312327        while (tmp != &timeout_list) {
    313                 awaiter_t *cur;
    314                
    315                 cur = list_get_instance(tmp, awaiter_t, to_event.link);
     328                awaiter_t *cur
     329                    = list_get_instance(tmp, awaiter_t, to_event.link);
     330               
    316331                if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires))
    317332                        break;
     333               
    318334                tmp = tmp->next;
    319335        }
     
    332348 *
    333349 * @return False if the call doesn't match any connection.
    334  *         True if the call was passed to the respective connection fibril.
     350 * @return True if the call was passed to the respective connection fibril.
    335351 *
    336352 */
     
    469485                         * the first IPC_M_PHONE_HUNGUP call and continues to
    470486                         * call async_get_call_timeout(). Repeat
    471                          * IPC_M_PHONE_HUNGUP until the caller notices. 
     487                         * IPC_M_PHONE_HUNGUP until the caller notices.
    472488                         */
    473489                        memset(call, 0, sizeof(ipc_call_t));
     
    476492                        return conn->close_callid;
    477493                }
    478 
     494               
    479495                if (usecs)
    480496                        async_insert_timeout(&conn->wdata);
     
    514530}
    515531
    516 /** Default fibril function that gets called to handle new connection.
    517  *
    518  * This function is defined as a weak symbol - to be redefined in user code.
    519  *
    520  * @param callid Hash of the incoming call.
    521  * @param call   Data of the incoming call.
    522  *
    523  */
    524 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
    525 {
    526         ipc_answer_0(callid, ENOENT);
    527 }
    528 
    529 /** Default fibril function that gets called to handle interrupt notifications.
    530  *
    531  * This function is defined as a weak symbol - to be redefined in user code.
    532  *
    533  * @param callid Hash of the incoming call.
    534  * @param call   Data of the incoming call.
    535  *
    536  */
    537 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
    538 {
    539 }
    540 
    541532/** Wrapper for client connection fibril.
    542533 *
     
    551542static int connection_fibril(void *arg)
    552543{
    553         unsigned long key;
    554         client_t *cl;
    555         link_t *lnk;
    556         bool destroy = false;
    557 
    558544        /*
    559545         * Setup fibril-local connection pointer.
    560546         */
    561547        FIBRIL_connection = (connection_t *) arg;
    562 
     548       
     549        futex_down(&async_futex);
     550       
    563551        /*
    564552         * Add our reference for the current connection in the client task
     
    566554         * hash in a new tracking structure.
    567555         */
    568         futex_down(&async_futex);
    569         key = FIBRIL_connection->in_task_hash;
    570         lnk = hash_table_find(&client_hash_table, &key);
     556       
     557        unsigned long key = FIBRIL_connection->in_task_hash;
     558        link_t *lnk = hash_table_find(&client_hash_table, &key);
     559       
     560        client_t *client;
     561       
    571562        if (lnk) {
    572                 cl = hash_table_get_instance(lnk, client_t, link);
    573                 cl->refcnt++;
     563                client = hash_table_get_instance(lnk, client_t, link);
     564                client->refcnt++;
    574565        } else {
    575                 cl = malloc(sizeof(client_t));
    576                 if (!cl) {
     566                client = malloc(sizeof(client_t));
     567                if (!client) {
    577568                        ipc_answer_0(FIBRIL_connection->callid, ENOMEM);
    578569                        futex_up(&async_futex);
    579570                        return 0;
    580571                }
    581                 cl->in_task_hash = FIBRIL_connection->in_task_hash;
     572               
     573                client->in_task_hash = FIBRIL_connection->in_task_hash;
     574               
    582575                async_serialize_start();
    583                 cl->data = async_client_data_create();
     576                client->data = async_client_data_create();
    584577                async_serialize_end();
    585                 cl->refcnt = 1;
    586                 hash_table_insert(&client_hash_table, &key, &cl->link);
    587         }
     578               
     579                client->refcnt = 1;
     580                hash_table_insert(&client_hash_table, &key, &client->link);
     581        }
     582       
    588583        futex_up(&async_futex);
    589 
    590         FIBRIL_connection->client = cl;
    591 
     584       
     585        FIBRIL_connection->client = client;
     586       
    592587        /*
    593588         * Call the connection handler function.
     
    599594         * Remove the reference for this client task connection.
    600595         */
     596        bool destroy;
     597       
    601598        futex_down(&async_futex);
    602         if (--cl->refcnt == 0) {
     599       
     600        if (--client->refcnt == 0) {
    603601                hash_table_remove(&client_hash_table, &key, 1);
    604602                destroy = true;
    605         }
     603        } else
     604                destroy = false;
     605       
    606606        futex_up(&async_futex);
    607 
     607       
    608608        if (destroy) {
    609                 if (cl->data)
    610                         async_client_data_destroy(cl->data);
    611                 free(cl);
    612         }
    613 
     609                if (client->data)
     610                        async_client_data_destroy(client->data);
     611               
     612                free(client);
     613        }
     614       
    614615        /*
    615616         * Remove myself from the connection hash table.
     
    624625         */
    625626        while (!list_empty(&FIBRIL_connection->msg_queue)) {
    626                 msg_t *msg;
    627                
    628                 msg = list_get_instance(FIBRIL_connection->msg_queue.next,
    629                     msg_t, link);
     627                msg_t *msg =
     628                    list_get_instance(FIBRIL_connection->msg_queue.next, msg_t,
     629                    link);
     630               
    630631                list_remove(&msg->link);
    631632                ipc_answer_0(msg->callid, EHANGUP);
     
    670671                if (callid)
    671672                        ipc_answer_0(callid, ENOMEM);
     673               
    672674                return (uintptr_t) NULL;
    673675        }
     
    717719static void handle_call(ipc_callid_t callid, ipc_call_t *call)
    718720{
    719         /* Unrouted call - do some default behaviour */
     721        /* Unrouted call - take some default action */
    720722        if ((callid & IPC_CALLID_NOTIFICATION)) {
    721723                process_notification(callid, call);
    722                 goto out;
     724                return;
    723725        }
    724726       
     
    726728        case IPC_M_CONNECT_ME:
    727729        case IPC_M_CONNECT_ME_TO:
    728                 /* Open new connection with fibril etc. */
     730                /* Open new connection with fibril, etc. */
    729731                async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
    730732                    callid, call, client_connection);
    731                 goto out;
     733                return;
    732734        }
    733735       
    734736        /* Try to route the call through the connection hash table */
    735737        if (route_call(callid, call))
    736                 goto out;
     738                return;
    737739       
    738740        /* Unknown call from unknown phone - hang it up */
    739741        ipc_answer_0(callid, EHANGUP);
    740         return;
    741        
    742 out:
    743         ;
    744742}
    745743
     
    754752        link_t *cur = timeout_list.next;
    755753        while (cur != &timeout_list) {
    756                 awaiter_t *waiter;
    757                
    758                 waiter = list_get_instance(cur, awaiter_t, to_event.link);
     754                awaiter_t *waiter =
     755                    list_get_instance(cur, awaiter_t, to_event.link);
     756               
    759757                if (tv_gt(&waiter->to_event.expires, &tv))
    760758                        break;
    761 
     759               
    762760                cur = cur->next;
    763 
     761               
    764762                list_remove(&waiter->to_event.link);
    765763                waiter->to_event.inlist = false;
     
    788786        while (true) {
    789787                if (fibril_switch(FIBRIL_FROM_MANAGER)) {
    790                         futex_up(&async_futex); 
     788                        futex_up(&async_futex);
    791789                        /*
    792790                         * async_futex is always held when entering a manager
     
    811809                                continue;
    812810                        } else
    813                                 timeout = tv_sub(&waiter->to_event.expires,
    814                                     &tv);
     811                                timeout = tv_sub(&waiter->to_event.expires, &tv);
    815812                } else
    816813                        timeout = SYNCH_NO_TIMEOUT;
    817814               
    818815                futex_up(&async_futex);
    819 
     816               
    820817                atomic_inc(&threads_in_ipc_wait);
    821818               
     
    825822               
    826823                atomic_dec(&threads_in_ipc_wait);
    827 
     824               
    828825                if (!callid) {
    829826                        handle_expired_timeouts();
     
    875872/** Initialize the async framework.
    876873 *
    877  * @return Zero on success or an error code.
    878  */
    879 int __async_init(void)
     874 */
     875void __async_init(void)
    880876{
    881877        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1,
    882             &client_hash_table_ops) || !hash_table_create(&conn_hash_table,
    883             CONN_HASH_TABLE_BUCKETS, 1, &conn_hash_table_ops)) {
    884                 return ENOMEM;
    885         }
    886 
    887         _async_sess_init();
    888        
    889         return 0;
     878            &client_hash_table_ops))
     879                abort();
     880       
     881        if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS, 1,
     882            &conn_hash_table_ops))
     883                abort();
    890884}
    891885
     
    900894 * @param retval Value returned in the answer.
    901895 * @param data   Call data of the answer.
     896 *
    902897 */
    903898static void reply_received(void *arg, int retval, ipc_call_t *data)
     
    947942    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
    948943{
    949         amsg_t *msg = malloc(sizeof(*msg));
     944        amsg_t *msg = malloc(sizeof(amsg_t));
    950945       
    951946        if (!msg)
     
    956951       
    957952        msg->wdata.to_event.inlist = false;
    958         /* We may sleep in the next method, but it will use its own mechanism */
     953       
     954        /*
     955         * We may sleep in the next method,
     956         * but it will use its own means
     957         */
    959958        msg->wdata.active = true;
    960959       
     
    987986    ipc_call_t *dataptr)
    988987{
    989         amsg_t *msg = malloc(sizeof(*msg));
     988        amsg_t *msg = malloc(sizeof(amsg_t));
    990989       
    991990        if (!msg)
     
    996995       
    997996        msg->wdata.to_event.inlist = false;
    998         /* We may sleep in next method, but it will use its own mechanism */
     997       
     998        /*
     999         * We may sleep in the next method,
     1000         * but it will use its own means
     1001         */
    9991002        msg->wdata.active = true;
    10001003       
     
    10951098void async_usleep(suseconds_t timeout)
    10961099{
    1097         amsg_t *msg = malloc(sizeof(*msg));
     1100        amsg_t *msg = malloc(sizeof(amsg_t));
    10981101       
    10991102        if (!msg)
     
    13071310}
    13081311
    1309 int async_forward_fast(ipc_callid_t callid, int phoneid, int imethod,
    1310     sysarg_t arg1, sysarg_t arg2, int mode)
     1312int async_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
     1313    sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    13111314{
    13121315        return ipc_forward_fast(callid, phoneid, imethod, arg1, arg2, mode);
    13131316}
    13141317
    1315 int async_forward_slow(ipc_callid_t callid, int phoneid, int imethod,
     1318int async_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
    13161319    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
    1317     int mode)
     1320    unsigned int mode)
    13181321{
    13191322        return ipc_forward_slow(callid, phoneid, imethod, arg1, arg2, arg3, arg4,
     
    14281431}
    14291432
    1430 /** Wrapper for making IPC_M_SHARE_IN calls using the async framework.
    1431  *
    1432  * @param phoneid       Phone that will be used to contact the receiving side.
    1433  * @param dst           Destination address space area base.
    1434  * @param size          Size of the destination address space area.
    1435  * @param arg           User defined argument.
    1436  * @param flags         Storage where the received flags will be stored. Can be
    1437  *                      NULL.
    1438  *
    1439  * @return              Zero on success or a negative error code from errno.h.
     1433/** Wrapper for IPC_M_SHARE_IN calls using the async framework.
     1434 *
     1435 * @param phoneid Phone that will be used to contact the receiving side.
     1436 * @param dst     Destination address space area base.
     1437 * @param size    Size of the destination address space area.
     1438 * @param arg     User defined argument.
     1439 * @param flags   Storage for the received flags. Can be NULL.
     1440 *
     1441 * @return Zero on success or a negative error code from errno.h.
     1442 *
    14401443 */
    14411444int async_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
    1442     int *flags)
    1443 {
    1444         int res;
     1445    unsigned int *flags)
     1446{
    14451447        sysarg_t tmp_flags;
    1446         res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
     1448        int res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
    14471449            (sysarg_t) size, arg, NULL, &tmp_flags);
     1450       
    14481451        if (flags)
    1449                 *flags = tmp_flags;
     1452                *flags = (unsigned int) tmp_flags;
     1453       
    14501454        return res;
    14511455}
     
    14531457/** Wrapper for receiving the IPC_M_SHARE_IN calls using the async framework.
    14541458 *
    1455  * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN calls
    1456  * so that the user doesn't have to remember the meaning of each IPC argument.
     1459 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN
     1460 * calls so that the user doesn't have to remember the meaning of each IPC
     1461 * argument.
    14571462 *
    14581463 * So far, this wrapper is to be used from within a connection fibril.
    14591464 *
    1460  * @param callid        Storage where the hash of the IPC_M_SHARE_IN call will
    1461  *                      be stored.
    1462  * @param size          Destination address space area size.   
    1463  *
    1464  * @return              Non-zero on success, zero on failure.
    1465  */
    1466 int async_share_in_receive(ipc_callid_t *callid, size_t *size)
    1467 {
    1468         ipc_call_t data;
    1469        
     1465 * @param callid Storage for the hash of the IPC_M_SHARE_IN call.
     1466 * @param size   Destination address space area size.
     1467 *
     1468 * @return True on success, false on failure.
     1469 *
     1470 */
     1471bool async_share_in_receive(ipc_callid_t *callid, size_t *size)
     1472{
    14701473        assert(callid);
    14711474        assert(size);
    1472 
     1475       
     1476        ipc_call_t data;
    14731477        *callid = async_get_call(&data);
     1478       
    14741479        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
    1475                 return 0;
     1480                return false;
     1481       
    14761482        *size = (size_t) IPC_GET_ARG2(data);
    1477         return 1;
     1483        return true;
    14781484}
    14791485
    14801486/** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework.
    14811487 *
    1482  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
    1483  * so that the user doesn't have to remember the meaning of each IPC argument.
    1484  *
    1485  * @param callid        Hash of the IPC_M_DATA_READ call to answer.
    1486  * @param src           Source address space base.
    1487  * @param flags         Flags to be used for sharing. Bits can be only cleared.
    1488  *
    1489  * @return              Zero on success or a value from @ref errno.h on failure.
    1490  */
    1491 int async_share_in_finalize(ipc_callid_t callid, void *src, int flags)
     1488 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     1489 * calls so that the user doesn't have to remember the meaning of each IPC
     1490 * argument.
     1491 *
     1492 * @param callid Hash of the IPC_M_DATA_READ call to answer.
     1493 * @param src    Source address space base.
     1494 * @param flags  Flags to be used for sharing. Bits can be only cleared.
     1495 *
     1496 * @return Zero on success or a value from @ref errno.h on failure.
     1497 *
     1498 */
     1499int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    14921500{
    14931501        return ipc_share_in_finalize(callid, src, flags);
    14941502}
    14951503
    1496 /** Wrapper for making IPC_M_SHARE_OUT calls using the async framework.
    1497  *
    1498  * @param phoneid       Phone that will be used to contact the receiving side.
    1499  * @param src           Source address space area base address.
    1500  * @param flags         Flags to be used for sharing. Bits can be only cleared.
    1501  *
    1502  * @return              Zero on success or a negative error code from errno.h.
    1503  */
    1504 int async_share_out_start(int phoneid, void *src, int flags)
     1504/** Wrapper for IPC_M_SHARE_OUT calls using the async framework.
     1505 *
     1506 * @param phoneid Phone that will be used to contact the receiving side.
     1507 * @param src     Source address space area base address.
     1508 * @param flags   Flags to be used for sharing. Bits can be only cleared.
     1509 *
     1510 * @return Zero on success or a negative error code from errno.h.
     1511 *
     1512 */
     1513int async_share_out_start(int phoneid, void *src, unsigned int flags)
    15051514{
    15061515        return async_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
     
    15101519/** Wrapper for receiving the IPC_M_SHARE_OUT calls using the async framework.
    15111520 *
    1512  * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT calls
    1513  * so that the user doesn't have to remember the meaning of each IPC argument.
     1521 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT
     1522 * calls so that the user doesn't have to remember the meaning of each IPC
     1523 * argument.
    15141524 *
    15151525 * So far, this wrapper is to be used from within a connection fibril.
    15161526 *
    1517  * @param callid        Storage where the hash of the IPC_M_SHARE_OUT call will
    1518  *                      be stored.
    1519  * @param size          Storage where the source address space area size will be
    1520  *                      stored.
    1521  * @param flags         Storage where the sharing flags will be stored.
    1522  *
    1523  * @return              Non-zero on success, zero on failure.
    1524  */
    1525 int async_share_out_receive(ipc_callid_t *callid, size_t *size, int *flags)
    1526 {
    1527         ipc_call_t data;
    1528        
     1527 * @param callid Storage for the hash of the IPC_M_SHARE_OUT call.
     1528 * @param size   Storage for the source address space area size.
     1529 * @param flags  Storage for the sharing flags.
     1530 *
     1531 * @return True on success, false on failure.
     1532 *
     1533 */
     1534bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags)
     1535{
    15291536        assert(callid);
    15301537        assert(size);
    15311538        assert(flags);
    1532 
     1539       
     1540        ipc_call_t data;
    15331541        *callid = async_get_call(&data);
     1542       
    15341543        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
    1535                 return 0;
     1544                return false;
     1545       
    15361546        *size = (size_t) IPC_GET_ARG2(data);
    1537         *flags = (int) IPC_GET_ARG3(data);
    1538         return 1;
     1547        *flags = (unsigned int) IPC_GET_ARG3(data);
     1548        return true;
    15391549}
    15401550
    15411551/** Wrapper for answering the IPC_M_SHARE_OUT calls using the async framework.
    15421552 *
    1543  * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls
    1544  * so that the user doesn't have to remember the meaning of each IPC argument.
    1545  *
    1546  * @param callid        Hash of the IPC_M_DATA_WRITE call to answer.
    1547  * @param dst           Destination address space area base address.   
    1548  *
    1549  * @return              Zero on success or a value from @ref errno.h on failure.
     1553 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT
     1554 * calls so that the user doesn't have to remember the meaning of each IPC
     1555 * argument.
     1556 *
     1557 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     1558 * @param dst    Destination address space area base address.
     1559 *
     1560 * @return Zero on success or a value from @ref errno.h on failure.
     1561 *
    15501562 */
    15511563int async_share_out_finalize(ipc_callid_t callid, void *dst)
     
    15541566}
    15551567
    1556 
    1557 /** Wrapper for making IPC_M_DATA_READ calls using the async framework.
    1558  *
    1559  * @param phoneid       Phone that will be used to contact the receiving side.
    1560  * @param dst           Address of the beginning of the destination buffer.
    1561  * @param size          Size of the destination buffer.
    1562  *
    1563  * @return              Zero on success or a negative error code from errno.h.
     1568/** Wrapper for IPC_M_DATA_READ calls using the async framework.
     1569 *
     1570 * @param phoneid Phone that will be used to contact the receiving side.
     1571 * @param dst     Address of the beginning of the destination buffer.
     1572 * @param size    Size of the destination buffer.
     1573 *
     1574 * @return Zero on success or a negative error code from errno.h.
     1575 *
    15641576 */
    15651577int async_data_read_start(int phoneid, void *dst, size_t size)
     
    15711583/** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework.
    15721584 *
    1573  * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ calls
    1574  * so that the user doesn't have to remember the meaning of each IPC argument.
     1585 * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ
     1586 * calls so that the user doesn't have to remember the meaning of each IPC
     1587 * argument.
    15751588 *
    15761589 * So far, this wrapper is to be used from within a connection fibril.
    15771590 *
    1578  * @param callid        Storage where the hash of the IPC_M_DATA_READ call will
    1579  *                      be stored.
    1580  * @param size          Storage where the maximum size will be stored. Can be
    1581  *                      NULL.
    1582  *
    1583  * @return              Non-zero on success, zero on failure.
    1584  */
    1585 int async_data_read_receive(ipc_callid_t *callid, size_t *size)
    1586 {
     1591 * @param callid Storage for the hash of the IPC_M_DATA_READ.
     1592 * @param size   Storage for the maximum size. Can be NULL.
     1593 *
     1594 * @return True on success, false on failure.
     1595 *
     1596 */
     1597bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
     1598{
     1599        assert(callid);
     1600       
    15871601        ipc_call_t data;
    1588        
    1589         assert(callid);
    1590 
    15911602        *callid = async_get_call(&data);
     1603       
    15921604        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ)
    1593                 return 0;
     1605                return false;
     1606       
    15941607        if (size)
    15951608                *size = (size_t) IPC_GET_ARG2(data);
    1596         return 1;
     1609       
     1610        return true;
    15971611}
    15981612
    15991613/** Wrapper for answering the IPC_M_DATA_READ calls using the async framework.
    16001614 *
    1601  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
    1602  * so that the user doesn't have to remember the meaning of each IPC argument.
    1603  *
    1604  * @param callid        Hash of the IPC_M_DATA_READ call to answer.
    1605  * @param src           Source address for the IPC_M_DATA_READ call.
    1606  * @param size          Size for the IPC_M_DATA_READ call. Can be smaller than
    1607  *                      the maximum size announced by the sender.
    1608  *
    1609  * @return              Zero on success or a value from @ref errno.h on failure.
     1615 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     1616 * calls so that the user doesn't have to remember the meaning of each IPC
     1617 * argument.
     1618 *
     1619 * @param callid Hash of the IPC_M_DATA_READ call to answer.
     1620 * @param src    Source address for the IPC_M_DATA_READ call.
     1621 * @param size   Size for the IPC_M_DATA_READ call. Can be smaller than
     1622 *               the maximum size announced by the sender.
     1623 *
     1624 * @return Zero on success or a value from @ref errno.h on failure.
     1625 *
    16101626 */
    16111627int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
     
    16471663}
    16481664
    1649 /** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
     1665/** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
    16501666 *
    16511667 * @param phoneid Phone that will be used to contact the receiving side.
     
    16641680/** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework.
    16651681 *
    1666  * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE calls
    1667  * so that the user doesn't have to remember the meaning of each IPC argument.
     1682 * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE
     1683 * calls so that the user doesn't have to remember the meaning of each IPC
     1684 * argument.
    16681685 *
    16691686 * So far, this wrapper is to be used from within a connection fibril.
    16701687 *
    1671  * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will
    1672  *               be stored.
    1673  * @param size   Storage where the suggested size will be stored. May be
    1674  *               NULL
    1675  *
    1676  * @return Non-zero on success, zero on failure.
    1677  *
    1678  */
    1679 int async_data_write_receive(ipc_callid_t *callid, size_t *size)
    1680 {
     1688 * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
     1689 * @param size   Storage for the suggested size. May be NULL.
     1690 *
     1691 * @return True on success, false on failure.
     1692 *
     1693 */
     1694bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
     1695{
     1696        assert(callid);
     1697       
    16811698        ipc_call_t data;
    1682        
    1683         assert(callid);
    1684        
    16851699        *callid = async_get_call(&data);
     1700       
    16861701        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE)
    1687                 return 0;
     1702                return false;
    16881703       
    16891704        if (size)
    16901705                *size = (size_t) IPC_GET_ARG2(data);
    16911706       
    1692         return 1;
     1707        return true;
    16931708}
    16941709
    16951710/** Wrapper for answering the IPC_M_DATA_WRITE calls using the async framework.
    16961711 *
    1697  * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls
    1698  * so that the user doesn't have to remember the meaning of each IPC argument.
     1712 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE
     1713 * calls so that the user doesn't have to remember the meaning of each IPC
     1714 * argument.
    16991715 *
    17001716 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     
    17921808 *
    17931809 */
    1794 void async_data_write_void(const int retval)
     1810void async_data_write_void(sysarg_t retval)
    17951811{
    17961812        ipc_callid_t callid;
  • uspace/lib/c/generic/async_sess.c

    rfd483ce r47b7006  
    105105#include <errno.h>
    106106#include <assert.h>
     107#include "private/async_sess.h"
    107108
    108109/** An inactive open connection. */
     
    137138 *
    138139 * Needs to be called prior to any other interface in this file.
    139  */
    140 void _async_sess_init(void)
     140 *
     141 */
     142void __async_sess_init(void)
    141143{
    142144        fibril_mutex_initialize(&async_sess_mutex);
  • uspace/lib/c/generic/fibril_synch.c

    rfd483ce r47b7006  
    105105
    106106        if (fibril_get_sercount() != 0)
    107                 core();
     107                abort();
    108108
    109109        futex_down(&async_futex);
     
    198198       
    199199        if (fibril_get_sercount() != 0)
    200                 core();
     200                abort();
    201201
    202202        futex_down(&async_futex);
     
    226226       
    227227        if (fibril_get_sercount() != 0)
    228                 core();
     228                abort();
    229229
    230230        futex_down(&async_futex);
  • uspace/lib/c/generic/io/io.c

    rfd483ce r47b7006  
    4646#include <ipc/devmap.h>
    4747#include <adt/list.h>
     48#include "../private/io.h"
    4849
    4950static void _ffillbuf(FILE *stream);
  • 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
  • uspace/lib/c/generic/malloc.c

    rfd483ce r47b7006  
    4545#include <futex.h>
    4646#include <adt/gcdlcm.h>
     47#include "private/malloc.h"
    4748
    4849/* Magic used in heap headers. */
     
    215216/** Initialize the heap allocator
    216217 *
    217  * Find how much physical memory we have and create
    218  * the heap management structures that mark the whole
    219  * physical memory as a single free block.
    220  *
    221  */
    222 void __heap_init(void)
    223 {
    224         futex_down(&malloc_futex);
    225        
    226         if (as_area_create((void *) &_heap, PAGE_SIZE,
    227             AS_AREA_WRITE | AS_AREA_READ)) {
    228                 heap_pages = 1;
    229                 heap_start = (void *) ALIGN_UP((uintptr_t) &_heap, BASE_ALIGN);
    230                 heap_end =
    231                     (void *) ALIGN_DOWN(((uintptr_t) &_heap) + PAGE_SIZE, BASE_ALIGN);
    232                
    233                 /* Make the entire area one large block. */
    234                 block_init(heap_start, heap_end - heap_start, true);
    235         }
    236        
    237         futex_up(&malloc_futex);
     218 * Create initial heap memory area. This routine is
     219 * only called from libc initialization, thus we do not
     220 * take any locks.
     221 *
     222 */
     223void __malloc_init(void)
     224{
     225        if (!as_area_create((void *) &_heap, PAGE_SIZE,
     226            AS_AREA_WRITE | AS_AREA_READ))
     227                abort();
     228       
     229        heap_pages = 1;
     230        heap_start = (void *) ALIGN_UP((uintptr_t) &_heap, BASE_ALIGN);
     231        heap_end =
     232            (void *) ALIGN_DOWN(((uintptr_t) &_heap) + PAGE_SIZE, BASE_ALIGN);
     233       
     234        /* Make the entire area one large block. */
     235        block_init(heap_start, heap_end - heap_start, true);
    238236}
    239237
  • uspace/lib/c/generic/private/async.h

    rfd483ce r47b7006  
    7979} awaiter_t;
    8080
    81 extern int __async_init(void);
     81extern void __async_init(void);
    8282extern void async_insert_timeout(awaiter_t *);
    8383
  • uspace/lib/c/generic/private/libc.h

    rfd483ce r47b7006  
    3737
    3838extern int main(int, char *[]);
    39 extern void __main(void *);
    40 extern void __exit(void);
     39extern void __main(void *) __attribute__((noreturn));
    4140
    4241#endif
  • uspace/lib/c/generic/thread.c

    rfd483ce r47b7006  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#include <thread.h>
     
    4141#include <str.h>
    4242#include <async.h>
     43#include "private/thread.h"
    4344
    4445#ifndef THREAD_INITIAL_STACK_PAGES_NO
     
    5051 * This function is called from __thread_entry() and is used
    5152 * to call the thread's implementing function and perform cleanup
    52  * and exit when thread returns back. Do not call this function
    53  * directly.
     53 * and exit when thread returns back.
    5454 *
    5555 * @param uarg Pointer to userspace argument structure.
     56 *
    5657 */
    5758void __thread_main(uspace_arg_t *uarg)
    5859{
    59         fibril_t *f;
    60 
    61         f = fibril_setup();
    62         __tcb_set(f->tcb);
    63 
     60        fibril_t *fibril = fibril_setup();
     61        if (fibril == NULL)
     62                thread_exit(0);
     63       
     64        __tcb_set(fibril->tcb);
     65       
    6466        uarg->uspace_thread_function(uarg->uspace_thread_arg);
    65         /* XXX: we cannot free the userspace stack while running on it */
    66 //      free(uarg->uspace_stack);
    67 //      free(uarg);
    68 
     67        /* XXX: we cannot free the userspace stack while running on it
     68                free(uarg->uspace_stack);
     69                free(uarg);
     70        */
     71       
    6972        /* If there is a manager, destroy it */
    7073        async_destroy_manager();
    71         fibril_teardown(f);
    72 
     74        fibril_teardown(fibril);
     75       
    7376        thread_exit(0);
    7477}
     
    127130 *
    128131 * @param status Exit status. Currently not used.
     132 *
    129133 */
    130134void thread_exit(int status)
    131135{
    132136        __SYSCALL1(SYS_THREAD_EXIT, (sysarg_t) status);
    133         for (;;)
    134                 ;
     137       
     138        /* Unreachable */
     139        while (1);
    135140}
    136141
  • uspace/lib/c/include/async.h

    rfd483ce r47b7006  
    5757extern atomic_t threads_in_ipc_wait;
    5858
     59#define async_manager() \
     60        fibril_switch(FIBRIL_TO_MANAGER)
     61
     62#define async_get_call(data) \
     63        async_get_call_timeout(data, 0)
     64
    5965extern ipc_callid_t async_get_call_timeout(ipc_call_t *, suseconds_t);
    60 
    61 static inline ipc_callid_t async_get_call(ipc_call_t *data)
    62 {
    63         return async_get_call_timeout(data, 0);
    64 }
    65 
    66 static inline void async_manager(void)
    67 {
    68         fibril_switch(FIBRIL_TO_MANAGER);
    69 }
    7066
    7167/*
     
    142138 */
    143139
    144 extern int async_forward_fast(ipc_callid_t, int, int, sysarg_t, sysarg_t, int);
    145 extern int async_forward_slow(ipc_callid_t, int, int, sysarg_t, sysarg_t,
    146     sysarg_t, sysarg_t, sysarg_t, int);
     140extern int async_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
     141    unsigned int);
     142extern int async_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
     143    sysarg_t, sysarg_t, sysarg_t, unsigned int);
    147144
    148145/*
     
    305302        async_share_in_start((phoneid), (dst), (size), (arg), (flags))
    306303
    307 extern int async_share_in_start(int, void *, size_t, sysarg_t, int *);
    308 extern int async_share_in_receive(ipc_callid_t *, size_t *);
    309 extern int async_share_in_finalize(ipc_callid_t, void *, int );
    310 extern int async_share_out_start(int, void *, int);
    311 extern int async_share_out_receive(ipc_callid_t *, size_t *, int *);
     304extern int async_share_in_start(int, void *, size_t, sysarg_t, unsigned int *);
     305extern bool async_share_in_receive(ipc_callid_t *, size_t *);
     306extern int async_share_in_finalize(ipc_callid_t, void *, unsigned int);
     307
     308extern int async_share_out_start(int, void *, unsigned int);
     309extern bool async_share_out_receive(ipc_callid_t *, size_t *, unsigned int *);
    312310extern int async_share_out_finalize(ipc_callid_t, void *);
    313311
     
    343341
    344342extern int async_data_read_start(int, void *, size_t);
    345 extern int async_data_read_receive(ipc_callid_t *, size_t *);
     343extern bool async_data_read_receive(ipc_callid_t *, size_t *);
    346344extern int async_data_read_finalize(ipc_callid_t, const void *, size_t);
    347345
     
    382380
    383381extern int async_data_write_start(int, const void *, size_t);
    384 extern int async_data_write_receive(ipc_callid_t *, size_t *);
     382extern bool async_data_write_receive(ipc_callid_t *, size_t *);
    385383extern int async_data_write_finalize(ipc_callid_t, void *, size_t);
    386384
    387385extern int async_data_write_accept(void **, const bool, const size_t,
    388386    const size_t, const size_t, size_t *);
    389 extern void async_data_write_void(const int);
     387extern void async_data_write_void(sysarg_t);
    390388
    391389extern int async_data_write_forward_fast(int, sysarg_t, sysarg_t, sysarg_t,
  • uspace/lib/c/include/async_sess.h

    rfd483ce r47b7006  
    4545} async_sess_t;
    4646
    47 extern void _async_sess_init(void);
    4847extern void async_session_create(async_sess_t *, int, sysarg_t);
    4948extern void async_session_destroy(async_sess_t *);
  • uspace/lib/c/include/byteorder.h

    rfd483ce r47b7006  
    8080#endif
    8181
    82 #define htons(n)        host2uint16_t_be((n))
    83 #define htonl(n)        host2uint32_t_be((n))
    84 #define ntohs(n)        uint16_t_be2host((n))
    85 #define ntohl(n)        uint32_t_be2host((n))
     82#define htons(n)  host2uint16_t_be((n))
     83#define htonl(n)  host2uint32_t_be((n))
     84#define ntohs(n)  uint16_t_be2host((n))
     85#define ntohl(n)  uint32_t_be2host((n))
    8686
    8787static inline uint64_t uint64_t_byteorder_swap(uint64_t n)
  • uspace/lib/c/include/err.h

    rfd483ce r47b7006  
    3939
    4040#define errx(status, fmt, ...) \
    41         { \
     41        do { \
    4242                printf((fmt), ##__VA_ARGS__); \
    43                 _exit(status); \
    44         }
     43                exit(status); \
     44        } while (0)
    4545
    4646#endif
  • uspace/lib/c/include/errno.h

    rfd483ce r47b7006  
    3939#include <fibril.h>
    4040
     41#define errno _errno
     42
    4143extern int _errno;
    42 
    43 #define errno _errno
    4444
    4545#define EMFILE        (-18)
     
    5757
    5858/** An API function is called while another blocking function is in progress. */
    59 #define EINPROGRESS     (-10036)
     59#define EINPROGRESS  (-10036)
    6060
    6161/** The socket identifier is not valid. */
    62 #define ENOTSOCK        (-10038)
     62#define ENOTSOCK  (-10038)
    6363
    6464/** The destination address required. */
    65 #define EDESTADDRREQ    (-10039)
     65#define EDESTADDRREQ  (-10039)
    6666
    6767/** Protocol is not supported.  */
    68 #define EPROTONOSUPPORT (-10043)
     68#define EPROTONOSUPPORT  (-10043)
    6969
    7070/** Socket type is not supported. */
    71 #define ESOCKTNOSUPPORT (-10044)
     71#define ESOCKTNOSUPPORT  (-10044)
    7272
    7373/** Protocol family is not supported. */
    74 #define EPFNOSUPPORT    (-10046)
     74#define EPFNOSUPPORT  (-10046)
    7575
    7676/** Address family is not supported. */
    77 #define EAFNOSUPPORT    (-10047)
     77#define EAFNOSUPPORT  (-10047)
    7878
    7979/** Address is already in use. */
    80 #define EADDRINUSE      (-10048)
     80#define EADDRINUSE  (-10048)
    8181
    8282/** The socket is not connected or bound. */
    83 #define ENOTCONN        (-10057)
     83#define ENOTCONN  (-10057)
    8484
    8585/** The requested operation was not performed. Try again later. */
    86 #define EAGAIN          (-11002)
     86#define EAGAIN  (-11002)
    8787
    88 /** No data.
    89  */
    90 #define NO_DATA         (-11004)
     88/** No data. */
     89#define NO_DATA (-11004)
    9190
    9291#endif
  • uspace/lib/c/include/loader/pcb.h

    rfd483ce r47b7006  
    5252        /** Program entry point. */
    5353        entry_point_t entry;
    54 
     54       
    5555        /** Current working directory. */
    5656        char *cwd;
  • uspace/lib/c/include/malloc.h

    rfd483ce r47b7006  
    3838#include <sys/types.h>
    3939
    40 extern void __heap_init(void);
    4140extern uintptr_t get_max_heap_addr(void);
    4241
  • uspace/lib/c/include/setjmp.h

    rfd483ce r47b7006  
    4141
    4242extern int setjmp(jmp_buf env);
    43 extern void longjmp(jmp_buf env,int val) __attribute__((__noreturn__));
     43extern void longjmp(jmp_buf env, int val) __attribute__((noreturn));
    4444
    4545#endif
  • uspace/lib/c/include/stdlib.h

    rfd483ce r47b7006  
    4040#include <stacktrace.h>
    4141
    42 #define abort() \
    43         do { \
    44                 stacktrace_print(); \
    45                 _exit(1); \
    46         } while (0)
     42#define RAND_MAX  714025
    4743
    48 #define core() \
    49         *((int *) 0) = 0xbadbad;
    50 
    51 #define exit(status)  _exit((status))
    52 
    53 #define RAND_MAX  714025
     44#define rand()       random()
     45#define srand(seed)  srandom(seed)
    5446
    5547extern long int random(void);
    5648extern void srandom(unsigned int seed);
    5749
    58 static inline int rand(void)
    59 {
    60         return random();
    61 }
    62 
    63 static inline void srand(unsigned int seed)
    64 {
    65         srandom(seed);
    66 }
     50extern void abort(void) __attribute__((noreturn));
    6751
    6852#endif
  • uspace/lib/c/include/syscall.h

    rfd483ce r47b7006  
    3232/**
    3333 * @file
    34  * @brief       Syscall function declaration for architectures that don't
    35  *              inline syscalls or architectures that handle syscalls
    36  *              according to the number of arguments.
     34 * @brief Syscall function declaration for architectures that don't
     35 *        inline syscalls or architectures that handle syscalls
     36 *        according to the number of arguments.
    3737 */
    3838
     
    4040#define LIBC_SYSCALL_H_
    4141
    42 #ifndef LIBARCH_SYSCALL_GENERIC
    43 #error "You can't include this file directly."
     42#ifndef LIBARCH_SYSCALL_GENERIC
     43        #error You cannot include this file directly
    4444#endif
    4545
     
    4747#include <kernel/syscall/syscall.h>
    4848
    49 #define __syscall0      __syscall
    50 #define __syscall1      __syscall
    51 #define __syscall2      __syscall
    52 #define __syscall3      __syscall
    53 #define __syscall4      __syscall
    54 #define __syscall5      __syscall
    55 #define __syscall6      __syscall
     49#define __syscall0  __syscall
     50#define __syscall1  __syscall
     51#define __syscall2  __syscall
     52#define __syscall3  __syscall
     53#define __syscall4  __syscall
     54#define __syscall5  __syscall
     55#define __syscall6  __syscall
    5656
    5757extern sysarg_t __syscall(const sysarg_t p1, const sysarg_t p2,
  • uspace/lib/c/include/thread.h

    rfd483ce r47b7006  
    3636#define LIBC_THREAD_H_
    3737
    38 #include <kernel/proc/uarg.h>
    3938#include <libarch/thread.h>
    4039#include <sys/types.h>
     
    4241typedef uint64_t thread_id_t;
    4342
    44 extern void __thread_entry(void);
    45 extern void __thread_main(uspace_arg_t *);
    46 
    4743extern int thread_create(void (*)(void *), void *, const char *, thread_id_t *);
    48 extern void thread_exit(int) __attribute__ ((noreturn));
     44extern void thread_exit(int) __attribute__((noreturn));
    4945extern void thread_detach(thread_id_t);
    5046extern int thread_join(thread_id_t);
  • uspace/lib/c/include/tls.h

    rfd483ce r47b7006  
    5757extern void tls_free_variant_1(tcb_t *, size_t);
    5858#endif
     59
    5960#ifdef CONFIG_TLS_VARIANT_2
    6061extern tcb_t *tls_alloc_variant_2(void **, size_t);
  • uspace/lib/c/include/unistd.h

    rfd483ce r47b7006  
    4141
    4242#ifndef NULL
    43         #define NULL    ((void *) 0)
     43        #define NULL  ((void *) 0)
    4444#endif
    4545
     
    7474extern int chdir(const char *);
    7575
    76 extern void _exit(int) __attribute__((noreturn));
     76extern void exit(int) __attribute__((noreturn));
    7777extern int usleep(useconds_t);
    7878extern unsigned int sleep(unsigned int);
  • uspace/lib/c/include/vfs/vfs.h

    rfd483ce r47b7006  
    5757extern int unmount(const char *);
    5858
    59 extern void __stdio_init(int filc, fdi_node_t *filv[]);
    60 extern void __stdio_done(void);
    61 
    6259extern int open_node(fdi_node_t *, int);
    6360extern int fd_phone(int);
  • uspace/srv/bd/ata_bd/ata_bd.c

    rfd483ce r47b7006  
    265265        sysarg_t method;
    266266        devmap_handle_t dh;
    267         int flags;
     267        unsigned int flags;
    268268        int retval;
    269269        uint64_t ba;
  • uspace/srv/bd/file_bd/file_bd.c

    rfd483ce r47b7006  
    177177        sysarg_t method;
    178178        size_t comm_size;
    179         int flags;
     179        unsigned int flags;
    180180        int retval;
    181181        uint64_t ba;
  • uspace/srv/bd/gxe_bd/gxe_bd.c

    rfd483ce r47b7006  
    160160        sysarg_t method;
    161161        devmap_handle_t dh;
    162         int flags;
     162        unsigned int flags;
    163163        int retval;
    164164        uint64_t ba;
  • uspace/srv/bd/part/guid_part/guid_part.c

    rfd483ce r47b7006  
    315315        sysarg_t method;
    316316        devmap_handle_t dh;
    317         int flags;
     317        unsigned int flags;
    318318        int retval;
    319319        aoff64_t ba;
  • uspace/srv/bd/part/mbr_part/mbr_part.c

    rfd483ce r47b7006  
    393393        sysarg_t method;
    394394        devmap_handle_t dh;
    395         int flags;
     395        unsigned int flags;
    396396        int retval;
    397397        uint64_t ba;
  • uspace/srv/bd/rd/rd.c

    rfd483ce r47b7006  
    102102         * Now we wait for the client to send us its communication as_area.
    103103         */
    104         int flags;
     104        unsigned int flags;
    105105        if (async_share_out_receive(&callid, &comm_size, &flags)) {
    106106                fs_va = as_get_mappable_page(comm_size);
Note: See TracChangeset for help on using the changeset viewer.