Changeset 8ff0bd2 in mainline for uspace/lib/c/generic


Ignore:
Timestamp:
2011-09-04T11:30:58Z (15 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
03bc76a
Parents:
d2c67e7 (diff), deac215e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

Location:
uspace/lib/c/generic
Files:
1 added
4 deleted
36 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/adt/hash_table.c

    rd2c67e7 r8ff0bd2  
    6161        assert(max_keys > 0);
    6262       
    63         h->entry = malloc(m * sizeof(link_t));
     63        h->entry = malloc(m * sizeof(list_t));
    6464        if (!h->entry)
    6565                return false;
    6666       
    67         memset((void *) h->entry, 0,  m * sizeof(link_t));
     67        memset((void *) h->entry, 0,  m * sizeof(list_t));
    6868       
    6969        hash_count_t i;
     
    123123        assert(chain < h->entries);
    124124       
    125         link_t *cur;
    126         for (cur = h->entry[chain].next; cur != &h->entry[chain];
    127             cur = cur->next) {
     125        list_foreach(h->entry[chain], cur) {
    128126                if (h->op->compare(key, h->max_keys, cur)) {
    129127                        /*
     
    153151        assert(keys <= h->max_keys);
    154152       
    155         link_t *cur;
    156        
    157153        if (keys == h->max_keys) {
     154                link_t *cur;
     155               
    158156                /*
    159157                 * All keys are known, hash_table_find() can be used to find the
     
    176174        hash_index_t chain;
    177175        for (chain = 0; chain < h->entries; chain++) {
    178                 for (cur = h->entry[chain].next; cur != &h->entry[chain];
     176                link_t *cur;
     177               
     178                for (cur = h->entry[chain].head.next; cur != &h->entry[chain].head;
    179179                    cur = cur->next) {
    180180                        if (h->op->compare(key, keys, cur)) {
     
    203203{
    204204        hash_index_t bucket;
    205         link_t *cur;
    206205       
    207206        for (bucket = 0; bucket < h->entries; bucket++) {
    208                 for (cur = h->entry[bucket].next; cur != &h->entry[bucket];
    209                     cur = cur->next) {
     207                list_foreach(h->entry[bucket], cur) {
    210208                        f(cur, arg);
    211209                }
  • uspace/lib/c/generic/adt/list.c

    rd2c67e7 r8ff0bd2  
    3030 * @{
    3131 */
    32 /** @file
     32
     33/**
     34 * @file
     35 * @brief       Functions completing doubly linked circular list implementaion.
     36 *
     37 * This file contains some of the functions implementing doubly linked circular lists.
     38 * However, this ADT is mostly implemented in @ref list.h.
    3339 */
    3440
    3541#include <adt/list.h>
    36 
     42#include <bool.h>
    3743
    3844/** Check for membership
    3945 *
    40  * Check whether link is contained in the list head.
    41  * The membership is defined as pointer equivalence.
     46 * Check whether link is contained in a list.
     47 * Membership is defined as pointer equivalence.
    4248 *
    43  * @param link Item to look for.
    44  * @param head List to look in.
     49 * @param link  Item to look for.
     50 * @param list  List to look in.
    4551 *
    4652 * @return true if link is contained in head, false otherwise.
    4753 *
    4854 */
    49 int list_member(const link_t *link, const link_t *head)
     55int list_member(const link_t *link, const list_t *list)
    5056{
    51         int found = 0;
    52         link_t *hlp = head->next;
     57        bool found = false;
     58        link_t *hlp = list->head.next;
    5359       
    54         while (hlp != head) {
     60        while (hlp != &list->head) {
    5561                if (hlp == link) {
    56                         found = 1;
     62                        found = true;
    5763                        break;
    5864                }
     
    6369}
    6470
    65 
    6671/** Concatenate two lists
    6772 *
    68  * Concatenate lists head1 and head2, producing a single
    69  * list head1 containing items from both (in head1, head2
    70  * order) and empty list head2.
     73 * Concatenate lists @a list1 and @a list2, producing a single
     74 * list @a list1 containing items from both (in @a list1, @a list2
     75 * order) and empty list @a list2.
    7176 *
    72  * @param head1 First list and concatenated output
    73  * @param head2 Second list and empty output.
     77 * @param list1         First list and concatenated output
     78 * @param list2         Second list and empty output.
    7479 *
    7580 */
    76 void list_concat(link_t *head1, link_t *head2)
     81void list_concat(list_t *list1, list_t *list2)
    7782{
    78         if (list_empty(head2))
     83        if (list_empty(list2))
    7984                return;
    80        
    81         head2->next->prev = head1->prev;
    82         head2->prev->next = head1;
    83         head1->prev->next = head2->next;
    84         head1->prev = head2->prev;
    85         list_initialize(head2);
     85
     86        list2->head.next->prev = list1->head.prev;
     87        list2->head.prev->next = &list1->head;
     88        list1->head.prev->next = list2->head.next;
     89        list1->head.prev = list2->head.prev;
     90        list_initialize(list2);
    8691}
    87 
    8892
    8993/** Count list items
     
    9195 * Return the number of items in the list.
    9296 *
    93  * @param link List to count.
    94  *
    95  * @return Number of items in the list.
    96  *
     97 * @param list          List to count.
     98 * @return              Number of items in the list.
    9799 */
    98 unsigned int list_count(const link_t *link)
     100unsigned int list_count(const list_t *list)
    99101{
    100102        unsigned int count = 0;
    101         link_t *hlp = link->next;
    102103       
    103         while (hlp != link) {
     104        list_foreach(*list, link) {
    104105                count++;
    105                 hlp = hlp->next;
    106106        }
    107107       
  • uspace/lib/c/generic/adt/measured_strings.c

    rd2c67e7 r8ff0bd2  
    4242#include <errno.h>
    4343#include <async.h>
    44 #include <async_obsolete.h>
    4544
    4645/** Creates a new measured string bundled with a copy of the given string
     
    298297 * size has to be negotiated in advance.
    299298 *
    300  * @param[in] phone     The other module phone.
     299 * @param[in] exch      Exchange.
    301300 * @param[out] strings  The returned measured strings array.
    302301 * @param[out] data     The measured strings data. This memory block stores the
     
    305304 * @return              EOK on success.
    306305 * @return              EINVAL if the strings or data parameter is NULL.
    307  * @return              EINVAL if the phone or count parameter is not positive.
     306 * @return              EINVAL if the exch or count parameter is invalid.
    308307 * @return              EINVAL if the sent array differs in size.
    309308 * @return              ENOMEM if there is not enough memory left.
     
    311310 *                      async_data_read_start() function.
    312311 */
    313 int
    314 measured_strings_return(int phone, measured_string_t **strings, uint8_t **data,
    315     size_t count)
     312int measured_strings_return(async_exch_t *exch, measured_string_t **strings,
     313    uint8_t **data, size_t count)
    316314{
    317315        size_t *lengths;
     
    320318        int rc;
    321319
    322         if ((phone < 0) || (!strings) || (!data) || (count <= 0))
     320        if ((exch == NULL) || (!strings) || (!data) || (count <= 0))
    323321                return EINVAL;
    324322
     
    327325                return ENOMEM;
    328326
    329         rc = async_obsolete_data_read_start(phone, lengths,
     327        rc = async_data_read_start(exch, lengths,
    330328            sizeof(size_t) * (count + 1));
    331329        if (rc != EOK) {
     
    352350                (*strings)[index].length = lengths[index];
    353351                if (lengths[index] > 0) {
    354                         rc = async_obsolete_data_read_start(phone, next, lengths[index]);
     352                        rc = async_data_read_start(exch, next, lengths[index]);
    355353                        if (rc != EOK) {
    356354                                free(lengths);
     
    376374 * size has to be negotiated in advance.
    377375 *
    378  * @param[in] phone     The other module phone.
     376 * @param[in] exch      Exchange.
    379377 * @param[in] strings   The measured strings array to be transferred.
    380378 * @param[in] count     The measured strings array size.
    381379 * @return              EOK on success.
    382380 * @return              EINVAL if the strings parameter is NULL.
    383  * @return              EINVAL if the phone or count parameter is not positive.
     381 * @return              EINVAL if the exch or count parameter is invalid.
    384382 * @return              Other error codes as defined for the
    385383 *                      async_data_write_start() function.
    386384 */
    387 int
    388 measured_strings_send(int phone, const measured_string_t *strings,
     385int measured_strings_send(async_exch_t *exch, const measured_string_t *strings,
    389386    size_t count)
    390387{
     
    393390        int rc;
    394391
    395         if ((phone < 0) || (!strings) || (count <= 0))
     392        if ((exch == NULL) || (!strings) || (count <= 0))
    396393                return EINVAL;
    397394
     
    400397                return ENOMEM;
    401398
    402         rc = async_obsolete_data_write_start(phone, lengths,
     399        rc = async_data_write_start(exch, lengths,
    403400            sizeof(size_t) * (count + 1));
    404401        if (rc != EOK) {
     
    411408        for (index = 0; index < count; index++) {
    412409                if (strings[index].length > 0) {
    413                         rc = async_obsolete_data_write_start(phone, strings[index].value,
     410                        rc = async_data_write_start(exch, strings[index].value,
    414411                            strings[index].length);
    415412                        if (rc != EOK)
     
    423420/** @}
    424421 */
    425 
  • uspace/lib/c/generic/adt/prodcons.c

    rd2c67e7 r8ff0bd2  
    6161                fibril_condvar_wait(&pc->cv, &pc->mtx);
    6262       
    63         link_t *head = pc->list.next;
     63        link_t *head = list_first(&pc->list);
    6464        list_remove(head);
    6565       
  • uspace/lib/c/generic/async.c

    rd2c67e7 r8ff0bd2  
    9898#include <ipc/ipc.h>
    9999#include <async.h>
     100#include "private/async.h"
    100101#undef LIBC_ASYNC_C_
    101102
     
    107108#include <errno.h>
    108109#include <sys/time.h>
    109 #include <arch/barrier.h>
     110#include <libarch/barrier.h>
    110111#include <bool.h>
    111112#include <malloc.h>
    112113#include <mem.h>
    113114#include <stdlib.h>
    114 #include "private/async.h"
     115#include <macros.h>
    115116
    116117#define CLIENT_HASH_TABLE_BUCKETS  32
     
    138139        link_t link;
    139140       
    140         sysarg_t in_task_hash;
     141        task_id_t in_task_id;
    141142        atomic_t refcnt;
    142143        void *data;
     
    150151        link_t link;
    151152       
    152         /** Incoming client task hash. */
    153         sysarg_t in_task_hash;
     153        /** Incoming client task ID. */
     154        task_id_t in_task_id;
    154155       
    155156        /** Incoming phone hash. */
     
    160161       
    161162        /** Messages that should be delivered to this fibril. */
    162         link_t msg_queue;
     163        list_t msg_queue;
    163164       
    164165        /** Identification of the opening call. */
     
    166167        /** Call data of the opening call. */
    167168        ipc_call_t call;
     169        /** Local argument or NULL if none. */
     170        void *carg;
    168171       
    169172        /** Identification of the closing call. */
     
    171174       
    172175        /** Fibril function that will be used to handle the connection. */
    173         void (*cfibril)(ipc_callid_t, ipc_call_t *);
     176        async_client_conn_t cfibril;
    174177} connection_t;
    175178
     
    201204}
    202205
    203 void *async_get_client_data(void)
    204 {
    205         assert(fibril_connection);
    206         return fibril_connection->client->data;
    207 }
    208 
    209206/** Default fibril function that gets called to handle new connection.
    210207 *
     
    213210 * @param callid Hash of the incoming call.
    214211 * @param call   Data of the incoming call.
    215  *
    216  */
    217 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)
     212 * @param arg    Local argument
     213 *
     214 */
     215static void default_client_connection(ipc_callid_t callid, ipc_call_t *call,
     216    void *arg)
    218217{
    219218        ipc_answer_0(callid, ENOENT);
     
    226225 * @param callid Hash of the incoming call.
    227226 * @param call   Data of the incoming call.
     227 * @param arg    Local argument.
    228228 *
    229229 */
     
    233233
    234234static async_client_conn_t client_connection = default_client_connection;
    235 static async_client_conn_t interrupt_received = default_interrupt_received;
     235static async_interrupt_handler_t interrupt_received = default_interrupt_received;
    236236
    237237/** Setter for client_connection function pointer.
     
    250250 *             notification fibril.
    251251 */
    252 void async_set_interrupt_received(async_client_conn_t intr)
     252void async_set_interrupt_received(async_interrupt_handler_t intr)
    253253{
    254254        interrupt_received = intr;
     
    284284{
    285285        assert(key);
     286        assert(keys == 2);
    286287        assert(item);
    287288       
    288289        client_t *client = hash_table_get_instance(item, client_t, link);
    289         return (key[0] == client->in_task_hash);
     290        return (key[0] == LOWER32(client->in_task_id) &&
     291            (key[1] == UPPER32(client->in_task_id)));
    290292}
    291293
     
    356358        wd->to_event.inlist = true;
    357359       
    358         link_t *tmp = timeout_list.next;
    359         while (tmp != &timeout_list) {
     360        link_t *tmp = timeout_list.head.next;
     361        while (tmp != &timeout_list.head) {
    360362                awaiter_t *cur
    361363                    = list_get_instance(tmp, awaiter_t, to_event.link);
     
    367369        }
    368370       
    369         list_append(&wd->to_event.link, tmp);
     371        list_insert_before(&wd->to_event.link, tmp);
    370372}
    371373
     
    564566        }
    565567       
    566         msg_t *msg = list_get_instance(conn->msg_queue.next, msg_t, link);
     568        msg_t *msg = list_get_instance(list_first(&conn->msg_queue), msg_t, link);
    567569        list_remove(&msg->link);
    568570       
     
    573575        futex_up(&async_futex);
    574576        return callid;
     577}
     578
     579static client_t *async_client_get(task_id_t client_id, bool create)
     580{
     581        unsigned long key[2] = {
     582                LOWER32(client_id),
     583                UPPER32(client_id),
     584        };
     585        client_t *client = NULL;
     586
     587        futex_down(&async_futex);
     588        link_t *lnk = hash_table_find(&client_hash_table, key);
     589        if (lnk) {
     590                client = hash_table_get_instance(lnk, client_t, link);
     591                atomic_inc(&client->refcnt);
     592        } else if (create) {
     593                client = malloc(sizeof(client_t));
     594                if (client) {
     595                        client->in_task_id = client_id;
     596                        client->data = async_client_data_create();
     597               
     598                        atomic_set(&client->refcnt, 1);
     599                        hash_table_insert(&client_hash_table, key, &client->link);
     600                }
     601        }
     602
     603        futex_up(&async_futex);
     604        return client;
     605}
     606
     607static void async_client_put(client_t *client)
     608{
     609        bool destroy;
     610        unsigned long key[2] = {
     611                LOWER32(client->in_task_id),
     612                UPPER32(client->in_task_id)
     613        };
     614       
     615        futex_down(&async_futex);
     616       
     617        if (atomic_predec(&client->refcnt) == 0) {
     618                hash_table_remove(&client_hash_table, key, 2);
     619                destroy = true;
     620        } else
     621                destroy = false;
     622       
     623        futex_up(&async_futex);
     624       
     625        if (destroy) {
     626                if (client->data)
     627                        async_client_data_destroy(client->data);
     628               
     629                free(client);
     630        }
     631}
     632
     633void *async_get_client_data(void)
     634{
     635        assert(fibril_connection);
     636        return fibril_connection->client->data;
     637}
     638
     639void *async_get_client_data_by_id(task_id_t client_id)
     640{
     641        client_t *client = async_client_get(client_id, false);
     642        if (!client)
     643                return NULL;
     644        if (!client->data) {
     645                async_client_put(client);
     646                return NULL;
     647        }
     648
     649        return client->data;
     650}
     651
     652void async_put_client_data_by_id(task_id_t client_id)
     653{
     654        client_t *client = async_client_get(client_id, false);
     655
     656        assert(client);
     657        assert(client->data);
     658
     659        /* Drop the reference we got in async_get_client_data_by_hash(). */
     660        async_client_put(client);
     661
     662        /* Drop our own reference we got at the beginning of this function. */
     663        async_client_put(client);
    575664}
    576665
     
    593682         */
    594683        fibril_connection = (connection_t *) arg;
    595        
    596         futex_down(&async_futex);
    597684       
    598685        /*
     
    601688         * hash in a new tracking structure.
    602689         */
    603        
    604         unsigned long key = fibril_connection->in_task_hash;
    605         link_t *lnk = hash_table_find(&client_hash_table, &key);
    606        
    607         client_t *client;
    608        
    609         if (lnk) {
    610                 client = hash_table_get_instance(lnk, client_t, link);
    611                 atomic_inc(&client->refcnt);
    612         } else {
    613                 client = malloc(sizeof(client_t));
    614                 if (!client) {
    615                         ipc_answer_0(fibril_connection->callid, ENOMEM);
    616                         futex_up(&async_futex);
    617                         return 0;
    618                 }
    619                
    620                 client->in_task_hash = fibril_connection->in_task_hash;
    621                 client->data = async_client_data_create();
    622                
    623                 atomic_set(&client->refcnt, 1);
    624                 hash_table_insert(&client_hash_table, &key, &client->link);
    625         }
    626        
    627         futex_up(&async_futex);
    628        
     690
     691        client_t *client = async_client_get(fibril_connection->in_task_id, true);
     692        if (!client) {
     693                ipc_answer_0(fibril_connection->callid, ENOMEM);
     694                return 0;
     695        }
     696
    629697        fibril_connection->client = client;
    630698       
     
    633701         */
    634702        fibril_connection->cfibril(fibril_connection->callid,
    635             &fibril_connection->call);
     703            &fibril_connection->call, fibril_connection->carg);
    636704       
    637705        /*
    638706         * Remove the reference for this client task connection.
    639707         */
    640         bool destroy;
    641        
    642         futex_down(&async_futex);
    643        
    644         if (atomic_predec(&client->refcnt) == 0) {
    645                 hash_table_remove(&client_hash_table, &key, 1);
    646                 destroy = true;
    647         } else
    648                 destroy = false;
    649        
    650         futex_up(&async_futex);
    651        
    652         if (destroy) {
    653                 if (client->data)
    654                         async_client_data_destroy(client->data);
    655                
    656                 free(client);
    657         }
     708        async_client_put(client);
    658709       
    659710        /*
     
    661712         */
    662713        futex_down(&async_futex);
    663         key = fibril_connection->in_phone_hash;
     714        unsigned long key = fibril_connection->in_phone_hash;
    664715        hash_table_remove(&conn_hash_table, &key, 1);
    665716        futex_up(&async_futex);
     
    670721        while (!list_empty(&fibril_connection->msg_queue)) {
    671722                msg_t *msg =
    672                     list_get_instance(fibril_connection->msg_queue.next, msg_t,
    673                     link);
     723                    list_get_instance(list_first(&fibril_connection->msg_queue),
     724                    msg_t, link);
    674725               
    675726                list_remove(&msg->link);
     
    695746 * particular fibrils.
    696747 *
    697  * @param in_task_hash  Identification of the incoming connection.
     748 * @param in_task_id    Identification of the incoming connection.
    698749 * @param in_phone_hash Identification of the incoming connection.
    699750 * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
     
    704755 * @param cfibril       Fibril function that should be called upon opening the
    705756 *                      connection.
     757 * @param carg          Extra argument to pass to the connection fibril
    706758 *
    707759 * @return New fibril id or NULL on failure.
    708760 *
    709761 */
    710 fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash,
     762fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
    711763    ipc_callid_t callid, ipc_call_t *call,
    712     async_client_conn_t cfibril)
     764    async_client_conn_t cfibril, void *carg)
    713765{
    714766        connection_t *conn = malloc(sizeof(*conn));
     
    720772        }
    721773       
    722         conn->in_task_hash = in_task_hash;
     774        conn->in_task_id = in_task_id;
    723775        conn->in_phone_hash = in_phone_hash;
    724776        list_initialize(&conn->msg_queue);
    725777        conn->callid = callid;
    726778        conn->close_callid = 0;
     779        conn->carg = carg;
    727780       
    728781        if (call)
     
    778831        case IPC_M_CONNECT_ME_TO:
    779832                /* Open new connection with fibril, etc. */
    780                 async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
    781                     callid, call, client_connection);
     833                async_new_connection(call->in_task_id, IPC_GET_ARG5(*call),
     834                    callid, call, client_connection, NULL);
    782835                return;
    783836        }
     
    799852        futex_down(&async_futex);
    800853       
    801         link_t *cur = timeout_list.next;
    802         while (cur != &timeout_list) {
     854        link_t *cur = list_first(&timeout_list);
     855        while (cur != NULL) {
    803856                awaiter_t *waiter =
    804857                    list_get_instance(cur, awaiter_t, to_event.link);
     
    806859                if (tv_gt(&waiter->to_event.expires, &tv))
    807860                        break;
    808                
    809                 cur = cur->next;
    810861               
    811862                list_remove(&waiter->to_event.link);
     
    821872                        fibril_add_ready(waiter->fid);
    822873                }
     874               
     875                cur = list_first(&timeout_list);
    823876        }
    824877       
     
    847900                suseconds_t timeout;
    848901                if (!list_empty(&timeout_list)) {
    849                         awaiter_t *waiter = list_get_instance(timeout_list.next,
    850                             awaiter_t, to_event.link);
     902                        awaiter_t *waiter = list_get_instance(
     903                            list_first(&timeout_list), awaiter_t, to_event.link);
    851904                       
    852905                        struct timeval tv;
     
    926979{
    927980        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
    928             1, &client_hash_table_ops))
     981            2, &client_hash_table_ops))
    929982                abort();
    930983       
     
    942995        session_ns->arg2 = 0;
    943996        session_ns->arg3 = 0;
     997       
     998        fibril_mutex_initialize(&session_ns->remote_state_mtx);
     999        session_ns->remote_state_data = NULL;
    9441000       
    9451001        list_initialize(&session_ns->exch_list);
     
    14141470 */
    14151471int async_connect_to_me(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2,
    1416     sysarg_t arg3, async_client_conn_t client_receiver)
     1472    sysarg_t arg3, async_client_conn_t client_receiver, void *carg)
    14171473{
    14181474        if (exch == NULL)
    14191475                return ENOENT;
    14201476       
    1421         sysarg_t task_hash;
    14221477        sysarg_t phone_hash;
    1423         int rc = async_req_3_5(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
    1424             NULL, NULL, NULL, &task_hash, &phone_hash);
     1478        sysarg_t rc;
     1479
     1480        aid_t req;
     1481        ipc_call_t answer;
     1482        req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
     1483            &answer);
     1484        async_wait_for(req, &rc);
    14251485        if (rc != EOK)
    1426                 return rc;
    1427        
     1486                return (int) rc;
     1487
     1488        phone_hash = IPC_GET_ARG5(answer);
     1489
    14281490        if (client_receiver != NULL)
    1429                 async_new_connection(task_hash, phone_hash, 0, NULL,
    1430                     client_receiver);
     1491                async_new_connection(answer.in_task_id, phone_hash, 0, NULL,
     1492                    client_receiver, carg);
    14311493       
    14321494        return EOK;
     
    15021564        sess->arg3 = 0;
    15031565       
     1566        fibril_mutex_initialize(&sess->remote_state_mtx);
     1567        sess->remote_state_data = NULL;
     1568       
    15041569        list_initialize(&sess->exch_list);
    15051570        fibril_mutex_initialize(&sess->mutex);
     
    15831648        sess->arg3 = arg3;
    15841649       
     1650        fibril_mutex_initialize(&sess->remote_state_mtx);
     1651        sess->remote_state_data = NULL;
     1652       
    15851653        list_initialize(&sess->exch_list);
    15861654        fibril_mutex_initialize(&sess->mutex);
     
    15881656       
    15891657        return sess;
     1658}
     1659
     1660/** Set arguments for new connections.
     1661 *
     1662 * FIXME This is an ugly hack to work around the problem that parallel
     1663 * exchanges are implemented using parallel connections. When we create
     1664 * a callback session, the framework does not know arguments for the new
     1665 * connections.
     1666 *
     1667 * The proper solution seems to be to implement parallel exchanges using
     1668 * tagging.
     1669 */
     1670void async_sess_args_set(async_sess_t *sess, sysarg_t arg1, sysarg_t arg2,
     1671    sysarg_t arg3)
     1672{
     1673        sess->arg1 = arg1;
     1674        sess->arg2 = arg2;
     1675        sess->arg3 = arg3;
    15901676}
    15911677
     
    16331719        sess->arg3 = arg3;
    16341720       
     1721        fibril_mutex_initialize(&sess->remote_state_mtx);
     1722        sess->remote_state_data = NULL;
     1723       
    16351724        list_initialize(&sess->exch_list);
    16361725        fibril_mutex_initialize(&sess->mutex);
     
    16641753        sess->arg3 = 0;
    16651754       
     1755        fibril_mutex_initialize(&sess->remote_state_mtx);
     1756        sess->remote_state_data = NULL;
     1757       
    16661758        list_initialize(&sess->exch_list);
    16671759        fibril_mutex_initialize(&sess->mutex);
     
    16851777int async_hangup(async_sess_t *sess)
    16861778{
     1779        async_exch_t *exch;
     1780       
    16871781        assert(sess);
    16881782       
    16891783        if (atomic_get(&sess->refcnt) > 0)
    16901784                return EBUSY;
     1785       
     1786        fibril_mutex_lock(&async_sess_mutex);
    16911787       
    16921788        int rc = async_hangup_internal(sess->phone);
    16931789        if (rc == EOK)
    16941790                free(sess);
     1791       
     1792        while (!list_empty(&sess->exch_list)) {
     1793                exch = (async_exch_t *)
     1794                    list_get_instance(list_first(&sess->exch_list),
     1795                    async_exch_t, sess_link);
     1796               
     1797                list_remove(&exch->sess_link);
     1798                list_remove(&exch->global_link);
     1799                async_hangup_internal(exch->phone);
     1800                free(exch);
     1801        }
     1802       
     1803        fibril_mutex_unlock(&async_sess_mutex);
    16951804       
    16961805        return rc;
     
    17241833                 */
    17251834                exch = (async_exch_t *)
    1726                     list_get_instance(sess->exch_list.next, async_exch_t, sess_link);
     1835                    list_get_instance(list_first(&sess->exch_list),
     1836                    async_exch_t, sess_link);
     1837               
    17271838                list_remove(&exch->sess_link);
    17281839                list_remove(&exch->global_link);
     
    17361847                        exch = (async_exch_t *) malloc(sizeof(async_exch_t));
    17371848                        if (exch != NULL) {
    1738                                 list_initialize(&exch->sess_link);
    1739                                 list_initialize(&exch->global_link);
     1849                                link_initialize(&exch->sess_link);
     1850                                link_initialize(&exch->global_link);
    17401851                                exch->sess = sess;
    17411852                                exch->phone = sess->phone;
     
    17541865                                exch = (async_exch_t *) malloc(sizeof(async_exch_t));
    17551866                                if (exch != NULL) {
    1756                                         list_initialize(&exch->sess_link);
    1757                                         list_initialize(&exch->global_link);
     1867                                        link_initialize(&exch->sess_link);
     1868                                        link_initialize(&exch->global_link);
    17581869                                        exch->sess = sess;
    17591870                                        exch->phone = phone;
     
    17671878                                 */
    17681879                                exch = (async_exch_t *)
    1769                                     list_get_instance(inactive_exch_list.next, async_exch_t,
    1770                                     global_link);
     1880                                    list_get_instance(list_first(&inactive_exch_list),
     1881                                    async_exch_t, global_link);
     1882                               
    17711883                                list_remove(&exch->sess_link);
    17721884                                list_remove(&exch->global_link);
     
    18081920        async_sess_t *sess = exch->sess;
    18091921       
     1922        atomic_dec(&sess->refcnt);
     1923       
    18101924        if (sess->mgmt == EXCHANGE_SERIALIZE)
    18111925                fibril_mutex_unlock(&sess->mutex);
     
    23222436        sess->arg3 = 0;
    23232437       
     2438        fibril_mutex_initialize(&sess->remote_state_mtx);
     2439        sess->remote_state_data = NULL;
     2440       
    23242441        list_initialize(&sess->exch_list);
    23252442        fibril_mutex_initialize(&sess->mutex);
     
    23682485        sess->arg3 = 0;
    23692486       
     2487        fibril_mutex_initialize(&sess->remote_state_mtx);
     2488        sess->remote_state_data = NULL;
     2489       
    23702490        list_initialize(&sess->exch_list);
    23712491        fibril_mutex_initialize(&sess->mutex);
     
    24102530        sess->arg3 = 0;
    24112531       
     2532        fibril_mutex_initialize(&sess->remote_state_mtx);
     2533        sess->remote_state_data = NULL;
     2534       
    24122535        list_initialize(&sess->exch_list);
    24132536        fibril_mutex_initialize(&sess->mutex);
     
    24172540}
    24182541
     2542int async_state_change_start(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2,
     2543    sysarg_t arg3, async_exch_t *other_exch)
     2544{
     2545        return async_req_5_0(exch, IPC_M_STATE_CHANGE_AUTHORIZE,
     2546            arg1, arg2, arg3, 0, other_exch->phone);
     2547}
     2548
     2549bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1,
     2550    sysarg_t *arg2, sysarg_t *arg3)
     2551{
     2552        assert(callid);
     2553
     2554        ipc_call_t call;
     2555        *callid = async_get_call(&call);
     2556
     2557        if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE)
     2558                return false;
     2559       
     2560        if (arg1)
     2561                *arg1 = IPC_GET_ARG1(call);
     2562        if (arg2)
     2563                *arg2 = IPC_GET_ARG2(call);
     2564        if (arg3)
     2565                *arg3 = IPC_GET_ARG3(call);
     2566
     2567        return true;
     2568}
     2569
     2570int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch)
     2571{
     2572        return ipc_answer_1(callid, EOK, other_exch->phone);
     2573}
     2574
     2575/** Lock and get session remote state
     2576 *
     2577 * Lock and get the local replica of the remote state
     2578 * in stateful sessions. The call should be paired
     2579 * with async_remote_state_release*().
     2580 *
     2581 * @param[in] sess Stateful session.
     2582 *
     2583 * @return Local replica of the remote state.
     2584 *
     2585 */
     2586void *async_remote_state_acquire(async_sess_t *sess)
     2587{
     2588        fibril_mutex_lock(&sess->remote_state_mtx);
     2589        return sess->remote_state_data;
     2590}
     2591
     2592/** Update the session remote state
     2593 *
     2594 * Update the local replica of the remote state
     2595 * in stateful sessions. The remote state must
     2596 * be already locked.
     2597 *
     2598 * @param[in] sess  Stateful session.
     2599 * @param[in] state New local replica of the remote state.
     2600 *
     2601 */
     2602void async_remote_state_update(async_sess_t *sess, void *state)
     2603{
     2604        assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
     2605        sess->remote_state_data = state;
     2606}
     2607
     2608/** Release the session remote state
     2609 *
     2610 * Unlock the local replica of the remote state
     2611 * in stateful sessions.
     2612 *
     2613 * @param[in] sess Stateful session.
     2614 *
     2615 */
     2616void async_remote_state_release(async_sess_t *sess)
     2617{
     2618        assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
     2619       
     2620        fibril_mutex_unlock(&sess->remote_state_mtx);
     2621}
     2622
     2623/** Release the session remote state and end an exchange
     2624 *
     2625 * Unlock the local replica of the remote state
     2626 * in stateful sessions. This is convenience function
     2627 * which gets the session pointer from the exchange
     2628 * and also ends the exchange.
     2629 *
     2630 * @param[in] exch Stateful session's exchange.
     2631 *
     2632 */
     2633void async_remote_state_release_exchange(async_exch_t *exch)
     2634{
     2635        if (exch == NULL)
     2636                return;
     2637       
     2638        async_sess_t *sess = exch->sess;
     2639        assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
     2640       
     2641        async_exchange_end(exch);
     2642        fibril_mutex_unlock(&sess->remote_state_mtx);
     2643}
     2644
    24192645/** @}
    24202646 */
  • uspace/lib/c/generic/async_obsolete.c

    rd2c67e7 r8ff0bd2  
    3838#include <async.h>
    3939#include <async_obsolete.h>
     40#include "private/async.h"
    4041#undef LIBC_ASYNC_C_
    4142#undef LIBC_ASYNC_OBSOLETE_C_
     
    4445#include <malloc.h>
    4546#include <errno.h>
    46 #include "private/async.h"
    4747
    4848/** Send message and return id of the sent message.
     
    166166}
    167167
    168 void async_obsolete_serialize_start(void)
    169 {
    170         fibril_inc_sercount();
    171 }
    172 
    173 void async_obsolete_serialize_end(void)
    174 {
    175         fibril_dec_sercount();
    176 }
    177 
    178168/** Wrapper for IPC_M_DATA_WRITE calls using the async framework.
    179169 *
     
    240230 */
    241231int async_obsolete_connect_to_me(int phone, sysarg_t arg1, sysarg_t arg2,
    242     sysarg_t arg3, async_client_conn_t client_receiver)
     232    sysarg_t arg3, async_client_conn_t client_receiver, void *carg)
    243233{
    244234        sysarg_t task_hash;
     
    251241        if (client_receiver != NULL)
    252242                async_new_connection(task_hash, phone_hash, 0, NULL,
    253                     client_receiver);
     243                    client_receiver, carg);
    254244       
    255245        return EOK;
  • uspace/lib/c/generic/ddi.c

    rd2c67e7 r8ff0bd2  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
     35#include <sys/types.h>
     36#include <abi/ddi/arg.h>
    3537#include <ddi.h>
    3638#include <libarch/ddi.h>
     
    4042#include <align.h>
    4143#include <libarch/config.h>
    42 #include <kernel/ddi/ddi_arg.h>
    4344
    4445/** Return unique device number.
  • uspace/lib/c/generic/devman.c

    rd2c67e7 r8ff0bd2  
    11/*
    22 * Copyright (c) 2007 Josef Cejka
    3  * Copyright (c) 2009 Jiri Svoboda
     3 * Copyright (c) 2011 Jiri Svoboda
    44 * Copyright (c) 2010 Lenka Trochtova
    55 * All rights reserved.
     
    3535 */
    3636
     37#include <adt/list.h>
    3738#include <str.h>
    3839#include <ipc/services.h>
     
    8889                        if (devman_driver_block_sess == NULL)
    8990                                devman_driver_block_sess =
    90                                     service_connect_blocking(EXCHANGE_SERIALIZE,
     91                                    service_connect_blocking(EXCHANGE_PARALLEL,
    9192                                    SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
    9293                }
     
    137138                if (devman_driver_sess == NULL)
    138139                        devman_driver_sess =
    139                             service_connect(EXCHANGE_SERIALIZE, SERVICE_DEVMAN,
     140                            service_connect(EXCHANGE_PARALLEL, SERVICE_DEVMAN,
    140141                            DEVMAN_DRIVER, 0);
    141142               
     
    194195       
    195196        exch = devman_exchange_begin(DEVMAN_DRIVER);
    196         async_connect_to_me(exch, 0, 0, 0, NULL);
     197        async_connect_to_me(exch, 0, 0, 0, conn, NULL);
    197198        devman_exchange_end(exch);
    198199       
     
    231232        }
    232233       
    233         link_t *link = match_ids->ids.next;
    234234        match_id_t *match_id = NULL;
    235235       
    236         while (link != &match_ids->ids) {
     236        list_foreach(match_ids->ids, link) {
    237237                match_id = list_get_instance(link, match_id_t, link);
    238238               
     
    255255                        return retval;
    256256                }
    257                
    258                 link = link->next;
    259257        }
    260258       
     
    273271}
    274272
    275 int devman_add_device_to_class(devman_handle_t devman_handle,
    276     const char *class_name)
     273int devman_add_device_to_category(devman_handle_t devman_handle,
     274    const char *cat_name)
    277275{
    278276        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
    279277       
    280278        ipc_call_t answer;
    281         aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CLASS,
     279        aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CATEGORY,
    282280            devman_handle, &answer);
    283         sysarg_t retval = async_data_write_start(exch, class_name,
    284             str_size(class_name));
     281        sysarg_t retval = async_data_write_start(exch, cat_name,
     282            str_size(cat_name));
    285283       
    286284        devman_exchange_end(exch);
     
    310308}
    311309
     310/** Remove function from device.
     311 *
     312 * Request devman to remove function owned by this driver task.
     313 * @param funh      Devman handle of the function
     314 *
     315 * @return EOK on success or negative error code.
     316 */
     317int devman_remove_function(devman_handle_t funh)
     318{
     319        async_exch_t *exch;
     320        sysarg_t retval;
     321       
     322        exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
     323        retval = async_req_1_0(exch, DEVMAN_REMOVE_FUNCTION, (sysarg_t) funh);
     324        devman_exchange_end(exch);
     325       
     326        return (int) retval;
     327}
     328
     329int devman_drv_fun_online(devman_handle_t funh)
     330{
     331        async_exch_t *exch = devman_exchange_begin(DEVMAN_DRIVER);
     332        if (exch == NULL)
     333                return ENOMEM;
     334       
     335        sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_ONLINE, funh);
     336       
     337        devman_exchange_end(exch);
     338        return (int) retval;
     339}
     340
     341int devman_drv_fun_offline(devman_handle_t funh)
     342{
     343        async_exch_t *exch = devman_exchange_begin(DEVMAN_DRIVER);
     344        if (exch == NULL)
     345                return ENOMEM;
     346       
     347        sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_OFFLINE, funh);
     348       
     349        devman_exchange_end(exch);
     350        return (int) retval;
     351}
     352
    312353async_sess_t *devman_parent_device_connect(exch_mgmt_t mgmt,
    313354    devman_handle_t handle, unsigned int flags)
     
    325366}
    326367
    327 int devman_device_get_handle(const char *pathname, devman_handle_t *handle,
     368int devman_fun_get_handle(const char *pathname, devman_handle_t *handle,
    328369    unsigned int flags)
    329370{
     
    335376                exch = devman_exchange_begin(DEVMAN_CLIENT);
    336377                if (exch == NULL)
    337                         return errno;
     378                        return ENOMEM;
    338379        }
    339380       
     
    366407}
    367408
    368 int devman_device_get_handle_by_class(const char *classname,
    369     const char *devname, devman_handle_t *handle, unsigned int flags)
     409static int devman_get_str_internal(sysarg_t method, sysarg_t arg1, char *buf,
     410    size_t buf_size)
    370411{
    371412        async_exch_t *exch;
    372        
    373         if (flags & IPC_FLAG_BLOCKING)
    374                 exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
    375         else {
    376                 exch = devman_exchange_begin(DEVMAN_CLIENT);
    377                 if (exch == NULL)
    378                         return errno;
    379         }
     413        ipc_call_t dreply;
     414        size_t act_size;
     415        sysarg_t dretval;
     416       
     417        exch = devman_exchange_begin_blocking(LOC_PORT_CONSUMER);
    380418       
    381419        ipc_call_t answer;
    382         aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
    383             flags, &answer);
    384         sysarg_t retval = async_data_write_start(exch, classname,
    385             str_size(classname));
    386        
    387         if (retval != EOK) {
    388                 devman_exchange_end(exch);
     420        aid_t req = async_send_1(exch, method, arg1, &answer);
     421        aid_t dreq = async_data_read(exch, buf, buf_size - 1, &dreply);
     422        async_wait_for(dreq, &dretval);
     423       
     424        devman_exchange_end(exch);
     425       
     426        if (dretval != EOK) {
    389427                async_wait_for(req, NULL);
    390                 return retval;
    391         }
    392        
    393         retval = async_data_write_start(exch, devname,
    394             str_size(devname));
    395        
    396         devman_exchange_end(exch);
    397        
    398         if (retval != EOK) {
    399                 async_wait_for(req, NULL);
    400                 return retval;
    401         }
    402        
     428                return dretval;
     429        }
     430       
     431        sysarg_t retval;
    403432        async_wait_for(req, &retval);
    404433       
    405         if (retval != EOK) {
    406                 if (handle != NULL)
    407                         *handle = (devman_handle_t) -1;
    408                
    409                 return retval;
    410         }
    411        
    412         if (handle != NULL)
    413                 *handle = (devman_handle_t) IPC_GET_ARG1(answer);
    414        
    415         return retval;
    416 }
    417 
    418 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size)
     434        if (retval != EOK)
     435                return retval;
     436       
     437        act_size = IPC_GET_ARG2(dreply);
     438        assert(act_size <= buf_size - 1);
     439        buf[act_size] = '\0';
     440       
     441        return EOK;
     442}
     443
     444int devman_fun_get_path(devman_handle_t handle, char *buf, size_t buf_size)
     445{
     446        return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, buf,
     447            buf_size);
     448}
     449
     450int devman_fun_get_name(devman_handle_t handle, char *buf, size_t buf_size)
     451{
     452        return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, buf,
     453            buf_size);
     454}
     455
     456int devman_fun_online(devman_handle_t funh)
    419457{
    420458        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
    421459        if (exch == NULL)
    422                 return errno;
    423        
     460                return ENOMEM;
     461       
     462        sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_ONLINE, funh);
     463       
     464        devman_exchange_end(exch);
     465        return (int) retval;
     466}
     467
     468int devman_fun_offline(devman_handle_t funh)
     469{
     470        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     471        if (exch == NULL)
     472                return ENOMEM;
     473       
     474        sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_OFFLINE, funh);
     475       
     476        devman_exchange_end(exch);
     477        return (int) retval;
     478}
     479
     480static int devman_get_handles_once(sysarg_t method, sysarg_t arg1,
     481    devman_handle_t *handle_buf, size_t buf_size, size_t *act_size)
     482{
     483        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
     484
    424485        ipc_call_t answer;
    425         aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_DEVICE_PATH,
    426             handle, &answer);
    427        
    428         ipc_call_t data_request_call;
    429         aid_t data_request = async_data_read(exch, path, path_size,
    430             &data_request_call);
    431        
    432         devman_exchange_end(exch);
    433        
    434         if (data_request == 0) {
     486        aid_t req = async_send_1(exch, method, arg1, &answer);
     487        int rc = async_data_read_start(exch, handle_buf, buf_size);
     488       
     489        devman_exchange_end(exch);
     490       
     491        if (rc != EOK) {
    435492                async_wait_for(req, NULL);
    436                 return ENOMEM;
    437         }
    438        
    439         sysarg_t data_request_rc;
    440         async_wait_for(data_request, &data_request_rc);
    441        
    442         sysarg_t opening_request_rc;
    443         async_wait_for(req, &opening_request_rc);
    444        
    445         if (data_request_rc != EOK) {
    446                 /* Prefer the return code of the opening request. */
    447                 if (opening_request_rc != EOK)
    448                         return (int) opening_request_rc;
    449                 else
    450                         return (int) data_request_rc;
    451         }
    452        
    453         if (opening_request_rc != EOK)
    454                 return (int) opening_request_rc;
    455        
    456         /* To be on the safe-side. */
    457         path[path_size - 1] = 0;
    458         size_t transferred_size = IPC_GET_ARG2(data_request_call);
    459         if (transferred_size >= path_size)
    460                 return ELIMIT;
    461        
    462         /* Terminate the string (trailing 0 not send over IPC). */
    463         path[transferred_size] = 0;
     493                return rc;
     494        }
     495       
     496        sysarg_t retval;
     497        async_wait_for(req, &retval);
     498       
     499        if (retval != EOK) {
     500                return retval;
     501        }
     502       
     503        *act_size = IPC_GET_ARG1(answer);
    464504        return EOK;
    465505}
    466506
     507/** Get list of handles.
     508 *
     509 * Returns an allocated array of handles.
     510 *
     511 * @param method        IPC method
     512 * @param arg1          IPC argument 1
     513 * @param data          Place to store pointer to array of handles
     514 * @param count         Place to store number of handles
     515 * @return              EOK on success or negative error code
     516 */
     517static int devman_get_handles_internal(sysarg_t method, sysarg_t arg1,
     518    devman_handle_t **data, size_t *count)
     519{
     520        devman_handle_t *handles;
     521        size_t act_size;
     522        size_t alloc_size;
     523        int rc;
     524
     525        *data = NULL;
     526        act_size = 0;   /* silence warning */
     527
     528        rc = devman_get_handles_once(method, arg1, NULL, 0,
     529            &act_size);
     530        if (rc != EOK)
     531                return rc;
     532
     533        alloc_size = act_size;
     534        handles = malloc(alloc_size);
     535        if (handles == NULL)
     536                return ENOMEM;
     537
     538        while (true) {
     539                rc = devman_get_handles_once(method, arg1, handles, alloc_size,
     540                    &act_size);
     541                if (rc != EOK)
     542                        return rc;
     543
     544                if (act_size <= alloc_size)
     545                        break;
     546
     547                alloc_size *= 2;
     548                free(handles);
     549
     550                handles = malloc(alloc_size);
     551                if (handles == NULL)
     552                        return ENOMEM;
     553        }
     554
     555        *count = act_size / sizeof(devman_handle_t);
     556        *data = handles;
     557        return EOK;
     558}
     559
     560int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh)
     561{
     562        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     563        if (exch == NULL)
     564                return ENOMEM;
     565       
     566        sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD,
     567            funh, devh);
     568       
     569        devman_exchange_end(exch);
     570        return (int) retval;
     571}
     572
     573int devman_dev_get_functions(devman_handle_t devh, devman_handle_t **funcs,
     574    size_t *count)
     575{
     576        return devman_get_handles_internal(DEVMAN_DEV_GET_FUNCTIONS,
     577            devh, funcs, count);
     578}
     579
     580int devman_fun_sid_to_handle(service_id_t sid, devman_handle_t *handle)
     581{
     582        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
     583        if (exch == NULL)
     584                return ENOMEM;
     585       
     586        sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_SID_TO_HANDLE,
     587            sid, handle);
     588       
     589        devman_exchange_end(exch);
     590        return (int) retval;
     591}
     592
    467593/** @}
    468594 */
  • uspace/lib/c/generic/elf/elf_load.c

    rd2c67e7 r8ff0bd2  
    2929 */
    3030
    31 /** @addtogroup generic 
     31/** @addtogroup generic
    3232 * @{
    3333 */
     
    4949#include <assert.h>
    5050#include <as.h>
     51#include <elf/elf.h>
    5152#include <unistd.h>
    5253#include <fcntl.h>
     
    5556#include <entry_point.h>
    5657
    57 #include "elf.h"
    58 #include "elf_load.h"
     58#include <elf/elf_load.h>
    5959
    6060#define DPRINTF(...)
     
    7474static int load_segment(elf_ld_t *elf, elf_segment_header_t *entry);
    7575
    76 /** Read until the buffer is read in its entirety. */
    77 static int my_read(int fd, void *buf, size_t len)
    78 {
    79         int cnt = 0;
    80         do {
    81                 buf += cnt;
    82                 len -= cnt;
    83                 cnt = read(fd, buf, len);
    84         } while ((cnt > 0) && ((len - cnt) > 0));
    85 
    86         return cnt;
    87 }
    88 
    8976/** Load ELF binary from a file.
    9077 *
     
    160147        int i, rc;
    161148
    162         rc = my_read(elf->fd, header, sizeof(elf_header_t));
    163         if (rc < 0) {
     149        rc = read_all(elf->fd, header, sizeof(elf_header_t));
     150        if (rc != sizeof(elf_header_t)) {
    164151                DPRINTF("Read error.\n");
    165152                return EE_INVALID;
     
    222209                        + i * sizeof(elf_segment_header_t), SEEK_SET);
    223210
    224                 rc = my_read(elf->fd, &segment_hdr,
     211                rc = read_all(elf->fd, &segment_hdr,
    225212                    sizeof(elf_segment_header_t));
    226                 if (rc < 0) {
     213                if (rc != sizeof(elf_segment_header_t)) {
    227214                        DPRINTF("Read error.\n");
    228215                        return EE_INVALID;
     
    244231                    + i * sizeof(elf_section_header_t), SEEK_SET);
    245232
    246                 rc = my_read(elf->fd, &section_hdr,
     233                rc = read_all(elf->fd, &section_hdr,
    247234                    sizeof(elf_section_header_t));
    248                 if (rc < 0) {
     235                if (rc != sizeof(elf_section_header_t)) {
    249236                        DPRINTF("Read error.\n");
    250237                        return EE_INVALID;
     
    334321        uintptr_t seg_addr;
    335322        size_t mem_sz;
    336         int rc;
     323        ssize_t rc;
    337324
    338325        bias = elf->bias;
     
    412399                if (now > left) now = left;
    413400
    414                 rc = my_read(elf->fd, dp, now);
    415 
    416                 if (rc < 0) {
     401                rc = read_all(elf->fd, dp, now);
     402
     403                if (rc != (ssize_t) now) {
    417404                        DPRINTF("Read error.\n");
    418405                        return EE_INVALID;
  • uspace/lib/c/generic/event.c

    rd2c67e7 r8ff0bd2  
    3939#include <libc.h>
    4040#include <event.h>
    41 #include <kernel/ipc/event_types.h>
    4241
    4342/** Subscribe event notifications.
     
    5049 */
    5150int event_subscribe(event_type_t evno, sysarg_t imethod)
     51{
     52        return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno,
     53            (sysarg_t) imethod);
     54}
     55
     56int event_task_subscribe(event_task_type_t evno, sysarg_t imethod)
    5257{
    5358        return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno,
     
    6772}
    6873
     74int event_task_unmask(event_task_type_t evno)
     75{
     76        return __SYSCALL1(SYS_EVENT_UNMASK, (sysarg_t) evno);
     77}
     78
    6979/** @}
    7080 */
  • uspace/lib/c/generic/fibril.c

    rd2c67e7 r8ff0bd2  
    4141#include <unistd.h>
    4242#include <stdio.h>
    43 #include <arch/barrier.h>
     43#include <libarch/barrier.h>
    4444#include <libarch/faddr.h>
    4545#include <futex.h>
     
    222222        fibril_t *dstf;
    223223        if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) {
    224                 dstf = list_get_instance(manager_list.next, fibril_t, link);
     224                dstf = list_get_instance(list_first(&manager_list), fibril_t,
     225                    link);
    225226                if (serialization_count && stype == FIBRIL_TO_MANAGER) {
    226227                        serialized_threads++;
     
    233234        } else {
    234235                if (!list_empty(&serialized_list)) {
    235                         dstf = list_get_instance(serialized_list.next, fibril_t,
    236                             link);
     236                        dstf = list_get_instance(list_first(&serialized_list),
     237                            fibril_t, link);
    237238                        serialized_threads--;
    238239                } else {
    239                         dstf = list_get_instance(ready_list.next, fibril_t,
    240                             link);
     240                        dstf = list_get_instance(list_first(&ready_list),
     241                            fibril_t, link);
    241242                }
    242243        }
     
    326327       
    327328        if (!list_empty(&manager_list))
    328                 list_remove(manager_list.next);
     329                list_remove(list_first(&manager_list));
    329330       
    330331        futex_up(&fibril_futex);
  • uspace/lib/c/generic/fibril_synch.c

    rd2c67e7 r8ff0bd2  
    148148                fibril_t *f;
    149149       
    150                 assert(!list_empty(&fm->waiters));
    151                 tmp = fm->waiters.next;
     150                tmp = list_first(&fm->waiters);
     151                assert(tmp != NULL);
    152152                wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
    153153                wdp->active = true;
     
    279279       
    280280        while (!list_empty(&frw->waiters)) {
    281                 link_t *tmp = frw->waiters.next;
     281                link_t *tmp = list_first(&frw->waiters);
    282282                awaiter_t *wdp;
    283283                fibril_t *f;
     
    422422        futex_down(&async_futex);
    423423        while (!list_empty(&fcv->waiters)) {
    424                 tmp = fcv->waiters.next;
     424                tmp = list_first(&fcv->waiters);
    425425                wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
    426426                list_remove(&wdp->wu_event.link);
  • uspace/lib/c/generic/io/console.c

    rd2c67e7 r8ff0bd2  
    7676bool console_kcon(void)
    7777{
    78 #if 0
    7978        return __SYSCALL0(SYS_DEBUG_ACTIVATE_CONSOLE);
    80 #endif
    81        
    82         return false;
    8379}
    8480
  • uspace/lib/c/generic/io/io.c

    rd2c67e7 r8ff0bd2  
    4545#include <vfs/vfs.h>
    4646#include <vfs/vfs_sess.h>
    47 #include <ipc/devmap.h>
     47#include <ipc/loc.h>
    4848#include <adt/list.h>
    4949#include "../private/io.h"
     
    101101static LIST_INITIALIZE(files);
    102102
    103 void __stdio_init(int filc, fdi_node_t *filv[])
     103void __stdio_init(int filc)
    104104{
    105105        if (filc > 0) {
    106                 stdin = fopen_node(filv[0], "r");
     106                stdin = fdopen(0, "r");
    107107        } else {
    108108                stdin = &stdin_null;
     
    111111       
    112112        if (filc > 1) {
    113                 stdout = fopen_node(filv[1], "w");
     113                stdout = fdopen(1, "w");
    114114        } else {
    115115                stdout = &stdout_klog;
     
    118118       
    119119        if (filc > 2) {
    120                 stderr = fopen_node(filv[2], "w");
     120                stderr = fdopen(2, "w");
    121121        } else {
    122122                stderr = &stderr_klog;
     
    127127void __stdio_done(void)
    128128{
    129         link_t *link = files.next;
    130        
    131         while (link != &files) {
    132                 FILE *file = list_get_instance(link, FILE, link);
     129        while (!list_empty(&files)) {
     130                FILE *file = list_get_instance(list_first(&files), FILE, link);
    133131                fclose(file);
    134                 link = files.next;
    135132        }
    136133}
     
    288285}
    289286
    290 FILE *fopen_node(fdi_node_t *node, const char *mode)
    291 {
    292         int flags;
    293         if (!parse_mode(mode, &flags))
    294                 return NULL;
    295        
    296         /* Open file. */
    297         FILE *stream = malloc(sizeof(FILE));
    298         if (stream == NULL) {
    299                 errno = ENOMEM;
    300                 return NULL;
    301         }
    302        
    303         stream->fd = open_node(node, flags);
    304         if (stream->fd < 0) {
    305                 /* errno was set by open_node() */
    306                 free(stream);
    307                 return NULL;
    308         }
    309        
    310         stream->error = false;
    311         stream->eof = false;
    312         stream->klog = false;
    313         stream->sess = NULL;
    314         stream->need_sync = false;
    315         _setvbuf(stream);
    316        
    317         list_append(&stream->link, &files);
    318        
    319         return stream;
    320 }
    321 
    322287int fclose(FILE *stream)
    323288{
     
    597562                }
    598563               
    599                 buf += now;
     564                data += now;
    600565                stream->buf_head += now;
    601566                buf_free -= now;
    602567                bytes_left -= now;
    603568                total_written += now;
     569                stream->buf_state = _bs_write;
    604570               
    605571                if (buf_free == 0) {
     
    609575                }
    610576        }
    611        
    612         if (total_written > 0)
    613                 stream->buf_state = _bs_write;
    614577
    615578        if (need_flush)
     
    717680off64_t ftell(FILE *stream)
    718681{
     682        _fflushbuf(stream);
    719683        return lseek(stream->fd, 0, SEEK_CUR);
    720684}
     
    784748}
    785749
    786 int fnode(FILE *stream, fdi_node_t *node)
    787 {
    788         if (stream->fd >= 0)
    789                 return fd_node(stream->fd, node);
     750int fhandle(FILE *stream, int *handle)
     751{
     752        if (stream->fd >= 0) {
     753                *handle = stream->fd;
     754                return EOK;
     755        }
    790756       
    791757        return ENOENT;
  • uspace/lib/c/generic/io/printf_core.c

    rd2c67e7 r8ff0bd2  
    7474#define PRINT_NUMBER_BUFFER_SIZE  (64 + 5)
    7575
     76/** Get signed or unsigned integer argument */
     77#define PRINTF_GET_INT_ARGUMENT(type, ap, flags) \
     78        ({ \
     79                unsigned type res; \
     80                \
     81                if ((flags) & __PRINTF_FLAG_SIGNED) { \
     82                        signed type arg = va_arg((ap), signed type); \
     83                        \
     84                        if (arg < 0) { \
     85                                res = -arg; \
     86                                (flags) |= __PRINTF_FLAG_NEGATIVE; \
     87                        } else \
     88                                res = arg; \
     89                } else \
     90                        res = va_arg((ap), unsigned type); \
     91                \
     92                res; \
     93        })
     94
    7695/** Enumeration of possible arguments types.
    7796 */
     
    206225        }
    207226       
    208         return (int) (counter + 1);
     227        return (int) (counter);
    209228}
    210229
     
    244263        }
    245264       
    246         return (int) (counter + 1);
     265        return (int) (counter);
    247266}
    248267
     
    831850                        size_t size;
    832851                        uint64_t number;
     852                       
    833853                        switch (qualifier) {
    834854                        case PrintfQualifierByte:
    835855                                size = sizeof(unsigned char);
    836                                 number = (uint64_t) va_arg(ap, unsigned int);
     856                                number = PRINTF_GET_INT_ARGUMENT(int, ap, flags);
    837857                                break;
    838858                        case PrintfQualifierShort:
    839859                                size = sizeof(unsigned short);
    840                                 number = (uint64_t) va_arg(ap, unsigned int);
     860                                number = PRINTF_GET_INT_ARGUMENT(int, ap, flags);
    841861                                break;
    842862                        case PrintfQualifierInt:
    843863                                size = sizeof(unsigned int);
    844                                 number = (uint64_t) va_arg(ap, unsigned int);
     864                                number = PRINTF_GET_INT_ARGUMENT(int, ap, flags);
    845865                                break;
    846866                        case PrintfQualifierLong:
    847867                                size = sizeof(unsigned long);
    848                                 number = (uint64_t) va_arg(ap, unsigned long);
     868                                number = PRINTF_GET_INT_ARGUMENT(long, ap, flags);
    849869                                break;
    850870                        case PrintfQualifierLongLong:
    851871                                size = sizeof(unsigned long long);
    852                                 number = (uint64_t) va_arg(ap, unsigned long long);
     872                                number = PRINTF_GET_INT_ARGUMENT(long long, ap, flags);
    853873                                break;
    854874                        case PrintfQualifierPointer:
     
    865885                                counter = -counter;
    866886                                goto out;
    867                         }
    868                        
    869                         if (flags & __PRINTF_FLAG_SIGNED) {
    870                                 if (number & (0x1 << (size * 8 - 1))) {
    871                                         flags |= __PRINTF_FLAG_NEGATIVE;
    872                                        
    873                                         if (size == sizeof(uint64_t)) {
    874                                                 number = -((int64_t) number);
    875                                         } else {
    876                                                 number = ~number;
    877                                                 number &=
    878                                                     ~(0xFFFFFFFFFFFFFFFFll <<
    879                                                     (size * 8));
    880                                                 number++;
    881                                         }
    882                                 }
    883887                        }
    884888                       
  • uspace/lib/c/generic/ipc.c

    rd2c67e7 r8ff0bd2  
    4747#include <futex.h>
    4848#include <fibril.h>
     49#include <macros.h>
    4950
    5051/**
     
    458459        while (!list_empty(&queued_calls)) {
    459460                async_call_t *call =
    460                     list_get_instance(queued_calls.next, async_call_t, list);
     461                    list_get_instance(list_first(&queued_calls), async_call_t, list);
    461462                ipc_callid_t callid =
    462463                    ipc_call_async_internal(call->u.msg.phoneid, &call->u.msg.data);
     
    511512       
    512513        link_t *item;
    513         for (item = dispatched_calls.next; item != &dispatched_calls;
     514        for (item = dispatched_calls.head.next; item != &dispatched_calls.head;
    514515            item = item->next) {
    515516                async_call_t *call =
     
    611612/** Request callback connection.
    612613 *
    613  * The @a taskhash and @a phonehash identifiers returned
     614 * The @a task_id and @a phonehash identifiers returned
    614615 * by the kernel can be used for connection tracking.
    615616 *
     
    618619 * @param arg2      User defined argument.
    619620 * @param arg3      User defined argument.
    620  * @param taskhash  Opaque identifier of the client task.
     621 * @param task_id   Identifier of the client task.
    621622 * @param phonehash Opaque identifier of the phone that will
    622623 *                  be used for incoming calls.
     
    626627 */
    627628int ipc_connect_to_me(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    628     sysarg_t *taskhash, sysarg_t *phonehash)
    629 {
    630         return ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2,
    631             arg3, NULL, NULL, NULL, taskhash, phonehash);
     629    task_id_t *task_id, sysarg_t *phonehash)
     630{
     631        ipc_call_t data;
     632        int rc = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid,
     633            IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, (sysarg_t) &data);
     634        if (rc == EOK) {
     635                *task_id = data.in_task_id;
     636                *phonehash = IPC_GET_ARG5(data);
     637        }       
     638        return rc;
    632639}
    633640
  • uspace/lib/c/generic/libc.c

    rd2c67e7 r8ff0bd2  
    9191                argc = 0;
    9292                argv = NULL;
    93                 __stdio_init(0, NULL);
     93                __stdio_init(0);
    9494        } else {
    9595                argc = __pcb->argc;
    9696                argv = __pcb->argv;
    97                 __stdio_init(__pcb->filc, __pcb->filv);
     97                __stdio_init(__pcb->filc);
    9898                (void) chdir(__pcb->cwd);
    9999        }
  • uspace/lib/c/generic/loader.c

    rd2c67e7 r8ff0bd2  
    256256 *
    257257 */
    258 int loader_set_files(loader_t *ldr, fdi_node_t *const files[])
    259 {
    260         /*
    261          * Serialize the arguments into a single array. First
    262          * compute size of the buffer needed.
    263          */
    264         fdi_node_t *const *ap = files;
    265         size_t count = 0;
    266         while (*ap != NULL) {
    267                 count++;
    268                 ap++;
    269         }
    270        
    271         fdi_node_t *files_buf;
    272         files_buf = (fdi_node_t *) malloc(count * sizeof(fdi_node_t));
    273         if (files_buf == NULL)
    274                 return ENOMEM;
    275        
    276         /* Fill the buffer */
    277         size_t i;
    278         for (i = 0; i < count; i++)
    279                 files_buf[i] = *files[i];
    280        
     258int loader_set_files(loader_t *ldr, int * const files[])
     259{
    281260        /* Send serialized files to the loader */
    282261        async_exch_t *exch = async_exchange_begin(ldr->sess);
    283        
    284         ipc_call_t answer;
    285         aid_t req = async_send_0(exch, LOADER_SET_FILES, &answer);
    286         sysarg_t rc = async_data_write_start(exch, (void *) files_buf,
    287             count * sizeof(fdi_node_t));
    288        
    289         async_exchange_end(exch);
    290         free(files_buf);
    291        
     262        async_exch_t *vfs_exch = vfs_exchange_begin();
     263       
     264        int i;
     265        for (i = 0; files[i]; i++);
     266
     267        ipc_call_t answer;
     268        aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer);
     269
     270        sysarg_t rc = EOK;
     271       
     272        for (i = 0; files[i]; i++) {
     273                rc = async_state_change_start(exch, VFS_PASS_HANDLE, *files[i],
     274                    0, vfs_exch);
     275                if (rc != EOK)
     276                        break;
     277        }
     278       
     279        vfs_exchange_end(vfs_exch);
     280        async_exchange_end(exch);
     281
    292282        if (rc != EOK) {
    293283                async_wait_for(req, NULL);
  • uspace/lib/c/generic/net/icmp_api.c

    rd2c67e7 r8ff0bd2  
    4242#include <net/ip_codes.h>
    4343#include <async.h>
    44 #include <async_obsolete.h>
    4544#include <sys/types.h>
    4645#include <sys/time.h>
     
    5554 * timeout occurs.
    5655 *
    57  * @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
     56 * @param[in] sess The ICMP session.
    5857 * @param[in] size      The message data length in bytes.
    5958 * @param[in] timeout   The timeout in milliseconds.
     
    7473 */
    7574int
    76 icmp_echo_msg(int icmp_phone, size_t size, mseconds_t timeout, ip_ttl_t ttl,
     75icmp_echo_msg(async_sess_t *sess, size_t size, mseconds_t timeout, ip_ttl_t ttl,
    7776    ip_tos_t tos, int dont_fragment, const struct sockaddr *addr,
    7877    socklen_t addrlen)
     
    8382        if (addrlen <= 0)
    8483                return EINVAL;
    85 
    86         message_id = async_obsolete_send_5(icmp_phone, NET_ICMP_ECHO, size, timeout, ttl,
     84       
     85        async_exch_t *exch = async_exchange_begin(sess);
     86       
     87        message_id = async_send_5(exch, NET_ICMP_ECHO, size, timeout, ttl,
    8788            tos, (sysarg_t) dont_fragment, NULL);
    88 
     89       
    8990        /* Send the address */
    90         async_obsolete_data_write_start(icmp_phone, addr, (size_t) addrlen);
     91        async_data_write_start(exch, addr, (size_t) addrlen);
     92       
     93        async_exchange_end(exch);
    9194
    9295        async_wait_for(message_id, &result);
  • uspace/lib/c/generic/net/icmp_common.c

    rd2c67e7 r8ff0bd2  
    4545/** Connect to the ICMP module.
    4646 *
    47  * @param[in] timeout Connection timeout in microseconds, zero
    48  *                    for no timeout.
    49  *
    50  * @return ICMP module phone on success.
    51  * @return ETIMEOUT if the connection timeouted.
     47 * @return ICMP module session.
    5248 *
    5349 */
    54 int icmp_connect_module(suseconds_t timeout)
     50async_sess_t *icmp_connect_module(void)
    5551{
    56         return connect_to_service_timeout(SERVICE_ICMP, timeout);
     52        return connect_to_service(SERVICE_ICMP);
    5753}
    5854
  • uspace/lib/c/generic/net/modules.c

    rd2c67e7 r8ff0bd2  
    4040
    4141#include <async.h>
    42 #include <async_obsolete.h>
    4342#include <malloc.h>
    4443#include <errno.h>
     
    4746#include <net/modules.h>
    4847#include <ns.h>
    49 #include <ns_obsolete.h>
    50 
    51 /** The time between connect requests in microseconds. */
    52 #define MODULE_WAIT_TIME  (10 * 1000)
    5348
    5449/** Answer a call.
     
    9893}
    9994
    100 /** Create bidirectional connection with the needed module service and registers
     95/** Create bidirectional connection with the needed module service and register
    10196 * the message receiver.
    10297 *
    103  * @param[in] need      The needed module service.
    104  * @param[in] arg1      The first parameter.
    105  * @param[in] arg2      The second parameter.
    106  * @param[in] arg3      The third parameter.
    107  * @param[in] client_receiver The message receiver.
    108  *
    109  * @return              The phone of the needed service.
    110  * @return              Other error codes as defined for the ipc_connect_to_me()
    111  *                      function.
    112  */
    113 int bind_service(services_t need, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    114     async_client_conn_t client_receiver)
    115 {
    116         return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0);
    117 }
    118 
    119 /** Create bidirectional connection with the needed module service and registers
    120  * the message receiver.
    121  *
    122  * @param[in] need      The needed module service.
    123  * @param[in] arg1      The first parameter.
    124  * @param[in] arg2      The second parameter.
    125  * @param[in] arg3      The third parameter.
    126  * @param[in] client_receiver The message receiver.
    127  * @param[in] timeout   The connection timeout in microseconds. No timeout if
    128  *                      set to zero (0).
    129  *
    130  * @return              The phone of the needed service.
    131  * @return              ETIMEOUT if the connection timeouted.
    132  * @return              Other error codes as defined for the ipc_connect_to_me()
    133  *                      function.
    134  *
    135  */
    136 int bind_service_timeout(services_t need, sysarg_t arg1, sysarg_t arg2,
    137     sysarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
     98 * @param[in] need            Needed module service.
     99 * @param[in] arg1            First parameter.
     100 * @param[in] arg2            Second parameter.
     101 * @param[in] arg3            Third parameter.
     102 * @param[in] client_receiver Message receiver.
     103 *
     104 * @return Session to the needed service.
     105 * @return Other error codes as defined for the async_connect_to_me()
     106 *         function.
     107 *
     108 */
     109async_sess_t *bind_service(services_t need, sysarg_t arg1, sysarg_t arg2,
     110    sysarg_t arg3, async_client_conn_t client_receiver)
    138111{
    139112        /* Connect to the needed service */
    140         int phone = connect_to_service_timeout(need, timeout);
    141         if (phone >= 0) {
     113        async_sess_t *sess = connect_to_service(need);
     114        if (sess != NULL) {
    142115                /* Request the bidirectional connection */
    143                 int rc = async_obsolete_connect_to_me(phone, arg1, arg2, arg3, client_receiver);
     116                async_exch_t *exch = async_exchange_begin(sess);
     117                int rc = async_connect_to_me(exch, arg1, arg2, arg3,
     118                    client_receiver, NULL);
     119                async_exchange_end(exch);
     120               
    144121                if (rc != EOK) {
    145                         async_obsolete_hangup(phone);
    146                         return rc;
     122                        async_hangup(sess);
     123                        errno = rc;
     124                        return NULL;
    147125                }
    148126        }
    149127       
    150         return phone;
    151 }
    152 
    153 /** Connects to the needed module.
    154  *
    155  * @param[in] need      The needed module service.
    156  * @return              The phone of the needed service.
    157  */
    158 int connect_to_service(services_t need)
    159 {
    160         return connect_to_service_timeout(need, 0);
    161 }
    162 
    163 /** Connects to the needed module.
    164  *
    165  *  @param[in] need     The needed module service.
    166  *  @param[in] timeout  The connection timeout in microseconds. No timeout if
    167  *                      set to zero (0).
    168  *  @return             The phone of the needed service.
    169  *  @return             ETIMEOUT if the connection timeouted.
    170  */
    171 int connect_to_service_timeout(services_t need, suseconds_t timeout)
    172 {
    173         int phone;
    174 
    175         /* If no timeout is set */
    176         if (timeout <= 0)
    177                 return service_obsolete_connect_blocking(need, 0, 0);
    178        
    179         while (true) {
    180                 phone = service_obsolete_connect(need, 0, 0);
    181                 if ((phone >= 0) || (phone != ENOENT))
    182                         return phone;
    183 
    184                 /* Abort if no time is left */
    185                 if (timeout <= 0)
    186                         return ETIMEOUT;
    187 
    188                 /* Wait the minimum of the module wait time and the timeout */
    189                 usleep((timeout <= MODULE_WAIT_TIME) ?
    190                     timeout : MODULE_WAIT_TIME);
    191                 timeout -= MODULE_WAIT_TIME;
    192         }
    193 }
    194 
    195 /** Replies the data to the other party.
    196  *
    197  * @param[in] data      The data buffer to be sent.
     128        return sess;
     129}
     130
     131/** Connect to the needed module.
     132 *
     133 * @param[in] need Needed module service.
     134 *
     135 * @return Session to the needed service.
     136 * @return NULL if the connection timeouted.
     137 *
     138 */
     139async_sess_t *connect_to_service(services_t need)
     140{
     141        return service_connect_blocking(EXCHANGE_SERIALIZE, need, 0, 0);
     142}
     143
     144/** Reply the data to the other party.
     145 *
     146 * @param[in] data        The data buffer to be sent.
    198147 * @param[in] data_length The buffer length.
    199  * @return              EOK on success.
    200  * @return              EINVAL if the client does not expect the data.
    201  * @return              EOVERFLOW if the client does not expect all the data.
    202  *                      Only partial data are transfered.
    203  * @return              Other error codes as defined for the
    204  *                      async_data_read_finalize() function.
     148 *
     149 * @return EOK on success.
     150 * @return EINVAL if the client does not expect the data.
     151 * @return EOVERFLOW if the client does not expect all the data.
     152 *         Only partial data are transfered.
     153 * @return Other error codes as defined for the
     154 *         async_data_read_finalize() function.
     155 *
    205156 */
    206157int data_reply(void *data, size_t data_length)
     
    208159        size_t length;
    209160        ipc_callid_t callid;
    210 
     161       
    211162        /* Fetch the request */
    212163        if (!async_data_read_receive(&callid, &length))
    213164                return EINVAL;
    214 
     165       
    215166        /* Check the requested data size */
    216167        if (length < data_length) {
     
    218169                return EOVERFLOW;
    219170        }
    220 
     171       
    221172        /* Send the data */
    222173        return async_data_read_finalize(callid, data, data_length);
  • uspace/lib/c/generic/net/socket_client.c

    rd2c67e7 r8ff0bd2  
    3939#include <assert.h>
    4040#include <async.h>
    41 #include <async_obsolete.h>
    4241#include <fibril_synch.h>
    4342#include <stdint.h>
     
    6564#define SOCKET_MAX_ACCEPTED_SIZE        0
    6665
    67 /** Default timeout for connections in microseconds. */
    68 #define SOCKET_CONNECT_TIMEOUT  (1 * 1000 * 1000)
    69 
    7066/**
    7167 * Maximum number of random attempts to find a new socket identifier before
     
    8783        /** Socket identifier. */
    8884        int socket_id;
    89         /** Parent module phone. */
    90         int phone;
     85        /** Parent module session. */
     86        async_sess_t *sess;
    9187        /** Parent module service. */
    9288        services_t service;
     
    147143/** Socket client library global data. */
    148144static struct socket_client_globals {
    149         /** TCP module phone. */
    150         int tcp_phone;
    151         /** UDP module phone. */
    152         int udp_phone;
    153 
    154 //      /** The last socket identifier.
    155 //       */
    156 //      int last_id;
     145        /** TCP module session. */
     146        async_sess_t *tcp_sess;
     147        /** UDP module session. */
     148        async_sess_t *udp_sess;
    157149
    158150        /** Active sockets. */
     
    167159        fibril_rwlock_t lock;
    168160} socket_globals = {
    169         .tcp_phone = -1,
    170         .udp_phone = -1,
    171 //      .last_id = 0,
     161        .tcp_sess = NULL,
     162        .udp_sess = NULL,
    172163        .sockets = NULL,
    173164        .lock = FIBRIL_RWLOCK_INITIALIZER(socket_globals.lock)
     
    203194 * @param[in] iid       The initial message identifier.
    204195 * @param[in] icall     The initial message call structure.
    205  */
    206 static void socket_connection(ipc_callid_t iid, ipc_call_t * icall)
     196 * @param[in] arg       Local argument.
     197 */
     198static void socket_connection(ipc_callid_t iid, ipc_call_t * icall, void *arg)
    207199{
    208200        ipc_callid_t callid;
     
    282274}
    283275
    284 /** Returns the TCP module phone.
    285  *
    286  * Connects to the TCP module if necessary.
    287  *
    288  * @return              The TCP module phone.
    289  * @return              Other error codes as defined for the
    290  *                      bind_service_timeout() function.
    291  */
    292 static int socket_get_tcp_phone(void)
    293 {
    294         if (socket_globals.tcp_phone < 0) {
    295                 socket_globals.tcp_phone = bind_service_timeout(SERVICE_TCP,
    296                     0, 0, SERVICE_TCP, socket_connection,
    297                     SOCKET_CONNECT_TIMEOUT);
    298         }
    299 
    300         return socket_globals.tcp_phone;
    301 }
    302 
    303 /** Returns the UDP module phone.
    304  *
    305  * Connects to the UDP module if necessary.
    306  *
    307  * @return              The UDP module phone.
    308  * @return              Other error codes as defined for the
    309  *                      bind_service_timeout() function.
    310  */
    311 static int socket_get_udp_phone(void)
    312 {
    313         if (socket_globals.udp_phone < 0) {
    314                 socket_globals.udp_phone = bind_service_timeout(SERVICE_UDP,
    315                     0, 0, SERVICE_UDP, socket_connection,
    316                     SOCKET_CONNECT_TIMEOUT);
    317         }
    318 
    319         return socket_globals.udp_phone;
     276/** Return the TCP module session.
     277 *
     278 * Connect to the TCP module if necessary.
     279 *
     280 * @return The TCP module session.
     281 *
     282 */
     283static async_sess_t *socket_get_tcp_sess(void)
     284{
     285        if (socket_globals.tcp_sess == NULL) {
     286                socket_globals.tcp_sess = bind_service(SERVICE_TCP,
     287                    0, 0, SERVICE_TCP, socket_connection);
     288        }
     289
     290        return socket_globals.tcp_sess;
     291}
     292
     293/** Return the UDP module session.
     294 *
     295 * Connect to the UDP module if necessary.
     296 *
     297 * @return The UDP module session.
     298 *
     299 */
     300static async_sess_t *socket_get_udp_sess(void)
     301{
     302        if (socket_globals.udp_sess == NULL) {
     303                socket_globals.udp_sess = bind_service(SERVICE_UDP,
     304                    0, 0, SERVICE_UDP, socket_connection);
     305        }
     306
     307        return socket_globals.udp_sess;
    320308}
    321309
     
    333321        sockets = socket_get_sockets();
    334322        count = 0;
    335 //      socket_id = socket_globals.last_id;
    336323
    337324        do {
     
    346333                        if (socket_id < INT_MAX) {
    347334                                ++socket_id;
    348 /*                      } else if(socket_globals.last_id) {
    349  *                              socket_globals.last_id = 0;
    350  *                              socket_id = 1;
    351  */                     } else {
     335                        } else {
    352336                                return ELIMIT;
    353337                        }
    354338                }
    355339        } while (sockets_find(sockets, socket_id));
    356 
    357 //      last_id = socket_id
     340       
    358341        return socket_id;
    359342}
     
    362345 *
    363346 * @param[in,out] socket The socket to be initialized.
    364  * @param[in] socket_id The new socket identifier.
    365  * @param[in] phone     The parent module phone.
    366  * @param[in] service   The parent module service.
    367  */
    368 static void
    369 socket_initialize(socket_t *socket, int socket_id, int phone,
    370     services_t service)
     347 * @param[in] socket_id  The new socket identifier.
     348 * @param[in] sess       The parent module session.
     349 * @param[in] service    The parent module service.
     350 */
     351static void socket_initialize(socket_t *socket, int socket_id,
     352    async_sess_t *sess, services_t service)
    371353{
    372354        socket->socket_id = socket_id;
    373         socket->phone = phone;
     355        socket->sess = sess;
    374356        socket->service = service;
    375357        dyn_fifo_initialize(&socket->received, SOCKET_INITIAL_RECEIVED_SIZE);
     
    396378 * @return              Other error codes as defined for the NET_SOCKET message.
    397379 * @return              Other error codes as defined for the
    398  *                      bind_service_timeout() function.
     380 *                      bind_service() function.
    399381 */
    400382int socket(int domain, int type, int protocol)
    401383{
    402384        socket_t *socket;
    403         int phone;
     385        async_sess_t *sess;
    404386        int socket_id;
    405387        services_t service;
     
    418400                        switch (protocol) {
    419401                        case IPPROTO_TCP:
    420                                 phone = socket_get_tcp_phone();
     402                                sess = socket_get_tcp_sess();
    421403                                service = SERVICE_TCP;
    422404                                break;
     
    433415                        switch (protocol) {
    434416                        case IPPROTO_UDP:
    435                                 phone = socket_get_udp_phone();
     417                                sess = socket_get_udp_sess();
    436418                                service = SERVICE_UDP;
    437419                                break;
     
    454436        }
    455437
    456         if (phone < 0)
    457                 return phone;
     438        if (sess == NULL)
     439                return ENOENT;
    458440
    459441        /* Create a new socket structure */
     
    472454                return socket_id;
    473455        }
    474 
    475         rc = (int) async_obsolete_req_3_3(phone, NET_SOCKET, socket_id, 0, service, NULL,
     456       
     457        async_exch_t *exch = async_exchange_begin(sess);
     458        rc = (int) async_req_3_3(exch, NET_SOCKET, socket_id, 0, service, NULL,
    476459            &fragment_size, &header_size);
     460        async_exchange_end(exch);
     461       
    477462        if (rc != EOK) {
    478463                fibril_rwlock_write_unlock(&socket_globals.lock);
     
    485470
    486471        /* Finish the new socket initialization */
    487         socket_initialize(socket, socket_id, phone, service);
     472        socket_initialize(socket, socket_id, sess, service);
    488473        /* Store the new socket */
    489474        rc = sockets_add(socket_get_sockets(), socket_id, socket);
     
    494479                dyn_fifo_destroy(&socket->accepted);
    495480                free(socket);
    496                 async_obsolete_msg_3(phone, NET_SOCKET_CLOSE, (sysarg_t) socket_id, 0,
     481               
     482                exch = async_exchange_begin(sess);
     483                async_msg_3(exch, NET_SOCKET_CLOSE, (sysarg_t) socket_id, 0,
    497484                    service);
     485                async_exchange_end(exch);
     486               
    498487                return rc;
    499488        }
     
    539528
    540529        /* Request the message */
    541         message_id = async_obsolete_send_3(socket->phone, message,
     530        async_exch_t *exch = async_exchange_begin(socket->sess);
     531        message_id = async_send_3(exch, message,
    542532            (sysarg_t) socket->socket_id, arg2, socket->service, NULL);
    543533        /* Send the address */
    544         async_obsolete_data_write_start(socket->phone, data, datalength);
     534        async_data_write_start(exch, data, datalength);
     535        async_exchange_end(exch);
    545536
    546537        fibril_rwlock_read_unlock(&socket_globals.lock);
     
    599590
    600591        /* Request listen backlog change */
    601         result = (int) async_obsolete_req_3_0(socket->phone, NET_SOCKET_LISTEN,
     592        async_exch_t *exch = async_exchange_begin(socket->sess);
     593        result = (int) async_req_3_0(exch, NET_SOCKET_LISTEN,
    602594            (sysarg_t) socket->socket_id, (sysarg_t) backlog, socket->service);
     595        async_exchange_end(exch);
    603596
    604597        fibril_rwlock_read_unlock(&socket_globals.lock);
     
    670663                return socket_id;
    671664        }
    672         socket_initialize(new_socket, socket_id, socket->phone,
     665        socket_initialize(new_socket, socket_id, socket->sess,
    673666            socket->service);
    674667        result = sockets_add(socket_get_sockets(), new_socket->socket_id,
     
    682675
    683676        /* Request accept */
    684         message_id = async_obsolete_send_5(socket->phone, NET_SOCKET_ACCEPT,
     677        async_exch_t *exch = async_exchange_begin(socket->sess);
     678        message_id = async_send_5(exch, NET_SOCKET_ACCEPT,
    685679            (sysarg_t) socket->socket_id, 0, socket->service, 0,
    686680            new_socket->socket_id, &answer);
    687681
    688682        /* Read address */
    689         async_obsolete_data_read_start(socket->phone, cliaddr, *addrlen);
     683        async_data_read_start(exch, cliaddr, *addrlen);
     684        async_exchange_end(exch);
     685       
    690686        fibril_rwlock_write_unlock(&socket_globals.lock);
    691687        async_wait_for(message_id, &ipc_result);
     
    781777
    782778        /* Request close */
    783         rc = (int) async_obsolete_req_3_0(socket->phone, NET_SOCKET_CLOSE,
     779        async_exch_t *exch = async_exchange_begin(socket->sess);
     780        rc = (int) async_req_3_0(exch, NET_SOCKET_CLOSE,
    784781            (sysarg_t) socket->socket_id, 0, socket->service);
     782        async_exchange_end(exch);
     783       
    785784        if (rc != EOK) {
    786785                fibril_rwlock_write_unlock(&socket_globals.lock);
     
    854853
    855854        /* Request send */
    856         message_id = async_obsolete_send_5(socket->phone, message,
     855        async_exch_t *exch = async_exchange_begin(socket->sess);
     856       
     857        message_id = async_send_5(exch, message,
    857858            (sysarg_t) socket->socket_id,
    858859            (fragments == 1 ? datalength : socket->data_fragment_size),
     
    861862        /* Send the address if given */
    862863        if (!toaddr ||
    863             (async_obsolete_data_write_start(socket->phone, toaddr, addrlen) == EOK)) {
     864            (async_data_write_start(exch, toaddr, addrlen) == EOK)) {
    864865                if (fragments == 1) {
    865866                        /* Send all if only one fragment */
    866                         async_obsolete_data_write_start(socket->phone, data, datalength);
     867                        async_data_write_start(exch, data, datalength);
    867868                } else {
    868869                        /* Send the first fragment */
    869                         async_obsolete_data_write_start(socket->phone, data,
     870                        async_data_write_start(exch, data,
    870871                            socket->data_fragment_size - socket->header_size);
    871872                        data = ((const uint8_t *) data) +
     
    874875                        /* Send the middle fragments */
    875876                        while (--fragments > 1) {
    876                                 async_obsolete_data_write_start(socket->phone, data,
     877                                async_data_write_start(exch, data,
    877878                                    socket->data_fragment_size);
    878879                                data = ((const uint8_t *) data) +
     
    881882
    882883                        /* Send the last fragment */
    883                         async_obsolete_data_write_start(socket->phone, data,
     884                        async_data_write_start(exch, data,
    884885                            (datalength + socket->header_size) %
    885886                            socket->data_fragment_size);
    886887                }
    887888        }
     889       
     890        async_exchange_end(exch);
    888891
    889892        async_wait_for(message_id, &result);
     
    10271030                return 0;
    10281031        }
     1032       
     1033        async_exch_t *exch = async_exchange_begin(socket->sess);
    10291034
    10301035        /* Prepare lengths if more fragments */
     
    10391044
    10401045                /* Request packet data */
    1041                 message_id = async_obsolete_send_4(socket->phone, message,
     1046                message_id = async_send_4(exch, message,
    10421047                    (sysarg_t) socket->socket_id, 0, socket->service,
    10431048                    (sysarg_t) flags, &answer);
     
    10451050                /* Read the address if desired */
    10461051                if(!fromaddr ||
    1047                     (async_obsolete_data_read_start(socket->phone, fromaddr,
     1052                    (async_data_read_start(exch, fromaddr,
    10481053                    *addrlen) == EOK)) {
    10491054                        /* Read the fragment lengths */
    1050                         if (async_obsolete_data_read_start(socket->phone, lengths,
     1055                        if (async_data_read_start(exch, lengths,
    10511056                            sizeof(int) * (fragments + 1)) == EOK) {
    10521057                                if (lengths[fragments] <= datalength) {
     
    10551060                                        for (index = 0; index < fragments;
    10561061                                            ++index) {
    1057                                                 async_obsolete_data_read_start(
    1058                                                     socket->phone, data,
     1062                                                async_data_read_start(exch, data,
    10591063                                                    lengths[index]);
    10601064                                                data = ((uint8_t *) data) +
     
    10681072        } else { /* fragments == 1 */
    10691073                /* Request packet data */
    1070                 message_id = async_obsolete_send_4(socket->phone, message,
     1074                message_id = async_send_4(exch, message,
    10711075                    (sysarg_t) socket->socket_id, 0, socket->service,
    10721076                    (sysarg_t) flags, &answer);
     
    10741078                /* Read the address if desired */
    10751079                if (!fromaddr ||
    1076                     (async_obsolete_data_read_start(socket->phone, fromaddr,
    1077                         *addrlen) == EOK)) {
     1080                    (async_data_read_start(exch, fromaddr, *addrlen) == EOK)) {
    10781081                        /* Read all if only one fragment */
    1079                         async_obsolete_data_read_start(socket->phone, data, datalength);
     1082                        async_data_read_start(exch, data, datalength);
    10801083                }
    10811084        }
     1085       
     1086        async_exchange_end(exch);
    10821087
    10831088        async_wait_for(message_id, &ipc_result);
     
    11911196
    11921197        /* Request option value */
    1193         message_id = async_obsolete_send_3(socket->phone, NET_SOCKET_GETSOCKOPT,
     1198        async_exch_t *exch = async_exchange_begin(socket->sess);
     1199       
     1200        message_id = async_send_3(exch, NET_SOCKET_GETSOCKOPT,
    11941201            (sysarg_t) socket->socket_id, (sysarg_t) optname, socket->service,
    11951202            NULL);
    11961203
    11971204        /* Read the length */
    1198         if (async_obsolete_data_read_start(socket->phone, optlen,
     1205        if (async_data_read_start(exch, optlen,
    11991206            sizeof(*optlen)) == EOK) {
    12001207                /* Read the value */
    1201                 async_obsolete_data_read_start(socket->phone, value, *optlen);
    1202         }
     1208                async_data_read_start(exch, value, *optlen);
     1209        }
     1210       
     1211        async_exchange_end(exch);
    12031212
    12041213        fibril_rwlock_read_unlock(&socket_globals.lock);
  • uspace/lib/c/generic/ns.c

    rd2c67e7 r8ff0bd2  
    4242{
    4343        async_exch_t *exch = async_exchange_begin(session_ns);
    44         int rc = async_connect_to_me(exch, service, 0, 0, NULL);
     44        int rc = async_connect_to_me(exch, service, 0, 0, NULL, NULL);
    4545        async_exchange_end(exch);
    4646       
     
    5656        async_exchange_end(exch);
    5757       
     58        /*
     59         * FIXME Ugly hack to work around limitation of implementing
     60         * parallel exchanges using multiple connections. Shift out
     61         * first argument for non-initial connections.
     62         */
     63        async_sess_args_set(sess, arg2, arg3, 0);
     64       
    5865        return sess;
    5966}
     
    6673            async_connect_me_to_blocking(mgmt, exch, service, arg2, arg3);
    6774        async_exchange_end(exch);
     75       
     76        /*
     77         * FIXME Ugly hack to work around limitation of implementing
     78         * parallel exchanges using multiple connections. Shift out
     79         * first argument for non-initial connections.
     80         */
     81        async_sess_args_set(sess, arg2, arg3, 0);
    6882       
    6983        return sess;
  • uspace/lib/c/generic/ns_obsolete.c

    rd2c67e7 r8ff0bd2  
    3636#include <async_obsolete.h>
    3737#include <ns_obsolete.h>
    38 #include <kernel/ipc/ipc_methods.h>
     38#include <abi/ipc/methods.h>
    3939
    4040int service_obsolete_connect(sysarg_t service, sysarg_t arg2, sysarg_t arg3)
  • uspace/lib/c/generic/private/async.h

    rd2c67e7 r8ff0bd2  
    3636#define LIBC_PRIVATE_ASYNC_H_
    3737
     38#include <async.h>
    3839#include <adt/list.h>
    3940#include <fibril.h>
     41#include <fibril_synch.h>
    4042#include <sys/time.h>
    4143#include <bool.h>
     44
     45/** Session data */
     46struct _async_sess {
     47        /** List of inactive exchanges */
     48        list_t exch_list;
     49       
     50        /** Exchange management style */
     51        exch_mgmt_t mgmt;
     52       
     53        /** Session identification */
     54        int phone;
     55       
     56        /** First clone connection argument */
     57        sysarg_t arg1;
     58       
     59        /** Second clone connection argument */
     60        sysarg_t arg2;
     61       
     62        /** Third clone connection argument */
     63        sysarg_t arg3;
     64       
     65        /** Exchange mutex */
     66        fibril_mutex_t mutex;
     67       
     68        /** Number of opened exchanges */
     69        atomic_t refcnt;
     70       
     71        /** Mutex for stateful connections */
     72        fibril_mutex_t remote_state_mtx;
     73       
     74        /** Data for stateful connections */
     75        void *remote_state_data;
     76};
     77
     78/** Exchange data */
     79struct _async_exch {
     80        /** Link into list of inactive exchanges */
     81        link_t sess_link;
     82       
     83        /** Link into global list of inactive exchanges */
     84        link_t global_link;
     85       
     86        /** Session pointer */
     87        async_sess_t *sess;
     88       
     89        /** Exchange identification */
     90        int phone;
     91};
    4292
    4393/** Structures of this type are used to track the timeout events. */
  • uspace/lib/c/generic/private/io.h

    rd2c67e7 r8ff0bd2  
    3636#define LIBC_PRIVATE_IO_H_
    3737
    38 #include <vfs/vfs.h>
    39 
    40 extern void __stdio_init(int filc, fdi_node_t *filv[]);
     38extern void __stdio_init(int);
    4139extern void __stdio_done(void);
    4240
  • uspace/lib/c/generic/private/thread.h

    rd2c67e7 r8ff0bd2  
    3636#define LIBC_PRIVATE_THREAD_H_
    3737
    38 #include <kernel/proc/uarg.h>
     38#include <abi/proc/uarg.h>
    3939
    4040extern void __thread_entry(void);
  • uspace/lib/c/generic/rtld/module.c

    rd2c67e7 r8ff0bd2  
    3535 */
    3636
     37#include <adt/list.h>
     38#include <elf/elf_load.h>
     39#include <fcntl.h>
     40#include <loader/pcb.h>
    3741#include <stdio.h>
    3842#include <stdlib.h>
    3943#include <unistd.h>
    40 #include <fcntl.h>
    41 #include <adt/list.h>
    42 #include <loader/pcb.h>
    4344
    4445#include <rtld/rtld.h>
     
    4748#include <rtld/rtld_arch.h>
    4849#include <rtld/module.h>
    49 #include <elf_load.h>
    5050
    5151/** (Eagerly) process all relocation tables in a module.
     
    9393module_t *module_find(const char *name)
    9494{
    95         link_t *head = &runtime_env->modules_head;
    96 
    97         link_t *cur;
    9895        module_t *m;
    9996        const char *p, *soname;
     
    110107
    111108        /* Traverse list of all modules. Not extremely fast, but simple */
    112         DPRINTF("head = %p\n", head);
    113         for (cur = head->next; cur != head; cur = cur->next) {
     109        list_foreach(runtime_env->modules, cur) {
    114110                DPRINTF("cur = %p\n", cur);
    115111                m = list_get_instance(cur, module_t, modules_link);
     
    177173
    178174        /* Insert into the list of loaded modules */
    179         list_append(&m->modules_link, &runtime_env->modules_head);
     175        list_append(&m->modules_link, &runtime_env->modules);
    180176
    181177        return m;
     
    249245void modules_process_relocs(module_t *start)
    250246{
    251         link_t *head = &runtime_env->modules_head;
    252 
    253         link_t *cur;
    254         module_t *m;
    255 
    256         for (cur = head->next; cur != head; cur = cur->next) {
     247        module_t *m;
     248
     249        list_foreach(runtime_env->modules, cur) {
    257250                m = list_get_instance(cur, module_t, modules_link);
    258251
     
    268261void modules_untag(void)
    269262{
    270         link_t *head = &runtime_env->modules_head;
    271 
    272         link_t *cur;
    273         module_t *m;
    274 
    275         for (cur = head->next; cur != head; cur = cur->next) {
     263        module_t *m;
     264
     265        list_foreach(runtime_env->modules, cur) {
    276266                m = list_get_instance(cur, module_t, modules_link);
    277267                m->bfs_tag = false;
  • uspace/lib/c/generic/rtld/rtld.c

    rd2c67e7 r8ff0bd2  
    4444{
    4545        runtime_env = &rt_env_static;
    46         list_initialize(&runtime_env->modules_head);
     46        list_initialize(&runtime_env->modules);
    4747        runtime_env->next_bias = 0x2000000;
    4848        runtime_env->program = NULL;
  • uspace/lib/c/generic/rtld/symbol.c

    rd2c67e7 r8ff0bd2  
    3838#include <stdlib.h>
    3939
     40#include <elf/elf.h>
    4041#include <rtld/rtld.h>
    4142#include <rtld/rtld_debug.h>
    4243#include <rtld/symbol.h>
    43 #include <elf.h>
    4444
    4545/*
     
    118118        module_t *m, *dm;
    119119        elf_symbol_t *sym, *s;
    120         link_t queue_head;
     120        list_t queue;
    121121        size_t i;
    122122
     
    132132
    133133        /* Insert root (the program) into the queue and tag it */
    134         list_initialize(&queue_head);
     134        list_initialize(&queue);
    135135        start->bfs_tag = true;
    136         list_append(&start->queue_link, &queue_head);
     136        list_append(&start->queue_link, &queue);
    137137
    138138        /* If the symbol is found, it will be stored in 'sym' */
     
    140140
    141141        /* While queue is not empty */
    142         while (!list_empty(&queue_head)) {
     142        while (!list_empty(&queue)) {
    143143                /* Pop first element from the queue */
    144                 m = list_get_instance(queue_head.next, module_t, queue_link);
     144                m = list_get_instance(list_first(&queue), module_t, queue_link);
    145145                list_remove(&m->queue_link);
    146146
     
    162162                        if (dm->bfs_tag == false) {
    163163                                dm->bfs_tag = true;
    164                                 list_append(&dm->queue_link, &queue_head);
     164                                list_append(&dm->queue_link, &queue);
    165165                        }
    166166                }
     
    168168
    169169        /* Empty the queue so that we leave it in a clean state */
    170         while (!list_empty(&queue_head))
    171                 list_remove(queue_head.next);
     170        while (!list_empty(&queue))
     171                list_remove(list_first(&queue));
    172172
    173173        if (!sym) {
  • uspace/lib/c/generic/str.c

    rd2c67e7 r8ff0bd2  
    22 * Copyright (c) 2005 Martin Decky
    33 * Copyright (c) 2008 Jiri Svoboda
     4 * Copyright (c) 2011 Martin Sucha
     5 * Copyright (c) 2011 Oleg Romanenko
    46 * All rights reserved.
    57 *
     
    540542
    541543        dstr_size = str_size(dest);
     544        if (dstr_size >= size)
     545                return;
     546       
    542547        str_cpy(dest + dstr_size, size - dstr_size, src);
     548}
     549
     550/** Convert space-padded ASCII to string.
     551 *
     552 * Common legacy text encoding in hardware is 7-bit ASCII fitted into
     553 * a fixed-width byte buffer (bit 7 always zero), right-padded with spaces
     554 * (ASCII 0x20). Convert space-padded ascii to string representation.
     555 *
     556 * If the text does not fit into the destination buffer, the function converts
     557 * as many characters as possible and returns EOVERFLOW.
     558 *
     559 * If the text contains non-ASCII bytes (with bit 7 set), the whole string is
     560 * converted anyway and invalid characters are replaced with question marks
     561 * (U_SPECIAL) and the function returns EIO.
     562 *
     563 * Regardless of return value upon return @a dest will always be well-formed.
     564 *
     565 * @param dest          Destination buffer
     566 * @param size          Size of destination buffer
     567 * @param src           Space-padded ASCII.
     568 * @param n             Size of the source buffer in bytes.
     569 *
     570 * @return              EOK on success, EOVERFLOW if the text does not fit
     571 *                      destination buffer, EIO if the text contains
     572 *                      non-ASCII bytes.
     573 */
     574int spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n)
     575{
     576        size_t sidx;
     577        size_t didx;
     578        size_t dlast;
     579        uint8_t byte;
     580        int rc;
     581        int result;
     582
     583        /* There must be space for a null terminator in the buffer. */
     584        assert(size > 0);
     585        result = EOK;
     586
     587        didx = 0;
     588        dlast = 0;
     589        for (sidx = 0; sidx < n; ++sidx) {
     590                byte = src[sidx];
     591                if (!ascii_check(byte)) {
     592                        byte = U_SPECIAL;
     593                        result = EIO;
     594                }
     595
     596                rc = chr_encode(byte, dest, &didx, size - 1);
     597                if (rc != EOK) {
     598                        assert(rc == EOVERFLOW);
     599                        dest[didx] = '\0';
     600                        return rc;
     601                }
     602
     603                /* Remember dest index after last non-empty character */
     604                if (byte != 0x20)
     605                        dlast = didx;
     606        }
     607
     608        /* Terminate string after last non-empty character */
     609        dest[dlast] = '\0';
     610        return result;
    543611}
    544612
     
    572640        dest[dest_off] = '\0';
    573641}
     642
     643/** Convert UTF16 string to string.
     644 *
     645 * Convert utf16 string @a src to string. The output is written to the buffer
     646 * specified by @a dest and @a size. @a size must be non-zero and the string
     647 * written will always be well-formed. Surrogate pairs also supported.
     648 *
     649 * @param dest  Destination buffer.
     650 * @param size  Size of the destination buffer.
     651 * @param src   Source utf16 string.
     652 *
     653 * @return EOK, if success, negative otherwise.
     654 */
     655int utf16_to_str(char *dest, size_t size, const uint16_t *src)
     656{
     657        size_t idx = 0, dest_off = 0;
     658        wchar_t ch;
     659        int rc = EOK;
     660
     661        /* There must be space for a null terminator in the buffer. */
     662        assert(size > 0);
     663
     664        while (src[idx]) {
     665                if ((src[idx] & 0xfc00) == 0xd800) {
     666                        if (src[idx + 1] && (src[idx + 1] & 0xfc00) == 0xdc00) {
     667                                ch = 0x10000;
     668                                ch += (src[idx] & 0x03FF) << 10;
     669                                ch += (src[idx + 1] & 0x03FF);
     670                                idx += 2;
     671                        }
     672                        else
     673                                break;
     674                } else {
     675                        ch = src[idx];
     676                        idx++;
     677                }
     678                rc = chr_encode(ch, dest, &dest_off, size - 1);
     679                if (rc != EOK)
     680                        break;
     681        }
     682        dest[dest_off] = '\0';
     683        return rc;
     684}
     685
     686int str_to_utf16(uint16_t *dest, size_t size, const char *src)
     687{
     688        int rc = EOK;
     689        size_t offset = 0;
     690        size_t idx = 0;
     691        wchar_t c;
     692
     693        assert(size > 0);
     694       
     695        while ((c = str_decode(src, &offset, STR_NO_LIMIT)) != 0) {
     696                if (c > 0x10000) {
     697                        if (idx + 2 >= size - 1) {
     698                                rc = EOVERFLOW;
     699                                break;
     700                        }
     701                        c = (c - 0x10000);
     702                        dest[idx] = 0xD800 | (c >> 10);
     703                        dest[idx + 1] = 0xDC00 | (c & 0x3FF);
     704                        idx++;
     705                } else {
     706                         dest[idx] = c;
     707                }
     708
     709                idx++;
     710                if (idx >= size - 1) {
     711                        rc = EOVERFLOW;
     712                        break;
     713                }
     714        }
     715
     716        dest[idx] = '\0';
     717        return rc;
     718}
     719
    574720
    575721/** Convert wide string to new string.
     
    652798
    653799        dest[dlen - 1] = '\0';
     800}
     801
     802/** Convert string to wide string.
     803 *
     804 * Convert string @a src to wide string. A new wide NULL-terminated
     805 * string will be allocated on the heap.
     806 *
     807 * @param src   Source string.
     808 */
     809wchar_t *str_to_awstr(const char *str)
     810{
     811        size_t len = str_length(str);
     812       
     813        wchar_t *wstr = calloc(len+1, sizeof(wchar_t));
     814        if (wstr == NULL)
     815                return NULL;
     816       
     817        str_to_wstr(wstr, len + 1, str);
     818        return wstr;
    654819}
    655820
     
    9501115        return dest;
    9511116}
    952 
    9531117
    9541118/** Convert initial part of string to unsigned long according to given base.
  • uspace/lib/c/generic/sysinfo.c

    rd2c67e7 r8ff0bd2  
    4747 *
    4848 */
    49 sysinfo_item_tag_t sysinfo_get_tag(const char *path)
     49sysinfo_item_val_type_t sysinfo_get_val_type(const char *path)
    5050{
    51         return (sysinfo_item_tag_t) __SYSCALL2(SYS_SYSINFO_GET_TAG,
     51        return (sysinfo_item_val_type_t) __SYSCALL2(SYS_SYSINFO_GET_VAL_TYPE,
    5252            (sysarg_t) path, (sysarg_t) str_size(path));
    5353}
  • uspace/lib/c/generic/task.c

    rd2c67e7 r8ff0bd2  
    4646#include <libc.h>
    4747#include "private/ns.h"
     48#include <vfs/vfs.h>
    4849
    4950task_id_t task_get_id(void)
     
    100101 */
    101102int task_spawnv(task_id_t *id, const char *path, const char *const args[])
     103{
     104        /* Send default files */
     105        int *files[4];
     106        int fd_stdin;
     107        int fd_stdout;
     108        int fd_stderr;
     109       
     110        if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
     111                files[0] = &fd_stdin;
     112        else
     113                files[0] = NULL;
     114       
     115        if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
     116                files[1] = &fd_stdout;
     117        else
     118                files[1] = NULL;
     119       
     120        if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
     121                files[2] = &fd_stderr;
     122        else
     123                files[2] = NULL;
     124       
     125        files[3] = NULL;
     126       
     127        return task_spawnvf(id, path, args, files);
     128}
     129
     130/** Create a new task by running an executable from the filesystem.
     131 *
     132 * This is really just a convenience wrapper over the more complicated
     133 * loader API. Arguments are passed as a null-terminated array of strings.
     134 * Files are passed as null-terminated array of pointers to fdi_node_t.
     135 *
     136 * @param id    If not NULL, the ID of the task is stored here on success.
     137 * @param path  Pathname of the binary to execute.
     138 * @param argv  Command-line arguments.
     139 * @param files Standard files to use.
     140 *
     141 * @return Zero on success or negative error code.
     142 *
     143 */
     144int task_spawnvf(task_id_t *id, const char *path, const char *const args[],
     145    int *const files[])
    102146{
    103147        /* Connect to a program loader. */
     
    127171                goto error;
    128172       
    129         /* Send default files */
    130         fdi_node_t *files[4];
    131         fdi_node_t stdin_node;
    132         fdi_node_t stdout_node;
    133         fdi_node_t stderr_node;
    134        
    135         if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
    136                 files[0] = &stdin_node;
    137         else
    138                 files[0] = NULL;
    139        
    140         if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
    141                 files[1] = &stdout_node;
    142         else
    143                 files[1] = NULL;
    144        
    145         if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
    146                 files[2] = &stderr_node;
    147         else
    148                 files[2] = NULL;
    149        
    150         files[3] = NULL;
    151        
     173        /* Send files */
    152174        rc = loader_set_files(ldr, files);
    153175        if (rc != EOK)
  • uspace/lib/c/generic/thread.c

    rd2c67e7 r8ff0bd2  
    3737#include <stdlib.h>
    3838#include <libarch/faddr.h>
    39 #include <kernel/proc/uarg.h>
     39#include <abi/proc/uarg.h>
    4040#include <fibril.h>
    4141#include <str.h>
  • uspace/lib/c/generic/time.c

    rd2c67e7 r8ff0bd2  
    3636#include <time.h>
    3737#include <bool.h>
    38 #include <arch/barrier.h>
     38#include <libarch/barrier.h>
    3939#include <macros.h>
    4040#include <errno.h>
  • uspace/lib/c/generic/udebug.c

    rd2c67e7 r8ff0bd2  
    3535#include <udebug.h>
    3636#include <sys/types.h>
    37 #include <kernel/ipc/ipc_methods.h>
     37#include <abi/ipc/methods.h>
    3838#include <async.h>
    3939
  • uspace/lib/c/generic/vfs/vfs.c

    rd2c67e7 r8ff0bd2  
    5151#include <assert.h>
    5252#include <str.h>
    53 #include <devmap.h>
     53#include <loc.h>
    5454#include <ipc/vfs.h>
    55 #include <ipc/devmap.h>
     55#include <ipc/loc.h>
    5656
    5757static FIBRIL_MUTEX_INITIALIZE(vfs_mutex);
     
    6969 *
    7070 */
    71 static async_exch_t *vfs_exchange_begin(void)
     71async_exch_t *vfs_exchange_begin(void)
    7272{
    7373        fibril_mutex_lock(&vfs_mutex);
     
    8787 *
    8888 */
    89 static void vfs_exchange_end(async_exch_t *exch)
     89void vfs_exchange_end(async_exch_t *exch)
    9090{
    9191        async_exchange_end(exch);
     
    142142}
    143143
    144 int mount(const char *fs_name, const char *mp, const char *fqdn,
     144int mount(const char *fs_name, const char *mp, const char *fqsn,
    145145    const char *opts, unsigned int flags)
    146146{
    147147        int null_id = -1;
    148         char null[DEVMAP_NAME_MAXLEN];
    149        
    150         if (str_cmp(fqdn, "") == 0) {
     148        char null[LOC_NAME_MAXLEN];
     149       
     150        if (str_cmp(fqsn, "") == 0) {
    151151                /* No device specified, create a fresh
    152152                   null/%d device instead */
    153                 null_id = devmap_null_create();
     153                null_id = loc_null_create();
    154154               
    155155                if (null_id == -1)
    156156                        return ENOMEM;
    157157               
    158                 snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id);
    159                 fqdn = null;
    160         }
    161        
    162         devmap_handle_t devmap_handle;
    163         int res = devmap_device_get_handle(fqdn, &devmap_handle, flags);
     158                snprintf(null, LOC_NAME_MAXLEN, "null/%d", null_id);
     159                fqsn = null;
     160        }
     161       
     162        service_id_t service_id;
     163        int res = loc_service_get_id(fqsn, &service_id, flags);
    164164        if (res != EOK) {
    165165                if (null_id != -1)
    166                         devmap_null_destroy(null_id);
     166                        loc_null_destroy(null_id);
    167167               
    168168                return res;
     
    173173        if (!mpa) {
    174174                if (null_id != -1)
    175                         devmap_null_destroy(null_id);
     175                        loc_null_destroy(null_id);
    176176               
    177177                return ENOMEM;
     
    181181
    182182        sysarg_t rc_orig;
    183         aid_t req = async_send_2(exch, VFS_IN_MOUNT, devmap_handle, flags, NULL);
     183        aid_t req = async_send_2(exch, VFS_IN_MOUNT, service_id, flags, NULL);
    184184        sysarg_t rc = async_data_write_start(exch, (void *) mpa, mpa_size);
    185185        if (rc != EOK) {
     
    189189               
    190190                if (null_id != -1)
    191                         devmap_null_destroy(null_id);
     191                        loc_null_destroy(null_id);
    192192               
    193193                if (rc_orig == EOK)
     
    204204               
    205205                if (null_id != -1)
    206                         devmap_null_destroy(null_id);
     206                        loc_null_destroy(null_id);
    207207               
    208208                if (rc_orig == EOK)
     
    219219               
    220220                if (null_id != -1)
    221                         devmap_null_destroy(null_id);
     221                        loc_null_destroy(null_id);
    222222               
    223223                if (rc_orig == EOK)
     
    235235               
    236236                if (null_id != -1)
    237                         devmap_null_destroy(null_id);
     237                        loc_null_destroy(null_id);
    238238               
    239239                if (rc_orig == EOK)
     
    248248       
    249249        if ((rc != EOK) && (null_id != -1))
    250                 devmap_null_destroy(null_id);
     250                loc_null_destroy(null_id);
    251251       
    252252        return (int) rc;
     
    329329}
    330330
    331 int open_node(fdi_node_t *node, int oflag)
    332 {
    333         async_exch_t *exch = vfs_exchange_begin();
    334        
    335         ipc_call_t answer;
    336         aid_t req = async_send_4(exch, VFS_IN_OPEN_NODE, node->fs_handle,
    337             node->devmap_handle, node->index, oflag, &answer);
    338        
    339         vfs_exchange_end(exch);
    340 
    341         sysarg_t rc;
    342         async_wait_for(req, &rc);
    343        
    344         if (rc != EOK)
    345                 return (int) rc;
    346        
    347         return (int) IPC_GET_ARG1(answer);
    348 }
    349 
    350331int close(int fildes)
    351332{
     
    415396        else
    416397                return -1;
     398}
     399
     400/** Read entire buffer.
     401 *
     402 * In face of short reads this function continues reading until either
     403 * the entire buffer is read or no more data is available (at end of file).
     404 *
     405 * @param fildes        File descriptor
     406 * @param buf           Buffer, @a nbytes bytes long
     407 * @param nbytes        Number of bytes to read
     408 *
     409 * @return              On success, positive number of bytes read.
     410 *                      On failure, negative error code from read().
     411 */
     412ssize_t read_all(int fildes, void *buf, size_t nbyte)
     413{
     414        ssize_t cnt = 0;
     415        size_t nread = 0;
     416        uint8_t *bp = (uint8_t *) buf;
     417
     418        do {
     419                bp += cnt;
     420                nread += cnt;
     421                cnt = read(fildes, bp, nbyte - nread);
     422        } while (cnt > 0 && (nbyte - nread - cnt) > 0);
     423
     424        if (cnt < 0)
     425                return cnt;
     426
     427        return nread + cnt;
     428}
     429
     430/** Write entire buffer.
     431 *
     432 * This function fails if it cannot write exactly @a len bytes to the file.
     433 *
     434 * @param fildes        File descriptor
     435 * @param buf           Data, @a nbytes bytes long
     436 * @param nbytes        Number of bytes to write
     437 *
     438 * @return              EOK on error, return value from write() if writing
     439 *                      failed.
     440 */
     441ssize_t write_all(int fildes, const void *buf, size_t nbyte)
     442{
     443        ssize_t cnt = 0;
     444        ssize_t nwritten = 0;
     445        const uint8_t *bp = (uint8_t *) buf;
     446
     447        do {
     448                bp += cnt;
     449                nwritten += cnt;
     450                cnt = write(fildes, bp, nbyte - nwritten);
     451        } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0);
     452
     453        if (cnt < 0)
     454                return cnt;
     455
     456        if ((ssize_t)nbyte - nwritten - cnt > 0)
     457                return EIO;
     458
     459        return nbyte;
    417460}
    418461
     
    749792        }
    750793       
    751         if (!stat.device) {
     794        if (!stat.service) {
    752795                errno = ENOENT;
    753796                return NULL;
    754797        }
    755798       
    756         return devmap_device_connect(mgmt, stat.device, 0);
    757 }
    758 
    759 int fd_node(int fildes, fdi_node_t *node)
    760 {
    761         struct stat stat;
    762         int rc = fstat(fildes, &stat);
    763        
    764         if (rc == EOK) {
    765                 node->fs_handle = stat.fs_handle;
    766                 node->devmap_handle = stat.devmap_handle;
    767                 node->index = stat.index;
    768         }
    769        
    770         return rc;
     799        return loc_service_connect(mgmt, stat.service, 0);
    771800}
    772801
     
    786815}
    787816
     817int fd_wait(void)
     818{
     819        async_exch_t *exch = vfs_exchange_begin();
     820       
     821        sysarg_t ret;
     822        sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret);
     823       
     824        vfs_exchange_end(exch);
     825       
     826        if (rc == EOK)
     827                return (int) ret;
     828       
     829        return (int) rc;
     830}
     831
    788832/** @}
    789833 */
Note: See TracChangeset for help on using the changeset viewer.