Changeset f4f866c in mainline for uspace/lib


Ignore:
Timestamp:
2010-04-23T21:42:26Z (16 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6c39a907
Parents:
38aaacc2 (diff), 80badbe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/lib
Files:
14 added
4 deleted
73 edited
7 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    r38aaacc2 rf4f866c  
    3535INCLUDE_LIBARCH = include/libarch
    3636
    37 PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH)
     37COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
     38COMMON_HEADER = $(ROOT_PATH)/common.h
     39COMMON_HEADER_ARCH = arch/$(UARCH)/include/common.h
     40
     41CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
     42
     43PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH)
    3844EXTRA_OUTPUT = $(LINKER_SCRIPT)
    39 EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(LINKER_SCRIPT)
     45EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPT)
    4046LIBRARY = libc
    41 
    42 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
    43 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
    4447
    4548-include $(COMMON_MAKEFILE)
     
    5861        generic/mem.c \
    5962        generic/str.c \
     63        generic/str_error.c \
    6064        generic/fibril.c \
    6165        generic/fibril_synch.c \
     
    7579        generic/io/printf_core.c \
    7680        generic/io/console.c \
     81        generic/io/screenbuffer.c \
    7782        generic/malloc.c \
    7883        generic/sysinfo.c \
     
    9095        generic/vfs/vfs.c \
    9196        generic/vfs/canonify.c \
    92         generic/stacktrace.c
     97        generic/stacktrace.c \
     98        generic/arg_parse.c \
     99        generic/stats.c
    93100
    94101SOURCES = \
     
    111118$(LINKER_SCRIPT): $(LINKER_SCRIPT).in
    112119        $(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -E -x c $< | grep -v "^\#" > $@
     120
     121$(COMMON_HEADER_ARCH): $(COMMON_HEADER)
     122        ln -sfn ../../../$< $@
  • uspace/lib/c/arch/abs32le/include/types.h

    r38aaacc2 rf4f866c  
    3838#define __32_BITS__
    3939
    40 typedef unsigned int sysarg_t;
     40#include <libarch/common.h>
    4141
    42 typedef char int8_t;
    43 typedef short int int16_t;
    44 typedef int int32_t;
    45 typedef long long int int64_t;
    46 
    47 typedef unsigned char uint8_t;
    48 typedef unsigned short int uint16_t;
    49 typedef unsigned int uint32_t;
    50 typedef unsigned long long int uint64_t;
     42typedef uint32_t sysarg_t;
    5143
    5244typedef int32_t ssize_t;
  • uspace/lib/c/arch/amd64/include/types.h

    r38aaacc2 rf4f866c  
    3838#define __64_BITS__
    3939
    40 typedef unsigned long long sysarg_t;
     40#include <libarch/common.h>
    4141
    42 typedef signed char int8_t;
    43 typedef short int int16_t;
    44 typedef int int32_t;
    45 typedef long long int int64_t;
    46 
    47 typedef unsigned char uint8_t;
    48 typedef unsigned short int uint16_t;
    49 typedef unsigned int uint32_t;
    50 typedef unsigned long long int uint64_t;
     42typedef uint64_t sysarg_t;
    5143
    5244typedef int64_t ssize_t;
  • uspace/lib/c/arch/arm32/include/types.h

    r38aaacc2 rf4f866c  
    2727 */
    2828
    29 /** @addtogroup libcarm32       
     29/** @addtogroup libcarm32
    3030 * @{
    3131 */
    32 /** @file 
     32/** @file
    3333 *  @brief Definitions of basic types like #uintptr_t.
    3434 */
     
    3939#define __32_BITS__
    4040
    41 typedef unsigned int sysarg_t;
     41#include <libarch/common.h>
    4242
    43 typedef char int8_t;
    44 typedef short int int16_t;
    45 typedef long int int32_t;
    46 typedef long long int int64_t;
    47 
    48 typedef unsigned char uint8_t;
    49 typedef unsigned short int uint16_t;
    50 typedef unsigned long int uint32_t;
    51 typedef unsigned long long int uint64_t;
     43typedef uint32_t sysarg_t;
    5244
    5345typedef int32_t ssize_t;
  • uspace/lib/c/arch/ia32/include/types.h

    r38aaacc2 rf4f866c  
    3838#define __32_BITS__
    3939
    40 typedef unsigned int sysarg_t;
     40#include <libarch/common.h>
    4141
    42 typedef char int8_t;
    43 typedef short int int16_t;
    44 typedef int int32_t;
    45 typedef long long int int64_t;
    46 
    47 typedef unsigned char uint8_t;
    48 typedef unsigned short int uint16_t;
    49 typedef unsigned int uint32_t;
    50 typedef unsigned long long int uint64_t;
     42typedef uint32_t sysarg_t;
    5143
    5244typedef int32_t ssize_t;
  • uspace/lib/c/arch/ia64/include/types.h

    r38aaacc2 rf4f866c  
    3838#define __64_BITS__
    3939
    40 typedef unsigned long sysarg_t;
     40#include <libarch/common.h>
    4141
    42 typedef char int8_t;
    43 typedef short int int16_t;
    44 typedef int int32_t;
    45 typedef long int int64_t;
    46 
    47 typedef unsigned char uint8_t;
    48 typedef unsigned short int uint16_t;
    49 typedef unsigned int uint32_t;
    50 typedef unsigned long int uint64_t;
     42typedef struct {
     43        uint64_t lo;
     44        int64_t hi;
     45} int128_t;
    5146
    5247typedef struct {
     
    5449        uint64_t hi;
    5550} uint128_t;
     51
     52typedef uint64_t sysarg_t;
    5653
    5754typedef int64_t ssize_t;
  • uspace/lib/c/arch/ia64/src/ddi.c

    r38aaacc2 rf4f866c  
    22#include <sysinfo.h>
    33
    4 uint64_t ia64_iospace_address=0;
    5 
     4uint64_t ia64_iospace_address = 0;
    65
    76uint64_t get_ia64_iospace_address(void)
    87{
    9 
    10         return sysinfo_value("ia64_iospace.address.virtual");
    11 
     8        sysarg_t addr;
     9        if (sysinfo_get_value("ia64_iospace.address.virtual", &addr) != 0)
     10                addr = 0;
     11       
     12        return addr;
    1213}
    1314
  • uspace/lib/c/arch/mips32/include/types.h

    r38aaacc2 rf4f866c  
    3939#define __32_BITS__
    4040
    41 typedef unsigned int sysarg_t;
     41#include <libarch/common.h>
    4242
    43 typedef char int8_t;
    44 typedef short int int16_t;
    45 typedef long int int32_t;
    46 typedef long long int int64_t;
    47 
    48 typedef unsigned char uint8_t;
    49 typedef unsigned short int uint16_t;
    50 typedef unsigned long int uint32_t;
    51 typedef unsigned long long int uint64_t;
     43typedef uint32_t sysarg_t;
    5244
    5345typedef int32_t ssize_t;
  • uspace/lib/c/arch/ppc32/include/types.h

    r38aaacc2 rf4f866c  
    3838#define __32_BITS__
    3939
    40 typedef unsigned int sysarg_t;
     40#include <libarch/common.h>
    4141
    42 typedef char int8_t;
    43 typedef short int int16_t;
    44 typedef int int32_t;
    45 typedef long long int int64_t;
    46 
    47 typedef unsigned char uint8_t;
    48 typedef unsigned short int uint16_t;
    49 typedef unsigned int uint32_t;
    50 typedef unsigned long long int uint64_t;
     42typedef uint32_t sysarg_t;
    5143
    5244typedef int32_t ssize_t;
  • uspace/lib/c/arch/sparc64/include/types.h

    r38aaacc2 rf4f866c  
    3838#define __64_BITS__
    3939
    40 typedef unsigned long sysarg_t;
     40#include <libarch/common.h>
    4141
    42 typedef signed char int8_t;
    43 typedef short int int16_t;
    44 typedef int int32_t;
    45 typedef long int int64_t;
    46 
    47 typedef unsigned char uint8_t;
    48 typedef unsigned short int uint16_t;
    49 typedef unsigned int uint32_t;
    50 typedef unsigned long int uint64_t;
     42typedef uint64_t sysarg_t;
    5143
    5244typedef int64_t ssize_t;
  • uspace/lib/c/generic/adt/hash_table.c

    r38aaacc2 rf4f866c  
    4242#include <malloc.h>
    4343#include <assert.h>
    44 #include <stdio.h>
    4544#include <str.h>
    4645
    4746/** Create chained hash table.
    4847 *
    49  * @param h             Hash table structure. Will be initialized by this call.
    50  * @param m             Number of hash table buckets.
    51  * @param max_keys      Maximal number of keys needed to identify an item.
    52  * @param op            Hash table operations structure.
    53  * @return              True on success
     48 * @param h        Hash table structure. Will be initialized by this call.
     49 * @param m        Number of hash table buckets.
     50 * @param max_keys Maximal number of keys needed to identify an item.
     51 * @param op       Hash table operations structure.
     52 *
     53 * @return True on success
     54 *
    5455 */
    5556int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys,
    5657    hash_table_operations_t *op)
    5758{
    58         hash_count_t i;
    59 
    6059        assert(h);
    6160        assert(op && op->hash && op->compare);
     
    6362       
    6463        h->entry = malloc(m * sizeof(link_t));
    65         if (!h->entry) {
    66                 printf("cannot allocate memory for hash table\n");
     64        if (!h->entry)
    6765                return false;
    68         }
     66       
    6967        memset((void *) h->entry, 0,  m * sizeof(link_t));
    7068       
     69        hash_count_t i;
    7170        for (i = 0; i < m; i++)
    7271                list_initialize(&h->entry[i]);
     
    7574        h->max_keys = max_keys;
    7675        h->op = op;
     76       
    7777        return true;
    7878}
     
    8080/** Destroy a hash table instance.
    8181 *
    82  * @param h             Hash table to be destroyed.
     82 * @param h Hash table to be destroyed.
     83 *
    8384 */
    8485void hash_table_destroy(hash_table_t *h)
     
    8687        assert(h);
    8788        assert(h->entry);
     89       
    8890        free(h->entry);
    8991}
     
    9193/** Insert item into a hash table.
    9294 *
    93  * @param h             Hash table.
    94  * @param key           Array of all keys necessary to compute hash index.
    95  * @param item          Item to be inserted into the hash table.
     95 * @param h    Hash table.
     96 * @param key  Array of all keys necessary to compute hash index.
     97 * @param item Item to be inserted into the hash table.
    9698 */
    9799void hash_table_insert(hash_table_t *h, unsigned long key[], link_t *item)
    98100{
    99         hash_index_t chain;
    100 
    101101        assert(item);
    102102        assert(h && h->op && h->op->hash && h->op->compare);
    103 
    104         chain = h->op->hash(key);
     103       
     104        hash_index_t chain = h->op->hash(key);
    105105        assert(chain < h->entries);
    106106       
     
    110110/** Search hash table for an item matching keys.
    111111 *
    112  * @param h             Hash table.
    113  * @param key           Array of all keys needed to compute hash index.
    114  *
    115  * @return              Matching item on success, NULL if there is no such item.
     112 * @param h   Hash table.
     113 * @param key Array of all keys needed to compute hash index.
     114 *
     115 * @return Matching item on success, NULL if there is no such item.
     116 *
    116117 */
    117118link_t *hash_table_find(hash_table_t *h, unsigned long key[])
    118119{
     120        assert(h && h->op && h->op->hash && h->op->compare);
     121       
     122        hash_index_t chain = h->op->hash(key);
     123        assert(chain < h->entries);
     124       
    119125        link_t *cur;
    120         hash_index_t chain;
    121 
    122         assert(h && h->op && h->op->hash && h->op->compare);
    123 
    124         chain = h->op->hash(key);
    125         assert(chain < h->entries);
    126        
    127126        for (cur = h->entry[chain].next; cur != &h->entry[chain];
    128127            cur = cur->next) {
     
    142141 * For each removed item, h->remove_callback() is called.
    143142 *
    144  * @param h             Hash table.
    145  * @param key           Array of keys that will be compared against items of
    146  *                      the hash table.
    147  * @param keys          Number of keys in the 'key' array.
     143 * @param h    Hash table.
     144 * @param key  Array of keys that will be compared against items of
     145 *             the hash table.
     146 * @param keys Number of keys in the 'key' array.
     147 *
    148148 */
    149149void hash_table_remove(hash_table_t *h, unsigned long key[], hash_count_t keys)
    150150{
    151         hash_index_t chain;
    152         link_t *cur;
    153 
    154151        assert(h && h->op && h->op->hash && h->op->compare &&
    155152            h->op->remove_callback);
    156153        assert(keys <= h->max_keys);
    157154       
     155        link_t *cur;
     156       
    158157        if (keys == h->max_keys) {
    159 
    160158                /*
    161159                 * All keys are known, hash_table_find() can be used to find the
    162160                 * entry.
    163161                 */
    164        
     162               
    165163                cur = hash_table_find(h, key);
    166164                if (cur) {
     
    168166                        h->op->remove_callback(cur);
    169167                }
     168               
    170169                return;
    171170        }
     
    175174         * Any partially matching entries are to be removed.
    176175         */
     176        hash_index_t chain;
    177177        for (chain = 0; chain < h->entries; chain++) {
    178178                for (cur = h->entry[chain].next; cur != &h->entry[chain];
     
    195195/** Apply fucntion to all items in hash table.
    196196 *
    197  * @param h             Hash table.
    198  * @param f             Function to be applied.
    199  * @param arg           Argument to be passed to the function.
    200  */
    201 void
    202 hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg)
     197 * @param h   Hash table.
     198 * @param f   Function to be applied.
     199 * @param arg Argument to be passed to the function.
     200 *
     201 */
     202void hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg)
    203203{
    204204        hash_index_t bucket;
    205205        link_t *cur;
    206 
     206       
    207207        for (bucket = 0; bucket < h->entries; bucket++) {
    208208                for (cur = h->entry[bucket].next; cur != &h->entry[bucket];
  • uspace/lib/c/generic/async.c

    r38aaacc2 rf4f866c  
    746746        if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1,
    747747            &conn_hash_table_ops)) {
    748                 printf("%s: cannot create hash table\n", "async");
     748                printf("%s: Cannot create async hash table\n", "libc");
    749749                return ENOMEM;
    750750        }
  • uspace/lib/c/generic/fibril.c

    r38aaacc2 rf4f866c  
    4848
    4949#ifndef FIBRIL_INITIAL_STACK_PAGES_NO
    50 #define FIBRIL_INITIAL_STACK_PAGES_NO   1
     50        #define FIBRIL_INITIAL_STACK_PAGES_NO  1
    5151#endif
    5252
    5353/**
    54  * This futex serializes access to ready_list, serialized_list and manager_list.
    55  */
     54 * This futex serializes access to ready_list,
     55 * serialized_list and manager_list.
     56 */
    5657static atomic_t fibril_futex = FUTEX_INITIALIZER;
    5758
     
    6061static LIST_INITIALIZE(manager_list);
    6162
    62 static void fibril_main(void);
    63 
    6463/** Number of threads that are executing a manager fibril. */
    6564static int threads_in_manager;
    66 /** Number of threads that are executing a manager fibril and are serialized. */
    67 static int serialized_threads;  /* Protected by async_futex */
     65
     66/**
     67 * Number of threads that are executing a manager fibril
     68 * and are serialized. Protected by async_futex.
     69 */
     70static int serialized_threads;
     71
    6872/** Fibril-local count of serialization. If > 0, we must not preempt */
    6973static fibril_local int serialization_count;
    70 
    71 /** Setup fibril information into TCB structure */
    72 fibril_t *fibril_setup(void)
    73 {
    74         fibril_t *f;
    75         tcb_t *tcb;
    76 
    77         tcb = __make_tls();
    78         if (!tcb)
    79                 return NULL;
    80 
    81         f = malloc(sizeof(fibril_t));
    82         if (!f) {
    83                 __free_tls(tcb);
    84                 return NULL;
    85         }
    86 
    87         tcb->fibril_data = f;
    88         f->tcb = tcb;
    89 
    90         f->func = NULL;
    91         f->arg = NULL;
    92         f->stack = NULL;
    93         f->clean_after_me = NULL;
    94         f->retval = 0;
    95         f->flags = 0;
    96 
    97         return f;
    98 }
    99 
    100 void fibril_teardown(fibril_t *f)
    101 {
    102         __free_tls(f->tcb);
    103         free(f);
    104 }
    10574
    10675/** Function that spans the whole life-cycle of a fibril.
     
    10978 * the fibril logic is called.  After its return, the return value is saved.
    11079 * The fibril then switches to another fibril, which cleans up after it.
    111  */
    112 void fibril_main(void)
    113 {
    114         fibril_t *f = __tcb_get()->fibril_data;
    115 
     80 *
     81 */
     82static void fibril_main(void)
     83{
     84        fibril_t *fibril = __tcb_get()->fibril_data;
     85       
    11686        /* Call the implementing function. */
    117         f->retval = f->func(f->arg);
    118 
     87        fibril->retval = fibril->func(fibril->arg);
     88       
    11989        fibril_switch(FIBRIL_FROM_DEAD);
    120         /* not reached */
     90        /* Not reached */
     91}
     92
     93/** Setup fibril information into TCB structure
     94 *
     95 */
     96fibril_t *fibril_setup(void)
     97{
     98        tcb_t *tcb = __make_tls();
     99        if (!tcb)
     100                return NULL;
     101       
     102        fibril_t *fibril = malloc(sizeof(fibril_t));
     103        if (!fibril) {
     104                __free_tls(tcb);
     105                return NULL;
     106        }
     107       
     108        tcb->fibril_data = fibril;
     109        fibril->tcb = tcb;
     110       
     111        fibril->func = NULL;
     112        fibril->arg = NULL;
     113        fibril->stack = NULL;
     114        fibril->clean_after_me = NULL;
     115        fibril->retval = 0;
     116        fibril->flags = 0;
     117       
     118        return fibril;
     119}
     120
     121void fibril_teardown(fibril_t *fibril)
     122{
     123        __free_tls(fibril->tcb);
     124        free(fibril);
    121125}
    122126
     
    126130 * held.
    127131 *
    128  * @param stype         Switch type. One of FIBRIL_PREEMPT, FIBRIL_TO_MANAGER,
    129  *                      FIBRIL_FROM_MANAGER, FIBRIL_FROM_DEAD. The parameter
    130  *                      describes the circumstances of the switch.
    131  * @return              Return 0 if there is no ready fibril,
    132  *                      return 1 otherwise.
     132 * @param stype Switch type. One of FIBRIL_PREEMPT, FIBRIL_TO_MANAGER,
     133 *              FIBRIL_FROM_MANAGER, FIBRIL_FROM_DEAD. The parameter
     134 *              describes the circumstances of the switch.
     135 *
     136 * @return 0 if there is no ready fibril,
     137 * @return 1 otherwise.
     138 *
    133139 */
    134140int fibril_switch(fibril_switch_type_t stype)
     
    246252/** Create a new fibril.
    247253 *
    248  * @param func          Implementing function of the new fibril.
    249  * @param arg           Argument to pass to func.
    250  *
    251  * @return              Return 0 on failure or TLS of the new fibril.
     254 * @param func Implementing function of the new fibril.
     255 * @param arg Argument to pass to func.
     256 *
     257 * @return 0 on failure or TLS of the new fibril.
     258 *
    252259 */
    253260fid_t fibril_create(int (*func)(void *), void *arg)
    254261{
    255         fibril_t *f;
    256 
    257         f = fibril_setup();
    258         if (!f)
     262        fibril_t *fibril;
     263       
     264        fibril = fibril_setup();
     265        if (fibril == NULL)
    259266                return 0;
    260         f->stack = (char *) malloc(FIBRIL_INITIAL_STACK_PAGES_NO *
    261             getpagesize());
    262         if (!f->stack) {
    263                 fibril_teardown(f);
     267       
     268        fibril->stack =
     269            (char *) malloc(FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize());
     270        if (!fibril->stack) {
     271                fibril_teardown(fibril);
    264272                return 0;
    265273        }
    266274       
    267         f->func = func;
    268         f->arg = arg;
    269 
    270         context_save(&f->ctx);
    271         context_set(&f->ctx, FADDR(fibril_main), f->stack,
    272             FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize(), f->tcb);
    273 
    274         return (fid_t) f;
     275        fibril->func = func;
     276        fibril->arg = arg;
     277       
     278        context_save(&fibril->ctx);
     279        context_set(&fibril->ctx, FADDR(fibril_main), fibril->stack,
     280            FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize(), fibril->tcb);
     281
     282        return (fid_t) fibril;
    275283}
    276284
    277285/** Add a fibril to the ready list.
    278286 *
    279  * @param fid           Pointer to the fibril structure of the fibril to be
    280  *                      added.
     287 * @param fid Pointer to the fibril structure of the fibril to be
     288 *            added.
     289 *
    281290 */
    282291void fibril_add_ready(fid_t fid)
    283292{
    284         fibril_t *f;
    285 
    286         f = (fibril_t *) fid;
     293        fibril_t *fibril = (fibril_t *) fid;
     294       
    287295        futex_down(&fibril_futex);
    288         if ((f->flags & FIBRIL_SERIALIZED))
    289                 list_append(&f->link, &serialized_list);
     296       
     297        if ((fibril->flags & FIBRIL_SERIALIZED))
     298                list_append(&fibril->link, &serialized_list);
    290299        else
    291                 list_append(&f->link, &ready_list);
     300                list_append(&fibril->link, &ready_list);
     301       
    292302        futex_up(&fibril_futex);
    293303}
     
    295305/** Add a fibril to the manager list.
    296306 *
    297  * @param fid           Pointer to the fibril structure of the fibril to be
    298  *                      added.
     307 * @param fid Pointer to the fibril structure of the fibril to be
     308 *            added.
     309 *
    299310 */
    300311void fibril_add_manager(fid_t fid)
    301312{
    302         fibril_t *f;
    303 
    304         f = (fibril_t *) fid;
    305 
     313        fibril_t *fibril = (fibril_t *) fid;
     314       
    306315        futex_down(&fibril_futex);
    307         list_append(&f->link, &manager_list);
     316        list_append(&fibril->link, &manager_list);
    308317        futex_up(&fibril_futex);
    309318}
     
    313322{
    314323        futex_down(&fibril_futex);
    315         if (list_empty(&manager_list)) {
    316                 futex_up(&fibril_futex);
    317                 return;
    318         }
    319         list_remove(manager_list.next);
     324       
     325        if (!list_empty(&manager_list))
     326                list_remove(manager_list.next);
     327       
    320328        futex_up(&fibril_futex);
    321329}
  • uspace/lib/c/generic/futex.c

    r38aaacc2 rf4f866c  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#include <futex.h>
     
    4040/** Initialize futex counter.
    4141 *
    42  * @param futex         Futex.
    43  * @param val           Initialization value.
     42 * @param futex Futex.
     43 * @param val   Initialization value.
     44 *
    4445 */
    4546void futex_initialize(futex_t *futex, int val)
     
    5051/** Try to down the futex.
    5152 *
    52  * @param futex         Futex.
    53  * @return              Non-zero if the futex was acquired.
    54  * @return              Zero if the futex was not acquired.
     53 * @param futex Futex.
     54 *
     55 * @return Non-zero if the futex was acquired.
     56 * @return Zero if the futex was not acquired.
     57 *
    5558 */
    5659int futex_trydown(futex_t *futex)
     
    6164/** Down the futex.
    6265 *
    63  * @param futex         Futex.
    64  * @return              ENOENT if there is no such virtual address.
    65  * @return              Zero in the uncontended case.
    66  * @return              Otherwise one of ESYNCH_OK_ATOMIC or ESYNCH_OK_BLOCKED.
     66 * @param futex Futex.
     67 *
     68 * @return ENOENT if there is no such virtual address.
     69 * @return Zero in the uncontended case.
     70 * @return Otherwise one of ESYNCH_OK_ATOMIC or ESYNCH_OK_BLOCKED.
     71 *
    6772 */
    6873int futex_down(futex_t *futex)
     
    7075        if ((atomic_signed_t) atomic_predec(futex) < 0)
    7176                return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count);
    72 
     77       
    7378        return 0;
    7479}
     
    7681/** Up the futex.
    7782 *
    78  * @param futex         Futex.
    79  * @return              ENOENT if there is no such virtual address.
    80  * @return              Zero in the uncontended case.
     83 * @param futex Futex.
     84 *
     85 * @return ENOENT if there is no such virtual address.
     86 * @return Zero in the uncontended case.
     87 *
    8188 */
    8289int futex_up(futex_t *futex)
     
    8491        if ((atomic_signed_t) atomic_postinc(futex) < 0)
    8592                return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->count);
    86                
     93       
    8794        return 0;
    8895}
  • uspace/lib/c/generic/io/asprintf.c

    r38aaacc2 rf4f866c  
    6161int asprintf(char **strp, const char *fmt, ...)
    6262{
    63         struct printf_spec ps = {
     63        printf_spec_t ps = {
    6464                asprintf_str_write,
    6565                asprintf_wstr_write,
  • uspace/lib/c/generic/io/console.c

    r38aaacc2 rf4f866c  
    4545}
    4646
    47 int console_get_size(int phone, int *cols, int *rows)
     47int console_get_size(int phone, ipcarg_t *cols, ipcarg_t *rows)
    4848{
    49         ipcarg_t cols_v;
    50         ipcarg_t rows_v;
    51         int rc;
    52 
    53         rc = async_req_0_2(phone, CONSOLE_GET_SIZE, &cols_v, &rows_v);
    54 
    55         *cols = (int) cols_v;
    56         *rows = (int) rows_v;
    57         return rc;
     49        return async_req_0_2(phone, CONSOLE_GET_SIZE, cols, rows);
    5850}
    5951
    60 void console_set_style(int phone, int style)
     52void console_set_style(int phone, uint8_t style)
    6153{
    6254        async_msg_1(phone, CONSOLE_SET_STYLE, style);
    6355}
    6456
    65 void console_set_color(int phone, int fg_color, int bg_color, int flags)
     57void console_set_color(int phone, uint8_t fg_color, uint8_t bg_color,
     58    uint8_t flags)
    6659{
    6760        async_msg_3(phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
    6861}
    6962
    70 void console_set_rgb_color(int phone, int fg_color, int bg_color)
     63void console_set_rgb_color(int phone, uint32_t fg_color, uint32_t bg_color)
    7164{
    7265        async_msg_2(phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
     
    7568void console_cursor_visibility(int phone, bool show)
    7669{
    77         async_msg_1(phone, CONSOLE_CURSOR_VISIBILITY, show != false);
     70        async_msg_1(phone, CONSOLE_CURSOR_VISIBILITY, (show != false));
    7871}
    7972
    80 int console_get_color_cap(int phone, int *ccap)
     73int console_get_color_cap(int phone, ipcarg_t *ccap)
    8174{
    82         ipcarg_t ccap_tmp;
    83         int rc;
    84 
    85         rc = async_req_0_1(phone, CONSOLE_GET_COLOR_CAP, &ccap_tmp);
    86         *ccap = ccap_tmp;
    87 
    88         return rc;
     75        return async_req_0_1(phone, CONSOLE_GET_COLOR_CAP, ccap);
    8976}
    9077
     
    9481}
    9582
    96 int console_get_pos(int phone, int *col, int *row)
     83int console_get_pos(int phone, ipcarg_t *col, ipcarg_t *row)
    9784{
    98         ipcarg_t col_v;
    99         ipcarg_t row_v;
    100         int rc;
    101 
    102         rc = async_req_0_2(phone, CONSOLE_GET_POS, &col_v, &row_v);
    103 
    104         *col = (int) col_v;
    105         *row = (int) row_v;
    106         return rc;
     85        return async_req_0_2(phone, CONSOLE_GET_POS, col, row);
    10786}
    10887
    109 void console_goto(int phone, int col, int row)
     88void console_set_pos(int phone, ipcarg_t col, ipcarg_t row)
    11089{
    11190        async_msg_2(phone, CONSOLE_GOTO, col, row);
  • uspace/lib/c/generic/io/printf_core.c

    r38aaacc2 rf4f866c  
    4545/** show prefixes 0x or 0 */
    4646#define __PRINTF_FLAG_PREFIX       0x00000001
     47
    4748/** signed / unsigned number */
    4849#define __PRINTF_FLAG_SIGNED       0x00000002
     50
    4951/** print leading zeroes */
    5052#define __PRINTF_FLAG_ZEROPADDED   0x00000004
     53
    5154/** align to left */
    5255#define __PRINTF_FLAG_LEFTALIGNED  0x00000010
     56
    5357/** always show + sign */
    5458#define __PRINTF_FLAG_SHOWPLUS     0x00000020
     59
    5560/** print space instead of plus */
    5661#define __PRINTF_FLAG_SPACESIGN    0x00000040
     62
    5763/** show big characters */
    5864#define __PRINTF_FLAG_BIGCHARS     0x00000080
     65
    5966/** number has - sign */
    6067#define __PRINTF_FLAG_NEGATIVE     0x00000100
     
    7885} qualifier_t;
    7986
    80 static char nullstr[] = "(NULL)";
    81 static char digits_small[] = "0123456789abcdef";
    82 static char digits_big[] = "0123456789ABCDEF";
    83 static char invalch = U_SPECIAL;
     87static const char *nullstr = "(NULL)";
     88static const char *digits_small = "0123456789abcdef";
     89static const char *digits_big = "0123456789ABCDEF";
     90static const char invalch = U_SPECIAL;
    8491
    8592/** Print one or more characters without adding newline.
     
    350357    uint32_t flags, printf_spec_t *ps)
    351358{
    352         char *digits;
     359        const char *digits;
    353360        if (flags & __PRINTF_FLAG_BIGCHARS)
    354361                digits = digits_big;
  • uspace/lib/c/generic/io/screenbuffer.c

    r38aaacc2 rf4f866c  
    3434
    3535#include <io/style.h>
     36#include <io/screenbuffer.h>
    3637#include <malloc.h>
    3738#include <unistd.h>
    38 #include "screenbuffer.h"
    3939
    4040/** Store one character to screenbuffer.
     
    6767 *
    6868 */
    69 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y)
     69screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, ipcarg_t size_x,
     70    ipcarg_t size_y)
    7071{
    7172        scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
     
    109110 *
    110111 */
    111 void screenbuffer_clear_line(screenbuffer_t *scr, size_t line)
     112void screenbuffer_clear_line(screenbuffer_t *scr, ipcarg_t line)
    112113{
    113         size_t x;
     114        ipcarg_t x;
    114115       
    115116        for (x = 0; x < scr->size_x; x++) {
     
    140141 *
    141142 */
    142 void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y)
     143void screenbuffer_goto(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
    143144{
    144145        scr->position_x = x % scr->size_x;
     
    166167 *
    167168 */
    168 void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, uint8_t bg_color, uint8_t flags)
     169void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
     170    uint8_t bg_color, uint8_t flags)
    169171{
    170172        scr->attrs.t = at_idx;
     
    181183 *
    182184 */
    183 void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, uint32_t bg_color)
     185void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
     186    uint32_t bg_color)
    184187{
    185188        scr->attrs.t = at_rgb;
  • uspace/lib/c/generic/io/vprintf.c

    r38aaacc2 rf4f866c  
    7676int vfprintf(FILE *stream, const char *fmt, va_list ap)
    7777{
    78         struct printf_spec ps = {
     78        printf_spec_t ps = {
    7979                vprintf_str_write,
    8080                vprintf_wstr_write,
  • uspace/lib/c/generic/libc.c

    r38aaacc2 rf4f866c  
    6262void __main(void *pcb_ptr)
    6363{
    64         int retval;
    65 
     64        /* Initialize user task run-time environment */
    6665        __heap_init();
    6766        __async_init();
     
    7574        char **argv;
    7675       
     76        /* Get command line arguments and initialize
     77           standard input and output */
    7778        if (__pcb == NULL) {
    7879                argc = 0;
     
    8687        }
    8788       
    88         retval = main(argc, argv);
    89 
    90         __stdio_done();
    91         (void) task_retval(retval);
     89        /* Run main() and set task return value
     90           according the result */
     91        (void) task_retval(main(argc, argv));
    9292}
    9393
    9494void __exit(void)
    9595{
     96        __stdio_done();
    9697        fibril_teardown(__tcb_get()->fibril_data);
    9798        _exit(0);
  • uspace/lib/c/generic/malloc.c

    r38aaacc2 rf4f866c  
    4343#include <bitops.h>
    4444#include <mem.h>
     45#include <futex.h>
    4546#include <adt/gcdlcm.h>
    4647
     
    7576#define NET_SIZE(size)  ((size) - STRUCT_OVERHEAD)
    7677
    77 
    7878/** Header of a heap block
    7979 *
     
    104104extern char _heap;
    105105
     106/** Futex for thread-safe heap manipulation */
     107static futex_t malloc_futex = FUTEX_INITIALIZER;
     108
    106109/** Address of heap start */
    107110static void *heap_start = 0;
     
    119122 *
    120123 * Fills in the structures related to a heap block.
     124 * Should be called only inside the critical section.
    121125 *
    122126 * @param addr Address of the block.
     
    144148 * Verifies that the structures related to a heap block still contain
    145149 * the magic constants. This helps detect heap corruption early on.
     150 * Should be called only inside the critical section.
    146151 *
    147152 * @param addr Address of the block.
     
    161166}
    162167
     168/** Increase the heap area size
     169 *
     170 * Should be called only inside the critical section.
     171 *
     172 * @param size Number of bytes to grow the heap by.
     173 *
     174 */
    163175static bool grow_heap(size_t size)
    164176{
     
    189201}
    190202
     203/** Decrease the heap area
     204 *
     205 * Should be called only inside the critical section.
     206 *
     207 * @param size Number of bytes to shrink the heap by.
     208 *
     209 */
    191210static void shrink_heap(void)
    192211{
     
    196215/** Initialize the heap allocator
    197216 *
    198  * Finds how much physical memory we have and creates
     217 * Find how much physical memory we have and create
    199218 * the heap management structures that mark the whole
    200219 * physical memory as a single free block.
     
    203222void __heap_init(void)
    204223{
     224        futex_down(&malloc_futex);
     225       
    205226        if (as_area_create((void *) &_heap, PAGE_SIZE,
    206227            AS_AREA_WRITE | AS_AREA_READ)) {
     
    213234                block_init(heap_start, heap_end - heap_start, true);
    214235        }
    215 }
    216 
     236       
     237        futex_up(&malloc_futex);
     238}
     239
     240/** Get maximum heap address
     241 *
     242 */
    217243uintptr_t get_max_heap_addr(void)
    218244{
     245        futex_down(&malloc_futex);
     246       
    219247        if (max_heap_size == (size_t) -1)
    220248                max_heap_size =
    221249                    max((size_t) (heap_end - heap_start), MAX_HEAP_SIZE);
    222250       
    223         return ((uintptr_t) heap_start + max_heap_size);
    224 }
    225 
     251        uintptr_t max_heap_addr = (uintptr_t) heap_start + max_heap_size;
     252       
     253        futex_up(&malloc_futex);
     254       
     255        return max_heap_addr;
     256}
     257
     258/** Split heap block and mark it as used.
     259 *
     260 * Should be called only inside the critical section.
     261 *
     262 * @param cur  Heap block to split.
     263 * @param size Number of bytes to split and mark from the beginning
     264 *             of the block.
     265 *
     266 */
    226267static void split_mark(heap_block_head_t *cur, const size_t size)
    227268{
     
    243284
    244285/** Allocate a memory block
     286 *
     287 * Should be called only inside the critical section.
    245288 *
    246289 * @param size  The size of the block to allocate.
     
    356399}
    357400
     401/** Allocate memory by number of elements
     402 *
     403 * @param nmemb Number of members to allocate.
     404 * @param size  Size of one member in bytes.
     405 *
     406 * @return Allocated memory or NULL.
     407 *
     408 */
    358409void *calloc(const size_t nmemb, const size_t size)
    359410{
     
    361412        if (block == NULL)
    362413                return NULL;
    363 
     414       
    364415        memset(block, 0, nmemb * size);
    365416        return block;
    366417}
    367418
     419/** Allocate memory
     420 *
     421 * @param size Number of bytes to allocate.
     422 *
     423 * @return Allocated memory or NULL.
     424 *
     425 */
    368426void *malloc(const size_t size)
    369427{
    370         return malloc_internal(size, BASE_ALIGN);
    371 }
    372 
     428        futex_down(&malloc_futex);
     429        void *block = malloc_internal(size, BASE_ALIGN);
     430        futex_up(&malloc_futex);
     431       
     432        return block;
     433}
     434
     435/** Allocate memory with specified alignment
     436 *
     437 * @param align Alignment in byes.
     438 * @param size  Number of bytes to allocate.
     439 *
     440 * @return Allocated memory or NULL.
     441 *
     442 */
    373443void *memalign(const size_t align, const size_t size)
    374444{
     
    379449            1 << (fnzb(max(sizeof(void *), align) - 1) + 1);
    380450       
    381         return malloc_internal(size, palign);
    382 }
    383 
     451        futex_down(&malloc_futex);
     452        void *block = malloc_internal(size, palign);
     453        futex_up(&malloc_futex);
     454       
     455        return block;
     456}
     457
     458/** Reallocate memory block
     459 *
     460 * @param addr Already allocated memory or NULL.
     461 * @param size New size of the memory block.
     462 *
     463 * @return Reallocated memory or NULL.
     464 *
     465 */
    384466void *realloc(const void *addr, const size_t size)
    385467{
    386468        if (addr == NULL)
    387469                return malloc(size);
     470       
     471        futex_down(&malloc_futex);
    388472       
    389473        /* Calculate the position of the header. */
     
    398482       
    399483        void *ptr = NULL;
     484        bool reloc = false;
    400485        size_t real_size = GROSS_SIZE(ALIGN_UP(size, BASE_ALIGN));
    401486        size_t orig_size = head->size;
     
    415500        } else {
    416501                /* Look at the next block. If it is free and the size is
    417                    sufficient then merge the two. */
     502                   sufficient then merge the two. Otherwise just allocate
     503                   a new block, copy the original data into it and
     504                   free the original block. */
    418505                heap_block_head_t *next_head =
    419506                    (heap_block_head_t *) (((void *) head) + head->size);
     
    427514                       
    428515                        ptr = ((void *) head) + sizeof(heap_block_head_t);
    429                 } else {
    430                         ptr = malloc(size);
    431                         if (ptr != NULL) {
    432                                 memcpy(ptr, addr, NET_SIZE(orig_size));
    433                                 free(addr);
    434                         }
     516                } else
     517                        reloc = true;
     518        }
     519       
     520        futex_up(&malloc_futex);
     521       
     522        if (reloc) {
     523                ptr = malloc(size);
     524                if (ptr != NULL) {
     525                        memcpy(ptr, addr, NET_SIZE(orig_size));
     526                        free(addr);
    435527                }
    436528        }
     
    442534 *
    443535 * @param addr The address of the block.
     536 *
    444537 */
    445538void free(const void *addr)
    446539{
     540        futex_down(&malloc_futex);
     541       
    447542        /* Calculate the position of the header. */
    448543        heap_block_head_t *head
     
    483578       
    484579        shrink_heap();
     580       
     581        futex_up(&malloc_futex);
    485582}
    486583
  • uspace/lib/c/generic/str.c

    r38aaacc2 rf4f866c  
    471471 * null-terminated and containing only complete characters.
    472472 *
    473  * @param dest   Destination buffer.
     473 * @param dest  Destination buffer.
    474474 * @param count Size of the destination buffer (must be > 0).
    475475 * @param src   Source string.
     
    477477void str_cpy(char *dest, size_t size, const char *src)
    478478{
    479         wchar_t ch;
    480         size_t src_off;
    481         size_t dest_off;
    482 
    483479        /* There must be space for a null terminator in the buffer. */
    484480        assert(size > 0);
    485481       
    486         src_off = 0;
    487         dest_off = 0;
    488 
     482        size_t src_off = 0;
     483        size_t dest_off = 0;
     484       
     485        wchar_t ch;
    489486        while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
    490487                if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
    491488                        break;
    492489        }
    493 
     490       
    494491        dest[dest_off] = '\0';
    495492}
     
    505502 * have to be null-terminated.
    506503 *
    507  * @param dest   Destination buffer.
     504 * @param dest  Destination buffer.
    508505 * @param count Size of the destination buffer (must be > 0).
    509506 * @param src   Source string.
    510  * @param n     Maximum number of bytes to read from @a src.
     507 * @param n     Maximum number of bytes to read from @a src.
    511508 */
    512509void str_ncpy(char *dest, size_t size, const char *src, size_t n)
    513510{
    514         wchar_t ch;
    515         size_t src_off;
    516         size_t dest_off;
    517 
    518511        /* There must be space for a null terminator in the buffer. */
    519512        assert(size > 0);
    520513       
    521         src_off = 0;
    522         dest_off = 0;
    523 
     514        size_t src_off = 0;
     515        size_t dest_off = 0;
     516       
     517        wchar_t ch;
    524518        while ((ch = str_decode(src, &src_off, n)) != 0) {
    525519                if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
    526520                        break;
    527521        }
    528 
     522       
    529523        dest[dest_off] = '\0';
    530524}
     
    896890}
    897891
     892/** Duplicate string.
     893 *
     894 * Allocate a new string and copy characters from the source
     895 * string into it. The duplicate string is allocated via sleeping
     896 * malloc(), thus this function can sleep in no memory conditions.
     897 *
     898 * The allocation cannot fail and the return value is always
     899 * a valid pointer. The duplicate string is always a well-formed
     900 * null-terminated UTF-8 string, but it can differ from the source
     901 * string on the byte level.
     902 *
     903 * @param src Source string.
     904 *
     905 * @return Duplicate string.
     906 *
     907 */
    898908char *str_dup(const char *src)
    899909{
    900         size_t size = str_size(src);
    901         void *dest = malloc(size + 1);
    902        
     910        size_t size = str_size(src) + 1;
     911        char *dest = (char *) malloc(size);
    903912        if (dest == NULL)
    904913                return (char *) NULL;
    905914       
    906         return (char *) memcpy(dest, src, size + 1);
    907 }
    908 
    909 char *str_ndup(const char *src, size_t max_size)
     915        str_cpy(dest, size, src);
     916        return dest;
     917}
     918
     919/** Duplicate string with size limit.
     920 *
     921 * Allocate a new string and copy up to @max_size bytes from the source
     922 * string into it. The duplicate string is allocated via sleeping
     923 * malloc(), thus this function can sleep in no memory conditions.
     924 * No more than @max_size + 1 bytes is allocated, but if the size
     925 * occupied by the source string is smaller than @max_size + 1,
     926 * less is allocated.
     927 *
     928 * The allocation cannot fail and the return value is always
     929 * a valid pointer. The duplicate string is always a well-formed
     930 * null-terminated UTF-8 string, but it can differ from the source
     931 * string on the byte level.
     932 *
     933 * @param src Source string.
     934 * @param n   Maximum number of bytes to duplicate.
     935 *
     936 * @return Duplicate string.
     937 *
     938 */
     939char *str_ndup(const char *src, size_t n)
    910940{
    911941        size_t size = str_size(src);
    912         if (size > max_size)
    913                 size = max_size;
     942        if (size > n)
     943                size = n;
    914944       
    915945        char *dest = (char *) malloc(size + 1);
    916        
    917946        if (dest == NULL)
    918947                return (char *) NULL;
    919948       
    920         memcpy(dest, src, size);
    921         dest[size] = 0;
     949        str_ncpy(dest, size + 1, src, size);
    922950        return dest;
    923951}
     
    9791007}
    9801008
     1009void order_suffix(const uint64_t val, uint64_t *rv, char *suffix)
     1010{
     1011        if (val > 10000000000000000000ULL) {
     1012                *rv = val / 1000000000000000000ULL;
     1013                *suffix = 'Z';
     1014        } else if (val > 1000000000000000000ULL) {
     1015                *rv = val / 1000000000000000ULL;
     1016                *suffix = 'E';
     1017        } else if (val > 1000000000000000ULL) {
     1018                *rv = val / 1000000000000ULL;
     1019                *suffix = 'T';
     1020        } else if (val > 1000000000000ULL) {
     1021                *rv = val / 1000000000ULL;
     1022                *suffix = 'G';
     1023        } else if (val > 1000000000ULL) {
     1024                *rv = val / 1000000ULL;
     1025                *suffix = 'M';
     1026        } else if (val > 1000000ULL) {
     1027                *rv = val / 1000ULL;
     1028                *suffix = 'k';
     1029        } else {
     1030                *rv = val;
     1031                *suffix = ' ';
     1032        }
     1033}
     1034
    9811035/** @}
    9821036 */
  • uspace/lib/c/generic/sysinfo.c

    r38aaacc2 rf4f866c  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#include <libc.h>
    3636#include <sysinfo.h>
    3737#include <str.h>
     38#include <errno.h>
     39#include <malloc.h>
     40#include <bool.h>
    3841
    39 sysarg_t sysinfo_value(const char *name)
     42/** Get sysinfo item type
     43 *
     44 * @param path Sysinfo path.
     45 *
     46 * @return Sysinfo item type.
     47 *
     48 */
     49sysinfo_item_tag_t sysinfo_get_tag(const char *path)
    4050{
    41         return __SYSCALL2(SYS_SYSINFO_VALUE, (sysarg_t) name,
    42             (sysarg_t) str_size(name));
     51        return (sysinfo_item_tag_t) __SYSCALL2(SYS_SYSINFO_GET_TAG,
     52            (sysarg_t) path, (sysarg_t) str_size(path));
     53}
     54
     55/** Get sysinfo numerical value
     56 *
     57 * @param path  Sysinfo path.
     58 * @param value Pointer to store the numerical value to.
     59 *
     60 * @return EOK if the value was successfully read and
     61 *         is of SYSINFO_VAL_VAL type.
     62 *
     63 */
     64int sysinfo_get_value(const char *path, sysarg_t *value)
     65{
     66        return (int) __SYSCALL3(SYS_SYSINFO_GET_VALUE, (sysarg_t) path,
     67            (sysarg_t) str_size(path), (sysarg_t) value);
     68}
     69
     70/** Get sysinfo binary data size
     71 *
     72 * @param path  Sysinfo path.
     73 * @param value Pointer to store the binary data size.
     74 *
     75 * @return EOK if the value was successfully read and
     76 *         is of SYSINFO_VAL_DATA type.
     77 *
     78 */
     79static int sysinfo_get_data_size(const char *path, size_t *size)
     80{
     81        return (int) __SYSCALL3(SYS_SYSINFO_GET_DATA_SIZE, (sysarg_t) path,
     82            (sysarg_t) str_size(path), (sysarg_t) size);
     83}
     84
     85/** Get sysinfo binary data
     86 *
     87 * @param path  Sysinfo path.
     88 * @param value Pointer to store the binary data size.
     89 *
     90 * @return Binary data read from sysinfo or NULL if the
     91 *         sysinfo item value type is not binary data.
     92 *         The returned non-NULL pointer should be
     93 *         freed by free().
     94 *
     95 */
     96void *sysinfo_get_data(const char *path, size_t *size)
     97{
     98        /* The binary data size might change during time.
     99           Unfortunatelly we cannot allocate the buffer
     100           and transfer the data as a single atomic operation.
     101       
     102           Let's hope that the number of iterations is bounded
     103           in common cases. */
     104       
     105        void *data = NULL;
     106       
     107        while (true) {
     108                /* Get the binary data size */
     109                int ret = sysinfo_get_data_size(path, size);
     110                if ((ret != EOK) || (size == 0)) {
     111                        /* Not a binary data item
     112                           or an empty item */
     113                        break;
     114                }
     115               
     116                data = realloc(data, *size);
     117                if (data == NULL)
     118                        break;
     119               
     120                /* Get the data */
     121                ret = __SYSCALL4(SYS_SYSINFO_GET_DATA, (sysarg_t) path,
     122                    (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size);
     123                if (ret == EOK)
     124                        return data;
     125               
     126                if (ret != ENOMEM) {
     127                        /* The failure to get the data was not caused
     128                           by wrong buffer size */
     129                        break;
     130                }
     131        }
     132       
     133        if (data != NULL)
     134                free(data);
     135       
     136        *size = 0;
     137        return NULL;
    43138}
    44139
  • uspace/lib/c/generic/task.c

    r38aaacc2 rf4f866c  
    7070 * loader API.
    7171 *
    72  * @param path pathname of the binary to execute
    73  * @param argv command-line arguments
     72 * @param path Pathname of the binary to execute.
     73 * @param argv Command-line arguments.
     74 * @param err  If not NULL, the error value is stored here.
    7475 *
    7576 * @return ID of the newly created task or zero on error.
    7677 *
    7778 */
    78 task_id_t task_spawn(const char *path, const char *const args[])
     79task_id_t task_spawn(const char *path, const char *const args[], int *err)
    7980{
    8081        /* Connect to a program loader. */
    8182        loader_t *ldr = loader_connect();
    82         if (ldr == NULL)
     83        if (ldr == NULL) {
     84                if (err != NULL)
     85                        *err = EREFUSED;
     86               
    8387                return 0;
     88        }
    8489       
    8590        /* Get task ID. */
     
    143148        /* Success */
    144149        free(ldr);
     150       
     151        if (err != NULL)
     152                *err = EOK;
     153       
    145154        return task_id;
    146155       
     
    149158        loader_abort(ldr);
    150159        free(ldr);
     160       
     161        if (err != NULL)
     162                *err = rc;
    151163       
    152164        return 0;
  • uspace/lib/c/include/bool.h

    r38aaacc2 rf4f866c  
    3636#define LIBC_BOOL_H_
    3737
    38 #define false 0
    39 #define true 1
     38#include <libarch/types.h>
    4039
    41 typedef short bool;
     40#define false  0
     41#define true   1
     42
     43typedef uint8_t bool;
    4244
    4345#endif
  • uspace/lib/c/include/errno.h

    r38aaacc2 rf4f866c  
    4343#define errno _errno
    4444
    45 #define EMFILE        (-17)
     45#define EMFILE        (-18)
    4646#define ENAMETOOLONG  (-256)
    4747#define EISDIR        (-257)
  • uspace/lib/c/include/futex.h

    r38aaacc2 rf4f866c  
    3939#include <sys/types.h>
    4040
    41 #define FUTEX_INITIALIZER     {1}
     41#define FUTEX_INITIALIZER  {1}
    4242
    4343typedef atomic_t futex_t;
  • uspace/lib/c/include/io/color.h

    r38aaacc2 rf4f866c  
    3636#define LIBC_IO_COLOR_H_
    3737
    38 enum console_color {
     38typedef enum {
    3939        COLOR_BLACK   = 0,
    4040        COLOR_BLUE    = 1,
     
    4848        CATTR_BRIGHT  = 8,
    4949        CATTR_BLINK   = 8
    50 };
     50} console_color_t;
    5151
    5252#endif
  • uspace/lib/c/include/io/console.h

    r38aaacc2 rf4f866c  
    4444} console_ev_type_t;
    4545
    46 enum {
     46typedef enum {
    4747        CONSOLE_CCAP_NONE = 0,
    4848        CONSOLE_CCAP_STYLE,
    4949        CONSOLE_CCAP_INDEXED,
    5050        CONSOLE_CCAP_RGB
    51 };
     51} console_caps_t;
    5252
    5353/** Console event structure. */
     
    6868extern void console_clear(int phone);
    6969
    70 extern int console_get_size(int phone, int *cols, int *rows);
    71 extern int console_get_pos(int phone, int *col, int *row);
    72 extern void console_goto(int phone, int col, int row);
     70extern int console_get_size(int phone, ipcarg_t *cols, ipcarg_t *rows);
     71extern int console_get_pos(int phone, ipcarg_t *col, ipcarg_t *row);
     72extern void console_set_pos(int phone, ipcarg_t col, ipcarg_t row);
    7373
    74 extern void console_set_style(int phone, int style);
    75 extern void console_set_color(int phone, int fg_color, int bg_color, int flags);
    76 extern void console_set_rgb_color(int phone, int fg_color, int bg_color);
     74extern void console_set_style(int phone, uint8_t style);
     75extern void console_set_color(int phone, uint8_t fg_color, uint8_t bg_color,
     76    uint8_t flags);
     77extern void console_set_rgb_color(int phone, uint32_t fg_color, uint32_t bg_color);
    7778
    7879extern void console_cursor_visibility(int phone, bool show);
    79 extern int console_get_color_cap(int phone, int *ccap);
     80extern int console_get_color_cap(int phone, ipcarg_t *ccap);
    8081extern void console_kcon_enable(int phone);
    8182
  • uspace/lib/c/include/io/keycode.h

    r38aaacc2 rf4f866c  
    5151 * they really are organized here by position, rather than by label.
    5252 */
    53 enum keycode {
     53typedef enum {
    5454
    5555        /* Main block row 1 */
     
    199199} keycode_t;
    200200
    201 enum keymod {
     201typedef enum {
    202202        KM_LSHIFT      = 0x001,
    203203        KM_RSHIFT      = 0x002,
  • uspace/lib/c/include/io/klog.h

    r38aaacc2 rf4f866c  
    3333 */
    3434
    35 #ifndef LIBC_STREAM_H_
    36 #define LIBC_STREAM_H_
     35#ifndef LIBC_IO_KLOG_H_
     36#define LIBC_IO_KLOG_H_
    3737
    3838#include <sys/types.h>
    3939
    40 extern size_t klog_write(const void *buf, size_t size);
     40extern size_t klog_write(const void *, size_t);
    4141extern void klog_update(void);
    4242
  • uspace/lib/c/include/io/printf_core.h

    r38aaacc2 rf4f866c  
    4040
    4141/** Structure for specifying output methods for different printf clones. */
    42 typedef struct printf_spec {
     42typedef struct {
    4343        /* String output function, returns number of printed characters or EOF */
    4444        int (*str_write)(const char *, size_t, void *);
     
    5151} printf_spec_t;
    5252
    53 int printf_core(const char *fmt, printf_spec_t *ps, va_list ap);
     53extern int printf_core(const char *, printf_spec_t *, va_list);
    5454
    5555#endif
  • uspace/lib/c/include/io/screenbuffer.h

    r38aaacc2 rf4f866c  
    3333 */
    3434
    35 #ifndef SCREENBUFFER_H__
    36 #define SCREENBUFFER_H__
     35#ifndef LIBC_SCREENBUFFER_H__
     36#define LIBC_SCREENBUFFER_H__
    3737
    3838#include <stdint.h>
    3939#include <sys/types.h>
     40#include <ipc/ipc.h>
    4041#include <bool.h>
    4142
    42 #define DEFAULT_FOREGROUND  0x0       /**< default console foreground color */
    43 #define DEFAULT_BACKGROUND  0xf0f0f0  /**< default console background color */
     43typedef enum {
     44        at_style,
     45        at_idx,
     46        at_rgb
     47} attr_type_t;
    4448
    4549typedef struct {
     
    5862} attr_rgb_t;
    5963
     64typedef union {
     65        attr_style_t s;
     66        attr_idx_t i;
     67        attr_rgb_t r;
     68} attr_val_t;
     69
    6070typedef struct {
    61         enum {
    62                 at_style,
    63                 at_idx,
    64                 at_rgb
    65         } t;
    66         union {
    67                 attr_style_t s;
    68                 attr_idx_t i;
    69                 attr_rgb_t r;
    70         } a;
     71        attr_type_t t;
     72        attr_val_t a;
    7173} attrs_t;
    7274
     
    8284        keyfield_t *buffer;      /**< Screen content - characters and
    8385                                      their attributes (used as a circular buffer) */
    84         size_t size_x;           /**< Number of columns  */
    85         size_t size_y;           /**< Number of rows */
     86        ipcarg_t size_x;         /**< Number of columns  */
     87        ipcarg_t size_y;         /**< Number of rows */
    8688       
    8789        /** Coordinates of last printed character for determining cursor position */
    88         size_t position_x;
    89         size_t position_y;
     90        ipcarg_t position_x;
     91        ipcarg_t position_y;
    9092       
    9193        attrs_t attrs;           /**< Current attributes. */
     
    107109 *
    108110 */
    109 static inline keyfield_t *get_field_at(screenbuffer_t *scr, size_t x, size_t y)
     111static inline keyfield_t *get_field_at(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y)
    110112{
    111113        return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x;
     
    120122 *
    121123 */
    122 static inline int attrs_same(attrs_t a1, attrs_t a2)
     124static inline bool attrs_same(attrs_t a1, attrs_t a2)
    123125{
    124126        if (a1.t != a2.t)
    125                 return 0;
     127                return false;
    126128       
    127129        switch (a1.t) {
     
    137139        }
    138140       
    139         return 0;
     141        return false;
    140142}
    141143
     144extern void screenbuffer_putchar(screenbuffer_t *, wchar_t);
     145extern screenbuffer_t *screenbuffer_init(screenbuffer_t *, ipcarg_t, ipcarg_t);
    142146
    143 void screenbuffer_putchar(screenbuffer_t *scr, wchar_t c);
    144 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y);
    145 
    146 void screenbuffer_clear(screenbuffer_t *scr);
    147 void screenbuffer_clear_line(screenbuffer_t *scr, size_t line);
    148 void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest);
    149 void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y);
    150 void screenbuffer_set_style(screenbuffer_t *scr, uint8_t style);
    151 void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color,
    152     uint8_t bg_color, uint8_t attr);
    153 void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color,
    154     uint32_t bg_color);
     147extern void screenbuffer_clear(screenbuffer_t *);
     148extern void screenbuffer_clear_line(screenbuffer_t *, ipcarg_t);
     149extern void screenbuffer_copy_buffer(screenbuffer_t *, keyfield_t *);
     150extern void screenbuffer_goto(screenbuffer_t *, ipcarg_t, ipcarg_t);
     151extern void screenbuffer_set_style(screenbuffer_t *, uint8_t);
     152extern void screenbuffer_set_color(screenbuffer_t *, uint8_t, uint8_t, uint8_t);
     153extern void screenbuffer_set_rgb_color(screenbuffer_t *, uint32_t, uint32_t);
    155154
    156155#endif
  • uspace/lib/c/include/io/style.h

    r38aaacc2 rf4f866c  
    3636#define LIBC_IO_STYLE_H_
    3737
    38 enum console_style {
     38typedef enum {
    3939        STYLE_NORMAL   = 0,
    40         STYLE_EMPHASIS = 1
    41 };
     40        STYLE_EMPHASIS = 1,
     41        STYLE_INVERTED = 2,
     42        STYLE_SELECTED = 3
     43} console_style_t;
    4244
    4345#endif
  • uspace/lib/c/include/str.h

    r38aaacc2 rf4f866c  
    8686extern char *str_ndup(const char *, size_t max_size);
    8787
     88extern void order_suffix(const uint64_t val, uint64_t *rv, char *suffix);
     89
    8890/*
    8991 * TODO: Get rid of this.
  • uspace/lib/c/include/sysinfo.h

    r38aaacc2 rf4f866c  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#ifndef LIBC_SYSINFO_H_
     
    3737
    3838#include <libc.h>
    39 #include <sysinfo.h>
    40 #include <str.h>
    4139
    42 sysarg_t sysinfo_value(const char *name);
     40/** Sysinfo value types
     41 *
     42 */
     43typedef enum {
     44        SYSINFO_VAL_UNDEFINED = 0,
     45        SYSINFO_VAL_VAL = 1,
     46        SYSINFO_VAL_DATA = 2
     47} sysinfo_item_tag_t;
     48
     49extern sysinfo_item_tag_t sysinfo_get_tag(const char *);
     50extern int sysinfo_get_value(const char *, sysarg_t *);
     51extern void *sysinfo_get_data(const char *, size_t *);
    4352
    4453#endif
  • uspace/lib/c/include/task.h

    r38aaacc2 rf4f866c  
    4646
    4747extern task_id_t task_get_id(void);
    48 extern int task_set_name(const char *name);
    49 extern task_id_t task_spawn(const char *path, const char *const argv[]);
    50 extern int task_wait(task_id_t id, task_exit_t *texit, int *retval);
    51 extern int task_retval(int val);
    52 
     48extern int task_set_name(const char *);
     49extern task_id_t task_spawn(const char *, const char *const[], int *);
     50extern int task_wait(task_id_t id, task_exit_t *, int *);
     51extern int task_retval(int);
    5352
    5453#endif
  • uspace/lib/clui/Makefile

    r38aaacc2 rf4f866c  
    2828
    2929USPACE_PREFIX = ../..
     30EXTRA_CFLAGS = -I.
    3031LIBRARY = libclui
    3132
  • uspace/lib/clui/tinput.c

    r38aaacc2 rf4f866c  
    4040#include <assert.h>
    4141#include <bool.h>
    42 
    43 #include "tinput.h"
     42#include <tinput.h>
    4443
    4544/** Seek direction */
     
    4948} seek_dir_t;
    5049
    51 static void tinput_init(tinput_t *ti);
    52 static void tinput_insert_string(tinput_t *ti, const char *str);
    53 static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb);
    54 static bool tinput_sel_active(tinput_t *ti);
    55 static void tinput_sel_all(tinput_t *ti);
    56 static void tinput_sel_delete(tinput_t *ti);
    57 static void tinput_key_ctrl(tinput_t *ti, console_event_t *ev);
    58 static void tinput_key_shift(tinput_t *ti, console_event_t *ev);
    59 static void tinput_key_ctrl_shift(tinput_t *ti, console_event_t *ev);
    60 static void tinput_key_unmod(tinput_t *ti, console_event_t *ev);
    61 static void tinput_pre_seek(tinput_t *ti, bool shift_held);
    62 static void tinput_post_seek(tinput_t *ti, bool shift_held);
     50static void tinput_init(tinput_t *);
     51static void tinput_insert_string(tinput_t *, const char *);
     52static void tinput_sel_get_bounds(tinput_t *, size_t *, size_t *);
     53static bool tinput_sel_active(tinput_t *);
     54static void tinput_sel_all(tinput_t *);
     55static void tinput_sel_delete(tinput_t *);
     56static void tinput_key_ctrl(tinput_t *, console_event_t *);
     57static void tinput_key_shift(tinput_t *, console_event_t *);
     58static void tinput_key_ctrl_shift(tinput_t *, console_event_t *);
     59static void tinput_key_unmod(tinput_t *, console_event_t *);
     60static void tinput_pre_seek(tinput_t *, bool);
     61static void tinput_post_seek(tinput_t *, bool);
    6362
    6463/** Create a new text input field. */
     
    6665{
    6766        tinput_t *ti;
    68 
     67       
    6968        ti = malloc(sizeof(tinput_t));
    7069        if (ti == NULL)
    7170                return NULL;
    72 
     71       
    7372        tinput_init(ti);
    7473        return ti;
     
    8180}
    8281
    83 static void tinput_display_tail(tinput_t *ti, int start, int pad)
    84 {
    85         static wchar_t dbuf[INPUT_MAX_SIZE + 1];
    86         int sa, sb;
    87         int i, p;
    88 
     82static void tinput_display_tail(tinput_t *ti, size_t start, size_t pad)
     83{
     84        wchar_t dbuf[INPUT_MAX_SIZE + 1];
     85       
     86        size_t sa;
     87        size_t sb;
    8988        tinput_sel_get_bounds(ti, &sa, &sb);
    90 
    91         console_goto(fphone(stdout), (ti->col0 + start) % ti->con_cols,
     89       
     90        console_set_pos(fphone(stdout), (ti->col0 + start) % ti->con_cols,
    9291            ti->row0 + (ti->col0 + start) / ti->con_cols);
    93         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
    94 
    95         p = start;
     92        console_set_style(fphone(stdout), STYLE_NORMAL);
     93       
     94        size_t p = start;
    9695        if (p < sa) {
    9796                memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(wchar_t));
     
    10099                p = sa;
    101100        }
    102 
     101       
    103102        if (p < sb) {
    104103                fflush(stdout);
    105                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_RED, 0);
     104                console_set_style(fphone(stdout), STYLE_SELECTED);
    106105                memcpy(dbuf, ti->buffer + p,
    107106                    (sb - p) * sizeof(wchar_t));
     
    110109                p = sb;
    111110        }
    112 
     111       
    113112        fflush(stdout);
    114         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
    115 
     113        console_set_style(fphone(stdout), STYLE_NORMAL);
     114       
    116115        if (p < ti->nc) {
    117116                memcpy(dbuf, ti->buffer + p,
     
    120119                printf("%ls", dbuf);
    121120        }
    122 
    123         for (i = 0; i < pad; ++i)
     121       
     122        for (p = 0; p < pad; p++)
    124123                putchar(' ');
     124       
    125125        fflush(stdout);
    126126}
     
    133133static void tinput_position_caret(tinput_t *ti)
    134134{
    135         console_goto(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,
     135        console_set_pos(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,
    136136            ti->row0 + (ti->col0 + ti->pos) / ti->con_cols);
    137137}
     
    140140static void tinput_update_origin(tinput_t *ti)
    141141{
    142         int width, rows;
    143 
    144         width = ti->col0 + ti->nc;
    145         rows = (width / ti->con_cols) + 1;
    146 
     142        ipcarg_t width = ti->col0 + ti->nc;
     143        ipcarg_t rows = (width / ti->con_cols) + 1;
     144       
    147145        /* Update row0 if the screen scrolled. */
    148146        if (ti->row0 + rows > ti->con_rows)
    149                 ti->row0 = ti->con_rows - rows; 
     147                ti->row0 = ti->con_rows - rows;
    150148}
    151149
    152150static void tinput_insert_char(tinput_t *ti, wchar_t c)
    153151{
    154         int i;
    155         int new_width, new_height;
    156 
    157152        if (ti->nc == INPUT_MAX_SIZE)
    158153                return;
    159 
    160         new_width = ti->col0 + ti->nc + 1;
     154       
     155        ipcarg_t new_width = ti->col0 + ti->nc + 1;
    161156        if (new_width % ti->con_cols == 0) {
    162157                /* Advancing to new line. */
    163                 new_height = (new_width / ti->con_cols) + 1;
    164                 if (new_height >= ti->con_rows)
    165                         return; /* Disallow text longer than 1 page for now. */
    166         }
    167 
    168         for (i = ti->nc; i > ti->pos; --i)
     158                ipcarg_t new_height = (new_width / ti->con_cols) + 1;
     159                if (new_height >= ti->con_rows) {
     160                        /* Disallow text longer than 1 page for now. */
     161                        return;
     162                }
     163        }
     164       
     165        size_t i;
     166        for (i = ti->nc; i > ti->pos; i--)
    169167                ti->buffer[i] = ti->buffer[i - 1];
    170 
     168       
    171169        ti->buffer[ti->pos] = c;
    172170        ti->pos += 1;
     
    174172        ti->buffer[ti->nc] = '\0';
    175173        ti->sel_start = ti->pos;
    176 
     174       
    177175        tinput_display_tail(ti, ti->pos - 1, 0);
    178176        tinput_update_origin(ti);
     
    182180static void tinput_insert_string(tinput_t *ti, const char *str)
    183181{
    184         int i;
    185         int new_width, new_height;
    186         int ilen;
    187         wchar_t c;
    188         size_t off;
    189 
    190         ilen = min((ssize_t) str_length(str), INPUT_MAX_SIZE - ti->nc);
     182        size_t ilen = min(str_length(str), INPUT_MAX_SIZE - ti->nc);
    191183        if (ilen == 0)
    192184                return;
    193 
    194         new_width = ti->col0 + ti->nc + ilen;
    195         new_height = (new_width / ti->con_cols) + 1;
    196         if (new_height >= ti->con_rows)
    197                 return; /* Disallow text longer than 1 page for now. */
    198 
    199         for (i = ti->nc - 1; i >= ti->pos; --i)
    200                 ti->buffer[i + ilen] = ti->buffer[i];
    201 
    202         off = 0; i = 0;
     185       
     186        ipcarg_t new_width = ti->col0 + ti->nc + ilen;
     187        ipcarg_t new_height = (new_width / ti->con_cols) + 1;
     188        if (new_height >= ti->con_rows) {
     189                /* Disallow text longer than 1 page for now. */
     190                return;
     191        }
     192       
     193        if (ti->nc > 0) {
     194                size_t i;
     195                for (i = ti->nc; i > ti->pos; i--)
     196                        ti->buffer[i + ilen - 1] = ti->buffer[i - 1];
     197        }
     198       
     199        size_t off = 0;
     200        size_t i = 0;
    203201        while (i < ilen) {
    204                 c = str_decode(str, &off, STR_NO_LIMIT);
     202                wchar_t c = str_decode(str, &off, STR_NO_LIMIT);
    205203                if (c == '\0')
    206204                        break;
    207 
     205               
    208206                /* Filter out non-printable chars. */
    209207                if (c < 32)
    210208                        c = 32;
    211 
     209               
    212210                ti->buffer[ti->pos + i] = c;
    213                 ++i;
    214         }
    215 
     211                i++;
     212        }
     213       
    216214        ti->pos += ilen;
    217215        ti->nc += ilen;
    218216        ti->buffer[ti->nc] = '\0';
    219217        ti->sel_start = ti->pos;
    220 
     218       
    221219        tinput_display_tail(ti, ti->pos - ilen, 0);
    222220        tinput_update_origin(ti);
     
    226224static void tinput_backspace(tinput_t *ti)
    227225{
    228         int i;
    229 
    230226        if (tinput_sel_active(ti)) {
    231227                tinput_sel_delete(ti);
    232228                return;
    233229        }
    234 
     230       
    235231        if (ti->pos == 0)
    236232                return;
    237 
    238         for (i = ti->pos; i < ti->nc; ++i)
     233       
     234        size_t i;
     235        for (i = ti->pos; i < ti->nc; i++)
    239236                ti->buffer[i - 1] = ti->buffer[i];
     237       
    240238        ti->pos -= 1;
    241239        ti->nc -= 1;
    242240        ti->buffer[ti->nc] = '\0';
    243241        ti->sel_start = ti->pos;
    244 
     242       
    245243        tinput_display_tail(ti, ti->pos, 1);
    246244        tinput_position_caret(ti);
     
    253251                return;
    254252        }
    255 
     253       
    256254        if (ti->pos == ti->nc)
    257255                return;
    258 
     256       
    259257        ti->pos += 1;
    260258        ti->sel_start = ti->pos;
    261 
     259       
    262260        tinput_backspace(ti);
    263261}
     
    266264{
    267265        tinput_pre_seek(ti, shift_held);
    268 
     266       
    269267        if (dir == seek_forward) {
    270268                if (ti->pos < ti->nc)
     
    274272                        ti->pos -= 1;
    275273        }
    276 
     274       
    277275        tinput_post_seek(ti, shift_held);
    278276}
     
    281279{
    282280        tinput_pre_seek(ti, shift_held);
    283 
     281       
    284282        if (dir == seek_forward) {
    285283                if (ti->pos == ti->nc)
    286284                        return;
    287 
    288                 while (1) {
     285               
     286                while (true) {
    289287                        ti->pos += 1;
    290 
     288                       
    291289                        if (ti->pos == ti->nc)
    292290                                break;
    293 
    294                         if (ti->buffer[ti->pos - 1] == ' ' &&
    295                             ti->buffer[ti->pos] != ' ')
     291                       
     292                        if ((ti->buffer[ti->pos - 1] == ' ') &&
     293                            (ti->buffer[ti->pos] != ' '))
    296294                                break;
    297295                }
     
    299297                if (ti->pos == 0)
    300298                        return;
    301 
    302                 while (1) {
     299               
     300                while (true) {
    303301                        ti->pos -= 1;
    304 
     302                       
    305303                        if (ti->pos == 0)
    306304                                break;
    307 
     305                       
    308306                        if (ti->buffer[ti->pos - 1] == ' ' &&
    309307                            ti->buffer[ti->pos] != ' ')
    310308                                break;
    311309                }
    312 
    313         }
    314 
     310       
     311        }
     312       
    315313        tinput_post_seek(ti, shift_held);
    316314}
     
    319317{
    320318        tinput_pre_seek(ti, shift_held);
    321 
     319       
    322320        if (dir == seek_forward) {
    323321                if (ti->pos + ti->con_cols <= ti->nc)
    324322                        ti->pos = ti->pos + ti->con_cols;
    325323        } else {
    326                 if (ti->pos - ti->con_cols >= 0)
     324                if (ti->pos >= ti->con_cols)
    327325                        ti->pos = ti->pos - ti->con_cols;
    328326        }
    329 
     327       
    330328        tinput_post_seek(ti, shift_held);
    331329}
     
    334332{
    335333        tinput_pre_seek(ti, shift_held);
    336 
     334       
    337335        if (dir == seek_backward)
    338336                ti->pos = 0;
    339337        else
    340338                ti->pos = ti->nc;
    341 
     339       
    342340        tinput_post_seek(ti, shift_held);
    343341}
     
    345343static void tinput_pre_seek(tinput_t *ti, bool shift_held)
    346344{
    347         if (tinput_sel_active(ti) && !shift_held) {
     345        if ((tinput_sel_active(ti)) && (!shift_held)) {
    348346                /* Unselect and redraw. */
    349347                ti->sel_start = ti->pos;
     
    362360                ti->sel_start = ti->pos;
    363361        }
     362       
    364363        tinput_position_caret(ti);
    365364}
     
    367366static void tinput_history_insert(tinput_t *ti, char *str)
    368367{
    369         int i;
    370 
    371368        if (ti->hnum < HISTORY_LEN) {
    372369                ti->hnum += 1;
     
    375372                        free(ti->history[HISTORY_LEN]);
    376373        }
    377 
    378         for (i = ti->hnum; i > 1; --i)
     374       
     375        size_t i;
     376        for (i = ti->hnum; i > 1; i--)
    379377                ti->history[i] = ti->history[i - 1];
    380 
     378       
    381379        ti->history[1] = str_dup(str);
    382 
     380       
    383381        if (ti->history[0] != NULL) {
    384382                free(ti->history[0]);
     
    395393}
    396394
    397 static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb)
     395static void tinput_sel_get_bounds(tinput_t *ti, size_t *sa, size_t *sb)
    398396{
    399397        if (ti->sel_start < ti->pos) {
     
    408406static bool tinput_sel_active(tinput_t *ti)
    409407{
    410         return ti->sel_start != ti->pos;
     408        return (ti->sel_start != ti->pos);
    411409}
    412410
     
    421419static void tinput_sel_delete(tinput_t *ti)
    422420{
    423         int sa, sb;
    424 
     421        size_t sa;
     422        size_t sb;
     423       
    425424        tinput_sel_get_bounds(ti, &sa, &sb);
    426425        if (sa == sb)
    427426                return;
    428 
     427       
    429428        memmove(ti->buffer + sa, ti->buffer + sb,
    430429            (ti->nc - sb) * sizeof(wchar_t));
     430       
    431431        ti->pos = ti->sel_start = sa;
    432432        ti->nc -= (sb - sa);
    433433        ti->buffer[ti->nc] = '\0';
    434 
     434       
    435435        tinput_display_tail(ti, sa, sb - sa);
    436436        tinput_position_caret(ti);
     
    439439static void tinput_sel_copy_to_cb(tinput_t *ti)
    440440{
    441         int sa, sb;
     441        size_t sa;
     442        size_t sb;
     443       
     444        tinput_sel_get_bounds(ti, &sa, &sb);
     445       
    442446        char *str;
    443 
    444         tinput_sel_get_bounds(ti, &sa, &sb);
    445 
     447       
    446448        if (sb < ti->nc) {
    447449                wchar_t tmp_c = ti->buffer[sb];
     
    454456        if (str == NULL)
    455457                goto error;
    456 
     458       
    457459        if (clipboard_put_str(str) != EOK)
    458460                goto error;
    459 
     461       
    460462        free(str);
    461463        return;
     464       
    462465error:
     466        /* TODO: Give the user some kind of warning. */
    463467        return;
    464         /* TODO: Give the user some warning. */
    465468}
    466469
     
    468471{
    469472        char *str;
    470         int rc;
    471 
    472         rc = clipboard_get_str(&str);
    473         if (rc != EOK || str == NULL)
    474                 return; /* TODO: Give the user some warning. */
    475 
     473        int rc = clipboard_get_str(&str);
     474       
     475        if ((rc != EOK) || (str == NULL)) {
     476                /* TODO: Give the user some kind of warning. */
     477                return;
     478        }
     479       
    476480        tinput_insert_string(ti, str);
    477481        free(str);
     
    480484static void tinput_history_seek(tinput_t *ti, int offs)
    481485{
    482         int pad;
    483 
    484         if (ti->hpos + offs < 0 || ti->hpos + offs > ti->hnum)
    485                 return;
    486 
     486        if (offs >= 0) {
     487                if (ti->hpos + offs > ti->hnum)
     488                        return;
     489        } else {
     490                if (ti->hpos < (size_t) -offs)
     491                        return;
     492        }
     493       
    487494        if (ti->history[ti->hpos] != NULL) {
    488495                free(ti->history[ti->hpos]);
    489496                ti->history[ti->hpos] = NULL;
    490497        }
    491 
     498       
    492499        ti->history[ti->hpos] = tinput_get_str(ti);
    493500        ti->hpos += offs;
    494 
    495         pad = ti->nc - str_length(ti->history[ti->hpos]);
    496         if (pad < 0) pad = 0;
    497 
     501       
     502        int pad = (int) ti->nc - str_length(ti->history[ti->hpos]);
     503        if (pad < 0)
     504                pad = 0;
     505       
    498506        tinput_set_str(ti, ti->history[ti->hpos]);
    499507        tinput_display_tail(ti, 0, pad);
     
    515523/** Read in one line of input.
    516524 *
    517  * @param ti    Text input.
    518  * @param dstr  Place to save pointer to new string.
    519  * @return      EOK on success, ENOENT if user requested abort, EIO
    520  *              if communication with console failed.
     525 * @param ti   Text input.
     526 * @param dstr Place to save pointer to new string.
     527 *
     528 * @return EOK on success
     529 * @return ENOENT if user requested abort
     530 * @return EIO if communication with console failed
     531 *
    521532 */
    522533int tinput_read(tinput_t *ti, char **dstr)
    523534{
    524         console_event_t ev;
    525         char *str;
    526 
    527535        fflush(stdout);
    528 
    529536        if (console_get_size(fphone(stdin), &ti->con_cols, &ti->con_rows) != EOK)
    530537                return EIO;
     538       
    531539        if (console_get_pos(fphone(stdin), &ti->col0, &ti->row0) != EOK)
    532540                return EIO;
    533 
    534         ti->pos = ti->sel_start = 0;
     541       
     542        ti->pos = 0;
     543        ti->sel_start = 0;
    535544        ti->nc = 0;
    536545        ti->buffer[0] = '\0';
    537546        ti->done = false;
    538547        ti->exit_clui = false;
    539 
     548       
    540549        while (!ti->done) {
    541550                fflush(stdout);
     551               
     552                console_event_t ev;
    542553                if (!console_get_event(fphone(stdin), &ev))
    543554                        return EIO;
    544 
     555               
    545556                if (ev.type != KEY_PRESS)
    546557                        continue;
    547 
    548                 if ((ev.mods & KM_CTRL) != 0 &&
    549                     (ev.mods & (KM_ALT | KM_SHIFT)) == 0) {
     558               
     559                if (((ev.mods & KM_CTRL) != 0) &&
     560                    ((ev.mods & (KM_ALT | KM_SHIFT)) == 0))
    550561                        tinput_key_ctrl(ti, &ev);
    551                 }
    552 
    553                 if ((ev.mods & KM_SHIFT) != 0 &&
    554                     (ev.mods & (KM_CTRL | KM_ALT)) == 0) {
     562               
     563                if (((ev.mods & KM_SHIFT) != 0) &&
     564                    ((ev.mods & (KM_CTRL | KM_ALT)) == 0))
    555565                        tinput_key_shift(ti, &ev);
    556                 }
    557 
    558                 if ((ev.mods & KM_CTRL) != 0 &&
    559                     (ev.mods & KM_SHIFT) != 0 &&
    560                     (ev.mods & KM_ALT) == 0) {
     566               
     567                if (((ev.mods & KM_CTRL) != 0) &&
     568                    ((ev.mods & KM_SHIFT) != 0) &&
     569                    ((ev.mods & KM_ALT) == 0))
    561570                        tinput_key_ctrl_shift(ti, &ev);
    562                 }
    563 
    564                 if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
     571               
     572                if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0)
    565573                        tinput_key_unmod(ti, &ev);
    566                 }
    567 
     574               
    568575                if (ev.c >= ' ') {
    569576                        tinput_sel_delete(ti);
     
    571578                }
    572579        }
    573 
     580       
    574581        if (ti->exit_clui)
    575582                return ENOENT;
    576 
     583       
    577584        ti->pos = ti->nc;
    578585        tinput_position_caret(ti);
    579586        putchar('\n');
    580 
    581         str = tinput_get_str(ti);
     587       
     588        char *str = tinput_get_str(ti);
    582589        if (str_cmp(str, "") != 0)
    583590                tinput_history_insert(ti, str);
    584 
     591       
    585592        ti->hpos = 0;
    586 
     593       
    587594        *dstr = str;
    588595        return EOK;
     
    700707                break;
    701708        case KC_UP:
    702                 tinput_history_seek(ti, +1);
     709                tinput_history_seek(ti, 1);
    703710                break;
    704711        case KC_DOWN:
  • uspace/lib/clui/tinput.h

    r38aaacc2 rf4f866c  
    2929/** @addtogroup libclui
    3030 * @{
    31  */ 
     31 */
    3232/**
    3333 * @file
     
    3737#define LIBCLUI_TINPUT_H_
    3838
    39 #define HISTORY_LEN 10
    40 #define INPUT_MAX_SIZE 1024
     39#include <ipc/ipc.h>
     40
     41#define HISTORY_LEN     10
     42#define INPUT_MAX_SIZE  1024
    4143
    4244/** Text input field (command line).
     
    4749        /** Buffer holding text currently being edited */
    4850        wchar_t buffer[INPUT_MAX_SIZE + 1];
     51       
    4952        /** Screen coordinates of the top-left corner of the text field */
    50         int col0, row0;
     53        ipcarg_t col0;
     54        ipcarg_t row0;
     55       
    5156        /** Screen dimensions */
    52         int con_cols, con_rows;
     57        ipcarg_t con_cols;
     58        ipcarg_t con_rows;
     59       
    5360        /** Number of characters in @c buffer */
    54         int nc;
     61        size_t nc;
     62       
    5563        /** Caret position within buffer */
    56         int pos;
     64        size_t pos;
     65       
    5766        /** Selection mark position within buffer */
    58         int sel_start;
    59 
     67        size_t sel_start;
     68       
    6069        /** History (dynamically allocated strings) */
    61         char *history[1 + HISTORY_LEN];
     70        char *history[HISTORY_LEN + 1];
     71       
    6272        /** Number of entries in @c history, not counting [0] */
    63         int hnum;
     73        size_t hnum;
     74       
    6475        /** Current position in history */
    65         int hpos;
     76        size_t hpos;
     77       
    6678        /** @c true if finished with this line (return to caller) */
    6779        bool done;
     80       
    6881        /** @c true if user requested to abort interactive loop */
    6982        bool exit_clui;
     
    7184
    7285extern tinput_t *tinput_new(void);
    73 extern void tinput_destroy(tinput_t *ti);
    74 extern int tinput_read(tinput_t *ti, char **str);
     86extern void tinput_destroy(tinput_t *);
     87extern int tinput_read(tinput_t *, char **);
    7588
    7689#endif
     
    7891/** @}
    7992 */
    80 
  • uspace/lib/net/Makefile

    r38aaacc2 rf4f866c  
    3737        generic/packet_remote.c \
    3838        adt/module_map.c \
    39         netif/netif.c \
    40         netif/netif_standalone.c \
     39        netif/netif_local.c \
     40        netif/netif_remote.c \
    4141        netif/netif_nil_bundle.c \
    4242        nil/nil_remote.c \
  • uspace/lib/net/adt/module_map.c

    r38aaacc2 rf4f866c  
    9494}
    9595
    96 task_id_t spawn(const char * fname){
    97         const char * argv[2];
     96task_id_t spawn(const char *fname)
     97{
     98        const char *argv[2];
    9899        task_id_t res;
    99 
     100       
    100101        argv[0] = fname;
    101102        argv[1] = NULL;
    102         res = task_spawn(fname, argv);
    103 
     103        res = task_spawn(fname, argv, NULL);
     104       
    104105        return res;
    105106}
  • uspace/lib/net/generic/net_remote.c

    r38aaacc2 rf4f866c  
    3232
    3333/** @file
    34  *  Networking interface implementation for standalone remote modules.
     34 *  Networking interface implementation for remote modules.
    3535 *  @see net_interface.h
    3636 */
  • uspace/lib/net/generic/packet_remote.c

    r38aaacc2 rf4f866c  
    3232
    3333/** @file
    34  *  Packet client interface implementation for standalone remote modules.
     34 *  Packet client interface implementation for remote modules.
    3535 *  @see packet_client.h
    3636 */
     
    4747#include <packet/packet_header.h>
    4848#include <packet/packet_messages.h>
     49#include <packet_remote.h>
    4950
    50 /** Obtains the packet from the packet server as the shared memory block.
    51  *  Creates the local packet mapping as well.
    52  *  @param[in] phone The packet server module phone.
    53  *  @param[out] packet The packet reference pointer to store the received packet reference.
    54  *  @param[in] packet_id The packet identifier.
    55  *  @param[in] size The packet total size in bytes.
    56  *  @returns EOK on success.
    57  *  @returns Other error codes as defined for the pm_add() function.
    58  *  @returns Other error codes as defined for the async_share_in_start() function.
     51/** Obtain the packet from the packet server as the shared memory block.
     52 *
     53 * Create the local packet mapping as well.
     54 *
     55 * @param[in]  phone     The packet server module phone.
     56 * @param[out] packet    The packet reference pointer to store the received
     57 *                       packet reference.
     58 * @param[in]  packet_id The packet identifier.
     59 * @param[in]  size      The packet total size in bytes.
     60 *
     61 * @return EOK on success.
     62 * @return Other error codes as defined for the pm_add() function.
     63 * @return Other error codes as defined for the async_share_in_start() function.
     64 *
    5965 */
    60 int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size);
    61 
    62 int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){
     66static int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){
    6367        ERROR_DECLARE;
    64 
    65         ipcarg_t size;
    66         packet_t next;
    67 
    68         if(! packet){
    69                 return EINVAL;
    70         }
    71         *packet = pm_find(packet_id);
    72         if(!(*packet)){
    73                 ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id, &size));
    74                 ERROR_PROPAGATE(packet_return(phone, packet, packet_id, size));
    75         }
    76         if((** packet).next){
    77                 return packet_translate(phone, &next, (** packet).next);
    78         }else return EOK;
    79 }
    80 
    81 int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){
    82         ERROR_DECLARE;
    83 
    84         aid_t message;
     68       
    8569        ipc_call_t answer;
    86         ipcarg_t result;
    87 
    88         message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
     70        aid_t message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
    8971        *packet = (packet_t) as_get_mappable_page(size);
    90         if(ERROR_OCCURRED(async_share_in_start_0_0(phone, * packet, size))
    91                 || ERROR_OCCURRED(pm_add(*packet))){
     72        if (ERROR_OCCURRED(async_share_in_start_0_0(phone, *packet, size))
     73            || ERROR_OCCURRED(pm_add(*packet))) {
    9274                munmap(*packet, size);
    9375                async_wait_for(message, NULL);
    9476                return ERROR_CODE;
    9577        }
     78       
     79        ipcarg_t result;
    9680        async_wait_for(message, &result);
     81       
    9782        return result;
    9883}
    9984
    100 packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix){
     85int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id)
     86{
    10187        ERROR_DECLARE;
     88       
     89        if (!packet)
     90                return EINVAL;
     91       
     92        *packet = pm_find(packet_id);
     93        if (!(*packet)) {
     94                ipcarg_t size;
     95               
     96                ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id, &size));
     97                ERROR_PROPAGATE(packet_return(phone, packet, packet_id, size));
     98        }
     99        if ((** packet).next) {
     100                packet_t next;
     101               
     102                return packet_translate_remote(phone, &next, (** packet).next);
     103        }
     104       
     105        return EOK;
     106}
    102107
     108packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
     109    size_t max_prefix, size_t max_suffix)
     110{
     111        ERROR_DECLARE;
     112       
    103113        ipcarg_t packet_id;
    104114        ipcarg_t size;
    105         packet_t packet;
    106 
    107         if(ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, &packet_id, &size))){
     115       
     116        if (ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4, max_content,
     117            addr_len, max_prefix, max_suffix, &packet_id, &size)))
    108118                return NULL;
     119       
     120       
     121        packet_t packet = pm_find(packet_id);
     122        if (!packet) {
     123                if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size)))
     124                        return NULL;
    109125        }
    110         packet = pm_find(packet_id);
    111         if(! packet){
    112                 if(ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size))){
    113                         return NULL;
    114                 }
    115         }
     126       
    116127        return packet;
    117128}
    118129
    119 packet_t packet_get_1(int phone, size_t content){
     130packet_t packet_get_1_remote(int phone, size_t content)
     131{
    120132        ERROR_DECLARE;
    121 
     133       
    122134        ipcarg_t packet_id;
    123135        ipcarg_t size;
    124         packet_t packet;
    125 
    126         if(ERROR_OCCURRED(async_req_1_2(phone, NET_PACKET_CREATE_1, content, &packet_id, &size))){
     136       
     137        if (ERROR_OCCURRED(async_req_1_2(phone, NET_PACKET_CREATE_1, content,
     138            &packet_id, &size)))
    127139                return NULL;
     140       
     141        packet_t packet = pm_find(packet_id);
     142        if (!packet) {
     143                if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size)))
     144                        return NULL;
    128145        }
    129         packet = pm_find(packet_id);
    130         if(! packet){
    131                 if(ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size))){
    132                         return NULL;
    133                 }
    134         }
     146       
    135147        return packet;
    136148}
    137149
    138 void pq_release(int phone, packet_id_t packet_id){
     150void pq_release_remote(int phone, packet_id_t packet_id)
     151{
    139152        async_msg_1(phone, NET_PACKET_RELEASE, packet_id);
    140153}
  • uspace/lib/net/il/arp_remote.c

    r38aaacc2 rf4f866c  
    3232
    3333/** @file
    34  *  ARP interface implementation for standalone remote modules.
     34 *  ARP interface implementation for remote modules.
    3535 *  @see arp_interface.h
    3636 */
  • uspace/lib/net/il/ip_client.c

    r38aaacc2 rf4f866c  
    5656}
    5757
    58 int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, ip_pseudo_header_ref * header, size_t * headerlen){
     58int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, void **header, size_t * headerlen){
    5959        ipv4_pseudo_header_ref header_in;
    6060        struct sockaddr_in * address_in;
     
    8484                        header_in->protocol = protocol;
    8585                        header_in->data_length = htons(data_length);
    86                         *header = (ip_pseudo_header_ref) header_in;
     86                        *header = header_in;
    8787                        return EOK;
    8888                // TODO IPv6
     
    164164}
    165165
    166 int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){
     166int ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, size_t data_length){
    167167        ipv4_pseudo_header_ref header_in;
    168168
  • uspace/lib/net/il/ip_remote.c

    r38aaacc2 rf4f866c  
    2828
    2929/** @addtogroup ip
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  IP interface implementation for standalone remote modules.
    35  *  @see ip_interface.h
    36  *  @see il_interface.h
     34 *
     35 * IP interface implementation for remote modules.
     36 *
     37 * @see ip_interface.h
     38 * @see il_interface.h
     39 *
    3740 */
    3841
     
    4750#include <il_messages.h>
    4851#include <ip_messages.h>
    49 
    50 int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){
    51         return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr, (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr);
    52 }
    53 
    54 int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg){
    55         return (int) bind_service(service, (ipcarg_t) protocol, me, service, receiver);
    56 }
    57 
    58 int ip_connect_module(services_t service){
     52#include <ip_remote.h>
     53
     54/** Add a route to the device routing table.
     55 *
     56 * The target network is routed using this device.
     57 *
     58 * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
     59 * @param[in] device_id The device identifier.
     60 * @param[in] address   The target network address.
     61 * @param[in] netmask   The target network mask.
     62 * @param[in] gateway   The target network gateway. Not used if zero.
     63 *
     64 */
     65int ip_add_route_req_remote(int ip_phone, device_id_t device_id,
     66    in_addr_t address, in_addr_t netmask, in_addr_t gateway)
     67{
     68        return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE,
     69            (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr,
     70            (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr);
     71}
     72
     73int ip_bind_service(services_t service, int protocol, services_t me,
     74    async_client_conn_t receiver, tl_received_msg_t tl_received_msg)
     75{
     76        return (int) bind_service(service, (ipcarg_t) protocol, me, service,
     77            receiver);
     78}
     79
     80int ip_connect_module(services_t service)
     81{
    5982        return connect_to_service(SERVICE_IP);
    6083}
    6184
    62 int ip_device_req(int ip_phone, device_id_t device_id, services_t service){
    63         return generic_device_req(ip_phone, NET_IL_DEVICE, device_id, 0, service);
    64 }
    65 
    66 int ip_get_route_req(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, ip_pseudo_header_ref * header, size_t * headerlen){
    67         aid_t message_id;
    68         ipcarg_t result;
     85/** Register the new device.
     86 *
     87 * Register itself as the ip packet receiver.
     88 * If the device uses ARP registers also the new ARP device.
     89 *
     90 * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
     91 * @param[in] device_id The new device identifier.
     92 * @param[in] netif     The underlying device network interface layer service.
     93 *
     94 * @return EOK on success.
     95 * @return ENOMEM if there is not enough memory left.
     96 * @return EINVAL if the device configuration is invalid.
     97 * @return ENOTSUP if the device uses IPv6.
     98 * @return ENOTSUP if the device uses DHCP.
     99 * @return Other error codes as defined for the net_get_device_conf_req()
     100 *         function.
     101 * @return Other error codes as defined for the arp_device_req() function.
     102 *
     103 */
     104int ip_device_req_remote(int ip_phone, device_id_t device_id,
     105    services_t service)
     106{
     107        return generic_device_req_remote(ip_phone, NET_IL_DEVICE, device_id, 0,
     108            service);
     109}
     110
     111/** Return the device identifier and the IP pseudo header based on the destination address.
     112 *
     113 * @param[in]  ip_phone    The IP module phone used for (semi)remote calls.
     114 * @param[in]  protocol    The transport protocol.
     115 * @param[in]  destination The destination address.
     116 * @param[in]  addrlen     The destination address length.
     117 * @param[out] device_id   The device identifier.
     118 * @param[out] header      The constructed IP pseudo header.
     119 * @param[out] headerlen   The IP pseudo header length.
     120 *
     121 */
     122int ip_get_route_req_remote(int ip_phone, ip_protocol_t protocol,
     123    const struct sockaddr *destination, socklen_t addrlen,
     124    device_id_t *device_id, void **header, size_t *headerlen)
     125{
     126        if ((!destination) || (addrlen == 0))
     127                return EINVAL;
     128       
     129        if ((!device_id) || (header) || (headerlen))
     130                return EBADMEM;
     131       
     132        *header = NULL;
     133       
    69134        ipc_call_t answer;
    70 
    71         if(!(destination && (addrlen > 0))){
    72                 return EINVAL;
    73         }
    74         if(!(device_id && header && headerlen)){
    75                 return EBADMEM;
    76         }
    77 
    78         *header = NULL;
    79         message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, (ipcarg_t) protocol, &answer);
    80         if((async_data_write_start(ip_phone, destination, addrlen) == EOK)
    81                 && (async_data_read_start(ip_phone, headerlen, sizeof(*headerlen)) == EOK)
    82                 && (*headerlen > 0)){
    83                 *header = (ip_pseudo_header_ref) malloc(*headerlen);
    84                 if(*header){
    85                         if(async_data_read_start(ip_phone, * header, * headerlen) != EOK){
     135        aid_t message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE,
     136            (ipcarg_t) protocol, &answer);
     137       
     138        if ((async_data_write_start(ip_phone, destination, addrlen) == EOK)
     139            && (async_data_read_start(ip_phone, headerlen, sizeof(*headerlen)) == EOK)
     140            && (*headerlen > 0)) {
     141                *header = malloc(*headerlen);
     142                if (*header) {
     143                        if (async_data_read_start(ip_phone, *header, *headerlen) != EOK)
    86144                                free(*header);
    87                         }
    88145                }
    89146        }
     147       
     148        ipcarg_t result;
    90149        async_wait_for(message_id, &result);
    91 
    92         if((result != EOK) && (*header)){
     150       
     151        if ((result != EOK) && (*header))
    93152                free(*header);
    94         }else{
     153        else
    95154                *device_id = IPC_GET_DEVICE(&answer);
    96         }
     155       
    97156        return (int) result;
    98157}
    99158
    100 int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){
    101         return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, packet_dimension);
    102 }
    103 
    104 int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
    105         return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, packet_get_id(packet), target, error);
    106 }
    107 
    108 int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
    109         return generic_send_msg(ip_phone, NET_IL_SEND, device_id, packet_get_id(packet), sender, error);
    110 }
    111 
    112 int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){
    113         return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr);
     159/** Return the device packet dimension for sending.
     160 *
     161 * @param[in]  ip_phone         The IP module phone used for (semi)remote calls.
     162 * @param[in]  device_id        The device identifier.
     163 * @param[out] packet_dimension The packet dimension.
     164 *
     165 * @return EOK on success.
     166 * @return ENOENT if there is no such device.
     167 * @return Other error codes as defined for the
     168 *         generic_packet_size_req_remote() function.
     169 *
     170 */
     171int ip_packet_size_req_remote(int ip_phone, device_id_t device_id,
     172    packet_dimension_ref packet_dimension)
     173{
     174        return generic_packet_size_req_remote(ip_phone, NET_IL_PACKET_SPACE, device_id,
     175            packet_dimension);
     176}
     177
     178/** Notify the IP module about the received error notification packet.
     179 *
     180 * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
     181 * @param[in] device_id The device identifier.
     182 * @param[in] packet    The received packet or the received packet queue.
     183 * @param[in] target    The target internetwork module service to be
     184 *                      delivered to.
     185 * @param[in] error     The packet error reporting service. Prefixes the
     186 *                      received packet.
     187 *
     188 * @return EOK on success.
     189 *
     190 */
     191int ip_received_error_msg_remote(int ip_phone, device_id_t device_id,
     192    packet_t packet, services_t target, services_t error)
     193{
     194        return generic_received_msg_remote(ip_phone, NET_IP_RECEIVED_ERROR,
     195            device_id, packet_get_id(packet), target, error);
     196}
     197
     198/** Send the packet queue.
     199 *
     200 * The packets may get fragmented if needed.
     201 *
     202 * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
     203 * @param[in] device_id The device identifier.
     204 * @param[in] packet    The packet fragments as a packet queue. All the
     205 *                      packets have to have the same destination address.
     206 * @param[in] sender    The sending module service.
     207 * @param[in] error     The packet error reporting service. Prefixes the
     208 *                      received packet.
     209 *
     210 * @return EOK on success.
     211 * @return Other error codes as defined for the generic_send_msg() function.
     212 *
     213 */
     214int ip_send_msg_remote(int ip_phone, device_id_t device_id, packet_t packet,
     215    services_t sender, services_t error)
     216{
     217        return generic_send_msg_remote(ip_phone, NET_IL_SEND, device_id,
     218            packet_get_id(packet), sender, error);
     219}
     220
     221/** Set the default gateway.
     222 *
     223 * This gateway is used if no other route is found.
     224 *
     225 * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
     226 * @param[in] device_id The device identifier.
     227 * @param[in] gateway   The default gateway.
     228 *
     229 */
     230int ip_set_gateway_req_remote(int ip_phone, device_id_t device_id,
     231    in_addr_t gateway)
     232{
     233        return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY,
     234            (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr);
    114235}
    115236
  • uspace/lib/net/include/arp_interface.h

    r38aaacc2 rf4f866c  
    2929/** @addtogroup arp
    3030 *  @{
    31  */
    32 
    33 /** @file
    34  *  ARP module interface.
    35  *  The same interface is used for standalone remote modules as well as for bundle modules.
    36  *  The standalone remote modules have to be compiled with the arp_remote.c source file.
    37  *  The bundle modules with the arp.c source file.
    3831 */
    3932
  • uspace/lib/net/include/icmp_interface.h

    r38aaacc2 rf4f866c  
    2929/** @addtogroup icmp
    3030 *  @{
    31  */
    32 
    33 /** @file
    34  *  ICMP module interface.
    35  *  The same interface is used for standalone remote modules as well as for bundle modules.
    36  *  The standalone remote modules have to be compiled with the icmp_remote.c source file.
    37  *  The bundle modules with the icmp.c source file.
    3831 */
    3932
  • uspace/lib/net/include/il_interface.h

    r38aaacc2 rf4f866c  
    3232
    3333/** @file
    34  *  Internetwork layer module interface for the underlying network interface layer.
    35  *  This interface is always called by the standalone remote modules.
     34 * Internetwork layer module interface for the underlying network interface layer.
     35 * This interface is always called by the remote modules.
    3636 */
    3737
     
    5050
    5151/** @name Internetwork layer module interface
    52  *  This interface is used by other modules.
     52 * This interface is used by other modules.
    5353 */
    5454/*@{*/
    5555
    56 /** Notifies the internetwork layer modules about the device state change.
    57  *  @param[in] il_phone The internetwork layer module phone used for (semi)remote calls.
    58  *  @param[in] device_id The device identifier.
    59  *  @param[in] state The new device state.
    60  *  @param[in] target The target internetwork module service to be delivered to.
    61  *  @returns EOK on success.
     56/** Notify the internetwork layer modules about the device state change.
     57 *
     58 * @param[in] il_phone  The internetwork layer module phone used for
     59 *                      (semi)remote calls.
     60 * @param[in] device_id The device identifier.
     61 * @param[in] state     The new device state.
     62 * @param[in] target    The target internetwork module service to be
     63 *                      delivered to.
     64 *
     65 * @return EOK on success.
     66 *
    6267 */
    63 static inline int il_device_state_msg(int il_phone, device_id_t device_id, device_state_t state, services_t target){
    64         return generic_device_state_msg(il_phone, NET_IL_DEVICE_STATE, device_id, state, target);
     68static inline int il_device_state_msg(int il_phone, device_id_t device_id,
     69    device_state_t state, services_t target)
     70{
     71        return generic_device_state_msg_remote(il_phone, NET_IL_DEVICE_STATE,
     72            device_id, state, target);
    6573}
    6674
    67 /** Notifies the internetwork layer modules about the received packet/s.
    68  *  @param[in] il_phone The internetwork layer module phone used for (semi)remote calls.
    69  *  @param[in] device_id The device identifier.
    70  *  @param[in] packet The received packet or the received packet queue.
    71  *  @param[in] target The target internetwork module service to be delivered to.
    72  *  @returns EOK on success.
     75/** Notify the internetwork layer modules about the received packet/s.
     76 *
     77 * @param[in] il_phone  The internetwork layer module phone used for
     78 *                      (semi)remote calls.
     79 * @param[in] device_id The device identifier.
     80 * @param[in] packet    The received packet or the received packet queue.
     81 * @param[in] target    The target internetwork module service to be
     82 *                      delivered to.
     83 *
     84 * @return EOK on success.
     85 *
    7386 */
    74 inline static int il_received_msg(int il_phone, device_id_t device_id, packet_t packet, services_t target){
    75         return generic_received_msg(il_phone, NET_IL_RECEIVED, device_id, packet_get_id(packet), target, 0);
     87inline static int il_received_msg(int il_phone, device_id_t device_id,
     88    packet_t packet, services_t target)
     89{
     90        return generic_received_msg_remote(il_phone, NET_IL_RECEIVED, device_id,
     91            packet_get_id(packet), target, 0);
    7692}
    7793
    78 /** Notifies the internetwork layer modules about the mtu change.
    79  *  @param[in] il_phone The internetwork layer module phone used for (semi)remote calls.
    80  *  @param[in] device_id The device identifier.
    81  *  @param[in] mtu The new mtu value.
    82  *  @param[in] target The target internetwork module service to be delivered to.
    83  *  @returns EOK on success.
     94/** Notify the internetwork layer modules about the mtu change.
     95 *
     96 * @param[in] il_phone  The internetwork layer module phone used for
     97 *                      (semi)remote calls.
     98 * @param[in] device_id The device identifier.
     99 * @param[in] mtu       The new mtu value.
     100 * @param[in] target    The target internetwork module service to be
     101 *                      delivered to.
     102 *
     103 * @return EOK on success.
     104 *
    84105 */
    85 inline static int il_mtu_changed_msg(int il_phone, device_id_t device_id, size_t mtu, services_t target){
    86         return generic_device_state_msg(il_phone, NET_IL_MTU_CHANGED, device_id, (int) mtu, target);
     106inline static int il_mtu_changed_msg(int il_phone, device_id_t device_id,
     107    size_t mtu, services_t target)
     108{
     109        return generic_device_state_msg_remote(il_phone, NET_IL_MTU_CHANGED,
     110            device_id, (int) mtu, target);
    87111}
    88112
  • uspace/lib/net/include/il_local.h

    r38aaacc2 rf4f866c  
    2727 */
    2828
    29 /** @addtogroup tl_standalone
     29/** @addtogroup il_local
    3030 *  @{
    3131 */
    3232
    33 #ifndef __TL_STANDALONE_H__
    34 #define __TL_STANDALONE_H__
     33#ifndef __IL_LOCAL_H__
     34#define __IL_LOCAL_H__
    3535
    3636#include <ipc/ipc.h>
    3737#include <async.h>
    3838
    39 extern int tl_module_message(ipc_callid_t callid, ipc_call_t *call,
     39extern int il_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
    4040    ipc_call_t *answer, int *answer_count);
    41 extern int tl_module_start(async_client_conn_t client_connection);
     41extern int il_module_start_standalone(async_client_conn_t client_connection);
    4242
    4343#endif
  • uspace/lib/net/include/il_messages.h

    r38aaacc2 rf4f866c  
    2828
    2929/** @addtogroup net_il
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Internetwork layer modules messages.
    35  *  @see il_interface.h
    36  *  @see ip_interface.h
     34 * Internetwork layer modules messages.
     35 * @see il_interface.h
     36 * @see ip_interface.h
    3737 */
    3838
     
    4444/** Internet layer modules messages.
    4545 */
    46 typedef enum{
     46typedef enum {
    4747        /** New device message.
    4848         *  @see ip_device_req()
     
    7272
    7373/** @name Internetwork layer specific message parameters definitions
     74 *
    7475 */
    7576/*@{*/
    7677
    77 /** Returns the protocol number message parameter.
    78  *  @param[in] call The message call structure.
     78/** Return the protocol number message parameter.
     79 * @param[in] call The message call structure.
     80 *
    7981 */
    80 #define IL_GET_PROTO(call)              (int) IPC_GET_ARG1(*call)
     82#define IL_GET_PROTO(call)  (int) IPC_GET_ARG1(*call)
    8183
    82 /** Returns the registering service message parameter.
    83  *  @param[in] call The message call structure.
     84/** Return the registering service message parameter.
     85 * @param[in] call The message call structure.
     86 *
    8487 */
    85 #define IL_GET_SERVICE(call)    (services_t) IPC_GET_ARG2(*call)
     88#define IL_GET_SERVICE(call)  (services_t) IPC_GET_ARG2(*call)
    8689
    8790/*@}*/
  • uspace/lib/net/include/ip_client.h

    r38aaacc2 rf4f866c  
    8787 *  @returns EINVAL if the headerlen parameter is not IPv4 pseudo header length.
    8888 */
    89 extern int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length);
     89extern int ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, size_t data_length);
    9090
    9191/** Constructs the IPv4 pseudo header.
     
    107107 *  @returns ENOMEM if there is not enough memory left.
    108108 */
    109 extern int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, ip_pseudo_header_ref * header, size_t * headerlen);
     109extern int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, void **header, size_t * headerlen);
    110110
    111111// TODO ipopt manipulation
  • uspace/lib/net/include/ip_interface.h

    r38aaacc2 rf4f866c  
    3131 */
    3232
    33 /** @file
    34  *  IP module interface.
    35  *  The same interface is used for standalone remote modules as well as for bundle modules.
    36  *  The standalone remote modules have to be compiled with the ip_remote.c source file.
    37  *  The bundle modules with the ip.c source file.
    38  */
    39 
    4033#ifndef __NET_IP_INTERFACE_H__
    4134#define __NET_IP_INTERFACE_H__
     
    5144#include <socket_codes.h>
    5245
     46#ifdef CONFIG_IL_TL_BUNDLE
     47
     48#include <ip_local.h>
     49
     50#define ip_received_error_msg  ip_received_error_msg_local
     51#define ip_set_gateway_req     ip_set_gateway_req_local
     52#define ip_packet_size_req     ip_packet_size_req_local
     53#define ip_device_req          ip_device_req_local
     54#define ip_add_route_req       ip_add_route_req_local
     55#define ip_send_msg            ip_send_msg_local
     56#define ip_get_route_req       ip_get_route_req_local
     57
     58#else
     59
     60#include <ip_remote.h>
     61
     62#define ip_received_error_msg  ip_received_error_msg_remote
     63#define ip_set_gateway_req     ip_set_gateway_req_remote
     64#define ip_packet_size_req     ip_packet_size_req_remote
     65#define ip_device_req          ip_device_req_remote
     66#define ip_add_route_req       ip_add_route_req_remote
     67#define ip_send_msg            ip_send_msg_remote
     68#define ip_get_route_req       ip_get_route_req_remote
     69
     70#endif
     71
    5372/** @name IP module interface
    5473 *  This interface is used by other modules.
    5574 */
    5675/*@{*/
    57 
    58 /** Type definition of the internet pseudo header pointer.
    59  */
    60 typedef void *          ip_pseudo_header_ref;
    6176
    6277/** The transport layer notification function type definition.
     
    8297extern int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg);
    8398
    84 /** Registers the new device.
    85  *  Registers itself as the ip packet receiver.
    86  *  If the device uses ARP registers also the new ARP device.
    87  *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
    88  *  @param[in] device_id The new device identifier.
    89  *  @param[in] netif The underlying device network interface layer service.
    90  *  @returns EOK on success.
    91  *  @returns ENOMEM if there is not enough memory left.
    92  *  @returns EINVAL if the device configuration is invalid.
    93  *  @returns ENOTSUP if the device uses IPv6.
    94  *  @returns ENOTSUP if the device uses DHCP.
    95  *  @returns Other error codes as defined for the net_get_device_conf_req() function.
    96  *  @returns Other error codes as defined for the arp_device_req() function.
    97  */
    98 extern int ip_device_req(int ip_phone, device_id_t device_id, services_t netif);
    99 
    100 /** Sends the packet queue.
    101  *  The packets may get fragmented if needed.
    102  *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
    103  *  @param[in] device_id The device identifier.
    104  *  @param[in] packet The packet fragments as a~packet queue. All the packets have to have the same destination address.
    105  *  @param[in] sender The sending module service.
    106  *  @param[in] error The packet error reporting service. Prefixes the received packet.
    107  *  @returns EOK on success.
    108  *  @returns Other error codes as defined for the generic_send_msg() function.
    109  */
    110 extern int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error);
    111 
    11299/** Connects to the IP module.
    113100 *  @param service The IP module service. Ignored parameter.
     
    117104extern int ip_connect_module(services_t service);
    118105
    119 /** Adds a route to the device routing table.
    120  *  The target network is routed using this device.
    121  *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
    122  *  @param[in] device_id The device identifier.
    123  *  @param[in] address The target network address.
    124  *  @param[in] netmask The target network mask.
    125  *  @param[in] gateway The target network gateway. Not used if zero.
    126  */
    127 extern int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway);
    128 
    129 /** Sets the default gateway.
    130  *  This gateway is used if no other route is found.
    131  *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
    132  *  @param[in] device_id The device identifier.
    133  *  @param[in] gateway The default gateway.
    134  */
    135 extern int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway);
    136 
    137 /** Returns the device packet dimension for sending.
    138  *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
    139  *  @param[in] device_id The device identifier.
    140  *  @param[out] packet_dimension The packet dimension.
    141  *  @returns EOK on success.
    142  *  @returns ENOENT if there is no such device.
    143  *  @returns Other error codes as defined for the generic_packet_size_req() function.
    144  */
    145 extern int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension);
    146 
    147 /** Notifies the IP module about the received error notification packet.
    148  *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
    149  *  @param[in] device_id The device identifier.
    150  *  @param[in] packet The received packet or the received packet queue.
    151  *  @param[in] target The target internetwork module service to be delivered to.
    152  *  @param[in] error The packet error reporting service. Prefixes the received packet.
    153  *  @returns EOK on success.
    154  */
    155 extern int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error);
    156 
    157 /** Returns the device identifier and the IP pseudo header based on the destination address.
    158  *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
    159  *  @param[in] protocol The transport protocol.
    160  *  @param[in] destination The destination address.
    161  *  @param[in] addrlen The destination address length.
    162  *  @param[out] device_id The device identifier.
    163  *  @param[out] header The constructed IP pseudo header.
    164  *  @param[out] headerlen The IP pseudo header length.
    165  */
    166 extern int ip_get_route_req(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, ip_pseudo_header_ref * header, size_t * headerlen);
    167 
    168106/*@}*/
    169107
  • uspace/lib/net/include/net_interface.h

    r38aaacc2 rf4f866c  
    2929/** @addtogroup net
    3030 *  @{
    31  */
    32 
    33 /** @file
    34  *  Networking module interface.
    35  *  The same interface is used for standalone remote modules as well as for bundle modules.
    36  *  The standalone remote modules have to be compiled with the net_remote.c source file.
    37  *  The bundle networking module is compiled with the net_bundle.c source file and the choosen bundle module implementation source files.
    3831 */
    3932
  • uspace/lib/net/include/netif_interface.h

    r38aaacc2 rf4f866c  
    2828
    2929/** @addtogroup netif
    30  *  @{
    31  */
    32 
    33 /** @file
    34  *  Network interface module interface.
    35  *  The same interface is used for standalone remote modules as well as for bundle network interface layer modules.
    36  *  The standalone remote modules have to be compiled with the netif_remote.c source file.
    37  *  The bundle network interface layer modules are compiled with the netif_nil_bundle.c source file and the choosen network interface layer implementation source file.
     30 * @{
    3831 */
    3932
     
    4134#define __NET_NETIF_INTERFACE_H__
    4235
    43 #include <ipc/services.h>
     36#ifdef CONFIG_NETIF_NIL_BUNDLE
    4437
    45 #include <net_messages.h>
    46 #include <adt/measured_strings.h>
    47 #include <packet/packet.h>
    48 #include <net_device.h>
     38#include <netif_local.h>
     39#include <netif_nil_bundle.h>
     40#include <packet/packet_server.h>
    4941
    50 /** @name Network interface module interface
    51  *  This interface is used by other modules.
    52  */
    53 /*@{*/
     42#define netif_module_message    netif_nil_module_message
     43#define netif_module_start      netif_nil_module_start
     44#define netif_get_addr_req      netif_get_addr_req_local
     45#define netif_probe_req         netif_probe_req_local
     46#define netif_send_msg          netif_send_msg_local
     47#define netif_start_req         netif_start_req_local
     48#define netif_stop_req          netif_stop_req_local
     49#define netif_stats_req         netif_stats_req_local
     50#define netif_bind_service      netif_bind_service_local
    5451
    55 /** Returns the device local hardware address.
    56  *  @param[in] netif_phone The network interface phone.
    57  *  @param[in] device_id The device identifier.
    58  *  @param[out] address The device local hardware address.
    59  *  @param[out] data The address data.
    60  *  @returns EOK on success.
    61  *  @returns EBADMEM if the address parameter is NULL.
    62  *  @returns ENOENT if there no such device.
    63  *  @returns Other error codes as defined for the netif_get_addr_message() function.
    64  */
    65 extern int netif_get_addr_req(int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data);
     52#else /* CONFIG_NETIF_NIL_BUNDLE */
    6653
    67 /** Probes the existence of the device.
    68  *  @param[in] netif_phone The network interface phone.
    69  *  @param[in] device_id The device identifier.
    70  *  @param[in] irq The device interrupt number.
    71  *  @param[in] io The device input/output address.
    72  *  @returns EOK on success.
    73  *  @returns Other errro codes as defined for the netif_probe_message().
    74  */
    75 extern int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io);
     54#include <netif_remote.h>
     55#include <packet/packet_client.h>
    7656
    77 /** Sends the packet queue.
    78  *  @param[in] netif_phone The network interface phone.
    79  *  @param[in] device_id The device identifier.
    80  *  @param[in] packet The packet queue.
    81  *  @param[in] sender The sending module service.
    82  *  @returns EOK on success.
    83  *  @returns Other error codes as defined for the generic_send_msg() function.
    84  */
    85 extern int netif_send_msg(int netif_phone, device_id_t device_id, packet_t packet, services_t sender);
     57#define netif_module_message    netif_module_message_standalone
     58#define netif_module_start      netif_module_start_standalone
     59#define netif_get_addr_req      netif_get_addr_req_remote
     60#define netif_probe_req         netif_probe_req_remote
     61#define netif_send_msg          netif_send_msg_remote
     62#define netif_start_req         netif_start_req_remote
     63#define netif_stop_req          netif_stop_req_remote
     64#define netif_stats_req         netif_stats_req_remote
     65#define netif_bind_service      netif_bind_service_remote
    8666
    87 /** Starts the device.
    88  *  @param[in] netif_phone The network interface phone.
    89  *  @param[in] device_id The device identifier.
    90  *  @returns EOK on success.
    91  *  @returns Other error codes as defined for the find_device() function.
    92  *  @returns Other error codes as defined for the netif_start_message() function.
    93  */
    94 extern int netif_start_req(int netif_phone, device_id_t device_id);
    95 
    96 /** Stops the device.
    97  *  @param[in] netif_phone The network interface phone.
    98  *  @param[in] device_id The device identifier.
    99  *  @returns EOK on success.
    100  *  @returns Other error codes as defined for the find_device() function.
    101  *  @returns Other error codes as defined for the netif_stop_message() function.
    102  */
    103 extern int netif_stop_req(int netif_phone, device_id_t device_id);
    104 
    105 /** Returns the device usage statistics.
    106  *  @param[in] netif_phone The network interface phone.
    107  *  @param[in] device_id The device identifier.
    108  *  @param[out] stats The device usage statistics.
    109  *  @returns EOK on success.
    110  */
    111 extern int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats);
    112 
    113 /** Creates bidirectional connection with the network interface module and registers the message receiver.
    114  *  @param[in] service The network interface module service.
    115  *  @param[in] device_id The device identifier.
    116  *  @param[in] me The requesting module service.
    117  *  @param[in] receiver The message receiver.
    118  *  @returns The phone of the needed service.
    119  *  @returns EOK on success.
    120  *  @returns Other error codes as defined for the bind_service() function.
    121  */
    122 extern int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver);
    123 
    124 /*@}*/
     67#endif /* CONFIG_NETIF_NIL_BUNDLE */
    12568
    12669#endif
  • uspace/lib/net/include/netif_messages.h

    r38aaacc2 rf4f866c  
    2828
    2929/** @addtogroup netif
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Network interface common module messages.
    35  *  @see netif_interface.h
     34 * Network interface common module messages.
    3635 */
    3736
     
    7675/*@{*/
    7776
    78 /** Returns the interrupt number message parameter.
    79  *  @param[in] call The message call structure.
     77/** Return the interrupt number message parameter.
     78 * @param[in] call The message call structure.
    8079 */
    8180#define NETIF_GET_IRQ(call) \
    8281        ({int irq = (int) IPC_GET_ARG2(*call); irq;})
    8382
    84 /** Returns the input/output address message parameter.
    85  *  @param[in] call The message call structure.
     83/** Return the input/output address message parameter.
     84 * @param[in] call The message call structure.
    8685 */
    8786#define NETIF_GET_IO(call) \
  • uspace/lib/net/include/netif_nil_bundle.h

    r38aaacc2 rf4f866c  
    3737#include <async.h>
    3838
    39 extern int netif_nil_module_message(ipc_callid_t callid, ipc_call_t *call,
    40     ipc_call_t *answer, int *answer_count);
    41 extern int netif_nil_module_start(async_client_conn_t client_connection);
     39extern int netif_nil_module_message(const char *, ipc_callid_t, ipc_call_t *,
     40    ipc_call_t *, int *);
     41extern int netif_nil_module_start(async_client_conn_t);
    4242
    4343#endif
  • uspace/lib/net/include/nil_interface.h

    r38aaacc2 rf4f866c  
    3131 */
    3232
    33 /** @file
    34  *  Network interface layer module interface.
    35  *  The same interface is used for standalone remote device modules as well as for bundle device modules.
    36  *  The standalone remote device modules have to be compiled with the nil_remote.c source file.
    37  *  The bundle device modules with the appropriate network interface layer source file (eth.c etc.).
    38  *  The upper layers cannot be bundled with the network interface layer.
    39  */
    40 
    4133#ifndef __NET_NIL_INTERFACE_H__
    4234#define __NET_NIL_INTERFACE_H__
     
    5345#include <net_device.h>
    5446
    55 /** @name Network interface layer module interface
    56  *  This interface is used by other modules.
    57  */
    58 /*@{*/
     47#define nil_bind_service(service, device_id, me, receiver) \
     48        bind_service(service, device_id, me, 0, receiver)
    5949
    60 /** Returns the device local hardware address.
    61  *  @param[in] nil_phone The network interface layer phone.
    62  *  @param[in] device_id The device identifier.
    63  *  @param[out] address The device local hardware address.
    64  *  @param[out] data The address data.
    65  *  @returns EOK on success.
    66  *  @returns EBADMEM if the address parameter and/or the data parameter is NULL.
    67  *  @returns ENOENT if there no such device.
    68  *  @returns Other error codes as defined for the generic_get_addr_req() function.
    69  */
    70 #define nil_get_addr_req(nil_phone, device_id, address, data)   \
     50#define nil_packet_size_req(nil_phone, device_id, packet_dimension) \
     51        generic_packet_size_req_remote(nil_phone, NET_NIL_PACKET_SPACE, device_id, \
     52            packet_dimension)
     53
     54#define nil_get_addr_req(nil_phone, device_id, address, data) \
    7155        generic_get_addr_req(nil_phone, NET_NIL_ADDR, device_id, address, data)
    7256
    73 /** Returns the device broadcast hardware address.
    74  *  @param[in] nil_phone The network interface layer phone.
    75  *  @param[in] device_id The device identifier.
    76  *  @param[out] address The device broadcast hardware address.
    77  *  @param[out] data The address data.
    78  *  @returns EOK on success.
    79  *  @returns EBADMEM if the address parameter is NULL.
    80  *  @returns ENOENT if there no such device.
    81  *  @returns Other error codes as defined for the generic_get_addr_req() function.
    82  */
    83 #define nil_get_broadcast_addr_req(nil_phone, device_id, address, data) \
    84         generic_get_addr_req(nil_phone, NET_NIL_BROADCAST_ADDR, device_id, address, data)
     57#define nil_get_broadcast_addr_req(nil_phone, device_id, address, data) \
     58        generic_get_addr_req(nil_phone, NET_NIL_BROADCAST_ADDR, device_id, \
     59            address, data)
    8560
    86 /** Sends the packet queue.
    87  *  @param[in] nil_phone The network interface layer phone.
    88  *  @param[in] device_id The device identifier.
    89  *  @param[in] packet The packet queue.
    90  *  @param[in] sender The sending module service.
    91  *  @returns EOK on success.
    92  *  @returns Other error codes as defined for the generic_send_msg() function.
    93  */
    94 #define nil_send_msg(nil_phone, device_id, packet, sender)      \
    95         generic_send_msg(nil_phone, NET_NIL_SEND, device_id, packet_get_id(packet), sender, 0)
     61#define nil_send_msg(nil_phone, device_id, packet, sender) \
     62        generic_send_msg_remote(nil_phone, NET_NIL_SEND, device_id, \
     63            packet_get_id(packet), sender, 0)
    9664
    97 /** Returns the device packet dimension for sending.
    98  *  @param[in] nil_phone The network interface layer phone.
    99  *  @param[in] device_id The device identifier.
    100  *  @param[out] packet_dimension The packet dimensions.
    101  *  @returns EOK on success.
    102  *  @returns ENOENT if there is no such device.
    103  *  @returns Other error codes as defined for the generic_packet_size_req() function.
    104  */
    105 #define nil_packet_size_req(nil_phone, device_id, packet_dimension)     \
    106         generic_packet_size_req(nil_phone, NET_NIL_PACKET_SPACE, device_id, packet_dimension)
     65#define nil_device_req(nil_phone, device_id, mtu, netif_service) \
     66        generic_device_req_remote(nil_phone, NET_NIL_DEVICE, device_id, mtu, \
     67            netif_service)
    10768
    108 /** Registers new device or updates the MTU of an existing one.
    109  *  @param[in] nil_phone The network interface layer phone.
    110  *  @param[in] device_id The new device identifier.
    111  *  @param[in] mtu The device maximum transmission unit.
    112  *  @param[in] netif_service The device driver service.
    113  *  @returns EOK on success.
    114  *  @returns EEXIST if the device with the different service exists.
    115  *  @returns ENOMEM if there is not enough memory left.
    116  *  @returns Other error codes as defined for the generic_device_req() function.
    117  */
    118 #define nil_device_req(nil_phone, device_id, mtu, netif_service)        \
    119         generic_device_req(nil_phone, NET_NIL_DEVICE, device_id, mtu, netif_service)
    12069
    121 /** Notifies the network interface layer about the device state change.
    122  *  @param[in] nil_phone The network interface layer phone.
    123  *  @param[in] device_id The device identifier.
    124  *  @param[in] state The new device state.
    125  *  @returns EOK on success.
    126  *  @returns Other error codes as defined for each specific module device state function.
    127  */
    128 extern int nil_device_state_msg(int nil_phone, device_id_t device_id, int state);
     70#ifdef CONFIG_NETIF_NIL_BUNDLE
    12971
    130 /** Passes the packet queue to the network interface layer.
    131  *  Processes and redistributes the received packet queue to the registered upper layers.
    132  *  @param[in] nil_phone The network interface layer phone.
    133  *  @param[in] device_id The source device identifier.
    134  *  @param[in] packet The received packet or the received packet queue.
    135  *  @param target The target service. Ignored parameter.
    136  *  @returns EOK on success.
    137  *  @returns Other error codes as defined for each specific module received function.
    138  */
    139 extern int nil_received_msg(int nil_phone, device_id_t device_id, packet_t packet, services_t target);
     72#include <nil_local.h>
     73#include <packet/packet_server.h>
    14074
    141 /** Creates bidirectional connection with the network interface layer module and registers the message receiver.
    142  *  @param[in] service The network interface layer module service.
    143  *  @param[in] device_id The device identifier.
    144  *  @param[in] me The requesting module service.
    145  *  @param[in] receiver The message receiver.
    146  *  @returns The phone of the needed service.
    147  *  @returns EOK on success.
    148  *  @returns Other error codes as defined for the bind_service() function.
    149  */
    150 #define nil_bind_service(service, device_id, me, receiver)      \
    151         bind_service(service, device_id, me, 0, receiver);
    152 /*@}*/
     75#define nil_device_state_msg  nil_device_state_msg_local
     76#define nil_received_msg      nil_received_msg_local
     77
     78#else /* CONFIG_NETIF_NIL_BUNDLE */
     79
     80#include <nil_remote.h>
     81#include <packet/packet_server.h>
     82
     83#define nil_device_state_msg  nil_device_state_msg_remote
     84#define nil_received_msg      nil_received_msg_remote
     85
     86#endif /* CONFIG_NETIF_NIL_BUNDLE */
    15387
    15488#endif
  • uspace/lib/net/include/nil_local.h

    r38aaacc2 rf4f866c  
    3232
    3333/** @file
    34  *  Network interface layer modules common skeleton.
    35  *  All network interface layer modules have to implement this interface.
     34 * Network interface layer modules common skeleton.
     35 * All network interface layer modules have to implement this interface.
    3636 */
    3737
    38 #ifndef __NET_NIL_MODULE_H__
    39 #define __NET_NIL_MODULE_H__
     38#ifndef __NET_NIL_LOCAL_H__
     39#define __NET_NIL_LOCAL_H__
    4040
    4141#include <ipc/ipc.h>
    4242
    4343/** Module initialization.
    44  *  Is called by the module_start() function.
    45  *  @param[in] net_phone The networking moduel phone.
    46  *  @returns EOK on success.
    47  *  @returns Other error codes as defined for each specific module initialize function.
     44 *
     45 * Is called by the module_start() function.
     46 *
     47 * @param[in] net_phone The networking moduel phone.
     48 *
     49 * @return EOK on success.
     50 * @return Other error codes as defined for each specific module initialize function.
     51 *
    4852 */
    49 extern int nil_initialize(int net_phone);
     53extern int nil_initialize(int);
     54
     55extern int nil_device_state_msg_local(int, device_id_t, int);
     56extern int nil_received_msg_local(int, device_id_t, packet_t, services_t);
    5057
    5158/** Message processing function.
    52  *  @param[in] callid The message identifier.
    53  *  @param[in] call The message parameters.
    54  *  @param[out] answer The message answer parameters.
    55  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    56  *  @returns EOK on success.
    57  *  @returns ENOTSUP if the message is not known.
    58  *  @returns Other error codes as defined for each specific module message function.
    59  *  @see nil_interface.h
    60  *  @see IS_NET_NIL_MESSAGE()
     59 *
     60 * @param[in]  name         Module name.
     61 * @param[in]  callid       The message identifier.
     62 * @param[in]  call         The message parameters.
     63 * @param[out] answer       The message answer parameters.
     64 * @param[out] answer_count The last parameter for the actual answer
     65 *                          in the answer parameter.
     66 *
     67 * @return EOK on success.
     68 * @return ENOTSUP if the message is not known.
     69 * @return Other error codes as defined for each specific
     70 *         module message function.
     71 *
     72 * @see nil_interface.h
     73 * @see IS_NET_NIL_MESSAGE()
     74 *
    6175 */
    62 extern int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
     76extern int nil_message_standalone(const char *, ipc_callid_t, ipc_call_t *, ipc_call_t *,
     77    int *);
     78
     79extern int nil_module_message_standalone(const char *, ipc_callid_t,
     80    ipc_call_t *, ipc_call_t *, int *);
     81extern int nil_module_start_standalone(async_client_conn_t);
    6382
    6483#endif
  • uspace/lib/net/include/nil_messages.h

    r38aaacc2 rf4f866c  
    2828
    2929/** @addtogroup net_nil
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Network interface layer module messages.
    35  *  @see nil_interface.h
     34 * Network interface layer module messages.
    3635 */
    3736
     
    4342#include <net_messages.h>
    4443
    45 /**  Network interface layer module messages.
     44/** Network interface layer module messages.
    4645 */
    4746typedef enum {
     
    8079/*@{*/
    8180
    82 /** Returns the protocol service message parameter.
     81/** Return the protocol service message parameter.
    8382 */
    8483#define NIL_GET_PROTO(call) \
  • uspace/lib/net/include/nil_remote.h

    r38aaacc2 rf4f866c  
    11/*
    2  * Copyright (c) 2010 Martin Decky
     2 * Copyright (c) 2009 Lukas Mejdrech
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup nil_standalone
    30  *  @{
     29/** @addtogroup netif
     30 * @{
    3131 */
    3232
    33 #ifndef __NIL_STANDALONE_H__
    34 #define __NIL_STANDALONE_H__
     33#ifndef __NET_NIL_REMOTE_H__
     34#define __NET_NIL_REMOTE_H__
    3535
     36#include <async.h>
     37#include <fibril_synch.h>
    3638#include <ipc/ipc.h>
    37 #include <async.h>
    3839
    39 extern int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
    40     ipc_call_t *answer, int *answer_count);
    41 extern int nil_module_start(async_client_conn_t client_connection);
     40extern int nil_device_state_msg_remote(int, device_id_t, int);
     41extern int nil_received_msg_remote(int, device_id_t, packet_t, services_t);
    4242
    4343#endif
  • uspace/lib/net/include/tl_common.h

    r38aaacc2 rf4f866c  
    4949DEVICE_MAP_DECLARE(packet_dimensions, packet_dimension_t);
    5050
     51extern int tl_get_ip_packet_dimension(int, packet_dimensions_ref,
     52    device_id_t, packet_dimension_ref *);
     53
    5154/** Gets the address port.
    5255 *  Supports AF_INET and AF_INET6 address families.
     
    5962 */
    6063extern int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port);
    61 
    62 /** Gets IP packet dimensions.
    63  *  Tries to search a cache and queries the IP module if not found.
    64  *  The reply is cached then.
    65  *  @param[in] ip_phone The IP moduel phone for (semi)remote calls.
    66  *  @param[in] packet_dimensions The packet dimensions cache.
    67  *  @param[in] device_id The device identifier.
    68  *  @param[out] packet_dimension The IP packet dimensions.
    69  *  @returns EOK on success.
    70  *  @returns EBADMEM if the packet_dimension parameter is NULL.
    71  *  @return ENOMEM if there is not enough memory left.
    72  *  @returns EINVAL if the packet_dimensions cache is not valid.
    73  *  @returns Other codes as defined for the ip_packet_size_req() function.
    74  */
    75 extern int tl_get_ip_packet_dimension(int ip_phone, packet_dimensions_ref packet_dimensions, device_id_t device_id, packet_dimension_ref * packet_dimension);
    7664
    7765/** Updates IP device packet dimensions cache.
  • uspace/lib/net/include/tl_interface.h

    r38aaacc2 rf4f866c  
    3232
    3333/** @file
    34  *  Transport layer module interface for the underlying internetwork layer.
     34 * Transport layer module interface for the underlying internetwork layer.
    3535 */
    3636
     
    4848
    4949/** @name Transport layer module interface
    50  *  This interface is used by other modules.
     50 * This interface is used by other modules.
    5151 */
    5252/*@{*/
    5353
    54 /** Notifies the remote transport layer modules about the received packet/s.
    55  *  @param[in] tl_phone The transport layer module phone used for remote calls.
    56  *  @param[in] device_id The device identifier.
    57  *  @param[in] packet The received packet or the received packet queue. The packet queue is used to carry a~fragmented datagram. The first packet contains the headers, the others contain only data.
    58  *  @param[in] target The target transport layer module service to be delivered to.
    59  *  @param[in] error The packet error reporting service. Prefixes the received packet.
    60  *  @returns EOK on success.
     54/** Notify the remote transport layer modules about the received packet/s.
     55 *
     56 * @param[in] tl_phone  The transport layer module phone used for remote calls.
     57 * @param[in] device_id The device identifier.
     58 * @param[in] packet    The received packet or the received packet queue.
     59 *                      The packet queue is used to carry a fragmented
     60 *                      datagram. The first packet contains the headers,
     61 *                      the others contain only data.
     62 * @param[in] target    The target transport layer module service to be
     63 *                      delivered to.
     64 * @param[in] error     The packet error reporting service. Prefixes the
     65 *                      received packet.
     66 *
     67 * @return EOK on success.
     68 *
    6169 */
    62 inline static int tl_received_msg(int tl_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
    63         return generic_received_msg(tl_phone, NET_TL_RECEIVED, device_id, packet_get_id(packet), target, error);
     70inline static int tl_received_msg(int tl_phone, device_id_t device_id,
     71    packet_t packet, services_t target, services_t error)
     72{
     73        return generic_received_msg_remote(tl_phone, NET_TL_RECEIVED, device_id,
     74            packet_get_id(packet), target, error);
    6475}
    6576
  • uspace/lib/net/include/tl_local.h

    r38aaacc2 rf4f866c  
    2727 */
    2828
    29 /** @addtogroup il_standalone
     29/** @addtogroup tl_local
    3030 *  @{
    3131 */
    3232
    33 #ifndef __IL_STANDALONE_H__
    34 #define __IL_STANDALONE_H__
     33#ifndef __TL_LOCAL_H__
     34#define __TL_LOCAL_H__
    3535
    3636#include <ipc/ipc.h>
    3737#include <async.h>
    3838
    39 extern int il_module_message(ipc_callid_t callid, ipc_call_t *call,
    40     ipc_call_t *answer, int *answer_count);
    41 extern int il_module_start(async_client_conn_t client_connection);
     39extern int tl_module_message_standalone(ipc_callid_t, ipc_call_t *,
     40    ipc_call_t *, int *);
     41extern int tl_module_start_standalone(async_client_conn_t);
    4242
    4343#endif
  • uspace/lib/net/netif/netif_nil_bundle.c

    r38aaacc2 rf4f866c  
    4141#include <net_messages.h>
    4242#include <packet/packet.h>
    43 #include <nil_module.h>
    4443#include <netif_nil_bundle.h>
    45 #include <netif.h>
     44#include <netif_local.h>
     45#include <nil_local.h>
    4646
    47 /** Distributes the messages between the module parts.
    48  *  @param[in] callid The message identifier.
    49  *  @param[in] call The message parameters.
    50  *  @param[out] answer The message answer parameters.
    51  *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
    52  *  @returns EOK on success.
    53  *  @returns ENOTSUP if the message is not known.
    54  *  @returns Other error codes as defined for each specific module message function.
     47/** Distribute the messages between the module parts.
     48 *
     49 * @param[in]  name         Module name.
     50 * @param[in]  callid       The message identifier.
     51 * @param[in]  call         The message parameters.
     52 * @param[out] answer       The message answer parameters.
     53 * @param[out] answer_count The last parameter for the actual
     54 *                          answer in the answer parameter.
     55 *
     56 * @return EOK on success.
     57 * @return ENOTSUP if the message is not known.
     58 * @return Other error codes as defined for each specific module message function.
     59 *
    5560 */
    56 int netif_nil_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
    57         if(IS_NET_NIL_MESSAGE(call) || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)){
    58                 return nil_message(callid, call, answer, answer_count);
    59         }else{
    60                 return netif_message(callid, call, answer, answer_count);
    61         }
     61int netif_nil_module_message(const char *name, ipc_callid_t callid,
     62    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
     63{
     64        if ((IS_NET_NIL_MESSAGE(call))
     65            || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME))
     66                return nil_message_standalone(name, callid, call, answer,
     67                    answer_count);
     68        else
     69                return netif_module_message_standalone(name, callid, call, answer,
     70                    answer_count);
    6271}
    6372
    64 /** Starts the bundle network interface module.
    65  *  Initializes the client connection serving function, initializes both module parts, registers the module service and starts the async manager, processing IPC messages in an infinite loop.
    66  *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
    67  *  @returns EOK on success.
    68  *  @returns Other error codes as defined for each specific module message function.
     73/** Start the bundle network interface module.
     74 *
     75 * Initialize the client connection serving function, initialize
     76 * both module parts, register the module service and start the
     77 * async manager, processing IPC messages in an infinite loop.
     78 *
     79 * @param[in] client_connection The client connection processing
     80 *                              function. The module skeleton propagates
     81 *                              its own one.
     82 *
     83 * @return EOK on success.
     84 * @return Other error codes as defined for each specific module message
     85 *         function.
     86 *
    6987 */
    70 int netif_nil_module_start(async_client_conn_t client_connection){
     88int netif_nil_module_start(async_client_conn_t client_connection)
     89{
    7190        ERROR_DECLARE;
    72 
     91       
    7392        ERROR_PROPAGATE(netif_init_module(client_connection));
    74         if(ERROR_OCCURRED(nil_initialize(netif_globals.net_phone))){
     93        if (ERROR_OCCURRED(nil_initialize(netif_globals.net_phone))) {
    7594                pm_destroy();
    7695                return ERROR_CODE;
    7796        }
    78         return netif_run_module();
     97       
     98        async_manager();
     99       
     100        pm_destroy();
     101        return EOK;
    79102}
    80103
  • uspace/lib/net/netif/netif_remote.c

    r38aaacc2 rf4f866c  
    2828
    2929/** @addtogroup netif
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Network interface module interface implementation for standalone remote modules.
    35  *  @see netif_interface.h
     34 * Network interface module interface implementation for remote modules.
    3635 */
    3736
     
    4342#include <packet/packet_client.h>
    4443#include <net_device.h>
    45 #include <netif_interface.h>
     44#include <netif_remote.h>
    4645#include <netif_messages.h>
    4746
    48 int netif_get_addr_req(int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data){
    49         return generic_get_addr_req(netif_phone, NET_NETIF_GET_ADDR, device_id, address, data);
     47int netif_get_addr_req_remote(int netif_phone, device_id_t device_id,
     48    measured_string_ref *address, char **data)
     49{
     50        return generic_get_addr_req(netif_phone, NET_NETIF_GET_ADDR, device_id,
     51            address, data);
    5052}
    5153
    52 int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io){
     54int netif_probe_req_remote(int netif_phone, device_id_t device_id, int irq, int io)
     55{
    5356        return async_req_3_0(netif_phone, NET_NETIF_PROBE, device_id, irq, io);
    5457}
    5558
    56 int netif_send_msg(int netif_phone, device_id_t device_id, packet_t packet, services_t sender){
    57         return generic_send_msg(netif_phone, NET_NETIF_SEND, device_id, packet_get_id(packet), sender, 0);
     59int netif_send_msg_remote(int netif_phone, device_id_t device_id, packet_t packet,
     60    services_t sender)
     61{
     62        return generic_send_msg_remote(netif_phone, NET_NETIF_SEND, device_id,
     63            packet_get_id(packet), sender, 0);
    5864}
    5965
    60 int netif_start_req(int netif_phone, device_id_t device_id){
     66int netif_start_req_remote(int netif_phone, device_id_t device_id)
     67{
    6168        return async_req_1_0(netif_phone, NET_NETIF_START, device_id);
    6269}
    6370
    64 int netif_stop_req(int netif_phone, device_id_t device_id){
     71int netif_stop_req_remote(int netif_phone, device_id_t device_id)
     72{
    6573        return async_req_1_0(netif_phone, NET_NETIF_STOP, device_id);
    6674}
    6775
    68 int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats){
    69         aid_t message_id;
     76int netif_stats_req_remote(int netif_phone, device_id_t device_id,
     77    device_stats_ref stats)
     78{
     79        if (!stats)
     80                return EBADMEM;
     81       
     82        aid_t message_id = async_send_1(netif_phone, NET_NETIF_STATS,
     83            (ipcarg_t) device_id, NULL);
     84        async_data_read_start(netif_phone, stats, sizeof(*stats));
     85       
    7086        ipcarg_t result;
    71 
    72         if(! stats){
    73                 return EBADMEM;
    74         }
    75         message_id = async_send_1(netif_phone, NET_NETIF_STATS, (ipcarg_t) device_id, NULL);
    76         async_data_read_start(netif_phone, stats, sizeof(*stats));
    7787        async_wait_for(message_id, &result);
     88       
    7889        return (int) result;
    7990}
    8091
    81 int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver){
     92int netif_bind_service_remote(services_t service, device_id_t device_id, services_t me,
     93    async_client_conn_t receiver)
     94{
    8295        return bind_service(service, device_id, me, 0, receiver);
    8396}
  • uspace/lib/net/nil/nil_remote.c

    r38aaacc2 rf4f866c  
    2828
    2929/** @addtogroup net_nil
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Network interface layer interface implementation for standalone remote modules.
    35  *  @see nil_interface.h
     34 * Network interface layer interface implementation for remote modules.
     35 * @see nil_interface.h
    3636 */
    3737
     
    4242#include <packet/packet_client.h>
    4343#include <nil_messages.h>
     44#include <nil_remote.h>
    4445
    45 int nil_device_state_msg(int nil_phone, device_id_t device_id, int state){
    46         return generic_device_state_msg(nil_phone, NET_NIL_DEVICE_STATE, device_id, state, 0);
     46/** Notify the network interface layer about the device state change.
     47 *
     48 * @param[in] nil_phone The network interface layer phone.
     49 * @param[in] device_id The device identifier.
     50 * @param[in] state     The new device state.
     51 *
     52 * @return EOK on success.
     53 * @return Other error codes as defined for each specific module device
     54 *         state function.
     55 *
     56 */
     57int nil_device_state_msg_remote(int nil_phone, device_id_t device_id, int state)
     58{
     59        return generic_device_state_msg_remote(nil_phone, NET_NIL_DEVICE_STATE,
     60            device_id, state, 0);
    4761}
    4862
    49 int nil_received_msg(int nil_phone, device_id_t device_id, packet_t packet, services_t target){
    50         return generic_received_msg(nil_phone, NET_NIL_RECEIVED, device_id, packet_get_id(packet), target, 0);
     63/** Pass the packet queue to the network interface layer.
     64 *
     65 * Process and redistribute the received packet queue to the registered
     66 * upper layers.
     67 *
     68 * @param[in] nil_phone The network interface layer phone.
     69 * @param[in] device_id The source device identifier.
     70 * @param[in] packet    The received packet or the received packet queue.
     71 * @param     target    The target service. Ignored parameter.
     72 *
     73 * @return EOK on success.
     74 * @return Other error codes as defined for each specific module
     75 *         received function.
     76 *
     77 */
     78int nil_received_msg_remote(int nil_phone, device_id_t device_id,
     79    packet_t packet, services_t target)
     80{
     81        return generic_received_msg_remote(nil_phone, NET_NIL_RECEIVED, device_id,
     82            packet_get_id(packet), target, 0);
    5183}
    5284
  • uspace/lib/net/tl/icmp_remote.c

    r38aaacc2 rf4f866c  
    3232
    3333/** @file
    34  *  ICMP interface implementation for standalone remote modules.
     34 *  ICMP interface implementation for remote modules.
    3535 *  @see icmp_interface.h
    3636 */
  • uspace/lib/net/tl/tl_common.c

    r38aaacc2 rf4f866c  
    4242#include <packet/packet.h>
    4343#include <packet/packet_client.h>
     44#include <packet_remote.h>
    4445#include <net_device.h>
    4546#include <icmp_interface.h>
     
    4748#include <in6.h>
    4849#include <inet.h>
    49 #include <ip_interface.h>
     50#include <ip_local.h>
     51#include <ip_remote.h>
    5052#include <socket_codes.h>
    5153#include <socket_errno.h>
     54#include <ip_interface.h>
     55#include <tl_interface.h>
    5256#include <tl_common.h>
    5357
     
    8286}
    8387
    84 int tl_get_ip_packet_dimension(int ip_phone, packet_dimensions_ref packet_dimensions, device_id_t device_id, packet_dimension_ref * packet_dimension){
     88/** Get IP packet dimensions.
     89 *
     90 * Try to search a cache and query the IP module if not found.
     91 * The reply is cached then.
     92 *
     93 * @param[in]  ip_phone          The IP moduel phone for (semi)remote calls.
     94 * @param[in]  packet_dimensions The packet dimensions cache.
     95 * @param[in]  device_id         The device identifier.
     96 * @param[out] packet_dimension  The IP packet dimensions.
     97 *
     98 * @return EOK on success.
     99 * @return EBADMEM if the packet_dimension parameter is NULL.
     100 * @return ENOMEM if there is not enough memory left.
     101 * @return EINVAL if the packet_dimensions cache is not valid.
     102 * @return Other codes as defined for the ip_packet_size_req() function.
     103 *
     104 */
     105int tl_get_ip_packet_dimension(int ip_phone,
     106    packet_dimensions_ref packet_dimensions, device_id_t device_id,
     107    packet_dimension_ref *packet_dimension)
     108{
    85109        ERROR_DECLARE;
    86 
    87         if(! packet_dimension){
     110       
     111        if (!packet_dimension)
    88112                return EBADMEM;
    89         }
    90 
     113       
    91114        *packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
    92         if(! * packet_dimension){
    93                 // ask for and remember them if not found
    94                 *packet_dimension = malloc(sizeof(** packet_dimension));
    95                 if(! * packet_dimension){
     115        if (!*packet_dimension) {
     116                /* Ask for and remember them if not found */
     117                *packet_dimension = malloc(sizeof(**packet_dimension));
     118                if(!*packet_dimension)
    96119                        return ENOMEM;
    97                 }
    98                 if(ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id, * packet_dimension))){
     120               
     121                if (ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id,
     122                    *packet_dimension))) {
    99123                        free(*packet_dimension);
    100124                        return ERROR_CODE;
    101125                }
    102                 ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id, * packet_dimension);
    103                 if(ERROR_CODE < 0){
     126               
     127                ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id,
     128                    *packet_dimension);
     129                if (ERROR_CODE < 0) {
    104130                        free(*packet_dimension);
    105131                        return ERROR_CODE;
    106132                }
    107133        }
     134       
    108135        return EOK;
    109136}
     
    169196        // detach the first packet and release the others
    170197        next = pq_detach(packet);
    171         if(next){
    172                 pq_release(packet_phone, packet_get_id(next));
    173         }
     198        if (next)
     199                pq_release_remote(packet_phone, packet_get_id(next));
     200       
    174201        length = packet_get_addr(packet, &src, NULL);
    175202        if((length > 0)
     
    180207                return EOK;
    181208        }else{
    182                 pq_release(packet_phone, packet_get_id(packet));
     209                pq_release_remote(packet_phone, packet_get_id(packet));
    183210        }
    184211        return ENOENT;
     
    200227        }
    201228        // get a new packet
    202         *packet = packet_get_4(packet_phone, length, dimension->addr_len, prefix + dimension->prefix, dimension->suffix);
     229        *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len, prefix + dimension->prefix, dimension->suffix);
    203230        if(! packet){
    204231                return ENOMEM;
     
    207234        data = packet_suffix(*packet, length);
    208235        if(! data){
    209                 pq_release(packet_phone, packet_get_id(*packet));
     236                pq_release_remote(packet_phone, packet_get_id(*packet));
    210237                return ENOMEM;
    211238        }
     
    214241        // set the packet destination address
    215242                || ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen))){
    216                 pq_release(packet_phone, packet_get_id(*packet));
     243                pq_release_remote(packet_phone, packet_get_id(*packet));
    217244                return ERROR_CODE;
    218245        }
  • uspace/lib/socket/Makefile

    r38aaacc2 rf4f866c  
    3535        generic/socket_client.c \
    3636        generic/socket_core.c \
     37        generic/socket_parse.c \
    3738        generic/inet.c \
    3839        generic/net_modules.c \
  • uspace/lib/socket/generic/net_modules.c

    r38aaacc2 rf4f866c  
    7777}
    7878
    79 int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver){
     79/** Create bidirectional connection with the needed module service and registers the message receiver.
     80 *
     81 * @param[in] need            The needed module service.
     82 * @param[in] arg1            The first parameter.
     83 * @param[in] arg2            The second parameter.
     84 * @param[in] arg3            The third parameter.
     85 * @param[in] client_receiver The message receiver.
     86 *
     87 * @return The phone of the needed service.
     88 * @return Other error codes as defined for the ipc_connect_to_me() function.
     89 *
     90 */
     91int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3,
     92    async_client_conn_t client_receiver)
     93{
    8094        return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0);
    8195}
    8296
    83 int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout){
     97/** Create bidirectional connection with the needed module service and registers the message receiver.
     98 *
     99 * @param[in] need            The needed module service.
     100 * @param[in] arg1            The first parameter.
     101 * @param[in] arg2            The second parameter.
     102 * @param[in] arg3            The third parameter.
     103 * @param[in] client_receiver The message receiver.
     104 * @param[in] timeout         The connection timeout in microseconds.
     105 *                            No timeout if set to zero (0).
     106 *
     107 * @return The phone of the needed service.
     108 * @return ETIMEOUT if the connection timeouted.
     109 * @return Other error codes as defined for the ipc_connect_to_me() function.
     110 *
     111 */
     112int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2,
     113    ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
     114{
    84115        ERROR_DECLARE;
    85 
    86         int phone;
    87         ipcarg_t phonehash;
    88 
    89         // connect to the needed service
    90         phone = connect_to_service_timeout(need, timeout);
    91         // if connected
    92         if(phone >= 0){
    93                 // request the bidirectional connection
    94                 if(ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash))){
     116       
     117        /* Connect to the needed service */
     118        int phone = connect_to_service_timeout(need, timeout);
     119        if (phone >= 0) {
     120                /* Request the bidirectional connection */
     121                ipcarg_t phonehash;
     122                if (ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3,
     123                    &phonehash))) {
    95124                        ipc_hangup(phone);
    96125                        return ERROR_CODE;
     
    98127                async_new_connection(phonehash, 0, NULL, client_receiver);
    99128        }
     129       
    100130        return phone;
    101131}
  • uspace/lib/socket/generic/socket_client.c

    r38aaacc2 rf4f866c  
    299299static int socket_generate_new_id(void){
    300300        sockets_ref sockets;
    301         int socket_id;
     301        int socket_id = 0;
    302302        int count;
    303303
  • uspace/lib/socket/generic/socket_core.c

    r38aaacc2 rf4f866c  
    9090        // release all received packets
    9191        while((packet_id = dyn_fifo_pop(&socket->received)) >= 0){
    92                 pq_release(packet_phone, packet_id);
     92                pq_release_local(packet_phone, packet_id);
    9393        }
    9494        dyn_fifo_destroy(&socket->received);
  • uspace/lib/socket/include/net_err.h

    r38aaacc2 rf4f866c  
    2828
    2929/** @addtogroup net
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Common error processing codes and routines.
     34 * Common error processing codes and routines.
    3535 */
    3636
     
    4141
    4242#ifdef CONFIG_DEBUG
     43        #include <stdio.h>
     44        #include <str_error.h>
     45#endif
    4346
    44 #include <stdio.h>
     47/** An actual stored error code.
     48 *
     49 */
     50#define ERROR_CODE  error_check_return_value
     51
     52/** An error processing routines declaration.
     53 *
     54 * This has to be declared in the block where the error processing
     55 * is desired.
     56 *
     57 */
     58#define ERROR_DECLARE  int ERROR_CODE
     59
     60/** Store the value as an error code and checks if an error occurred.
     61 *
     62 * @param[in] value The value to be checked. May be a function call.
     63 * @return False if the value indicates success (EOK).
     64 * @return True otherwise.
     65 *
     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)
    4580
    4681#endif
    4782
    48 /** An actual stored error code.
    49  */
    50 #define ERROR_CODE                                      error_check_return_value
    51 
    52 /** An error processing routines declaration.
    53  *  This has to be declared in the block where the error processing is desired.
    54  */
    55 #define ERROR_DECLARE                           int ERROR_CODE
    56 
    57 /** Stores the value as an error code and checks if an error occurred.
    58  *  @param[in] value The value to be checked. May be a function call.
    59  *  @returns FALSE if the value indicates success (EOK).
    60  *  @returns TRUE otherwise.
    61  */
    62 #ifdef CONFIG_DEBUG
    63 
    64 #define ERROR_OCCURRED(value)                                                                                           \
    65         (((ERROR_CODE = (value)) != EOK)                                                                                \
    66         && ({printf("error at %s:%d %d\n", __FILE__, __LINE__, ERROR_CODE); 1;}))
    67 
    68 #else
    69 
    70 #define ERROR_OCCURRED(value)           ((ERROR_CODE = (value)) != EOK)
    71 
    72 #endif
    73 
    74 /** Checks if an error occurred and immediately exits the actual function returning the error code.
    75  *  @param[in] value The value to be checked. May be a function call.
     83/** Error propagation
     84 *
     85 * Check if an error occurred and immediately exit the actual
     86 * function returning the error code.
     87 *
     88 * @param[in] value The value to be checked. May be a function call.
     89 *
    7690 */
    7791
    78 #define ERROR_PROPAGATE(value)  if(ERROR_OCCURRED(value)) return ERROR_CODE
     92#define ERROR_PROPAGATE(value) \
     93        if (ERROR_OCCURRED(value)) \
     94                return ERROR_CODE
    7995
    8096#endif
  • uspace/lib/socket/include/net_messages.h

    r38aaacc2 rf4f866c  
    462462/*@}*/
    463463
    464 /** Notifies the module about the device state change.
    465  *  @param[in] phone The service module phone.
    466  *  @param[in] message The service specific message.
    467  *  @param[in] device_id The device identifier.
    468  *  @param[in] state The new device state.
    469  *  @param[in] target The target module service.
    470  *  @returns EOK on success.
    471  */
    472 static inline int generic_device_state_msg(int phone, int message, device_id_t device_id, int state, services_t target){
    473         async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) state, target);
     464/** Notify the module about the device state change.
     465 *
     466 * @param[in] phone     The service module phone.
     467 * @param[in] message   The service specific message.
     468 * @param[in] device_id The device identifier.
     469 * @param[in] state     The new device state.
     470 * @param[in] target    The target module service.
     471 *
     472 * @return EOK on success.
     473 *
     474 */
     475static inline int generic_device_state_msg_remote(int phone, int message,
     476    device_id_t device_id, int state, services_t target)
     477{
     478        async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     479            (ipcarg_t) state, target);
     480       
    474481        return EOK;
    475482}
    476483
    477 /** Notifies a module about the device.
    478  *  @param[in] phone The service module phone.
    479  *  @param[in] message The service specific message.
    480  *  @param[in] device_id The device identifier.
    481  *  @param[in] arg2 The second argument of the message.
    482  *  @param[in] service The device module service.
    483  *  @returns EOK on success.
    484  *  @returns Other error codes as defined for the specific service message.
    485  */
    486 static inline int generic_device_req(int phone, int message, device_id_t device_id, int arg2, services_t service){
    487         return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) arg2, (ipcarg_t) service);
     484/** Notify a module about the device.
     485 *
     486 * @param[in] phone     The service module phone.
     487 * @param[in] message   The service specific message.
     488 * @param[in] device_id The device identifier.
     489 * @param[in] arg2      The second argument of the message.
     490 * @param[in] service   The device module service.
     491 *
     492 * @return EOK on success.
     493 * @return Other error codes as defined for the specific service message.
     494 *
     495 */
     496static inline int generic_device_req_remote(int phone, int message,
     497    device_id_t device_id, int arg2, services_t service)
     498{
     499        return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     500            (ipcarg_t) arg2, (ipcarg_t) service);
    488501}
    489502
     
    521534}
    522535
    523 /** Returns the device packet dimension for sending.
    524  *  @param[in] phone The service module phone.
    525  *  @param[in] message The service specific message.
    526  *  @param[in] device_id The device identifier.
    527  *  @param[out] packet_dimension The packet dimension.
    528  *  @returns EOK on success.
    529  *  @returns EBADMEM if the packet_dimension parameter is NULL.
    530  *  @returns Other error codes as defined for the specific service message.
    531  */
    532 static inline int generic_packet_size_req(int phone, int message, device_id_t device_id, packet_dimension_ref packet_dimension){
    533         ipcarg_t result;
     536/** Return the device packet dimension for sending.
     537 *
     538 * @param[in]  phone            The service module phone.
     539 * @param[in]  message          The service specific message.
     540 * @param[in]  device_id        The device identifier.
     541 * @param[out] packet_dimension The packet dimension.
     542 *
     543 * @return EOK on success.
     544 * @return EBADMEM if the packet_dimension parameter is NULL.
     545 * @return Other error codes as defined for the specific service message.
     546 *
     547 */
     548static inline int generic_packet_size_req_remote(int phone, int message,
     549    device_id_t device_id, packet_dimension_ref packet_dimension)
     550{
     551        if (!packet_dimension)
     552                return EBADMEM;
     553       
     554        ipcarg_t addr_len;
    534555        ipcarg_t prefix;
    535556        ipcarg_t content;
    536557        ipcarg_t suffix;
    537         ipcarg_t addr_len;
    538 
    539         if(! packet_dimension){
    540                 return EBADMEM;
    541         }
    542         result = async_req_1_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix);
     558       
     559        ipcarg_t result = async_req_1_4(phone, (ipcarg_t) message,
     560            (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix);
     561       
    543562        packet_dimension->prefix = (size_t) prefix;
    544563        packet_dimension->content = (size_t) content;
    545564        packet_dimension->suffix = (size_t) suffix;
    546565        packet_dimension->addr_len = (size_t) addr_len;
     566       
    547567        return (int) result;
    548568}
    549569
    550 /** Passes the packet queue to the module.
    551  *  @param[in] phone The service module phone.
    552  *  @param[in] message The service specific message.
    553  *  @param[in] device_id The device identifier.
    554  *  @param[in] packet_id The received packet or the received packet queue identifier.
    555  *  @param[in] target The target module service.
    556  *  @param[in] error The error module service.
    557  *  @returns EOK on success.
    558  */
    559 static inline int generic_received_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t target, services_t error){
    560         if(error){
    561                 async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) target, (ipcarg_t) error);
    562         }else{
    563                 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) target);
    564         }
     570/** Pass the packet queue to the module.
     571 *
     572 * @param[in] phone     The service module phone.
     573 * @param[in] message   The service specific message.
     574 * @param[in] device_id The device identifier.
     575 * @param[in] packet_id The received packet or the received packet queue
     576 *                      identifier.
     577 * @param[in] target    The target module service.
     578 * @param[in] error     The error module service.
     579 *
     580 * @return EOK on success.
     581 *
     582 */
     583static inline int generic_received_msg_remote(int phone, int message,
     584    device_id_t device_id, packet_id_t packet_id, services_t target,
     585    services_t error)
     586{
     587        if (error)
     588                async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     589                    (ipcarg_t) packet_id, (ipcarg_t) target, (ipcarg_t) error);
     590        else
     591                async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     592                    (ipcarg_t) packet_id, (ipcarg_t) target);
     593       
    565594        return EOK;
    566595}
    567596
    568 /** Sends the packet queue.
    569  *  @param[in] phone The service module phone.
    570  *  @param[in] message The service specific message.
    571  *  @param[in] device_id The device identifier.
    572  *  @param[in] packet_id The packet or the packet queue identifier.
    573  *  @param[in] sender The sending module service.
    574  *  @param[in] error The error module service.
    575  *  @returns EOK on success.
    576  */
    577 static inline int generic_send_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t sender, services_t error){
    578         if(error){
    579                 async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error);
    580         }else{
    581                 async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender);
    582         }
     597/** Send the packet queue.
     598 *
     599 * @param[in] phone     The service module phone.
     600 * @param[in] message   The service specific message.
     601 * @param[in] device_id The device identifier.
     602 * @param[in] packet_id The packet or the packet queue identifier.
     603 * @param[in] sender    The sending module service.
     604 * @param[in] error     The error module service.
     605 *
     606 * @return EOK on success.
     607 *
     608 */
     609static inline int generic_send_msg_remote(int phone, int message,
     610    device_id_t device_id, packet_id_t packet_id, services_t sender,
     611    services_t error)
     612{
     613        if (error)
     614                async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     615                    (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error);
     616        else
     617                async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
     618                    (ipcarg_t) packet_id, (ipcarg_t) sender);
     619       
    583620        return EOK;
    584621}
  • uspace/lib/socket/include/net_modules.h

    r38aaacc2 rf4f866c  
    7272extern void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count);
    7373
    74 /** Creates bidirectional connection with the needed module service and registers the message receiver.
    75  *  @param[in] need The needed module service.
    76  *  @param[in] arg1 The first parameter.
    77  *  @param[in] arg2 The second parameter.
    78  *  @param[in] arg3 The third parameter.
    79  *  @param[in] client_receiver The message receiver.
    80  *  @returns The phone of the needed service.
    81  *  @returns Other error codes as defined for the ipc_connect_to_me() function.
    82  */
    83 extern int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver);
    84 
    85 /** Creates bidirectional connection with the needed module service and registers the message receiver.
    86  *  @param[in] need The needed module service.
    87  *  @param[in] arg1 The first parameter.
    88  *  @param[in] arg2 The second parameter.
    89  *  @param[in] arg3 The third parameter.
    90  *  @param[in] client_receiver The message receiver.
    91  *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
    92  *  @returns The phone of the needed service.
    93  *  @returns ETIMEOUT if the connection timeouted.
    94  *  @returns Other error codes as defined for the ipc_connect_to_me() function.
    95  */
    96 extern int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout);
     74extern int bind_service(services_t, ipcarg_t, ipcarg_t, ipcarg_t,
     75    async_client_conn_t);
     76extern int bind_service_timeout(services_t, ipcarg_t, ipcarg_t, ipcarg_t,
     77    async_client_conn_t, suseconds_t);
    9778
    9879/** Connects to the needed module.
  • uspace/lib/socket/include/packet/packet_client.h

    r38aaacc2 rf4f866c  
    4545#define __NET_PACKET_CLIENT_H__
    4646
    47 #include "packet.h"
     47#include <packet/packet.h>
    4848
    4949/** @name Packet client interface
     
    172172 *  @returns Other error codes as defined for the packet_return() function.
    173173 */
    174 extern int packet_translate(int phone, packet_ref packet, packet_id_t packet_id);
     174extern int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id);
    175175
    176176/** Obtains the packet of the given dimensions.
     
    184184 *  @returns NULL on error.
    185185 */
    186 extern packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix);
     186extern packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix);
    187187
    188188/** Obtains the packet of the given content size.
     
    193193 *  @returns NULL on error.
    194194 */
    195 extern packet_t packet_get_1(int phone, size_t content);
     195extern packet_t packet_get_1_local(int phone, size_t content);
    196196
    197197/** Releases the packet queue.
     
    202202 *  @param[in] packet_id The packet identifier.
    203203 */
    204 extern void pq_release(int phone, packet_id_t packet_id);
     204extern void pq_release_local(int phone, packet_id_t packet_id);
    205205
    206206/** Returns the packet copy.
  • uspace/lib/socket/packet/packet_client.c

    r38aaacc2 rf4f866c  
    156156packet_t packet_get_copy(int phone, packet_t packet){
    157157        packet_t copy;
    158         uint8_t * src;
    159         uint8_t * dest;
     158        uint8_t * src = NULL;
     159        uint8_t * dest = NULL;
    160160        size_t addrlen;
    161161
     
    164164        }
    165165        // get a new packet
    166         copy = packet_get_4(phone, PACKET_DATA_LENGTH(packet), PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, PACKET_MIN_SUFFIX(packet));
     166        copy = packet_get_4_local(phone, PACKET_DATA_LENGTH(packet), PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix, PACKET_MIN_SUFFIX(packet));
    167167        if(! copy){
    168168                return NULL;
     
    178178                return copy;
    179179        }else{
    180                 pq_release(phone, copy->packet_id);
     180                pq_release_local(phone, copy->packet_id);
    181181                return NULL;
    182182        }
  • uspace/lib/socket/packet/packet_server.c

    r38aaacc2 rf4f866c  
    9797};
    9898
    99 int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){
    100         if(! packet){
     99int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id)
     100{
     101        if (!packet)
    101102                return EINVAL;
    102         }
     103       
    103104        *packet = pm_find(packet_id);
    104105        return (*packet) ? EOK : ENOENT;
     
    161162}
    162163
    163 /** Returns the packet of dimensions at least as given.
    164  *  Tries to reuse free packets first.
    165  *  Creates a&nbsp;new packet aligned to the memory page size if none available.
    166  *  Locks the global data during its processing.
    167  *  @param[in] addr_len The source and destination addresses maximal length in bytes.
    168  *  @param[in] max_prefix The maximal prefix length in bytes.
    169  *  @param[in] max_content The maximal content length in bytes.
    170  *  @param[in] max_suffix The maximal suffix length in bytes.
    171  *  @returns The packet of dimensions at least as given.
    172  *  @returns NULL if there is not enough memory left.
    173  */
    174 static packet_t packet_get(size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix){
    175         int index;
     164/** Return the packet of dimensions at least as given.
     165 *
     166 * Try to reuse free packets first.
     167 * Create a new packet aligned to the memory page size if none available.
     168 * Lock the global data during its processing.
     169 *
     170 * @param[in] addr_len    The source and destination addresses
     171 *                        maximal length in bytes.
     172 * @param[in] max_prefix  The maximal prefix length in bytes.
     173 * @param[in] max_content The maximal content length in bytes.
     174 * @param[in] max_suffix  The maximal suffix length in bytes.
     175 *
     176 * @return The packet of dimensions at least as given.
     177 * @return NULL if there is not enough memory left.
     178 *
     179 */
     180static packet_t packet_get_local(size_t addr_len, size_t max_prefix,
     181    size_t max_content, size_t max_suffix)
     182{
     183        size_t length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix
     184            + max_content + max_suffix, PAGE_SIZE);
     185       
     186        fibril_mutex_lock(&ps_globals.lock);
     187       
    176188        packet_t packet;
    177         size_t length;
    178 
    179         length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE);
    180         fibril_mutex_lock(&ps_globals.lock);
    181         for(index = 0; index < FREE_QUEUES_COUNT - 1; ++ index){
    182                 if(length <= ps_globals.sizes[index]){
     189        unsigned int index;
     190       
     191        for (index = 0; index < FREE_QUEUES_COUNT - 1; index++) {
     192                if (length <= ps_globals.sizes[index]) {
    183193                        packet = ps_globals.free[index];
    184                         while(packet_is_valid(packet) && (packet->length < length)){
     194                       
     195                        while (packet_is_valid(packet) && (packet->length < length))
    185196                                packet = pm_find(packet->next);
    186                         }
    187                         if(packet_is_valid(packet)){
    188                                 if(packet == ps_globals.free[index]){
     197                       
     198                        if (packet_is_valid(packet)) {
     199                                if (packet == ps_globals.free[index])
    189200                                        ps_globals.free[index] = pq_detach(packet);
    190                                 }else{
     201                                else
    191202                                        pq_detach(packet);
    192                                 }
    193                                 packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
     203                               
     204                                packet_init(packet, addr_len, max_prefix, max_content,
     205                                    max_suffix);
    194206                                fibril_mutex_unlock(&ps_globals.lock);
    195                                 // remove debug dump
    196 //                              printf("packet %d got\n", packet->packet_id);
     207                               
    197208                                return packet;
    198209                        }
    199210                }
    200211        }
    201         packet = packet_create(length, addr_len, max_prefix, max_content, max_suffix);
     212       
     213        packet = packet_create(length, addr_len, max_prefix, max_content,
     214            max_suffix);
     215       
    202216        fibril_mutex_unlock(&ps_globals.lock);
    203         // remove debug dump
    204 //      printf("packet %d created\n", packet->packet_id);
     217       
    205218        return packet;
    206219}
    207220
    208 packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix){
    209         return packet_get(addr_len, max_prefix, max_content, max_suffix);
    210 }
    211 
    212 packet_t packet_get_1(int phone, size_t content){
    213         return packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content, DEFAULT_SUFFIX);
    214 }
    215 
    216 /** Releases the packet and returns it to the appropriate free packet queue.
     221packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len,
     222    size_t max_prefix, size_t max_suffix)
     223{
     224        return packet_get_local(addr_len, max_prefix, max_content, max_suffix);
     225}
     226
     227packet_t packet_get_1_local(int phone, size_t content)
     228{
     229        return packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content,
     230            DEFAULT_SUFFIX);
     231}
     232
     233/** Release the packet and returns it to the appropriate free packet queue.
     234 *
    217235 *  Should be used only when the global data are locked.
     236 *
    218237 *  @param[in] packet The packet to be released.
     238 *
    219239 */
    220240static void packet_release(packet_t packet){
     
    247267}
    248268
    249 void pq_release(int phone, packet_id_t packet_id){
     269void pq_release_local(int phone, packet_id_t packet_id)
     270{
    250271        (void) packet_release_wrapper(packet_id);
    251272}
     
    281302                        return EOK;
    282303                case NET_PACKET_CREATE_1:
    283                         packet = packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);
     304                        packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);
    284305                        if(! packet){
    285306                                return ENOMEM;
     
    290311                        return EOK;
    291312                case NET_PACKET_CREATE_4:
    292                         packet = packet_get(((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call));
     313                        packet = packet_get_local(((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call));
    293314                        if(! packet){
    294315                                return ENOMEM;
Note: See TracChangeset for help on using the changeset viewer.