Changeset 925a21e in mainline for uspace/lib/c/generic


Ignore:
Timestamp:
2011-09-24T14:20:29Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5bf76c1
Parents:
867e2555 (diff), 1ab4aca (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:
2 added
3 deleted
26 edited

Legend:

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

    r867e2555 r925a21e  
    152152       
    153153        if (keys == h->max_keys) {
    154                 link_t *cur;
    155                
    156154                /*
    157155                 * All keys are known, hash_table_find() can be used to find the
     
    159157                 */
    160158               
    161                 cur = hash_table_find(h, key);
     159                link_t *cur = hash_table_find(h, key);
    162160                if (cur) {
    163161                        list_remove(cur);
     
    174172        hash_index_t chain;
    175173        for (chain = 0; chain < h->entries; chain++) {
    176                 link_t *cur;
    177                
    178                 for (cur = h->entry[chain].head.next; cur != &h->entry[chain].head;
     174                for (link_t *cur = h->entry[chain].head.next;
     175                    cur != &h->entry[chain].head;
    179176                    cur = cur->next) {
    180177                        if (h->op->compare(key, keys, cur)) {
     
    193190}
    194191
    195 /** Apply fucntion to all items in hash table.
     192/** Apply function to all items in hash table.
    196193 *
    197194 * @param h   Hash table.
  • uspace/lib/c/generic/adt/list.c

    r867e2555 r925a21e  
    3333/**
    3434 * @file
    35  * @brief       Functions completing doubly linked circular list implementaion.
     35 * @brief       Functions completing doubly linked circular list implementation.
    3636 *
    3737 * This file contains some of the functions implementing doubly linked circular lists.
     
    5050 * @param list  List to look in.
    5151 *
    52  * @return true if link is contained in head, false otherwise.
     52 * @return true if link is contained in list, false otherwise.
    5353 *
    5454 */
  • uspace/lib/c/generic/as.c

    r867e2555 r925a21e  
    123123 * @retval ENOENT Mapping not found.
    124124 */
    125 int as_get_physical_mapping(void *address, uintptr_t *frame)
     125int as_get_physical_mapping(const void *address, uintptr_t *frame)
    126126{
    127127        uintptr_t tmp_frame;
  • uspace/lib/c/generic/async.c

    r867e2555 r925a21e  
    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
    117118#define CONN_HASH_TABLE_BUCKETS    32
     119
     120/** Session data */
     121struct async_sess {
     122        /** List of inactive exchanges */
     123        list_t exch_list;
     124       
     125        /** Exchange management style */
     126        exch_mgmt_t mgmt;
     127       
     128        /** Session identification */
     129        int phone;
     130       
     131        /** First clone connection argument */
     132        sysarg_t arg1;
     133       
     134        /** Second clone connection argument */
     135        sysarg_t arg2;
     136       
     137        /** Third clone connection argument */
     138        sysarg_t arg3;
     139       
     140        /** Exchange mutex */
     141        fibril_mutex_t mutex;
     142       
     143        /** Number of opened exchanges */
     144        atomic_t refcnt;
     145       
     146        /** Mutex for stateful connections */
     147        fibril_mutex_t remote_state_mtx;
     148       
     149        /** Data for stateful connections */
     150        void *remote_state_data;
     151};
     152
     153/** Exchange data */
     154struct async_exch {
     155        /** Link into list of inactive exchanges */
     156        link_t sess_link;
     157       
     158        /** Link into global list of inactive exchanges */
     159        link_t global_link;
     160       
     161        /** Session pointer */
     162        async_sess_t *sess;
     163       
     164        /** Exchange identification */
     165        int phone;
     166};
    118167
    119168/** Async framework global futex */
     
    134183} msg_t;
    135184
     185/** Message data */
     186typedef struct {
     187        awaiter_t wdata;
     188       
     189        /** If reply was received. */
     190        bool done;
     191       
     192        /** Pointer to where the answer data is stored. */
     193        ipc_call_t *dataptr;
     194       
     195        sysarg_t retval;
     196} amsg_t;
     197
    136198/* Client connection data */
    137199typedef struct {
    138200        link_t link;
    139201       
    140         sysarg_t in_task_hash;
     202        task_id_t in_task_id;
    141203        atomic_t refcnt;
    142204        void *data;
     
    150212        link_t link;
    151213       
    152         /** Incoming client task hash. */
    153         sysarg_t in_task_hash;
     214        /** Incoming client task ID. */
     215        task_id_t in_task_id;
    154216       
    155217        /** Incoming phone hash. */
     
    203265}
    204266
    205 void *async_get_client_data(void)
    206 {
    207         assert(fibril_connection);
    208         return fibril_connection->client->data;
    209 }
    210 
    211267/** Default fibril function that gets called to handle new connection.
    212268 *
     
    289345{
    290346        assert(key);
     347        assert(keys == 2);
    291348        assert(item);
    292349       
    293350        client_t *client = hash_table_get_instance(item, client_t, link);
    294         return (key[0] == client->in_task_hash);
     351        return (key[0] == LOWER32(client->in_task_id) &&
     352            (key[1] == UPPER32(client->in_task_id)));
    295353}
    296354
     
    580638}
    581639
     640static client_t *async_client_get(task_id_t client_id, bool create)
     641{
     642        unsigned long key[2] = {
     643                LOWER32(client_id),
     644                UPPER32(client_id),
     645        };
     646        client_t *client = NULL;
     647
     648        futex_down(&async_futex);
     649        link_t *lnk = hash_table_find(&client_hash_table, key);
     650        if (lnk) {
     651                client = hash_table_get_instance(lnk, client_t, link);
     652                atomic_inc(&client->refcnt);
     653        } else if (create) {
     654                client = malloc(sizeof(client_t));
     655                if (client) {
     656                        client->in_task_id = client_id;
     657                        client->data = async_client_data_create();
     658               
     659                        atomic_set(&client->refcnt, 1);
     660                        hash_table_insert(&client_hash_table, key, &client->link);
     661                }
     662        }
     663
     664        futex_up(&async_futex);
     665        return client;
     666}
     667
     668static void async_client_put(client_t *client)
     669{
     670        bool destroy;
     671        unsigned long key[2] = {
     672                LOWER32(client->in_task_id),
     673                UPPER32(client->in_task_id)
     674        };
     675       
     676        futex_down(&async_futex);
     677       
     678        if (atomic_predec(&client->refcnt) == 0) {
     679                hash_table_remove(&client_hash_table, key, 2);
     680                destroy = true;
     681        } else
     682                destroy = false;
     683       
     684        futex_up(&async_futex);
     685       
     686        if (destroy) {
     687                if (client->data)
     688                        async_client_data_destroy(client->data);
     689               
     690                free(client);
     691        }
     692}
     693
     694void *async_get_client_data(void)
     695{
     696        assert(fibril_connection);
     697        return fibril_connection->client->data;
     698}
     699
     700void *async_get_client_data_by_id(task_id_t client_id)
     701{
     702        client_t *client = async_client_get(client_id, false);
     703        if (!client)
     704                return NULL;
     705        if (!client->data) {
     706                async_client_put(client);
     707                return NULL;
     708        }
     709
     710        return client->data;
     711}
     712
     713void async_put_client_data_by_id(task_id_t client_id)
     714{
     715        client_t *client = async_client_get(client_id, false);
     716
     717        assert(client);
     718        assert(client->data);
     719
     720        /* Drop the reference we got in async_get_client_data_by_hash(). */
     721        async_client_put(client);
     722
     723        /* Drop our own reference we got at the beginning of this function. */
     724        async_client_put(client);
     725}
     726
    582727/** Wrapper for client connection fibril.
    583728 *
     
    598743         */
    599744        fibril_connection = (connection_t *) arg;
    600        
    601         futex_down(&async_futex);
    602745       
    603746        /*
     
    606749         * hash in a new tracking structure.
    607750         */
    608        
    609         unsigned long key = fibril_connection->in_task_hash;
    610         link_t *lnk = hash_table_find(&client_hash_table, &key);
    611        
    612         client_t *client;
    613        
    614         if (lnk) {
    615                 client = hash_table_get_instance(lnk, client_t, link);
    616                 atomic_inc(&client->refcnt);
    617         } else {
    618                 client = malloc(sizeof(client_t));
    619                 if (!client) {
    620                         ipc_answer_0(fibril_connection->callid, ENOMEM);
    621                         futex_up(&async_futex);
    622                         return 0;
    623                 }
    624                
    625                 client->in_task_hash = fibril_connection->in_task_hash;
    626                 client->data = async_client_data_create();
    627                
    628                 atomic_set(&client->refcnt, 1);
    629                 hash_table_insert(&client_hash_table, &key, &client->link);
    630         }
    631        
    632         futex_up(&async_futex);
    633        
     751
     752        client_t *client = async_client_get(fibril_connection->in_task_id, true);
     753        if (!client) {
     754                ipc_answer_0(fibril_connection->callid, ENOMEM);
     755                return 0;
     756        }
     757
    634758        fibril_connection->client = client;
    635759       
     
    643767         * Remove the reference for this client task connection.
    644768         */
    645         bool destroy;
    646        
    647         futex_down(&async_futex);
    648        
    649         if (atomic_predec(&client->refcnt) == 0) {
    650                 hash_table_remove(&client_hash_table, &key, 1);
    651                 destroy = true;
    652         } else
    653                 destroy = false;
    654        
    655         futex_up(&async_futex);
    656        
    657         if (destroy) {
    658                 if (client->data)
    659                         async_client_data_destroy(client->data);
    660                
    661                 free(client);
    662         }
     769        async_client_put(client);
    663770       
    664771        /*
     
    666773         */
    667774        futex_down(&async_futex);
    668         key = fibril_connection->in_phone_hash;
     775        unsigned long key = fibril_connection->in_phone_hash;
    669776        hash_table_remove(&conn_hash_table, &key, 1);
    670777        futex_up(&async_futex);
     
    700807 * particular fibrils.
    701808 *
    702  * @param in_task_hash  Identification of the incoming connection.
     809 * @param in_task_id    Identification of the incoming connection.
    703810 * @param in_phone_hash Identification of the incoming connection.
    704811 * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
     
    714821 *
    715822 */
    716 fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash,
     823fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
    717824    ipc_callid_t callid, ipc_call_t *call,
    718825    async_client_conn_t cfibril, void *carg)
     
    726833        }
    727834       
    728         conn->in_task_hash = in_task_hash;
     835        conn->in_task_id = in_task_id;
    729836        conn->in_phone_hash = in_phone_hash;
    730837        list_initialize(&conn->msg_queue);
     
    785892        case IPC_M_CONNECT_ME_TO:
    786893                /* Open new connection with fibril, etc. */
    787                 async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call),
     894                async_new_connection(call->in_task_id, IPC_GET_ARG5(*call),
    788895                    callid, call, client_connection, NULL);
    789896                return;
     
    9331040{
    9341041        if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS,
    935             1, &client_hash_table_ops))
     1042            2, &client_hash_table_ops))
    9361043                abort();
    9371044       
     
    9491056        session_ns->arg2 = 0;
    9501057        session_ns->arg3 = 0;
     1058       
     1059        fibril_mutex_initialize(&session_ns->remote_state_mtx);
     1060        session_ns->remote_state_data = NULL;
    9511061       
    9521062        list_initialize(&session_ns->exch_list);
     
    14261536                return ENOENT;
    14271537       
    1428         sysarg_t task_hash;
    14291538        sysarg_t phone_hash;
    1430         int rc = async_req_3_5(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
    1431             NULL, NULL, NULL, &task_hash, &phone_hash);
     1539        sysarg_t rc;
     1540
     1541        aid_t req;
     1542        ipc_call_t answer;
     1543        req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3,
     1544            &answer);
     1545        async_wait_for(req, &rc);
    14321546        if (rc != EOK)
    1433                 return rc;
    1434        
     1547                return (int) rc;
     1548
     1549        phone_hash = IPC_GET_ARG5(answer);
     1550
    14351551        if (client_receiver != NULL)
    1436                 async_new_connection(task_hash, phone_hash, 0, NULL,
     1552                async_new_connection(answer.in_task_id, phone_hash, 0, NULL,
    14371553                    client_receiver, carg);
    14381554       
     
    15091625        sess->arg3 = 0;
    15101626       
     1627        fibril_mutex_initialize(&sess->remote_state_mtx);
     1628        sess->remote_state_data = NULL;
     1629       
    15111630        list_initialize(&sess->exch_list);
    15121631        fibril_mutex_initialize(&sess->mutex);
     
    15901709        sess->arg3 = arg3;
    15911710       
     1711        fibril_mutex_initialize(&sess->remote_state_mtx);
     1712        sess->remote_state_data = NULL;
     1713       
    15921714        list_initialize(&sess->exch_list);
    15931715        fibril_mutex_initialize(&sess->mutex);
     
    15951717       
    15961718        return sess;
     1719}
     1720
     1721/** Set arguments for new connections.
     1722 *
     1723 * FIXME This is an ugly hack to work around the problem that parallel
     1724 * exchanges are implemented using parallel connections. When we create
     1725 * a callback session, the framework does not know arguments for the new
     1726 * connections.
     1727 *
     1728 * The proper solution seems to be to implement parallel exchanges using
     1729 * tagging.
     1730 */
     1731void async_sess_args_set(async_sess_t *sess, sysarg_t arg1, sysarg_t arg2,
     1732    sysarg_t arg3)
     1733{
     1734        sess->arg1 = arg1;
     1735        sess->arg2 = arg2;
     1736        sess->arg3 = arg3;
    15971737}
    15981738
     
    16401780        sess->arg3 = arg3;
    16411781       
     1782        fibril_mutex_initialize(&sess->remote_state_mtx);
     1783        sess->remote_state_data = NULL;
     1784       
    16421785        list_initialize(&sess->exch_list);
    16431786        fibril_mutex_initialize(&sess->mutex);
     
    16711814        sess->arg3 = 0;
    16721815       
     1816        fibril_mutex_initialize(&sess->remote_state_mtx);
     1817        sess->remote_state_data = NULL;
     1818       
    16731819        list_initialize(&sess->exch_list);
    16741820        fibril_mutex_initialize(&sess->mutex);
     
    16921838int async_hangup(async_sess_t *sess)
    16931839{
     1840        async_exch_t *exch;
     1841       
    16941842        assert(sess);
    16951843       
    16961844        if (atomic_get(&sess->refcnt) > 0)
    16971845                return EBUSY;
     1846       
     1847        fibril_mutex_lock(&async_sess_mutex);
    16981848       
    16991849        int rc = async_hangup_internal(sess->phone);
    17001850        if (rc == EOK)
    17011851                free(sess);
     1852       
     1853        while (!list_empty(&sess->exch_list)) {
     1854                exch = (async_exch_t *)
     1855                    list_get_instance(list_first(&sess->exch_list),
     1856                    async_exch_t, sess_link);
     1857               
     1858                list_remove(&exch->sess_link);
     1859                list_remove(&exch->global_link);
     1860                async_hangup_internal(exch->phone);
     1861                free(exch);
     1862        }
     1863       
     1864        fibril_mutex_unlock(&async_sess_mutex);
    17021865       
    17031866        return rc;
     
    23342497        sess->arg3 = 0;
    23352498       
     2499        fibril_mutex_initialize(&sess->remote_state_mtx);
     2500        sess->remote_state_data = NULL;
     2501       
    23362502        list_initialize(&sess->exch_list);
    23372503        fibril_mutex_initialize(&sess->mutex);
     
    23802546        sess->arg3 = 0;
    23812547       
     2548        fibril_mutex_initialize(&sess->remote_state_mtx);
     2549        sess->remote_state_data = NULL;
     2550       
    23822551        list_initialize(&sess->exch_list);
    23832552        fibril_mutex_initialize(&sess->mutex);
     
    24222591        sess->arg3 = 0;
    24232592       
     2593        fibril_mutex_initialize(&sess->remote_state_mtx);
     2594        sess->remote_state_data = NULL;
     2595       
    24242596        list_initialize(&sess->exch_list);
    24252597        fibril_mutex_initialize(&sess->mutex);
     
    24292601}
    24302602
     2603int async_state_change_start(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2,
     2604    sysarg_t arg3, async_exch_t *other_exch)
     2605{
     2606        return async_req_5_0(exch, IPC_M_STATE_CHANGE_AUTHORIZE,
     2607            arg1, arg2, arg3, 0, other_exch->phone);
     2608}
     2609
     2610bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1,
     2611    sysarg_t *arg2, sysarg_t *arg3)
     2612{
     2613        assert(callid);
     2614
     2615        ipc_call_t call;
     2616        *callid = async_get_call(&call);
     2617
     2618        if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE)
     2619                return false;
     2620       
     2621        if (arg1)
     2622                *arg1 = IPC_GET_ARG1(call);
     2623        if (arg2)
     2624                *arg2 = IPC_GET_ARG2(call);
     2625        if (arg3)
     2626                *arg3 = IPC_GET_ARG3(call);
     2627
     2628        return true;
     2629}
     2630
     2631int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch)
     2632{
     2633        return ipc_answer_1(callid, EOK, other_exch->phone);
     2634}
     2635
     2636/** Lock and get session remote state
     2637 *
     2638 * Lock and get the local replica of the remote state
     2639 * in stateful sessions. The call should be paired
     2640 * with async_remote_state_release*().
     2641 *
     2642 * @param[in] sess Stateful session.
     2643 *
     2644 * @return Local replica of the remote state.
     2645 *
     2646 */
     2647void *async_remote_state_acquire(async_sess_t *sess)
     2648{
     2649        fibril_mutex_lock(&sess->remote_state_mtx);
     2650        return sess->remote_state_data;
     2651}
     2652
     2653/** Update the session remote state
     2654 *
     2655 * Update the local replica of the remote state
     2656 * in stateful sessions. The remote state must
     2657 * be already locked.
     2658 *
     2659 * @param[in] sess  Stateful session.
     2660 * @param[in] state New local replica of the remote state.
     2661 *
     2662 */
     2663void async_remote_state_update(async_sess_t *sess, void *state)
     2664{
     2665        assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
     2666        sess->remote_state_data = state;
     2667}
     2668
     2669/** Release the session remote state
     2670 *
     2671 * Unlock the local replica of the remote state
     2672 * in stateful sessions.
     2673 *
     2674 * @param[in] sess Stateful session.
     2675 *
     2676 */
     2677void async_remote_state_release(async_sess_t *sess)
     2678{
     2679        assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
     2680       
     2681        fibril_mutex_unlock(&sess->remote_state_mtx);
     2682}
     2683
     2684/** Release the session remote state and end an exchange
     2685 *
     2686 * Unlock the local replica of the remote state
     2687 * in stateful sessions. This is convenience function
     2688 * which gets the session pointer from the exchange
     2689 * and also ends the exchange.
     2690 *
     2691 * @param[in] exch Stateful session's exchange.
     2692 *
     2693 */
     2694void async_remote_state_release_exchange(async_exch_t *exch)
     2695{
     2696        if (exch == NULL)
     2697                return;
     2698       
     2699        async_sess_t *sess = exch->sess;
     2700        assert(fibril_mutex_is_locked(&sess->remote_state_mtx));
     2701       
     2702        async_exchange_end(exch);
     2703        fibril_mutex_unlock(&sess->remote_state_mtx);
     2704}
     2705
    24312706/** @}
    24322707 */
  • uspace/lib/c/generic/ddi.c

    r867e2555 r925a21e  
    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

    r867e2555 r925a21e  
    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.
     
    8989                        if (devman_driver_block_sess == NULL)
    9090                                devman_driver_block_sess =
    91                                     service_connect_blocking(EXCHANGE_SERIALIZE,
     91                                    service_connect_blocking(EXCHANGE_PARALLEL,
    9292                                    SERVICE_DEVMAN, DEVMAN_DRIVER, 0);
    9393                }
     
    138138                if (devman_driver_sess == NULL)
    139139                        devman_driver_sess =
    140                             service_connect(EXCHANGE_SERIALIZE, SERVICE_DEVMAN,
     140                            service_connect(EXCHANGE_PARALLEL, SERVICE_DEVMAN,
    141141                            DEVMAN_DRIVER, 0);
    142142               
     
    195195       
    196196        exch = devman_exchange_begin(DEVMAN_DRIVER);
    197         async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
     197        async_connect_to_me(exch, 0, 0, 0, conn, NULL);
    198198        devman_exchange_end(exch);
    199199       
     
    271271}
    272272
    273 int devman_add_device_to_class(devman_handle_t devman_handle,
    274     const char *class_name)
     273int devman_add_device_to_category(devman_handle_t devman_handle,
     274    const char *cat_name)
    275275{
    276276        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
    277277       
    278278        ipc_call_t answer;
    279         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,
    280280            devman_handle, &answer);
    281         sysarg_t retval = async_data_write_start(exch, class_name,
    282             str_size(class_name));
     281        sysarg_t retval = async_data_write_start(exch, cat_name,
     282            str_size(cat_name));
    283283       
    284284        devman_exchange_end(exch);
     
    308308}
    309309
     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
    310353async_sess_t *devman_parent_device_connect(exch_mgmt_t mgmt,
    311354    devman_handle_t handle, unsigned int flags)
     
    323366}
    324367
    325 int devman_device_get_handle(const char *pathname, devman_handle_t *handle,
     368int devman_fun_get_handle(const char *pathname, devman_handle_t *handle,
    326369    unsigned int flags)
    327370{
     
    333376                exch = devman_exchange_begin(DEVMAN_CLIENT);
    334377                if (exch == NULL)
    335                         return errno;
     378                        return ENOMEM;
    336379        }
    337380       
     
    364407}
    365408
    366 int devman_device_get_handle_by_class(const char *classname,
    367     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)
    368411{
    369412        async_exch_t *exch;
    370        
    371         if (flags & IPC_FLAG_BLOCKING)
    372                 exch = devman_exchange_begin_blocking(DEVMAN_CLIENT);
    373         else {
    374                 exch = devman_exchange_begin(DEVMAN_CLIENT);
    375                 if (exch == NULL)
    376                         return errno;
    377         }
     413        ipc_call_t dreply;
     414        size_t act_size;
     415        sysarg_t dretval;
     416       
     417        exch = devman_exchange_begin_blocking(LOC_PORT_CONSUMER);
    378418       
    379419        ipc_call_t answer;
    380         aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
    381             flags, &answer);
    382         sysarg_t retval = async_data_write_start(exch, classname,
    383             str_size(classname));
    384        
    385         if (retval != EOK) {
    386                 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) {
    387427                async_wait_for(req, NULL);
    388                 return retval;
    389         }
    390        
    391         retval = async_data_write_start(exch, devname,
    392             str_size(devname));
    393        
    394         devman_exchange_end(exch);
    395        
    396         if (retval != EOK) {
    397                 async_wait_for(req, NULL);
    398                 return retval;
    399         }
    400        
     428                return dretval;
     429        }
     430       
     431        sysarg_t retval;
    401432        async_wait_for(req, &retval);
    402433       
    403         if (retval != EOK) {
    404                 if (handle != NULL)
    405                         *handle = (devman_handle_t) -1;
    406                
    407                 return retval;
    408         }
    409        
    410         if (handle != NULL)
    411                 *handle = (devman_handle_t) IPC_GET_ARG1(answer);
    412        
    413         return retval;
    414 }
    415 
    416 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)
    417457{
    418458        async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT);
    419459        if (exch == NULL)
    420                 return errno;
    421        
     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
    422485        ipc_call_t answer;
    423         aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_DEVICE_PATH,
    424             handle, &answer);
    425        
    426         ipc_call_t data_request_call;
    427         aid_t data_request = async_data_read(exch, path, path_size,
    428             &data_request_call);
    429        
    430         devman_exchange_end(exch);
    431        
    432         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) {
    433492                async_wait_for(req, NULL);
    434                 return ENOMEM;
    435         }
    436        
    437         sysarg_t data_request_rc;
    438         async_wait_for(data_request, &data_request_rc);
    439        
    440         sysarg_t opening_request_rc;
    441         async_wait_for(req, &opening_request_rc);
    442        
    443         if (data_request_rc != EOK) {
    444                 /* Prefer the return code of the opening request. */
    445                 if (opening_request_rc != EOK)
    446                         return (int) opening_request_rc;
    447                 else
    448                         return (int) data_request_rc;
    449         }
    450        
    451         if (opening_request_rc != EOK)
    452                 return (int) opening_request_rc;
    453        
    454         /* To be on the safe-side. */
    455         path[path_size - 1] = 0;
    456         size_t transferred_size = IPC_GET_ARG2(data_request_call);
    457         if (transferred_size >= path_size)
    458                 return ELIMIT;
    459        
    460         /* Terminate the string (trailing 0 not send over IPC). */
    461         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);
    462504        return EOK;
    463505}
    464506
     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
    465593/** @}
    466594 */
  • uspace/lib/c/generic/event.c

    r867e2555 r925a21e  
    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

    r867e2555 r925a21e  
    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>
  • uspace/lib/c/generic/io/console.c

    r867e2555 r925a21e  
    8787{
    8888        async_exch_t *exch = async_exchange_begin(ctrl->output_sess);
    89         async_msg_0(exch, CONSOLE_CLEAR);
     89        async_req_0_0(exch, CONSOLE_CLEAR);
    9090        async_exchange_end(exch);
    9191}
     
    103103{
    104104        async_exch_t *exch = async_exchange_begin(ctrl->output_sess);
    105         async_msg_1(exch, CONSOLE_SET_STYLE, style);
    106         async_exchange_end(exch);
    107 }
    108 
    109 void console_set_color(console_ctrl_t *ctrl, uint8_t fg_color, uint8_t bg_color,
     105        async_req_1_0(exch, CONSOLE_SET_STYLE, style);
     106        async_exchange_end(exch);
     107}
     108
     109void console_set_color(console_ctrl_t *ctrl, uint8_t bgcolor, uint8_t fgcolor,
    110110    uint8_t flags)
    111111{
    112112        async_exch_t *exch = async_exchange_begin(ctrl->output_sess);
    113         async_msg_3(exch, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
    114         async_exchange_end(exch);
    115 }
    116 
    117 void console_set_rgb_color(console_ctrl_t *ctrl, uint32_t fg_color,
    118     uint32_t bg_color)
    119 {
    120         async_exch_t *exch = async_exchange_begin(ctrl->output_sess);
    121         async_msg_2(exch, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
     113        async_req_3_0(exch, CONSOLE_SET_COLOR, bgcolor, fgcolor, flags);
     114        async_exchange_end(exch);
     115}
     116
     117void console_set_rgb_color(console_ctrl_t *ctrl, uint32_t bgcolor,
     118    uint32_t fgcolor)
     119{
     120        async_exch_t *exch = async_exchange_begin(ctrl->output_sess);
     121        async_req_2_0(exch, CONSOLE_SET_RGB_COLOR, bgcolor, fgcolor);
    122122        async_exchange_end(exch);
    123123}
     
    126126{
    127127        async_exch_t *exch = async_exchange_begin(ctrl->output_sess);
    128         async_msg_1(exch, CONSOLE_CURSOR_VISIBILITY, (show != false));
     128        async_req_1_0(exch, CONSOLE_CURSOR_VISIBILITY, (show != false));
    129129        async_exchange_end(exch);
    130130}
     
    151151{
    152152        async_exch_t *exch = async_exchange_begin(ctrl->output_sess);
    153         async_msg_2(exch, CONSOLE_GOTO, col, row);
     153        async_req_2_0(exch, CONSOLE_GOTO, col, row);
    154154        async_exchange_end(exch);
    155155}
  • uspace/lib/c/generic/io/io.c

    r867e2555 r925a21e  
    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;
     
    285285}
    286286
    287 FILE *fopen_node(fdi_node_t *node, const char *mode)
    288 {
    289         int flags;
    290         if (!parse_mode(mode, &flags))
    291                 return NULL;
    292        
    293         /* Open file. */
    294         FILE *stream = malloc(sizeof(FILE));
    295         if (stream == NULL) {
    296                 errno = ENOMEM;
    297                 return NULL;
    298         }
    299        
    300         stream->fd = open_node(node, flags);
    301         if (stream->fd < 0) {
    302                 /* errno was set by open_node() */
    303                 free(stream);
    304                 return NULL;
    305         }
    306        
    307         stream->error = false;
    308         stream->eof = false;
    309         stream->klog = false;
    310         stream->sess = NULL;
    311         stream->need_sync = false;
    312         _setvbuf(stream);
    313        
    314         list_append(&stream->link, &files);
    315        
    316         return stream;
    317 }
    318 
    319287int fclose(FILE *stream)
    320288{
     
    450418
    451419        bytes_used = stream->buf_head - stream->buf_tail;
    452         if (bytes_used == 0)
    453                 return;
    454420
    455421        /* If buffer has prefetched read data, we need to seek back. */
    456         if (stream->buf_state == _bs_read)
     422        if (bytes_used > 0 && stream->buf_state == _bs_read)
    457423                lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR);
    458424
    459425        /* If buffer has unwritten data, we need to write them out. */
    460         if (stream->buf_state == _bs_write)
     426        if (bytes_used > 0 && stream->buf_state == _bs_write)
    461427                (void) _fwrite(stream->buf_tail, 1, bytes_used, stream);
    462428
     
    780746}
    781747
    782 int fnode(FILE *stream, fdi_node_t *node)
    783 {
    784         if (stream->fd >= 0)
    785                 return fd_node(stream->fd, node);
     748int fhandle(FILE *stream, int *handle)
     749{
     750        if (stream->fd >= 0) {
     751                *handle = stream->fd;
     752                return EOK;
     753        }
    786754       
    787755        return ENOENT;
  • uspace/lib/c/generic/io/printf_core.c

    r867e2555 r925a21e  
    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

    r867e2555 r925a21e  
    4747#include <futex.h>
    4848#include <fibril.h>
     49#include <macros.h>
    4950
    5051/**
     
    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

    r867e2555 r925a21e  
    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

    r867e2555 r925a21e  
    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/malloc.c

    r867e2555 r925a21e  
    873873void free(const void *addr)
    874874{
     875        if (addr == NULL)
     876                return;
     877
    875878        futex_down(&malloc_futex);
    876879       
  • uspace/lib/c/generic/ns.c

    r867e2555 r925a21e  
    5252{
    5353        async_exch_t *exch = async_exchange_begin(session_ns);
     54        if (!exch)
     55                return NULL;
    5456        async_sess_t *sess =
    5557            async_connect_me_to(mgmt, exch, service, arg2, arg3);
    5658        async_exchange_end(exch);
     59
     60        if (!sess)
     61                return NULL;
     62       
     63        /*
     64         * FIXME Ugly hack to work around limitation of implementing
     65         * parallel exchanges using multiple connections. Shift out
     66         * first argument for non-initial connections.
     67         */
     68        async_sess_args_set(sess, arg2, arg3, 0);
    5769       
    5870        return sess;
     
    6678            async_connect_me_to_blocking(mgmt, exch, service, arg2, arg3);
    6779        async_exchange_end(exch);
     80       
     81        /*
     82         * FIXME Ugly hack to work around limitation of implementing
     83         * parallel exchanges using multiple connections. Shift out
     84         * first argument for non-initial connections.
     85         */
     86        async_sess_args_set(sess, arg2, arg3, 0);
    6887       
    6988        return sess;
  • uspace/lib/c/generic/private/async.h

    r867e2555 r925a21e  
    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>
     
    7981} awaiter_t;
    8082
    81 /** Message data */
    82 typedef struct {
    83         awaiter_t wdata;
    84        
    85         /** If reply was received. */
    86         bool done;
    87        
    88         /** Pointer to where the answer data is stored. */
    89         ipc_call_t *dataptr;
    90        
    91         sysarg_t retval;
    92 } amsg_t;
    93 
    9483extern void __async_init(void);
    9584extern void async_insert_timeout(awaiter_t *);
  • uspace/lib/c/generic/private/io.h

    r867e2555 r925a21e  
    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

    r867e2555 r925a21e  
    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/str.c

    r867e2555 r925a21e  
    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 *
     
    549551 *
    550552 * Common legacy text encoding in hardware is 7-bit ASCII fitted into
    551  * a fixed-with byte buffer (bit 7 always zero), right-padded with spaces
     553 * a fixed-width byte buffer (bit 7 always zero), right-padded with spaces
    552554 * (ASCII 0x20). Convert space-padded ascii to string representation.
    553555 *
     
    639641}
    640642
     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
     720
    641721/** Convert wide string to new string.
    642722 *
     
    718798
    719799        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;
    720819}
    721820
     
    10161115        return dest;
    10171116}
    1018 
    10191117
    10201118/** Convert initial part of string to unsigned long according to given base.
     
    11931291}
    11941292
     1293/** Convert string to uint8_t.
     1294 *
     1295 * @param nptr   Pointer to string.
     1296 * @param endptr If not NULL, pointer to the first invalid character
     1297 *               is stored here.
     1298 * @param base   Zero or number between 2 and 36 inclusive.
     1299 * @param strict Do not allow any trailing characters.
     1300 * @param result Result of the conversion.
     1301 *
     1302 * @return EOK if conversion was successful.
     1303 *
     1304 */
     1305int str_uint8_t(const char *nptr, char **endptr, unsigned int base,
     1306    bool strict, uint8_t *result)
     1307{
     1308        assert(result != NULL);
     1309       
     1310        bool neg;
     1311        char *lendptr;
     1312        uint64_t res;
     1313        int ret = str_uint(nptr, &lendptr, base, &neg, &res);
     1314       
     1315        if (endptr != NULL)
     1316                *endptr = (char *) lendptr;
     1317       
     1318        if (ret != EOK)
     1319                return ret;
     1320       
     1321        /* Do not allow negative values */
     1322        if (neg)
     1323                return EINVAL;
     1324       
     1325        /* Check whether we are at the end of
     1326           the string in strict mode */
     1327        if ((strict) && (*lendptr != 0))
     1328                return EINVAL;
     1329       
     1330        /* Check for overflow */
     1331        uint8_t _res = (uint8_t) res;
     1332        if (_res != res)
     1333                return EOVERFLOW;
     1334       
     1335        *result = _res;
     1336       
     1337        return EOK;
     1338}
     1339
     1340/** Convert string to uint16_t.
     1341 *
     1342 * @param nptr   Pointer to string.
     1343 * @param endptr If not NULL, pointer to the first invalid character
     1344 *               is stored here.
     1345 * @param base   Zero or number between 2 and 36 inclusive.
     1346 * @param strict Do not allow any trailing characters.
     1347 * @param result Result of the conversion.
     1348 *
     1349 * @return EOK if conversion was successful.
     1350 *
     1351 */
     1352int str_uint16_t(const char *nptr, char **endptr, unsigned int base,
     1353    bool strict, uint16_t *result)
     1354{
     1355        assert(result != NULL);
     1356       
     1357        bool neg;
     1358        char *lendptr;
     1359        uint64_t res;
     1360        int ret = str_uint(nptr, &lendptr, base, &neg, &res);
     1361       
     1362        if (endptr != NULL)
     1363                *endptr = (char *) lendptr;
     1364       
     1365        if (ret != EOK)
     1366                return ret;
     1367       
     1368        /* Do not allow negative values */
     1369        if (neg)
     1370                return EINVAL;
     1371       
     1372        /* Check whether we are at the end of
     1373           the string in strict mode */
     1374        if ((strict) && (*lendptr != 0))
     1375                return EINVAL;
     1376       
     1377        /* Check for overflow */
     1378        uint16_t _res = (uint16_t) res;
     1379        if (_res != res)
     1380                return EOVERFLOW;
     1381       
     1382        *result = _res;
     1383       
     1384        return EOK;
     1385}
     1386
     1387/** Convert string to uint32_t.
     1388 *
     1389 * @param nptr   Pointer to string.
     1390 * @param endptr If not NULL, pointer to the first invalid character
     1391 *               is stored here.
     1392 * @param base   Zero or number between 2 and 36 inclusive.
     1393 * @param strict Do not allow any trailing characters.
     1394 * @param result Result of the conversion.
     1395 *
     1396 * @return EOK if conversion was successful.
     1397 *
     1398 */
     1399int str_uint32_t(const char *nptr, char **endptr, unsigned int base,
     1400    bool strict, uint32_t *result)
     1401{
     1402        assert(result != NULL);
     1403       
     1404        bool neg;
     1405        char *lendptr;
     1406        uint64_t res;
     1407        int ret = str_uint(nptr, &lendptr, base, &neg, &res);
     1408       
     1409        if (endptr != NULL)
     1410                *endptr = (char *) lendptr;
     1411       
     1412        if (ret != EOK)
     1413                return ret;
     1414       
     1415        /* Do not allow negative values */
     1416        if (neg)
     1417                return EINVAL;
     1418       
     1419        /* Check whether we are at the end of
     1420           the string in strict mode */
     1421        if ((strict) && (*lendptr != 0))
     1422                return EINVAL;
     1423       
     1424        /* Check for overflow */
     1425        uint32_t _res = (uint32_t) res;
     1426        if (_res != res)
     1427                return EOVERFLOW;
     1428       
     1429        *result = _res;
     1430       
     1431        return EOK;
     1432}
     1433
    11951434/** Convert string to uint64_t.
    11961435 *
  • uspace/lib/c/generic/sysinfo.c

    r867e2555 r925a21e  
    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

    r867e2555 r925a21e  
    4646#include <libc.h>
    4747#include "private/ns.h"
     48#include <vfs/vfs.h>
    4849
    4950task_id_t task_get_id(void)
     
    102103{
    103104        /* Send default files */
    104         fdi_node_t *files[4];
    105         fdi_node_t stdin_node;
    106         fdi_node_t stdout_node;
    107         fdi_node_t stderr_node;
    108        
    109         if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
    110                 files[0] = &stdin_node;
     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;
    111112        else
    112113                files[0] = NULL;
    113114       
    114         if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
    115                 files[1] = &stdout_node;
     115        if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
     116                files[1] = &fd_stdout;
    116117        else
    117118                files[1] = NULL;
    118119       
    119         if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
    120                 files[2] = &stderr_node;
     120        if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
     121                files[2] = &fd_stderr;
    121122        else
    122123                files[2] = NULL;
     
    142143 */
    143144int task_spawnvf(task_id_t *id, const char *path, const char *const args[],
    144     fdi_node_t *const files[])
     145    int *const files[])
    145146{
    146147        /* Connect to a program loader. */
  • uspace/lib/c/generic/thread.c

    r867e2555 r925a21e  
    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

    r867e2555 r925a21e  
    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

    r867e2555 r925a21e  
    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

    r867e2555 r925a21e  
    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,
    145     const char *opts, unsigned int flags)
     144int mount(const char *fs_name, const char *mp, const char *fqsn,
     145    const char *opts, unsigned int flags, unsigned int instance)
    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_3(exch, VFS_IN_MOUNT, service_id, flags,
     184            instance, NULL);
    184185        sysarg_t rc = async_data_write_start(exch, (void *) mpa, mpa_size);
    185186        if (rc != EOK) {
     
    189190               
    190191                if (null_id != -1)
    191                         devmap_null_destroy(null_id);
     192                        loc_null_destroy(null_id);
    192193               
    193194                if (rc_orig == EOK)
     
    204205               
    205206                if (null_id != -1)
    206                         devmap_null_destroy(null_id);
     207                        loc_null_destroy(null_id);
    207208               
    208209                if (rc_orig == EOK)
     
    219220               
    220221                if (null_id != -1)
    221                         devmap_null_destroy(null_id);
     222                        loc_null_destroy(null_id);
    222223               
    223224                if (rc_orig == EOK)
     
    235236               
    236237                if (null_id != -1)
    237                         devmap_null_destroy(null_id);
     238                        loc_null_destroy(null_id);
    238239               
    239240                if (rc_orig == EOK)
     
    248249       
    249250        if ((rc != EOK) && (null_id != -1))
    250                 devmap_null_destroy(null_id);
     251                loc_null_destroy(null_id);
    251252       
    252253        return (int) rc;
     
    327328       
    328329        return ret;
    329 }
    330 
    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);
    348330}
    349331
     
    673655        async_exch_t *exch = vfs_exchange_begin();
    674656       
    675         req = async_send_0(exch, VFS_IN_UNLINK, NULL);
     657        req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL);
    676658        rc = async_data_write_start(exch, pa, pa_size);
    677659        if (rc != EOK) {
     
    811793        }
    812794       
    813         if (!stat.device) {
     795        if (!stat.service) {
    814796                errno = ENOENT;
    815797                return NULL;
    816798        }
    817799       
    818         return devmap_device_connect(mgmt, stat.device, 0);
    819 }
    820 
    821 int fd_node(int fildes, fdi_node_t *node)
    822 {
    823         struct stat stat;
    824         int rc = fstat(fildes, &stat);
    825        
    826         if (rc == EOK) {
    827                 node->fs_handle = stat.fs_handle;
    828                 node->devmap_handle = stat.devmap_handle;
    829                 node->index = stat.index;
    830         }
    831        
    832         return rc;
     800        return loc_service_connect(mgmt, stat.service, 0);
    833801}
    834802
     
    848816}
    849817
     818int fd_wait(void)
     819{
     820        async_exch_t *exch = vfs_exchange_begin();
     821       
     822        sysarg_t ret;
     823        sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret);
     824       
     825        vfs_exchange_end(exch);
     826       
     827        if (rc == EOK)
     828                return (int) ret;
     829       
     830        return (int) rc;
     831}
     832
    850833/** @}
    851834 */
Note: See TracChangeset for help on using the changeset viewer.