Changeset f4f866c in mainline for uspace/lib/c
- Timestamp:
- 2010-04-23T21:42:26Z (15 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/c
- Files:
-
- 6 added
- 35 edited
- 2 moved
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 94 * @param key 95 * @param item 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 198 * @param f 199 * @param arg 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 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 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 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 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
Note:
See TracChangeset
for help on using the changeset viewer.