Changes in / [7494fb4:63a1e60] in mainline


Ignore:
Files:
1 deleted
24 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/pm.h

    r7494fb4 r63a1e60  
    8383
    8484#define TSS_BASIC_SIZE  104
    85 #define TSS_IOMAP_SIZE  (8 * 1024 + 1)  /* 8K for bitmap + 1 terminating byte for convenience */
     85#define TSS_IOMAP_SIZE  (16 * 1024 + 1)  /* 16K for bitmap + 1 terminating byte for convenience */
    8686
    8787#define IO_PORTS  (64 * 1024)
  • kernel/arch/amd64/src/ddi/ddi.c

    r7494fb4 r63a1e60  
    126126                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    127127                    TSS_IOMAP_SIZE * 8);
    128                 bitmap_copy(&iomap, &TASK->arch.iomap, bits);
     128                bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
    129129               
    130                 /*
    131                  * Set the trailing bits in the last byte of the map to disable
    132                  * I/O access.
    133                  */
    134                 bitmap_set_range(&iomap, bits, ALIGN_UP(bits, 8) - bits);
    135130                /*
    136131                 * It is safe to set the trailing eight bits because of the
    137132                 * extra convenience byte in TSS_IOMAP_SIZE.
    138133                 */
    139                 bitmap_set_range(&iomap, ALIGN_UP(bits, 8), 8);
     134                bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
    140135        }
    141136        irq_spinlock_unlock(&TASK->lock, false);
  • kernel/arch/ia32/include/pm.h

    r7494fb4 r63a1e60  
    7575
    7676#define TSS_BASIC_SIZE  104
    77 #define TSS_IOMAP_SIZE  (8 * 1024 + 1)  /* 8K for bitmap + 1 terminating byte for convenience */
     77#define TSS_IOMAP_SIZE  (16 * 1024 + 1)  /* 16K for bitmap + 1 terminating byte for convenience */
    7878
    7979#define IO_PORTS  (64 * 1024)
  • kernel/arch/ia32/src/ddi/ddi.c

    r7494fb4 r63a1e60  
    127127                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    128128                    TSS_IOMAP_SIZE * 8);
    129                 bitmap_copy(&iomap, &TASK->arch.iomap, bits);
     129                bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
    130130               
    131                 /*
    132                  * Set the trailing bits in the last byte of the map to disable
    133                  * I/O access.
    134                  */
    135                 bitmap_set_range(&iomap, bits, ALIGN_UP(bits, 8) - bits);
    136131                /*
    137132                 * It is safe to set the trailing eight bits because of the
    138133                 * extra convenience byte in TSS_IOMAP_SIZE.
    139134                 */
    140                 bitmap_set_range(&iomap, ALIGN_UP(bits, 8), 8);
     135                bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
    141136        }
    142137        irq_spinlock_unlock(&TASK->lock, false);
  • kernel/generic/src/adt/bitmap.c

    r7494fb4 r63a1e60  
    3232/**
    3333 * @file
    34  * @brief Implementation of bitmap ADT.
     34 * @brief       Implementation of bitmap ADT.
    3535 *
    3636 * This file implements bitmap ADT and provides functions for
     
    5151 * No portion of the bitmap is set or cleared by this function.
    5252 *
    53  * @param bitmap        Bitmap structure.
    54  * @param map           Address of the memory used to hold the map.
    55  * @param bits          Number of bits stored in bitmap.
     53 * @param bitmap Bitmap structure.
     54 * @param map Address of the memory used to hold the map.
     55 * @param bits Number of bits stored in bitmap.
    5656 */
    5757void bitmap_initialize(bitmap_t *bitmap, uint8_t *map, size_t bits)
     
    6363/** Set range of bits.
    6464 *
    65  * @param bitmap        Bitmap structure.
    66  * @param start         Starting bit.
    67  * @param bits          Number of bits to set.
     65 * @param bitmap Bitmap structure.
     66 * @param start Starting bit.
     67 * @param bits Number of bits to set.
    6868 */
    6969void bitmap_set_range(bitmap_t *bitmap, size_t start, size_t bits)
     
    7171        size_t i = 0;
    7272        size_t aligned_start;
    73         size_t lub;     /* leading unaligned bits */
    74         size_t amb;     /* aligned middle bits */
    75         size_t tab;     /* trailing aligned bits */
     73        size_t lub;             /* leading unaligned bits */
     74        size_t amb;             /* aligned middle bits */
     75        size_t tab;             /* trailing aligned bits */
    7676       
    7777        ASSERT(start + bits <= bitmap->bits);
     
    8282        tab = amb % 8;
    8383       
    84         if (!bits)
    85                 return;
    86 
    87         if (start + bits < aligned_start) {
    88                 /* Set bits in the middle of byte. */
    89                 bitmap->map[start / 8] |= ((1 << lub) - 1) << (start & 7);
    90                 return;
     84        if ( start + bits < aligned_start ) {
     85            /*
     86            * Set bits in the middle of byte
     87            */
     88            bitmap->map[start / 8] |= ((1 << lub)-1) << (start&7);
     89            return;
    9190        }
    9291       
    9392        if (lub) {
    94                 /* Make sure to set any leading unaligned bits. */
     93                /*
     94                 * Make sure to set any leading unaligned bits.
     95                 */
    9596                bitmap->map[start / 8] |= ~((1 << (8 - lub)) - 1);
    9697        }
    9798        for (i = 0; i < amb / 8; i++) {
    98                 /* The middle bits can be set byte by byte. */
     99                /*
     100                 * The middle bits can be set byte by byte.
     101                 */
    99102                bitmap->map[aligned_start / 8 + i] = ALL_ONES;
    100103        }
    101104        if (tab) {
    102                 /* Make sure to set any trailing aligned bits. */
     105                /*
     106                 * Make sure to set any trailing aligned bits.
     107                 */
    103108                bitmap->map[aligned_start / 8 + i] |= (1 << tab) - 1;
    104109        }
     
    108113/** Clear range of bits.
    109114 *
    110  * @param bitmap        Bitmap structure.
    111  * @param start         Starting bit.
    112  * @param bits          Number of bits to clear.
     115 * @param bitmap Bitmap structure.
     116 * @param start Starting bit.
     117 * @param bits Number of bits to clear.
    113118 */
    114119void bitmap_clear_range(bitmap_t *bitmap, size_t start, size_t bits)
     
    116121        size_t i = 0;
    117122        size_t aligned_start;
    118         size_t lub;     /* leading unaligned bits */
    119         size_t amb;     /* aligned middle bits */
    120         size_t tab;     /* trailing aligned bits */
     123        size_t lub;             /* leading unaligned bits */
     124        size_t amb;             /* aligned middle bits */
     125        size_t tab;             /* trailing aligned bits */
    121126       
    122127        ASSERT(start + bits <= bitmap->bits);
     
    127132        tab = amb % 8;
    128133
    129         if (!bits)
    130                 return;
    131 
    132         if (start + bits < aligned_start) {
    133                 /* Set bits in the middle of byte */
    134                 bitmap->map[start / 8] &= ~(((1 << lub) - 1) << (start & 7));
    135                 return;
     134        if ( start + bits < aligned_start )
     135        {
     136            /*
     137            * Set bits in the middle of byte
     138            */
     139            bitmap->map[start / 8] &= ~(((1 << lub)-1) << (start&7));
     140            return;
    136141        }
    137142
     143
    138144        if (lub) {
    139                 /* Make sure to clear any leading unaligned bits. */
     145                /*
     146                 * Make sure to clear any leading unaligned bits.
     147                 */
    140148                bitmap->map[start / 8] &= (1 << (8 - lub)) - 1;
    141149        }
    142150        for (i = 0; i < amb / 8; i++) {
    143                 /* The middle bits can be cleared byte by byte. */
     151                /*
     152                 * The middle bits can be cleared byte by byte.
     153                 */
    144154                bitmap->map[aligned_start / 8 + i] = ALL_ZEROES;
    145155        }
    146156        if (tab) {
    147                 /* Make sure to clear any trailing aligned bits. */
     157                /*
     158                 * Make sure to clear any trailing aligned bits.
     159                 */
    148160                bitmap->map[aligned_start / 8 + i] &= ~((1 << tab) - 1);
    149161        }
     
    153165/** Copy portion of one bitmap into another bitmap.
    154166 *
    155  * @param dst           Destination bitmap.
    156  * @param src           Source bitmap.
    157  * @param bits          Number of bits to copy.
     167 * @param dst Destination bitmap.
     168 * @param src Source bitmap.
     169 * @param bits Number of bits to copy.
    158170 */
    159171void bitmap_copy(bitmap_t *dst, bitmap_t *src, size_t bits)
  • tools/toolchain.sh

    r7494fb4 r63a1e60  
    6262        echo " ia32       IA-32 (x86, i386)"
    6363        echo " ia64       IA-64 (Itanium)"
    64         echo " mips32     MIPS little-endian 32b"
    65         echo " mips32eb   MIPS big-endian 32b"
    66         echo " mips64     MIPS little-endian 64b"
     64        echo " mips32     MIPS little-endian"
     65        echo " mips32eb   MIPS big-endian"
    6766        echo " ppc32      32-bit PowerPC"
    6867        echo " ppc64      64-bit PowerPC"
     
    304303                build_target "mips32eb" "mips-linux-gnu"
    305304                ;;
    306         "mips64")
    307                 build_target "mips64" "mips64el-linux-gnu"
    308                 ;;
    309305        "ppc32")
    310306                build_target "ppc32" "ppc-linux-gnu"
     
    324320                build_target "mips32" "mipsel-linux-gnu"
    325321                build_target "mips32eb" "mips-linux-gnu"
    326                 build_target "mips64" "mips64el-linux-gnu"
    327322                build_target "ppc32" "ppc-linux-gnu"
    328323                build_target "ppc64" "ppc64-linux-gnu"
  • uspace/app/netstart/Makefile

    r7494fb4 r63a1e60  
    2929
    3030USPACE_PREFIX = ../..
    31 LIBS =
    32 EXTRA_CFLAGS =
     31LIBS = $(LIBNET_PREFIX)/libnet.a
     32EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
    3333
    3434BINARY = netstart
  • uspace/lib/c/generic/adt/measured_strings.c

    r7494fb4 r63a1e60  
    4141#include <unistd.h>
    4242#include <errno.h>
     43#include <err.h>
    4344#include <async.h>
    4445
     
    134135    size_t count)
    135136{
     137        ERROR_DECLARE;
     138
    136139        size_t *lengths;
    137140        size_t index;
     
    139142        char *next;
    140143        ipc_callid_t callid;
    141         int rc;
    142144
    143145        if ((!strings) || (!data) || (count <= 0))
     
    153155                return EINVAL;
    154156        }
    155         rc = async_data_write_finalize(callid, lengths, length);
    156         if (rc != EOK) {
    157                 free(lengths);
    158                 return rc;
     157        if (ERROR_OCCURRED(async_data_write_finalize(callid, lengths,
     158            length))) {
     159                free(lengths);
     160                return ERROR_CODE;
    159161        }
    160162
     
    185187                                return EINVAL;
    186188                        }
    187                         rc = async_data_write_finalize(callid, next,
    188                             lengths[index]);
    189                         if (rc != EOK) {
     189                        if (ERROR_OCCURRED(async_data_write_finalize(callid,
     190                            next, lengths[index]))) {
    190191                                free(*data);
    191192                                free(*strings);
    192193                                free(lengths);
    193                                 return rc;
     194                                return ERROR_CODE;
    194195                        }
    195196                        (*strings)[index].value = next;
     
    250251int measured_strings_reply(const measured_string_ref strings, size_t count)
    251252{
     253        ERROR_DECLARE;
     254
    252255        size_t *lengths;
    253256        size_t index;
    254257        size_t length;
    255258        ipc_callid_t callid;
    256         int rc;
    257259
    258260        if ((!strings) || (count <= 0))
     
    268270                return EINVAL;
    269271        }
    270         rc = async_data_read_finalize(callid, lengths, length);
    271         if (rc != EOK) {
    272                 free(lengths);
    273                 return rc;
     272        if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths, length))) {
     273                free(lengths);
     274                return ERROR_CODE;
    274275        }
    275276        free(lengths);
     
    281282                                return EINVAL;
    282283                        }
    283                         rc = async_data_read_finalize(callid,
    284                             strings[index].value, strings[index].length);
    285                         if (rc != EOK)
    286                                 return rc;
     284                        ERROR_PROPAGATE(async_data_read_finalize(callid,
     285                            strings[index].value, strings[index].length));
    287286                }
    288287        }
     
    314313    size_t count)
    315314{
     315        ERROR_DECLARE;
     316
    316317        size_t *lengths;
    317318        size_t index;
    318319        char *next;
    319         int rc;
    320320
    321321        if ((phone < 0) || (!strings) || (!data) || (count <= 0))
     
    326326                return ENOMEM;
    327327
    328         rc = async_data_read_start(phone, lengths,
    329             sizeof(size_t) * (count + 1));
    330         if (rc != EOK) {
    331                 free(lengths);
    332                 return rc;
     328        if (ERROR_OCCURRED(async_data_read_start(phone, lengths,
     329            sizeof(size_t) * (count + 1)))) {
     330                free(lengths);
     331                return ERROR_CODE;
    333332        }
    334333
     
    351350                (*strings)[index].length = lengths[index];
    352351                if (lengths[index] > 0) {
    353                         rc = async_data_read_start(phone, next, lengths[index]);
    354                         if (rc != EOK) {
     352                        if (ERROR_OCCURRED(async_data_read_start(phone, next,
     353                            lengths[index]))) {
    355354                                free(lengths);
    356355                                free(data);
    357356                                free(strings);
    358                                 return rc;
     357                                return ERROR_CODE;
    359358                        }
    360359                        (*strings)[index].value = next;
     
    388387    size_t count)
    389388{
     389        ERROR_DECLARE;
     390
    390391        size_t *lengths;
    391392        size_t index;
    392         int rc;
    393393
    394394        if ((phone < 0) || (!strings) || (count <= 0))
     
    399399                return ENOMEM;
    400400
    401         rc = async_data_write_start(phone, lengths,
    402             sizeof(size_t) * (count + 1));
    403         if (rc != EOK) {
    404                 free(lengths);
    405                 return rc;
     401        if (ERROR_OCCURRED(async_data_write_start(phone, lengths,
     402            sizeof(size_t) * (count + 1)))) {
     403                free(lengths);
     404                return ERROR_CODE;
    406405        }
    407406
     
    410409        for (index = 0; index < count; index++) {
    411410                if (strings[index].length > 0) {
    412                         rc = async_data_write_start(phone, strings[index].value,
    413                             strings[index].length);
    414                         if (rc != EOK)
    415                                 return rc;
     411                        ERROR_PROPAGATE(async_data_write_start(phone,
     412                            strings[index].value, strings[index].length));
    416413                }
    417414        }
  • uspace/lib/c/generic/net/modules.c

    r7494fb4 r63a1e60  
    4141#include <async.h>
    4242#include <malloc.h>
    43 #include <errno.h>
     43#include <err.h>
    4444#include <sys/time.h>
    4545
     
    137137    ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
    138138{
    139         int rc;
     139        ERROR_DECLARE;
    140140       
    141141        /* Connect to the needed service */
     
    144144                /* Request the bidirectional connection */
    145145                ipcarg_t phonehash;
    146                
    147                 rc = ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash);
    148                 if (rc != EOK) {
     146                if (ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3,
     147                    &phonehash))) {
    149148                        ipc_hangup(phone);
    150                         return rc;
     149                        return ERROR_CODE;
    151150                }
    152151                async_new_connection(phonehash, 0, NULL, client_receiver);
     
    213212int data_receive(void **data, size_t *length)
    214213{
     214        ERROR_DECLARE;
     215
    215216        ipc_callid_t callid;
    216         int rc;
    217217
    218218        if (!data || !length)
     
    229229
    230230        // fetch the data
    231         rc = async_data_write_finalize(callid, *data, *length);
    232         if (rc != EOK) {
     231        if (ERROR_OCCURRED(async_data_write_finalize(callid, *data, *length))) {
    233232                free(data);
    234                 return rc;
     233                return ERROR_CODE;
    235234        }
    236235
  • uspace/lib/c/generic/net/packet.c

    r7494fb4 r63a1e60  
    4141#include <unistd.h>
    4242#include <errno.h>
     43#include <err.h>
    4344
    4445#include <sys/mman.h>
     
    9091int pm_init(void)
    9192{
    92         int rc;
     93        ERROR_DECLARE;
    9394
    9495        fibril_rwlock_initialize(&pm_globals.lock);
    95        
    9696        fibril_rwlock_write_lock(&pm_globals.lock);
    97         rc = gpm_initialize(&pm_globals.packet_map);
     97        ERROR_PROPAGATE(gpm_initialize(&pm_globals.packet_map));
    9898        fibril_rwlock_write_unlock(&pm_globals.lock);
    99        
    100         return rc;
     99        return EOK;
    101100}
    102101
     
    140139int pm_add(packet_t packet)
    141140{
     141        ERROR_DECLARE;
     142
    142143        packet_map_ref map;
    143         int rc;
    144144
    145145        if (!packet_is_valid(packet))
     
    160160                        }
    161161                        bzero(map, sizeof(packet_map_t));
    162                         rc = gpm_add(&pm_globals.packet_map, map);
    163                         if (rc < 0) {
     162                        if ((ERROR_CODE =
     163                            gpm_add(&pm_globals.packet_map, map)) < 0) {
    164164                                fibril_rwlock_write_unlock(&pm_globals.lock);
    165165                                free(map);
    166                                 return rc;
     166                                return ERROR_CODE;
    167167                        }
    168168                } while (PACKET_MAP_PAGE(packet->packet_id) >=
  • uspace/lib/c/generic/net/socket_client.c

    r7494fb4 r63a1e60  
    4343#include <stdlib.h>
    4444#include <errno.h>
     45#include <err.h>
    4546
    4647#include <ipc/services.h>
     
    211212static void socket_connection(ipc_callid_t iid, ipc_call_t * icall)
    212213{
     214        ERROR_DECLARE;
     215
    213216        ipc_callid_t callid;
    214217        ipc_call_t call;
    215218        socket_ref socket;
    216         int rc;
    217219
    218220loop:
     
    229231                    SOCKET_GET_SOCKET_ID(call));
    230232                if (!socket) {
    231                         rc = ENOTSOCK;
     233                        ERROR_CODE = ENOTSOCK;
    232234                        fibril_rwlock_read_unlock(&socket_globals.lock);
    233235                        break;
     
    238240                        fibril_mutex_lock(&socket->receive_lock);
    239241                        // push the number of received packet fragments
    240                         rc = dyn_fifo_push(&socket->received,
     242                        if (!ERROR_OCCURRED(dyn_fifo_push(&socket->received,
    241243                            SOCKET_GET_DATA_FRAGMENTS(call),
    242                             SOCKET_MAX_RECEIVED_SIZE);
    243                         if (rc == EOK) {
     244                            SOCKET_MAX_RECEIVED_SIZE))) {
    244245                                // signal the received packet
    245246                                fibril_condvar_signal(&socket->receive_signal);
     
    251252                        // push the new socket identifier
    252253                        fibril_mutex_lock(&socket->accept_lock);
    253                         rc = dyn_fifo_push(&socket->accepted, 1,
    254                             SOCKET_MAX_ACCEPTED_SIZE);
    255                         if (rc != EOK) {
     254                        if (!ERROR_OCCURRED(dyn_fifo_push(&socket->accepted,
     255                            1, SOCKET_MAX_ACCEPTED_SIZE))) {
    256256                                // signal the accepted socket
    257257                                fibril_condvar_signal(&socket->accept_signal);
     
    261261
    262262                default:
    263                         rc = ENOTSUP;
     263                        ERROR_CODE = ENOTSUP;
    264264                }
    265265
     
    280280
    281281        default:
    282                 rc = ENOTSUP;
    283         }
    284 
    285         ipc_answer_0(callid, (ipcarg_t) rc);
     282                ERROR_CODE = ENOTSUP;
     283        }
     284
     285        ipc_answer_0(callid, (ipcarg_t) ERROR_CODE);
    286286        goto loop;
    287287}
     
    405405int socket(int domain, int type, int protocol)
    406406{
     407        ERROR_DECLARE;
     408
    407409        socket_ref socket;
    408410        int phone;
     
    411413        ipcarg_t fragment_size;
    412414        ipcarg_t header_size;
    413         int rc;
    414415
    415416        // find the appropriate service
     
    478479        }
    479480
    480         rc = (int) async_req_3_3(phone, NET_SOCKET, socket_id, 0, service, NULL,
    481             &fragment_size, &header_size);
    482         if (rc != EOK) {
     481        if (ERROR_OCCURRED((int) async_req_3_3(phone, NET_SOCKET, socket_id, 0,
     482            service, NULL, &fragment_size, &header_size))) {
    483483                fibril_rwlock_write_unlock(&socket_globals.lock);
    484484                free(socket);
    485                 return rc;
     485                return ERROR_CODE;
    486486        }
    487487
     
    492492        socket_initialize(socket, socket_id, phone, service);
    493493        // store the new socket
    494         rc = sockets_add(socket_get_sockets(), socket_id, socket);
     494        ERROR_CODE = sockets_add(socket_get_sockets(), socket_id, socket);
    495495
    496496        fibril_rwlock_write_unlock(&socket_globals.lock);
    497         if (rc < 0) {
     497        if (ERROR_CODE < 0) {
    498498                dyn_fifo_destroy(&socket->received);
    499499                dyn_fifo_destroy(&socket->accepted);
     
    501501                async_msg_3(phone, NET_SOCKET_CLOSE, (ipcarg_t) socket_id, 0,
    502502                    service);
    503                 return rc;
     503                return ERROR_CODE;
    504504        }
    505505
     
    770770int closesocket(int socket_id)
    771771{
     772        ERROR_DECLARE;
     773
    772774        socket_ref socket;
    773         int rc;
    774775
    775776        fibril_rwlock_write_lock(&socket_globals.lock);
     
    786787
    787788        // request close
    788         rc = (int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE,
    789             (ipcarg_t) socket->socket_id, 0, socket->service);
    790         if (rc != EOK) {
    791                 fibril_rwlock_write_unlock(&socket_globals.lock);
    792                 return rc;
    793         }
     789        ERROR_PROPAGATE((int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE,
     790            (ipcarg_t) socket->socket_id, 0, socket->service));
    794791        // free the socket structure
    795792        socket_destroy(socket);
  • uspace/lib/c/include/adt/generic_char_map.h

    r7494fb4 r63a1e60  
    4040#include <unistd.h>
    4141#include <errno.h>
     42#include <err.h>
    4243
    4344#include <adt/char_map.h>
     
    8485             type *value) \
    8586        { \
    86                 int rc; \
     87                ERROR_DECLARE; \
    8788                int index; \
    8889                if (!name##_is_valid(map)) \
     
    9192                if (index < 0) \
    9293                        return index; \
    93                 rc = char_map_add(&map->names, name, length, index); \
    94                 if (rc != EOK) { \
     94                if (ERROR_OCCURRED(char_map_add(&map->names, name, length, \
     95                    index))) { \
    9596                        name##_items_exclude_index(&map->values, index); \
    96                         return rc; \
     97                        return ERROR_CODE; \
    9798                } \
    9899                return EOK; \
     
    140141        int name##_initialize(name##_ref map) \
    141142        { \
    142                 int rc; \
     143                ERROR_DECLARE; \
    143144                if (!map) \
    144145                        return EINVAL; \
    145                 rc = char_map_initialize(&map->names); \
    146                 if (rc != EOK) \
    147                         return rc; \
    148                 rc = name##_items_initialize(&map->values); \
    149                 if (rc != EOK) { \
     146                ERROR_PROPAGATE(char_map_initialize(&map->names)); \
     147                if (ERROR_OCCURRED(name##_items_initialize(&map->values))) { \
    150148                        char_map_destroy(&map->names); \
    151                         return rc; \
     149                        return ERROR_CODE; \
    152150                } \
    153151                map->magic = GENERIC_CHAR_MAP_MAGIC_VALUE; \
  • uspace/lib/c/include/err.h

    r7494fb4 r63a1e60  
    3737
    3838#include <stdio.h>
     39#include <errno.h>
     40
     41#ifdef CONFIG_DEBUG
     42#include <str_error.h>
     43#endif
    3944
    4045#define errx(status, fmt, ...) { \
     
    4348}
    4449
     50
     51/** An actual stored error code.  */
     52#define ERROR_CODE  error_check_return_value
     53
     54/** An error processing routines declaration.
     55 *
     56 * This has to be declared in the block where the error processing
     57 * is desired.
     58 */
     59#define ERROR_DECLARE  int ERROR_CODE
     60
     61/** Store the value as an error code and checks if an error occurred.
     62 *
     63 * @param[in] value     The value to be checked. May be a function call.
     64 * @return              False if the value indicates success (EOK).
     65 * @return              True otherwise.
     66 */
     67#ifdef CONFIG_DEBUG
     68
     69#define ERROR_OCCURRED(value) \
     70        (((ERROR_CODE = (value)) != EOK) && \
     71        ({ \
     72                fprintf(stderr, "libsocket error at %s:%d (%s)\n", \
     73                __FILE__, __LINE__, str_error(ERROR_CODE)); \
     74                1; \
     75        }))
     76
     77#else
     78
     79#define ERROR_OCCURRED(value)   ((ERROR_CODE = (value)) != EOK)
     80
     81#endif
     82
     83#define ERROR_NONE(value)       !ERROR_OCCURRED((value))
     84
     85/** Error propagation
     86 *
     87 * Check if an error occurred and immediately exit the actual
     88 * function returning the error code.
     89 *
     90 * @param[in] value     The value to be checked. May be a function call.
     91 *
     92 */
     93
     94#define ERROR_PROPAGATE(value) \
     95        if (ERROR_OCCURRED(value)) \
     96                return ERROR_CODE
     97
    4598#endif
    4699
    47100/** @}
    48101 */
    49 
  • uspace/lib/c/include/stdio.h

    r7494fb4 r63a1e60  
    4646#define BUFSIZ  4096
    4747
    48 #define DEBUG(fmt, ...) \
     48#define DEBUG(fmt, ...)se\
    4949        { \
    5050                char _buf[256]; \
  • uspace/lib/net/adt/module_map.c

    r7494fb4 r63a1e60  
    3838#include <task.h>
    3939#include <unistd.h>
    40 #include <errno.h>
     40#include <err.h>
    4141
    4242#include <ipc/services.h>
     
    6767    connect_module_t connect_module)
    6868{
     69        ERROR_DECLARE;
     70
    6971        module_ref tmp_module;
    70         int rc;
    7172
    7273        tmp_module = (module_ref) malloc(sizeof(module_t));
     
    8283        tmp_module->connect_module = connect_module;
    8384
    84         rc = modules_add(modules, tmp_module->name, 0, tmp_module);
    85         if (rc != EOK) {
     85        if (ERROR_OCCURRED(modules_add(modules, tmp_module->name, 0,
     86            tmp_module))) {
    8687                free(tmp_module);
    87                 return rc;
     88                return ERROR_CODE;
    8889        }
    8990        if (module)
  • uspace/lib/net/generic/packet_remote.c

    r7494fb4 r63a1e60  
    3838#include <async.h>
    3939#include <errno.h>
     40#include <err.h>
    4041#include <ipc/ipc.h>
    4142#include <ipc/packet.h>
     
    6667packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size)
    6768{
     69        ERROR_DECLARE;
     70       
    6871        ipc_call_t answer;
    69         aid_t message;
    70         int rc;
    71        
    72         message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
     72        aid_t message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
    7373
    7474        *packet = (packet_t) as_get_mappable_page(size);
    75         rc = async_share_in_start_0_0(phone, *packet, size);
    76         if (rc != EOK) {
     75        if (ERROR_OCCURRED(async_share_in_start_0_0(phone, *packet, size)) ||
     76            ERROR_OCCURRED(pm_add(*packet))) {
    7777                munmap(*packet, size);
    7878                async_wait_for(message, NULL);
    79                 return rc;
    80         }
    81         rc = pm_add(*packet);
    82         if (rc != EOK) {
    83                 munmap(*packet, size);
    84                 async_wait_for(message, NULL);
    85                 return rc;
     79                return ERROR_CODE;
    8680        }
    8781       
     
    109103int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id)
    110104{
    111         int rc;
     105        ERROR_DECLARE;
    112106       
    113107        if (!packet)
     
    118112                ipcarg_t size;
    119113               
    120                 rc = async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id,
    121                     &size);
    122                 if (rc != EOK)
    123                         return rc;
    124                 rc = packet_return(phone, packet, packet_id, size);
    125                 if (rc != EOK)
    126                         return rc;
     114                ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE,
     115                    packet_id, &size));
     116                ERROR_PROPAGATE(packet_return(phone, packet, packet_id, size));
    127117        }
    128118        if ((*packet)->next) {
     
    151141    size_t max_prefix, size_t max_suffix)
    152142{
     143        ERROR_DECLARE;
     144       
    153145        ipcarg_t packet_id;
    154146        ipcarg_t size;
    155         int rc;
    156        
    157         rc = async_req_4_2(phone, NET_PACKET_CREATE_4, max_content, addr_len,
    158             max_prefix, max_suffix, &packet_id, &size);
    159         if (rc != EOK)
     147       
     148        if (ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4,
     149            max_content, addr_len, max_prefix, max_suffix, &packet_id, &size)))
    160150                return NULL;
    161151       
     
    163153        packet_t packet = pm_find(packet_id);
    164154        if (!packet) {
    165                 rc = packet_return(phone, &packet, packet_id, size);
    166                 if (rc != EOK)
     155                if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id,
     156                    size)))
    167157                        return NULL;
    168158        }
     
    182172packet_t packet_get_1_remote(int phone, size_t content)
    183173{
     174        ERROR_DECLARE;
     175       
    184176        ipcarg_t packet_id;
    185177        ipcarg_t size;
    186         int rc;
    187        
    188         rc = async_req_1_2(phone, NET_PACKET_CREATE_1, content, &packet_id,
    189             &size);
    190         if (rc != EOK)
     178       
     179        if (ERROR_OCCURRED(async_req_1_2(phone, NET_PACKET_CREATE_1, content,
     180            &packet_id, &size)))
    191181                return NULL;
    192182       
    193183        packet_t packet = pm_find(packet_id);
    194184        if (!packet) {
    195                 rc = packet_return(phone, &packet, packet_id, size);
    196                 if (rc != EOK)
     185                if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id,
     186                    size)))
    197187                        return NULL;
    198188        }
  • uspace/lib/net/netif/netif_local.c

    r7494fb4 r63a1e60  
    4343#include <ipc/services.h>
    4444#include <ipc/netif.h>
    45 #include <errno.h>
     45#include <err.h>
    4646
    4747#include <generic.h>
     
    113113int netif_start_req_local(int netif_phone, device_id_t device_id)
    114114{
    115         int rc;
     115        ERROR_DECLARE;
    116116       
    117117        fibril_rwlock_write_lock(&netif_globals.lock);
    118118       
    119119        netif_device_t *device;
    120         rc = find_device(device_id, &device);
    121         if (rc != EOK) {
     120        if (ERROR_OCCURRED(find_device(device_id, &device))) {
    122121                fibril_rwlock_write_unlock(&netif_globals.lock);
    123                 return rc;
     122                return ERROR_CODE;
    124123        }
    125124       
     
    149148int netif_stop_req_local(int netif_phone, device_id_t device_id)
    150149{
    151         int rc;
     150        ERROR_DECLARE;
    152151       
    153152        fibril_rwlock_write_lock(&netif_globals.lock);
    154153       
    155154        netif_device_t *device;
    156         rc = find_device(device_id, &device);
    157         if (rc != EOK) {
     155        if (ERROR_OCCURRED(find_device(device_id, &device))) {
    158156                fibril_rwlock_write_unlock(&netif_globals.lock);
    159                 return rc;
     157                return ERROR_CODE;
    160158        }
    161159       
     
    205203    measured_string_ref *address, char **data)
    206204{
    207         int rc;
     205        ERROR_DECLARE;
    208206       
    209207        if (!address || !data)
     
    213211       
    214212        measured_string_t translation;
    215         rc = netif_get_addr_message(device_id, &translation);
    216         if (rc == EOK) {
     213        if (!ERROR_OCCURRED(netif_get_addr_message(device_id, &translation))) {
    217214                *address = measured_string_copy(&translation);
    218                 rc = (*address) ? EOK : ENOMEM;
     215                ERROR_CODE = (*address) ? EOK : ENOMEM;
    219216        }
    220217       
     
    223220        *data = (**address).value;
    224221       
    225         return rc;
     222        return ERROR_CODE;
    226223}
    227224
     
    267264int netif_init_module(async_client_conn_t client_connection)
    268265{
    269         int rc;
     266        ERROR_DECLARE;
    270267       
    271268        async_set_client_connection(client_connection);
     
    274271        netif_device_map_initialize(&netif_globals.device_map);
    275272       
    276         rc = pm_init();
    277         if (rc != EOK)
    278                 return rc;
     273        ERROR_PROPAGATE(pm_init());
    279274       
    280275        fibril_rwlock_initialize(&netif_globals.lock);
    281        
    282         rc = netif_initialize();
    283         if (rc != EOK) {
     276        if (ERROR_OCCURRED(netif_initialize())) {
    284277                pm_destroy();
    285                 return rc;
     278                return ERROR_CODE;
    286279        }
    287280       
     
    324317static int register_message(const char *name, device_id_t device_id, int phone)
    325318{
     319        ERROR_DECLARE;
     320       
    326321        netif_device_t *device;
    327         int rc;
    328        
    329         rc = find_device(device_id, &device);
    330         if (rc != EOK)
    331                 return rc;
    332        
    333         if (device->nil_phone > 0)
     322        ERROR_PROPAGATE(find_device(device_id, &device));
     323        if(device->nil_phone > 0)
    334324                return ELIMIT;
    335325       
     
    359349    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
    360350{
     351        ERROR_DECLARE;
     352       
    361353        size_t length;
    362354        device_stats_t stats;
    363355        packet_t packet;
    364356        measured_string_t address;
    365         int rc;
    366357       
    367358        *answer_count = 0;
     
    376367        case IPC_M_CONNECT_TO_ME:
    377368                fibril_rwlock_write_lock(&netif_globals.lock);
    378                 rc = register_message(name, IPC_GET_DEVICE(call),
     369                ERROR_CODE = register_message(name, IPC_GET_DEVICE(call),
    379370                    IPC_GET_PHONE(call));
    380371                fibril_rwlock_write_unlock(&netif_globals.lock);
    381                 return rc;
     372                return ERROR_CODE;
    382373               
    383374        case NET_NETIF_SEND:
    384                 rc = packet_translate_remote(netif_globals.net_phone, &packet,
    385                     IPC_GET_PACKET(call));
    386                 if (rc != EOK)
    387                         return rc;
     375                ERROR_PROPAGATE(packet_translate_remote(netif_globals.net_phone,
     376                    &packet, IPC_GET_PACKET(call)));
    388377                return netif_send_msg_local(0, IPC_GET_DEVICE(call), packet,
    389378                    IPC_GET_SENDER(call));
    390                
     379                   
    391380        case NET_NETIF_START:
    392381                return netif_start_req_local(0, IPC_GET_DEVICE(call));
     
    395384                fibril_rwlock_read_lock(&netif_globals.lock);
    396385
    397                 rc = async_data_read_receive(&callid, &length);
    398                 if (rc != EOK) {
     386                if (ERROR_OCCURRED(async_data_read_receive(&callid, &length))) {
    399387                        fibril_rwlock_read_unlock(&netif_globals.lock);
    400                         return rc;
     388                        return ERROR_CODE;
    401389                }
    402390                if (length < sizeof(device_stats_t)) {
     
    405393                }
    406394
    407                 rc = netif_get_device_stats(IPC_GET_DEVICE(call), &stats);
    408                 if (rc == EOK) {
    409                         rc = async_data_read_finalize(callid, &stats,
     395                if (ERROR_NONE(netif_get_device_stats(IPC_GET_DEVICE(call),
     396                    &stats))) {
     397                        ERROR_CODE = async_data_read_finalize(callid, &stats,
    410398                            sizeof(device_stats_t));
    411399                }
    412400
    413401                fibril_rwlock_read_unlock(&netif_globals.lock);
    414                 return rc;
     402                return ERROR_CODE;
    415403
    416404        case NET_NETIF_STOP:
     
    419407        case NET_NETIF_GET_ADDR:
    420408                fibril_rwlock_read_lock(&netif_globals.lock);
    421                 rc = netif_get_addr_message(IPC_GET_DEVICE(call), &address);
    422                 if (rc == EOK)
    423                         rc = measured_strings_reply(&address, 1);
     409                if (ERROR_NONE(netif_get_addr_message(IPC_GET_DEVICE(call),
     410                    &address)))
     411                        ERROR_CODE = measured_strings_reply(&address, 1);
    424412                fibril_rwlock_read_unlock(&netif_globals.lock);
    425                 return rc;
     413                return ERROR_CODE;
    426414        }
    427415       
     
    443431int netif_module_start_standalone(async_client_conn_t client_connection)
    444432{
    445         int rc;
    446        
    447         rc = netif_init_module(client_connection);
    448         if (rc != EOK)
    449                 return rc;
     433        ERROR_DECLARE;
     434       
     435        ERROR_PROPAGATE(netif_init_module(client_connection));
    450436       
    451437        async_manager();
  • uspace/lib/net/tl/socket_core.c

    r7494fb4 r63a1e60  
    4848#include <stdlib.h>
    4949#include <errno.h>
     50#include <err.h>
    5051
    5152#include <adt/dynamic_fifo.h>
     
    163164    const char *key, size_t key_length)
    164165{
     166        ERROR_DECLARE;
     167
    165168        socket_core_ref *socket_ref;
    166         int rc;
    167169
    168170        // create a wrapper
     
    173175        *socket_ref = socket;
    174176        // add the wrapper
    175         rc = socket_port_map_add(&socket_port->map, key, key_length,
    176             socket_ref);
    177         if (rc != EOK) {
     177        if (ERROR_OCCURRED(socket_port_map_add(&socket_port->map, key,
     178            key_length, socket_ref))) {
    178179                free(socket_ref);
    179                 return rc;
     180                return ERROR_CODE;
    180181        }
    181182       
     
    203204    int port)
    204205{
     206        ERROR_DECLARE;
     207
    205208        socket_port_ref socket_port;
    206         int rc;
    207209
    208210        // create a wrapper
     
    212214
    213215        socket_port->count = 0;
    214         rc = socket_port_map_initialize(&socket_port->map);
    215         if (rc != EOK)
    216                 goto fail;
    217        
    218         rc = socket_port_add_core(socket_port, socket, SOCKET_MAP_KEY_LISTENING,
    219             0);
    220         if (rc != EOK)
    221                 goto fail;
     216        if (ERROR_OCCURRED(socket_port_map_initialize(&socket_port->map)) ||
     217            ERROR_OCCURRED(socket_port_add_core(socket_port, socket,
     218            SOCKET_MAP_KEY_LISTENING, 0))) {
     219                socket_port_map_destroy(&socket_port->map);
     220                free(socket_port);
     221                return ERROR_CODE;
     222        }
    222223       
    223224        // register the incomming port
    224         rc = socket_ports_add(global_sockets, port, socket_port);
    225         if (rc < 0)
    226                 goto fail;
     225        ERROR_CODE = socket_ports_add(global_sockets, port, socket_port);
     226        if (ERROR_CODE < 0) {
     227                socket_port_map_destroy(&socket_port->map);
     228                free(socket_port);
     229                return ERROR_CODE;
     230        }
    227231       
    228232        socket->port = port;
    229233        return EOK;
    230 
    231 fail:
    232         socket_port_map_destroy(&socket_port->map);
    233         free(socket_port);
    234         return rc;
    235        
    236234}
    237235
     
    418416    void *specific_data, int *socket_id)
    419417{
     418        ERROR_DECLARE;
     419
    420420        socket_core_ref socket;
     421        int res;
    421422        int positive;
    422         int rc;
    423423
    424424        if (!socket_id)
     
    447447        socket->key_length = 0;
    448448        socket->specific_data = specific_data;
    449         rc = dyn_fifo_initialize(&socket->received, SOCKET_INITIAL_RECEIVED_SIZE);
    450         if (rc != EOK) {
     449        if (ERROR_OCCURRED(dyn_fifo_initialize(&socket->received,
     450            SOCKET_INITIAL_RECEIVED_SIZE))) {
    451451                free(socket);
    452                 return rc;
    453         }
    454        
    455         rc = dyn_fifo_initialize(&socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE);
    456         if (rc != EOK) {
     452                return ERROR_CODE;
     453        }
     454        if (ERROR_OCCURRED(dyn_fifo_initialize(&socket->accepted,
     455            SOCKET_INITIAL_ACCEPTED_SIZE))) {
    457456                dyn_fifo_destroy(&socket->received);
    458457                free(socket);
    459                 return rc;
     458                return ERROR_CODE;
    460459        }
    461460        socket->socket_id = *socket_id;
    462         rc = socket_cores_add(local_sockets, socket->socket_id, socket);
    463         if (rc < 0) {
     461        res = socket_cores_add(local_sockets, socket->socket_id, socket);
     462        if (res < 0) {
    464463                dyn_fifo_destroy(&socket->received);
    465464                dyn_fifo_destroy(&socket->accepted);
    466465                free(socket);
    467                 return rc;
     466                return res;
    468467        }
    469468       
     
    524523int socket_reply_packets(packet_t packet, size_t *length)
    525524{
     525        ERROR_DECLARE;
     526
    526527        packet_t next_packet;
    527528        size_t fragments;
    528529        size_t *lengths;
    529530        size_t index;
    530         int rc;
    531531
    532532        if (!length)
     
    536536        if (!next_packet) {
    537537                // write all if only one fragment
    538                 rc = data_reply(packet_get_data(packet),
    539                     packet_get_data_length(packet));
    540                 if (rc != EOK)
    541                         return rc;
     538                ERROR_PROPAGATE(data_reply(packet_get_data(packet),
     539                    packet_get_data_length(packet)));
    542540                // store the total length
    543541                *length = packet_get_data_length(packet);
     
    566564               
    567565                // write the fragment lengths
    568                 rc = data_reply(lengths, sizeof(int) * (fragments + 1));
    569                 if (rc != EOK) {
     566                if (ERROR_OCCURRED(data_reply(lengths,
     567                    sizeof(int) * (fragments + 1)))) {
    570568                        free(lengths);
    571                         return rc;
     569                        return ERROR_CODE;
    572570                }
    573571                next_packet = packet;
     
    575573                // write the fragments
    576574                for (index = 0; index < fragments; ++index) {
    577                         rc = data_reply(packet_get_data(next_packet),
     575                        ERROR_CODE = data_reply(packet_get_data(next_packet),
    578576                            lengths[index]);
    579                         if (rc != EOK) {
     577                        if (ERROR_OCCURRED(ERROR_CODE)) {
    580578                                free(lengths);
    581                                 return rc;
     579                                return ERROR_CODE;
    582580                        }
    583581                        next_packet = pq_next(next_packet);
     
    682680    socket_core_ref socket, const char *key, size_t key_length)
    683681{
     682        ERROR_DECLARE;
     683
    684684        socket_port_ref socket_port;
    685         int rc;
    686685
    687686        // find ports
     
    691690       
    692691        // add the socket
    693         rc = socket_port_add_core(socket_port, socket, key, key_length);
    694         if (rc != EOK)
    695                 return rc;
     692        ERROR_PROPAGATE(socket_port_add_core(socket_port, socket, key,
     693            key_length));
    696694       
    697695        socket->port = port;
  • uspace/lib/net/tl/tl_common.c

    r7494fb4 r63a1e60  
    5454#include <ipc/services.h>
    5555#include <errno.h>
     56#include <err.h>
    5657
    5758DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t);
     
    123124    packet_dimension_ref *packet_dimension)
    124125{
    125         int rc;
     126        ERROR_DECLARE;
    126127       
    127128        if (!packet_dimension)
     
    136137                        return ENOMEM;
    137138               
    138                 rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension);
    139                 if (rc != EOK) {
     139                if (ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id,
     140                    *packet_dimension))) {
    140141                        free(*packet_dimension);
    141                         return rc;
     142                        return ERROR_CODE;
    142143                }
    143144               
    144                 rc = packet_dimensions_add(packet_dimensions, device_id,
     145                ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id,
    145146                    *packet_dimension);
    146                 if (rc < 0) {
     147                if (ERROR_CODE < 0) {
    147148                        free(*packet_dimension);
    148                         return rc;
     149                        return ERROR_CODE;
    149150                }
    150151        }
     
    291292    socklen_t addrlen)
    292293{
     294        ERROR_DECLARE;
     295
    293296        ipc_callid_t callid;
    294297        size_t length;
    295         void *data;
    296         int rc;
     298        void * data;
    297299
    298300        if (!dimension)
     
    317319
    318320        // read the data into the packet
    319         rc = async_data_write_finalize(callid, data, length);
    320         if (rc != EOK) {
     321        if (ERROR_OCCURRED(async_data_write_finalize(callid, data, length)) ||
     322            // set the packet destination address
     323            ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr,
     324            addrlen))) {
    321325                pq_release_remote(packet_phone, packet_get_id(*packet));
    322                 return rc;
    323         }
    324        
    325         // set the packet destination address
    326         rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen);
    327         if (rc != EOK) {
    328                 pq_release_remote(packet_phone, packet_get_id(*packet));
    329                 return rc;
     326                return ERROR_CODE;
    330327        }
    331328
  • uspace/lib/packet/generic/packet_server.c

    r7494fb4 r63a1e60  
    4242#include <async.h>
    4343#include <errno.h>
     44#include <err.h>
    4445#include <fibril_synch.h>
    4546#include <unistd.h>
     
    161162    size_t max_content, size_t max_suffix)
    162163{
     164        ERROR_DECLARE;
     165
    163166        packet_t packet;
    164         int rc;
    165167
    166168        // already locked
     
    175177        packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
    176178        packet->magic_value = PACKET_MAGIC_VALUE;
    177         rc = pm_add(packet);
    178         if (rc != EOK) {
     179        if (ERROR_OCCURRED(pm_add(packet))) {
    179180                munmap(packet, packet->length);
    180181                return NULL;
  • uspace/srv/hw/netif/dp8390/dp8390.h

    r7494fb4 r63a1e60  
    4343/** Input/output size.
    4444 */
    45 #define DP8390_IO_SIZE  0x020
     45#define DP8390_IO_SIZE  0x01f
    4646
    4747/*
  • uspace/srv/hw/netif/dp8390/dp8390_module.c

    r7494fb4 r63a1e60  
    158158
    159159int netif_get_device_stats(device_id_t device_id, device_stats_ref stats){
     160        ERROR_DECLARE;
     161
    160162        netif_device_t * device;
    161163        eth_stat_t * de_stat;
    162         int rc;
    163164
    164165        if(! stats){
    165166                return EBADMEM;
    166167        }
    167         rc = find_device(device_id, &device);
    168         if (rc != EOK)
    169                 return rc;
     168        ERROR_PROPAGATE(find_device(device_id, &device));
    170169        de_stat = &((dpeth_t *) device->specific)->de_stat;
    171170        null_device_stats(stats);
     
    186185
    187186int netif_get_addr_message(device_id_t device_id, measured_string_ref address){
    188         netif_device_t * device;
    189         int rc;
     187        ERROR_DECLARE;
     188
     189        netif_device_t * device;
    190190
    191191        if(! address){
    192192                return EBADMEM;
    193193        }
    194         rc = find_device(device_id, &device);
    195         if (rc != EOK)
    196                 return rc;
     194        ERROR_PROPAGATE(find_device(device_id, &device));
    197195        address->value = (char *) (&((dpeth_t *) device->specific)->de_address);
    198196        address->length = CONVERT_SIZE(ether_addr_t, char, 1);
     
    203201
    204202int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
    205         netif_device_t * device;
    206         dpeth_t * dep;
    207         int rc;
     203        ERROR_DECLARE;
     204
     205        netif_device_t * device;
     206        dpeth_t * dep;
    208207
    209208        device = (netif_device_t *) malloc(sizeof(netif_device_t));
     
    225224        dep->de_mode = DEM_DISABLED;
    226225        //TODO address?
    227         rc = pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port);
    228         if (rc != EOK) {
     226        if(ERROR_OCCURRED(pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port))
     227                || ERROR_OCCURRED(do_probe(dep))){
    229228                free(dep);
    230229                free(device);
    231                 return rc;
    232         }       
    233         rc = do_probe(dep);
    234         if (rc != EOK) {
     230                return ERROR_CODE;
     231        }
     232        if(ERROR_OCCURRED(netif_device_map_add(&netif_globals.device_map, device->device_id, device))){
    235233                free(dep);
    236234                free(device);
    237                 return rc;
    238         }
    239         rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device);
    240         if (rc != EOK){
    241                 free(dep);
    242                 free(device);
    243                 return rc;
     235                return ERROR_CODE;
    244236        }
    245237        return EOK;
     
    247239
    248240int netif_send_message(device_id_t device_id, packet_t packet, services_t sender){
     241        ERROR_DECLARE;
     242
    249243        netif_device_t * device;
    250244        dpeth_t * dep;
    251245        packet_t next;
    252         int rc;
    253 
    254         rc = find_device(device_id, &device);
    255         if (rc != EOK)
    256                 return rc;
     246
     247        ERROR_PROPAGATE(find_device(device_id, &device));
    257248        if(device->state != NETIF_ACTIVE){
    258249                netif_pq_release(packet_get_id(packet));
     
    272263
    273264int netif_start_message(netif_device_t * device){
    274         dpeth_t * dep;
    275         int rc;
     265        ERROR_DECLARE;
     266
     267        dpeth_t * dep;
    276268
    277269        if(device->state != NETIF_ACTIVE){
     
    279271                dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR);
    280272                dp8390_cmds[2].addr = dp8390_cmds[0].addr;
    281                 rc = ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code);
    282                 if (rc != EOK)
    283                         return rc;
    284                 rc = do_init(dep, DL_BROAD_REQ);
    285                 if (rc != EOK) {
     273                ERROR_PROPAGATE(ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code));
     274                if(ERROR_OCCURRED(do_init(dep, DL_BROAD_REQ))){
    286275                        ipc_unregister_irq(dep->de_irq, device->device_id);
    287                         return rc;
     276                        return ERROR_CODE;
    288277                }
    289278                return change_state(device, NETIF_ACTIVE);
     
    361350int main(int argc, char *argv[])
    362351{
    363         int rc;
     352        ERROR_DECLARE;
    364353       
    365354        /* Start the module */
    366         rc = netif_module_start(netif_client_connection);
    367         return rc;
     355        if (ERROR_OCCURRED(netif_module_start(netif_client_connection)))
     356                return ERROR_CODE;
     357       
     358        return EOK;
    368359}
    369360
  • uspace/srv/net/net/net.c

    r7494fb4 r63a1e60  
    4242#include <ddi.h>
    4343#include <errno.h>
     44#include <err.h>
    4445#include <malloc.h>
    4546#include <stdio.h>
     
    9192    const char *value)
    9293{
    93         int rc;
     94        ERROR_DECLARE;
    9495       
    9596        measured_string_ref setting =
     
    99100       
    100101        /* Add the configuration setting */
    101         rc = measured_strings_add(configuration, name, 0, setting);
    102         if (rc != EOK) {
     102        if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
    103103                free(setting);
    104                 return rc;
     104                return ERROR_CODE;
    105105        }
    106106       
     
    110110/** Generate new system-unique device identifier.
    111111 *
    112  * @returns             The system-unique devic identifier.
     112 * @returns The system-unique devic identifier.
     113 *
    113114 */
    114115static device_id_t generate_new_device_id(void)
     
    119120static int parse_line(measured_strings_ref configuration, char *line)
    120121{
    121         int rc;
     122        ERROR_DECLARE;
    122123       
    123124        /* From the beginning */
     
    169170       
    170171        /* Add the configuration setting */
    171         rc = measured_strings_add(configuration, name, 0, setting);
    172         if (rc != EOK) {
     172        if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
    173173                free(setting);
    174                 return rc;
     174                return ERROR_CODE;
    175175        }
    176176       
     
    181181    measured_strings_ref configuration)
    182182{
     183        ERROR_DECLARE;
     184       
    183185        printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename);
    184186       
     
    204206                        if (index >= BUFFER_SIZE) {
    205207                                line[BUFFER_SIZE - 1] = '\0';
    206                                 fprintf(stderr, "%s: Configuration line %u too "
    207                                     "long: %s\n", NAME, line_number, line);
     208                                fprintf(stderr, "%s: Configuration line %u too long: %s\n",
     209                                    NAME, line_number, line);
    208210                               
    209211                                /* No space left in the line buffer */
    210212                                return EOVERFLOW;
     213                        } else {
     214                                /* Append the character */
     215                                line[index] = (char) read;
     216                                index++;
    211217                        }
    212                         /* Append the character */
    213                         line[index] = (char) read;
    214                         index++;
    215218                } else {
    216219                        /* On error or new line */
    217220                        line[index] = '\0';
    218221                        line_number++;
    219                         if (parse_line(configuration, line) != EOK) {
    220                                 fprintf(stderr, "%s: Configuration error on "
    221                                     "line %u: %s\n", NAME, line_number, line);
    222                         }
     222                        if (ERROR_OCCURRED(parse_line(configuration, line)))
     223                                fprintf(stderr, "%s: Configuration error on line %u: %s\n",
     224                                    NAME, line_number, line);
    223225                       
    224226                        index = 0;
     
    268270static int net_initialize(async_client_conn_t client_connection)
    269271{
    270         int rc;
     272        ERROR_DECLARE;
    271273       
    272274        netifs_initialize(&net_globals.netifs);
     
    276278       
    277279        // TODO: dynamic configuration
    278         rc = read_configuration();
    279         if (rc != EOK)
    280                 return rc;
    281        
    282         rc = add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME,
    283             SERVICE_LO, 0, connect_to_service);
    284         if (rc != EOK)
    285                 return rc;
    286         rc = add_module(NULL, &net_globals.modules, DP8390_NAME,
    287             DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service);
    288         if (rc != EOK)
    289                 return rc;
    290         rc = add_module(NULL, &net_globals.modules, ETHERNET_NAME,
    291             ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
    292         if (rc != EOK)
    293                 return rc;
    294         rc = add_module(NULL, &net_globals.modules, NILDUMMY_NAME,
    295             NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
    296         if (rc != EOK)
    297                 return rc;
     280        ERROR_PROPAGATE(read_configuration());
     281       
     282        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
     283            LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));
     284        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
     285            DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));
     286        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
     287            ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0,
     288            connect_to_service));
     289        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
     290            NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0,
     291            connect_to_service));
    298292       
    299293        /* Build specific initialization */
     
    320314static int net_module_start(async_client_conn_t client_connection)
    321315{
     316        ERROR_DECLARE;
     317       
     318        async_set_client_connection(client_connection);
     319        ERROR_PROPAGATE(pm_init());
     320       
    322321        ipcarg_t phonehash;
    323         int rc;
    324        
    325         async_set_client_connection(client_connection);
    326         rc = pm_init();
    327         if (rc != EOK)
    328                 return rc;
    329        
    330        
    331         rc = net_initialize(client_connection);
    332         if (rc != EOK)
    333                 goto out;
    334        
    335         rc = REGISTER_ME(SERVICE_NETWORKING, &phonehash);
    336         if (rc != EOK)
    337                 goto out;
     322       
     323        if (ERROR_OCCURRED(net_initialize(client_connection)) ||
     324            ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))) {
     325                pm_destroy();
     326                return ERROR_CODE;
     327        }
    338328       
    339329        async_manager();
    340 
    341 out:
     330       
    342331        pm_destroy();
    343         return rc;
     332        return EOK;
    344333}
    345334
     
    426415static int start_device(netif_t *netif)
    427416{
    428         int rc;
     417        ERROR_DECLARE;
    429418       
    430419        /* Mandatory netif */
     
    467456        int io = setting ? strtol(setting->value, NULL, 16) : 0;
    468457       
    469         rc = netif_probe_req_remote(netif->driver->phone, netif->id, irq, io);
    470         if (rc != EOK)
    471                 return rc;
     458        ERROR_PROPAGATE(netif_probe_req_remote(netif->driver->phone, netif->id, irq, io));
    472459       
    473460        /* Network interface layer startup */
     
    481468                int mtu = setting ? strtol(setting->value, NULL, 10) : 0;
    482469               
    483                 rc = nil_device_req(netif->nil->phone, netif->id, mtu,
    484                     netif->driver->service);
    485                 if (rc != EOK)
    486                         return rc;
     470                ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu,
     471                    netif->driver->service));
    487472               
    488473                internet_service = netif->nil->service;
     
    493478        switch (netif->il->service) {
    494479        case SERVICE_IP:
    495                 rc = ip_device_req(netif->il->phone, netif->id,
    496                     internet_service);
    497                 if (rc != EOK)
    498                         return rc;
     480                ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id,
     481                    internet_service));
    499482                break;
    500483        default:
     
    502485        }
    503486       
    504         return netif_start_req_remote(netif->driver->phone, netif->id);
     487        ERROR_PROPAGATE(netif_start_req_remote(netif->driver->phone, netif->id));
     488        return EOK;
    505489}
    506490
     
    520504static int startup(void)
    521505{
     506        ERROR_DECLARE;
     507       
    522508        const char *conf_files[] = {
    523509                "lo",
     
    525511        };
    526512        size_t count = sizeof(conf_files) / sizeof(char *);
    527         int rc;
    528513       
    529514        size_t i;
     
    537522                        return EXDEV;
    538523               
    539                 rc = measured_strings_initialize(&netif->configuration);
    540                 if (rc != EOK)
    541                         return rc;
     524                ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
    542525               
    543526                /* Read configuration files */
    544                 rc = read_netif_configuration(conf_files[i], netif);
    545                 if (rc != EOK) {
     527                if (ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))) {
    546528                        measured_strings_destroy(&netif->configuration);
    547529                        free(netif);
    548                         return rc;
     530                        return ERROR_CODE;
    549531                }
    550532               
     
    572554                 * and needed modules.
    573555                 */
    574                 rc = char_map_add(&net_globals.netif_names, netif->name, 0,
    575                     index);
    576                 if (rc != EOK) {
     556                if ((ERROR_OCCURRED(char_map_add(&net_globals.netif_names,
     557                    netif->name, 0, index))) || (ERROR_OCCURRED(start_device(netif)))) {
    577558                        measured_strings_destroy(&netif->configuration);
    578559                        netifs_exclude_index(&net_globals.netifs, index);
    579                         return rc;
    580                 }
    581                
    582                 rc = start_device(netif);
    583                 if (rc != EOK) {
    584                         measured_strings_destroy(&netif->configuration);
    585                         netifs_exclude_index(&net_globals.netifs, index);
    586                         return rc;
     560                        return ERROR_CODE;
    587561                }
    588562               
     
    620594    int *answer_count)
    621595{
     596        ERROR_DECLARE;
     597       
    622598        measured_string_ref strings;
    623599        char *data;
    624         int rc;
    625600       
    626601        *answer_count = 0;
     
    629604                return EOK;
    630605        case NET_NET_GET_DEVICE_CONF:
    631                 rc = measured_strings_receive(&strings, &data,
    632                     IPC_GET_COUNT(call));
    633                 if (rc != EOK)
    634                         return rc;
     606                ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
     607                    IPC_GET_COUNT(call)));
    635608                net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings,
    636609                    IPC_GET_COUNT(call), NULL);
     
    639612                free(data);
    640613               
    641                 rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
     614                ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
    642615                free(strings);
    643                 return rc;
     616                return ERROR_CODE;
    644617        case NET_NET_GET_CONF:
    645                 rc = measured_strings_receive(&strings, &data,
    646                     IPC_GET_COUNT(call));
    647                 if (rc != EOK)
    648                         return rc;
     618                ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
     619                    IPC_GET_COUNT(call)));
    649620                net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL);
    650621               
     
    652623                free(data);
    653624               
    654                 rc = measured_strings_reply(strings, IPC_GET_COUNT(call));
     625                ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
    655626                free(strings);
    656                 return rc;
     627                return ERROR_CODE;
    657628        case NET_NET_STARTUP:
    658629                return startup();
    659630        }
    660        
    661631        return ENOTSUP;
    662632}
     
    700670int main(int argc, char *argv[])
    701671{
    702         int rc;
    703        
    704         rc = net_module_start(net_client_connection);
    705         if (rc != EOK) {
    706                 fprintf(stderr, "%s: net_module_start error %i\n", NAME, rc);
    707                 return rc;
     672        ERROR_DECLARE;
     673       
     674        if (ERROR_OCCURRED(net_module_start(net_client_connection))) {
     675                fprintf(stderr, "%s: net_module_start error %i\n", NAME, ERROR_CODE);
     676                return ERROR_CODE;
    708677        }
    709678       
  • uspace/srv/net/net/net_standalone.c

    r7494fb4 r63a1e60  
    4242#include <ipc/ipc.h>
    4343#include <ipc/net.h>
    44 #include <errno.h>
    4544
    4645#include <ip_interface.h>
     
    6160int net_initialize_build(async_client_conn_t client_connection)
    6261{
    63         int rc;
     62        ERROR_DECLARE;
    6463       
    6564        task_id_t task_id = spawn("/srv/ip");
     
    6766                return EINVAL;
    6867       
    69         rc = add_module(NULL, &net_globals.modules, IP_NAME,
    70             IP_FILENAME, SERVICE_IP, task_id, ip_connect_module);
    71         if (rc != EOK)
    72                 return rc;
     68        ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, IP_NAME,
     69            IP_FILENAME, SERVICE_IP, task_id, ip_connect_module));
    7370       
    7471        if (!spawn("/srv/icmp"))
Note: See TracChangeset for help on using the changeset viewer.