Changes in / [197ef43:6aef742] in mainline


Ignore:
Files:
1 added
4 deleted
47 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/ipc/event_types.h

    r197ef43 r6aef742  
    4141        /** Returning from kernel console to userspace */
    4242        EVENT_KCONSOLE,
    43         /** A task/thread has faulted and will be terminated */
     43        /** A thread has faulted and will be terminated */
    4444        EVENT_FAULT,
    4545        EVENT_END
  • kernel/generic/include/proc/task.h

    r197ef43 r6aef742  
    131131extern task_t *task_find_by_id(task_id_t);
    132132extern int task_kill(task_id_t);
    133 extern void task_kill_self(bool) __attribute__((noreturn));
    134133extern void task_get_accounting(task_t *, uint64_t *, uint64_t *);
    135134extern void task_print_list(bool);
     
    156155extern sysarg_t sys_task_set_name(const char *, size_t);
    157156extern sysarg_t sys_task_kill(task_id_t *);
    158 extern sysarg_t sys_task_exit(sysarg_t);
    159157
    160158#endif
  • kernel/generic/include/syscall/syscall.h

    r197ef43 r6aef742  
    4848        SYS_TASK_SET_NAME,
    4949        SYS_TASK_KILL,
    50         SYS_TASK_EXIT,
    5150        SYS_PROGRAM_SPAWN_LOADER,
    5251       
  • kernel/generic/src/interrupt/interrupt.c

    r197ef43 r6aef742  
    4545#include <console/console.h>
    4646#include <console/cmd.h>
     47#include <ipc/event.h>
    4748#include <synch/mutex.h>
    4849#include <time/delay.h>
     
    187188        printf("\n");
    188189       
    189         task_kill_self(true);
     190        /*
     191         * Userspace can subscribe for FAULT events to take action
     192         * whenever a thread faults. (E.g. take a dump, run a debugger).
     193         * The notification is always available, but unless Udebug is enabled,
     194         * that's all you get.
     195         */
     196        if (event_is_subscribed(EVENT_FAULT)) {
     197                /* Notify the subscriber that a fault occurred. */
     198                event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
     199                    UPPER32(TASK->taskid), (sysarg_t) THREAD);
     200               
     201#ifdef CONFIG_UDEBUG
     202                /* Wait for a debugging session. */
     203                udebug_thread_fault();
     204#endif
     205        }
     206       
     207        task_kill(TASK->taskid);
     208        thread_exit();
    190209}
    191210
  • kernel/generic/src/proc/task.c

    r197ef43 r6aef742  
    384384{
    385385        task_id_t taskid;
    386         int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
     386        int rc;
     387
     388        rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
    387389        if (rc != 0)
    388390                return (sysarg_t) rc;
    389        
     391
    390392        return (sysarg_t) task_kill(taskid);
    391393}
     
    518520}
    519521
    520 /** Kill the currently running task.
    521  *
    522  * @param notify Send out fault notifications.
    523  *
    524  * @return Zero on success or an error code from errno.h.
    525  *
    526  */
    527 void task_kill_self(bool notify)
    528 {
    529         /*
    530          * User space can subscribe for FAULT events to take action
    531          * whenever a task faults (to take a dump, run a debugger, etc.).
    532          * The notification is always available, but unless udebug is enabled,
    533          * that's all you get.
    534         */
    535         if (notify) {
    536                 if (event_is_subscribed(EVENT_FAULT)) {
    537                         /* Notify the subscriber that a fault occurred. */
    538                         event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
    539                             UPPER32(TASK->taskid), (sysarg_t) THREAD);
    540                
    541 #ifdef CONFIG_UDEBUG
    542                         /* Wait for a debugging session. */
    543                         udebug_thread_fault();
    544 #endif
    545                 }
    546         }
    547        
    548         irq_spinlock_lock(&tasks_lock, true);
    549         task_kill_internal(TASK);
    550         irq_spinlock_unlock(&tasks_lock, true);
    551        
    552         thread_exit();
    553 }
    554 
    555 /** Process syscall to terminate the current task.
    556  *
    557  * @param notify Send out fault notifications.
    558  *
    559  */
    560 sysarg_t sys_task_exit(sysarg_t notify)
    561 {
    562         task_kill_self(notify);
    563        
    564         /* Unreachable */
    565         return EOK;
    566 }
    567 
    568522static bool task_print_walker(avltree_node_t *node, void *arg)
    569523{
  • kernel/generic/src/syscall/syscall.c

    r197ef43 r6aef742  
    8686        } else {
    8787                printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
    88                 task_kill_self(true);
     88                task_kill(TASK->taskid);
     89                thread_exit();
    8990        }
    9091       
     
    130131        (syshandler_t) sys_task_set_name,
    131132        (syshandler_t) sys_task_kill,
    132         (syshandler_t) sys_task_exit,
    133133        (syshandler_t) sys_program_spawn_loader,
    134134       
  • uspace/lib/c/Makefile

    r197ef43 r6aef742  
    9797        generic/adt/char_map.c \
    9898        generic/time.c \
     99        generic/err.c \
    99100        generic/stdlib.c \
    100101        generic/mman.c \
  • uspace/lib/c/arch/abs32le/src/entry.c

    r197ef43 r6aef742  
    3737{
    3838        __main(NULL);
     39        __exit();
    3940}
    4041
  • uspace/lib/c/arch/abs32le/src/thread_entry.c

    r197ef43 r6aef742  
    3131
    3232#include <unistd.h>
    33 #include "../../../generic/private/thread.h"
     33#include <thread.h>
    3434
    3535void __thread_entry(void)
  • uspace/lib/c/arch/amd64/src/entry.s

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

    r197ef43 r6aef742  
    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
    5658
    5759.data
     
    6062ras_page:
    6163        .long 0
     64
  • uspace/lib/c/arch/ia32/src/entry.s

    r197ef43 r6aef742  
    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

    r197ef43 r6aef742  
    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
     460:
     47        br.call.sptk.many b0 = __exit
  • uspace/lib/c/arch/mips32/src/entry.s

    r197ef43 r6aef742  
    5656        jal __main
    5757        nop
     58       
     59        jal __exit
     60        nop
    5861.end
    5962
  • uspace/lib/c/arch/ppc32/src/entry.s

    r197ef43 r6aef742  
    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

    r197ef43 r6aef742  
    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

    r197ef43 r6aef742  
    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 ]
    4449 *
    4550 * Example of use (pseudo C):
     
    122127
    123128/**
    124  * Structures of this type are used to group information about
    125  * a call and about a message queue link.
     129 * Structures of this type are used to group information about a call and a
     130 * message queue link.
    126131 */
    127132typedef struct {
     
    151156        /** Link to the client tracking structure. */
    152157        client_t *client;
    153        
     158
    154159        /** Messages that should be delivered to this fibril. */
    155160        link_t msg_queue;
     
    168173
    169174/** Identifier of the incoming connection handled by the current fibril. */
    170 static fibril_local connection_t *FIBRIL_connection;
     175fibril_local connection_t *FIBRIL_connection;
    171176
    172177static void *default_client_data_constructor(void)
     
    197202{
    198203        assert(FIBRIL_connection);
     204
    199205        return FIBRIL_connection->client->data;
    200206}
    201207
    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  */
    210 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
    211 {
    212         ipc_answer_0(callid, ENOENT);
    213 }
     208static void default_client_connection(ipc_callid_t callid, ipc_call_t *call);
     209static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call);
    214210
    215211/**
     
    217213 */
    218214static 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  */
    228 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
    229 {
    230 }
    231215
    232216/**
     
    240224static LIST_INITIALIZE(timeout_list);
    241225
    242 #define CLIENT_HASH_TABLE_BUCKETS  32
    243 #define CONN_HASH_TABLE_BUCKETS    32
    244 
    245 static hash_index_t client_hash(unsigned long key[])
     226#define CLIENT_HASH_TABLE_BUCKETS       32
     227#define CONN_HASH_TABLE_BUCKETS         32
     228
     229static hash_index_t client_hash(unsigned long *key)
    246230{
    247231        assert(key);
    248         return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
     232        return (((*key) >> 4) % CLIENT_HASH_TABLE_BUCKETS);
    249233}
    250234
    251235static int client_compare(unsigned long key[], hash_count_t keys, link_t *item)
    252236{
    253         client_t *client = hash_table_get_instance(item, client_t, link);
    254         return (key[0] == client->in_task_hash);
     237        client_t *cl = hash_table_get_instance(item, client_t, link);
     238        return (key[0] == cl->in_task_hash);
    255239}
    256240
     
    273257 *
    274258 */
    275 static hash_index_t conn_hash(unsigned long key[])
     259static hash_index_t conn_hash(unsigned long *key)
    276260{
    277261        assert(key);
    278         return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS);
     262        return (((*key) >> 4) % CONN_HASH_TABLE_BUCKETS);
    279263}
    280264
     
    290274static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item)
    291275{
    292         connection_t *conn = hash_table_get_instance(item, connection_t, link);
    293         return (key[0] == conn->in_phone_hash);
     276        connection_t *hs = hash_table_get_instance(item, connection_t, link);
     277        return (key[0] == hs->in_phone_hash);
    294278}
    295279
     
    306290        free(hash_table_get_instance(item, connection_t, link));
    307291}
     292
    308293
    309294/** Operations for the connection hash table. */
     
    326311        link_t *tmp = timeout_list.next;
    327312        while (tmp != &timeout_list) {
    328                 awaiter_t *cur
    329                     = list_get_instance(tmp, awaiter_t, to_event.link);
     313                awaiter_t *cur;
    330314               
     315                cur = list_get_instance(tmp, awaiter_t, to_event.link);
    331316                if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires))
    332317                        break;
    333                
    334318                tmp = tmp->next;
    335319        }
     
    348332 *
    349333 * @return False if the call doesn't match any connection.
    350  * @return True if the call was passed to the respective connection fibril.
     334 *         True if the call was passed to the respective connection fibril.
    351335 *
    352336 */
     
    485469                         * the first IPC_M_PHONE_HUNGUP call and continues to
    486470                         * call async_get_call_timeout(). Repeat
    487                          * IPC_M_PHONE_HUNGUP until the caller notices.
     471                         * IPC_M_PHONE_HUNGUP until the caller notices. 
    488472                         */
    489473                        memset(call, 0, sizeof(ipc_call_t));
     
    492476                        return conn->close_callid;
    493477                }
    494                
     478
    495479                if (usecs)
    496480                        async_insert_timeout(&conn->wdata);
     
    530514}
    531515
     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 */
     524static 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 */
     537static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)
     538{
     539}
     540
    532541/** Wrapper for client connection fibril.
    533542 *
     
    542551static int connection_fibril(void *arg)
    543552{
     553        unsigned long key;
     554        client_t *cl;
     555        link_t *lnk;
     556        bool destroy = false;
     557
    544558        /*
    545559         * Setup fibril-local connection pointer.
    546560         */
    547561        FIBRIL_connection = (connection_t *) arg;
    548        
    549         futex_down(&async_futex);
    550        
     562
    551563        /*
    552564         * Add our reference for the current connection in the client task
     
    554566         * hash in a new tracking structure.
    555567         */
    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        
     568        futex_down(&async_futex);
     569        key = FIBRIL_connection->in_task_hash;
     570        lnk = hash_table_find(&client_hash_table, &key);
    562571        if (lnk) {
    563                 client = hash_table_get_instance(lnk, client_t, link);
    564                 client->refcnt++;
     572                cl = hash_table_get_instance(lnk, client_t, link);
     573                cl->refcnt++;
    565574        } else {
    566                 client = malloc(sizeof(client_t));
    567                 if (!client) {
     575                cl = malloc(sizeof(client_t));
     576                if (!cl) {
    568577                        ipc_answer_0(FIBRIL_connection->callid, ENOMEM);
    569578                        futex_up(&async_futex);
    570579                        return 0;
    571580                }
    572                
    573                 client->in_task_hash = FIBRIL_connection->in_task_hash;
    574                
     581                cl->in_task_hash = FIBRIL_connection->in_task_hash;
    575582                async_serialize_start();
    576                 client->data = async_client_data_create();
     583                cl->data = async_client_data_create();
    577584                async_serialize_end();
    578                
    579                 client->refcnt = 1;
    580                 hash_table_insert(&client_hash_table, &key, &client->link);
    581         }
    582        
     585                cl->refcnt = 1;
     586                hash_table_insert(&client_hash_table, &key, &cl->link);
     587        }
    583588        futex_up(&async_futex);
    584        
    585         FIBRIL_connection->client = client;
    586        
     589
     590        FIBRIL_connection->client = cl;
     591
    587592        /*
    588593         * Call the connection handler function.
     
    594599         * Remove the reference for this client task connection.
    595600         */
    596         bool destroy;
    597        
    598601        futex_down(&async_futex);
    599        
    600         if (--client->refcnt == 0) {
     602        if (--cl->refcnt == 0) {
    601603                hash_table_remove(&client_hash_table, &key, 1);
    602604                destroy = true;
    603         } else
    604                 destroy = false;
    605        
     605        }
    606606        futex_up(&async_futex);
    607        
     607
    608608        if (destroy) {
    609                 if (client->data)
    610                         async_client_data_destroy(client->data);
    611                
    612                 free(client);
    613         }
    614        
     609                if (cl->data)
     610                        async_client_data_destroy(cl->data);
     611                free(cl);
     612        }
     613
    615614        /*
    616615         * Remove myself from the connection hash table.
     
    625624         */
    626625        while (!list_empty(&FIBRIL_connection->msg_queue)) {
    627                 msg_t *msg =
    628                     list_get_instance(FIBRIL_connection->msg_queue.next, msg_t,
    629                     link);
     626                msg_t *msg;
    630627               
     628                msg = list_get_instance(FIBRIL_connection->msg_queue.next,
     629                    msg_t, link);
    631630                list_remove(&msg->link);
    632631                ipc_answer_0(msg->callid, EHANGUP);
     
    671670                if (callid)
    672671                        ipc_answer_0(callid, ENOMEM);
    673                
    674672                return (uintptr_t) NULL;
    675673        }
     
    719717static void handle_call(ipc_callid_t callid, ipc_call_t *call)
    720718{
    721         /* Unrouted call - take some default action */
     719        /* Unrouted call - do some default behaviour */
    722720        if ((callid & IPC_CALLID_NOTIFICATION)) {
    723721                process_notification(callid, call);
    724                 return;
     722                goto out;
    725723        }
    726724       
     
    728726        case IPC_M_CONNECT_ME:
    729727        case IPC_M_CONNECT_ME_TO:
    730                 /* Open new connection with fibril, etc. */
     728                /* Open new connection with fibril etc. */
    731729                async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
    732730                    callid, call, client_connection);
    733                 return;
     731                goto out;
    734732        }
    735733       
    736734        /* Try to route the call through the connection hash table */
    737735        if (route_call(callid, call))
    738                 return;
     736                goto out;
    739737       
    740738        /* Unknown call from unknown phone - hang it up */
    741739        ipc_answer_0(callid, EHANGUP);
     740        return;
     741       
     742out:
     743        ;
    742744}
    743745
     
    752754        link_t *cur = timeout_list.next;
    753755        while (cur != &timeout_list) {
    754                 awaiter_t *waiter =
    755                     list_get_instance(cur, awaiter_t, to_event.link);
     756                awaiter_t *waiter;
    756757               
     758                waiter = list_get_instance(cur, awaiter_t, to_event.link);
    757759                if (tv_gt(&waiter->to_event.expires, &tv))
    758760                        break;
    759                
     761
    760762                cur = cur->next;
    761                
     763
    762764                list_remove(&waiter->to_event.link);
    763765                waiter->to_event.inlist = false;
     
    786788        while (true) {
    787789                if (fibril_switch(FIBRIL_FROM_MANAGER)) {
    788                         futex_up(&async_futex);
     790                        futex_up(&async_futex); 
    789791                        /*
    790792                         * async_futex is always held when entering a manager
     
    809811                                continue;
    810812                        } else
    811                                 timeout = tv_sub(&waiter->to_event.expires, &tv);
     813                                timeout = tv_sub(&waiter->to_event.expires,
     814                                    &tv);
    812815                } else
    813816                        timeout = SYNCH_NO_TIMEOUT;
    814817               
    815818                futex_up(&async_futex);
    816                
     819
    817820                atomic_inc(&threads_in_ipc_wait);
    818821               
     
    822825               
    823826                atomic_dec(&threads_in_ipc_wait);
    824                
     827
    825828                if (!callid) {
    826829                        handle_expired_timeouts();
     
    872875/** Initialize the async framework.
    873876 *
    874  */
    875 void __async_init(void)
     877 * @return Zero on success or an error code.
     878 */
     879int __async_init(void)
    876880{
    877881        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1,
    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();
     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;
    884890}
    885891
     
    894900 * @param retval Value returned in the answer.
    895901 * @param data   Call data of the answer.
    896  *
    897902 */
    898903static void reply_received(void *arg, int retval, ipc_call_t *data)
     
    942947    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr)
    943948{
    944         amsg_t *msg = malloc(sizeof(amsg_t));
     949        amsg_t *msg = malloc(sizeof(*msg));
    945950       
    946951        if (!msg)
     
    951956       
    952957        msg->wdata.to_event.inlist = false;
    953        
    954         /*
    955          * We may sleep in the next method,
    956          * but it will use its own means
    957          */
     958        /* We may sleep in the next method, but it will use its own mechanism */
    958959        msg->wdata.active = true;
    959960       
     
    986987    ipc_call_t *dataptr)
    987988{
    988         amsg_t *msg = malloc(sizeof(amsg_t));
     989        amsg_t *msg = malloc(sizeof(*msg));
    989990       
    990991        if (!msg)
     
    995996       
    996997        msg->wdata.to_event.inlist = false;
    997        
    998         /*
    999          * We may sleep in the next method,
    1000          * but it will use its own means
    1001          */
     998        /* We may sleep in next method, but it will use its own mechanism */
    1002999        msg->wdata.active = true;
    10031000       
     
    10981095void async_usleep(suseconds_t timeout)
    10991096{
    1100         amsg_t *msg = malloc(sizeof(amsg_t));
     1097        amsg_t *msg = malloc(sizeof(*msg));
    11011098       
    11021099        if (!msg)
     
    13101307}
    13111308
    1312 int async_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
    1313     sysarg_t arg1, sysarg_t arg2, unsigned int mode)
     1309int async_forward_fast(ipc_callid_t callid, int phoneid, int imethod,
     1310    sysarg_t arg1, sysarg_t arg2, int mode)
    13141311{
    13151312        return ipc_forward_fast(callid, phoneid, imethod, arg1, arg2, mode);
    13161313}
    13171314
    1318 int async_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
     1315int async_forward_slow(ipc_callid_t callid, int phoneid, int imethod,
    13191316    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
    1320     unsigned int mode)
     1317    int mode)
    13211318{
    13221319        return ipc_forward_slow(callid, phoneid, imethod, arg1, arg2, arg3, arg4,
     
    14311428}
    14321429
    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  *
     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.
    14431440 */
    14441441int async_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
    1445     unsigned int *flags)
    1446 {
     1442    int *flags)
     1443{
     1444        int res;
    14471445        sysarg_t tmp_flags;
    1448         int res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
     1446        res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
    14491447            (sysarg_t) size, arg, NULL, &tmp_flags);
    1450        
    14511448        if (flags)
    1452                 *flags = (unsigned int) tmp_flags;
    1453        
     1449                *flags = tmp_flags;
    14541450        return res;
    14551451}
     
    14571453/** Wrapper for receiving the IPC_M_SHARE_IN calls using the async framework.
    14581454 *
    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.
     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.
    14621457 *
    14631458 * So far, this wrapper is to be used from within a connection fibril.
    14641459 *
    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  */
    1471 bool async_share_in_receive(ipc_callid_t *callid, size_t *size)
    1472 {
     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 */
     1466int async_share_in_receive(ipc_callid_t *callid, size_t *size)
     1467{
     1468        ipc_call_t data;
     1469       
    14731470        assert(callid);
    14741471        assert(size);
    1475        
    1476         ipc_call_t data;
     1472
    14771473        *callid = async_get_call(&data);
    1478        
    14791474        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
    1480                 return false;
    1481        
     1475                return 0;
    14821476        *size = (size_t) IPC_GET_ARG2(data);
    1483         return true;
     1477        return 1;
    14841478}
    14851479
    14861480/** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework.
    14871481 *
    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  */
    1499 int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
     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 */
     1491int async_share_in_finalize(ipc_callid_t callid, void *src, int flags)
    15001492{
    15011493        return ipc_share_in_finalize(callid, src, flags);
    15021494}
    15031495
    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  */
    1513 int async_share_out_start(int phoneid, void *src, unsigned int flags)
     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 */
     1504int async_share_out_start(int phoneid, void *src, int flags)
    15141505{
    15151506        return async_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
     
    15191510/** Wrapper for receiving the IPC_M_SHARE_OUT calls using the async framework.
    15201511 *
    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.
     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.
    15241514 *
    15251515 * So far, this wrapper is to be used from within a connection fibril.
    15261516 *
    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  */
    1534 bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags)
    1535 {
     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 */
     1525int async_share_out_receive(ipc_callid_t *callid, size_t *size, int *flags)
     1526{
     1527        ipc_call_t data;
     1528       
    15361529        assert(callid);
    15371530        assert(size);
    15381531        assert(flags);
    1539        
    1540         ipc_call_t data;
     1532
    15411533        *callid = async_get_call(&data);
    1542        
    15431534        if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
    1544                 return false;
    1545        
     1535                return 0;
    15461536        *size = (size_t) IPC_GET_ARG2(data);
    1547         *flags = (unsigned int) IPC_GET_ARG3(data);
    1548         return true;
     1537        *flags = (int) IPC_GET_ARG3(data);
     1538        return 1;
    15491539}
    15501540
    15511541/** Wrapper for answering the IPC_M_SHARE_OUT calls using the async framework.
    15521542 *
    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  *
     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.
    15621550 */
    15631551int async_share_out_finalize(ipc_callid_t callid, void *dst)
     
    15661554}
    15671555
    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  *
     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.
    15761564 */
    15771565int async_data_read_start(int phoneid, void *dst, size_t size)
     
    15831571/** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework.
    15841572 *
    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.
     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.
    15881575 *
    15891576 * So far, this wrapper is to be used from within a connection fibril.
    15901577 *
    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  */
    1597 bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
    1598 {
     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 */
     1585int async_data_read_receive(ipc_callid_t *callid, size_t *size)
     1586{
     1587        ipc_call_t data;
     1588       
    15991589        assert(callid);
    1600        
    1601         ipc_call_t data;
     1590
    16021591        *callid = async_get_call(&data);
    1603        
    16041592        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ)
    1605                 return false;
    1606        
     1593                return 0;
    16071594        if (size)
    16081595                *size = (size_t) IPC_GET_ARG2(data);
    1609        
    1610         return true;
     1596        return 1;
    16111597}
    16121598
    16131599/** Wrapper for answering the IPC_M_DATA_READ calls using the async framework.
    16141600 *
    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  *
     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.
    16261610 */
    16271611int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
     
    16631647}
    16641648
    1665 /** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
     1649/** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
    16661650 *
    16671651 * @param phoneid Phone that will be used to contact the receiving side.
     
    16801664/** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework.
    16811665 *
    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.
     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.
    16851668 *
    16861669 * So far, this wrapper is to be used from within a connection fibril.
    16871670 *
    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  */
    1694 bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
    1695 {
     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 */
     1679int async_data_write_receive(ipc_callid_t *callid, size_t *size)
     1680{
     1681        ipc_call_t data;
     1682       
    16961683        assert(callid);
    16971684       
    1698         ipc_call_t data;
    16991685        *callid = async_get_call(&data);
    1700        
    17011686        if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE)
    1702                 return false;
     1687                return 0;
    17031688       
    17041689        if (size)
    17051690                *size = (size_t) IPC_GET_ARG2(data);
    17061691       
    1707         return true;
     1692        return 1;
    17081693}
    17091694
    17101695/** Wrapper for answering the IPC_M_DATA_WRITE calls using the async framework.
    17111696 *
    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.
     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.
    17151699 *
    17161700 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     
    18081792 *
    18091793 */
    1810 void async_data_write_void(sysarg_t retval)
     1794void async_data_write_void(const int retval)
    18111795{
    18121796        ipc_callid_t callid;
  • uspace/lib/c/generic/async_sess.c

    r197ef43 r6aef742  
    105105#include <errno.h>
    106106#include <assert.h>
    107 #include "private/async_sess.h"
    108107
    109108/** An inactive open connection. */
     
    138137 *
    139138 * Needs to be called prior to any other interface in this file.
    140  *
    141  */
    142 void __async_sess_init(void)
     139 */
     140void _async_sess_init(void)
    143141{
    144142        fibril_mutex_initialize(&async_sess_mutex);
  • uspace/lib/c/generic/fibril_synch.c

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

    r197ef43 r6aef742  
    4646#include <ipc/devmap.h>
    4747#include <adt/list.h>
    48 #include "../private/io.h"
    4948
    5049static void _ffillbuf(FILE *stream);
  • uspace/lib/c/generic/ipc.c

    r197ef43 r6aef742  
    4949
    5050/**
    51  * Structures of this type are used for keeping track
    52  * of sent asynchronous calls and queing unsent calls.
     51 * Structures of this type are used for keeping track of sent asynchronous calls
     52 * and queing unsent calls.
    5353 */
    5454typedef struct {
    5555        link_t list;
    56        
     56
    5757        ipc_async_callback_t callback;
    5858        void *private;
    59        
    6059        union {
    6160                ipc_callid_t callid;
     
    6564                } msg;
    6665        } u;
    67        
    68         /** Fibril waiting for sending this call. */
    69         fid_t fid;
     66        fid_t fid;      /**< Fibril waiting for sending this call. */
    7067} async_call_t;
    7168
     
    7471/** List of asynchronous calls that were not accepted by kernel.
    7572 *
    76  * Protected by async_futex, because if the call is not accepted
    77  * by the kernel, the async framework is used automatically.
    78  *
     73 * It is protected by async_futex, because if the call cannot be sent into the
     74 * kernel, the async framework is used automatically.
    7975 */
    8076LIST_INITIALIZE(queued_calls);
     
    8278static atomic_t ipc_futex = FUTEX_INITIALIZER;
    8379
    84 /** Fast synchronous call.
    85  *
    86  * Only three payload arguments can be passed using this function. However,
    87  * this function is faster than the generic ipc_call_sync_slow() because
    88  * the payload is passed directly in registers.
    89  *
    90  * @param phoneid Phone handle for the call.
    91  * @param method  Requested method.
    92  * @param arg1    Service-defined payload argument.
    93  * @param arg2    Service-defined payload argument.
    94  * @param arg3    Service-defined payload argument.
    95  * @param result1 If non-NULL, the return ARG1 will be stored there.
    96  * @param result2 If non-NULL, the return ARG2 will be stored there.
    97  * @param result3 If non-NULL, the return ARG3 will be stored there.
    98  * @param result4 If non-NULL, the return ARG4 will be stored there.
    99  * @param result5 If non-NULL, the return ARG5 will be stored there.
    100  *
    101  * @return Negative values representing IPC errors.
    102  * @return Otherwise the RETVAL of the answer.
    103  *
    104  */
    105 int ipc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1,
    106     sysarg_t arg2, sysarg_t arg3, sysarg_t *result1, sysarg_t *result2,
    107     sysarg_t *result3, sysarg_t *result4, sysarg_t *result5)
     80/** Make a fast synchronous call.
     81 *
     82 * Only three payload arguments can be passed using this function. However, this
     83 * function is faster than the generic ipc_call_sync_slow() because the payload
     84 * is passed directly in registers.
     85 *
     86 * @param phoneid       Phone handle for the call.
     87 * @param method        Requested method.
     88 * @param arg1          Service-defined payload argument.
     89 * @param arg2          Service-defined payload argument.
     90 * @param arg3          Service-defined payload argument.
     91 * @param result1       If non-NULL, the return ARG1 will be stored there.
     92 * @param result2       If non-NULL, the return ARG2 will be stored there.
     93 * @param result3       If non-NULL, the return ARG3 will be stored there.
     94 * @param result4       If non-NULL, the return ARG4 will be stored there.
     95 * @param result5       If non-NULL, the return ARG5 will be stored there.
     96 *
     97 * @return              Negative values represent errors returned by IPC.
     98 *                      Otherwise the RETVAL of the answer is returned.
     99 */
     100int
     101ipc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1, sysarg_t arg2,
     102    sysarg_t arg3, sysarg_t *result1, sysarg_t *result2, sysarg_t *result3,
     103    sysarg_t *result4, sysarg_t *result5)
    108104{
    109105        ipc_call_t resdata;
    110         int callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
     106        int callres;
     107       
     108        callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
    111109            arg2, arg3, (sysarg_t) &resdata);
    112110        if (callres)
    113111                return callres;
    114        
    115112        if (result1)
    116113                *result1 = IPC_GET_ARG1(resdata);
     
    123120        if (result5)
    124121                *result5 = IPC_GET_ARG5(resdata);
    125        
     122
    126123        return IPC_GET_RETVAL(resdata);
    127124}
    128125
    129 /** Synchronous call transmitting 5 arguments of payload.
     126/** Make a synchronous call transmitting 5 arguments of payload.
    130127 *
    131128 * @param phoneid Phone handle for the call.
     
    142139 * @param result5 If non-NULL, storage for the fifth return argument.
    143140 *
    144  * @return Negative values representing IPC errors.
    145  * @return Otherwise the RETVAL of the answer.
    146  *
    147  */
    148 int ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
    149     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
    150     sysarg_t *result1, sysarg_t *result2, sysarg_t *result3, sysarg_t *result4,
    151     sysarg_t *result5)
     141 * @return Negative value means IPC error.
     142 *         Otherwise the RETVAL of the answer.
     143 *
     144 */
     145int
     146ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
     147    sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *result1,
     148    sysarg_t *result2, sysarg_t *result3, sysarg_t *result4, sysarg_t *result5)
    152149{
    153150        ipc_call_t data;
     
    179176}
    180177
    181 /** Send asynchronous message via syscall.
     178/** Syscall to send asynchronous message.
    182179 *
    183180 * @param phoneid Phone handle for the call.
     
    187184 *
    188185 */
    189 static ipc_callid_t ipc_call_async_internal(int phoneid, ipc_call_t *data)
     186static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
    190187{
    191188        return __SYSCALL2(SYS_IPC_CALL_ASYNC_SLOW, phoneid, (sysarg_t) data);
    192189}
    193190
    194 /** Prolog for ipc_call_async_*() functions.
    195  *
    196  * @param private  Argument for the answer/error callback.
    197  * @param callback Answer/error callback.
    198  *
    199  * @return New, partially initialized async_call structure or NULL.
    200  *
     191/** Prolog to ipc_call_async_*() functions.
     192 *
     193 * @param private       Argument for the answer/error callback.
     194 * @param callback      Answer/error callback.
     195 *
     196 * @return              New, partially initialized async_call structure or NULL.
    201197 */
    202198static inline async_call_t *ipc_prepare_async(void *private,
    203199    ipc_async_callback_t callback)
    204200{
    205         async_call_t *call =
    206             (async_call_t *) malloc(sizeof(async_call_t));
     201        async_call_t *call;
     202
     203        call = malloc(sizeof(*call));
    207204        if (!call) {
    208205                if (callback)
    209206                        callback(private, ENOMEM, NULL);
    210                
    211207                return NULL;
    212208        }
    213        
    214209        call->callback = callback;
    215210        call->private = private;
    216        
     211
    217212        return call;
    218213}
    219214
    220 /** Epilog for ipc_call_async_*() functions.
    221  *
    222  * @param callid      Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
    223  * @param phoneid     Phone handle through which the call was made.
    224  * @param call        Structure returned by ipc_prepare_async().
    225  * @param can_preempt If true, the current fibril can be preempted
    226  *                    in this call.
    227  *
     215/** Epilogue of ipc_call_async_*() functions.
     216 *
     217 * @param callid        Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
     218 * @param phoneid       Phone handle through which the call was made.
     219 * @param call          async_call structure returned by ipc_prepare_async().
     220 * @param can_preempt   If non-zero, the current fibril can be preempted in this
     221 *                      call.
    228222 */
    229223static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
    230     async_call_t *call, bool can_preempt)
    231 {
    232         if (!call) {
    233                 /* Nothing to do regardless if failed or not */
     224    async_call_t *call, int can_preempt)
     225{
     226        if (!call) { /* Nothing to do regardless if failed or not */
    234227                futex_up(&ipc_futex);
    235228                return;
    236229        }
    237        
     230
    238231        if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
    239232                futex_up(&ipc_futex);
    240                
    241233                /* Call asynchronous handler with error code */
    242234                if (call->callback)
    243235                        call->callback(call->private, ENOENT, NULL);
    244                
    245236                free(call);
    246237                return;
    247238        }
    248        
     239
    249240        if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
    250241                futex_up(&ipc_futex);
    251                
     242
    252243                call->u.msg.phoneid = phoneid;
    253244               
    254245                futex_down(&async_futex);
    255246                list_append(&call->list, &queued_calls);
    256                
     247
    257248                if (can_preempt) {
    258249                        call->fid = fibril_get_id();
     
    263254                        futex_up(&async_futex);
    264255                }
    265                
    266256                return;
    267257        }
    268        
    269258        call->u.callid = callid;
    270        
    271259        /* Add call to the list of dispatched calls */
    272260        list_append(&call->list, &dispatched_calls);
    273261        futex_up(&ipc_futex);
    274 }
    275 
    276 /** Fast asynchronous call.
     262       
     263}
     264
     265/** Make a fast asynchronous call.
    277266 *
    278267 * This function can only handle four arguments of payload. It is, however,
     
    280269 *
    281270 * Note that this function is a void function.
    282  *
    283  * During normal operation, answering this call will trigger the callback.
    284  * In case of fatal error, the callback handler is called with the proper
    285  * error code. If the call cannot be temporarily made, it is queued.
     271 * During normal opertation, answering this call will trigger the callback.
     272 * In case of fatal error, call the callback handler with the proper error code.
     273 * If the call cannot be temporarily made, queue it.
    286274 *
    287275 * @param phoneid     Phone handle for the call.
     
    293281 * @param private     Argument to be passed to the answer/error callback.
    294282 * @param callback    Answer or error callback.
    295  * @param can_preempt If true, the current fibril will be preempted in
     283 * @param can_preempt If non-zero, the current fibril will be preempted in
    296284 *                    case the kernel temporarily refuses to accept more
    297285 *                    asynchronous calls.
     
    300288void ipc_call_async_fast(int phoneid, sysarg_t imethod, sysarg_t arg1,
    301289    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, void *private,
    302     ipc_async_callback_t callback, bool can_preempt)
     290    ipc_async_callback_t callback, int can_preempt)
    303291{
    304292        async_call_t *call = NULL;
     
    311299       
    312300        /*
    313          * We need to make sure that we get callid
    314          * before another thread accesses the queue again.
     301         * We need to make sure that we get callid before another thread
     302         * accesses the queue again.
    315303         */
    316        
    317304        futex_down(&ipc_futex);
    318305        ipc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid,
     
    325312                                return;
    326313                }
    327                
    328314                IPC_SET_IMETHOD(call->u.msg.data, imethod);
    329315                IPC_SET_ARG1(call->u.msg.data, arg1);
     
    331317                IPC_SET_ARG3(call->u.msg.data, arg3);
    332318                IPC_SET_ARG4(call->u.msg.data, arg4);
    333                
    334319                /*
    335320                 * To achieve deterministic behavior, we always zero out the
    336321                 * arguments that are beyond the limits of the fast version.
    337322                 */
    338                
    339323                IPC_SET_ARG5(call->u.msg.data, 0);
    340324        }
    341        
    342325        ipc_finish_async(callid, phoneid, call, can_preempt);
    343326}
    344327
    345 /** Asynchronous call transmitting the entire payload.
     328/** Make an asynchronous call transmitting the entire payload.
    346329 *
    347330 * Note that this function is a void function.
    348  *
    349  * During normal operation, answering this call will trigger the callback.
    350  * In case of fatal error, the callback handler is called with the proper
    351  * error code. If the call cannot be temporarily made, it is queued.
     331 * During normal opertation, answering this call will trigger the callback.
     332 * In case of fatal error, call the callback handler with the proper error code.
     333 * If the call cannot be temporarily made, queue it.
    352334 *
    353335 * @param phoneid     Phone handle for the call.
     
    360342 * @param private     Argument to be passed to the answer/error callback.
    361343 * @param callback    Answer or error callback.
    362  * @param can_preempt If true, the current fibril will be preempted in
     344 * @param can_preempt If non-zero, the current fibril will be preempted in
    363345 *                    case the kernel temporarily refuses to accept more
    364346 *                    asynchronous calls.
     
    367349void ipc_call_async_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
    368350    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private,
    369     ipc_async_callback_t callback, bool can_preempt)
    370 {
    371         async_call_t *call = ipc_prepare_async(private, callback);
     351    ipc_async_callback_t callback, int can_preempt)
     352{
     353        async_call_t *call;
     354        ipc_callid_t callid;
     355
     356        call = ipc_prepare_async(private, callback);
    372357        if (!call)
    373358                return;
    374        
     359
    375360        IPC_SET_IMETHOD(call->u.msg.data, imethod);
    376361        IPC_SET_ARG1(call->u.msg.data, arg1);
     
    379364        IPC_SET_ARG4(call->u.msg.data, arg4);
    380365        IPC_SET_ARG5(call->u.msg.data, arg5);
    381        
    382366        /*
    383          * We need to make sure that we get callid
    384          * before another threadaccesses the queue again.
     367         * We need to make sure that we get callid before another thread
     368         * accesses the queue again.
    385369         */
    386        
    387370        futex_down(&ipc_futex);
    388         ipc_callid_t callid =
    389             ipc_call_async_internal(phoneid, &call->u.msg.data);
    390        
     371        callid = _ipc_call_async(phoneid, &call->u.msg.data);
     372
    391373        ipc_finish_async(callid, phoneid, call, can_preempt);
    392374}
    393375
    394 /** Answer received call (fast version).
     376
     377/** Answer a received call - fast version.
    395378 *
    396379 * The fast answer makes use of passing retval and first four arguments in
    397380 * registers. If you need to return more, use the ipc_answer_slow() instead.
    398381 *
    399  * @param callid Hash of the call being answered.
    400  * @param retval Return value.
    401  * @param arg1   First return argument.
    402  * @param arg2   Second return argument.
    403  * @param arg3   Third return argument.
    404  * @param arg4   Fourth return argument.
    405  *
    406  * @return Zero on success.
    407  * @return Value from @ref errno.h on failure.
    408  *
     382 * @param callid        Hash of the call being answered.
     383 * @param retval        Return value.
     384 * @param arg1          First return argument.
     385 * @param arg2          Second return argument.
     386 * @param arg3          Third return argument.
     387 * @param arg4          Fourth return argument.
     388 *
     389 * @return              Zero on success or a value from @ref errno.h on failure.
    409390 */
    410391sysarg_t ipc_answer_fast(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     
    415396}
    416397
    417 /** Answer received call (entire payload).
    418  *
    419  * @param callid Hash of the call being answered.
    420  * @param retval Return value.
    421  * @param arg1   First return argument.
    422  * @param arg2   Second return argument.
    423  * @param arg3   Third return argument.
    424  * @param arg4   Fourth return argument.
    425  * @param arg5   Fifth return argument.
    426  *
    427  * @return Zero on success.
    428  * @return Value from @ref errno.h on failure.
    429  *
     398/** Answer a received call - slow full version.
     399 *
     400 * @param callid        Hash of the call being answered.
     401 * @param retval        Return value.
     402 * @param arg1          First return argument.
     403 * @param arg2          Second return argument.
     404 * @param arg3          Third return argument.
     405 * @param arg4          Fourth return argument.
     406 * @param arg5          Fifth return argument.
     407 *
     408 * @return              Zero on success or a value from @ref errno.h on failure.
    430409 */
    431410sysarg_t ipc_answer_slow(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     
    433412{
    434413        ipc_call_t data;
    435        
     414
    436415        IPC_SET_RETVAL(data, retval);
    437416        IPC_SET_ARG1(data, arg1);
     
    440419        IPC_SET_ARG4(data, arg4);
    441420        IPC_SET_ARG5(data, arg5);
    442        
     421
    443422        return __SYSCALL2(SYS_IPC_ANSWER_SLOW, callid, (sysarg_t) &data);
    444423}
    445424
    446 /** Try to dispatch queued calls from the async queue.
    447  *
    448  */
    449 static void dispatch_queued_calls(void)
    450 {
     425
     426/** Try to dispatch queued calls from the async queue. */
     427static void try_dispatch_queued_calls(void)
     428{
     429        async_call_t *call;
     430        ipc_callid_t callid;
     431
    451432        /** @todo
    452          * Integrate intelligently ipc_futex so that it is locked during
    453          * ipc_call_async_*() until it is added to dispatched_calls.
     433         * Integrate intelligently ipc_futex, so that it is locked during
     434         * ipc_call_async_*(), until it is added to dispatched_calls.
    454435         */
    455        
    456436        futex_down(&async_futex);
    457        
    458437        while (!list_empty(&queued_calls)) {
    459                 async_call_t *call =
    460                     list_get_instance(queued_calls.next, async_call_t, list);
    461                 ipc_callid_t callid =
    462                     ipc_call_async_internal(call->u.msg.phoneid, &call->u.msg.data);
    463                
    464                 if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY)
     438                call = list_get_instance(queued_calls.next, async_call_t, list);
     439                callid = _ipc_call_async(call->u.msg.phoneid,
     440                    &call->u.msg.data);
     441                if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
    465442                        break;
    466                
     443                }
    467444                list_remove(&call->list);
    468                
     445
    469446                futex_up(&async_futex);
    470                
    471447                if (call->fid)
    472448                        fibril_add_ready(call->fid);
     
    475451                        if (call->callback)
    476452                                call->callback(call->private, ENOENT, NULL);
    477                        
    478453                        free(call);
    479454                } else {
    480455                        call->u.callid = callid;
    481                        
    482456                        futex_down(&ipc_futex);
    483457                        list_append(&call->list, &dispatched_calls);
    484458                        futex_up(&ipc_futex);
    485459                }
    486                
    487460                futex_down(&async_futex);
    488461        }
    489        
    490462        futex_up(&async_futex);
    491463}
    492464
    493 /** Handle received answer.
     465/** Handle a received answer.
    494466 *
    495467 * Find the hash of the answer and call the answer callback.
    496468 *
    497  * The answer has the same hash as the request OR'ed with
    498  * the IPC_CALLID_ANSWERED bit.
    499  *
    500  * @todo Use hash table.
    501  *
    502  * @param callid Hash of the received answer.
    503  * @param data   Call data of the answer.
    504  *
     469 * @todo Make it use hash table.
     470 *
     471 * @param callid        Hash of the received answer.
     472 *                      The answer has the same hash as the request OR'ed with
     473 *                      the IPC_CALLID_ANSWERED bit.
     474 * @param data          Call data of the answer.
    505475 */
    506476static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
    507477{
     478        link_t *item;
     479        async_call_t *call;
     480
    508481        callid &= ~IPC_CALLID_ANSWERED;
    509482       
    510483        futex_down(&ipc_futex);
    511        
    512         link_t *item;
    513484        for (item = dispatched_calls.next; item != &dispatched_calls;
    514485            item = item->next) {
    515                 async_call_t *call =
    516                     list_get_instance(item, async_call_t, list);
    517                
     486                call = list_get_instance(item, async_call_t, list);
    518487                if (call->u.callid == callid) {
    519488                        list_remove(&call->list);
    520                        
    521489                        futex_up(&ipc_futex);
    522                        
    523490                        if (call->callback)
    524                                 call->callback(call->private,
     491                                call->callback(call->private, 
    525492                                    IPC_GET_RETVAL(*data), data);
    526                        
    527493                        free(call);
    528494                        return;
    529495                }
    530496        }
    531        
    532497        futex_up(&ipc_futex);
    533498}
    534499
    535 /** Wait for first IPC call to come.
    536  *
    537  * @param call  Incoming call storage.
    538  * @param usec  Timeout in microseconds
    539  * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
    540  *
    541  * @return Hash of the call. Note that certain bits have special
    542  *         meaning: IPC_CALLID_ANSWERED is set in an answer
    543  *         and IPC_CALLID_NOTIFICATION is used for notifications.
    544  *
    545  */
    546 ipc_callid_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec,
    547     unsigned int flags)
    548 {
    549         ipc_callid_t callid =
    550             __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
    551        
     500
     501/** Wait for a first call to come.
     502 *
     503 * @param call          Storage where the incoming call data will be stored.
     504 * @param usec          Timeout in microseconds
     505 * @param flags         Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
     506 *
     507 * @return              Hash of the call. Note that certain bits have special
     508 *                      meaning. IPC_CALLID_ANSWERED will be set in an answer
     509 *                      and IPC_CALLID_NOTIFICATION is used for notifications.
     510 *                     
     511 */
     512ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags)
     513{
     514        ipc_callid_t callid;
     515
     516        callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
    552517        /* Handle received answers */
    553518        if (callid & IPC_CALLID_ANSWERED) {
    554519                handle_answer(callid, call);
    555                 dispatch_queued_calls();
     520                try_dispatch_queued_calls();
    556521        }
    557        
     522
    558523        return callid;
    559524}
    560525
    561 /** Interrupt one thread of this task from waiting for IPC.
    562  *
    563  */
    564 void ipc_poke(void)
    565 {
    566         __SYSCALL0(SYS_IPC_POKE);
    567 }
    568 
    569 /** Wait for first IPC call to come.
    570  *
    571  * Only requests are returned, answers are processed internally.
    572  *
    573  * @param call Incoming call storage.
    574  * @param usec Timeout in microseconds
    575  *
    576  * @return Hash of the call.
    577  *
    578  */
    579 ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)
     526/** Wait some time for an IPC call.
     527 *
     528 * The call will return after an answer is received.
     529 *
     530 * @param call          Storage where the incoming call data will be stored.
     531 * @param usec          Timeout in microseconds.
     532 *
     533 * @return              Hash of the answer.
     534 */
     535ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec)
    580536{
    581537        ipc_callid_t callid;
    582        
     538
    583539        do {
    584540                callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
    585541        } while (callid & IPC_CALLID_ANSWERED);
    586        
     542
    587543        return callid;
    588544}
     
    590546/** Check if there is an IPC call waiting to be picked up.
    591547 *
    592  * Only requests are returned, answers are processed internally.
    593  *
    594  * @param call Incoming call storage.
    595  *
    596  * @return Hash of the call.
    597  *
     548 * @param call          Storage where the incoming call will be stored.
     549 * @return              Hash of the answer.
    598550 */
    599551ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
    600552{
    601553        ipc_callid_t callid;
    602        
     554
    603555        do {
    604556                callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
    605557                    SYNCH_FLAGS_NON_BLOCKING);
    606558        } while (callid & IPC_CALLID_ANSWERED);
    607        
     559
    608560        return callid;
    609561}
    610562
    611 /** Request callback connection.
    612  *
    613  * The @a taskhash and @a phonehash identifiers returned
    614  * by the kernel can be used for connection tracking.
    615  *
    616  * @param phoneid   Phone handle used for contacting the other side.
    617  * @param arg1      User defined argument.
    618  * @param arg2      User defined argument.
    619  * @param arg3      User defined argument.
    620  * @param taskhash  Opaque identifier of the client task.
    621  * @param phonehash Opaque identifier of the phone that will
    622  *                  be used for incoming calls.
    623  *
    624  * @return Zero on success or a negative error code.
    625  *
    626  */
    627 int ipc_connect_to_me(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
     563/** Interrupt one thread of this task from waiting for IPC. */
     564void ipc_poke(void)
     565{
     566        __SYSCALL0(SYS_IPC_POKE);
     567}
     568
     569/** Ask destination to do a callback connection.
     570 *
     571 * @param phoneid       Phone handle used for contacting the other side.
     572 * @param arg1          Service-defined argument.
     573 * @param arg2          Service-defined argument.
     574 * @param arg3          Service-defined argument.
     575 * @param taskhash      Storage where the kernel will store an opaque
     576 *                      identifier of the client task.
     577 * @param phonehash     Storage where the kernel will store an opaque
     578 *                      identifier of the phone that will be used for incoming
     579 *                      calls. This identifier can be used for connection
     580 *                      tracking.
     581 *
     582 * @return              Zero on success or a negative error code.
     583 */
     584int ipc_connect_to_me(int phoneid, int arg1, int arg2, int arg3,
    628585    sysarg_t *taskhash, sysarg_t *phonehash)
    629586{
     
    632589}
    633590
    634 /** Request new connection.
    635  *
    636  * @param phoneid Phone handle used for contacting the other side.
    637  * @param arg1    User defined argument.
    638  * @param arg2    User defined argument.
    639  * @param arg3    User defined argument.
    640  *
    641  * @return New phone handle on success or a negative error code.
    642  *
    643  */
    644 int ipc_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
     591/** Ask through phone for a new connection to some service.
     592 *
     593 * @param phoneid       Phone handle used for contacting the other side.
     594 * @param arg1          User defined argument.
     595 * @param arg2          User defined argument.
     596 * @param arg3          User defined argument.
     597 *
     598 * @return              New phone handle on success or a negative error code.
     599 */
     600int ipc_connect_me_to(int phoneid, int arg1, int arg2, int arg3)
    645601{
    646602        sysarg_t newphid;
    647         int res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     603        int res;
     604
     605        res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
    648606            NULL, NULL, NULL, NULL, &newphid);
    649607        if (res)
    650608                return res;
    651        
    652609        return newphid;
    653610}
    654611
    655 /** Request new connection (blocking)
     612/** Ask through phone for a new connection to some service.
    656613 *
    657614 * If the connection is not available at the moment, the
    658  * call should block. This has to be, however, implemented
    659  * on the server side.
    660  *
    661  * @param phoneid Phone handle used for contacting the other side.
    662  * @param arg1    User defined argument.
    663  * @param arg2    User defined argument.
    664  * @param arg3    User defined argument.
    665  *
    666  * @return New phone handle on success or a negative error code.
    667  *
    668  */
    669 int ipc_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
    670     sysarg_t arg3)
     615 * call will block.
     616 *
     617 * @param phoneid       Phone handle used for contacting the other side.
     618 * @param arg1          User defined argument.
     619 * @param arg2          User defined argument.
     620 * @param arg3          User defined argument.
     621 *
     622 * @return              New phone handle on success or a negative error code.
     623 */
     624int ipc_connect_me_to_blocking(int phoneid, int arg1, int arg2, int arg3)
    671625{
    672626        sysarg_t newphid;
    673         int res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     627        int res;
     628
     629        res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
    674630            IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
    675631        if (res)
    676632                return res;
    677        
    678633        return newphid;
    679634}
     
    681636/** Hang up a phone.
    682637 *
    683  * @param phoneid Handle of the phone to be hung up.
    684  *
    685  * @return Zero on success or a negative error code.
    686  *
     638 * @param phoneid       Handle of the phone to be hung up.
     639 *
     640 * @return              Zero on success or a negative error code.
    687641 */
    688642int ipc_hangup(int phoneid)
     
    692646
    693647/** Forward a received call to another destination.
    694  *
    695  * For non-system methods, the old method, arg1 and arg2 are rewritten
    696  * by the new values. For system methods, the new method, arg1 and arg2
    697  * are written to the old arg1, arg2 and arg3, respectivelly. Calls with
    698  * immutable methods are forwarded verbatim.
    699648 *
    700649 * @param callid  Hash of the call to forward.
     
    707656 * @return Zero on success or an error code.
    708657 *
    709  */
    710 int ipc_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
    711     sysarg_t arg1, sysarg_t arg2, unsigned int mode)
     658 * For non-system methods, the old method, arg1 and arg2 are rewritten by the
     659 * new values. For system methods, the new method, arg1 and arg2 are written
     660 * to the old arg1, arg2 and arg3, respectivelly. Calls with immutable
     661 * methods are forwarded verbatim.
     662 */
     663int ipc_forward_fast(ipc_callid_t callid, int phoneid, int imethod,
     664    sysarg_t arg1, sysarg_t arg2, int mode)
    712665{
    713666        return __SYSCALL6(SYS_IPC_FORWARD_FAST, callid, phoneid, imethod, arg1,
     
    715668}
    716669
    717 int ipc_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
     670
     671int ipc_forward_slow(ipc_callid_t callid, int phoneid, int imethod,
    718672    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
    719     unsigned int mode)
     673    int mode)
    720674{
    721675        ipc_call_t data;
     
    728682        IPC_SET_ARG5(data, arg5);
    729683       
    730         return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data,
    731             mode);
    732 }
    733 
    734 /** Wrapper for IPC_M_SHARE_IN calls.
    735  *
    736  * @param phoneid Phone that will be used to contact the receiving side.
    737  * @param dst     Destination address space area base.
    738  * @param size    Size of the destination address space area.
    739  * @param arg     User defined argument.
    740  * @param flags   Storage for received flags. Can be NULL.
    741  *
    742  * @return Zero on success or a negative error code from errno.h.
    743  *
     684        return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data, mode);
     685}
     686
     687/** Wrapper for making IPC_M_SHARE_IN calls.
     688 *
     689 * @param phoneid       Phone that will be used to contact the receiving side.
     690 * @param dst           Destination address space area base.
     691 * @param size          Size of the destination address space area.
     692 * @param arg           User defined argument.
     693 * @param flags         Storage where the received flags will be stored. Can be
     694 *                      NULL.
     695 *
     696 * @return              Zero on success or a negative error code from errno.h.
    744697 */
    745698int ipc_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
    746     unsigned int *flags)
     699    int *flags)
    747700{
    748701        sysarg_t tmp_flags = 0;
     
    751704       
    752705        if (flags)
    753                 *flags = (unsigned int) tmp_flags;
     706                *flags = tmp_flags;
    754707       
    755708        return res;
     
    758711/** Wrapper for answering the IPC_M_SHARE_IN calls.
    759712 *
    760  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
    761  * calls so that the user doesn't have to remember the meaning of each
    762  * IPC argument.
    763  *
    764  * @param callid Hash of the IPC_M_DATA_READ call to answer.
    765  * @param src    Source address space base.
    766  * @param flags Flags to be used for sharing. Bits can be only cleared.
    767  *
    768  * @return Zero on success or a value from @ref errno.h on failure.
    769  *
    770  */
    771 int ipc_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
     713 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
     714 * so that the user doesn't have to remember the meaning of each IPC argument.
     715 *
     716 * @param callid        Hash of the IPC_M_DATA_READ call to answer.
     717 * @param src           Source address space base.
     718 * @param flags         Flags to be used for sharing. Bits can be only cleared.
     719 *
     720 * @return              Zero on success or a value from @ref errno.h on failure.
     721 */
     722int ipc_share_in_finalize(ipc_callid_t callid, void *src, int flags)
    772723{
    773724        return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) flags);
    774725}
    775726
    776 /** Wrapper for IPC_M_SHARE_OUT calls.
    777  *
    778  * @param phoneid Phone that will be used to contact the receiving side.
    779  * @param src     Source address space area base address.
    780  * @param flags   Flags to be used for sharing. Bits can be only cleared.
    781  *
    782  * @return Zero on success or a negative error code from errno.h.
    783  *
    784  */
    785 int ipc_share_out_start(int phoneid, void *src, unsigned int flags)
     727/** Wrapper for making IPC_M_SHARE_OUT calls.
     728 *
     729 * @param phoneid       Phone that will be used to contact the receiving side.
     730 * @param src           Source address space area base address.
     731 * @param flags         Flags to be used for sharing. Bits can be only cleared.
     732 *
     733 * @return              Zero on success or a negative error code from errno.h.
     734 */
     735int ipc_share_out_start(int phoneid, void *src, int flags)
    786736{
    787737        return ipc_call_sync_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
     
    791741/** Wrapper for answering the IPC_M_SHARE_OUT calls.
    792742 *
    793  * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT
    794  * calls so that the user doesn't have to remember the meaning of each
    795  * IPC argument.
    796  *
    797  * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
    798  * @param dst    Destination address space area base address.
    799  *
    800  * @return Zero on success or a value from @ref errno.h on failure.
    801  *
     743 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls
     744 * so that the user doesn't have to remember the meaning of each IPC argument.
     745 *
     746 * @param callid        Hash of the IPC_M_DATA_WRITE call to answer.
     747 * @param dst           Destination address space area base address.   
     748 *
     749 * @return              Zero on success or a value from @ref errno.h on failure.
    802750 */
    803751int ipc_share_out_finalize(ipc_callid_t callid, void *dst)
     
    806754}
    807755
    808 /** Wrapper for IPC_M_DATA_READ calls.
    809  *
    810  * @param phoneid Phone that will be used to contact the receiving side.
    811  * @param dst     Address of the beginning of the destination buffer.
    812  * @param size    Size of the destination buffer.
    813  *
    814  * @return Zero on success or a negative error code from errno.h.
    815  *
     756
     757/** Wrapper for making IPC_M_DATA_READ calls.
     758 *
     759 * @param phoneid       Phone that will be used to contact the receiving side.
     760 * @param dst           Address of the beginning of the destination buffer.
     761 * @param size          Size of the destination buffer.
     762 *
     763 * @return              Zero on success or a negative error code from errno.h.
    816764 */
    817765int ipc_data_read_start(int phoneid, void *dst, size_t size)
     
    823771/** Wrapper for answering the IPC_M_DATA_READ calls.
    824772 *
    825  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
    826  * calls so that the user doesn't have to remember the meaning of each
    827  * IPC argument.
    828  *
    829  * @param callid Hash of the IPC_M_DATA_READ call to answer.
    830  * @param src    Source address for the IPC_M_DATA_READ call.
    831  * @param size   Size for the IPC_M_DATA_READ call. Can be smaller than
    832  *               the maximum size announced by the sender.
    833  *
    834  * @return Zero on success or a value from @ref errno.h on failure.
    835  *
     773 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
     774 * so that the user doesn't have to remember the meaning of each IPC argument.
     775 *
     776 * @param callid        Hash of the IPC_M_DATA_READ call to answer.
     777 * @param src           Source address for the IPC_M_DATA_READ call.
     778 * @param size          Size for the IPC_M_DATA_READ call. Can be smaller than
     779 *                      the maximum size announced by the sender.
     780 *
     781 * @return              Zero on success or a value from @ref errno.h on failure.
    836782 */
    837783int ipc_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
     
    840786}
    841787
    842 /** Wrapper for IPC_M_DATA_WRITE calls.
    843  *
    844  * @param phoneid Phone that will be used to contact the receiving side.
    845  * @param src     Address of the beginning of the source buffer.
    846  * @param size    Size of the source buffer.
    847  *
    848  * @return Zero on success or a negative error code from errno.h.
    849  *
     788/** Wrapper for making IPC_M_DATA_WRITE calls.
     789 *
     790 * @param phoneid       Phone that will be used to contact the receiving side.
     791 * @param src           Address of the beginning of the source buffer.
     792 * @param size          Size of the source buffer.
     793 *
     794 * @return              Zero on success or a negative error code from errno.h.
    850795 */
    851796int ipc_data_write_start(int phoneid, const void *src, size_t size)
     
    857802/** Wrapper for answering the IPC_M_DATA_WRITE calls.
    858803 *
    859  * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE
    860  * calls so that the user doesn't have to remember the meaning of each
    861  * IPC argument.
    862  *
    863  * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
    864  * @param dst    Final destination address for the IPC_M_DATA_WRITE call.
    865  * @param size   Final size for the IPC_M_DATA_WRITE call.
    866  *
    867  * @return Zero on success or a value from @ref errno.h on failure.
    868  *
     804 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls
     805 * so that the user doesn't have to remember the meaning of each IPC argument.
     806 *
     807 * @param callid        Hash of the IPC_M_DATA_WRITE call to answer.
     808 * @param dst           Final destination address for the IPC_M_DATA_WRITE call.
     809 * @param size          Final size for the IPC_M_DATA_WRITE call.
     810 *
     811 * @return              Zero on success or a value from @ref errno.h on failure.
    869812 */
    870813int ipc_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
  • uspace/lib/c/generic/libc.c

    r197ef43 r6aef742  
    4141 */
    4242
    43 #include <libc.h>
    44 #include <stdlib.h>
     43#include <stdio.h>
     44#include <unistd.h>
     45#include <malloc.h>
    4546#include <tls.h>
     47#include <thread.h>
    4648#include <fibril.h>
    47 #include <task.h>
     49#include <async.h>
     50#include <as.h>
    4851#include <loader/pcb.h>
    4952#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"
    5453
    55 static bool env_setup = false;
     54void _exit(int status)
     55{
     56        thread_exit(status);
     57}
    5658
    5759void __main(void *pcb_ptr)
    5860{
    5961        /* Initialize user task run-time environment */
    60         __malloc_init();
     62        __heap_init();
    6163        __async_init();
    62         __async_sess_init();
    63        
    6464        fibril_t *fibril = fibril_setup();
    65         if (fibril == NULL)
    66                 abort();
    67        
    6865        __tcb_set(fibril->tcb);
    6966       
     
    7168        __pcb = (pcb_t *) pcb_ptr;
    7269       
    73         /* The basic run-time environment is setup */
    74         env_setup = true;
    75        
    7670        int argc;
    7771        char **argv;
    7872       
    79         /*
    80          * Get command line arguments and initialize
    81          * standard input and output
    82          */
     73        /* Get command line arguments and initialize
     74           standard input and output */
    8375        if (__pcb == NULL) {
    8476                argc = 0;
     
    9284        }
    9385       
    94         /*
    95          * Run main() and set task return value
    96          * according the result
    97          */
    98         int retval = main(argc, argv);
    99         exit(retval);
     86        /* Run main() and set task return value
     87           according the result */
     88        (void) task_retval(main(argc, argv));
    10089}
    10190
    102 void exit(int status)
     91void __exit(void)
    10392{
    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 
    116 void abort(void)
    117 {
    118         __SYSCALL1(SYS_TASK_EXIT, true);
    119        
    120         /* Unreachable */
    121         while (1);
     93        __stdio_done();
     94        fibril_teardown(__tcb_get()->fibril_data);
     95        _exit(0);
    12296}
    12397
  • uspace/lib/c/generic/malloc.c

    r197ef43 r6aef742  
    4545#include <futex.h>
    4646#include <adt/gcdlcm.h>
    47 #include "private/malloc.h"
    4847
    4948/* Magic used in heap headers. */
     
    216215/** Initialize the heap allocator
    217216 *
    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  */
    223 void __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);
     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 */
     222void __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);
    236238}
    237239
  • uspace/lib/c/generic/private/async.h

    r197ef43 r6aef742  
    7979} awaiter_t;
    8080
    81 extern void __async_init(void);
    8281extern void async_insert_timeout(awaiter_t *);
    8382
  • uspace/lib/c/generic/private/libc.h

    r197ef43 r6aef742  
    3737
    3838extern int main(int, char *[]);
    39 extern void __main(void *) __attribute__((noreturn));
     39extern void __main(void *);
     40extern void __exit(void);
    4041
    4142#endif
  • uspace/lib/c/generic/thread.c

    r197ef43 r6aef742  
    3131 */
    3232/** @file
    33  */
     33 */ 
    3434
    3535#include <thread.h>
     
    4141#include <str.h>
    4242#include <async.h>
    43 #include "private/thread.h"
    4443
    4544#ifndef THREAD_INITIAL_STACK_PAGES_NO
     
    5150 * This function is called from __thread_entry() and is used
    5251 * to call the thread's implementing function and perform cleanup
    53  * and exit when thread returns back.
     52 * and exit when thread returns back. Do not call this function
     53 * directly.
    5454 *
    5555 * @param uarg Pointer to userspace argument structure.
    56  *
    5756 */
    5857void __thread_main(uspace_arg_t *uarg)
    5958{
    60         fibril_t *fibril = fibril_setup();
    61         if (fibril == NULL)
    62                 thread_exit(0);
    63        
    64         __tcb_set(fibril->tcb);
    65        
     59        fibril_t *f;
     60
     61        f = fibril_setup();
     62        __tcb_set(f->tcb);
     63
    6664        uarg->uspace_thread_function(uarg->uspace_thread_arg);
    67         /* XXX: we cannot free the userspace stack while running on it
    68                 free(uarg->uspace_stack);
    69                 free(uarg);
    70         */
    71        
     65        /* XXX: we cannot free the userspace stack while running on it */
     66//      free(uarg->uspace_stack);
     67//      free(uarg);
     68
    7269        /* If there is a manager, destroy it */
    7370        async_destroy_manager();
    74         fibril_teardown(fibril);
    75        
     71        fibril_teardown(f);
     72
    7673        thread_exit(0);
    7774}
     
    130127 *
    131128 * @param status Exit status. Currently not used.
    132  *
    133129 */
    134130void thread_exit(int status)
    135131{
    136132        __SYSCALL1(SYS_THREAD_EXIT, (sysarg_t) status);
    137        
    138         /* Unreachable */
    139         while (1);
     133        for (;;)
     134                ;
    140135}
    141136
  • uspace/lib/c/include/async.h

    r197ef43 r6aef742  
    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 
     59extern int __async_init(void);
    6560extern ipc_callid_t async_get_call_timeout(ipc_call_t *, suseconds_t);
     61
     62static inline ipc_callid_t async_get_call(ipc_call_t *data)
     63{
     64        return async_get_call_timeout(data, 0);
     65}
     66
     67static inline void async_manager(void)
     68{
     69        fibril_switch(FIBRIL_TO_MANAGER);
     70}
    6671
    6772/*
     
    138143 */
    139144
    140 extern int async_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
    141     unsigned int);
    142 extern int async_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
    143     sysarg_t, sysarg_t, sysarg_t, unsigned int);
     145extern int async_forward_fast(ipc_callid_t, int, int, sysarg_t, sysarg_t, int);
     146extern int async_forward_slow(ipc_callid_t, int, int, sysarg_t, sysarg_t,
     147    sysarg_t, sysarg_t, sysarg_t, int);
    144148
    145149/*
     
    302306        async_share_in_start((phoneid), (dst), (size), (arg), (flags))
    303307
    304 extern int async_share_in_start(int, void *, size_t, sysarg_t, unsigned int *);
    305 extern bool async_share_in_receive(ipc_callid_t *, size_t *);
    306 extern int async_share_in_finalize(ipc_callid_t, void *, unsigned int);
    307 
    308 extern int async_share_out_start(int, void *, unsigned int);
    309 extern bool async_share_out_receive(ipc_callid_t *, size_t *, unsigned int *);
     308extern int async_share_in_start(int, void *, size_t, sysarg_t, int *);
     309extern int async_share_in_receive(ipc_callid_t *, size_t *);
     310extern int async_share_in_finalize(ipc_callid_t, void *, int );
     311extern int async_share_out_start(int, void *, int);
     312extern int async_share_out_receive(ipc_callid_t *, size_t *, int *);
    310313extern int async_share_out_finalize(ipc_callid_t, void *);
    311314
     
    341344
    342345extern int async_data_read_start(int, void *, size_t);
    343 extern bool async_data_read_receive(ipc_callid_t *, size_t *);
     346extern int async_data_read_receive(ipc_callid_t *, size_t *);
    344347extern int async_data_read_finalize(ipc_callid_t, const void *, size_t);
    345348
     
    380383
    381384extern int async_data_write_start(int, const void *, size_t);
    382 extern bool async_data_write_receive(ipc_callid_t *, size_t *);
     385extern int async_data_write_receive(ipc_callid_t *, size_t *);
    383386extern int async_data_write_finalize(ipc_callid_t, void *, size_t);
    384387
    385388extern int async_data_write_accept(void **, const bool, const size_t,
    386389    const size_t, const size_t, size_t *);
    387 extern void async_data_write_void(sysarg_t);
     390extern void async_data_write_void(const int);
    388391
    389392extern int async_data_write_forward_fast(int, sysarg_t, sysarg_t, sysarg_t,
  • uspace/lib/c/include/async_sess.h

    r197ef43 r6aef742  
    4545} async_sess_t;
    4646
     47extern void _async_sess_init(void);
    4748extern void async_session_create(async_sess_t *, int, sysarg_t);
    4849extern void async_session_destroy(async_sess_t *);
  • uspace/lib/c/include/byteorder.h

    r197ef43 r6aef742  
    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

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

    r197ef43 r6aef742  
    3939#include <fibril.h>
    4040
     41extern int _errno;
     42
    4143#define errno _errno
    42 
    43 extern int _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 #define NO_DATA (-11004)
     88/** No data.
     89 */
     90#define NO_DATA         (-11004)
    9091
    9192#endif
  • uspace/lib/c/include/ipc/ipc.h

    r197ef43 r6aef742  
    5353 * possible, the fast version is used.
    5454 */
    55 
    5655#define ipc_call_sync_0_0(phoneid, method) \
    5756        ipc_call_sync_fast((phoneid), (method), 0, 0, 0, 0, 0, 0, 0, 0)
     
    183182    sysarg_t *);
    184183
    185 extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, sysarg_t, unsigned int);
     184extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, uint32_t, int);
     185extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, uint32_t);
    186186extern void ipc_poke(void);
    187187
    188 #define ipc_wait_for_call(data) \
    189         ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
    190 
    191 extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, sysarg_t);
     188static inline ipc_callid_t ipc_wait_for_call(ipc_call_t *data)
     189{
     190        return ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
     191}
     192
    192193extern ipc_callid_t ipc_trywait_for_call(ipc_call_t *);
    193194
     
    198199 * to m.
    199200 */
    200 
    201201#define ipc_answer_0(callid, retval) \
    202202        ipc_answer_fast((callid), (retval), 0, 0, 0, 0)
     
    223223 * to m.
    224224 */
    225 
    226225#define ipc_call_async_0(phoneid, method, private, callback, can_preempt) \
    227226        ipc_call_async_fast((phoneid), (method), 0, 0, 0, 0, (private), \
     
    249248
    250249extern void ipc_call_async_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    251     sysarg_t, void *, ipc_async_callback_t, bool);
     250    sysarg_t, void *, ipc_async_callback_t, int);
    252251extern void ipc_call_async_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
    253     sysarg_t, sysarg_t, void *, ipc_async_callback_t, bool);
    254 
    255 extern int ipc_connect_to_me(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t *,
    256     sysarg_t *);
    257 extern int ipc_connect_me_to(int, sysarg_t, sysarg_t, sysarg_t);
    258 extern int ipc_connect_me_to_blocking(int, sysarg_t, sysarg_t, sysarg_t);
    259 
     252    sysarg_t, sysarg_t, void *, ipc_async_callback_t, int);
     253
     254extern int ipc_connect_to_me(int, int, int, int, sysarg_t *, sysarg_t *);
     255extern int ipc_connect_me_to(int, int, int, int);
     256extern int ipc_connect_me_to_blocking(int, int, int, int);
    260257extern int ipc_hangup(int);
    261 
    262 extern int ipc_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
    263     unsigned int);
    264 extern int ipc_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
    265     sysarg_t, sysarg_t, sysarg_t, unsigned int);
     258extern int ipc_forward_fast(ipc_callid_t, int, int, sysarg_t, sysarg_t, int);
     259extern int ipc_forward_slow(ipc_callid_t, int, int, sysarg_t, sysarg_t,
     260    sysarg_t, sysarg_t, sysarg_t, int);
    266261
    267262/*
    268263 * User-friendly wrappers for ipc_share_in_start().
    269264 */
    270 
    271265#define ipc_share_in_start_0_0(phoneid, dst, size) \
    272266        ipc_share_in_start((phoneid), (dst), (size), 0, NULL)
     
    278272        ipc_share_in_start((phoneid), (dst), (size), (arg), (flags))
    279273
    280 extern int ipc_share_in_start(int, void *, size_t, sysarg_t, unsigned int *);
    281 extern int ipc_share_in_finalize(ipc_callid_t, void *, unsigned int);
    282 extern int ipc_share_out_start(int, void *, unsigned int);
     274extern int ipc_share_in_start(int, void *, size_t, sysarg_t, int *);
     275extern int ipc_share_in_finalize(ipc_callid_t, void *, int );
     276extern int ipc_share_out_start(int, void *, int);
    283277extern int ipc_share_out_finalize(ipc_callid_t, void *);
    284278extern int ipc_data_read_start(int, void *, size_t);
  • uspace/lib/c/include/loader/pcb.h

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

    r197ef43 r6aef742  
    3838#include <sys/types.h>
    3939
     40extern void __heap_init(void);
    4041extern uintptr_t get_max_heap_addr(void);
    4142
  • uspace/lib/c/include/setjmp.h

    r197ef43 r6aef742  
    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

    r197ef43 r6aef742  
    4040#include <stacktrace.h>
    4141
     42#define abort() \
     43        do { \
     44                stacktrace_print(); \
     45                _exit(1); \
     46        } while (0)
     47
     48#define core() \
     49        *((int *) 0) = 0xbadbad;
     50
     51#define exit(status)  _exit((status))
     52
    4253#define RAND_MAX  714025
    43 
    44 #define rand()       random()
    45 #define srand(seed)  srandom(seed)
    4654
    4755extern long int random(void);
    4856extern void srandom(unsigned int seed);
    4957
    50 extern void abort(void) __attribute__((noreturn));
     58static inline int rand(void)
     59{
     60        return random();
     61}
     62
     63static inline void srand(unsigned int seed)
     64{
     65        srandom(seed);
     66}
    5167
    5268#endif
  • uspace/lib/c/include/syscall.h

    r197ef43 r6aef742  
    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 cannot include this file directly
     42#ifndef LIBARCH_SYSCALL_GENERIC
     43#error "You can't 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

    r197ef43 r6aef742  
    3636#define LIBC_THREAD_H_
    3737
     38#include <kernel/proc/uarg.h>
    3839#include <libarch/thread.h>
    3940#include <sys/types.h>
     
    4142typedef uint64_t thread_id_t;
    4243
     44extern void __thread_entry(void);
     45extern void __thread_main(uspace_arg_t *);
     46
    4347extern int thread_create(void (*)(void *), void *, const char *, thread_id_t *);
    44 extern void thread_exit(int) __attribute__((noreturn));
     48extern void thread_exit(int) __attribute__ ((noreturn));
    4549extern void thread_detach(thread_id_t);
    4650extern int thread_join(thread_id_t);
  • uspace/lib/c/include/tls.h

    r197ef43 r6aef742  
    5757extern void tls_free_variant_1(tcb_t *, size_t);
    5858#endif
    59 
    6059#ifdef CONFIG_TLS_VARIANT_2
    6160extern tcb_t *tls_alloc_variant_2(void **, size_t);
  • uspace/lib/c/include/unistd.h

    r197ef43 r6aef742  
    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

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

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

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

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

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

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

    r197ef43 r6aef742  
    102102         * Now we wait for the client to send us its communication as_area.
    103103         */
    104         unsigned int flags;
     104        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.