Changeset f4f866c in mainline for uspace/lib
- Timestamp:
- 2010-04-23T21:42:26Z (16 years ago)
- 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. - Location:
- uspace/lib
- Files:
-
- 14 added
- 4 deleted
- 73 edited
- 7 moved
-
c/Makefile (modified) (5 diffs)
-
c/arch/abs32le/include/types.h (modified) (1 diff)
-
c/arch/amd64/include/types.h (modified) (1 diff)
-
c/arch/arm32/include/types.h (modified) (2 diffs)
-
c/arch/ia32/include/types.h (modified) (1 diff)
-
c/arch/ia64/include/types.h (modified) (2 diffs)
-
c/arch/ia64/src/ddi.c (modified) (1 diff)
-
c/arch/mips32/include/types.h (modified) (1 diff)
-
c/arch/ppc32/include/types.h (modified) (1 diff)
-
c/arch/sparc64/include/types.h (modified) (1 diff)
-
c/generic/adt/hash_table.c (modified) (11 diffs)
-
c/generic/arg_parse.c (added)
-
c/generic/async.c (modified) (1 diff)
-
c/generic/fibril.c (modified) (7 diffs)
-
c/generic/futex.c (modified) (7 diffs)
-
c/generic/io/asprintf.c (modified) (1 diff)
-
c/generic/io/console.c (modified) (3 diffs)
-
c/generic/io/printf_core.c (modified) (3 diffs)
-
c/generic/io/screenbuffer.c (moved) (moved from uspace/srv/hid/console/screenbuffer.c ) (6 diffs)
-
c/generic/io/vprintf.c (modified) (1 diff)
-
c/generic/libc.c (modified) (3 diffs)
-
c/generic/malloc.c (modified) (19 diffs)
-
c/generic/stats.c (added)
-
c/generic/str.c (modified) (5 diffs)
-
c/generic/str_error.c (added)
-
c/generic/sysinfo.c (modified) (1 diff)
-
c/generic/task.c (modified) (3 diffs)
-
c/include/arg_parse.h (added)
-
c/include/bool.h (modified) (1 diff)
-
c/include/errno.h (modified) (1 diff)
-
c/include/futex.h (modified) (1 diff)
-
c/include/io/color.h (modified) (2 diffs)
-
c/include/io/console.h (modified) (2 diffs)
-
c/include/io/keycode.h (modified) (2 diffs)
-
c/include/io/klog.h (modified) (1 diff)
-
c/include/io/printf_core.h (modified) (2 diffs)
-
c/include/io/screenbuffer.h (moved) (moved from uspace/srv/hid/console/screenbuffer.h ) (6 diffs)
-
c/include/io/style.h (modified) (1 diff)
-
c/include/stats.h (added)
-
c/include/str.h (modified) (1 diff)
-
c/include/str_error.h (added)
-
c/include/sysinfo.h (modified) (2 diffs)
-
c/include/task.h (modified) (1 diff)
-
clui/Makefile (modified) (1 diff)
-
clui/tinput.c (modified) (33 diffs)
-
clui/tinput.h (modified) (5 diffs)
-
net/Makefile (modified) (1 diff)
-
net/adt/module_map.c (modified) (1 diff)
-
net/generic/net_remote.c (modified) (1 diff)
-
net/generic/packet_remote.c (modified) (2 diffs)
-
net/il/arp_remote.c (modified) (1 diff)
-
net/il/ip_client.c (modified) (3 diffs)
-
net/il/ip_remote.c (modified) (2 diffs)
-
net/include/arp_interface.h (modified) (1 diff)
-
net/include/icmp_interface.h (modified) (1 diff)
-
net/include/il_interface.h (modified) (2 diffs)
-
net/include/il_local.h (moved) (moved from uspace/lib/net/include/tl_standalone.h ) (1 diff)
-
net/include/il_messages.h (modified) (3 diffs)
-
net/include/ip_client.h (modified) (2 diffs)
-
net/include/ip_interface.h (modified) (4 diffs)
-
net/include/ip_local.h (added)
-
net/include/ip_remote.h (added)
-
net/include/net_interface.h (modified) (1 diff)
-
net/include/netif.h (deleted)
-
net/include/netif_interface.h (modified) (2 diffs)
-
net/include/netif_local.h (added)
-
net/include/netif_messages.h (modified) (2 diffs)
-
net/include/netif_module.h (deleted)
-
net/include/netif_nil_bundle.h (modified) (1 diff)
-
net/include/netif_remote.h (added)
-
net/include/nil_interface.h (modified) (2 diffs)
-
net/include/nil_local.h (moved) (moved from uspace/lib/net/include/nil_module.h ) (1 diff)
-
net/include/nil_messages.h (modified) (3 diffs)
-
net/include/nil_remote.h (moved) (moved from uspace/lib/net/include/nil_standalone.h ) (2 diffs)
-
net/include/packet_remote.h (added)
-
net/include/tl_common.h (modified) (2 diffs)
-
net/include/tl_interface.h (modified) (2 diffs)
-
net/include/tl_local.h (moved) (moved from uspace/lib/net/include/il_standalone.h ) (1 diff)
-
net/netif/netif.c (deleted)
-
net/netif/netif_local.c (added)
-
net/netif/netif_nil_bundle.c (modified) (1 diff)
-
net/netif/netif_remote.c (moved) (moved from uspace/lib/netif/generic/netif_remote.c ) (2 diffs)
-
net/netif/netif_standalone.c (deleted)
-
net/nil/nil_remote.c (modified) (2 diffs)
-
net/tl/icmp_remote.c (modified) (1 diff)
-
net/tl/tl_common.c (modified) (8 diffs)
-
socket/Makefile (modified) (1 diff)
-
socket/generic/net_modules.c (modified) (2 diffs)
-
socket/generic/socket_client.c (modified) (1 diff)
-
socket/generic/socket_core.c (modified) (1 diff)
-
socket/generic/socket_parse.c (added)
-
socket/include/net_err.h (modified) (2 diffs)
-
socket/include/net_messages.h (modified) (2 diffs)
-
socket/include/net_modules.h (modified) (1 diff)
-
socket/include/packet/packet_client.h (modified) (5 diffs)
-
socket/include/socket_parse.h (added)
-
socket/packet/packet_client.c (modified) (3 diffs)
-
socket/packet/packet_server.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
r38aaacc2 rf4f866c 35 35 INCLUDE_LIBARCH = include/libarch 36 36 37 PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) 37 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common 38 COMMON_HEADER = $(ROOT_PATH)/common.h 39 COMMON_HEADER_ARCH = arch/$(UARCH)/include/common.h 40 41 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config 42 43 PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) 38 44 EXTRA_OUTPUT = $(LINKER_SCRIPT) 39 EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $( LINKER_SCRIPT)45 EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPT) 40 46 LIBRARY = libc 41 42 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common43 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config44 47 45 48 -include $(COMMON_MAKEFILE) … … 58 61 generic/mem.c \ 59 62 generic/str.c \ 63 generic/str_error.c \ 60 64 generic/fibril.c \ 61 65 generic/fibril_synch.c \ … … 75 79 generic/io/printf_core.c \ 76 80 generic/io/console.c \ 81 generic/io/screenbuffer.c \ 77 82 generic/malloc.c \ 78 83 generic/sysinfo.c \ … … 90 95 generic/vfs/vfs.c \ 91 96 generic/vfs/canonify.c \ 92 generic/stacktrace.c 97 generic/stacktrace.c \ 98 generic/arg_parse.c \ 99 generic/stats.c 93 100 94 101 SOURCES = \ … … 111 118 $(LINKER_SCRIPT): $(LINKER_SCRIPT).in 112 119 $(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 38 38 #define __32_BITS__ 39 39 40 typedef unsigned int sysarg_t; 40 #include <libarch/common.h> 41 41 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; 42 typedef uint32_t sysarg_t; 51 43 52 44 typedef int32_t ssize_t; -
uspace/lib/c/arch/amd64/include/types.h
r38aaacc2 rf4f866c 38 38 #define __64_BITS__ 39 39 40 typedef unsigned long long sysarg_t; 40 #include <libarch/common.h> 41 41 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; 42 typedef uint64_t sysarg_t; 51 43 52 44 typedef int64_t ssize_t; -
uspace/lib/c/arch/arm32/include/types.h
r38aaacc2 rf4f866c 27 27 */ 28 28 29 /** @addtogroup libcarm32 29 /** @addtogroup libcarm32 30 30 * @{ 31 31 */ 32 /** @file 32 /** @file 33 33 * @brief Definitions of basic types like #uintptr_t. 34 34 */ … … 39 39 #define __32_BITS__ 40 40 41 typedef unsigned int sysarg_t; 41 #include <libarch/common.h> 42 42 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; 43 typedef uint32_t sysarg_t; 52 44 53 45 typedef int32_t ssize_t; -
uspace/lib/c/arch/ia32/include/types.h
r38aaacc2 rf4f866c 38 38 #define __32_BITS__ 39 39 40 typedef unsigned int sysarg_t; 40 #include <libarch/common.h> 41 41 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; 42 typedef uint32_t sysarg_t; 51 43 52 44 typedef int32_t ssize_t; -
uspace/lib/c/arch/ia64/include/types.h
r38aaacc2 rf4f866c 38 38 #define __64_BITS__ 39 39 40 typedef unsigned long sysarg_t; 40 #include <libarch/common.h> 41 41 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; 42 typedef struct { 43 uint64_t lo; 44 int64_t hi; 45 } int128_t; 51 46 52 47 typedef struct { … … 54 49 uint64_t hi; 55 50 } uint128_t; 51 52 typedef uint64_t sysarg_t; 56 53 57 54 typedef int64_t ssize_t; -
uspace/lib/c/arch/ia64/src/ddi.c
r38aaacc2 rf4f866c 2 2 #include <sysinfo.h> 3 3 4 uint64_t ia64_iospace_address=0; 5 4 uint64_t ia64_iospace_address = 0; 6 5 7 6 uint64_t get_ia64_iospace_address(void) 8 7 { 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; 12 13 } 13 14 -
uspace/lib/c/arch/mips32/include/types.h
r38aaacc2 rf4f866c 39 39 #define __32_BITS__ 40 40 41 typedef unsigned int sysarg_t; 41 #include <libarch/common.h> 42 42 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; 43 typedef uint32_t sysarg_t; 52 44 53 45 typedef int32_t ssize_t; -
uspace/lib/c/arch/ppc32/include/types.h
r38aaacc2 rf4f866c 38 38 #define __32_BITS__ 39 39 40 typedef unsigned int sysarg_t; 40 #include <libarch/common.h> 41 41 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; 42 typedef uint32_t sysarg_t; 51 43 52 44 typedef int32_t ssize_t; -
uspace/lib/c/arch/sparc64/include/types.h
r38aaacc2 rf4f866c 38 38 #define __64_BITS__ 39 39 40 typedef unsigned long sysarg_t; 40 #include <libarch/common.h> 41 41 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; 42 typedef uint64_t sysarg_t; 51 43 52 44 typedef int64_t ssize_t; -
uspace/lib/c/generic/adt/hash_table.c
r38aaacc2 rf4f866c 42 42 #include <malloc.h> 43 43 #include <assert.h> 44 #include <stdio.h>45 44 #include <str.h> 46 45 47 46 /** Create chained hash table. 48 47 * 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 * 54 55 */ 55 56 int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys, 56 57 hash_table_operations_t *op) 57 58 { 58 hash_count_t i;59 60 59 assert(h); 61 60 assert(op && op->hash && op->compare); … … 63 62 64 63 h->entry = malloc(m * sizeof(link_t)); 65 if (!h->entry) { 66 printf("cannot allocate memory for hash table\n"); 64 if (!h->entry) 67 65 return false; 68 }66 69 67 memset((void *) h->entry, 0, m * sizeof(link_t)); 70 68 69 hash_count_t i; 71 70 for (i = 0; i < m; i++) 72 71 list_initialize(&h->entry[i]); … … 75 74 h->max_keys = max_keys; 76 75 h->op = op; 76 77 77 return true; 78 78 } … … 80 80 /** Destroy a hash table instance. 81 81 * 82 * @param h Hash table to be destroyed. 82 * @param h Hash table to be destroyed. 83 * 83 84 */ 84 85 void hash_table_destroy(hash_table_t *h) … … 86 87 assert(h); 87 88 assert(h->entry); 89 88 90 free(h->entry); 89 91 } … … 91 93 /** Insert item into a hash table. 92 94 * 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. 96 98 */ 97 99 void hash_table_insert(hash_table_t *h, unsigned long key[], link_t *item) 98 100 { 99 hash_index_t chain;100 101 101 assert(item); 102 102 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); 105 105 assert(chain < h->entries); 106 106 … … 110 110 /** Search hash table for an item matching keys. 111 111 * 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 * 116 117 */ 117 118 link_t *hash_table_find(hash_table_t *h, unsigned long key[]) 118 119 { 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 119 125 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 127 126 for (cur = h->entry[chain].next; cur != &h->entry[chain]; 128 127 cur = cur->next) { … … 142 141 * For each removed item, h->remove_callback() is called. 143 142 * 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 * 148 148 */ 149 149 void hash_table_remove(hash_table_t *h, unsigned long key[], hash_count_t keys) 150 150 { 151 hash_index_t chain;152 link_t *cur;153 154 151 assert(h && h->op && h->op->hash && h->op->compare && 155 152 h->op->remove_callback); 156 153 assert(keys <= h->max_keys); 157 154 155 link_t *cur; 156 158 157 if (keys == h->max_keys) { 159 160 158 /* 161 159 * All keys are known, hash_table_find() can be used to find the 162 160 * entry. 163 161 */ 164 162 165 163 cur = hash_table_find(h, key); 166 164 if (cur) { … … 168 166 h->op->remove_callback(cur); 169 167 } 168 170 169 return; 171 170 } … … 175 174 * Any partially matching entries are to be removed. 176 175 */ 176 hash_index_t chain; 177 177 for (chain = 0; chain < h->entries; chain++) { 178 178 for (cur = h->entry[chain].next; cur != &h->entry[chain]; … … 195 195 /** Apply fucntion to all items in hash table. 196 196 * 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 */ 202 void hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg) 203 203 { 204 204 hash_index_t bucket; 205 205 link_t *cur; 206 206 207 207 for (bucket = 0; bucket < h->entries; bucket++) { 208 208 for (cur = h->entry[bucket].next; cur != &h->entry[bucket]; -
uspace/lib/c/generic/async.c
r38aaacc2 rf4f866c 746 746 if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1, 747 747 &conn_hash_table_ops)) { 748 printf("%s: cannot create hash table\n", "async");748 printf("%s: Cannot create async hash table\n", "libc"); 749 749 return ENOMEM; 750 750 } -
uspace/lib/c/generic/fibril.c
r38aaacc2 rf4f866c 48 48 49 49 #ifndef FIBRIL_INITIAL_STACK_PAGES_NO 50 #define FIBRIL_INITIAL_STACK_PAGES_NO150 #define FIBRIL_INITIAL_STACK_PAGES_NO 1 51 51 #endif 52 52 53 53 /** 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 */ 56 57 static atomic_t fibril_futex = FUTEX_INITIALIZER; 57 58 … … 60 61 static LIST_INITIALIZE(manager_list); 61 62 62 static void fibril_main(void);63 64 63 /** Number of threads that are executing a manager fibril. */ 65 64 static 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 */ 70 static int serialized_threads; 71 68 72 /** Fibril-local count of serialization. If > 0, we must not preempt */ 69 73 static 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 }105 74 106 75 /** Function that spans the whole life-cycle of a fibril. … … 109 78 * the fibril logic is called. After its return, the return value is saved. 110 79 * 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 */ 82 static void fibril_main(void) 83 { 84 fibril_t *fibril = __tcb_get()->fibril_data; 85 116 86 /* Call the implementing function. */ 117 f ->retval = f->func(f->arg);118 87 fibril->retval = fibril->func(fibril->arg); 88 119 89 fibril_switch(FIBRIL_FROM_DEAD); 120 /* not reached */ 90 /* Not reached */ 91 } 92 93 /** Setup fibril information into TCB structure 94 * 95 */ 96 fibril_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 121 void fibril_teardown(fibril_t *fibril) 122 { 123 __free_tls(fibril->tcb); 124 free(fibril); 121 125 } 122 126 … … 126 130 * held. 127 131 * 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 * 133 139 */ 134 140 int fibril_switch(fibril_switch_type_t stype) … … 246 252 /** Create a new fibril. 247 253 * 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 * 252 259 */ 253 260 fid_t fibril_create(int (*func)(void *), void *arg) 254 261 { 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) 259 266 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); 264 272 return 0; 265 273 } 266 274 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; 275 283 } 276 284 277 285 /** Add a fibril to the ready list. 278 286 * 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 * 281 290 */ 282 291 void fibril_add_ready(fid_t fid) 283 292 { 284 fibril_t *f; 285 286 f = (fibril_t *) fid; 293 fibril_t *fibril = (fibril_t *) fid; 294 287 295 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); 290 299 else 291 list_append(&f->link, &ready_list); 300 list_append(&fibril->link, &ready_list); 301 292 302 futex_up(&fibril_futex); 293 303 } … … 295 305 /** Add a fibril to the manager list. 296 306 * 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 * 299 310 */ 300 311 void fibril_add_manager(fid_t fid) 301 312 { 302 fibril_t *f; 303 304 f = (fibril_t *) fid; 305 313 fibril_t *fibril = (fibril_t *) fid; 314 306 315 futex_down(&fibril_futex); 307 list_append(&f ->link, &manager_list);316 list_append(&fibril->link, &manager_list); 308 317 futex_up(&fibril_futex); 309 318 } … … 313 322 { 314 323 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 320 328 futex_up(&fibril_futex); 321 329 } -
uspace/lib/c/generic/futex.c
r38aaacc2 rf4f866c 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 35 #include <futex.h> … … 40 40 /** Initialize futex counter. 41 41 * 42 * @param futex Futex. 43 * @param val Initialization value. 42 * @param futex Futex. 43 * @param val Initialization value. 44 * 44 45 */ 45 46 void futex_initialize(futex_t *futex, int val) … … 50 51 /** Try to down the futex. 51 52 * 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 * 55 58 */ 56 59 int futex_trydown(futex_t *futex) … … 61 64 /** Down the futex. 62 65 * 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 * 67 72 */ 68 73 int futex_down(futex_t *futex) … … 70 75 if ((atomic_signed_t) atomic_predec(futex) < 0) 71 76 return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count); 72 77 73 78 return 0; 74 79 } … … 76 81 /** Up the futex. 77 82 * 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 * 81 88 */ 82 89 int futex_up(futex_t *futex) … … 84 91 if ((atomic_signed_t) atomic_postinc(futex) < 0) 85 92 return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->count); 86 93 87 94 return 0; 88 95 } -
uspace/lib/c/generic/io/asprintf.c
r38aaacc2 rf4f866c 61 61 int asprintf(char **strp, const char *fmt, ...) 62 62 { 63 struct printf_specps = {63 printf_spec_t ps = { 64 64 asprintf_str_write, 65 65 asprintf_wstr_write, -
uspace/lib/c/generic/io/console.c
r38aaacc2 rf4f866c 45 45 } 46 46 47 int console_get_size(int phone, i nt *cols, int *rows)47 int console_get_size(int phone, ipcarg_t *cols, ipcarg_t *rows) 48 48 { 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); 58 50 } 59 51 60 void console_set_style(int phone, int style)52 void console_set_style(int phone, uint8_t style) 61 53 { 62 54 async_msg_1(phone, CONSOLE_SET_STYLE, style); 63 55 } 64 56 65 void console_set_color(int phone, int fg_color, int bg_color, int flags) 57 void console_set_color(int phone, uint8_t fg_color, uint8_t bg_color, 58 uint8_t flags) 66 59 { 67 60 async_msg_3(phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags); 68 61 } 69 62 70 void console_set_rgb_color(int phone, int fg_color, int bg_color)63 void console_set_rgb_color(int phone, uint32_t fg_color, uint32_t bg_color) 71 64 { 72 65 async_msg_2(phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color); … … 75 68 void console_cursor_visibility(int phone, bool show) 76 69 { 77 async_msg_1(phone, CONSOLE_CURSOR_VISIBILITY, show != false);70 async_msg_1(phone, CONSOLE_CURSOR_VISIBILITY, (show != false)); 78 71 } 79 72 80 int console_get_color_cap(int phone, i nt *ccap)73 int console_get_color_cap(int phone, ipcarg_t *ccap) 81 74 { 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); 89 76 } 90 77 … … 94 81 } 95 82 96 int console_get_pos(int phone, i nt *col, int *row)83 int console_get_pos(int phone, ipcarg_t *col, ipcarg_t *row) 97 84 { 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); 107 86 } 108 87 109 void console_ goto(int phone, int col, int row)88 void console_set_pos(int phone, ipcarg_t col, ipcarg_t row) 110 89 { 111 90 async_msg_2(phone, CONSOLE_GOTO, col, row); -
uspace/lib/c/generic/io/printf_core.c
r38aaacc2 rf4f866c 45 45 /** show prefixes 0x or 0 */ 46 46 #define __PRINTF_FLAG_PREFIX 0x00000001 47 47 48 /** signed / unsigned number */ 48 49 #define __PRINTF_FLAG_SIGNED 0x00000002 50 49 51 /** print leading zeroes */ 50 52 #define __PRINTF_FLAG_ZEROPADDED 0x00000004 53 51 54 /** align to left */ 52 55 #define __PRINTF_FLAG_LEFTALIGNED 0x00000010 56 53 57 /** always show + sign */ 54 58 #define __PRINTF_FLAG_SHOWPLUS 0x00000020 59 55 60 /** print space instead of plus */ 56 61 #define __PRINTF_FLAG_SPACESIGN 0x00000040 62 57 63 /** show big characters */ 58 64 #define __PRINTF_FLAG_BIGCHARS 0x00000080 65 59 66 /** number has - sign */ 60 67 #define __PRINTF_FLAG_NEGATIVE 0x00000100 … … 78 85 } qualifier_t; 79 86 80 static c har nullstr[]= "(NULL)";81 static c har digits_small[]= "0123456789abcdef";82 static c har digits_big[]= "0123456789ABCDEF";83 static c har invalch = U_SPECIAL;87 static const char *nullstr = "(NULL)"; 88 static const char *digits_small = "0123456789abcdef"; 89 static const char *digits_big = "0123456789ABCDEF"; 90 static const char invalch = U_SPECIAL; 84 91 85 92 /** Print one or more characters without adding newline. … … 350 357 uint32_t flags, printf_spec_t *ps) 351 358 { 352 c har *digits;359 const char *digits; 353 360 if (flags & __PRINTF_FLAG_BIGCHARS) 354 361 digits = digits_big; -
uspace/lib/c/generic/io/screenbuffer.c
r38aaacc2 rf4f866c 34 34 35 35 #include <io/style.h> 36 #include <io/screenbuffer.h> 36 37 #include <malloc.h> 37 38 #include <unistd.h> 38 #include "screenbuffer.h"39 39 40 40 /** Store one character to screenbuffer. … … 67 67 * 68 68 */ 69 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, size_t size_x, size_t size_y) 69 screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, ipcarg_t size_x, 70 ipcarg_t size_y) 70 71 { 71 72 scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y); … … 109 110 * 110 111 */ 111 void screenbuffer_clear_line(screenbuffer_t *scr, size_t line)112 void screenbuffer_clear_line(screenbuffer_t *scr, ipcarg_t line) 112 113 { 113 size_t x;114 ipcarg_t x; 114 115 115 116 for (x = 0; x < scr->size_x; x++) { … … 140 141 * 141 142 */ 142 void screenbuffer_goto(screenbuffer_t *scr, size_t x, size_t y)143 void screenbuffer_goto(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y) 143 144 { 144 145 scr->position_x = x % scr->size_x; … … 166 167 * 167 168 */ 168 void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, uint8_t bg_color, uint8_t flags) 169 void screenbuffer_set_color(screenbuffer_t *scr, uint8_t fg_color, 170 uint8_t bg_color, uint8_t flags) 169 171 { 170 172 scr->attrs.t = at_idx; … … 181 183 * 182 184 */ 183 void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, uint32_t bg_color) 185 void screenbuffer_set_rgb_color(screenbuffer_t *scr, uint32_t fg_color, 186 uint32_t bg_color) 184 187 { 185 188 scr->attrs.t = at_rgb; -
uspace/lib/c/generic/io/vprintf.c
r38aaacc2 rf4f866c 76 76 int vfprintf(FILE *stream, const char *fmt, va_list ap) 77 77 { 78 struct printf_specps = {78 printf_spec_t ps = { 79 79 vprintf_str_write, 80 80 vprintf_wstr_write, -
uspace/lib/c/generic/libc.c
r38aaacc2 rf4f866c 62 62 void __main(void *pcb_ptr) 63 63 { 64 int retval; 65 64 /* Initialize user task run-time environment */ 66 65 __heap_init(); 67 66 __async_init(); … … 75 74 char **argv; 76 75 76 /* Get command line arguments and initialize 77 standard input and output */ 77 78 if (__pcb == NULL) { 78 79 argc = 0; … … 86 87 } 87 88 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)); 92 92 } 93 93 94 94 void __exit(void) 95 95 { 96 __stdio_done(); 96 97 fibril_teardown(__tcb_get()->fibril_data); 97 98 _exit(0); -
uspace/lib/c/generic/malloc.c
r38aaacc2 rf4f866c 43 43 #include <bitops.h> 44 44 #include <mem.h> 45 #include <futex.h> 45 46 #include <adt/gcdlcm.h> 46 47 … … 75 76 #define NET_SIZE(size) ((size) - STRUCT_OVERHEAD) 76 77 77 78 78 /** Header of a heap block 79 79 * … … 104 104 extern char _heap; 105 105 106 /** Futex for thread-safe heap manipulation */ 107 static futex_t malloc_futex = FUTEX_INITIALIZER; 108 106 109 /** Address of heap start */ 107 110 static void *heap_start = 0; … … 119 122 * 120 123 * Fills in the structures related to a heap block. 124 * Should be called only inside the critical section. 121 125 * 122 126 * @param addr Address of the block. … … 144 148 * Verifies that the structures related to a heap block still contain 145 149 * the magic constants. This helps detect heap corruption early on. 150 * Should be called only inside the critical section. 146 151 * 147 152 * @param addr Address of the block. … … 161 166 } 162 167 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 */ 163 175 static bool grow_heap(size_t size) 164 176 { … … 189 201 } 190 202 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 */ 191 210 static void shrink_heap(void) 192 211 { … … 196 215 /** Initialize the heap allocator 197 216 * 198 * Find s how much physical memory we have and creates217 * Find how much physical memory we have and create 199 218 * the heap management structures that mark the whole 200 219 * physical memory as a single free block. … … 203 222 void __heap_init(void) 204 223 { 224 futex_down(&malloc_futex); 225 205 226 if (as_area_create((void *) &_heap, PAGE_SIZE, 206 227 AS_AREA_WRITE | AS_AREA_READ)) { … … 213 234 block_init(heap_start, heap_end - heap_start, true); 214 235 } 215 } 216 236 237 futex_up(&malloc_futex); 238 } 239 240 /** Get maximum heap address 241 * 242 */ 217 243 uintptr_t get_max_heap_addr(void) 218 244 { 245 futex_down(&malloc_futex); 246 219 247 if (max_heap_size == (size_t) -1) 220 248 max_heap_size = 221 249 max((size_t) (heap_end - heap_start), MAX_HEAP_SIZE); 222 250 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 */ 226 267 static void split_mark(heap_block_head_t *cur, const size_t size) 227 268 { … … 243 284 244 285 /** Allocate a memory block 286 * 287 * Should be called only inside the critical section. 245 288 * 246 289 * @param size The size of the block to allocate. … … 356 399 } 357 400 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 */ 358 409 void *calloc(const size_t nmemb, const size_t size) 359 410 { … … 361 412 if (block == NULL) 362 413 return NULL; 363 414 364 415 memset(block, 0, nmemb * size); 365 416 return block; 366 417 } 367 418 419 /** Allocate memory 420 * 421 * @param size Number of bytes to allocate. 422 * 423 * @return Allocated memory or NULL. 424 * 425 */ 368 426 void *malloc(const size_t size) 369 427 { 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 */ 373 443 void *memalign(const size_t align, const size_t size) 374 444 { … … 379 449 1 << (fnzb(max(sizeof(void *), align) - 1) + 1); 380 450 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 */ 384 466 void *realloc(const void *addr, const size_t size) 385 467 { 386 468 if (addr == NULL) 387 469 return malloc(size); 470 471 futex_down(&malloc_futex); 388 472 389 473 /* Calculate the position of the header. */ … … 398 482 399 483 void *ptr = NULL; 484 bool reloc = false; 400 485 size_t real_size = GROSS_SIZE(ALIGN_UP(size, BASE_ALIGN)); 401 486 size_t orig_size = head->size; … … 415 500 } else { 416 501 /* 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. */ 418 505 heap_block_head_t *next_head = 419 506 (heap_block_head_t *) (((void *) head) + head->size); … … 427 514 428 515 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); 435 527 } 436 528 } … … 442 534 * 443 535 * @param addr The address of the block. 536 * 444 537 */ 445 538 void free(const void *addr) 446 539 { 540 futex_down(&malloc_futex); 541 447 542 /* Calculate the position of the header. */ 448 543 heap_block_head_t *head … … 483 578 484 579 shrink_heap(); 580 581 futex_up(&malloc_futex); 485 582 } 486 583 -
uspace/lib/c/generic/str.c
r38aaacc2 rf4f866c 471 471 * null-terminated and containing only complete characters. 472 472 * 473 * @param dest Destination buffer.473 * @param dest Destination buffer. 474 474 * @param count Size of the destination buffer (must be > 0). 475 475 * @param src Source string. … … 477 477 void str_cpy(char *dest, size_t size, const char *src) 478 478 { 479 wchar_t ch;480 size_t src_off;481 size_t dest_off;482 483 479 /* There must be space for a null terminator in the buffer. */ 484 480 assert(size > 0); 485 481 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; 489 486 while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) { 490 487 if (chr_encode(ch, dest, &dest_off, size - 1) != EOK) 491 488 break; 492 489 } 493 490 494 491 dest[dest_off] = '\0'; 495 492 } … … 505 502 * have to be null-terminated. 506 503 * 507 * @param dest Destination buffer.504 * @param dest Destination buffer. 508 505 * @param count Size of the destination buffer (must be > 0). 509 506 * @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. 511 508 */ 512 509 void str_ncpy(char *dest, size_t size, const char *src, size_t n) 513 510 { 514 wchar_t ch;515 size_t src_off;516 size_t dest_off;517 518 511 /* There must be space for a null terminator in the buffer. */ 519 512 assert(size > 0); 520 513 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; 524 518 while ((ch = str_decode(src, &src_off, n)) != 0) { 525 519 if (chr_encode(ch, dest, &dest_off, size - 1) != EOK) 526 520 break; 527 521 } 528 522 529 523 dest[dest_off] = '\0'; 530 524 } … … 896 890 } 897 891 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 */ 898 908 char *str_dup(const char *src) 899 909 { 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); 903 912 if (dest == NULL) 904 913 return (char *) NULL; 905 914 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 */ 939 char *str_ndup(const char *src, size_t n) 910 940 { 911 941 size_t size = str_size(src); 912 if (size > max_size)913 size = max_size;942 if (size > n) 943 size = n; 914 944 915 945 char *dest = (char *) malloc(size + 1); 916 917 946 if (dest == NULL) 918 947 return (char *) NULL; 919 948 920 memcpy(dest, src, size); 921 dest[size] = 0; 949 str_ncpy(dest, size + 1, src, size); 922 950 return dest; 923 951 } … … 979 1007 } 980 1008 1009 void 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 981 1035 /** @} 982 1036 */ -
uspace/lib/c/generic/sysinfo.c
r38aaacc2 rf4f866c 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 35 #include <libc.h> 36 36 #include <sysinfo.h> 37 37 #include <str.h> 38 #include <errno.h> 39 #include <malloc.h> 40 #include <bool.h> 38 41 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 */ 49 sysinfo_item_tag_t sysinfo_get_tag(const char *path) 40 50 { 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 */ 64 int 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 */ 79 static 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 */ 96 void *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; 43 138 } 44 139 -
uspace/lib/c/generic/task.c
r38aaacc2 rf4f866c 70 70 * loader API. 71 71 * 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. 74 75 * 75 76 * @return ID of the newly created task or zero on error. 76 77 * 77 78 */ 78 task_id_t task_spawn(const char *path, const char *const args[] )79 task_id_t task_spawn(const char *path, const char *const args[], int *err) 79 80 { 80 81 /* Connect to a program loader. */ 81 82 loader_t *ldr = loader_connect(); 82 if (ldr == NULL) 83 if (ldr == NULL) { 84 if (err != NULL) 85 *err = EREFUSED; 86 83 87 return 0; 88 } 84 89 85 90 /* Get task ID. */ … … 143 148 /* Success */ 144 149 free(ldr); 150 151 if (err != NULL) 152 *err = EOK; 153 145 154 return task_id; 146 155 … … 149 158 loader_abort(ldr); 150 159 free(ldr); 160 161 if (err != NULL) 162 *err = rc; 151 163 152 164 return 0; -
uspace/lib/c/include/bool.h
r38aaacc2 rf4f866c 36 36 #define LIBC_BOOL_H_ 37 37 38 #define false 0 39 #define true 1 38 #include <libarch/types.h> 40 39 41 typedef short bool; 40 #define false 0 41 #define true 1 42 43 typedef uint8_t bool; 42 44 43 45 #endif -
uspace/lib/c/include/errno.h
r38aaacc2 rf4f866c 43 43 #define errno _errno 44 44 45 #define EMFILE (-1 7)45 #define EMFILE (-18) 46 46 #define ENAMETOOLONG (-256) 47 47 #define EISDIR (-257) -
uspace/lib/c/include/futex.h
r38aaacc2 rf4f866c 39 39 #include <sys/types.h> 40 40 41 #define FUTEX_INITIALIZER {1}41 #define FUTEX_INITIALIZER {1} 42 42 43 43 typedef atomic_t futex_t; -
uspace/lib/c/include/io/color.h
r38aaacc2 rf4f866c 36 36 #define LIBC_IO_COLOR_H_ 37 37 38 enum console_color{38 typedef enum { 39 39 COLOR_BLACK = 0, 40 40 COLOR_BLUE = 1, … … 48 48 CATTR_BRIGHT = 8, 49 49 CATTR_BLINK = 8 50 } ;50 } console_color_t; 51 51 52 52 #endif -
uspace/lib/c/include/io/console.h
r38aaacc2 rf4f866c 44 44 } console_ev_type_t; 45 45 46 enum {46 typedef enum { 47 47 CONSOLE_CCAP_NONE = 0, 48 48 CONSOLE_CCAP_STYLE, 49 49 CONSOLE_CCAP_INDEXED, 50 50 CONSOLE_CCAP_RGB 51 } ;51 } console_caps_t; 52 52 53 53 /** Console event structure. */ … … 68 68 extern void console_clear(int phone); 69 69 70 extern int console_get_size(int phone, i nt *cols, int *rows);71 extern int console_get_pos(int phone, i nt *col, int *row);72 extern void console_ goto(int phone, int col, int row);70 extern int console_get_size(int phone, ipcarg_t *cols, ipcarg_t *rows); 71 extern int console_get_pos(int phone, ipcarg_t *col, ipcarg_t *row); 72 extern void console_set_pos(int phone, ipcarg_t col, ipcarg_t row); 73 73 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); 74 extern void console_set_style(int phone, uint8_t style); 75 extern void console_set_color(int phone, uint8_t fg_color, uint8_t bg_color, 76 uint8_t flags); 77 extern void console_set_rgb_color(int phone, uint32_t fg_color, uint32_t bg_color); 77 78 78 79 extern void console_cursor_visibility(int phone, bool show); 79 extern int console_get_color_cap(int phone, i nt *ccap);80 extern int console_get_color_cap(int phone, ipcarg_t *ccap); 80 81 extern void console_kcon_enable(int phone); 81 82 -
uspace/lib/c/include/io/keycode.h
r38aaacc2 rf4f866c 51 51 * they really are organized here by position, rather than by label. 52 52 */ 53 enum keycode{53 typedef enum { 54 54 55 55 /* Main block row 1 */ … … 199 199 } keycode_t; 200 200 201 enum keymod{201 typedef enum { 202 202 KM_LSHIFT = 0x001, 203 203 KM_RSHIFT = 0x002, -
uspace/lib/c/include/io/klog.h
r38aaacc2 rf4f866c 33 33 */ 34 34 35 #ifndef LIBC_ STREAM_H_36 #define LIBC_ STREAM_H_35 #ifndef LIBC_IO_KLOG_H_ 36 #define LIBC_IO_KLOG_H_ 37 37 38 38 #include <sys/types.h> 39 39 40 extern size_t klog_write(const void * buf, size_t size);40 extern size_t klog_write(const void *, size_t); 41 41 extern void klog_update(void); 42 42 -
uspace/lib/c/include/io/printf_core.h
r38aaacc2 rf4f866c 40 40 41 41 /** Structure for specifying output methods for different printf clones. */ 42 typedef struct printf_spec{42 typedef struct { 43 43 /* String output function, returns number of printed characters or EOF */ 44 44 int (*str_write)(const char *, size_t, void *); … … 51 51 } printf_spec_t; 52 52 53 int printf_core(const char *fmt, printf_spec_t *ps, va_list ap);53 extern int printf_core(const char *, printf_spec_t *, va_list); 54 54 55 55 #endif -
uspace/lib/c/include/io/screenbuffer.h
r38aaacc2 rf4f866c 33 33 */ 34 34 35 #ifndef SCREENBUFFER_H__36 #define SCREENBUFFER_H__35 #ifndef LIBC_SCREENBUFFER_H__ 36 #define LIBC_SCREENBUFFER_H__ 37 37 38 38 #include <stdint.h> 39 39 #include <sys/types.h> 40 #include <ipc/ipc.h> 40 41 #include <bool.h> 41 42 42 #define DEFAULT_FOREGROUND 0x0 /**< default console foreground color */ 43 #define DEFAULT_BACKGROUND 0xf0f0f0 /**< default console background color */ 43 typedef enum { 44 at_style, 45 at_idx, 46 at_rgb 47 } attr_type_t; 44 48 45 49 typedef struct { … … 58 62 } attr_rgb_t; 59 63 64 typedef union { 65 attr_style_t s; 66 attr_idx_t i; 67 attr_rgb_t r; 68 } attr_val_t; 69 60 70 typedef 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; 71 73 } attrs_t; 72 74 … … 82 84 keyfield_t *buffer; /**< Screen content - characters and 83 85 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 */ 86 88 87 89 /** 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; 90 92 91 93 attrs_t attrs; /**< Current attributes. */ … … 107 109 * 108 110 */ 109 static inline keyfield_t *get_field_at(screenbuffer_t *scr, size_t x, size_t y)111 static inline keyfield_t *get_field_at(screenbuffer_t *scr, ipcarg_t x, ipcarg_t y) 110 112 { 111 113 return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; … … 120 122 * 121 123 */ 122 static inline intattrs_same(attrs_t a1, attrs_t a2)124 static inline bool attrs_same(attrs_t a1, attrs_t a2) 123 125 { 124 126 if (a1.t != a2.t) 125 return 0;127 return false; 126 128 127 129 switch (a1.t) { … … 137 139 } 138 140 139 return 0;141 return false; 140 142 } 141 143 144 extern void screenbuffer_putchar(screenbuffer_t *, wchar_t); 145 extern screenbuffer_t *screenbuffer_init(screenbuffer_t *, ipcarg_t, ipcarg_t); 142 146 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); 147 extern void screenbuffer_clear(screenbuffer_t *); 148 extern void screenbuffer_clear_line(screenbuffer_t *, ipcarg_t); 149 extern void screenbuffer_copy_buffer(screenbuffer_t *, keyfield_t *); 150 extern void screenbuffer_goto(screenbuffer_t *, ipcarg_t, ipcarg_t); 151 extern void screenbuffer_set_style(screenbuffer_t *, uint8_t); 152 extern void screenbuffer_set_color(screenbuffer_t *, uint8_t, uint8_t, uint8_t); 153 extern void screenbuffer_set_rgb_color(screenbuffer_t *, uint32_t, uint32_t); 155 154 156 155 #endif -
uspace/lib/c/include/io/style.h
r38aaacc2 rf4f866c 36 36 #define LIBC_IO_STYLE_H_ 37 37 38 enum console_style{38 typedef enum { 39 39 STYLE_NORMAL = 0, 40 STYLE_EMPHASIS = 1 41 }; 40 STYLE_EMPHASIS = 1, 41 STYLE_INVERTED = 2, 42 STYLE_SELECTED = 3 43 } console_style_t; 42 44 43 45 #endif -
uspace/lib/c/include/str.h
r38aaacc2 rf4f866c 86 86 extern char *str_ndup(const char *, size_t max_size); 87 87 88 extern void order_suffix(const uint64_t val, uint64_t *rv, char *suffix); 89 88 90 /* 89 91 * TODO: Get rid of this. -
uspace/lib/c/include/sysinfo.h
r38aaacc2 rf4f866c 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 35 #ifndef LIBC_SYSINFO_H_ … … 37 37 38 38 #include <libc.h> 39 #include <sysinfo.h>40 #include <str.h>41 39 42 sysarg_t sysinfo_value(const char *name); 40 /** Sysinfo value types 41 * 42 */ 43 typedef enum { 44 SYSINFO_VAL_UNDEFINED = 0, 45 SYSINFO_VAL_VAL = 1, 46 SYSINFO_VAL_DATA = 2 47 } sysinfo_item_tag_t; 48 49 extern sysinfo_item_tag_t sysinfo_get_tag(const char *); 50 extern int sysinfo_get_value(const char *, sysarg_t *); 51 extern void *sysinfo_get_data(const char *, size_t *); 43 52 44 53 #endif -
uspace/lib/c/include/task.h
r38aaacc2 rf4f866c 46 46 47 47 extern 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 48 extern int task_set_name(const char *); 49 extern task_id_t task_spawn(const char *, const char *const[], int *); 50 extern int task_wait(task_id_t id, task_exit_t *, int *); 51 extern int task_retval(int); 53 52 54 53 #endif -
uspace/lib/clui/Makefile
r38aaacc2 rf4f866c 28 28 29 29 USPACE_PREFIX = ../.. 30 EXTRA_CFLAGS = -I. 30 31 LIBRARY = libclui 31 32 -
uspace/lib/clui/tinput.c
r38aaacc2 rf4f866c 40 40 #include <assert.h> 41 41 #include <bool.h> 42 43 #include "tinput.h" 42 #include <tinput.h> 44 43 45 44 /** Seek direction */ … … 49 48 } seek_dir_t; 50 49 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);50 static void tinput_init(tinput_t *); 51 static void tinput_insert_string(tinput_t *, const char *); 52 static void tinput_sel_get_bounds(tinput_t *, size_t *, size_t *); 53 static bool tinput_sel_active(tinput_t *); 54 static void tinput_sel_all(tinput_t *); 55 static void tinput_sel_delete(tinput_t *); 56 static void tinput_key_ctrl(tinput_t *, console_event_t *); 57 static void tinput_key_shift(tinput_t *, console_event_t *); 58 static void tinput_key_ctrl_shift(tinput_t *, console_event_t *); 59 static void tinput_key_unmod(tinput_t *, console_event_t *); 60 static void tinput_pre_seek(tinput_t *, bool); 61 static void tinput_post_seek(tinput_t *, bool); 63 62 64 63 /** Create a new text input field. */ … … 66 65 { 67 66 tinput_t *ti; 68 67 69 68 ti = malloc(sizeof(tinput_t)); 70 69 if (ti == NULL) 71 70 return NULL; 72 71 73 72 tinput_init(ti); 74 73 return ti; … … 81 80 } 82 81 83 static void tinput_display_tail(tinput_t *ti, int start, int pad)84 { 85 staticwchar_t dbuf[INPUT_MAX_SIZE + 1];86 int sa, sb;87 int i, p;88 82 static 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; 89 88 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, 92 91 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; 96 95 if (p < sa) { 97 96 memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(wchar_t)); … … 100 99 p = sa; 101 100 } 102 101 103 102 if (p < sb) { 104 103 fflush(stdout); 105 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_RED, 0);104 console_set_style(fphone(stdout), STYLE_SELECTED); 106 105 memcpy(dbuf, ti->buffer + p, 107 106 (sb - p) * sizeof(wchar_t)); … … 110 109 p = sb; 111 110 } 112 111 113 112 fflush(stdout); 114 console_set_ color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);115 113 console_set_style(fphone(stdout), STYLE_NORMAL); 114 116 115 if (p < ti->nc) { 117 116 memcpy(dbuf, ti->buffer + p, … … 120 119 printf("%ls", dbuf); 121 120 } 122 123 for ( i = 0; i < pad; ++i)121 122 for (p = 0; p < pad; p++) 124 123 putchar(' '); 124 125 125 fflush(stdout); 126 126 } … … 133 133 static void tinput_position_caret(tinput_t *ti) 134 134 { 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, 136 136 ti->row0 + (ti->col0 + ti->pos) / ti->con_cols); 137 137 } … … 140 140 static void tinput_update_origin(tinput_t *ti) 141 141 { 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 147 145 /* Update row0 if the screen scrolled. */ 148 146 if (ti->row0 + rows > ti->con_rows) 149 ti->row0 = ti->con_rows - rows; 147 ti->row0 = ti->con_rows - rows; 150 148 } 151 149 152 150 static void tinput_insert_char(tinput_t *ti, wchar_t c) 153 151 { 154 int i;155 int new_width, new_height;156 157 152 if (ti->nc == INPUT_MAX_SIZE) 158 153 return; 159 160 new_width = ti->col0 + ti->nc + 1;154 155 ipcarg_t new_width = ti->col0 + ti->nc + 1; 161 156 if (new_width % ti->con_cols == 0) { 162 157 /* 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--) 169 167 ti->buffer[i] = ti->buffer[i - 1]; 170 168 171 169 ti->buffer[ti->pos] = c; 172 170 ti->pos += 1; … … 174 172 ti->buffer[ti->nc] = '\0'; 175 173 ti->sel_start = ti->pos; 176 174 177 175 tinput_display_tail(ti, ti->pos - 1, 0); 178 176 tinput_update_origin(ti); … … 182 180 static void tinput_insert_string(tinput_t *ti, const char *str) 183 181 { 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); 191 183 if (ilen == 0) 192 184 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; 203 201 while (i < ilen) { 204 c = str_decode(str, &off, STR_NO_LIMIT);202 wchar_t c = str_decode(str, &off, STR_NO_LIMIT); 205 203 if (c == '\0') 206 204 break; 207 205 208 206 /* Filter out non-printable chars. */ 209 207 if (c < 32) 210 208 c = 32; 211 209 212 210 ti->buffer[ti->pos + i] = c; 213 ++i;214 } 215 211 i++; 212 } 213 216 214 ti->pos += ilen; 217 215 ti->nc += ilen; 218 216 ti->buffer[ti->nc] = '\0'; 219 217 ti->sel_start = ti->pos; 220 218 221 219 tinput_display_tail(ti, ti->pos - ilen, 0); 222 220 tinput_update_origin(ti); … … 226 224 static void tinput_backspace(tinput_t *ti) 227 225 { 228 int i;229 230 226 if (tinput_sel_active(ti)) { 231 227 tinput_sel_delete(ti); 232 228 return; 233 229 } 234 230 235 231 if (ti->pos == 0) 236 232 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++) 239 236 ti->buffer[i - 1] = ti->buffer[i]; 237 240 238 ti->pos -= 1; 241 239 ti->nc -= 1; 242 240 ti->buffer[ti->nc] = '\0'; 243 241 ti->sel_start = ti->pos; 244 242 245 243 tinput_display_tail(ti, ti->pos, 1); 246 244 tinput_position_caret(ti); … … 253 251 return; 254 252 } 255 253 256 254 if (ti->pos == ti->nc) 257 255 return; 258 256 259 257 ti->pos += 1; 260 258 ti->sel_start = ti->pos; 261 259 262 260 tinput_backspace(ti); 263 261 } … … 266 264 { 267 265 tinput_pre_seek(ti, shift_held); 268 266 269 267 if (dir == seek_forward) { 270 268 if (ti->pos < ti->nc) … … 274 272 ti->pos -= 1; 275 273 } 276 274 277 275 tinput_post_seek(ti, shift_held); 278 276 } … … 281 279 { 282 280 tinput_pre_seek(ti, shift_held); 283 281 284 282 if (dir == seek_forward) { 285 283 if (ti->pos == ti->nc) 286 284 return; 287 288 while ( 1) {285 286 while (true) { 289 287 ti->pos += 1; 290 288 291 289 if (ti->pos == ti->nc) 292 290 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] != ' ')) 296 294 break; 297 295 } … … 299 297 if (ti->pos == 0) 300 298 return; 301 302 while ( 1) {299 300 while (true) { 303 301 ti->pos -= 1; 304 302 305 303 if (ti->pos == 0) 306 304 break; 307 305 308 306 if (ti->buffer[ti->pos - 1] == ' ' && 309 307 ti->buffer[ti->pos] != ' ') 310 308 break; 311 309 } 312 313 } 314 310 311 } 312 315 313 tinput_post_seek(ti, shift_held); 316 314 } … … 319 317 { 320 318 tinput_pre_seek(ti, shift_held); 321 319 322 320 if (dir == seek_forward) { 323 321 if (ti->pos + ti->con_cols <= ti->nc) 324 322 ti->pos = ti->pos + ti->con_cols; 325 323 } else { 326 if (ti->pos - ti->con_cols >= 0)324 if (ti->pos >= ti->con_cols) 327 325 ti->pos = ti->pos - ti->con_cols; 328 326 } 329 327 330 328 tinput_post_seek(ti, shift_held); 331 329 } … … 334 332 { 335 333 tinput_pre_seek(ti, shift_held); 336 334 337 335 if (dir == seek_backward) 338 336 ti->pos = 0; 339 337 else 340 338 ti->pos = ti->nc; 341 339 342 340 tinput_post_seek(ti, shift_held); 343 341 } … … 345 343 static void tinput_pre_seek(tinput_t *ti, bool shift_held) 346 344 { 347 if ( tinput_sel_active(ti) && !shift_held) {345 if ((tinput_sel_active(ti)) && (!shift_held)) { 348 346 /* Unselect and redraw. */ 349 347 ti->sel_start = ti->pos; … … 362 360 ti->sel_start = ti->pos; 363 361 } 362 364 363 tinput_position_caret(ti); 365 364 } … … 367 366 static void tinput_history_insert(tinput_t *ti, char *str) 368 367 { 369 int i;370 371 368 if (ti->hnum < HISTORY_LEN) { 372 369 ti->hnum += 1; … … 375 372 free(ti->history[HISTORY_LEN]); 376 373 } 377 378 for (i = ti->hnum; i > 1; --i) 374 375 size_t i; 376 for (i = ti->hnum; i > 1; i--) 379 377 ti->history[i] = ti->history[i - 1]; 380 378 381 379 ti->history[1] = str_dup(str); 382 380 383 381 if (ti->history[0] != NULL) { 384 382 free(ti->history[0]); … … 395 393 } 396 394 397 static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb)395 static void tinput_sel_get_bounds(tinput_t *ti, size_t *sa, size_t *sb) 398 396 { 399 397 if (ti->sel_start < ti->pos) { … … 408 406 static bool tinput_sel_active(tinput_t *ti) 409 407 { 410 return ti->sel_start != ti->pos;408 return (ti->sel_start != ti->pos); 411 409 } 412 410 … … 421 419 static void tinput_sel_delete(tinput_t *ti) 422 420 { 423 int sa, sb; 424 421 size_t sa; 422 size_t sb; 423 425 424 tinput_sel_get_bounds(ti, &sa, &sb); 426 425 if (sa == sb) 427 426 return; 428 427 429 428 memmove(ti->buffer + sa, ti->buffer + sb, 430 429 (ti->nc - sb) * sizeof(wchar_t)); 430 431 431 ti->pos = ti->sel_start = sa; 432 432 ti->nc -= (sb - sa); 433 433 ti->buffer[ti->nc] = '\0'; 434 434 435 435 tinput_display_tail(ti, sa, sb - sa); 436 436 tinput_position_caret(ti); … … 439 439 static void tinput_sel_copy_to_cb(tinput_t *ti) 440 440 { 441 int sa, sb; 441 size_t sa; 442 size_t sb; 443 444 tinput_sel_get_bounds(ti, &sa, &sb); 445 442 446 char *str; 443 444 tinput_sel_get_bounds(ti, &sa, &sb); 445 447 446 448 if (sb < ti->nc) { 447 449 wchar_t tmp_c = ti->buffer[sb]; … … 454 456 if (str == NULL) 455 457 goto error; 456 458 457 459 if (clipboard_put_str(str) != EOK) 458 460 goto error; 459 461 460 462 free(str); 461 463 return; 464 462 465 error: 466 /* TODO: Give the user some kind of warning. */ 463 467 return; 464 /* TODO: Give the user some warning. */465 468 } 466 469 … … 468 471 { 469 472 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 476 480 tinput_insert_string(ti, str); 477 481 free(str); … … 480 484 static void tinput_history_seek(tinput_t *ti, int offs) 481 485 { 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 487 494 if (ti->history[ti->hpos] != NULL) { 488 495 free(ti->history[ti->hpos]); 489 496 ti->history[ti->hpos] = NULL; 490 497 } 491 498 492 499 ti->history[ti->hpos] = tinput_get_str(ti); 493 500 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 498 506 tinput_set_str(ti, ti->history[ti->hpos]); 499 507 tinput_display_tail(ti, 0, pad); … … 515 523 /** Read in one line of input. 516 524 * 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 * 521 532 */ 522 533 int tinput_read(tinput_t *ti, char **dstr) 523 534 { 524 console_event_t ev;525 char *str;526 527 535 fflush(stdout); 528 529 536 if (console_get_size(fphone(stdin), &ti->con_cols, &ti->con_rows) != EOK) 530 537 return EIO; 538 531 539 if (console_get_pos(fphone(stdin), &ti->col0, &ti->row0) != EOK) 532 540 return EIO; 533 534 ti->pos = ti->sel_start = 0; 541 542 ti->pos = 0; 543 ti->sel_start = 0; 535 544 ti->nc = 0; 536 545 ti->buffer[0] = '\0'; 537 546 ti->done = false; 538 547 ti->exit_clui = false; 539 548 540 549 while (!ti->done) { 541 550 fflush(stdout); 551 552 console_event_t ev; 542 553 if (!console_get_event(fphone(stdin), &ev)) 543 554 return EIO; 544 555 545 556 if (ev.type != KEY_PRESS) 546 557 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)) 550 561 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)) 555 565 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)) 561 570 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) 565 573 tinput_key_unmod(ti, &ev); 566 } 567 574 568 575 if (ev.c >= ' ') { 569 576 tinput_sel_delete(ti); … … 571 578 } 572 579 } 573 580 574 581 if (ti->exit_clui) 575 582 return ENOENT; 576 583 577 584 ti->pos = ti->nc; 578 585 tinput_position_caret(ti); 579 586 putchar('\n'); 580 581 str = tinput_get_str(ti);587 588 char *str = tinput_get_str(ti); 582 589 if (str_cmp(str, "") != 0) 583 590 tinput_history_insert(ti, str); 584 591 585 592 ti->hpos = 0; 586 593 587 594 *dstr = str; 588 595 return EOK; … … 700 707 break; 701 708 case KC_UP: 702 tinput_history_seek(ti, +1);709 tinput_history_seek(ti, 1); 703 710 break; 704 711 case KC_DOWN: -
uspace/lib/clui/tinput.h
r38aaacc2 rf4f866c 29 29 /** @addtogroup libclui 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file … … 37 37 #define LIBCLUI_TINPUT_H_ 38 38 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 41 43 42 44 /** Text input field (command line). … … 47 49 /** Buffer holding text currently being edited */ 48 50 wchar_t buffer[INPUT_MAX_SIZE + 1]; 51 49 52 /** Screen coordinates of the top-left corner of the text field */ 50 int col0, row0; 53 ipcarg_t col0; 54 ipcarg_t row0; 55 51 56 /** Screen dimensions */ 52 int con_cols, con_rows; 57 ipcarg_t con_cols; 58 ipcarg_t con_rows; 59 53 60 /** Number of characters in @c buffer */ 54 int nc; 61 size_t nc; 62 55 63 /** Caret position within buffer */ 56 int pos; 64 size_t pos; 65 57 66 /** Selection mark position within buffer */ 58 int sel_start;59 67 size_t sel_start; 68 60 69 /** History (dynamically allocated strings) */ 61 char *history[1 + HISTORY_LEN]; 70 char *history[HISTORY_LEN + 1]; 71 62 72 /** Number of entries in @c history, not counting [0] */ 63 int hnum; 73 size_t hnum; 74 64 75 /** Current position in history */ 65 int hpos; 76 size_t hpos; 77 66 78 /** @c true if finished with this line (return to caller) */ 67 79 bool done; 80 68 81 /** @c true if user requested to abort interactive loop */ 69 82 bool exit_clui; … … 71 84 72 85 extern tinput_t *tinput_new(void); 73 extern void tinput_destroy(tinput_t * ti);74 extern int tinput_read(tinput_t * ti, char **str);86 extern void tinput_destroy(tinput_t *); 87 extern int tinput_read(tinput_t *, char **); 75 88 76 89 #endif … … 78 91 /** @} 79 92 */ 80 -
uspace/lib/net/Makefile
r38aaacc2 rf4f866c 37 37 generic/packet_remote.c \ 38 38 adt/module_map.c \ 39 netif/netif .c \40 netif/netif_ standalone.c \39 netif/netif_local.c \ 40 netif/netif_remote.c \ 41 41 netif/netif_nil_bundle.c \ 42 42 nil/nil_remote.c \ -
uspace/lib/net/adt/module_map.c
r38aaacc2 rf4f866c 94 94 } 95 95 96 task_id_t spawn(const char * fname){ 97 const char * argv[2]; 96 task_id_t spawn(const char *fname) 97 { 98 const char *argv[2]; 98 99 task_id_t res; 99 100 100 101 argv[0] = fname; 101 102 argv[1] = NULL; 102 res = task_spawn(fname, argv );103 103 res = task_spawn(fname, argv, NULL); 104 104 105 return res; 105 106 } -
uspace/lib/net/generic/net_remote.c
r38aaacc2 rf4f866c 32 32 33 33 /** @file 34 * Networking interface implementation for standaloneremote modules.34 * Networking interface implementation for remote modules. 35 35 * @see net_interface.h 36 36 */ -
uspace/lib/net/generic/packet_remote.c
r38aaacc2 rf4f866c 32 32 33 33 /** @file 34 * Packet client interface implementation for standaloneremote modules.34 * Packet client interface implementation for remote modules. 35 35 * @see packet_client.h 36 36 */ … … 47 47 #include <packet/packet_header.h> 48 48 #include <packet/packet_messages.h> 49 #include <packet_remote.h> 49 50 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 * 59 65 */ 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){ 66 static int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){ 63 67 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 85 69 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); 89 71 *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))) { 92 74 munmap(*packet, size); 93 75 async_wait_for(message, NULL); 94 76 return ERROR_CODE; 95 77 } 78 79 ipcarg_t result; 96 80 async_wait_for(message, &result); 81 97 82 return result; 98 83 } 99 84 100 packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix){ 85 int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id) 86 { 101 87 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 } 102 107 108 packet_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 103 113 ipcarg_t packet_id; 104 114 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))) 108 118 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; 109 125 } 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 116 127 return packet; 117 128 } 118 129 119 packet_t packet_get_1(int phone, size_t content){ 130 packet_t packet_get_1_remote(int phone, size_t content) 131 { 120 132 ERROR_DECLARE; 121 133 122 134 ipcarg_t packet_id; 123 135 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))) 127 139 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; 128 145 } 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 135 147 return packet; 136 148 } 137 149 138 void pq_release(int phone, packet_id_t packet_id){ 150 void pq_release_remote(int phone, packet_id_t packet_id) 151 { 139 152 async_msg_1(phone, NET_PACKET_RELEASE, packet_id); 140 153 } -
uspace/lib/net/il/arp_remote.c
r38aaacc2 rf4f866c 32 32 33 33 /** @file 34 * ARP interface implementation for standaloneremote modules.34 * ARP interface implementation for remote modules. 35 35 * @see arp_interface.h 36 36 */ -
uspace/lib/net/il/ip_client.c
r38aaacc2 rf4f866c 56 56 } 57 57 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){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, void **header, size_t * headerlen){ 59 59 ipv4_pseudo_header_ref header_in; 60 60 struct sockaddr_in * address_in; … … 84 84 header_in->protocol = protocol; 85 85 header_in->data_length = htons(data_length); 86 *header = (ip_pseudo_header_ref)header_in;86 *header = header_in; 87 87 return EOK; 88 88 // TODO IPv6 … … 164 164 } 165 165 166 int ip_client_set_pseudo_header_data_length( ip_pseudo_header_refheader, size_t headerlen, size_t data_length){166 int ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, size_t data_length){ 167 167 ipv4_pseudo_header_ref header_in; 168 168 -
uspace/lib/net/il/ip_remote.c
r38aaacc2 rf4f866c 28 28 29 29 /** @addtogroup ip 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @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 * 37 40 */ 38 41 … … 47 50 #include <il_messages.h> 48 51 #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 */ 65 int 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 73 int 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 80 int ip_connect_module(services_t service) 81 { 59 82 return connect_to_service(SERVICE_IP); 60 83 } 61 84 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 */ 104 int 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 */ 122 int 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 69 134 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) 86 144 free(*header); 87 }88 145 } 89 146 } 147 148 ipcarg_t result; 90 149 async_wait_for(message_id, &result); 91 92 if ((result != EOK) && (*header)){150 151 if ((result != EOK) && (*header)) 93 152 free(*header); 94 }else{153 else 95 154 *device_id = IPC_GET_DEVICE(&answer); 96 }155 97 156 return (int) result; 98 157 } 99 158 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 */ 171 int 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 */ 191 int 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 */ 214 int 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 */ 230 int 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); 114 235 } 115 236 -
uspace/lib/net/include/arp_interface.h
r38aaacc2 rf4f866c 29 29 /** @addtogroup arp 30 30 * @{ 31 */32 33 /** @file34 * 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.38 31 */ 39 32 -
uspace/lib/net/include/icmp_interface.h
r38aaacc2 rf4f866c 29 29 /** @addtogroup icmp 30 30 * @{ 31 */32 33 /** @file34 * 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.38 31 */ 39 32 -
uspace/lib/net/include/il_interface.h
r38aaacc2 rf4f866c 32 32 33 33 /** @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. 36 36 */ 37 37 … … 50 50 51 51 /** @name Internetwork layer module interface 52 * This interface is used by other modules.52 * This interface is used by other modules. 53 53 */ 54 54 /*@{*/ 55 55 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 * 62 67 */ 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); 68 static 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); 65 73 } 66 74 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 * 73 86 */ 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); 87 inline 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); 76 92 } 77 93 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 * 84 105 */ 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); 106 inline 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); 87 111 } 88 112 -
uspace/lib/net/include/il_local.h
r38aaacc2 rf4f866c 27 27 */ 28 28 29 /** @addtogroup tl_standalone29 /** @addtogroup il_local 30 30 * @{ 31 31 */ 32 32 33 #ifndef __ TL_STANDALONE_H__34 #define __ TL_STANDALONE_H__33 #ifndef __IL_LOCAL_H__ 34 #define __IL_LOCAL_H__ 35 35 36 36 #include <ipc/ipc.h> 37 37 #include <async.h> 38 38 39 extern int tl_module_message(ipc_callid_t callid, ipc_call_t *call,39 extern int il_module_message_standalone(ipc_callid_t callid, ipc_call_t *call, 40 40 ipc_call_t *answer, int *answer_count); 41 extern int tl_module_start(async_client_conn_t client_connection);41 extern int il_module_start_standalone(async_client_conn_t client_connection); 42 42 43 43 #endif -
uspace/lib/net/include/il_messages.h
r38aaacc2 rf4f866c 28 28 29 29 /** @addtogroup net_il 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Internetwork layer modules messages.35 * @see il_interface.h36 * @see ip_interface.h34 * Internetwork layer modules messages. 35 * @see il_interface.h 36 * @see ip_interface.h 37 37 */ 38 38 … … 44 44 /** Internet layer modules messages. 45 45 */ 46 typedef enum {46 typedef enum { 47 47 /** New device message. 48 48 * @see ip_device_req() … … 72 72 73 73 /** @name Internetwork layer specific message parameters definitions 74 * 74 75 */ 75 76 /*@{*/ 76 77 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 * 79 81 */ 80 #define IL_GET_PROTO(call) (int) IPC_GET_ARG1(*call)82 #define IL_GET_PROTO(call) (int) IPC_GET_ARG1(*call) 81 83 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 * 84 87 */ 85 #define IL_GET_SERVICE(call) (services_t) IPC_GET_ARG2(*call)88 #define IL_GET_SERVICE(call) (services_t) IPC_GET_ARG2(*call) 86 89 87 90 /*@}*/ -
uspace/lib/net/include/ip_client.h
r38aaacc2 rf4f866c 87 87 * @returns EINVAL if the headerlen parameter is not IPv4 pseudo header length. 88 88 */ 89 extern int ip_client_set_pseudo_header_data_length( ip_pseudo_header_refheader, size_t headerlen, size_t data_length);89 extern int ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, size_t data_length); 90 90 91 91 /** Constructs the IPv4 pseudo header. … … 107 107 * @returns ENOMEM if there is not enough memory left. 108 108 */ 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);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, void **header, size_t * headerlen); 110 110 111 111 // TODO ipopt manipulation -
uspace/lib/net/include/ip_interface.h
r38aaacc2 rf4f866c 31 31 */ 32 32 33 /** @file34 * 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 40 33 #ifndef __NET_IP_INTERFACE_H__ 41 34 #define __NET_IP_INTERFACE_H__ … … 51 44 #include <socket_codes.h> 52 45 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 53 72 /** @name IP module interface 54 73 * This interface is used by other modules. 55 74 */ 56 75 /*@{*/ 57 58 /** Type definition of the internet pseudo header pointer.59 */60 typedef void * ip_pseudo_header_ref;61 76 62 77 /** The transport layer notification function type definition. … … 82 97 extern int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg); 83 98 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 112 99 /** Connects to the IP module. 113 100 * @param service The IP module service. Ignored parameter. … … 117 104 extern int ip_connect_module(services_t service); 118 105 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 168 106 /*@}*/ 169 107 -
uspace/lib/net/include/net_interface.h
r38aaacc2 rf4f866c 29 29 /** @addtogroup net 30 30 * @{ 31 */32 33 /** @file34 * 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.38 31 */ 39 32 -
uspace/lib/net/include/netif_interface.h
r38aaacc2 rf4f866c 28 28 29 29 /** @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 * @{ 38 31 */ 39 32 … … 41 34 #define __NET_NETIF_INTERFACE_H__ 42 35 43 #i nclude <ipc/services.h>36 #ifdef CONFIG_NETIF_NIL_BUNDLE 44 37 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> 49 41 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 54 51 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 */ 66 53 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> 76 56 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 86 66 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 */ 125 68 126 69 #endif -
uspace/lib/net/include/netif_messages.h
r38aaacc2 rf4f866c 28 28 29 29 /** @addtogroup netif 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Network interface common module messages. 35 * @see netif_interface.h 34 * Network interface common module messages. 36 35 */ 37 36 … … 76 75 /*@{*/ 77 76 78 /** Return sthe 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. 80 79 */ 81 80 #define NETIF_GET_IRQ(call) \ 82 81 ({int irq = (int) IPC_GET_ARG2(*call); irq;}) 83 82 84 /** Return sthe 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. 86 85 */ 87 86 #define NETIF_GET_IO(call) \ -
uspace/lib/net/include/netif_nil_bundle.h
r38aaacc2 rf4f866c 37 37 #include <async.h> 38 38 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);39 extern int netif_nil_module_message(const char *, ipc_callid_t, ipc_call_t *, 40 ipc_call_t *, int *); 41 extern int netif_nil_module_start(async_client_conn_t); 42 42 43 43 #endif -
uspace/lib/net/include/nil_interface.h
r38aaacc2 rf4f866c 31 31 */ 32 32 33 /** @file34 * 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 41 33 #ifndef __NET_NIL_INTERFACE_H__ 42 34 #define __NET_NIL_INTERFACE_H__ … … 53 45 #include <net_device.h> 54 46 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) 59 49 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) \ 71 55 generic_get_addr_req(nil_phone, NET_NIL_ADDR, device_id, address, data) 72 56 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) 85 60 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) 96 64 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) 107 68 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)120 69 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 129 71 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> 140 74 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 */ 153 87 154 88 #endif -
uspace/lib/net/include/nil_local.h
r38aaacc2 rf4f866c 32 32 33 33 /** @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. 36 36 */ 37 37 38 #ifndef __NET_NIL_ MODULE_H__39 #define __NET_NIL_ MODULE_H__38 #ifndef __NET_NIL_LOCAL_H__ 39 #define __NET_NIL_LOCAL_H__ 40 40 41 41 #include <ipc/ipc.h> 42 42 43 43 /** 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 * 48 52 */ 49 extern int nil_initialize(int net_phone); 53 extern int nil_initialize(int); 54 55 extern int nil_device_state_msg_local(int, device_id_t, int); 56 extern int nil_received_msg_local(int, device_id_t, packet_t, services_t); 50 57 51 58 /** 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 * 61 75 */ 62 extern int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count); 76 extern int nil_message_standalone(const char *, ipc_callid_t, ipc_call_t *, ipc_call_t *, 77 int *); 78 79 extern int nil_module_message_standalone(const char *, ipc_callid_t, 80 ipc_call_t *, ipc_call_t *, int *); 81 extern int nil_module_start_standalone(async_client_conn_t); 63 82 64 83 #endif -
uspace/lib/net/include/nil_messages.h
r38aaacc2 rf4f866c 28 28 29 29 /** @addtogroup net_nil 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Network interface layer module messages. 35 * @see nil_interface.h 34 * Network interface layer module messages. 36 35 */ 37 36 … … 43 42 #include <net_messages.h> 44 43 45 /** Network interface layer module messages.44 /** Network interface layer module messages. 46 45 */ 47 46 typedef enum { … … 80 79 /*@{*/ 81 80 82 /** Return sthe protocol service message parameter.81 /** Return the protocol service message parameter. 83 82 */ 84 83 #define NIL_GET_PROTO(call) \ -
uspace/lib/net/include/nil_remote.h
r38aaacc2 rf4f866c 1 1 /* 2 * Copyright (c) 20 10 Martin Decky2 * Copyright (c) 2009 Lukas Mejdrech 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup n il_standalone30 * @{29 /** @addtogroup netif 30 * @{ 31 31 */ 32 32 33 #ifndef __N IL_STANDALONE_H__34 #define __N IL_STANDALONE_H__33 #ifndef __NET_NIL_REMOTE_H__ 34 #define __NET_NIL_REMOTE_H__ 35 35 36 #include <async.h> 37 #include <fibril_synch.h> 36 38 #include <ipc/ipc.h> 37 #include <async.h>38 39 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); 40 extern int nil_device_state_msg_remote(int, device_id_t, int); 41 extern int nil_received_msg_remote(int, device_id_t, packet_t, services_t); 42 42 43 43 #endif -
uspace/lib/net/include/tl_common.h
r38aaacc2 rf4f866c 49 49 DEVICE_MAP_DECLARE(packet_dimensions, packet_dimension_t); 50 50 51 extern int tl_get_ip_packet_dimension(int, packet_dimensions_ref, 52 device_id_t, packet_dimension_ref *); 53 51 54 /** Gets the address port. 52 55 * Supports AF_INET and AF_INET6 address families. … … 59 62 */ 60 63 extern 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);76 64 77 65 /** Updates IP device packet dimensions cache. -
uspace/lib/net/include/tl_interface.h
r38aaacc2 rf4f866c 32 32 33 33 /** @file 34 * Transport layer module interface for the underlying internetwork layer.34 * Transport layer module interface for the underlying internetwork layer. 35 35 */ 36 36 … … 48 48 49 49 /** @name Transport layer module interface 50 * This interface is used by other modules.50 * This interface is used by other modules. 51 51 */ 52 52 /*@{*/ 53 53 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 * 61 69 */ 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); 70 inline 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); 64 75 } 65 76 -
uspace/lib/net/include/tl_local.h
r38aaacc2 rf4f866c 27 27 */ 28 28 29 /** @addtogroup il_standalone29 /** @addtogroup tl_local 30 30 * @{ 31 31 */ 32 32 33 #ifndef __ IL_STANDALONE_H__34 #define __ IL_STANDALONE_H__33 #ifndef __TL_LOCAL_H__ 34 #define __TL_LOCAL_H__ 35 35 36 36 #include <ipc/ipc.h> 37 37 #include <async.h> 38 38 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);39 extern int tl_module_message_standalone(ipc_callid_t, ipc_call_t *, 40 ipc_call_t *, int *); 41 extern int tl_module_start_standalone(async_client_conn_t); 42 42 43 43 #endif -
uspace/lib/net/netif/netif_nil_bundle.c
r38aaacc2 rf4f866c 41 41 #include <net_messages.h> 42 42 #include <packet/packet.h> 43 #include <nil_module.h>44 43 #include <netif_nil_bundle.h> 45 #include <netif.h> 44 #include <netif_local.h> 45 #include <nil_local.h> 46 46 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 * 55 60 */ 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 } 61 int 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); 62 71 } 63 72 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 * 69 87 */ 70 int netif_nil_module_start(async_client_conn_t client_connection){ 88 int netif_nil_module_start(async_client_conn_t client_connection) 89 { 71 90 ERROR_DECLARE; 72 91 73 92 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))) { 75 94 pm_destroy(); 76 95 return ERROR_CODE; 77 96 } 78 return netif_run_module(); 97 98 async_manager(); 99 100 pm_destroy(); 101 return EOK; 79 102 } 80 103 -
uspace/lib/net/netif/netif_remote.c
r38aaacc2 rf4f866c 28 28 29 29 /** @addtogroup netif 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @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. 36 35 */ 37 36 … … 43 42 #include <packet/packet_client.h> 44 43 #include <net_device.h> 45 #include <netif_ interface.h>44 #include <netif_remote.h> 46 45 #include <netif_messages.h> 47 46 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); 47 int 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); 50 52 } 51 53 52 int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io){ 54 int netif_probe_req_remote(int netif_phone, device_id_t device_id, int irq, int io) 55 { 53 56 return async_req_3_0(netif_phone, NET_NETIF_PROBE, device_id, irq, io); 54 57 } 55 58 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); 59 int 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); 58 64 } 59 65 60 int netif_start_req(int netif_phone, device_id_t device_id){ 66 int netif_start_req_remote(int netif_phone, device_id_t device_id) 67 { 61 68 return async_req_1_0(netif_phone, NET_NETIF_START, device_id); 62 69 } 63 70 64 int netif_stop_req(int netif_phone, device_id_t device_id){ 71 int netif_stop_req_remote(int netif_phone, device_id_t device_id) 72 { 65 73 return async_req_1_0(netif_phone, NET_NETIF_STOP, device_id); 66 74 } 67 75 68 int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats){ 69 aid_t message_id; 76 int 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 70 86 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));77 87 async_wait_for(message_id, &result); 88 78 89 return (int) result; 79 90 } 80 91 81 int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver){ 92 int netif_bind_service_remote(services_t service, device_id_t device_id, services_t me, 93 async_client_conn_t receiver) 94 { 82 95 return bind_service(service, device_id, me, 0, receiver); 83 96 } -
uspace/lib/net/nil/nil_remote.c
r38aaacc2 rf4f866c 28 28 29 29 /** @addtogroup net_nil 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Network interface layer interface implementation for standaloneremote modules.35 * @see nil_interface.h34 * Network interface layer interface implementation for remote modules. 35 * @see nil_interface.h 36 36 */ 37 37 … … 42 42 #include <packet/packet_client.h> 43 43 #include <nil_messages.h> 44 #include <nil_remote.h> 44 45 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 */ 57 int 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); 47 61 } 48 62 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 */ 78 int 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); 51 83 } 52 84 -
uspace/lib/net/tl/icmp_remote.c
r38aaacc2 rf4f866c 32 32 33 33 /** @file 34 * ICMP interface implementation for standaloneremote modules.34 * ICMP interface implementation for remote modules. 35 35 * @see icmp_interface.h 36 36 */ -
uspace/lib/net/tl/tl_common.c
r38aaacc2 rf4f866c 42 42 #include <packet/packet.h> 43 43 #include <packet/packet_client.h> 44 #include <packet_remote.h> 44 45 #include <net_device.h> 45 46 #include <icmp_interface.h> … … 47 48 #include <in6.h> 48 49 #include <inet.h> 49 #include <ip_interface.h> 50 #include <ip_local.h> 51 #include <ip_remote.h> 50 52 #include <socket_codes.h> 51 53 #include <socket_errno.h> 54 #include <ip_interface.h> 55 #include <tl_interface.h> 52 56 #include <tl_common.h> 53 57 … … 82 86 } 83 87 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 */ 105 int 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 { 85 109 ERROR_DECLARE; 86 87 if (! packet_dimension){110 111 if (!packet_dimension) 88 112 return EBADMEM; 89 } 90 113 91 114 *packet_dimension = packet_dimensions_find(packet_dimensions, device_id); 92 if (! * packet_dimension){93 / / ask for and remember them if not found94 *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) 96 119 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))) { 99 123 free(*packet_dimension); 100 124 return ERROR_CODE; 101 125 } 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) { 104 130 free(*packet_dimension); 105 131 return ERROR_CODE; 106 132 } 107 133 } 134 108 135 return EOK; 109 136 } … … 169 196 // detach the first packet and release the others 170 197 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 174 201 length = packet_get_addr(packet, &src, NULL); 175 202 if((length > 0) … … 180 207 return EOK; 181 208 }else{ 182 pq_release (packet_phone, packet_get_id(packet));209 pq_release_remote(packet_phone, packet_get_id(packet)); 183 210 } 184 211 return ENOENT; … … 200 227 } 201 228 // 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); 203 230 if(! packet){ 204 231 return ENOMEM; … … 207 234 data = packet_suffix(*packet, length); 208 235 if(! data){ 209 pq_release (packet_phone, packet_get_id(*packet));236 pq_release_remote(packet_phone, packet_get_id(*packet)); 210 237 return ENOMEM; 211 238 } … … 214 241 // set the packet destination address 215 242 || 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)); 217 244 return ERROR_CODE; 218 245 } -
uspace/lib/socket/Makefile
r38aaacc2 rf4f866c 35 35 generic/socket_client.c \ 36 36 generic/socket_core.c \ 37 generic/socket_parse.c \ 37 38 generic/inet.c \ 38 39 generic/net_modules.c \ -
uspace/lib/socket/generic/net_modules.c
r38aaacc2 rf4f866c 77 77 } 78 78 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 */ 91 int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, 92 async_client_conn_t client_receiver) 93 { 80 94 return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0); 81 95 } 82 96 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 */ 112 int 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 { 84 115 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))) { 95 124 ipc_hangup(phone); 96 125 return ERROR_CODE; … … 98 127 async_new_connection(phonehash, 0, NULL, client_receiver); 99 128 } 129 100 130 return phone; 101 131 } -
uspace/lib/socket/generic/socket_client.c
r38aaacc2 rf4f866c 299 299 static int socket_generate_new_id(void){ 300 300 sockets_ref sockets; 301 int socket_id ;301 int socket_id = 0; 302 302 int count; 303 303 -
uspace/lib/socket/generic/socket_core.c
r38aaacc2 rf4f866c 90 90 // release all received packets 91 91 while((packet_id = dyn_fifo_pop(&socket->received)) >= 0){ 92 pq_release (packet_phone, packet_id);92 pq_release_local(packet_phone, packet_id); 93 93 } 94 94 dyn_fifo_destroy(&socket->received); -
uspace/lib/socket/include/net_err.h
r38aaacc2 rf4f866c 28 28 29 29 /** @addtogroup net 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Common error processing codes and routines.34 * Common error processing codes and routines. 35 35 */ 36 36 … … 41 41 42 42 #ifdef CONFIG_DEBUG 43 #include <stdio.h> 44 #include <str_error.h> 45 #endif 43 46 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) 45 80 46 81 #endif 47 82 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 * 76 90 */ 77 91 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 79 95 80 96 #endif -
uspace/lib/socket/include/net_messages.h
r38aaacc2 rf4f866c 462 462 /*@}*/ 463 463 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 */ 475 static 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 474 481 return EOK; 475 482 } 476 483 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 */ 496 static 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); 488 501 } 489 502 … … 521 534 } 522 535 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 */ 548 static 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; 534 555 ipcarg_t prefix; 535 556 ipcarg_t content; 536 557 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 543 562 packet_dimension->prefix = (size_t) prefix; 544 563 packet_dimension->content = (size_t) content; 545 564 packet_dimension->suffix = (size_t) suffix; 546 565 packet_dimension->addr_len = (size_t) addr_len; 566 547 567 return (int) result; 548 568 } 549 569 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 */ 583 static 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 565 594 return EOK; 566 595 } 567 596 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 */ 609 static 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 583 620 return EOK; 584 621 } -
uspace/lib/socket/include/net_modules.h
r38aaacc2 rf4f866c 72 72 extern void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count); 73 73 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); 74 extern int bind_service(services_t, ipcarg_t, ipcarg_t, ipcarg_t, 75 async_client_conn_t); 76 extern int bind_service_timeout(services_t, ipcarg_t, ipcarg_t, ipcarg_t, 77 async_client_conn_t, suseconds_t); 97 78 98 79 /** Connects to the needed module. -
uspace/lib/socket/include/packet/packet_client.h
r38aaacc2 rf4f866c 45 45 #define __NET_PACKET_CLIENT_H__ 46 46 47 #include "packet.h"47 #include <packet/packet.h> 48 48 49 49 /** @name Packet client interface … … 172 172 * @returns Other error codes as defined for the packet_return() function. 173 173 */ 174 extern int packet_translate (int phone, packet_ref packet, packet_id_t packet_id);174 extern int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id); 175 175 176 176 /** Obtains the packet of the given dimensions. … … 184 184 * @returns NULL on error. 185 185 */ 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);186 extern packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix); 187 187 188 188 /** Obtains the packet of the given content size. … … 193 193 * @returns NULL on error. 194 194 */ 195 extern packet_t packet_get_1 (int phone, size_t content);195 extern packet_t packet_get_1_local(int phone, size_t content); 196 196 197 197 /** Releases the packet queue. … … 202 202 * @param[in] packet_id The packet identifier. 203 203 */ 204 extern void pq_release (int phone, packet_id_t packet_id);204 extern void pq_release_local(int phone, packet_id_t packet_id); 205 205 206 206 /** Returns the packet copy. -
uspace/lib/socket/packet/packet_client.c
r38aaacc2 rf4f866c 156 156 packet_t packet_get_copy(int phone, packet_t packet){ 157 157 packet_t copy; 158 uint8_t * src ;159 uint8_t * dest ;158 uint8_t * src = NULL; 159 uint8_t * dest = NULL; 160 160 size_t addrlen; 161 161 … … 164 164 } 165 165 // 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)); 167 167 if(! copy){ 168 168 return NULL; … … 178 178 return copy; 179 179 }else{ 180 pq_release (phone, copy->packet_id);180 pq_release_local(phone, copy->packet_id); 181 181 return NULL; 182 182 } -
uspace/lib/socket/packet/packet_server.c
r38aaacc2 rf4f866c 97 97 }; 98 98 99 int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){ 100 if(! packet){ 99 int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id) 100 { 101 if (!packet) 101 102 return EINVAL; 102 }103 103 104 *packet = pm_find(packet_id); 104 105 return (*packet) ? EOK : ENOENT; … … 161 162 } 162 163 163 /** Returns the packet of dimensions at least as given. 164 * Tries to reuse free packets first. 165 * Creates a 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 */ 180 static 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 176 188 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]) { 183 193 packet = ps_globals.free[index]; 184 while(packet_is_valid(packet) && (packet->length < length)){ 194 195 while (packet_is_valid(packet) && (packet->length < length)) 185 196 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]) 189 200 ps_globals.free[index] = pq_detach(packet); 190 }else{201 else 191 202 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); 194 206 fibril_mutex_unlock(&ps_globals.lock); 195 // remove debug dump 196 // printf("packet %d got\n", packet->packet_id); 207 197 208 return packet; 198 209 } 199 210 } 200 211 } 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 202 216 fibril_mutex_unlock(&ps_globals.lock); 203 // remove debug dump 204 // printf("packet %d created\n", packet->packet_id); 217 205 218 return packet; 206 219 } 207 220 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. 221 packet_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 227 packet_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 * 217 235 * Should be used only when the global data are locked. 236 * 218 237 * @param[in] packet The packet to be released. 238 * 219 239 */ 220 240 static void packet_release(packet_t packet){ … … 247 267 } 248 268 249 void pq_release(int phone, packet_id_t packet_id){ 269 void pq_release_local(int phone, packet_id_t packet_id) 270 { 250 271 (void) packet_release_wrapper(packet_id); 251 272 } … … 281 302 return EOK; 282 303 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); 284 305 if(! packet){ 285 306 return ENOMEM; … … 290 311 return EOK; 291 312 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)); 293 314 if(! packet){ 294 315 return ENOMEM;
Note:
See TracChangeset
for help on using the changeset viewer.
