Changeset 90478727 in mainline for uspace/lib/c


Ignore:
Timestamp:
2012-08-12T11:46:44Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
41b764b7
Parents:
e1e4192 (diff), 371cb6c (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:
2 added
39 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    re1e4192 r90478727  
    7272        generic/device/nic.c \
    7373        generic/device/pci.c \
     74        generic/device/ahci.c \
    7475        generic/elf/elf_load.c \
    7576        generic/event.c \
  • uspace/lib/c/arch/abs32le/_link.ld.in

    re1e4192 r90478727  
    1414SECTIONS {
    1515#ifdef LOADER
     16        . = 0x70001000 + SIZEOF_HEADERS;
     17       
    1618        .interp : {
    1719                *(.interp);
    18         } :interp
    19        
    20         . = 0x70001000 + SIZEOF_HEADERS;
     20        } :interp :text
    2121#else
    2222        . = 0x1000 + SIZEOF_HEADERS;
    2323#endif
     24       
     25        /* Make sure the code is aligned reasonably */
     26        . = ALIGN(., 16);
     27       
    2428        .text : {
    2529                *(.text .text.*);
  • uspace/lib/c/arch/amd64/_link.ld.in

    re1e4192 r90478727  
    1515SECTIONS {
    1616#ifdef LOADER
     17        . = 0x70001000 + SIZEOF_HEADERS;
     18       
    1719        .interp : {
    1820                *(.interp);
    19         } :interp
    20        
    21         . = 0x70001000 + SIZEOF_HEADERS;
     21        } :interp :text
    2222#else
    2323        . = 0x1000 + SIZEOF_HEADERS;
    2424#endif
     25       
     26        /* Make sure the code is aligned reasonably */
     27        . = ALIGN(., 16);
     28       
    2529        .init : {
    2630                *(.init);
  • uspace/lib/c/arch/amd64/include/elf_linux.h

    re1e4192 r90478727  
    6666        uint64_t rsp;
    6767        uint64_t ss;
     68
     69        /*
     70         * The following registers need to be part of elf_regs_t.
     71         * Unfortunately, we don't have any information about them in our
     72         * istate_t.
     73         */
     74        uint64_t unused_fs_base;
     75        uint64_t unused_gs_base;
     76        uint64_t unused_ds;
     77        uint64_t unused_es;
     78        uint64_t unused_fs;
     79        uint64_t unused_gs;
    6880} elf_regs_t;
    6981
     
    91103        elf_regs->rsp = istate->rsp;
    92104        elf_regs->ss = istate->ss;
     105
     106        /*
     107         * Reset the registers for which there is not enough info in istate_t.
     108         */
     109        elf_regs->unused_fs_base = 0;
     110        elf_regs->unused_gs_base = 0;
     111        elf_regs->unused_ds = 0;
     112        elf_regs->unused_es = 0;
     113        elf_regs->unused_fs = 0;
     114        elf_regs->unused_gs = 0;
    93115}
    94116
  • uspace/lib/c/arch/arm32/_link.ld.in

    re1e4192 r90478727  
    1414SECTIONS {
    1515#ifdef LOADER
     16        . = 0x70001000 + SIZEOF_HEADERS;
     17       
    1618        .interp : {
    1719                *(.interp);
    18         } :interp
    19        
    20         . = 0x70001000 + SIZEOF_HEADERS;
     20        } :interp :text
    2121#else
    2222        . = 0x1000 + SIZEOF_HEADERS;
    2323#endif
     24       
     25        /* Make sure the code is aligned reasonably */
     26        . = ALIGN(., 8);
     27       
    2428        .init : {
    2529                *(.init);
  • uspace/lib/c/arch/arm32/src/fibril.S

    re1e4192 r90478727  
    3535        stmia r0!, {sp, lr}
    3636        stmia r0!, {r4-r11}
    37 
     37       
    3838        # return 1
    3939        mov r0, #1
     
    4343        ldmia r0!, {sp, lr}
    4444        ldmia r0!, {r4-r11}
    45 
    46         #return 0
     45       
     46        # return 0
    4747        mov r0, #0
    4848        mov pc, lr
  • uspace/lib/c/arch/arm32/src/stacktrace_asm.S

    re1e4192 r90478727  
    4141
    4242stacktrace_pc_get:
    43         mov r0, lr 
     43        mov r0, lr
    4444        mov pc, lr
  • uspace/lib/c/arch/arm32/src/thread_entry.s

    re1e4192 r90478727  
    4242        push {fp, ip, lr, pc}
    4343        sub fp, ip, #4
    44 
    45         b __thread_main
     44       
     45        b __thread_main
  • uspace/lib/c/arch/ia32/_link.ld.in

    re1e4192 r90478727  
    1919
    2020SECTIONS {
    21 #if defined(LOADER) || defined(DLEXE)
    22         .interp : {
    23                 *(.interp);
    24         } :interp
    25 #endif
    2621#ifdef LOADER
    2722        . = 0x70001000 + SIZEOF_HEADERS;
     
    2924        . = 0x1000 + SIZEOF_HEADERS;
    3025#endif
     26       
     27#if defined(LOADER) || defined(DLEXE)
     28        .interp : {
     29                *(.interp);
     30        } :interp :text
     31#endif
     32       
     33        /* Make sure the code is aligned reasonably */
     34        . = ALIGN(., 16);
     35       
    3136        .init : {
    3237                *(.init);
     
    3742                *(.rodata .rodata.*);
    3843        } :text
    39 
     44       
    4045#if defined(SHLIB) || defined(DLEXE)
    4146        .rel.plt : {
     
    8085#if defined(SHLIB) || defined(DLEXE)
    8186        .data.rel : {
    82                 *(.data.rel .data.rel.*);
     87                *(.data.rel .data.rel.*);
    8388        } :data
    84 
     89       
    8590        .got : {
    86                 *(.got);
     91                *(.got);
    8792        } :data
     93       
    8894        .got.plt : {
    89                 *(.got.plt);
     95                *(.got.plt);
    9096        } :data
    9197#endif
  • uspace/lib/c/arch/ia64/Makefile.common

    re1e4192 r90478727  
    2727#
    2828
    29 GCC_CFLAGS += -fno-unwind-tables
     29#
     30# FIXME:
     31#
     32# The -fno-selective-scheduling and -fno-selective-scheduling2 options
     33# should be removed as soon as a bug in GCC concerning unchecked
     34# speculative loads is fixed.
     35#
     36# See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53975 for reference.
     37#
     38
     39GCC_CFLAGS += -fno-unwind-tables -fno-selective-scheduling -fno-selective-scheduling2
    3040
    3141ENDIANESS = LE
  • uspace/lib/c/arch/ia64/_link.ld.in

    re1e4192 r90478727  
    1414SECTIONS {
    1515#ifdef LOADER
     16        . = 0x800000000 + SIZEOF_HEADERS;
     17       
    1618        .interp : {
    1719                *(.interp);
    18         } :interp
    19        
    20         . = 0x800000000 + SIZEOF_HEADERS;
     20        } :interp :text
    2121#else
    2222        . = 0x4000 + SIZEOF_HEADERS;
    2323#endif
    24         /*
    25          * XXX This is just a work around. Problem: .init section does not
    26          * have the proper alignment.
    27          */
     24       
     25        /* Make sure the code is aligned reasonably */
    2826        . = ALIGN(., 16);
    29 
     27       
    3028        .init : {
    3129                *(.init);
  • uspace/lib/c/arch/ia64/include/fibril.h

    re1e4192 r90478727  
    4949#define PFM_MASK  (~0x3fffffffff)
    5050
    51 #define PSTHREAD_INITIAL_STACK_PAGES_NO  2
    52 
    5351/* Stack is divided into two equal parts (for memory stack and register stack). */
    54 #define PSTHREAD_INITIAL_STACK_DIVISION  2
     52#define FIBRIL_INITIAL_STACK_DIVISION  2
    5553
    5654#define context_set(c, _pc, stack, size, tls) \
     
    5856                (c)->pc = (uint64_t) _pc; \
    5957                (c)->bsp = ((uint64_t) stack) + \
    60                     size / PSTHREAD_INITIAL_STACK_DIVISION; \
     58                    size / FIBRIL_INITIAL_STACK_DIVISION; \
    6159                (c)->ar_pfs &= PFM_MASK; \
    6260                (c)->sp = ((uint64_t) stack) + \
    63                     ALIGN_UP((size / PSTHREAD_INITIAL_STACK_DIVISION), STACK_ALIGNMENT) - \
     61                    ALIGN_UP((size / FIBRIL_INITIAL_STACK_DIVISION), STACK_ALIGNMENT) - \
    6462                    SP_DELTA; \
    6563                (c)->tp = (uint64_t) tls; \
  • uspace/lib/c/arch/ia64/include/thread.h

    re1e4192 r90478727  
    2727 */
    2828
    29 /** @addtogroup libcia64       
     29/** @addtogroup libcia64
    3030 * @{
    3131 */
     
    3636#define LIBC_ia64_THREAD_H_
    3737
    38 #define THREAD_INITIAL_STACK_PAGES_NO 2
    39 
    4038#endif
    4139
  • uspace/lib/c/arch/mips32/Makefile.common

    re1e4192 r90478727  
    2727#
    2828
    29 GCC_CFLAGS += -mips3 -mabi=32
     29GCC_CFLAGS += -msoft-float -mips3 -mabi=32
    3030
    3131ENDIANESS = LE
  • uspace/lib/c/arch/mips32/_link.ld.in

    re1e4192 r90478727  
    1414SECTIONS {
    1515#ifdef LOADER
     16        . = 0x70004000 + SIZEOF_HEADERS;
     17       
    1618        .interp : {
    1719                *(.interp);
    18         } :interp
    19        
    20         . = 0x70004000 + SIZEOF_HEADERS;
     20        } :interp :text
    2121#else
    2222        . = 0x4000 + SIZEOF_HEADERS;
    2323#endif
     24       
     25        /* Make sure the code is aligned reasonably */
     26        . = ALIGN(., 16);
     27       
    2428        .init : {
    2529                *(.init);
  • uspace/lib/c/arch/mips32eb/Makefile.common

    re1e4192 r90478727  
    2727#
    2828
    29 GCC_CFLAGS += -mips3 -mabi=32
     29GCC_CFLAGS += -msoft-float -mips3 -mabi=32
    3030
    3131ENDIANESS = BE
  • uspace/lib/c/arch/mips64/Makefile.common

    re1e4192 r90478727  
    2727#
    2828
    29 GCC_CFLAGS += -mips3 -mabi=64
     29GCC_CFLAGS += -msoft-float -mips3 -mabi=64
    3030AFLAGS = -64
    3131
  • uspace/lib/c/arch/mips64/_link.ld.in

    re1e4192 r90478727  
    1515SECTIONS {
    1616#ifdef LOADER
     17        . = 0x70004000 + SIZEOF_HEADERS;
     18       
    1719        .interp : {
    1820                *(.interp);
    19         } :interp
    20        
    21         . = 0x70004000 + SIZEOF_HEADERS;
     21        } :interp :text
    2222#else
    2323        . = 0x4000 + SIZEOF_HEADERS;
    2424#endif
     25       
     26        /* Make sure the code is aligned reasonably */
     27        . = ALIGN(., 16);
     28       
    2529        .init : {
    2630                *(.init);
  • uspace/lib/c/arch/ppc32/_link.ld.in

    re1e4192 r90478727  
    1515SECTIONS {
    1616#ifdef LOADER
     17        . = 0x70001000 + SIZEOF_HEADERS;
     18       
    1719        .interp : {
    1820                *(.interp);
    19         } :interp
    20        
    21         . = 0x70001000 + SIZEOF_HEADERS;
     21        } :interp :text
    2222#else
    2323        . = 0x1000 + SIZEOF_HEADERS;
    2424#endif
     25       
     26        /* Make sure the code is aligned reasonably */
     27        . = ALIGN(., 4);
     28       
    2529        .init : {
    2630                *(.init);
  • uspace/lib/c/arch/sparc64/_link.ld.in

    re1e4192 r90478727  
    1414SECTIONS {
    1515#ifdef LOADER
     16        . = 0x70004000 + SIZEOF_HEADERS;
     17       
    1618        .interp : {
    1719                *(.interp);
    18         } :interp
    19        
    20         . = 0x70004000 + SIZEOF_HEADERS;
     20        } :interp :text
    2121#else
    2222        . = 0x4000 + SIZEOF_HEADERS;
    2323#endif
     24       
     25        /* Make sure the code is aligned reasonably */
     26        . = ALIGN(., 16);
     27       
    2428        .init : {
    2529                *(.init);
  • uspace/lib/c/generic/as.c

    re1e4192 r90478727  
    4646 *
    4747 * @param base  Starting virtual address of the area.
    48  *              If set to (void *) -1, the kernel finds
    49  *              a mappable area.
     48 *              If set to AS_AREA_ANY ((void *) -1),
     49 *              the kernel finds a mappable area.
    5050 * @param size  Size of the area.
    5151 * @param flags Flags describing type of the area.
    5252 *
    5353 * @return Starting virtual address of the created area on success.
    54  * @return (void *) -1 otherwise.
     54 * @return AS_MAP_FAILED ((void *) -1) otherwise.
    5555 *
    5656 */
  • uspace/lib/c/generic/async.c

    re1e4192 r90478727  
    13881388
    13891389        futex_down(&async_futex);
    1390         if (msg->done)
     1390        if (msg->done) {
    13911391                amsg_destroy(msg);
    1392         else
     1392        } else {
     1393                msg->dataptr = NULL;
    13931394                msg->forget = true;
     1395        }
    13941396        futex_up(&async_futex);
    13951397}
  • uspace/lib/c/generic/devman.c

    re1e4192 r90478727  
    430430        async_wait_for(req, &retval);
    431431       
    432         if (retval != EOK)
    433                 return retval;
     432        if (retval != EOK) {
     433                return retval;
     434        }
    434435       
    435436        act_size = IPC_GET_ARG2(dreply);
     
    449450{
    450451        return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, buf,
     452            buf_size);
     453}
     454
     455int devman_fun_get_driver_name(devman_handle_t handle, char *buf, size_t buf_size)
     456{
     457        return devman_get_str_internal(DEVMAN_FUN_GET_DRIVER_NAME, handle, buf,
    451458            buf_size);
    452459}
  • uspace/lib/c/generic/elf/elf_load.c

    re1e4192 r90478727  
    366366        a = as_area_create((uint8_t *) base + bias, mem_sz,
    367367            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
    368         if (a == (void *) -1) {
     368        if (a == AS_MAP_FAILED) {
    369369                DPRINTF("memory mapping failed (0x%x, %d)\n",
    370370                    base + bias, mem_sz);
  • uspace/lib/c/generic/fibril.c

    re1e4192 r90478727  
    286286}
    287287
     288/** Delete a fibril that has never run.
     289 *
     290 * Free resources of a fibril that has been created with fibril_create()
     291 * but never readied using fibril_add_ready().
     292 *
     293 * @param fid Pointer to the fibril structure of the fibril to be
     294 *            added.
     295 */
     296void fibril_destroy(fid_t fid)
     297{
     298        fibril_t *fibril = (fibril_t *) fid;
     299       
     300        free(fibril->stack);
     301        fibril_teardown(fibril);
     302}
     303
    288304/** Add a fibril to the ready list.
    289305 *
  • uspace/lib/c/generic/loc.c

    re1e4192 r90478727  
    450450}
    451451
     452/** Get service server name.
     453 *
     454 * Provided ID of a service, return the name of its server.
     455 *
     456 * @param svc_id        Service ID
     457 * @param name          Place to store pointer to new string. Caller should
     458 *                      free it using free().
     459 * @return              EOK on success or negative error code
     460 */
     461int loc_service_get_server_name(service_id_t svc_id, char **name)
     462{
     463        return loc_get_name_internal(LOC_SERVICE_GET_SERVER_NAME, svc_id, name);
     464}
     465
    452466int loc_namespace_get_id(const char *name, service_id_t *handle,
    453467    unsigned int flags)
  • uspace/lib/c/generic/malloc.c

    re1e4192 r90478727  
    109109        (((uintptr_t) (area)->end) - sizeof(heap_block_foot_t))
    110110
     111#define AREA_LAST_BLOCK_HEAD(area) \
     112        ((uintptr_t) BLOCK_HEAD(((heap_block_foot_t *) AREA_LAST_BLOCK_FOOT(area))))
     113
    111114/** Get header in heap block.
    112115 *
     
    285288        /* Align the heap area size on page boundary */
    286289        size_t asize = ALIGN_UP(size, PAGE_SIZE);
    287         void *astart = as_area_create((void *) -1, asize,
     290        void *astart = as_area_create(AS_AREA_ANY, asize,
    288291            AS_AREA_WRITE | AS_AREA_READ);
    289         if (astart == (void *) -1)
     292        if (astart == AS_MAP_FAILED)
    290293                return false;
    291294       
     
    346349                return false;
    347350       
    348         /* Add new free block */
    349         size_t net_size = (size_t) (end - area->end);
    350         if (net_size > 0)
    351                 block_init(area->end, net_size, true, area);
     351        heap_block_head_t *last_head =
     352            (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area);
     353       
     354        if (last_head->free) {
     355                /* Add the new space to the last block. */
     356                size_t net_size = (size_t) (end - area->end) + last_head->size;
     357                malloc_assert(net_size > 0);
     358                block_init(last_head, net_size, true, area);
     359        } else {
     360                /* Add new free block */
     361                size_t net_size = (size_t) (end - area->end);
     362                if (net_size > 0)
     363                        block_init(area->end, net_size, true, area);
     364        }
    352365       
    353366        /* Update heap area parameters */
     
    355368       
    356369        return true;
    357 }
    358 
    359 /** Try to enlarge any of the heap areas
    360  *
    361  * Should be called only inside the critical section.
    362  *
    363  * @param size Gross size of item to allocate (bytes).
    364  *
    365  */
    366 static bool heap_grow(size_t size)
    367 {
    368         if (size == 0)
    369                 return true;
    370        
    371         /* First try to enlarge some existing area */
    372         for (heap_area_t *area = first_heap_area; area != NULL;
    373             area = area->next) {
    374                 if (area_grow(area, size))
    375                         return true;
    376         }
    377        
    378         /* Eventually try to create a new area */
    379         return area_create(AREA_OVERHEAD(size));
    380370}
    381371
     
    661651}
    662652
     653/** Try to enlarge any of the heap areas.
     654 *
     655 * If successful, allocate block of the given size in the area.
     656 * Should be called only inside the critical section.
     657 *
     658 * @param size  Gross size of item to allocate (bytes).
     659 * @param align Memory address alignment.
     660 *
     661 * @return Allocated block.
     662 * @return NULL on failure.
     663 *
     664 */
     665static void *heap_grow_and_alloc(size_t size, size_t align)
     666{
     667        if (size == 0)
     668                return NULL;
     669       
     670        /* First try to enlarge some existing area */
     671        for (heap_area_t *area = first_heap_area; area != NULL;
     672            area = area->next) {
     673               
     674                if (area_grow(area, size + align)) {
     675                        heap_block_head_t *first =
     676                            (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area);
     677                       
     678                        void *addr =
     679                            malloc_area(area, first, NULL, size, align);
     680                        malloc_assert(addr != NULL);
     681                        return addr;
     682                }
     683        }
     684       
     685        /* Eventually try to create a new area */
     686        if (area_create(AREA_OVERHEAD(size + align))) {
     687                heap_block_head_t *first =
     688                    (heap_block_head_t *) AREA_FIRST_BLOCK_HEAD(last_heap_area);
     689               
     690                void *addr =
     691                    malloc_area(last_heap_area, first, NULL, size, align);
     692                malloc_assert(addr != NULL);
     693                return addr;
     694        }
     695       
     696        return NULL;
     697}
     698
    663699/** Allocate a memory block
    664700 *
     
    679715       
    680716        size_t falign = lcm(align, BASE_ALIGN);
    681         size_t real_size = GROSS_SIZE(ALIGN_UP(size, falign));
    682        
    683         bool retry = false;
    684         heap_block_head_t *split;
    685        
    686 loop:
     717       
     718        /* Check for integer overflow. */
     719        if (falign < align)
     720                return NULL;
     721       
     722        /*
     723         * The size of the allocated block needs to be naturally
     724         * aligned, because the footer structure also needs to reside
     725         * on a naturally aligned address in order to avoid unaligned
     726         * memory accesses.
     727         */
     728        size_t gross_size = GROSS_SIZE(ALIGN_UP(size, BASE_ALIGN));
    687729       
    688730        /* Try the next fit approach */
    689         split = next_fit;
     731        heap_block_head_t *split = next_fit;
    690732       
    691733        if (split != NULL) {
    692                 void *addr = malloc_area(split->area, split, NULL, real_size,
     734                void *addr = malloc_area(split->area, split, NULL, gross_size,
    693735                    falign);
    694736               
     
    703745                    AREA_FIRST_BLOCK_HEAD(area);
    704746               
    705                 void *addr = malloc_area(area, first, split, real_size,
     747                void *addr = malloc_area(area, first, split, gross_size,
    706748                    falign);
    707749               
     
    710752        }
    711753       
    712         if (!retry) {
    713                 /* Try to grow the heap space */
    714                 if (heap_grow(real_size)) {
    715                         retry = true;
    716                         goto loop;
    717                 }
    718         }
    719        
    720         return NULL;
     754        /* Finally, try to grow heap space and allocate in the new area. */
     755        return heap_grow_and_alloc(gross_size, falign);
    721756}
    722757
     
    731766void *calloc(const size_t nmemb, const size_t size)
    732767{
     768        // FIXME: Check for overflow
     769       
    733770        void *block = malloc(nmemb * size);
    734771        if (block == NULL)
     
    870907        if (addr == NULL)
    871908                return;
    872 
     909       
    873910        futex_down(&malloc_futex);
    874911       
  • uspace/lib/c/generic/mman.c

    re1e4192 r90478727  
    4242{
    4343        if (!start)
    44                 start = (void *) -1;
     44                start = AS_AREA_ANY;
    4545       
    4646//      if (!((flags & MAP_SHARED) ^ (flags & MAP_PRIVATE)))
  • uspace/lib/c/generic/str.c

    re1e4192 r90478727  
    428428 *
    429429 * Do a char-by-char comparison of two NULL-terminated strings.
    430  * The strings are considered equal iff they consist of the same
    431  * characters on the minimum of their lengths.
     430 * The strings are considered equal iff their length is equal
     431 * and both strings consist of the same sequence of characters.
     432 *
     433 * A string S1 is less than another string S2 if it has a character with
     434 * lower value at the first character position where the strings differ.
     435 * If the strings differ in length, the shorter one is treated as if
     436 * padded by characters with a value of zero.
    432437 *
    433438 * @param s1 First string to compare.
    434439 * @param s2 Second string to compare.
    435440 *
    436  * @return 0 if the strings are equal, -1 if first is smaller,
    437  *         1 if second smaller.
     441 * @return 0 if the strings are equal, -1 if the first is less than the second,
     442 *         1 if the second is less than the first.
    438443 *
    439444 */
     
    466471 *
    467472 * Do a char-by-char comparison of two NULL-terminated strings.
    468  * The strings are considered equal iff they consist of the same
    469  * characters on the minimum of their lengths and the length limit.
     473 * The strings are considered equal iff
     474 * min(str_length(s1), max_len) == min(str_length(s2), max_len)
     475 * and both strings consist of the same sequence of characters,
     476 * up to max_len characters.
     477 *
     478 * A string S1 is less than another string S2 if it has a character with
     479 * lower value at the first character position where the strings differ.
     480 * If the strings differ in length, the shorter one is treated as if
     481 * padded by characters with a value of zero. Only the first max_len
     482 * characters are considered.
    470483 *
    471484 * @param s1      First string to compare.
     
    473486 * @param max_len Maximum number of characters to consider.
    474487 *
    475  * @return 0 if the strings are equal, -1 if first is smaller,
    476  *         1 if second smaller.
     488 * @return 0 if the strings are equal, -1 if the first is less than the second,
     489 *         1 if the second is less than the first.
    477490 *
    478491 */
     
    508521        return 0;
    509522
     523}
     524
     525/** Test whether p is a prefix of s.
     526 *
     527 * Do a char-by-char comparison of two NULL-terminated strings
     528 * and determine if p is a prefix of s.
     529 *
     530 * @param s The string in which to look
     531 * @param p The string to check if it is a prefix of s
     532 *
     533 * @return true iff p is prefix of s else false
     534 *
     535 */
     536bool str_test_prefix(const char *s, const char *p)
     537{
     538        wchar_t c1 = 0;
     539        wchar_t c2 = 0;
     540       
     541        size_t off1 = 0;
     542        size_t off2 = 0;
     543
     544        while (true) {
     545                c1 = str_decode(s, &off1, STR_NO_LIMIT);
     546                c2 = str_decode(p, &off2, STR_NO_LIMIT);
     547               
     548                if (c2 == 0)
     549                        return true;
     550
     551                if (c1 != c2)
     552                        return false;
     553               
     554                if (c1 == 0)
     555                        break;
     556        }
     557
     558        return false;
    510559}
    511560
     
    10851134                c = (c >= 'a' ? c - 'a' + 10 : (c >= 'A' ? c - 'A' + 10 :
    10861135                    (c <= '9' ? c - '0' : 0xff)));
    1087                 if (c > base) {
     1136                if (c >= base) {
    10881137                        break;
    10891138                }
  • uspace/lib/c/generic/thread.c

    re1e4192 r90478727  
    4141#include <str.h>
    4242#include <async.h>
     43#include <errno.h>
     44#include <as.h>
    4345#include "private/thread.h"
    4446
    45 #ifndef THREAD_INITIAL_STACK_PAGES_NO
    46 #define THREAD_INITIAL_STACK_PAGES_NO   2
     47#ifndef THREAD_INITIAL_STACK_PAGES
     48        #define THREAD_INITIAL_STACK_PAGES  2
    4749#endif
    4850
     
    6567       
    6668        uarg->uspace_thread_function(uarg->uspace_thread_arg);
    67         /* XXX: we cannot free the userspace stack while running on it
    68                 free(uarg->uspace_stack);
    69                 free(uarg);
    70         */
     69        /*
     70         * XXX: we cannot free the userspace stack while running on it
     71         *
     72         * free(uarg->uspace_stack);
     73         * free(uarg);
     74         */
    7175       
    7276        /* If there is a manager, destroy it */
     
    9296    thread_id_t *tid)
    9397{
    94         char *stack;
    95         uspace_arg_t *uarg;
    96         int rc;
    97 
    98         stack = (char *) malloc(getpagesize() * THREAD_INITIAL_STACK_PAGES_NO);
    99         if (!stack)
    100                 return -1;
    101                
    102         uarg = (uspace_arg_t *) malloc(sizeof(uspace_arg_t));
    103         if (!uarg) {
    104                 free(stack);
    105                 return -1;
     98        uspace_arg_t *uarg =
     99            (uspace_arg_t *) malloc(sizeof(uspace_arg_t));
     100        if (!uarg)
     101                return ENOMEM;
     102       
     103        size_t stack_size = getpagesize() * THREAD_INITIAL_STACK_PAGES;
     104        void *stack = as_area_create(AS_AREA_ANY, stack_size,
     105            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
     106        if (stack == AS_MAP_FAILED) {
     107                free(uarg);
     108                return ENOMEM;
    106109        }
    107110       
    108111        uarg->uspace_entry = (void *) FADDR(__thread_entry);
    109         uarg->uspace_stack = (void *) stack;
     112        uarg->uspace_stack = stack;
     113        uarg->uspace_stack_size = stack_size;
    110114        uarg->uspace_thread_function = function;
    111115        uarg->uspace_thread_arg = arg;
    112116        uarg->uspace_uarg = uarg;
    113117       
    114         rc = __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg, (sysarg_t) name,
    115             (sysarg_t) str_size(name), (sysarg_t) tid);
     118        int rc = __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg,
     119            (sysarg_t) name, (sysarg_t) str_size(name), (sysarg_t) tid);
    116120       
    117         if (rc) {
     121        if (rc != EOK) {
    118122                /*
    119123                 * Failed to create a new thread.
    120                  * Free up the allocated structures.
     124                 * Free up the allocated data.
    121125                 */
     126                as_area_destroy(stack);
    122127                free(uarg);
    123                 free(stack);
    124128        }
    125 
     129       
    126130        return rc;
    127131}
  • uspace/lib/c/include/as.h

    re1e4192 r90478727  
    4141#include <libarch/config.h>
    4242
     43#define AS_AREA_ANY    ((void *) -1)
     44#define AS_MAP_FAILED  ((void *) -1)
     45
    4346static inline size_t SIZE2PAGES(size_t size)
    4447{
  • uspace/lib/c/include/devman.h

    re1e4192 r90478727  
    6464    size_t *);
    6565extern int devman_fun_get_name(devman_handle_t, char *, size_t);
     66extern int devman_fun_get_driver_name(devman_handle_t, char *, size_t);
    6667extern int devman_fun_get_path(devman_handle_t, char *, size_t);
    6768extern int devman_fun_online(devman_handle_t);
  • uspace/lib/c/include/fibril.h

    re1e4192 r90478727  
    8787
    8888extern fid_t fibril_create(int (*func)(void *), void *arg);
     89extern void fibril_destroy(fid_t fid);
    8990extern fibril_t *fibril_setup(void);
    9091extern void fibril_teardown(fibril_t *f);
  • uspace/lib/c/include/ipc/dev_iface.h

    re1e4192 r90478727  
    5151        /** Interface provided by USB HID devices. */
    5252        USBHID_DEV_IFACE,
     53        /** Interface provided by AHCI devices. */
     54        AHCI_DEV_IFACE,
    5355
    5456        /** Interface provided by Real Time Clock devices */
  • uspace/lib/c/include/ipc/devman.h

    re1e4192 r90478727  
    157157        DEVMAN_FUN_GET_CHILD,
    158158        DEVMAN_FUN_GET_NAME,
     159        DEVMAN_FUN_GET_DRIVER_NAME,
    159160        DEVMAN_FUN_ONLINE,
    160161        DEVMAN_FUN_OFFLINE,
  • uspace/lib/c/include/ipc/loc.h

    re1e4192 r90478727  
    5656        LOC_SERVICE_GET_ID,
    5757        LOC_SERVICE_GET_NAME,
     58        LOC_SERVICE_GET_SERVER_NAME,
    5859        LOC_NAMESPACE_GET_ID,
    5960        LOC_CALLBACK_CREATE,
  • uspace/lib/c/include/loc.h

    re1e4192 r90478727  
    5656    unsigned int);
    5757extern int loc_service_get_name(service_id_t, char **);
     58extern int loc_service_get_server_name(service_id_t, char **);
    5859extern int loc_namespace_get_id(const char *, service_id_t *,
    5960    unsigned int);
  • uspace/lib/c/include/str.h

    re1e4192 r90478727  
    7979extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
    8080
     81extern bool str_test_prefix(const char *s, const char *p);
     82
    8183extern void str_cpy(char *dest, size_t size, const char *src);
    8284extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
  • uspace/lib/c/include/sys/mman.h

    re1e4192 r90478727  
    3939#include <sys/types.h>
    4040
    41 #define MAP_FAILED  ((void *) -1)
     41#define MAP_FAILED  AS_MAP_FAILED
    4242
    4343#define MAP_SHARED     (1 << 0)
Note: See TracChangeset for help on using the changeset viewer.