Changeset db96017 in mainline for uspace/lib/c


Ignore:
Timestamp:
2012-04-07T17:41:44Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b6913b7
Parents:
b69e4c0 (diff), 6bb169b5 (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:
12 added
60 edited
8 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    rb69e4c0 rdb96017  
    6767        generic/devman.c \
    6868        generic/device/hw_res.c \
     69        generic/device/hw_res_parsed.c \
    6970        generic/device/char_dev.c \
     71        generic/device/nic.c \
     72        generic/device/pci.c \
    7073        generic/elf/elf_load.c \
    7174        generic/event.c \
     
    103106        generic/adt/list.c \
    104107        generic/adt/hash_table.c \
     108        generic/adt/hash_set.c \
    105109        generic/adt/dynamic_fifo.c \
    106110        generic/adt/measured_strings.c \
  • uspace/lib/c/arch/amd64/include/fibril.h

    rb69e4c0 rdb96017  
    3838#include <sys/types.h>
    3939
    40 /* According to ABI the stack MUST be aligned on
     40/*
     41 * According to ABI the stack MUST be aligned on
    4142 * 16-byte boundary. If it is not, the va_arg calling will
    4243 * panic sooner or later
    4344 */
    44 #define SP_DELTA     16
     45#define SP_DELTA  16
    4546
    4647#define context_set(c, _pc, stack, size, ptls) \
  • uspace/lib/c/arch/arm32/include/fibril.h

    rb69e4c0 rdb96017  
    2727 */
    2828
    29 /** @addtogroup libcarm32       
     29/** @addtogroup libcarm32
    3030 * @{
    3131 */
     
    4242
    4343/** Size of a stack item */
    44 #define STACK_ITEM_SIZE         4
     44#define STACK_ITEM_SIZE  4
    4545
    4646/** Stack alignment - see <a href="http://www.arm.com/support/faqdev/14269.html">ABI</a> for details */
    47 #define STACK_ALIGNMENT         8
     47#define STACK_ALIGNMENT  8
    4848
    49 #define SP_DELTA        (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     49#define SP_DELTA  (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
    5050
    5151
    52 /** Sets data to the context. 
    53  * 
     52/** Sets data to the context.
     53 *
    5454 *  @param c     Context (#context_t).
    5555 *  @param _pc   Program counter.
     
    6262                (c)->pc = (sysarg_t) (_pc); \
    6363                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
    64                 (c)->tls = ((sysarg_t)(ptls)) + sizeof(tcb_t) + ARM_TP_OFFSET; \
     64                (c)->tls = ((sysarg_t)(ptls)) + sizeof(tcb_t) + ARM_TP_OFFSET; \
    6565                (c)->fp = 0; \
    6666        } while (0)
    6767
    68 /** Fibril context. 
     68/** Fibril context.
    6969 *
    7070 *  Only registers preserved accross function calls are included. r9 is used
     
    9191}
    9292
    93 
    9493#endif
    9594
  • uspace/lib/c/arch/ia32/include/fibril.h

    rb69e4c0 rdb96017  
    3838#include <sys/types.h>
    3939
    40 /* According to ABI the stack MUST be aligned on
     40/*
     41 * According to ABI the stack MUST be aligned on
    4142 * 16-byte boundary. If it is not, the va_arg calling will
    4243 * panic sooner or later
  • uspace/lib/c/arch/ia64/include/ddi.h

    rb69e4c0 rdb96017  
    5252static inline void pio_write_8(ioport8_t *port, uint8_t v)
    5353{
    54         uintptr_t prt = (uintptr_t) port;
     54        if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
     55                uintptr_t prt = (uintptr_t) port;
    5556
    56         *((ioport8_t *)(IA64_IOSPACE_ADDRESS +
    57             ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
     57                *((ioport8_t *)(IA64_IOSPACE_ADDRESS +
     58                    ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
     59        } else {
     60                *port = v;
     61        }
    5862
    5963        asm volatile ("mf\n" ::: "memory");
     64        asm volatile ("mf.a\n" ::: "memory");
    6065}
    6166
    6267static inline void pio_write_16(ioport16_t *port, uint16_t v)
    6368{
    64         uintptr_t prt = (uintptr_t) port;
     69        if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
     70                uintptr_t prt = (uintptr_t) port;
    6571
    66         *((ioport16_t *)(IA64_IOSPACE_ADDRESS +
    67             ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
     72                *((ioport16_t *)(IA64_IOSPACE_ADDRESS +
     73                    ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
     74        } else {
     75                *port = v;
     76        }
    6877
    6978        asm volatile ("mf\n" ::: "memory");
     79        asm volatile ("mf.a\n" ::: "memory");
    7080}
    7181
    7282static inline void pio_write_32(ioport32_t *port, uint32_t v)
    7383{
    74         uintptr_t prt = (uintptr_t) port;
     84        if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
     85                uintptr_t prt = (uintptr_t) port;
    7586
    76         *((ioport32_t *)(IA64_IOSPACE_ADDRESS +
    77             ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
     87                *((ioport32_t *)(IA64_IOSPACE_ADDRESS +
     88                    ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
     89        } else {
     90                *port = v;
     91        }
    7892
    7993        asm volatile ("mf\n" ::: "memory");
     94        asm volatile ("mf.a\n" ::: "memory");
    8095}
    8196
    8297static inline uint8_t pio_read_8(ioport8_t *port)
    8398{
    84         uintptr_t prt = (uintptr_t) port;
     99        uint8_t v;
    85100
    86101        asm volatile ("mf\n" ::: "memory");
    87102
    88         return *((ioport8_t *)(IA64_IOSPACE_ADDRESS +
    89             ((prt & 0xfff) | ((prt >> 2) << 12))));
     103        if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
     104                uintptr_t prt = (uintptr_t) port;
     105
     106                v = *((ioport8_t *)(IA64_IOSPACE_ADDRESS +
     107                    ((prt & 0xfff) | ((prt >> 2) << 12))));
     108        } else {
     109                v = *port;
     110        }
     111
     112        asm volatile ("mf.a\n" ::: "memory");
     113
     114        return v;
    90115}
    91116
    92117static inline uint16_t pio_read_16(ioport16_t *port)
    93118{
    94         uintptr_t prt = (uintptr_t) port;
     119        uint16_t v;
    95120
    96121        asm volatile ("mf\n" ::: "memory");
    97122
    98         return *((ioport16_t *)(IA64_IOSPACE_ADDRESS +
    99             ((prt & 0xfff) | ((prt >> 2) << 12))));
     123        if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
     124                uintptr_t prt = (uintptr_t) port;
     125
     126                v = *((ioport16_t *)(IA64_IOSPACE_ADDRESS +
     127                    ((prt & 0xfff) | ((prt >> 2) << 12))));
     128        } else {
     129                v = *port;
     130        }
     131
     132        asm volatile ("mf.a\n" ::: "memory");
     133
     134        return v;
    100135}
    101136
    102137static inline uint32_t pio_read_32(ioport32_t *port)
    103138{
    104         uintptr_t prt = (uintptr_t) port;
     139        uint32_t v;
    105140
    106141        asm volatile ("mf\n" ::: "memory");
    107142
    108         return *((ioport32_t *)(IA64_IOSPACE_ADDRESS +
    109             ((prt & 0xfff) | ((prt >> 2) << 12))));
     143        if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
     144                uintptr_t prt = (uintptr_t) port;
     145
     146                v = *((ioport32_t *)(IA64_IOSPACE_ADDRESS +
     147                    ((prt & 0xfff) | ((prt >> 2) << 12))));
     148        } else {
     149                v = *port;
     150        }
     151
     152        asm volatile ("mf.a\n" ::: "memory");
     153
     154        return v;
    110155}
    111156
  • uspace/lib/c/arch/ia64/include/fibril.h

    rb69e4c0 rdb96017  
    2727 */
    2828
    29 /** @addtogroup libcia64       
     29/** @addtogroup libcia64
    3030 * @{
    3131 */
     
    4545 * No need to allocate scratch area.
    4646 */
    47 #define SP_DELTA        (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     47#define SP_DELTA  (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
    4848
    49 #define PFM_MASK        (~0x3fffffffff)
     49#define PFM_MASK  (~0x3fffffffff)
    5050
    51 #define PSTHREAD_INITIAL_STACK_PAGES_NO 2
     51#define PSTHREAD_INITIAL_STACK_PAGES_NO  2
     52
    5253/* Stack is divided into two equal parts (for memory stack and register stack). */
    53 #define PSTHREAD_INITIAL_STACK_DIVISION
     54#define PSTHREAD_INITIAL_STACK_DIVISION  2
    5455
    55 #define context_set(c, _pc, stack, size, tls)                                                           \
    56         do {                                                                                            \
    57                 (c)->pc = (uint64_t) _pc;                                                               \
    58                 (c)->bsp = ((uint64_t) stack) + size / PSTHREAD_INITIAL_STACK_DIVISION;                                                         \
    59                 (c)->ar_pfs &= PFM_MASK;                                                                \
    60                 (c)->sp = ((uint64_t) stack) + ALIGN_UP((size / PSTHREAD_INITIAL_STACK_DIVISION), STACK_ALIGNMENT) - SP_DELTA;          \
    61                 (c)->tp = (uint64_t) tls;                                                               \
    62         } while (0);
    63        
     56#define context_set(c, _pc, stack, size, tls) \
     57        do { \
     58                (c)->pc = (uint64_t) _pc; \
     59                (c)->bsp = ((uint64_t) stack) + \
     60                    size / PSTHREAD_INITIAL_STACK_DIVISION; \
     61                (c)->ar_pfs &= PFM_MASK; \
     62                (c)->sp = ((uint64_t) stack) + \
     63                    ALIGN_UP((size / PSTHREAD_INITIAL_STACK_DIVISION), STACK_ALIGNMENT) - \
     64                    SP_DELTA; \
     65                (c)->tp = (uint64_t) tls; \
     66        } while (0)
    6467
    6568/*
  • uspace/lib/c/arch/mips32/Makefile.inc

    rb69e4c0 rdb96017  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
    31         arch/$(UARCH)/src/entryjmp.s \
    32         arch/$(UARCH)/src/thread_entry.s \
     30        arch/$(UARCH)/src/entry.S \
     31        arch/$(UARCH)/src/entryjmp.S \
     32        arch/$(UARCH)/src/thread_entry.S \
    3333        arch/$(UARCH)/src/syscall.c \
    3434        arch/$(UARCH)/src/fibril.S \
  • uspace/lib/c/arch/mips32/include/atomic.h

    rb69e4c0 rdb96017  
    6767                "       ll %0, %1\n"
    6868                "       addu %0, %0, %3\n"      /* same as add, but never traps on overflow */
    69                 "       move %2, %0\n"
     69                "       move %2, %0\n"
    7070                "       sc %0, %1\n"
    7171                "       beq %0, %4, 1b\n"       /* if the atomic operation failed, try again */
  • uspace/lib/c/arch/mips32/include/config.h

    rb69e4c0 rdb96017  
    3636#define LIBC_mips32_CONFIG_H_
    3737
    38 #define PAGE_WIDTH      14
    39 #define PAGE_SIZE       (1 << PAGE_WIDTH)
     38#define PAGE_WIDTH  14
     39#define PAGE_SIZE   (1 << PAGE_WIDTH)
    4040
    4141#endif
  • uspace/lib/c/arch/mips32/include/faddr.h

    rb69e4c0 rdb96017  
    3838#include <libarch/types.h>
    3939
    40 #define FADDR(fptr)             ((uintptr_t) (fptr))
     40#define FADDR(fptr)  ((uintptr_t) (fptr))
    4141
    4242#endif
  • uspace/lib/c/arch/mips32/include/fibril.h

    rb69e4c0 rdb96017  
    3838
    3939#include <sys/types.h>
     40#include <libarch/stack.h>
     41#include <align.h>
    4042
    41 /* We define our own context_set, because we need to set
    42  * the TLS pointer to the tcb+0x7000
     43#define SP_DELTA  (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     44
     45/*
     46 * We define our own context_set, because we need to set
     47 * the TLS pointer to the tcb + 0x7000
    4348 *
    4449 * See tls_set in thread.h
    4550 */
    46 #define context_set(c, _pc, stack, size, ptls)                  \
    47         (c)->pc = (sysarg_t) (_pc);                             \
    48         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;     \
    49         (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t);
    50 
    51 
    52 /* +16 is just for sure that the called function
    53  * have space to store it's arguments
    54  */
    55 #define SP_DELTA        (8+16)
     51#define context_set(c, _pc, stack, size, ptls) \
     52        do { \
     53                (c)->pc = (sysarg_t) (_pc); \
     54                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     55                (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); \
     56        } while (0)
    5657
    5758typedef struct  {
  • uspace/lib/c/arch/mips32/src/entry.S

    rb69e4c0 rdb96017  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .init, "ax"
     
    4143.ent __entry
    4244__entry:
    43         .frame $sp, 32, $31
    44         .cpload $25
     45        .frame $sp, ABI_STACK_FRAME, $ra
     46        .cpload $t9
    4547       
    46         # FIXME: Reflect exactly ABI specs here
     48        # Allocate the stack frame.
     49        addiu $sp, -ABI_STACK_FRAME
    4750       
    48         addiu $sp, -32
    49         .cprestore 16   # Allow PIC code
     51        # Allow PIC code
     52        .cprestore 16
    5053       
    51         # Pass pcb_ptr to __main() as the first argument. pcb_ptr is already
     54        # Pass pcb_ptr to __main() as the first argument. It is already
    5255        # in $a0. As the first argument is passed in $a0, no operation
    5356        # is needed.
     
    5558        jal __main
    5659        nop
    57 .end
     60       
     61        #
     62        # Not reached.
     63        #
     64        addiu $sp, ABI_STACK_FRAME
     65.end __entry
  • uspace/lib/c/arch/mips32/src/entryjmp.S

    rb69e4c0 rdb96017  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .text
     
    4143entry_point_jmp:
    4244        # tmp := entry_point
    43         move $25, $a0
     45        move $t9, $a0
    4446       
    4547        # Pass pcb to the entry point in $a0
    4648        move $a0, $a1
    47         jr $25
    48         nop
    49 .end
     49       
     50        jr $t9
     51        addiu $sp, -ABI_STACK_FRAME
     52        addiu $sp, ABI_STACK_FRAME
     53.end entry_point_jmp
  • uspace/lib/c/arch/mips32/src/fibril.S

    rb69e4c0 rdb96017  
    3333
    3434#include <libarch/context_offset.h>
    35        
     35
    3636.global context_save
    3737.global context_restore
    38        
     38
    3939context_save:
    4040        CONTEXT_SAVE_ARCH_CORE $a0
    41 
     41       
    4242        # context_save returns 1
    4343        j $ra
    44         li $v0, 1       
    45        
     44        li $v0, 1
     45
    4646context_restore:
    4747        CONTEXT_RESTORE_ARCH_CORE $a0
    48 
    49         # Just for the jump into first function, but one instruction
    50         # should not bother us
    51         move $t9, $ra   
     48       
     49        # Just for the jump into first function,
     50        # but one instruction should not bother us
     51        move $t9, $ra
     52       
    5253        # context_restore returns 0
    5354        j $ra
    54         xor $v0, $v0   
    55 
     55        xor $v0, $v0
  • uspace/lib/c/arch/mips32/src/syscall.c

    rb69e4c0 rdb96017  
    5757                  "r" (__mips_reg_t1),
    5858                  "r" (__mips_reg_v0)
    59                 : "%ra" /* We are a function call, although C does not
    60                          * know it */
     59                /*
     60                 * We are a function call, although C
     61                 * does not know it.
     62                 */
     63                : "%ra"
    6164        );
    6265       
  • uspace/lib/c/arch/mips32/src/thread_entry.S

    rb69e4c0 rdb96017  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032
     
    4042.ent __thread_entry
    4143__thread_entry:
    42         .frame $sp, 32, $31
    43         .cpload $25
     44        .frame $sp, ABI_STACK_FRAME, $ra
     45        .cpload $t9
    4446       
    4547        #
    4648        # v0 contains address of uarg.
    4749        #
    48         add $4, $2, 0
     50        add $a0, $v0, 0
    4951       
    50         addiu $sp, -32
     52        # Allocate the stack frame.
     53        addiu $sp, -ABI_STACK_FRAME
     54       
     55        # Allow PIC code
    5156        .cprestore 16
    5257       
     
    5762        # Not reached.
    5863        #
     64        addiu $sp, ABI_STACK_FRAME
    5965.end __thread_entry
  • uspace/lib/c/arch/mips32eb/Makefile.inc

    rb69e4c0 rdb96017  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
    31         arch/$(UARCH)/src/entryjmp.s \
    32         arch/$(UARCH)/src/thread_entry.s \
     30        arch/$(UARCH)/src/entry.S \
     31        arch/$(UARCH)/src/entryjmp.S \
     32        arch/$(UARCH)/src/thread_entry.S \
    3333        arch/$(UARCH)/src/syscall.c \
    3434        arch/$(UARCH)/src/fibril.S \
  • uspace/lib/c/arch/mips64/Makefile.inc

    rb69e4c0 rdb96017  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
    31         arch/$(UARCH)/src/entryjmp.s \
    32         arch/$(UARCH)/src/thread_entry.s \
     30        arch/$(UARCH)/src/entry.S \
     31        arch/$(UARCH)/src/entryjmp.S \
     32        arch/$(UARCH)/src/thread_entry.S \
    3333        arch/$(UARCH)/src/syscall.c \
    3434        arch/$(UARCH)/src/fibril.S \
  • uspace/lib/c/arch/mips64/include/fibril.h

    rb69e4c0 rdb96017  
    3838
    3939#include <sys/types.h>
     40#include <libarch/stack.h>
     41#include <align.h>
    4042
    41 /* We define our own context_set, because we need to set
    42  * the TLS pointer to the tcb+0x7000
     43#define SP_DELTA  (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     44
     45/*
     46 * We define our own context_set, because we need to set
     47 * the TLS pointer to the tcb + 0x7000
    4348 *
    4449 * See tls_set in thread.h
    4550 */
    4651#define context_set(c, _pc, stack, size, ptls) \
    47         (c)->pc = (sysarg_t) (_pc); \
    48         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
    49         (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t);
    50 
    51 /* +16 is just for sure that the called function
    52  * have space to store it's arguments
    53  */
    54 #define SP_DELTA  (8 + 16)
     52        do { \
     53                (c)->pc = (sysarg_t) (_pc); \
     54                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     55                (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); \
     56        } while (0)
    5557
    5658typedef struct {
  • uspace/lib/c/arch/mips64/src/entry.S

    rb69e4c0 rdb96017  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .init, "ax"
     
    4143.ent __entry
    4244__entry:
    43         .frame $sp, 32, $31
    44         .cpload $25
    45 
    46         # Mips o32 may store its arguments on stack, make space (16 bytes),
    47         # so that it could work with -O0
    48         # Make space additional 16 bytes for the stack frame
    49 
    50         addiu $sp, -32
    51         .cprestore 16   # Allow PIC code
    52 
    53         # Pass pcb_ptr to __main() as the first argument. pcb_ptr is already
     45        .frame $sp, ABI_STACK_FRAME, $ra
     46        .cpload $t9
     47       
     48        # Allocate the stack frame.
     49        addiu $sp, -ABI_STACK_FRAME
     50       
     51        # Allow PIC code
     52        .cprestore 16
     53       
     54        # Pass pcb_ptr to __main() as the first argument. It is already
    5455        # in $a0. As the first argument is passed in $a0, no operation
    5556        # is needed.
    56 
     57       
    5758        jal __main
    5859        nop
    59 .end
     60       
     61        #
     62        # Not reached.
     63        #
     64        addiu $sp, ABI_STACK_FRAME
     65.end __entry
  • uspace/lib/c/arch/mips64/src/entryjmp.S

    rb69e4c0 rdb96017  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .text
     
    3436## void entry_point_jmp(void *entry_point, void *pcb);
    3537#
    36 # $a0 (=$4)     contains entry_point
    37 # $a1 (=$5)     contains pcb
     38# $a0 (=$4) contains entry_point
     39# $a1 (=$5) contains pcb
    3840#
    3941# Jump to program entry point
     
    4143entry_point_jmp:
    4244        # tmp := entry_point
    43         move $25, $a0
    44 
     45        move $t9, $a0
     46       
    4547        # Pass pcb to the entry point in $a0
    4648        move $a0, $a1
    47         jr $25
    48         nop
    49 .end
     49       
     50        jr $t9
     51        addiu $sp, -ABI_STACK_FRAME
     52        addiu $sp, ABI_STACK_FRAME
     53.end entry_point_jmp
  • uspace/lib/c/arch/mips64/src/thread_entry.S

    rb69e4c0 rdb96017  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    30        
     32
    3133.set noat
    3234.set noreorder
    3335.option pic2
    34        
     36
    3537.globl __thread_entry
    3638
     
    4042.ent __thread_entry
    4143__thread_entry:
    42         .frame $sp, 32, $31
    43         .cpload $25
    44 
     44        .frame $sp, ABI_STACK_FRAME, $ra
     45        .cpload $t9
     46       
    4547        #
    4648        # v0 contains address of uarg.
    4749        #
    48         add $4, $2, 0
    49         # Mips o32 may store its arguments on stack, make space
    50         addiu $sp, -32
     50        add $a0, $v0, 0
     51       
     52        # Allocate the stack frame.
     53        addiu $sp, -ABI_STACK_FRAME
     54       
     55        # Allow PIC code
    5156        .cprestore 16
    5257       
    5358        jal __thread_main
    5459        nop
    55                
     60       
    5661        #
    5762        # Not reached.
    5863        #
     64        addiu $sp, ABI_STACK_FRAME
    5965.end __thread_entry
  • uspace/lib/c/arch/ppc32/include/fibril.h

    rb69e4c0 rdb96017  
    2727 */
    2828
    29 /** @addtogroup libcppc32       
     29/** @addtogroup libcppc32
    3030 * @{
    3131 */
     
    3838#include <sys/types.h>
    3939
    40 /* We define our own context_set, because we need to set
    41  * the TLS pointer to the tcb+0x7000
     40#define SP_DELTA  16
     41
     42/*
     43 * We define our own context_set, because we need to set
     44 * the TLS pointer to the tcb + 0x7000
    4245 *
    4346 * See tls_set in thread.h
    4447 */
    45 #define context_set(c, _pc, stack, size, ptls)                  \
    46         (c)->pc = (sysarg_t) (_pc);                             \
    47         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;     \
    48         (c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t);
    49 
    50 #define SP_DELTA        16
     48#define context_set(c, _pc, stack, size, ptls) \
     49        do { \
     50                (c)->pc = (sysarg_t) (_pc); \
     51                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     52                (c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t); \
     53        } while (0)
    5154
    5255typedef struct {
  • uspace/lib/c/arch/sparc64/include/fibril.h

    rb69e4c0 rdb96017  
    4040#include <align.h>
    4141
    42 #define SP_DELTA        (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE)
     42#define SP_DELTA  (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE)
    4343
    4444#define context_set(c, _pc, stack, size, ptls) \
     
    5050                (c)->tp = (uint64_t) ptls; \
    5151        } while (0)
    52        
     52
    5353/*
    5454 * Save only registers that must be preserved across
  • uspace/lib/c/generic/adt/hash_table.c

    rb69e4c0 rdb96017  
    7676       
    7777        return true;
     78}
     79
     80/** Remove all elements from the hash table
     81 *
     82 * @param h Hash table to be cleared
     83 */
     84void hash_table_clear(hash_table_t *h)
     85{
     86        for (hash_count_t chain = 0; chain < h->entries; ++chain) {
     87                link_t *cur;
     88                link_t *next;
     89               
     90                for (cur = h->entry[chain].head.next;
     91                    cur != &h->entry[chain].head;
     92                    cur = next) {
     93                        next = cur->next;
     94                        list_remove(cur);
     95                        h->op->remove_callback(cur);
     96                }
     97        }
    7898}
    7999
     
    198218 */
    199219void hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg)
    200 {
    201         hash_index_t bucket;
    202        
    203         for (bucket = 0; bucket < h->entries; bucket++) {
    204                 list_foreach(h->entry[bucket], cur) {
     220{       
     221        for (hash_index_t bucket = 0; bucket < h->entries; bucket++) {
     222                link_t *cur;
     223                link_t *next;
     224
     225                for (cur = h->entry[bucket].head.next; cur != &h->entry[bucket].head;
     226                    cur = next) {
     227                        /*
     228                         * The next pointer must be stored prior to the functor
     229                         * call to allow using destructor as the functor (the
     230                         * free function could overwrite the cur->next pointer).
     231                         */
     232                        next = cur->next;
    205233                        f(cur, arg);
    206234                }
  • uspace/lib/c/generic/as.c

    rb69e4c0 rdb96017  
    4545/** Create address space area.
    4646 *
    47  * @param address Virtual address where to place new address space area.
    48  * @param size    Size of the area.
    49  * @param flags   Flags describing type of the area.
     47 * @param base  Starting virtual address of the area.
     48 *              If set to (void *) -1, the kernel finds
     49 *              a mappable area.
     50 * @param size  Size of the area.
     51 * @param flags Flags describing type of the area.
    5052 *
    51  * @return address on success, (void *) -1 otherwise.
     53 * @return Starting virtual address of the created area on success.
     54 * @return (void *) -1 otherwise.
    5255 *
    5356 */
    54 void *as_area_create(void *address, size_t size, unsigned int flags)
     57void *as_area_create(void *base, size_t size, unsigned int flags)
    5558{
    56         return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address,
    57             (sysarg_t) size, (sysarg_t) flags);
     59        return (void *) __SYSCALL4(SYS_AS_AREA_CREATE, (sysarg_t) base,
     60            (sysarg_t) size, (sysarg_t) flags, (sysarg_t) __entry);
    5861}
    5962
     
    102105}
    103106
    104 /** Return pointer to unmapped address space area
     107/** Find mapping to physical address.
    105108 *
    106  * @param size Requested size of the allocation.
     109 * @param      virt Virtual address to find mapping for.
     110 * @param[out] phys Physical adress.
    107111 *
    108  * @return Pointer to the beginning of unmapped address space area.
     112 * @return EOK on no error.
     113 * @retval ENOENT if no mapping was found.
    109114 *
    110115 */
    111 void *as_get_mappable_page(size_t size)
     116int as_get_physical_mapping(const void *virt, uintptr_t *phys)
    112117{
    113         return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA,
    114             (sysarg_t) __entry, (sysarg_t) size);
    115 }
    116 
    117 /** Find mapping to physical address.
    118  *
    119  * @param address Virtual address in question (virtual).
    120  * @param[out] frame Frame address (physical).
    121  * @return Error code.
    122  * @retval EOK No error, @p frame holds the translation.
    123  * @retval ENOENT Mapping not found.
    124  */
    125 int as_get_physical_mapping(const void *address, uintptr_t *frame)
    126 {
    127         uintptr_t tmp_frame;
    128         uintptr_t virt = (uintptr_t) address;
    129        
    130         int rc = (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING,
    131             (sysarg_t) virt, (sysarg_t) &tmp_frame);
    132         if (rc != EOK) {
    133                 return rc;
    134         }
    135        
    136         if (frame != NULL) {
    137                 *frame = tmp_frame;
    138         }
    139        
    140         return EOK;
     118        return (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING, (sysarg_t) virt,
     119            (sysarg_t) phys);
    141120}
    142121
  • uspace/lib/c/generic/async.c

    rb69e4c0 rdb96017  
    257257void async_set_client_data_constructor(async_client_data_ctor_t ctor)
    258258{
     259        assert(async_client_data_create == default_client_data_constructor);
    259260        async_client_data_create = ctor;
    260261}
     
    262263void async_set_client_data_destructor(async_client_data_dtor_t dtor)
    263264{
     265        assert(async_client_data_destroy == default_client_data_destructor);
    264266        async_client_data_destroy = dtor;
    265267}
     
    303305void async_set_client_connection(async_client_conn_t conn)
    304306{
     307        assert(client_connection == default_client_connection);
    305308        client_connection = conn;
    306309}
     
    18481851       
    18491852        int rc = async_hangup_internal(sess->phone);
    1850         if (rc == EOK)
    1851                 free(sess);
    18521853       
    18531854        while (!list_empty(&sess->exch_list)) {
     
    18611862                free(exch);
    18621863        }
     1864
     1865        free(sess);
    18631866       
    18641867        fibril_mutex_unlock(&async_sess_mutex);
     
    19982001 *
    19992002 * @param exch  Exchange for sending the message.
    2000  * @param dst   Destination address space area base.
    20012003 * @param size  Size of the destination address space area.
    20022004 * @param arg   User defined argument.
    20032005 * @param flags Storage for the received flags. Can be NULL.
     2006 * @param dst   Destination address space area base. Cannot be NULL.
    20042007 *
    20052008 * @return Zero on success or a negative error code from errno.h.
    20062009 *
    20072010 */
    2008 int async_share_in_start(async_exch_t *exch, void *dst, size_t size,
    2009     sysarg_t arg, unsigned int *flags)
     2011int async_share_in_start(async_exch_t *exch, size_t size, sysarg_t arg,
     2012    unsigned int *flags, void **dst)
    20102013{
    20112014        if (exch == NULL)
    20122015                return ENOENT;
    20132016       
    2014         sysarg_t tmp_flags;
    2015         int res = async_req_3_2(exch, IPC_M_SHARE_IN, (sysarg_t) dst,
    2016             (sysarg_t) size, arg, NULL, &tmp_flags);
     2017        sysarg_t _flags = 0;
     2018        sysarg_t _dst = (sysarg_t) -1;
     2019        int res = async_req_2_4(exch, IPC_M_SHARE_IN, (sysarg_t) size,
     2020            arg, NULL, &_flags, NULL, &_dst);
    20172021       
    20182022        if (flags)
    2019                 *flags = (unsigned int) tmp_flags;
    2020        
     2023                *flags = (unsigned int) _flags;
     2024       
     2025        *dst = (void *) _dst;
    20212026        return res;
    20222027}
     
    20472052                return false;
    20482053       
    2049         *size = (size_t) IPC_GET_ARG2(data);
     2054        *size = (size_t) IPC_GET_ARG1(data);
    20502055        return true;
    20512056}
     
    20532058/** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework.
    20542059 *
    2055  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     2060 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_IN
    20562061 * calls so that the user doesn't have to remember the meaning of each IPC
    20572062 * argument.
     
    21312136 *
    21322137 */
    2133 int async_share_out_finalize(ipc_callid_t callid, void *dst)
     2138int async_share_out_finalize(ipc_callid_t callid, void **dst)
    21342139{
    21352140        return ipc_share_out_finalize(callid, dst);
  • uspace/lib/c/generic/ddi.c

    rb69e4c0 rdb96017  
    3333 */
    3434
     35#include <assert.h>
     36#include <unistd.h>
     37#include <errno.h>
    3538#include <sys/types.h>
    3639#include <abi/ddi/arg.h>
     
    4245#include <align.h>
    4346#include <libarch/config.h>
     47#include "private/libc.h"
    4448
    4549/** Return unique device number.
     
    5357}
    5458
    55 /** Map piece of physical memory to task.
     59/** Map a piece of physical memory to task.
    5660 *
    5761 * Caller of this function must have the CAP_MEM_MANAGER capability.
    5862 *
    59  * @param pf            Physical address of the starting frame.
    60  * @param vp            Virtual address of the starting page.
    61  * @param pages         Number of pages to map.
    62  * @param flags         Flags for the new address space area.
     63 * @param phys  Physical address of the starting frame.
     64 * @param pages Number of pages to map.
     65 * @param flags Flags for the new address space area.
     66 * @param virt  Virtual address of the starting page.
    6367 *
    64  * @return              0 on success, EPERM if the caller lacks the
    65  *                      CAP_MEM_MANAGER capability, ENOENT if there is no task
    66  *                      with specified ID and ENOMEM if there was some problem
    67  *                      in creating address space area.
     68 * @return EOK on success
     69 * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability
     70 * @return ENOENT if there is no task with specified ID
     71 * @return ENOMEM if there was some problem in creating
     72 *         the address space area.
     73 *
    6874 */
    69 int physmem_map(void *pf, void *vp, unsigned long pages, int flags)
     75int physmem_map(void *phys, size_t pages, unsigned int flags, void **virt)
    7076{
    71         return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp, pages,
    72             flags);
     77        return __SYSCALL5(SYS_PHYSMEM_MAP, (sysarg_t) phys,
     78            pages, flags, (sysarg_t) virt, (sysarg_t) __entry);
     79}
     80
     81int dmamem_map(void *virt, size_t size, unsigned int map_flags,
     82    unsigned int flags, void **phys)
     83{
     84        return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size,
     85            (sysarg_t) map_flags, (sysarg_t) flags & ~DMAMEM_FLAGS_ANONYMOUS,
     86            (sysarg_t) phys, (sysarg_t) virt, 0);
     87}
     88
     89int dmamem_map_anonymous(size_t size, unsigned int map_flags,
     90    unsigned int flags, void **phys, void **virt)
     91{
     92        return (int) __SYSCALL6(SYS_DMAMEM_MAP, (sysarg_t) size,
     93            (sysarg_t) map_flags, (sysarg_t) flags | DMAMEM_FLAGS_ANONYMOUS,
     94            (sysarg_t) phys, (sysarg_t) virt, (sysarg_t) __entry);
     95}
     96
     97int dmamem_unmap(void *virt, size_t size)
     98{
     99        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size, 0);
     100}
     101
     102int dmamem_unmap_anonymous(void *virt)
     103{
     104        return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, 0,
     105            DMAMEM_FLAGS_ANONYMOUS);
    73106}
    74107
     
    77110 * Caller of this function must have the IO_MEM_MANAGER capability.
    78111 *
    79  * @param id            Task ID.
    80  * @param ioaddr        Starting address of the I/O range.
    81  * @param size          Size of the range.
     112 * @param id     Task ID.
     113 * @param ioaddr Starting address of the I/O range.
     114 * @param size   Size of the range.
    82115 *
    83  * @return              0 on success, EPERM if the caller lacks the
    84  *                      CAP_IO_MANAGER capability, ENOENT if there is no task
    85  *                      with specified ID and ENOMEM if there was some problem
    86  *                      in allocating memory.
     116 * @return EOK on success
     117 * @return EPERM if the caller lacks the CAP_IO_MANAGER capability
     118 * @return ENOENT if there is no task with specified ID
     119 * @return ENOMEM if there was some problem in allocating memory.
     120 *
    87121 */
    88122int iospace_enable(task_id_t id, void *ioaddr, unsigned long size)
    89123{
    90124        ddi_ioarg_t arg;
    91 
     125       
    92126        arg.task_id = id;
    93127        arg.ioaddr = ioaddr;
    94128        arg.size = size;
    95 
     129       
    96130        return __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg);
    97131}
     
    99133/** Enable PIO for specified I/O range.
    100134 *
    101  * @param pio_addr      I/O start address.
    102  * @param size          Size of the I/O region.
    103  * @param use_addr      Address where the final address for application's PIO
    104  *                      will be stored.
     135 * @param pio_addr I/O start address.
     136 * @param size     Size of the I/O region.
     137 * @param virt     Virtual address for application's
     138 *                 PIO operations.
    105139 *
    106  * @return              Zero on success or negative error code.
     140 * @return EOK on success.
     141 * @return Negative error code on failure.
     142 *
    107143 */
    108 int pio_enable(void *pio_addr, size_t size, void **use_addr)
     144int pio_enable(void *pio_addr, size_t size, void **virt)
    109145{
    110         void *phys;
    111         void *virt;
    112         size_t offset;
    113         unsigned int pages;
    114 
    115146#ifdef IO_SPACE_BOUNDARY
    116147        if (pio_addr < IO_SPACE_BOUNDARY) {
    117                 *use_addr = pio_addr;
     148                *virt = pio_addr;
    118149                return iospace_enable(task_get_id(), pio_addr, size);
    119150        }
    120151#endif
    121 
    122         phys = (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
    123         offset = pio_addr - phys;
    124         pages = ALIGN_UP(offset + size, PAGE_SIZE) >> PAGE_WIDTH;
    125         virt = as_get_mappable_page(pages << PAGE_WIDTH);
    126         *use_addr = virt + offset;
    127         return physmem_map(phys, virt, pages, AS_AREA_READ | AS_AREA_WRITE);
     152       
     153        void *phys_frame =
     154            (void *) ALIGN_DOWN((uintptr_t) pio_addr, PAGE_SIZE);
     155        size_t offset = pio_addr - phys_frame;
     156        size_t pages = SIZE2PAGES(offset + size);
     157       
     158        void *virt_page;
     159        int rc = physmem_map(phys_frame, pages,
     160            AS_AREA_READ | AS_AREA_WRITE, &virt_page);
     161        if (rc != EOK)
     162                return rc;
     163       
     164        *virt = virt_page + offset;
     165        return EOK;
    128166}
    129167
     
    138176 *
    139177 */
    140 int register_irq(int inr, int devno, int method, irq_code_t *ucode)
     178int irq_register(int inr, int devno, int method, irq_code_t *ucode)
    141179{
    142         return __SYSCALL4(SYS_REGISTER_IRQ, inr, devno, method,
     180        return __SYSCALL4(SYS_IRQ_REGISTER, inr, devno, method,
    143181            (sysarg_t) ucode);
    144182}
     
    152190 *
    153191 */
    154 int unregister_irq(int inr, int devno)
     192int irq_unregister(int inr, int devno)
    155193{
    156         return __SYSCALL2(SYS_UNREGISTER_IRQ, inr, devno);
     194        return __SYSCALL2(SYS_IRQ_UNREGISTER, inr, devno);
    157195}
    158196
  • uspace/lib/c/generic/devman.c

    rb69e4c0 rdb96017  
    177177
    178178/** Register running driver with device manager. */
    179 int devman_driver_register(const char *name, async_client_conn_t conn)
     179int devman_driver_register(const char *name)
    180180{
    181181        async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER);
     
    192192        }
    193193       
    194         async_set_client_connection(conn);
    195        
    196194        exch = devman_exchange_begin(DEVMAN_DRIVER);
    197         async_connect_to_me(exch, 0, 0, 0, conn, NULL);
     195        async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
    198196        devman_exchange_end(exch);
    199197       
  • uspace/lib/c/generic/elf/elf_load.c

    rb69e4c0 rdb96017  
    364364         * and writeable.
    365365         */
    366         a = as_area_create((uint8_t *)base + bias, mem_sz,
     366        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 == (void *) -1) {
    369369                DPRINTF("memory mapping failed (0x%x, %d)\n",
    370                         base+bias, mem_sz);
     370                    base + bias, mem_sz);
    371371                return EE_MEMORY;
    372372        }
  • uspace/lib/c/generic/fibril_synch.c

    rb69e4c0 rdb96017  
    447447}
    448448
     449/** Timer fibril.
     450 *
     451 * @param arg   Timer
     452 */
     453static int fibril_timer_func(void *arg)
     454{
     455        fibril_timer_t *timer = (fibril_timer_t *) arg;
     456        int rc;
     457
     458        fibril_mutex_lock(&timer->lock);
     459
     460        while (true) {
     461                while (timer->state != fts_active &&
     462                    timer->state != fts_cleanup) {
     463
     464                        if (timer->state == fts_cleanup)
     465                                break;
     466
     467                        fibril_condvar_wait(&timer->cv, &timer->lock);
     468                }
     469
     470                if (timer->state == fts_cleanup)
     471                        break;
     472
     473                rc = fibril_condvar_wait_timeout(&timer->cv, &timer->lock,
     474                    timer->delay);
     475                if (rc == ETIMEOUT) {
     476                        timer->state = fts_fired;
     477                        fibril_mutex_unlock(&timer->lock);
     478                        timer->fun(timer->arg);
     479                        fibril_mutex_lock(&timer->lock);
     480                }
     481        }
     482
     483        fibril_mutex_unlock(&timer->lock);
     484        return 0;
     485}
     486
     487/** Create new timer.
     488 *
     489 * @return              New timer on success, @c NULL if out of memory.
     490 */
     491fibril_timer_t *fibril_timer_create(void)
     492{
     493        fid_t fid;
     494        fibril_timer_t *timer;
     495
     496        timer = calloc(1, sizeof(fibril_timer_t));
     497        if (timer == NULL)
     498                return NULL;
     499
     500        fid = fibril_create(fibril_timer_func, (void *) timer);
     501        if (fid == 0) {
     502                free(timer);
     503                return NULL;
     504        }
     505
     506        fibril_mutex_initialize(&timer->lock);
     507        fibril_condvar_initialize(&timer->cv);
     508
     509        timer->fibril = fid;
     510        timer->state = fts_not_set;
     511
     512        fibril_add_ready(fid);
     513
     514        return timer;
     515}
     516
     517/** Destroy timer.
     518 *
     519 * @param timer         Timer, must not be active or accessed by other threads.
     520 */
     521void fibril_timer_destroy(fibril_timer_t *timer)
     522{
     523        fibril_mutex_lock(&timer->lock);
     524        assert(timer->state != fts_active);
     525        timer->state = fts_cleanup;
     526        fibril_condvar_broadcast(&timer->cv);
     527        fibril_mutex_unlock(&timer->lock);
     528}
     529
     530/** Set timer.
     531 *
     532 * Set timer to execute a callback function after the specified
     533 * interval.
     534 *
     535 * @param timer         Timer
     536 * @param delay         Delay in microseconds
     537 * @param fun           Callback function
     538 * @param arg           Argument for @a fun
     539 */
     540void fibril_timer_set(fibril_timer_t *timer, suseconds_t delay,
     541    fibril_timer_fun_t fun, void *arg)
     542{
     543        fibril_mutex_lock(&timer->lock);
     544        timer->state = fts_active;
     545        timer->delay = delay;
     546        timer->fun = fun;
     547        timer->arg = arg;
     548        fibril_condvar_broadcast(&timer->cv);
     549        fibril_mutex_unlock(&timer->lock);
     550}
     551
     552/** Clear timer.
     553 *
     554 * Clears (cancels) timer and returns last state of the timer.
     555 * This can be one of:
     556 *    - fts_not_set     If the timer has not been set or has been cleared
     557 *    - fts_active      Timer was set but did not fire
     558 *    - fts_fired       Timer fired
     559 *
     560 * @param timer         Timer
     561 * @return              Last timer state
     562 */
     563fibril_timer_state_t fibril_timer_clear(fibril_timer_t *timer)
     564{
     565        fibril_timer_state_t old_state;
     566
     567        fibril_mutex_lock(&timer->lock);
     568        old_state = timer->state;
     569        timer->state = fts_not_set;
     570
     571        timer->delay = 0;
     572        timer->fun = NULL;
     573        timer->arg = NULL;
     574        fibril_condvar_broadcast(&timer->cv);
     575        fibril_mutex_unlock(&timer->lock);
     576
     577        return old_state;
     578}
     579
    449580/** @}
    450581 */
  • uspace/lib/c/generic/ipc.c

    rb69e4c0 rdb96017  
    4848#include <fibril.h>
    4949#include <macros.h>
     50#include "private/libc.h"
    5051
    5152/**
     
    760761 *
    761762 * @param phoneid Phone that will be used to contact the receiving side.
    762  * @param dst     Destination address space area base.
    763763 * @param size    Size of the destination address space area.
    764764 * @param arg     User defined argument.
    765765 * @param flags   Storage for received flags. Can be NULL.
     766 * @param dst     Destination address space area base. Cannot be NULL.
    766767 *
    767768 * @return Zero on success or a negative error code from errno.h.
    768769 *
    769770 */
    770 int ipc_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
    771     unsigned int *flags)
    772 {
    773         sysarg_t tmp_flags = 0;
    774         int res = ipc_call_sync_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,
    775             (sysarg_t) size, arg, NULL, &tmp_flags);
     771int ipc_share_in_start(int phoneid, size_t size, sysarg_t arg,
     772    unsigned int *flags, void **dst)
     773{
     774        sysarg_t _flags = 0;
     775        sysarg_t _dst = (sysarg_t) -1;
     776        int res = ipc_call_sync_2_4(phoneid, IPC_M_SHARE_IN, (sysarg_t) size,
     777            arg, NULL, &_flags, NULL, &_dst);
    776778       
    777779        if (flags)
    778                 *flags = (unsigned int) tmp_flags;
    779        
     780                *flags = (unsigned int) _flags;
     781       
     782        *dst = (void *) _dst;
    780783        return res;
    781784}
     
    783786/** Wrapper for answering the IPC_M_SHARE_IN calls.
    784787 *
    785  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     788 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_IN
    786789 * calls so that the user doesn't have to remember the meaning of each
    787790 * IPC argument.
     
    796799int ipc_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    797800{
    798         return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) flags);
     801        return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags,
     802            (sysarg_t) __entry);
    799803}
    800804
     
    826830 *
    827831 */
    828 int ipc_share_out_finalize(ipc_callid_t callid, void *dst)
    829 {
    830         return ipc_answer_1(callid, EOK, (sysarg_t) dst);
     832int ipc_share_out_finalize(ipc_callid_t callid, void **dst)
     833{
     834        return ipc_answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t) dst);
    831835}
    832836
  • uspace/lib/c/generic/loc.c

    rb69e4c0 rdb96017  
    4747static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
    4848static bool loc_callback_created = false;
     49static loc_cat_change_cb_t cat_change_cb = NULL;
    4950
    5051static async_sess_t *loc_supp_block_sess = NULL;
     
    5455static async_sess_t *loc_consumer_sess = NULL;
    5556
    56 static loc_cat_change_cb_t cat_change_cb = NULL;
    57 
    5857static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    5958{
    60         loc_cat_change_cb_t cb_fun;
    61        
    6259        while (true) {
    6360                ipc_call_t call;
     
    6966                }
    7067               
    71                 int retval;
    72                
    7368                switch (IPC_GET_IMETHOD(call)) {
    7469                case LOC_EVENT_CAT_CHANGE:
    7570                        fibril_mutex_lock(&loc_callback_mutex);
    76                         cb_fun = cat_change_cb;
    77                         if (cb_fun != NULL) {
     71                        loc_cat_change_cb_t cb_fun = cat_change_cb;
     72                        fibril_mutex_unlock(&loc_callback_mutex);
     73                       
     74                        async_answer_0(callid, EOK);
     75                       
     76                        if (cb_fun != NULL)
    7877                                (*cb_fun)();
    79                         }
    80                         fibril_mutex_unlock(&loc_callback_mutex);
    81                         retval = 0;
     78                       
    8279                        break;
    8380                default:
    84                         retval = ENOTSUP;
     81                        async_answer_0(callid, ENOTSUP);
    8582                }
    86                
    87                 async_answer_0(callid, retval);
    8883        }
    8984}
     
    10196}
    10297
     98/** Create callback
     99 *
     100 * Must be called with loc_callback_mutex locked.
     101 *
     102 * @return EOK on success.
     103 *
     104 */
    103105static int loc_callback_create(void)
    104106{
    105         async_exch_t *exch;
    106         sysarg_t retval;
    107         int rc = EOK;
    108 
    109         fibril_mutex_lock(&loc_callback_mutex);
    110        
    111107        if (!loc_callback_created) {
    112                 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     108                async_exch_t *exch =
     109                    loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
    113110               
    114111                ipc_call_t answer;
    115112                aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer);
    116                 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
     113                int rc = async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
    117114                loc_exchange_end(exch);
    118115               
     116                if (rc != EOK)
     117                        return rc;
     118               
     119                sysarg_t retval;
    119120                async_wait_for(req, &retval);
    120                 if (rc != EOK)
    121                         goto done;
    122                
    123                 if (retval != EOK) {
    124                         rc = retval;
    125                         goto done;
    126                 }
     121                if (retval != EOK)
     122                        return retval;
    127123               
    128124                loc_callback_created = true;
    129125        }
    130126       
    131         rc = EOK;
    132 done:
    133         fibril_mutex_unlock(&loc_callback_mutex);
    134         return rc;
     127        return EOK;
    135128}
    136129
     
    242235
    243236/** Register new driver with loc. */
    244 int loc_server_register(const char *name, async_client_conn_t conn)
     237int loc_server_register(const char *name)
    245238{
    246239        async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER);
     
    256249                return retval;
    257250        }
    258        
    259         async_set_client_connection(conn);
    260251       
    261252        exch = loc_exchange_begin(LOC_PORT_SUPPLIER);
     
    797788    sysarg_t **data, size_t *count)
    798789{
    799         service_id_t *ids;
    800         size_t act_size;
    801         size_t alloc_size;
    802         int rc;
    803 
    804790        *data = NULL;
    805         act_size = 0;   /* silence warning */
    806 
    807         rc = loc_category_get_ids_once(method, arg1, NULL, 0,
     791        *count = 0;
     792       
     793        size_t act_size = 0;
     794        int rc = loc_category_get_ids_once(method, arg1, NULL, 0,
    808795            &act_size);
    809796        if (rc != EOK)
    810797                return rc;
    811 
    812         alloc_size = act_size;
    813         ids = malloc(alloc_size);
     798       
     799        size_t alloc_size = act_size;
     800        service_id_t *ids = malloc(alloc_size);
    814801        if (ids == NULL)
    815802                return ENOMEM;
    816 
     803       
    817804        while (true) {
    818805                rc = loc_category_get_ids_once(method, arg1, ids, alloc_size,
     
    820807                if (rc != EOK)
    821808                        return rc;
    822 
     809               
    823810                if (act_size <= alloc_size)
    824811                        break;
    825 
    826                 alloc_size *= 2;
    827                 free(ids);
    828 
    829                 ids = malloc(alloc_size);
     812               
     813                alloc_size = act_size;
     814                ids = realloc(ids, alloc_size);
    830815                if (ids == NULL)
    831816                        return ENOMEM;
    832817        }
    833 
     818       
    834819        *count = act_size / sizeof(category_id_t);
    835820        *data = ids;
     
    869854int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
    870855{
    871         if (loc_callback_create() != EOK)
     856        fibril_mutex_lock(&loc_callback_mutex);
     857        if (loc_callback_create() != EOK) {
     858                fibril_mutex_unlock(&loc_callback_mutex);
    872859                return EIO;
    873 
     860        }
     861       
    874862        cat_change_cb = cb_fun;
     863        fibril_mutex_unlock(&loc_callback_mutex);
     864       
    875865        return EOK;
    876866}
  • uspace/lib/c/generic/malloc.c

    rb69e4c0 rdb96017  
    283283static bool area_create(size_t size)
    284284{
    285         void *start = as_get_mappable_page(size);
    286         if (start == NULL)
    287                 return false;
    288        
    289         /* Align the heap area on page boundary */
    290         void *astart = (void *) ALIGN_UP((uintptr_t) start, PAGE_SIZE);
     285        /* Align the heap area size on page boundary */
    291286        size_t asize = ALIGN_UP(size, PAGE_SIZE);
    292        
    293         astart = as_area_create(astart, asize, AS_AREA_WRITE | AS_AREA_READ);
     287        void *astart = as_area_create((void *) -1, asize,
     288            AS_AREA_WRITE | AS_AREA_READ);
    294289        if (astart == (void *) -1)
    295290                return false;
  • uspace/lib/c/generic/mman.c

    rb69e4c0 rdb96017  
    4242{
    4343        if (!start)
    44                 start = as_get_mappable_page(length);
     44                start = (void *) -1;
    4545       
    4646//      if (!((flags & MAP_SHARED) ^ (flags & MAP_PRIVATE)))
  • uspace/lib/c/generic/net/packet.c

    rb69e4c0 rdb96017  
    3636 */
    3737
     38#include <assert.h>
    3839#include <malloc.h>
    3940#include <mem.h>
     
    4445#include <sys/mman.h>
    4546
    46 #include <adt/generic_field.h>
     47#include <adt/hash_table.h>
    4748#include <net/packet.h>
    4849#include <net/packet_header.h>
    4950
    50 /** Packet map page size. */
    51 #define PACKET_MAP_SIZE 100
    52 
    53 /** Returns the packet map page index.
    54  * @param[in] packet_id The packet identifier.
    55  */
    56 #define PACKET_MAP_PAGE(packet_id)      (((packet_id) - 1) / PACKET_MAP_SIZE)
    57 
    58 /** Returns the packet index in the corresponding packet map page.
    59  *  @param[in] packet_id The packet identifier.
    60  */
    61 #define PACKET_MAP_INDEX(packet_id)     (((packet_id) - 1) % PACKET_MAP_SIZE)
    62 
    63 /** Type definition of the packet map page. */
    64 typedef packet_t *packet_map_t[PACKET_MAP_SIZE];
    65 
    66 /** Packet map.
    67  * Maps packet identifiers to the packet references.
    68  * @see generic_field.h
    69  */
    70 GENERIC_FIELD_DECLARE(gpm, packet_map_t);
     51/** Packet hash table size. */
     52#define PACKET_HASH_TABLE_SIZE  128
    7153
    7254/** Packet map global data. */
     
    7557        fibril_rwlock_t lock;
    7658        /** Packet map. */
    77         gpm_t packet_map;
     59        hash_table_t packet_map;
     60        /** Packet map operations */
     61        hash_table_operations_t operations;
    7862} pm_globals;
    7963
    80 GENERIC_FIELD_IMPLEMENT(gpm, packet_map_t);
     64typedef struct {
     65        link_t link;
     66        packet_t *packet;
     67} pm_entry_t;
     68
     69/**
     70 * Hash function for the packet mapping hash table
     71 */
     72static hash_index_t pm_hash(unsigned long key[])
     73{
     74        return (hash_index_t) key[0] % PACKET_HASH_TABLE_SIZE;
     75}
     76
     77/**
     78 * Key compare function for the packet mapping hash table
     79 */
     80static int pm_compare(unsigned long key[], hash_count_t keys, link_t *link)
     81{
     82        pm_entry_t *entry = list_get_instance(link, pm_entry_t, link);
     83        return entry->packet->packet_id == key[0];
     84}
     85
     86/**
     87 * Remove callback for the packet mapping hash table
     88 */
     89static void pm_remove_callback(link_t *link)
     90{
     91        pm_entry_t *entry = list_get_instance(link, pm_entry_t, link);
     92        free(entry);
     93}
     94
     95/**
     96 * Wrapper used when destroying the whole table
     97 */
     98static void pm_free_wrapper(link_t *link, void *ignored)
     99{
     100        pm_entry_t *entry = list_get_instance(link, pm_entry_t, link);
     101        free(entry);
     102}
     103
    81104
    82105/** Initializes the packet map.
     
    87110int pm_init(void)
    88111{
    89         int rc;
     112        int rc = EOK;
    90113
    91114        fibril_rwlock_initialize(&pm_globals.lock);
    92115       
    93116        fibril_rwlock_write_lock(&pm_globals.lock);
    94         rc = gpm_initialize(&pm_globals.packet_map);
     117       
     118        pm_globals.operations.hash = pm_hash;
     119        pm_globals.operations.compare = pm_compare;
     120        pm_globals.operations.remove_callback = pm_remove_callback;
     121
     122        if (!hash_table_create(&pm_globals.packet_map, PACKET_HASH_TABLE_SIZE, 1,
     123            &pm_globals.operations))
     124                rc = ENOMEM;
     125       
    95126        fibril_rwlock_write_unlock(&pm_globals.lock);
    96127       
     
    100131/** Finds the packet mapping.
    101132 *
    102  * @param[in] packet_id The packet identifier to be found.
    103  * @return              The found packet reference.
    104  * @return              NULL if the mapping does not exist.
     133 * @param[in] packet_id Packet identifier to be found.
     134 *
     135 * @return The found packet reference.
     136 * @return NULL if the mapping does not exist.
     137 *
    105138 */
    106139packet_t *pm_find(packet_id_t packet_id)
    107140{
    108         packet_map_t *map;
    109         packet_t *packet;
    110 
    111141        if (!packet_id)
    112142                return NULL;
    113 
     143       
    114144        fibril_rwlock_read_lock(&pm_globals.lock);
    115         if (packet_id > PACKET_MAP_SIZE * gpm_count(&pm_globals.packet_map)) {
    116                 fibril_rwlock_read_unlock(&pm_globals.lock);
    117                 return NULL;
    118         }
    119         map = gpm_get_index(&pm_globals.packet_map, PACKET_MAP_PAGE(packet_id));
    120         if (!map) {
    121                 fibril_rwlock_read_unlock(&pm_globals.lock);
    122                 return NULL;
    123         }
    124         packet = (*map) [PACKET_MAP_INDEX(packet_id)];
     145       
     146        unsigned long key = packet_id;
     147        link_t *link = hash_table_find(&pm_globals.packet_map, &key);
     148       
     149        packet_t *packet;
     150        if (link != NULL) {
     151                pm_entry_t *entry =
     152                    hash_table_get_instance(link, pm_entry_t, link);
     153                packet = entry->packet;
     154        } else
     155                packet = NULL;
     156       
    125157        fibril_rwlock_read_unlock(&pm_globals.lock);
    126158        return packet;
     
    129161/** Adds the packet mapping.
    130162 *
    131  * @param[in] packet    The packet to be remembered.
    132  * @return              EOK on success.
    133  * @return              EINVAL if the packet is not valid.
    134  * @return              EINVAL if the packet map is not initialized.
    135  * @return              ENOMEM if there is not enough memory left.
     163 * @param[in] packet Packet to be remembered.
     164 *
     165 * @return EOK on success.
     166 * @return EINVAL if the packet is not valid.
     167 * @return ENOMEM if there is not enough memory left.
     168 *
    136169 */
    137170int pm_add(packet_t *packet)
    138171{
    139         packet_map_t *map;
    140         int rc;
    141 
    142172        if (!packet_is_valid(packet))
    143173                return EINVAL;
    144 
     174       
    145175        fibril_rwlock_write_lock(&pm_globals.lock);
    146 
    147         if (PACKET_MAP_PAGE(packet->packet_id) <
    148             gpm_count(&pm_globals.packet_map)) {
    149                 map = gpm_get_index(&pm_globals.packet_map,
    150                     PACKET_MAP_PAGE(packet->packet_id));
    151         } else {
    152                 do {
    153                         map = (packet_map_t *) malloc(sizeof(packet_map_t));
    154                         if (!map) {
    155                                 fibril_rwlock_write_unlock(&pm_globals.lock);
    156                                 return ENOMEM;
    157                         }
    158                         bzero(map, sizeof(packet_map_t));
    159                         rc = gpm_add(&pm_globals.packet_map, map);
    160                         if (rc < 0) {
    161                                 fibril_rwlock_write_unlock(&pm_globals.lock);
    162                                 free(map);
    163                                 return rc;
    164                         }
    165                 } while (PACKET_MAP_PAGE(packet->packet_id) >=
    166                     gpm_count(&pm_globals.packet_map));
     176       
     177        pm_entry_t *entry = malloc(sizeof(pm_entry_t));
     178        if (entry == NULL) {
     179                fibril_rwlock_write_unlock(&pm_globals.lock);
     180                return ENOMEM;
    167181        }
    168 
    169         (*map) [PACKET_MAP_INDEX(packet->packet_id)] = packet;
     182       
     183        entry->packet = packet;
     184       
     185        unsigned long key = packet->packet_id;
     186        hash_table_insert(&pm_globals.packet_map, &key, &entry->link);
     187       
    170188        fibril_rwlock_write_unlock(&pm_globals.lock);
     189       
    171190        return EOK;
    172191}
    173192
    174 /** Releases the packet map. */
     193/** Remove the packet mapping
     194 *
     195 * @param[in] packet The packet to be removed
     196 *
     197 */
     198void pm_remove(packet_t *packet)
     199{
     200        assert(packet_is_valid(packet));
     201       
     202        fibril_rwlock_write_lock(&pm_globals.lock);
     203       
     204        unsigned long key = packet->packet_id;
     205        hash_table_remove(&pm_globals.packet_map, &key, 1);
     206       
     207        fibril_rwlock_write_unlock(&pm_globals.lock);
     208}
     209
     210/** Release the packet map. */
    175211void pm_destroy(void)
    176212{
    177         int count;
    178         int index;
    179         packet_map_t *map;
    180         packet_t *packet;
    181 
    182213        fibril_rwlock_write_lock(&pm_globals.lock);
    183         count = gpm_count(&pm_globals.packet_map);
    184         while (count > 0) {
    185                 map = gpm_get_index(&pm_globals.packet_map, count - 1);
    186                 for (index = PACKET_MAP_SIZE - 1; index >= 0; --index) {
    187                         packet = (*map)[index];
    188                         if (packet_is_valid(packet))
    189                                 munmap(packet, packet->length);
    190                 }
    191         }
    192         gpm_destroy(&pm_globals.packet_map, free);
    193         /* leave locked */
     214        hash_table_apply(&pm_globals.packet_map, pm_free_wrapper, NULL);
     215        hash_table_destroy(&pm_globals.packet_map);
     216        /* Leave locked */
    194217}
    195218
     
    199222 * The packet is inserted right before the packets of the same order value.
    200223 *
    201  * @param[in,out] first The first packet of the queue. Sets the first packet of
    202  *                      the queue. The original first packet may be shifted by
    203  *                      the new packet.
    204  * @param[in] packet    The packet to be added.
    205  * @param[in] order     The packet order value.
    206  * @param[in] metric    The metric value of the packet.
    207  * @return              EOK on success.
    208  * @return              EINVAL if the first parameter is NULL.
    209  * @return              EINVAL if the packet is not valid.
     224 * @param[in,out] first First packet of the queue. Sets the first
     225 *                      packet of the queue. The original first packet
     226 *                      may be shifted by the new packet.
     227 * @param[in] packet    Packet to be added.
     228 * @param[in] order     Packet order value.
     229 * @param[in] metric    Metric value of the packet.
     230 *
     231 * @return EOK on success.
     232 * @return EINVAL if the first parameter is NULL.
     233 * @return EINVAL if the packet is not valid.
     234 *
    210235 */
    211236int pq_add(packet_t **first, packet_t *packet, size_t order, size_t metric)
    212237{
    213         packet_t *item;
    214 
    215         if (!first || !packet_is_valid(packet))
     238        if ((!first) || (!packet_is_valid(packet)))
    216239                return EINVAL;
    217 
     240       
    218241        pq_set_order(packet, order, metric);
    219242        if (packet_is_valid(*first)) {
    220                 item = * first;
     243                packet_t *cur = *first;
     244               
    221245                do {
    222                         if (item->order < order) {
    223                                 if (item->next) {
    224                                         item = pm_find(item->next);
    225                                 } else {
    226                                         item->next = packet->packet_id;
    227                                         packet->previous = item->packet_id;
     246                        if (cur->order < order) {
     247                                if (cur->next)
     248                                        cur = pm_find(cur->next);
     249                                else {
     250                                        cur->next = packet->packet_id;
     251                                        packet->previous = cur->packet_id;
     252                                       
    228253                                        return EOK;
    229254                                }
    230255                        } else {
    231                                 packet->previous = item->previous;
    232                                 packet->next = item->packet_id;
    233                                 item->previous = packet->packet_id;
    234                                 item = pm_find(packet->previous);
    235                                 if (item)
    236                                         item->next = packet->packet_id;
     256                                packet->previous = cur->previous;
     257                                packet->next = cur->packet_id;
     258                               
     259                                cur->previous = packet->packet_id;
     260                                cur = pm_find(packet->previous);
     261                               
     262                                if (cur)
     263                                        cur->next = packet->packet_id;
    237264                                else
    238265                                        *first = packet;
     266                               
    239267                                return EOK;
    240268                        }
    241                 } while (packet_is_valid(item));
     269                } while (packet_is_valid(cur));
    242270        }
     271       
    243272        *first = packet;
    244273        return EOK;
     
    312341
    313342        next = pm_find(packet->next);
    314         if (next) {
     343        if (next)
    315344                next->previous = packet->previous;
    316                 previous = pm_find(next->previous);
    317                 if (previous)
    318                         previous->next = next->packet_id;
    319         }
     345       
     346        previous = pm_find(packet->previous);
     347        if (previous)
     348                previous->next = packet->next ;
     349       
    320350        packet->previous = 0;
    321351        packet->next = 0;
  • uspace/lib/c/generic/ns.c

    rb69e4c0 rdb96017  
    5454        if (!exch)
    5555                return NULL;
     56       
    5657        async_sess_t *sess =
    5758            async_connect_me_to(mgmt, exch, service, arg2, arg3);
    5859        async_exchange_end(exch);
    59 
     60       
    6061        if (!sess)
    6162                return NULL;
     
    7576{
    7677        async_exch_t *exch = async_exchange_begin(session_ns);
     78        if (!exch)
     79                return NULL;
    7780        async_sess_t *sess =
    7881            async_connect_me_to_blocking(mgmt, exch, service, arg2, arg3);
    7982        async_exchange_end(exch);
     83
     84        if (!sess)
     85                return NULL;
    8086       
    8187        /*
  • uspace/lib/c/generic/str.c

    rb69e4c0 rdb96017  
    261261}
    262262
     263/** Get size of string with size limit.
     264 *
     265 * Get the number of bytes which are used by the string @a str
     266 * (excluding the NULL-terminator), but no more than @max_size bytes.
     267 *
     268 * @param str      String to consider.
     269 * @param max_size Maximum number of bytes to measure.
     270 *
     271 * @return Number of bytes used by the string
     272 *
     273 */
     274size_t str_nsize(const char *str, size_t max_size)
     275{
     276        size_t size = 0;
     277       
     278        while ((*str++ != 0) && (size < max_size))
     279                size++;
     280       
     281        return size;
     282}
     283
     284/** Get size of wide string with size limit.
     285 *
     286 * Get the number of bytes which are used by the wide string @a str
     287 * (excluding the NULL-terminator), but no more than @max_size bytes.
     288 *
     289 * @param str      Wide string to consider.
     290 * @param max_size Maximum number of bytes to measure.
     291 *
     292 * @return Number of bytes used by the wide string
     293 *
     294 */
     295size_t wstr_nsize(const wchar_t *str, size_t max_size)
     296{
     297        return (wstr_nlength(str, max_size) * sizeof(wchar_t));
     298}
     299
    263300/** Get size of wide string with length limit.
    264301 *
     
    839876       
    840877        return NULL;
     878}
     879
     880/** Removes specified trailing characters from a string.
     881 *
     882 * @param str String to remove from.
     883 * @param ch  Character to remove.
     884 */
     885void str_rtrim(char *str, wchar_t ch)
     886{
     887        size_t off = 0;
     888        size_t pos = 0;
     889        wchar_t c;
     890        bool update_last_chunk = true;
     891        char *last_chunk = NULL;
     892
     893        while ((c = str_decode(str, &off, STR_NO_LIMIT))) {
     894                if (c != ch) {
     895                        update_last_chunk = true;
     896                        last_chunk = NULL;
     897                } else if (update_last_chunk) {
     898                        update_last_chunk = false;
     899                        last_chunk = (str + pos);
     900                }
     901                pos = off;
     902        }
     903
     904        if (last_chunk)
     905                *last_chunk = '\0';
     906}
     907
     908/** Removes specified leading characters from a string.
     909 *
     910 * @param str String to remove from.
     911 * @param ch  Character to remove.
     912 */
     913void str_ltrim(char *str, wchar_t ch)
     914{
     915        wchar_t acc;
     916        size_t off = 0;
     917        size_t pos = 0;
     918        size_t str_sz = str_size(str);
     919
     920        while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
     921                if (acc != ch)
     922                        break;
     923                else
     924                        pos = off;
     925        }
     926
     927        if (pos > 0) {
     928                memmove(str, &str[pos], str_sz - pos);
     929                pos = str_sz - pos;
     930                str[str_sz - pos] = '\0';
     931        }
    841932}
    842933
     
    14441535 *
    14451536 */
    1446 int str_uint64(const char *nptr, char **endptr, unsigned int base,
     1537int str_uint64_t(const char *nptr, char **endptr, unsigned int base,
    14471538    bool strict, uint64_t *result)
    14481539{
  • uspace/lib/c/generic/sysinfo.c

    rb69e4c0 rdb96017  
    4040#include <bool.h>
    4141
     42/** Get sysinfo keys size
     43 *
     44 * @param path  Sysinfo path.
     45 * @param value Pointer to store the keys size.
     46 *
     47 * @return EOK if the keys were successfully read.
     48 *
     49 */
     50static int sysinfo_get_keys_size(const char *path, size_t *size)
     51{
     52        return (int) __SYSCALL3(SYS_SYSINFO_GET_KEYS_SIZE, (sysarg_t) path,
     53            (sysarg_t) str_size(path), (sysarg_t) size);
     54}
     55
     56/** Get sysinfo keys
     57 *
     58 * @param path  Sysinfo path.
     59 * @param value Pointer to store the keys size.
     60 *
     61 * @return Keys read from sysinfo or NULL if the
     62 *         sysinfo item has no subkeys.
     63 *         The returned non-NULL pointer should be
     64 *         freed by free().
     65 *
     66 */
     67char *sysinfo_get_keys(const char *path, size_t *size)
     68{
     69        /*
     70         * The size of the keys might change during time.
     71         * Unfortunatelly we cannot allocate the buffer
     72         * and transfer the keys as a single atomic operation.
     73         */
     74       
     75        /* Get the keys size */
     76        int ret = sysinfo_get_keys_size(path, size);
     77        if ((ret != EOK) || (size == 0)) {
     78                /*
     79                 * Item with no subkeys.
     80                 */
     81                *size = 0;
     82                return NULL;
     83        }
     84       
     85        char *data = malloc(*size);
     86        if (data == NULL) {
     87                *size = 0;
     88                return NULL;
     89        }
     90       
     91        /* Get the data */
     92        size_t sz;
     93        ret = __SYSCALL5(SYS_SYSINFO_GET_KEYS, (sysarg_t) path,
     94            (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size,
     95            (sysarg_t) &sz);
     96        if (ret == EOK) {
     97                *size = sz;
     98                return data;
     99        }
     100       
     101        free(data);
     102        *size = 0;
     103        return NULL;
     104}
     105
    42106/** Get sysinfo item type
    43107 *
     
    70134/** Get sysinfo binary data size
    71135 *
    72  * @param path  Sysinfo path.
    73  * @param value Pointer to store the binary data size.
     136 * @param path Sysinfo path.
     137 * @param size Pointer to store the binary data size.
    74138 *
    75139 * @return EOK if the value was successfully read and
     
    85149/** Get sysinfo binary data
    86150 *
    87  * @param path  Sysinfo path.
    88  * @param value Pointer to store the binary data size.
     151 * @param path Sysinfo path.
     152 * @param size Pointer to store the binary data size.
    89153 *
    90154 * @return Binary data read from sysinfo or NULL if the
     
    134198}
    135199
     200/** Get sysinfo property
     201 *
     202 * @param path Sysinfo path.
     203 * @param name Property name.
     204 * @param size Pointer to store the binary data size.
     205 *
     206 * @return Property value read from sysinfo or NULL if the
     207 *         sysinfo item value type is not binary data.
     208 *         The returned non-NULL pointer should be
     209 *         freed by free().
     210 *
     211 */
     212void *sysinfo_get_property(const char *path, const char *name, size_t *size)
     213{
     214        size_t total_size;
     215        void *data = sysinfo_get_data(path, &total_size);
     216        if ((data == NULL) || (total_size == 0)) {
     217                *size = 0;
     218                return NULL;
     219        }
     220       
     221        size_t pos = 0;
     222        while (pos < total_size) {
     223                /* Process each property with sanity checks */
     224                size_t cur_size = str_nsize(data + pos, total_size - pos);
     225                if (((char *) data)[pos + cur_size] != 0)
     226                        break;
     227               
     228                bool found = (str_cmp(data + pos, name) == 0);
     229               
     230                pos += cur_size + 1;
     231                if (pos >= total_size)
     232                        break;
     233               
     234                /* Process value size */
     235                size_t value_size;
     236                memcpy(&value_size, data + pos, sizeof(value_size));
     237               
     238                pos += sizeof(value_size);
     239                if ((pos >= total_size) || (pos + value_size > total_size))
     240                        break;
     241               
     242                if (found) {
     243                        void *value = malloc(value_size);
     244                        if (value == NULL)
     245                                break;
     246                       
     247                        memcpy(value, data + pos, value_size);
     248                        free(data);
     249                       
     250                        *size = value_size;
     251                        return value;
     252                }
     253               
     254                pos += value_size;
     255        }
     256       
     257        free(data);
     258       
     259        *size = 0;
     260        return NULL;
     261}
     262
    136263/** @}
    137264 */
  • uspace/lib/c/generic/time.c

    rb69e4c0 rdb96017  
    147147                }
    148148               
    149                 void *addr = as_get_mappable_page(PAGE_SIZE);
    150                 if (addr == NULL) {
    151                         errno = ENOMEM;
    152                         return -1;
    153                 }
    154                
    155                 rc = physmem_map((void *) faddr, addr, 1,
    156                     AS_AREA_READ | AS_AREA_CACHEABLE);
     149                void *addr;
     150                rc = physmem_map((void *) faddr, 1,
     151                    AS_AREA_READ | AS_AREA_CACHEABLE, &addr);
    157152                if (rc != EOK) {
    158153                        as_area_destroy(addr);
  • uspace/lib/c/generic/vfs/vfs.c

    rb69e4c0 rdb96017  
    831831}
    832832
     833int get_mtab_list(list_t *mtab_list)
     834{
     835        sysarg_t rc;
     836        aid_t req;
     837        size_t i;
     838        sysarg_t num_mounted_fs;
     839       
     840        async_exch_t *exch = vfs_exchange_begin();
     841
     842        req = async_send_0(exch, VFS_IN_MTAB_GET, NULL);
     843
     844        /* Ask VFS how many filesystems are mounted */
     845        rc = async_req_0_1(exch, VFS_IN_PING, &num_mounted_fs);
     846        if (rc != EOK)
     847                goto exit;
     848
     849        for (i = 0; i < num_mounted_fs; ++i) {
     850                mtab_ent_t *mtab_ent;
     851
     852                mtab_ent = malloc(sizeof(mtab_ent_t));
     853                if (!mtab_ent) {
     854                        rc = ENOMEM;
     855                        goto exit;
     856                }
     857
     858                memset(mtab_ent, 0, sizeof(mtab_ent_t));
     859
     860                rc = async_data_read_start(exch, (void *) mtab_ent->mp,
     861                    MAX_PATH_LEN);
     862                if (rc != EOK)
     863                        goto exit;
     864
     865                rc = async_data_read_start(exch, (void *) mtab_ent->opts,
     866                        MAX_MNTOPTS_LEN);
     867                if (rc != EOK)
     868                        goto exit;
     869
     870                rc = async_data_read_start(exch, (void *) mtab_ent->fs_name,
     871                        FS_NAME_MAXLEN);
     872                if (rc != EOK)
     873                        goto exit;
     874
     875                sysarg_t p[2];
     876
     877                rc = async_req_0_2(exch, VFS_IN_PING, &p[0], &p[1]);
     878                if (rc != EOK)
     879                        goto exit;
     880
     881                mtab_ent->instance = p[0];
     882                mtab_ent->service_id = p[1];
     883
     884                link_initialize(&mtab_ent->link);
     885                list_append(&mtab_ent->link, mtab_list);
     886        }
     887
     888exit:
     889        async_wait_for(req, &rc);
     890        vfs_exchange_end(exch);
     891        return rc;
     892}
     893
    833894/** @}
    834895 */
  • uspace/lib/c/include/adt/hash_table.h

    rb69e4c0 rdb96017  
    8686extern bool hash_table_create(hash_table_t *, hash_count_t, hash_count_t,
    8787    hash_table_operations_t *);
     88extern void hash_table_clear(hash_table_t *);
    8889extern void hash_table_insert(hash_table_t *, unsigned long [], link_t *);
    8990extern link_t *hash_table_find(hash_table_t *, unsigned long []);
  • uspace/lib/c/include/as.h

    rb69e4c0 rdb96017  
    5959extern int as_area_destroy(void *);
    6060extern void *set_maxheapsize(size_t);
    61 extern void *as_get_mappable_page(size_t);
    6261extern int as_get_physical_mapping(const void *, uintptr_t *);
    6362
  • uspace/lib/c/include/async.h

    rb69e4c0 rdb96017  
    346346 */
    347347
    348 #define async_share_in_start_0_0(exch, dst, size) \
    349         async_share_in_start(exch, dst, size, 0, NULL)
    350 #define async_share_in_start_0_1(exch, dst, size, flags) \
    351         async_share_in_start(exch, dst, size, 0, flags)
    352 #define async_share_in_start_1_0(exch, dst, size, arg) \
    353         async_share_in_start(exch, dst, size, arg, NULL)
    354 #define async_share_in_start_1_1(exch, dst, size, arg, flags) \
    355         async_share_in_start(exch, dst, size, arg, flags)
    356 
    357 extern int async_share_in_start(async_exch_t *, void *, size_t, sysarg_t,
    358     unsigned int *);
     348#define async_share_in_start_0_0(exch, size, dst) \
     349        async_share_in_start(exch, size, 0, NULL, dst)
     350#define async_share_in_start_0_1(exch, size, flags, dst) \
     351        async_share_in_start(exch, size, 0, flags, dst)
     352#define async_share_in_start_1_0(exch, size, arg, dst) \
     353        async_share_in_start(exch, size, arg, NULL, dst)
     354#define async_share_in_start_1_1(exch, size, arg, flags, dst) \
     355        async_share_in_start(exch, size, arg, flags, dst)
     356
     357extern int async_share_in_start(async_exch_t *, size_t, sysarg_t,
     358    unsigned int *, void **);
    359359extern bool async_share_in_receive(ipc_callid_t *, size_t *);
    360360extern int async_share_in_finalize(ipc_callid_t, void *, unsigned int);
     
    362362extern int async_share_out_start(async_exch_t *, void *, unsigned int);
    363363extern bool async_share_out_receive(ipc_callid_t *, size_t *, unsigned int *);
    364 extern int async_share_out_finalize(ipc_callid_t, void *);
     364extern int async_share_out_finalize(ipc_callid_t, void **);
    365365
    366366/*
  • uspace/lib/c/include/bitops.h

    rb69e4c0 rdb96017  
    4040/** Mask with bit @a n set. */
    4141#define BIT_V(type, n) \
    42     ((type)1 << ((n) - 1))
     42    ((type) 1 << (n))
    4343
    4444/** Mask with rightmost @a n bits set. */
    4545#define BIT_RRANGE(type, n) \
    46     (BIT_V(type, (n) + 1) - 1)
     46    (BIT_V(type, (n)) - 1)
    4747
    4848/** Mask with bits @a hi .. @a lo set. @a hi >= @a lo. */
  • uspace/lib/c/include/ddi.h

    rb69e4c0 rdb96017  
    4141
    4242extern int device_assign_devno(void);
    43 extern int physmem_map(void *, void *, unsigned long, int);
     43
     44extern int physmem_map(void *, size_t, unsigned int, void **);
     45
     46extern int dmamem_map(void *, size_t, unsigned int, unsigned int, void **);
     47extern int dmamem_map_anonymous(size_t, unsigned int, unsigned int, void **,
     48    void **);
     49extern int dmamem_unmap(void *, size_t);
     50extern int dmamem_unmap_anonymous(void *);
     51
    4452extern int iospace_enable(task_id_t, void *, unsigned long);
    4553extern int pio_enable(void *, size_t, void **);
    46 extern int register_irq(int, int, int, irq_code_t *);
    47 extern int unregister_irq(int, int);
     54
     55extern int irq_register(int, int, int, irq_code_t *);
     56extern int irq_unregister(int, int);
    4857
    4958#endif
  • uspace/lib/c/include/device/hw_res.h

    rb69e4c0 rdb96017  
    4040#include <bool.h>
    4141
     42#define DMA_MODE_ON_DEMAND  0
     43#define DMA_MODE_WRITE      (1 << 2)
     44#define DMA_MODE_READ       (1 << 3)
     45#define DMA_MODE_AUTO       (1 << 4)
     46#define DMA_MODE_DOWN       (1 << 5)
     47#define DMA_MODE_SINGLE     (1 << 6)
     48#define DMA_MODE_BLOCK      (1 << 7)
     49
    4250/** HW resource provider interface */
    4351typedef enum {
    4452        HW_RES_GET_RESOURCE_LIST = 0,
    45         HW_RES_ENABLE_INTERRUPT
     53        HW_RES_ENABLE_INTERRUPT,
     54        HW_RES_DMA_CHANNEL_SETUP,
    4655} hw_res_method_t;
    4756
     
    5059        INTERRUPT,
    5160        IO_RANGE,
    52         MEM_RANGE
     61        MEM_RANGE,
     62        DMA_CHANNEL_8,
     63        DMA_CHANNEL_16,
    5364} hw_res_type_t;
    5465
     
    7788                        int irq;
    7889                } interrupt;
     90               
     91                union {
     92                        unsigned int dma8;
     93                        unsigned int dma16;
     94                } dma_channel;
    7995        } res;
    8096} hw_resource_t;
     
    98114extern bool hw_res_enable_interrupt(async_sess_t *);
    99115
     116extern int hw_res_dma_channel_setup(async_sess_t *, unsigned int, uint32_t,
     117    uint16_t, uint8_t);
     118
    100119#endif
    101120
  • uspace/lib/c/include/device/pci.h

    rb69e4c0 rdb96017  
    11/*
    2  * Copyright (c) 2009 Lukas Mejdrech
     2 * Copyright (c) 2011 Jiri Michalec
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libnet
     29/** @addtogroup libc
    3030 * @{
    3131 */
     32/** @file
     33 */
    3234
    33 #ifndef LIBNET_NETIF_REMOTE_H_
    34 #define LIBNET_NETIF_REMOTE_H_
     35#ifndef LIBC_DEVICE_PCI_H_
     36#define LIBC_DEVICE_PCI_H_
    3537
    36 #include <ipc/services.h>
    37 #include <adt/measured_strings.h>
    38 #include <net/device.h>
    39 #include <net/packet.h>
    4038#include <async.h>
    4139
    42 extern int netif_get_addr_req(async_sess_t *, device_id_t, measured_string_t **,
    43     uint8_t **);
    44 extern int netif_probe_req(async_sess_t *, device_id_t, int, void *);
    45 extern int netif_send_msg(async_sess_t *, device_id_t, packet_t *, services_t);
    46 extern int netif_start_req(async_sess_t *, device_id_t);
    47 extern int netif_stop_req(async_sess_t *, device_id_t);
    48 extern int netif_stats_req(async_sess_t *, device_id_t, device_stats_t *);
    49 extern async_sess_t *netif_bind_service(services_t, device_id_t, services_t,
    50     async_client_conn_t);
     40#define PCI_DEVICE_ID  0x02
     41
     42typedef enum {
     43        IPC_M_CONFIG_SPACE_READ_8,
     44        IPC_M_CONFIG_SPACE_READ_16,
     45        IPC_M_CONFIG_SPACE_READ_32,
     46       
     47        IPC_M_CONFIG_SPACE_WRITE_8,
     48        IPC_M_CONFIG_SPACE_WRITE_16,
     49        IPC_M_CONFIG_SPACE_WRITE_32
     50} pci_dev_iface_funcs_t;
     51
     52extern int pci_config_space_read_8(async_sess_t *, uint32_t, uint8_t *);
     53extern int pci_config_space_read_16(async_sess_t *, uint32_t, uint16_t *);
     54extern int pci_config_space_read_32(async_sess_t *, uint32_t, uint32_t *);
     55
     56extern int pci_config_space_write_8(async_sess_t *, uint32_t, uint8_t);
     57extern int pci_config_space_write_16(async_sess_t *, uint32_t, uint16_t);
     58extern int pci_config_space_write_32(async_sess_t *, uint32_t, uint32_t);
    5159
    5260#endif
  • uspace/lib/c/include/devman.h

    rb69e4c0 rdb96017  
    4646extern void devman_exchange_end(async_exch_t *);
    4747
    48 extern int devman_driver_register(const char *, async_client_conn_t);
     48extern int devman_driver_register(const char *);
    4949extern int devman_add_function(const char *, fun_type_t, match_id_list_t *,
    5050    devman_handle_t, devman_handle_t *);
  • uspace/lib/c/include/errno.h

    rb69e4c0 rdb96017  
    9696#define ENOTCONN  (-10057)
    9797
     98#define ECONNREFUSED  (-10058)
     99
     100#define ECONNABORTED  (-10059)
     101
    98102/** The requested operation was not performed. Try again later. */
    99103#define EAGAIN  (-11002)
  • uspace/lib/c/include/fibril.h

    rb69e4c0 rdb96017  
    4141
    4242#define context_set_generic(c, _pc, stack, size, ptls) \
    43         (c)->pc = (sysarg_t) (_pc); \
    44         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
    45         (c)->tls = (sysarg_t) (ptls);
     43        do { \
     44                (c)->pc = (sysarg_t) (_pc); \
     45                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     46                (c)->tls = (sysarg_t) (ptls); \
     47        } while (0)
    4648
    4749#define FIBRIL_SERIALIZED  1
  • uspace/lib/c/include/fibril_synch.h

    rb69e4c0 rdb96017  
    107107        fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name)
    108108
     109typedef void (*fibril_timer_fun_t)(void *);
     110
     111typedef enum {
     112        /** Timer has not been set or has been cleared */
     113        fts_not_set,
     114        /** Timer was set but did not fire yet */
     115        fts_active,
     116        /** Timer has fired and has not been cleared since */
     117        fts_fired,
     118        /** Timer is being destroyed */
     119        fts_cleanup
     120} fibril_timer_state_t;
     121
     122/** Fibril timer.
     123 *
     124 * When a timer is set it executes a callback function (in a separate
     125 * fibril) after a specified time interval. The timer can be cleared
     126 * (canceled) before that. From the return value of fibril_timer_clear()
     127 * one can tell whether the timer fired or not.
     128 */
     129typedef struct {
     130        fibril_mutex_t lock;
     131        fibril_condvar_t cv;
     132        fid_t fibril;
     133        fibril_timer_state_t state;
     134
     135        suseconds_t delay;
     136        fibril_timer_fun_t fun;
     137        void *arg;
     138} fibril_timer_t;
     139
    109140extern void fibril_mutex_initialize(fibril_mutex_t *);
    110141extern void fibril_mutex_lock(fibril_mutex_t *);
     
    129160extern void fibril_condvar_broadcast(fibril_condvar_t *);
    130161
     162extern fibril_timer_t *fibril_timer_create(void);
     163extern void fibril_timer_destroy(fibril_timer_t *);
     164extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t,
     165    void *);
     166extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *);
     167
    131168#endif
    132169
  • uspace/lib/c/include/ipc/dev_iface.h

    rb69e4c0 rdb96017  
    3636typedef enum {
    3737        HW_RES_DEV_IFACE = 0,
     38        /** Character device interface */
    3839        CHAR_DEV_IFACE,
    39 
     40       
     41        /** Network interface controller interface */
     42        NIC_DEV_IFACE,
     43       
    4044        /** Interface provided by any PCI device. */
    4145        PCI_DEV_IFACE,
  • uspace/lib/c/include/ipc/il.h

    rb69e4c0 rdb96017  
    5454        NET_IL_MTU_CHANGED,
    5555       
     56        /**
     57         * Device address changed message
     58         * @see il_addr_changed_msg()
     59         */
     60        NET_IL_ADDR_CHANGED,
     61
    5662        /** Packet received message.
    5763         * @see il_received_msg()
  • uspace/lib/c/include/ipc/ipc.h

    rb69e4c0 rdb96017  
    271271 */
    272272
    273 #define ipc_share_in_start_0_0(phoneid, dst, size) \
    274         ipc_share_in_start((phoneid), (dst), (size), 0, NULL)
    275 #define ipc_share_in_start_0_1(phoneid, dst, size, flags) \
    276         ipc_share_in_start((phoneid), (dst), (size), 0, (flags))
    277 #define ipc_share_in_start_1_0(phoneid, dst, size, arg) \
    278         ipc_share_in_start((phoneid), (dst), (size), (arg), NULL)
    279 #define ipc_share_in_start_1_1(phoneid, dst, size, arg, flags) \
    280         ipc_share_in_start((phoneid), (dst), (size), (arg), (flags))
    281 
    282 extern int ipc_share_in_start(int, void *, size_t, sysarg_t, unsigned int *);
     273#define ipc_share_in_start_0_0(phoneid, size, dst) \
     274        ipc_share_in_start((phoneid), (size), 0, NULL, (dst))
     275#define ipc_share_in_start_0_1(phoneid, size, flags, dst) \
     276        ipc_share_in_start((phoneid), (size), 0, (flags), (dst))
     277#define ipc_share_in_start_1_0(phoneid, size, arg, dst) \
     278        ipc_share_in_start((phoneid), (size), (arg), NULL, (dst))
     279#define ipc_share_in_start_1_1(phoneid, size, arg, flags, dst) \
     280        ipc_share_in_start((phoneid), (size), (arg), (flags), (dst))
     281
     282extern int ipc_share_in_start(int, size_t, sysarg_t, unsigned int *, void **);
    283283extern int ipc_share_in_finalize(ipc_callid_t, void *, unsigned int);
    284284extern int ipc_share_out_start(int, void *, unsigned int);
    285 extern int ipc_share_out_finalize(ipc_callid_t, void *);
     285extern int ipc_share_out_finalize(ipc_callid_t, void **);
    286286extern int ipc_data_read_start(int, void *, size_t);
    287287extern int ipc_data_read_finalize(ipc_callid_t, const void *, size_t);
  • uspace/lib/c/include/ipc/net.h

    rb69e4c0 rdb96017  
    277277 *
    278278 */
    279 #define IPC_GET_DEVICE(call)  ((device_id_t) IPC_GET_ARG1(call))
     279#define IPC_GET_DEVICE(call)  ((nic_device_id_t) IPC_GET_ARG1(call))
    280280
    281281/** Return the packet identifier message argument.
     
    298298 *
    299299 */
    300 #define IPC_GET_STATE(call)  ((device_state_t) IPC_GET_ARG2(call))
     300#define IPC_GET_STATE(call)  ((nic_device_state_t) IPC_GET_ARG2(call))
     301
     302/** Return the device handle argument
     303 *
     304 * @param[in] call Message call structure
     305 *
     306 */
     307#define IPC_GET_DEVICE_HANDLE(call)  ((service_id_t) IPC_GET_ARG2(call))
     308
     309/** Return the device driver service message argument.
     310 *
     311 * @param[in] call Message call structure.
     312 *
     313 */
     314#define IPC_GET_SERVICE(call)  ((services_t) IPC_GET_ARG3(call))
     315
     316/** Return the target service message argument.
     317 *
     318 * @param[in] call Message call structure.
     319 *
     320 */
     321#define IPC_GET_TARGET(call)  ((services_t) IPC_GET_ARG3(call))
     322
     323/** Return the sender service message argument.
     324 *
     325 * @param[in] call Message call structure.
     326 *
     327 */
     328#define IPC_GET_SENDER(call)  ((services_t) IPC_GET_ARG3(call))
    301329
    302330/** Return the maximum transmission unit message argument.
     
    305333 *
    306334 */
    307 #define IPC_GET_MTU(call)  ((size_t) IPC_GET_ARG2(call))
    308 
    309 /** Return the device driver service message argument.
    310  *
    311  * @param[in] call Message call structure.
    312  *
    313  */
    314 #define IPC_GET_SERVICE(call)  ((services_t) IPC_GET_ARG3(call))
    315 
    316 /** Return the target service message argument.
    317  *
    318  * @param[in] call Message call structure.
    319  *
    320  */
    321 #define IPC_GET_TARGET(call)  ((services_t) IPC_GET_ARG3(call))
    322 
    323 /** Return the sender service message argument.
    324  *
    325  * @param[in] call Message call structure.
    326  *
    327  */
    328 #define IPC_GET_SENDER(call)  ((services_t) IPC_GET_ARG3(call))
     335#define IPC_GET_MTU(call)  ((size_t) IPC_GET_ARG3(call))
    329336
    330337/** Return the error service message argument.
  • uspace/lib/c/include/ipc/net_net.h

    rb69e4c0 rdb96017  
    4343/** Networking subsystem central module messages. */
    4444typedef enum {
    45         /** Returns the general configuration
     45        /** Return general configuration
    4646         * @see net_get_conf_req()
    4747         */
    4848        NET_NET_GET_CONF = NET_FIRST,
    49         /** Returns the device specific configuration
     49        /** Return device specific configuration
    5050         * @see net_get_device_conf_req()
    5151         */
    5252        NET_NET_GET_DEVICE_CONF,
    53         /** Starts the networking stack. */
    54         NET_NET_STARTUP,
     53        /** Return number of mastered devices */
     54        NET_NET_GET_DEVICES_COUNT,
     55        /** Return names and device IDs of all devices */
     56        NET_NET_GET_DEVICES
    5557} net_messages;
    5658
  • uspace/lib/c/include/ipc/nil.h

    rb69e4c0 rdb96017  
    4646         */
    4747        NET_NIL_DEVICE = NET_NIL_FIRST,
    48         /** New device state message.
    49          * @see nil_device_state_msg()
    50          */
    51         NET_NIL_DEVICE_STATE,
    52         /** Received packet queue message.
    53          * @see nil_received_msg()
    54          */
    55         NET_NIL_RECEIVED,
    5648        /** Send packet queue message.
    5749         * @see nil_send_msg()
     
    6961         * @see nil_get_broadcast_addr()
    7062         */
    71         NET_NIL_BROADCAST_ADDR,
     63        NET_NIL_BROADCAST_ADDR
    7264} nil_messages;
    7365
  • uspace/lib/c/include/ipc/services.h

    rb69e4c0 rdb96017  
    4949        SERVICE_CLIPBOARD  = FOURCC('c', 'l', 'i', 'p'),
    5050        SERVICE_NETWORKING = FOURCC('n', 'e', 't', ' '),
    51         SERVICE_LO         = FOURCC('l', 'o', ' ', ' '),
    52         SERVICE_NE2000     = FOURCC('n', 'e', '2', 'k'),
    5351        SERVICE_ETHERNET   = FOURCC('e', 't', 'h', ' '),
    5452        SERVICE_NILDUMMY   = FOURCC('n', 'i', 'l', 'd'),
  • uspace/lib/c/include/ipc/vfs.h

    rb69e4c0 rdb96017  
    4242#define FS_NAME_MAXLEN  20
    4343#define MAX_PATH_LEN    (64 * 1024)
     44#define MAX_MNTOPTS_LEN 256
    4445#define PLB_SIZE        (2 * MAX_PATH_LEN)
    4546
     
    8081        VFS_IN_DUP,
    8182        VFS_IN_WAIT_HANDLE,
     83        VFS_IN_MTAB_GET,
    8284} vfs_in_request_t;
    8385
  • uspace/lib/c/include/loc.h

    rb69e4c0 rdb96017  
    4646extern void loc_exchange_end(async_exch_t *);
    4747
    48 extern int loc_server_register(const char *, async_client_conn_t);
     48extern int loc_server_register(const char *);
    4949extern int loc_service_register(const char *, service_id_t *);
    5050extern int loc_service_register_with_iface(const char *, service_id_t *,
  • uspace/lib/c/include/net/device.h

    rb69e4c0 rdb96017  
    3232
    3333/** @file
    34  * Device identifier, state and usage statistics.
     34 * Network device.
    3535 */
    3636
    37 #ifndef LIBC_DEVICE_ID_TYPE_H_
    38 #define LIBC_DEVICE_ID_TYPE_H_
     37#ifndef LIBC_NET_DEVICE_H_
     38#define LIBC_NET_DEVICE_H_
    3939
    4040#include <adt/int_map.h>
     41#include <nic/nic.h>
    4142
    4243/** Device identifier to generic type map declaration. */
    43 #define DEVICE_MAP_DECLARE      INT_MAP_DECLARE
     44#define DEVICE_MAP_DECLARE  INT_MAP_DECLARE
    4445
    4546/** Device identifier to generic type map implementation. */
    46 #define DEVICE_MAP_IMPLEMENT    INT_MAP_IMPLEMENT
     47#define DEVICE_MAP_IMPLEMENT  INT_MAP_IMPLEMENT
     48
     49/** Device identifier type. */
     50typedef int nic_device_id_t;
    4751
    4852/** Invalid device identifier. */
    49 #define DEVICE_INVALID_ID       (-1)
    50 
    51 /** Device identifier type. */
    52 typedef int device_id_t;
    53 
    54 /** Device state type. */
    55 typedef enum device_state device_state_t;
    56 
    57 /** Type definition of the device usage statistics.
    58  * @see device_stats
    59  */
    60 typedef struct device_stats device_stats_t;
    61 
    62 /** Device state. */
    63 enum device_state {
    64         /** Device not present or not initialized. */
    65         NETIF_NULL = 0,
    66         /** Device present and stopped. */
    67         NETIF_STOPPED,
    68         /** Device present and active. */
    69         NETIF_ACTIVE,
    70         /** Device present but unable to transmit. */
    71         NETIF_CARRIER_LOST
    72 };
    73 
    74 /** Device usage statistics. */
    75 struct device_stats {
    76         /** Total packets received. */
    77         unsigned long receive_packets;
    78         /** Total packets transmitted. */
    79         unsigned long send_packets;
    80         /** Total bytes received. */
    81         unsigned long receive_bytes;
    82         /** Total bytes transmitted. */
    83         unsigned long send_bytes;
    84         /** Bad packets received counter. */
    85         unsigned long receive_errors;
    86         /** Packet transmition problems counter. */
    87         unsigned long send_errors;
    88         /** No space in buffers counter. */
    89         unsigned long receive_dropped;
    90         /** No space available counter. */
    91         unsigned long send_dropped;
    92         /** Total multicast packets received. */
    93         unsigned long multicast;
    94         /** The number of collisions due to congestion on the medium. */
    95         unsigned long collisions;
    96 
    97         /* detailed receive_errors */
    98 
    99         /** Received packet length error counter. */
    100         unsigned long receive_length_errors;
    101         /** Receiver buffer overflow counter. */
    102         unsigned long receive_over_errors;
    103         /** Received packet with crc error counter. */
    104         unsigned long receive_crc_errors;
    105         /** Received frame alignment error counter. */
    106         unsigned long receive_frame_errors;
    107         /** Receiver fifo overrun counter. */
    108         unsigned long receive_fifo_errors;
    109         /** Receiver missed packet counter. */
    110         unsigned long receive_missed_errors;
    111 
    112         /* detailed send_errors */
    113 
    114         /** Transmitter aborted counter. */
    115         unsigned long send_aborted_errors;
    116         /** Transmitter carrier errors counter. */
    117         unsigned long send_carrier_errors;
    118         /** Transmitter fifo overrun counter. */
    119         unsigned long send_fifo_errors;
    120         /** Transmitter carrier errors counter. */
    121         unsigned long send_heartbeat_errors;
    122         /** Transmitter window errors counter. */
    123         unsigned long send_window_errors;
    124 
    125         /* for cslip etc */
    126        
    127         /** Total compressed packets received. */
    128         unsigned long receive_compressed;
    129         /** Total compressed packet transmitted. */
    130         unsigned long send_compressed;
    131 };
     53#define NIC_DEVICE_INVALID_ID  (-1)
    13254
    13355#endif
  • uspace/lib/c/include/net/packet.h

    rb69e4c0 rdb96017  
    3838#define LIBC_PACKET_H_
    3939
     40#include <sys/types.h>
     41
    4042/** Packet identifier type.
    4143 * Value zero is used as an invalid identifier.
    4244 */
    43 typedef int packet_id_t;
     45typedef sysarg_t packet_id_t;
    4446
    4547/** Type definition of the packet.
     
    5153 * @see packet_dimension
    5254 */
    53 typedef struct packet_dimension packet_dimension_t;
     55typedef struct packet_dimension packet_dimension_t;
    5456
    5557/** Packet dimension. */
     
    7173extern packet_t *pm_find(packet_id_t);
    7274extern int pm_add(packet_t *);
     75extern void pm_remove(packet_t *);
    7376extern int pm_init(void);
    7477extern void pm_destroy(void);
  • uspace/lib/c/include/net/packet_header.h

    rb69e4c0 rdb96017  
    6161#define PACKET_MAGIC_VALUE      0x11227788
    6262
     63/** Maximum total length of the packet */
     64#define PACKET_MAX_LENGTH  65536
     65
    6366/** Packet header. */
    6467struct packet {
     
    8588         */
    8689        size_t length;
     90
     91        /** Offload info provided by the NIC */
     92        uint32_t offload_info;
     93
     94        /** Mask which bits in offload info are valid */
     95        uint32_t offload_mask;
    8796
    8897        /** Stored source and destination addresses length. */
  • uspace/lib/c/include/str.h

    rb69e4c0 rdb96017  
    6161extern size_t wstr_size(const wchar_t *str);
    6262
     63extern size_t str_nsize(const char *str, size_t max_size);
     64extern size_t wstr_nsize(const wchar_t *str, size_t max_size);
     65
    6366extern size_t str_lsize(const char *str, size_t max_len);
    6467extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
     
    9194extern char *str_rchr(const char *str, wchar_t ch);
    9295
     96extern void str_rtrim(char *str, wchar_t ch);
     97extern void str_ltrim(char *str, wchar_t ch);
     98
    9399extern bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos);
    94100extern bool wstr_remove(wchar_t *str, size_t pos);
     
    100106extern int str_uint16_t(const char *, char **, unsigned int, bool, uint16_t *);
    101107extern int str_uint32_t(const char *, char **, unsigned int, bool, uint32_t *);
    102 extern int str_uint64(const char *, char **, unsigned int, bool, uint64_t *);
     108extern int str_uint64_t(const char *, char **, unsigned int, bool, uint64_t *);
    103109extern int str_size_t(const char *, char **, unsigned int, bool, size_t *);
    104110
  • uspace/lib/c/include/sysinfo.h

    rb69e4c0 rdb96017  
    4040#include <abi/sysinfo.h>
    4141
     42extern char *sysinfo_get_keys(const char *, size_t *);
    4243extern sysinfo_item_val_type_t sysinfo_get_val_type(const char *);
    4344extern int sysinfo_get_value(const char *, sysarg_t *);
    4445extern void *sysinfo_get_data(const char *, size_t *);
     46extern void *sysinfo_get_property(const char *, const char *, size_t *);
    4547
    4648#endif
  • uspace/lib/c/include/vfs/vfs.h

    rb69e4c0 rdb96017  
    3939#include <ipc/vfs.h>
    4040#include <ipc/loc.h>
     41#include <adt/list.h>
    4142#include <stdio.h>
    4243#include <async.h>
     44#include "vfs_mtab.h"
    4345
    4446enum vfs_change_state_type {
     
    5557
    5658extern int fd_wait(void);
     59extern int get_mtab_list(list_t *mtab_list);
    5760
    5861extern async_exch_t *vfs_exchange_begin(void);
  • uspace/lib/c/include/vfs/vfs_mtab.h

    rb69e4c0 rdb96017  
    11/*
    2  * Copyright (c) 2006 Josef Cejka
     2 * Copyright (c) 2011 Maurizio Lombardi
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup kbd_port
    30  * @ingroup  kbd
     29/** @addtogroup libc
    3130 * @{
    3231 */
    33 
    3432/** @file
    35  * @brief i8042 port driver.
    3633 */
    3734
    38 #ifndef i8042_H_
    39 #define i8042_H_
     35#ifndef LIBC_VFS_MTAB_H_
     36#define LIBC_VFS_MTAB_H_
    4037
    4138#include <sys/types.h>
    42 #include <libarch/ddi.h>
    43 #include <async.h>
     39#include <ipc/vfs.h>
     40#include <adt/list.h>
    4441
    45 /** i8042 HW I/O interface */
    46 struct i8042 {
    47         ioport8_t data;
    48         uint8_t pad[3];
    49         ioport8_t status;
    50 } __attribute__ ((packed));
    51 typedef struct i8042 i8042_t;
    52 
    53 /** Softstate structure, one for each serial port (primary and aux). */
    54 typedef struct {
     42typedef struct mtab_ent {
     43        link_t link;
     44        char mp[MAX_PATH_LEN];
     45        char opts[MAX_MNTOPTS_LEN];
     46        char fs_name[FS_NAME_MAXLEN];
     47        unsigned int instance;
    5548        service_id_t service_id;
    56         async_sess_t *client_sess;
    57 } i8042_port_t;
     49} mtab_ent_t;
    5850
    5951#endif
    6052
    61 /**
    62  * @}
     53/** @}
    6354 */
Note: See TracChangeset for help on using the changeset viewer.