Changeset dff90fa7 in mainline for uspace/lib/c/generic


Ignore:
Timestamp:
2013-06-05T19:41:12Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
74dcc07
Parents:
f288d85 (diff), 6db5d4b (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:

mainline changes

Location:
uspace/lib/c/generic
Files:
2 added
10 edited

Legend:

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

    rf288d85 rdff90fa7  
    8181 * @param init_size Initial desired number of hash table buckets. Pass zero
    8282 *                 if you want the default initial size.
    83  * @param max_keys Maximal number of keys needed to identify an item.
     83 * @param max_load The table is resized when the average load per bucket
     84 *                 exceeds this number. Pass zero if you want the default.
    8485 * @param op       Hash table operations structure. remove_callback()
    8586 *                 is optional and can be NULL if no action is to be taken
  • uspace/lib/c/generic/async.c

    rf288d85 rdff90fa7  
    350350static async_client_conn_t client_connection = default_client_connection;
    351351static async_interrupt_handler_t interrupt_received = default_interrupt_received;
     352static size_t interrupt_handler_stksz = FIBRIL_DFLT_STK_SIZE;
    352353
    353354/** Setter for client_connection function pointer.
     
    370371{
    371372        interrupt_received = intr;
     373}
     374
     375/** Set the stack size for the interrupt handler notification fibrils.
     376 *
     377 * @param size Stack size in bytes.
     378 */
     379void async_set_interrupt_handler_stack_size(size_t size)
     380{
     381        interrupt_handler_stksz = size;
    372382}
    373383
     
    587597        msg->call = *call;
    588598       
    589         fid_t fid = fibril_create(notification_fibril, msg);
     599        fid_t fid = fibril_create_generic(notification_fibril, msg,
     600            interrupt_handler_stksz);
    590601        if (fid == 0) {
    591602                free(msg);
     
    20572068       
    20582069        async_sess_t *sess = exch->sess;
     2070        assert(sess != NULL);
    20592071       
    20602072        atomic_dec(&sess->refcnt);
     
    20782090 * @param arg   User defined argument.
    20792091 * @param flags Storage for the received flags. Can be NULL.
    2080  * @param dst   Destination address space area base. Cannot be NULL.
     2092 * @param dst   Address of the storage for the destination address space area
     2093 *              base address. Cannot be NULL.
    20812094 *
    20822095 * @return Zero on success or a negative error code from errno.h.
     
    22062219 *
    22072220 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
    2208  * @param dst    Destination address space area base address.
     2221 * @param dst    Address of the storage for the destination address space area
     2222 *               base address.
    22092223 *
    22102224 * @return Zero on success or a value from @ref errno.h on failure.
  • uspace/lib/c/generic/device/hw_res_parsed.c

    rf288d85 rdff90fa7  
    188188        hw_resource_list_t hw_resources;
    189189        hw_res_list_parsed_clean(hw_res_parsed);
    190         bzero(&hw_resources, sizeof(hw_resource_list_t));
     190        memset(&hw_resources, 0, sizeof(hw_resource_list_t));
    191191       
    192192        int rc = hw_res_get_resource_list(sess, &hw_resources);
  • uspace/lib/c/generic/fibril.c

    rf288d85 rdff90fa7  
    9595fibril_t *fibril_setup(void)
    9696{
    97         tcb_t *tcb = __make_tls();
     97        tcb_t *tcb = tls_make();
    9898        if (!tcb)
    9999                return NULL;
     
    101101        fibril_t *fibril = malloc(sizeof(fibril_t));
    102102        if (!fibril) {
    103                 __free_tls(tcb);
     103                tls_free(tcb);
    104104                return NULL;
    105105        }
     
    122122void fibril_teardown(fibril_t *fibril)
    123123{
    124         __free_tls(fibril->tcb);
     124        tls_free(fibril->tcb);
    125125        free(fibril);
    126126}
     
    256256 * @param func Implementing function of the new fibril.
    257257 * @param arg Argument to pass to func.
     258 * @param stksz Stack size in bytes.
    258259 *
    259260 * @return 0 on failure or TLS of the new fibril.
    260261 *
    261262 */
    262 fid_t fibril_create(int (*func)(void *), void *arg)
     263fid_t fibril_create_generic(int (*func)(void *), void *arg, size_t stksz)
    263264{
    264265        fibril_t *fibril;
     
    268269                return 0;
    269270       
    270         size_t stack_size = stack_size_get();
     271        size_t stack_size = (stksz == FIBRIL_DFLT_STK_SIZE) ?
     272            stack_size_get() : stksz;
    271273        fibril->stack = as_area_create((void *) -1, stack_size,
    272274            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE | AS_AREA_GUARD |
  • uspace/lib/c/generic/io/con_srv.c

    rf288d85 rdff90fa7  
    3535 */
    3636#include <errno.h>
     37#include <io/cons_event.h>
    3738#include <ipc/console.h>
    3839#include <stdlib.h>
     
    4041
    4142#include <io/con_srv.h>
     43
     44static int console_ev_encode(cons_event_t *event, ipc_call_t *call)
     45{
     46        IPC_SET_ARG1(*call, event->type);
     47
     48        switch (event->type) {
     49        case CEV_KEY:
     50                IPC_SET_ARG2(*call, event->ev.key.type);
     51                IPC_SET_ARG3(*call, event->ev.key.key);
     52                IPC_SET_ARG4(*call, event->ev.key.mods);
     53                IPC_SET_ARG5(*call, event->ev.key.c);
     54                break;
     55        case CEV_POS:
     56                IPC_SET_ARG2(*call, (event->ev.pos.pos_id << 16) | (event->ev.pos.type & 0xffff));
     57                IPC_SET_ARG3(*call, event->ev.pos.btn_num);
     58                IPC_SET_ARG4(*call, event->ev.pos.hpos);
     59                IPC_SET_ARG5(*call, event->ev.pos.vpos);
     60                break;
     61        default:
     62                return EIO;
     63        }
     64
     65        return EOK;
     66}
    4267
    4368static void con_read_srv(con_srv_t *srv, ipc_callid_t callid,
     
    273298{
    274299        int rc;
    275         kbd_event_t event;
     300        cons_event_t event;
     301        ipc_call_t result;
    276302
    277303        if (srv->srvs->ops->get_event == NULL) {
     
    281307
    282308        rc = srv->srvs->ops->get_event(srv, &event);
    283         async_answer_4(callid, rc, event.type, event.key, event.mods, event.c);
     309        if (rc != EOK) {
     310                async_answer_0(callid, rc);
     311                return;
     312        }
     313
     314        rc = console_ev_encode(&event, &result);
     315        if (rc != EOK) {
     316                async_answer_0(callid, rc);
     317                return;
     318        }
     319
     320        async_answer_5(callid, rc, IPC_GET_ARG1(result), IPC_GET_ARG2(result),
     321            IPC_GET_ARG3(result), IPC_GET_ARG4(result), IPC_GET_ARG5(result));
    284322}
    285323
  • uspace/lib/c/generic/io/console.c

    rf288d85 rdff90fa7  
    154154}
    155155
    156 bool console_get_kbd_event(console_ctrl_t *ctrl, kbd_event_t *event)
     156static int console_ev_decode(ipc_call_t *call, cons_event_t *event)
     157{
     158        event->type = IPC_GET_ARG1(*call);
     159
     160        switch (event->type) {
     161        case CEV_KEY:
     162                event->ev.key.type = IPC_GET_ARG2(*call);
     163                event->ev.key.key = IPC_GET_ARG3(*call);
     164                event->ev.key.mods = IPC_GET_ARG4(*call);
     165                event->ev.key.c = IPC_GET_ARG5(*call);
     166                break;
     167        case CEV_POS:
     168                event->ev.pos.pos_id = IPC_GET_ARG2(*call) >> 16;
     169                event->ev.pos.type = IPC_GET_ARG2(*call) & 0xffff;
     170                event->ev.pos.btn_num = IPC_GET_ARG3(*call);
     171                event->ev.pos.hpos = IPC_GET_ARG4(*call);
     172                event->ev.pos.vpos = IPC_GET_ARG5(*call);
     173                break;
     174        default:
     175                return EIO;
     176        }
     177
     178        return EOK;
     179}
     180
     181bool console_get_event(console_ctrl_t *ctrl, cons_event_t *event)
    157182{
    158183        if (ctrl->input_aid == 0) {
    159                 sysarg_t type;
    160                 sysarg_t key;
    161                 sysarg_t mods;
    162                 sysarg_t c;
     184                ipc_call_t result;
    163185               
    164186                async_exch_t *exch = async_exchange_begin(ctrl->input_sess);
    165                 int rc = async_req_0_4(exch, CONSOLE_GET_EVENT, &type, &key, &mods, &c);
     187                aid_t aid = async_send_0(exch, CONSOLE_GET_EVENT, &result);
    166188                async_exchange_end(exch);
     189               
     190                sysarg_t rc;
     191                async_wait_for(aid, &rc);
    167192               
    168193                if (rc != EOK) {
     
    171196                }
    172197               
    173                 event->type = type;
    174                 event->key = key;
    175                 event->mods = mods;
    176                 event->c = c;
     198                rc = console_ev_decode(&result, event);
     199                if (rc != EOK) {
     200                        errno = rc;
     201                        return false;
     202                }
    177203        } else {
    178204                sysarg_t retval;
     
    186212                }
    187213               
    188                 event->type = IPC_GET_ARG1(ctrl->input_call);
    189                 event->key = IPC_GET_ARG2(ctrl->input_call);
    190                 event->mods = IPC_GET_ARG3(ctrl->input_call);
    191                 event->c = IPC_GET_ARG4(ctrl->input_call);
     214                int rc = console_ev_decode(&ctrl->input_call, event);
     215                if (rc != EOK) {
     216                        errno = rc;
     217                        return false;
     218                }
    192219        }
    193220       
     
    195222}
    196223
    197 bool console_get_kbd_event_timeout(console_ctrl_t *ctrl, kbd_event_t *event,
     224bool console_get_event_timeout(console_ctrl_t *ctrl, cons_event_t *event,
    198225    suseconds_t *timeout)
    199226{
     
    223250        }
    224251       
    225         event->type = IPC_GET_ARG1(ctrl->input_call);
    226         event->key = IPC_GET_ARG2(ctrl->input_call);
    227         event->mods = IPC_GET_ARG3(ctrl->input_call);
    228         event->c = IPC_GET_ARG4(ctrl->input_call);
     252        rc = console_ev_decode(&ctrl->input_call, event);
     253        if (rc != EOK) {
     254                errno = rc;
     255                return false;
     256        }
    229257       
    230258        /* Update timeout */
  • uspace/lib/c/generic/mem.c

    rf288d85 rdff90fa7  
    224224 * @param s1  Pointer to the first area to compare.
    225225 * @param s2  Pointer to the second area to compare.
    226  * @param len Size of the first area in bytes. Both areas must have
    227  *            the same length.
    228  *
    229  * @return If len is 0, return zero. If the areas match, return
    230  *         zero. Otherwise return non-zero.
    231  *
    232  */
    233 int bcmp(const void *s1, const void *s2, size_t len)
     226 * @param len Size of the areas in bytes.
     227 *
     228 * @return Zero if areas have the same contents. If they differ,
     229 *         the sign of the result is the same as the sign of the
     230 *         difference of the first pair of different bytes.
     231 *
     232 */
     233int memcmp(const void *s1, const void *s2, size_t len)
    234234{
    235235        uint8_t *u1 = (uint8_t *) s1;
    236236        uint8_t *u2 = (uint8_t *) s2;
    237        
    238         for (; (len != 0) && (*u1++ == *u2++); len--);
    239        
    240         return len;
     237        size_t i;
     238
     239        for (i = 0; i < len; i++) {
     240                if (*u1 != *u2)
     241                        return (int)(*u1) - (int)(*u2);
     242                ++u1;
     243                ++u2;
     244        }
     245
     246        return 0;
    241247}
    242248
  • uspace/lib/c/generic/net/inet.c

    rf288d85 rdff90fa7  
    144144        /* Erase if no address */
    145145        if (!address) {
    146                 bzero(data, count);
     146                memset(data, 0, count);
    147147                return ENOENT;
    148148        }
     
    181181                } else {
    182182                        /* Erase the rest of the address */
    183                         bzero(data + index, count - index);
     183                        memset(data + index, 0, count - index);
    184184                        return EOK;
    185185                }
  • uspace/lib/c/generic/net/socket_client.c

    rf288d85 rdff90fa7  
    192192/** Default thread for new connections.
    193193 *
    194  * @param[in] iid       The initial message identifier.
    195  * @param[in] icall     The initial message call structure.
    196  * @param[in] arg       Local argument.
     194 * @param[in] iid   The initial message identifier.
     195 * @param[in] icall The initial message call structure.
     196 * @param[in] arg   Local argument.
     197 *
    197198 */
    198199static void socket_connection(ipc_callid_t iid, ipc_call_t * icall, void *arg)
    199200{
    200         ipc_callid_t callid;
    201         ipc_call_t call;
    202         socket_t *socket;
    203         int rc;
    204 
    205 loop:
    206         callid = async_get_call(&call);
    207 
    208         switch (IPC_GET_IMETHOD(call)) {
    209         case NET_SOCKET_RECEIVED:
    210         case NET_SOCKET_ACCEPTED:
    211         case NET_SOCKET_DATA_FRAGMENT_SIZE:
    212                 fibril_rwlock_read_lock(&socket_globals.lock);
    213 
    214                 /* Find the socket */
    215                 socket = sockets_find(socket_get_sockets(),
    216                     SOCKET_GET_SOCKET_ID(call));
    217                 if (!socket) {
    218                         rc = ENOTSOCK;
    219                         fibril_rwlock_read_unlock(&socket_globals.lock);
    220                         break;
     201        while (true) {
     202                ipc_call_t call;
     203                ipc_callid_t callid = async_get_call(&call);
     204               
     205                if (!IPC_GET_IMETHOD(call)) {
     206                        async_answer_0(callid, 0);
     207                        return;
    221208                }
     209               
     210                int rc;
    222211               
    223212                switch (IPC_GET_IMETHOD(call)) {
    224213                case NET_SOCKET_RECEIVED:
    225                         fibril_mutex_lock(&socket->receive_lock);
    226                         /* Push the number of received packet fragments */
    227                         rc = dyn_fifo_push(&socket->received,
    228                             SOCKET_GET_DATA_FRAGMENTS(call),
    229                             SOCKET_MAX_RECEIVED_SIZE);
    230                         if (rc == EOK) {
    231                                 /* Signal the received packet */
    232                                 fibril_condvar_signal(&socket->receive_signal);
     214                case NET_SOCKET_ACCEPTED:
     215                case NET_SOCKET_DATA_FRAGMENT_SIZE:
     216                        fibril_rwlock_read_lock(&socket_globals.lock);
     217                       
     218                        /* Find the socket */
     219                        socket_t *socket = sockets_find(socket_get_sockets(),
     220                            SOCKET_GET_SOCKET_ID(call));
     221                        if (!socket) {
     222                                rc = ENOTSOCK;
     223                                fibril_rwlock_read_unlock(&socket_globals.lock);
     224                                break;
    233225                        }
    234                         fibril_mutex_unlock(&socket->receive_lock);
     226                       
     227                        switch (IPC_GET_IMETHOD(call)) {
     228                        case NET_SOCKET_RECEIVED:
     229                                fibril_mutex_lock(&socket->receive_lock);
     230                                /* Push the number of received packet fragments */
     231                                rc = dyn_fifo_push(&socket->received,
     232                                    SOCKET_GET_DATA_FRAGMENTS(call),
     233                                    SOCKET_MAX_RECEIVED_SIZE);
     234                                if (rc == EOK) {
     235                                        /* Signal the received packet */
     236                                        fibril_condvar_signal(&socket->receive_signal);
     237                                }
     238                                fibril_mutex_unlock(&socket->receive_lock);
     239                                break;
     240                               
     241                        case NET_SOCKET_ACCEPTED:
     242                                /* Push the new socket identifier */
     243                                fibril_mutex_lock(&socket->accept_lock);
     244                                rc = dyn_fifo_push(&socket->accepted, 1,
     245                                    SOCKET_MAX_ACCEPTED_SIZE);
     246                                if (rc == EOK) {
     247                                        /* Signal the accepted socket */
     248                                        fibril_condvar_signal(&socket->accept_signal);
     249                                }
     250                                fibril_mutex_unlock(&socket->accept_lock);
     251                                break;
     252                       
     253                        default:
     254                                rc = ENOTSUP;
     255                        }
     256                       
     257                        if ((SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0) &&
     258                            (SOCKET_GET_DATA_FRAGMENT_SIZE(call) !=
     259                            socket->data_fragment_size)) {
     260                                fibril_rwlock_write_lock(&socket->sending_lock);
     261                               
     262                                /* Set the data fragment size */
     263                                socket->data_fragment_size =
     264                                    SOCKET_GET_DATA_FRAGMENT_SIZE(call);
     265                               
     266                                fibril_rwlock_write_unlock(&socket->sending_lock);
     267                        }
     268                       
     269                        fibril_rwlock_read_unlock(&socket_globals.lock);
    235270                        break;
    236 
    237                 case NET_SOCKET_ACCEPTED:
    238                         /* Push the new socket identifier */
    239                         fibril_mutex_lock(&socket->accept_lock);
    240                         rc = dyn_fifo_push(&socket->accepted, 1,
    241                             SOCKET_MAX_ACCEPTED_SIZE);
    242                         if (rc == EOK) {
    243                                 /* Signal the accepted socket */
    244                                 fibril_condvar_signal(&socket->accept_signal);
    245                         }
    246                         fibril_mutex_unlock(&socket->accept_lock);
    247                         break;
    248 
     271                       
    249272                default:
    250273                        rc = ENOTSUP;
    251274                }
    252 
    253                 if ((SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0) &&
    254                     (SOCKET_GET_DATA_FRAGMENT_SIZE(call) !=
    255                     socket->data_fragment_size)) {
    256                         fibril_rwlock_write_lock(&socket->sending_lock);
    257 
    258                         /* Set the data fragment size */
    259                         socket->data_fragment_size =
    260                             SOCKET_GET_DATA_FRAGMENT_SIZE(call);
    261 
    262                         fibril_rwlock_write_unlock(&socket->sending_lock);
    263                 }
    264 
    265                 fibril_rwlock_read_unlock(&socket_globals.lock);
    266                 break;
    267 
    268         default:
    269                 rc = ENOTSUP;
    270         }
    271 
    272         async_answer_0(callid, (sysarg_t) rc);
    273         goto loop;
     275               
     276                async_answer_0(callid, (sysarg_t) rc);
     277        }
    274278}
    275279
     
    442446                return ENOMEM;
    443447
    444         bzero(socket, sizeof(*socket));
     448        memset(socket, 0, sizeof(*socket));
    445449        fibril_rwlock_write_lock(&socket_globals.lock);
    446450
     
    653657                return ENOMEM;
    654658        }
    655         bzero(new_socket, sizeof(*new_socket));
     659        memset(new_socket, 0, sizeof(*new_socket));
    656660        socket_id = socket_generate_new_id();
    657661        if (socket_id <= 0) {
  • uspace/lib/c/generic/tls.c

    rf288d85 rdff90fa7  
    5151 * @return Pointer to TCB.
    5252 */
    53 tcb_t *__make_tls(void)
     53tcb_t *tls_make(void)
    5454{
    5555        void *data;
     
    5757        size_t tls_size = &_tbss_end - &_tdata_start;
    5858       
    59         tcb = __alloc_tls(&data, tls_size);
     59        tcb = tls_alloc_arch(&data, tls_size);
    6060        if (!tcb)
    6161                return NULL;
     
    7474}
    7575
    76 void __free_tls(tcb_t *tcb)
     76void tls_free(tcb_t *tcb)
    7777{
    7878        size_t tls_size = &_tbss_end - &_tdata_start;
    79         __free_tls_arch(tcb, tls_size);
     79        tls_free_arch(tcb, tls_size);
    8080}
    8181
Note: See TracChangeset for help on using the changeset viewer.