Changeset f4f866c in mainline for uspace/lib/c


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

Merge mainline changes.

Location:
uspace/lib/c
Files:
6 added
35 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    r38aaacc2 rf4f866c  
    4646
    4747extern task_id_t task_get_id(void);
    48 extern int task_set_name(const char *name);
    49 extern task_id_t task_spawn(const char *path, const char *const argv[]);
    50 extern int task_wait(task_id_t id, task_exit_t *texit, int *retval);
    51 extern int task_retval(int val);
    52 
     48extern int task_set_name(const char *);
     49extern task_id_t task_spawn(const char *, const char *const[], int *);
     50extern int task_wait(task_id_t id, task_exit_t *, int *);
     51extern int task_retval(int);
    5352
    5453#endif
Note: See TracChangeset for help on using the changeset viewer.