Changeset 8fb1bf82 in mainline for uspace/lib/c


Ignore:
Timestamp:
2010-11-25T13:42:50Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8df8415
Parents:
a93d79a (diff), eb667613 (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:
8 added
68 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    ra93d79a r8fb1bf82  
    5757        generic/clipboard.c \
    5858        generic/devmap.c \
     59        generic/devman.c \
     60        generic/device/hw_res.c \
     61        generic/device/char.c \
    5962        generic/event.c \
    6063        generic/errno.c \
  • uspace/lib/c/arch/abs32le/include/fibril.h

    ra93d79a r8fb1bf82  
    4444                (ctx)->pc = (uintptr_t) (_pc); \
    4545                (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
     46                (ctx)->fp = 0; \
    4647                (ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \
    4748        } while (0)
     
    5354typedef struct {
    5455        uintptr_t sp;
     56        uintptr_t fp;
    5557        uintptr_t pc;
    5658        uintptr_t tls;
    5759} context_t;
     60
     61static inline uintptr_t context_get_fp(context_t *ctx)
     62{
     63        /* On real hardware, this function returns the frame pointer. */
     64        return ctx->fp;
     65}
    5866
    5967#endif
  • uspace/lib/c/arch/abs32le/include/inttypes.h

    ra93d79a r8fb1bf82  
    3434#define LIBC_abs32le_INTTYPES_H_
    3535
    36 #define PRId8 "d"
    37 #define PRId16 "d"
    38 #define PRId32 "d"
    39 #define PRId64 "lld"
    40 #define PRIdPTR "d"
    41 
    42 #define PRIo8 "o"
    43 #define PRIo16 "o"
    44 #define PRIo32 "o"
    45 #define PRIo64 "llo"
    46 #define PRIoPTR "o"
    47 
    48 #define PRIu8 "u"
    49 #define PRIu16 "u"
    50 #define PRIu32 "u"
    51 #define PRIu64 "llu"
    52 #define PRIuPTR "u"
    53 
    54 #define PRIx8 "x"
    55 #define PRIx16 "x"
    56 #define PRIx32 "x"
    57 #define PRIx64 "llx"
    58 #define PRIxPTR "x"
    59 
    60 #define PRIX8 "X"
    61 #define PRIX16 "X"
    62 #define PRIX32 "X"
    63 #define PRIX64 "llX"
    64 #define PRIXPTR "X"
     36#define PRIdPTR  PRId32
     37#define PRIoPTR  PRIo32
     38#define PRIuPTR  PRIu32
     39#define PRIxPTR  PRIx32
     40#define PRIXPTR  PRIX32
    6541
    6642#endif
  • uspace/lib/c/arch/abs32le/include/istate.h

    ra93d79a r8fb1bf82  
    3636#define LIBC_abs32le__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * On real hardware this stores the registers which
    43  * need to be preserved during interupts.
    44  */
    45 typedef struct istate {
    46         uintptr_t ip;
    47         uintptr_t fp;
    48         uint32_t stack[];
    49 } istate_t;
    50 
    51 static inline uintptr_t istate_get_pc(istate_t *istate)
    52 {
    53         return istate->ip;
    54 }
    55 
    56 static inline uintptr_t istate_get_fp(istate_t *istate)
    57 {
    58         return istate->fp;
    59 }
     38#include <arch/istate.h>
    6039
    6140#endif
  • uspace/lib/c/arch/abs32le/src/stacktrace.c

    ra93d79a r8fb1bf82  
    5656uintptr_t stacktrace_fp_get(void)
    5757{
    58         return NULL;
     58        return (uintptr_t) NULL;
    5959}
    6060
    6161uintptr_t stacktrace_pc_get(void)
    6262{
    63         return NULL;
     63        return (uintptr_t) NULL;
    6464}
    6565
  • uspace/lib/c/arch/abs32le/src/tls.c

    ra93d79a r8fb1bf82  
    4646uintptr_t __aeabi_read_tp(void)
    4747{
    48         return NULL;
     48        return (uintptr_t) NULL;
    4949}
    5050
  • uspace/lib/c/arch/amd64/include/fibril.h

    ra93d79a r8fb1bf82  
    5656 */
    5757typedef struct {
    58     uint64_t sp;
    59     uint64_t pc;
    60    
    61     uint64_t rbx;
    62     uint64_t rbp;
     58        uint64_t sp;
     59        uint64_t pc;
    6360
    64     uint64_t r12;
    65     uint64_t r13;
    66     uint64_t r14;
    67     uint64_t r15;
     61        uint64_t rbx;
     62        uint64_t rbp;
    6863
    69     uint64_t tls;
     64        uint64_t r12;
     65        uint64_t r13;
     66        uint64_t r14;
     67        uint64_t r15;
     68
     69        uint64_t tls;
    7070} context_t;
     71
     72static inline uintptr_t context_get_fp(context_t *ctx)
     73{
     74        return ctx->rbp;
     75}
    7176
    7277#endif
  • uspace/lib/c/arch/amd64/include/inttypes.h

    ra93d79a r8fb1bf82  
    4141#define LIBC_amd64_INTTYPES_H_
    4242
    43 #define PRId8 "d"
    44 #define PRId16 "d"
    45 #define PRId32 "d"
    46 #define PRId64 "lld"
    47 #define PRIdPTR "lld"
    48 
    49 #define PRIo8 "o"
    50 #define PRIo16 "o"
    51 #define PRIo32 "o"
    52 #define PRIo64 "llo"
    53 #define PRIoPTR "llo"
    54 
    55 #define PRIu8 "u"
    56 #define PRIu16 "u"
    57 #define PRIu32 "u"
    58 #define PRIu64 "llu"
    59 #define PRIuPTR "llu"
    60 
    61 #define PRIx8 "x"
    62 #define PRIx16 "x"
    63 #define PRIx32 "x"
    64 #define PRIx64 "llx"
    65 #define PRIxPTR "llx"
    66 
    67 #define PRIX8 "X"
    68 #define PRIX16 "X"
    69 #define PRIX32 "X"
    70 #define PRIX64 "llX"
    71 #define PRIXPTR "llX"
     43#define PRIdPTR  PRId64
     44#define PRIoPTR  PRIo64
     45#define PRIuPTR  PRIu64
     46#define PRIxPTR  PRIx64
     47#define PRIXPTR  PRIX64
    7248
    7349#endif
  • uspace/lib/c/arch/amd64/include/istate.h

    ra93d79a r8fb1bf82  
    3636#define LIBC_amd64_ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint64_t rax;
    46         uint64_t rcx;
    47         uint64_t rdx;
    48         uint64_t rsi;
    49         uint64_t rdi;
    50         uint64_t r8;
    51         uint64_t r9;
    52         uint64_t r10;
    53         uint64_t r11;
    54         uint64_t rbp;
    55         uint64_t error_word;
    56         uint64_t rip;
    57         uint64_t cs;
    58         uint64_t rflags;
    59         uint64_t stack[]; /* Additional data on stack */
    60 } istate_t;
    61 
    62 static inline uintptr_t istate_get_pc(istate_t *istate)
    63 {
    64         return istate->rip;
    65 }
    66 
    67 static inline uintptr_t istate_get_fp(istate_t *istate)
    68 {
    69         return istate->rbp;
    70 }
     38#include <arch/istate.h>
    7139
    7240#endif
  • uspace/lib/c/arch/amd64/src/entry.s

    ra93d79a r8fb1bf82  
    4242        #
    4343        pushq $0
    44         mov %rsp, %rbp
     44        movq %rsp, %rbp
    4545       
    4646        # %rdi was deliberately chosen as the first argument is also in %rdi
  • uspace/lib/c/arch/amd64/src/fibril.S

    ra93d79a r8fb1bf82  
    4949        movq %rax, OFFSET_TLS(%rdi)
    5050               
    51         xorq %rax,%rax          # context_save returns 1
    52         incq %rax
     51        xorl %eax, %eax         # context_save returns 1
     52        incl %eax
    5353        ret
    5454
     
    6767        # Set thread local storage
    6868        movq OFFSET_TLS(%rdi), %rdi   # Set arg1 to TLS addr
    69         movq $1, %rax           # SYS_TLS_SET
     69        movl $1, %eax           # SYS_TLS_SET
    7070        syscall
    7171
    72         xorq %rax,%rax          # context_restore returns 0
     72        xorl %eax, %eax         # context_restore returns 0
    7373        ret
  • uspace/lib/c/arch/arm32/include/fibril.h

    ra93d79a r8fb1bf82  
    8686} context_t;
    8787
     88static inline uintptr_t context_get_fp(context_t *ctx)
     89{
     90        return ctx->fp;
     91}
     92
    8893
    8994#endif
  • uspace/lib/c/arch/arm32/include/inttypes.h

    ra93d79a r8fb1bf82  
    4141#define LIBC_arm32_INTTYPES_H_
    4242
    43 #define PRId8 "d"
    44 #define PRId16 "d"
    45 #define PRId32 "d"
    46 #define PRId64 "lld"
    47 #define PRIdPTR "d"
    48 
    49 #define PRIo8 "o"
    50 #define PRIo16 "o"
    51 #define PRIo32 "o"
    52 #define PRIo64 "llo"
    53 #define PRIoPTR "o"
    54 
    55 #define PRIu8 "u"
    56 #define PRIu16 "u"
    57 #define PRIu32 "u"
    58 #define PRIu64 "llu"
    59 #define PRIuPTR "u"
    60 
    61 #define PRIx8 "x"
    62 #define PRIx16 "x"
    63 #define PRIx32 "x"
    64 #define PRIx64 "llx"
    65 #define PRIxPTR "x"
    66 
    67 #define PRIX8 "X"
    68 #define PRIX16 "X"
    69 #define PRIX32 "X"
    70 #define PRIX64 "llX"
    71 #define PRIXPTR "X"
     43#define PRIdPTR  PRId32
     44#define PRIoPTR  PRIo32
     45#define PRIuPTR  PRIu32
     46#define PRIxPTR  PRIx32
     47#define PRIXPTR  PRIX32
    7248
    7349#endif
  • uspace/lib/c/arch/arm32/include/istate.h

    ra93d79a r8fb1bf82  
    3636#define LIBC_arm32__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint32_t spsr;
    46         uint32_t sp;
    47         uint32_t lr;
    48 
    49         uint32_t r0;
    50         uint32_t r1;
    51         uint32_t r2;
    52         uint32_t r3;
    53         uint32_t r4;
    54         uint32_t r5;
    55         uint32_t r6;
    56         uint32_t r7;
    57         uint32_t r8;
    58         uint32_t r9;
    59         uint32_t r10;
    60         uint32_t fp;
    61         uint32_t r12;
    62 
    63         uint32_t pc;
    64 } istate_t;
    65 
    66 static inline uintptr_t istate_get_pc(istate_t *istate)
    67 {
    68         return istate->pc;
    69 }
    70 
    71 static inline uintptr_t istate_get_fp(istate_t *istate)
    72 {
    73         return istate->fp;
    74 }
     38#include <arch/istate.h>
    7539
    7640#endif
  • uspace/lib/c/arch/ia32/include/fibril.h

    ra93d79a r8fb1bf82  
    6767} context_t;
    6868
     69static inline uintptr_t context_get_fp(context_t *ctx)
     70{
     71        return ctx->ebp;
     72}
     73
    6974#endif
    7075
  • uspace/lib/c/arch/ia32/include/inttypes.h

    ra93d79a r8fb1bf82  
    4141#define LIBC_ia32_INTTYPES_H_
    4242
    43 #define PRId8 "d"
    44 #define PRId16 "d"
    45 #define PRId32 "d"
    46 #define PRId64 "lld"
    47 #define PRIdPTR "d"
    48 
    49 #define PRIo8 "o"
    50 #define PRIo16 "o"
    51 #define PRIo32 "o"
    52 #define PRIo64 "llo"
    53 #define PRIoPTR "o"
    54 
    55 #define PRIu8 "u"
    56 #define PRIu16 "u"
    57 #define PRIu32 "u"
    58 #define PRIu64 "llu"
    59 #define PRIuPTR "u"
    60 
    61 #define PRIx8 "x"
    62 #define PRIx16 "x"
    63 #define PRIx32 "x"
    64 #define PRIx64 "llx"
    65 #define PRIxPTR "x"
    66 
    67 #define PRIX8 "X"
    68 #define PRIX16 "X"
    69 #define PRIX32 "X"
    70 #define PRIX64 "llX"
    71 #define PRIXPTR "X"
     43#define PRIdPTR  PRId32
     44#define PRIoPTR  PRIo32
     45#define PRIuPTR  PRIu32
     46#define PRIxPTR  PRIx32
     47#define PRIXPTR  PRIX32
    7248
    7349#endif
  • uspace/lib/c/arch/ia32/include/istate.h

    ra93d79a r8fb1bf82  
    3636#define LIBC_ia32__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint32_t eax;
    46         uint32_t ecx;
    47         uint32_t edx;
    48         uint32_t ebp;
    49 
    50         uint32_t gs;
    51         uint32_t fs;
    52         uint32_t es;
    53         uint32_t ds;
    54 
    55         uint32_t error_word;
    56         uint32_t eip;
    57         uint32_t cs;
    58         uint32_t eflags;
    59         uint32_t stack[];
    60 } istate_t;
    61 
    62 static inline uintptr_t istate_get_pc(istate_t *istate)
    63 {
    64         return istate->eip;
    65 }
    66 
    67 static inline uintptr_t istate_get_fp(istate_t *istate)
    68 {
    69         return istate->ebp;
    70 }
     38#include <arch/istate.h>
    7139
    7240#endif
  • uspace/lib/c/arch/ia64/include/fibril.h

    ra93d79a r8fb1bf82  
    130130} context_t;
    131131
     132static inline uintptr_t context_get_fp(context_t *ctx)
     133{
     134        return 0;       /* FIXME */
     135}
     136
    132137#endif
    133138
  • uspace/lib/c/arch/ia64/include/inttypes.h

    ra93d79a r8fb1bf82  
    4141#define LIBC_ia64_INTTYPES_H_
    4242
    43 #define PRId8 "d"
    44 #define PRId16 "d"
    45 #define PRId32 "d"
    46 #define PRId64 "ld"
    47 #define PRIdPTR "ld"
    48 
    49 #define PRIo8 "o"
    50 #define PRIo16 "o"
    51 #define PRIo32 "o"
    52 #define PRIo64 "lo"
    53 #define PRIoPTR "lo"
    54 
    55 #define PRIu8 "u"
    56 #define PRIu16 "u"
    57 #define PRIu32 "u"
    58 #define PRIu64 "lu"
    59 #define PRIuPTR "lu"
    60 
    61 #define PRIx8 "x"
    62 #define PRIx16 "x"
    63 #define PRIx32 "x"
    64 #define PRIx64 "lx"
    65 #define PRIxPTR "lx"
    66 
    67 #define PRIX8 "X"
    68 #define PRIX16 "X"
    69 #define PRIX32 "X"
    70 #define PRIX64 "lX"
    71 #define PRIXPTR "lX"
     43#define PRIdPTR  PRId64
     44#define PRIoPTR  PRIo64
     45#define PRIuPTR  PRIu64
     46#define PRIxPTR  PRIx64
     47#define PRIXPTR  PRIX64
    7248
    7349#endif
  • uspace/lib/c/arch/ia64/include/istate.h

    ra93d79a r8fb1bf82  
    3636#define LIBC_ia64_ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         /* TODO */
    46 } istate_t;
    47 
    48 static inline uintptr_t istate_get_pc(istate_t *istate)
    49 {
    50         /* TODO */
    51         return 0;
    52 }
    53 
    54 static inline uintptr_t istate_get_fp(istate_t *istate)
    55 {
    56         /* TODO */
    57         return 0;
    58 }
     38#include <arch/istate.h>
    5939
    6040#endif
  • uspace/lib/c/arch/mips32/include/fibril.h

    ra93d79a r8fb1bf82  
    8585} context_t;
    8686
     87static inline uintptr_t context_get_fp(context_t *ctx)
     88{
     89        return ctx->sp;
     90}
     91
    8792#endif
    8893
  • uspace/lib/c/arch/mips32/include/inttypes.h

    ra93d79a r8fb1bf82  
    4141#define LIBC_mips32_INTTYPES_H_
    4242
    43 #define PRId8 "d"
    44 #define PRId16 "d"
    45 #define PRId32 "d"
    46 #define PRId64 "lld"
    47 #define PRIdPTR "d"
    48 
    49 #define PRIo8 "o"
    50 #define PRIo16 "o"
    51 #define PRIo32 "o"
    52 #define PRIo64 "llo"
    53 #define PRIoPTR "o"
    54 
    55 #define PRIu8 "u"
    56 #define PRIu16 "u"
    57 #define PRIu32 "u"
    58 #define PRIu64 "llu"
    59 #define PRIuPTR "u"
    60 
    61 #define PRIx8 "x"
    62 #define PRIx16 "x"
    63 #define PRIx32 "x"
    64 #define PRIx64 "llx"
    65 #define PRIxPTR "x"
    66 
    67 #define PRIX8 "X"
    68 #define PRIX16 "X"
    69 #define PRIX32 "X"
    70 #define PRIX64 "llX"
    71 #define PRIXPTR "x"
     43#define PRIdPTR  PRId32
     44#define PRIoPTR  PRIo32
     45#define PRIuPTR  PRIu32
     46#define PRIxPTR  PRIx32
     47#define PRIXPTR  PRIX32
    7248
    7349#endif
  • uspace/lib/c/arch/mips32/include/istate.h

    ra93d79a r8fb1bf82  
    3636#define LIBC_mips32__ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         uint32_t at;
    46         uint32_t v0;
    47         uint32_t v1;
    48         uint32_t a0;
    49         uint32_t a1;
    50         uint32_t a2;
    51         uint32_t a3;
    52         uint32_t t0;
    53         uint32_t t1;
    54         uint32_t t2;
    55         uint32_t t3;
    56         uint32_t t4;
    57         uint32_t t5;
    58         uint32_t t6;
    59         uint32_t t7;
    60         uint32_t t8;
    61         uint32_t t9;
    62         uint32_t gp;
    63         uint32_t sp;
    64         uint32_t ra;
    65 
    66         uint32_t lo;
    67         uint32_t hi;
    68 
    69         uint32_t status; /* cp0_status */
    70         uint32_t epc; /* cp0_epc */
    71         uint32_t k1; /* We use it as thread-local pointer */
    72 } istate_t;
    73 
    74 static inline uintptr_t istate_get_pc(istate_t *istate)
    75 {
    76         return istate->epc;
    77 }
    78 
    79 static inline uintptr_t istate_get_fp(istate_t *istate)
    80 {
    81         /* TODO */
    82         return 0;
    83 }
     38#include <arch/istate.h>
    8439
    8540#endif
  • uspace/lib/c/arch/ppc32/include/fibril.h

    ra93d79a r8fb1bf82  
    7878} __attribute__ ((packed)) context_t;
    7979
     80static inline uintptr_t context_get_fp(context_t *ctx)
     81{
     82        return ctx->sp;
     83}
     84
    8085#endif
    8186
  • uspace/lib/c/arch/ppc32/include/inttypes.h

    ra93d79a r8fb1bf82  
    4141#define LIBC_ppc32_INTTYPES_H_
    4242
    43 #define PRId8 "d"
    44 #define PRId16 "d"
    45 #define PRId32 "d"
    46 #define PRId64 "lld"
    47 #define PRIdPTR "d"
    48 
    49 #define PRIo8 "o"
    50 #define PRIo16 "o"
    51 #define PRIo32 "o"
    52 #define PRIo64 "llo"
    53 #define PRIoPTR "o"
    54 
    55 #define PRIu8 "u"
    56 #define PRIu16 "u"
    57 #define PRIu32 "u"
    58 #define PRIu64 "llu"
    59 #define PRIuPTR "u"
    60 
    61 #define PRIx8 "x"
    62 #define PRIx16 "x"
    63 #define PRIx32 "x"
    64 #define PRIx64 "llx"
    65 #define PRIxPTR "x"
    66 
    67 #define PRIX8 "X"
    68 #define PRIX16 "X"
    69 #define PRIX32 "X"
    70 #define PRIX64 "llX"
    71 #define PRIXPTR "X"
     43#define PRIdPTR  PRId32
     44#define PRIoPTR  PRIo32
     45#define PRIuPTR  PRIu32
     46#define PRIxPTR  PRIx32
     47#define PRIXPTR  PRIX32
    7248
    7349#endif
  • uspace/lib/c/arch/sparc64/include/fibril.h

    ra93d79a r8fb1bf82  
    7777} context_t;
    7878
     79static inline uintptr_t context_get_fp(context_t *ctx)
     80{
     81        return ctx->sp + STACK_BIAS;
     82}
     83
    7984#endif
    8085
  • uspace/lib/c/arch/sparc64/include/inttypes.h

    ra93d79a r8fb1bf82  
    4141#define LIBC_sparc64_INTTYPES_H_
    4242
    43 #define PRId8 "d"
    44 #define PRId16 "d"
    45 #define PRId32 "d"
    46 #define PRId64 "lld"
    47 #define PRIdPTR "lld"
    48 
    49 #define PRIo8 "o"
    50 #define PRIo16 "o"
    51 #define PRIo32 "o"
    52 #define PRIo64 "llo"
    53 #define PRIoPTR "llo"
    54 
    55 #define PRIu8 "u"
    56 #define PRIu16 "u"
    57 #define PRIu32 "u"
    58 #define PRIu64 "llu"
    59 #define PRIuPTR "llu"
    60 
    61 #define PRIx8 "x"
    62 #define PRIx16 "x"
    63 #define PRIx32 "x"
    64 #define PRIx64 "llx"
    65 #define PRIxPTR "llx"
    66 
    67 #define PRIX8 "X"
    68 #define PRIX16 "X"
    69 #define PRIX32 "X"
    70 #define PRIX64 "llX"
    71 #define PRIXPTR "llX"
     43#define PRIdPTR  PRId64
     44#define PRIoPTR  PRIo64
     45#define PRIuPTR  PRIu64
     46#define PRIxPTR  PRIx64
     47#define PRIXPTR  PRIX64
    7248
    7349#endif
  • uspace/lib/c/arch/sparc64/include/istate.h

    ra93d79a r8fb1bf82  
    3636#define LIBC_sparc64_ISTATE_H_
    3737
    38 #include <sys/types.h>
    39 
    40 /** Interrupt context.
    41  *
    42  * This is a copy of the kernel definition with which it must be kept in sync.
    43  */
    44 typedef struct istate {
    45         /* TODO */
    46 } istate_t;
    47 
    48 static inline uintptr_t istate_get_pc(istate_t *istate)
    49 {
    50         /* TODO */
    51         return 0;
    52 }
    53 
    54 static inline uintptr_t istate_get_fp(istate_t *istate)
    55 {
    56         /* TODO */
    57         return 0;
    58 }
     38#include <arch/istate.h>
    5939
    6040#endif
  • uspace/lib/c/generic/adt/char_map.c

    ra93d79a r8fb1bf82  
    6060 * @param[in] value     The integral value to be stored for the key character
    6161 *                      string.
    62  * @returns             EOK on success.
    63  * @returns             ENOMEM if there is not enough memory left.
    64  * @returns             EEXIST if the key character string is already used.
     62 * @return              EOK on success.
     63 * @return              ENOMEM if there is not enough memory left.
     64 * @return              EEXIST if the key character string is already used.
    6565 */
    6666static int
    67 char_map_add_item(char_map_ref map, const char *identifier, size_t length,
     67char_map_add_item(char_map_t *map, const char *identifier, size_t length,
    6868    const int value)
    6969{
    7070        if (map->next == (map->size - 1)) {
    71                 char_map_ref *tmp;
    72 
    73                 tmp = (char_map_ref *) realloc(map->items,
    74                     sizeof(char_map_ref) * 2 * map->size);
     71                char_map_t **tmp;
     72
     73                tmp = (char_map_t **) realloc(map->items,
     74                    sizeof(char_map_t *) * 2 * map->size);
    7575                if (!tmp)
    7676                        return ENOMEM;
     
    8080        }
    8181
    82         map->items[map->next] = (char_map_ref) malloc(sizeof(char_map_t));
     82        map->items[map->next] = (char_map_t *) malloc(sizeof(char_map_t));
    8383        if (!map->items[map->next])
    8484                return ENOMEM;
     
    107107 *
    108108 * @param[in] map       The character string to integer map.
    109  * @returns             TRUE if the map is valid.
    110  * @returns             FALSE otherwise.
    111  */
    112 static int char_map_is_valid(const char_map_ref map)
     109 * @return              TRUE if the map is valid.
     110 * @return              FALSE otherwise.
     111 */
     112static int char_map_is_valid(const char_map_t *map)
    113113{
    114114        return map && (map->magic == CHAR_MAP_MAGIC_VALUE);
     
    127127 * @param[in] value     The integral value to be stored for the key character
    128128 *                      string.
    129  * @returns             EOK on success.
    130  * @returns             EINVAL if the map is not valid.
    131  * @returns             EINVAL if the identifier parameter is NULL.
    132  * @returns             EINVAL if the length parameter zero (0) and the
     129 * @return              EOK on success.
     130 * @return              EINVAL if the map is not valid.
     131 * @return              EINVAL if the identifier parameter is NULL.
     132 * @return              EINVAL if the length parameter zero (0) and the
    133133 *                      identifier parameter is an empty character string (the
    134134 *                      first character is the terminating zero ('\0')
    135135 *                      character.
    136  * @returns             EEXIST if the key character string is already used.
    137  * @returns             Other error codes as defined for the
     136 * @return              EEXIST if the key character string is already used.
     137 * @return              Other error codes as defined for the
    138138 *                      char_map_add_item() function.
    139139 */
    140140int
    141 char_map_add(char_map_ref map, const char *identifier, size_t length,
     141char_map_add(char_map_t *map, const char *identifier, size_t length,
    142142    const int value)
    143143{
     
    172172 * @param[in,out] map   The character string to integer map.
    173173 */
    174 void char_map_destroy(char_map_ref map)
     174void char_map_destroy(char_map_t *map)
    175175{
    176176        if (char_map_is_valid(map)) {
     
    196196 *                      zero (0) which means that the string is processed until
    197197 *                      the terminating zero ('\0') character is found.
    198  * @returns             The node holding the integral value assigned to the key
     198 * @return              The node holding the integral value assigned to the key
    199199 *                      character string.
    200  * @returns             NULL if the key is not assigned a node.
    201  */
    202 static char_map_ref
    203 char_map_find_node(const char_map_ref map, const char *identifier,
     200 * @return              NULL if the key is not assigned a node.
     201 */
     202static char_map_t *
     203char_map_find_node(const char_map_t *map, const char *identifier,
    204204    size_t length)
    205205{
     
    224224        }
    225225
    226         return map;
     226        return (char_map_t *) map;
    227227}
    228228
     
    239239 *                      zero (0) which means that the string is processed until
    240240 *                      the terminating zero ('\0') character is found.
    241  * @returns             The integral value assigned to the key character string.
    242  * @returns             CHAR_MAP_NULL if the key is not assigned a value.
    243  */
    244 int char_map_exclude(char_map_ref map, const char *identifier, size_t length)
    245 {
    246         char_map_ref node;
     241 * @return              The integral value assigned to the key character string.
     242 * @return              CHAR_MAP_NULL if the key is not assigned a value.
     243 */
     244int char_map_exclude(char_map_t *map, const char *identifier, size_t length)
     245{
     246        char_map_t *node;
    247247
    248248        node = char_map_find_node(map, identifier, length);
     
    267267 *                      zero (0) which means that the string is processed until
    268268 *                      the terminating zero ('\0') character is found.
    269  *  @returns            The integral value assigned to the key character string.
    270  *  @returns            CHAR_MAP_NULL if the key is not assigned a value.
    271  */
    272 int char_map_find(const char_map_ref map, const char *identifier, size_t length)
    273 {
    274         char_map_ref node;
     269 *  @return             The integral value assigned to the key character string.
     270 *  @return             CHAR_MAP_NULL if the key is not assigned a value.
     271 */
     272int char_map_find(const char_map_t *map, const char *identifier, size_t length)
     273{
     274        char_map_t *node;
    275275
    276276        node = char_map_find_node(map, identifier, length);
     
    281281 *
    282282 *  @param[in,out] map  The character string to integer map.
    283  *  @returns            EOK on success.
    284  *  @returns            EINVAL if the map parameter is NULL.
    285  *  @returns            ENOMEM if there is not enough memory left.
    286  */
    287 int char_map_initialize(char_map_ref map)
     283 *  @return             EOK on success.
     284 *  @return             EINVAL if the map parameter is NULL.
     285 *  @return             ENOMEM if there is not enough memory left.
     286 */
     287int char_map_initialize(char_map_t *map)
    288288{
    289289        if (!map)
     
    295295        map->next = 0;
    296296
    297         map->items = malloc(sizeof(char_map_ref) * map->size);
     297        map->items = malloc(sizeof(char_map_t *) * map->size);
    298298        if (!map->items) {
    299299                map->magic = 0;
     
    319319 *  @param[in] value    The integral value to be stored for the key character
    320320 *                      string.
    321  *  @returns            EOK on success.
    322  *  @returns            EINVAL if the map is not valid.
    323  *  @returns            EINVAL if the identifier parameter is NULL.
    324  *  @returns            EINVAL if the length parameter zero (0) and the
     321 *  @return             EOK on success.
     322 *  @return             EINVAL if the map is not valid.
     323 *  @return             EINVAL if the identifier parameter is NULL.
     324 *  @return             EINVAL if the length parameter zero (0) and the
    325325 *                      identifier parameter is an empty character string (the
    326326 *                      first character is the terminating zero ('\0) character.
    327  *  @returns            EEXIST if the key character string is already used.
    328  *  @returns            Other error codes as defined for the char_map_add_item()
     327 *  @return             EEXIST if the key character string is already used.
     328 *  @return             Other error codes as defined for the char_map_add_item()
    329329 *                      function.
    330330 */
    331331int
    332 char_map_update(char_map_ref map, const char *identifier, const size_t length,
     332char_map_update(char_map_t *map, const char *identifier, const size_t length,
    333333    const int value)
    334334{
    335         char_map_ref node;
     335        char_map_t *node;
    336336
    337337        node = char_map_find_node(map, identifier, length);
  • uspace/lib/c/generic/adt/dynamic_fifo.c

    ra93d79a r8fb1bf82  
    2828
    2929/** @addtogroup libc
    30  *  @{
     30 * @{
    3131 */
    3232
     
    3434 * Dynamic first in first out positive integer queue implementation.
    3535 */
     36
     37#include <adt/dynamic_fifo.h>
    3638
    3739#include <errno.h>
     
    3941#include <mem.h>
    4042
    41 #include <adt/dynamic_fifo.h>
    42 
    4343/** Internal magic value for a consistency check. */
    4444#define DYN_FIFO_MAGIC_VALUE    0x58627659
     
    5656 *
    5757 * @param[in] fifo      The dynamic queue.
    58  * @returns             TRUE if the queue is valid.
    59  * @returns             FALSE otherwise.
    60  */
    61 static int dyn_fifo_is_valid(dyn_fifo_ref fifo)
     58 * @return              TRUE if the queue is valid.
     59 * @return              FALSE otherwise.
     60 */
     61static int dyn_fifo_is_valid(dyn_fifo_t *fifo)
    6262{
    6363        return fifo && (fifo->magic_value == DYN_FIFO_MAGIC_VALUE);
     
    6868 * @param[in,out] fifo  The dynamic queue.
    6969 * @param[in] size      The initial queue size.
    70  * @returns             EOK on success.
    71  * @returns             EINVAL if the queue is not valid.
    72  * @returns             EBADMEM if the fifo parameter is NULL.
    73  * @returns             ENOMEM if there is not enough memory left.
    74  */
    75 int dyn_fifo_initialize(dyn_fifo_ref fifo, int size)
     70 * @return              EOK on success.
     71 * @return              EINVAL if the queue is not valid.
     72 * @return              EBADMEM if the fifo parameter is NULL.
     73 * @return              ENOMEM if there is not enough memory left.
     74 */
     75int dyn_fifo_initialize(dyn_fifo_t *fifo, int size)
    7676{
    7777        if (!fifo)
     
    100100 *                      this limit. May be zero or negative to indicate no
    101101 *                      limit.
    102  * @returns             EOK on success.
    103  * @returns             EINVAL if the queue is not valid.
    104  * @returns             ENOMEM if there is not enough memory left.
    105  */
    106 int dyn_fifo_push(dyn_fifo_ref fifo, int value, int max_size)
    107 {
    108         int * new_items;
     102 * @return              EOK on success.
     103 * @return              EINVAL if the queue is not valid.
     104 * @return              ENOMEM if there is not enough memory left.
     105 */
     106int dyn_fifo_push(dyn_fifo_t *fifo, int value, int max_size)
     107{
     108        int *new_items;
    109109
    110110        if (!dyn_fifo_is_valid(fifo))
     
    149149/** Returns and excludes the first item in the queue.
    150150 *
    151  * @param[in,out] fifoi The dynamic queue.
    152  * @returns             Value of the first item in the queue.
    153  * @returns             EINVAL if the queue is not valid.
    154  * @returns             ENOENT if the queue is empty.
    155  */
    156 int dyn_fifo_pop(dyn_fifo_ref fifo)
     151 * @param[in,out] fifo  The dynamic queue.
     152 * @return              Value of the first item in the queue.
     153 * @return              EINVAL if the queue is not valid.
     154 * @return              ENOENT if the queue is empty.
     155 */
     156int dyn_fifo_pop(dyn_fifo_t *fifo)
    157157{
    158158        int value;
     
    172172 *
    173173 * @param[in,out] fifo  The dynamic queue.
    174  * @returnsi            Value of the first item in the queue.
    175  * @returns             EINVAL if the queue is not valid.
    176  * @returns             ENOENT if the queue is empty.
    177  */
    178 int dyn_fifo_value(dyn_fifo_ref fifo)
     174 * @return              Value of the first item in the queue.
     175 * @return              EINVAL if the queue is not valid.
     176 * @return              ENOENT if the queue is empty.
     177 */
     178int dyn_fifo_value(dyn_fifo_t *fifo)
    179179{
    180180        if (!dyn_fifo_is_valid(fifo))
     
    189189/** Clears and destroys the queue.
    190190 *
    191  *  @param[in,out] fifo         The dynamic queue.
    192  *  @returns                    EOK on success.
    193  *  @returns                    EINVAL if the queue is not valid.
    194  */
    195 int dyn_fifo_destroy(dyn_fifo_ref fifo)
     191 * @param[in,out] fifo  The dynamic queue.
     192 * @return              EOK on success.
     193 * @return              EINVAL if the queue is not valid.
     194 */
     195int dyn_fifo_destroy(dyn_fifo_t *fifo)
    196196{
    197197        if (!dyn_fifo_is_valid(fifo))
  • uspace/lib/c/generic/adt/measured_strings.c

    ra93d79a r8fb1bf82  
    4141#include <unistd.h>
    4242#include <errno.h>
    43 #include <err.h>
    4443#include <async.h>
    4544
     
    5251 * @param[in] string    The initial character string to be stored.
    5352 * @param[in] length    The length of the given string without the terminating
    54  *                      zero ('/0') character. If the length is zero (0), the
    55  *                      actual length is computed. The given length is used and
    56  *                      appended with the terminating zero ('\\0') character
     53 *                      zero ('\0') character. If the length is zero, the actual
     54 *                      length is computed. The given length is used and
     55 *                      appended with the terminating zero ('\0') character
    5756 *                      otherwise.
    58  * @returns             The new bundled character string with measured length.
    59  * @returns             NULL if there is not enough memory left.
    60  */
    61 measured_string_ref
    62 measured_string_create_bulk(const char * string, size_t length)
    63 {
    64         measured_string_ref new;
     57 * @return              The new bundled character string with measured length.
     58 * @return              NULL if there is not enough memory left.
     59 */
     60measured_string_t *
     61measured_string_create_bulk(const char *string, size_t length)
     62{
     63        measured_string_t *new;
    6564
    6665        if (length == 0) {
    6766                while (string[length])
    68                         ++length;
    69         }
    70         new = (measured_string_ref) malloc(sizeof(measured_string_t) +
     67                        length++;
     68        }
     69        new = (measured_string_t *) malloc(sizeof(measured_string_t) +
    7170            (sizeof(char) * (length + 1)));
    7271        if (!new)
     
    8584 *
    8685 * @param[in] source    The source measured string to be copied.
    87  * @returns             The copy of the given measured string.
    88  * @returns             NULL if the source parameter is NULL.
    89  * @returns             NULL if there is not enough memory left.
    90  */
    91 measured_string_ref measured_string_copy(measured_string_ref source)
    92 {
    93         measured_string_ref new;
     86 * @return              The copy of the given measured string.
     87 * @return              NULL if the source parameter is NULL.
     88 * @return              NULL if there is not enough memory left.
     89 */
     90measured_string_t *measured_string_copy(measured_string_t *source)
     91{
     92        measured_string_t *new;
    9493
    9594        if (!source)
    9695                return NULL;
    9796
    98         new = (measured_string_ref) malloc(sizeof(measured_string_t));
     97        new = (measured_string_t *) malloc(sizeof(measured_string_t));
    9998        if (new) {
    10099                new->value = (char *) malloc(source->length + 1);
     
    104103                        new->value[new->length] = '\0';
    105104                        return new;
    106                 } else {
    107                         free(new);
    108105                }
     106                free(new);
    109107        }
    110108
     
    122120 *                      actual character strings.
    123121 *  @param[in] count    The size of the measured strings array.
    124  *  @returns            EOK on success.
    125  *  @returns            EINVAL if the strings or data parameter is NULL.
    126  *  @returns            EINVAL if the count parameter is zero (0).
    127  *  @returns            EINVAL if the sent array differs in size.
    128  *  @returns            EINVAL if there is inconsistency in sent measured
     122 *  @return             EOK on success.
     123 *  @return             EINVAL if the strings or data parameter is NULL.
     124 *  @return             EINVAL if the count parameter is zero (0).
     125 *  @return             EINVAL if the sent array differs in size.
     126 *  @return             EINVAL if there is inconsistency in sent measured
    129127 *                      strings' lengths (should not occur).
    130  *  @returns            ENOMEM if there is not enough memory left.
    131  *  @returns            Other error codes as defined for the
     128 *  @return             ENOMEM if there is not enough memory left.
     129 *  @return             Other error codes as defined for the
    132130 *                      async_data_write_finalize() function.
    133131 */
    134132int
    135 measured_strings_receive(measured_string_ref *strings, char **data,
     133measured_strings_receive(measured_string_t **strings, char **data,
    136134    size_t count)
    137135{
    138         ERROR_DECLARE;
    139 
    140136        size_t *lengths;
    141137        size_t index;
     
    143139        char *next;
    144140        ipc_callid_t callid;
     141        int rc;
    145142
    146143        if ((!strings) || (!data) || (count <= 0))
     
    156153                return EINVAL;
    157154        }
    158         if(ERROR_OCCURRED(async_data_write_finalize(callid, lengths,
    159             sizeof(size_t) * (count + 1)))) {
    160                 free(lengths);
    161                 return ERROR_CODE;
     155        rc = async_data_write_finalize(callid, lengths, length);
     156        if (rc != EOK) {
     157                free(lengths);
     158                return rc;
    162159        }
    163160
    164161        *data = malloc(lengths[count]);
    165         if (!(*data)) {
     162        if (!*data) {
    166163                free(lengths);
    167164                return ENOMEM;
     
    169166        (*data)[lengths[count] - 1] = '\0';
    170167
    171         *strings = (measured_string_ref) malloc(sizeof(measured_string_t) *
     168        *strings = (measured_string_t *) malloc(sizeof(measured_string_t) *
    172169            count);
    173         if (!(*strings)) {
     170        if (!*strings) {
    174171                free(lengths);
    175172                free(*data);
     
    178175
    179176        next = *data;
    180         for (index = 0; index < count; ++index) {
     177        for (index = 0; index < count; index++) {
    181178                (*strings)[index].length = lengths[index];
    182179                if (lengths[index] > 0) {
    183                         if ((!async_data_write_receive(&callid, &length)) ||
     180                        if (!async_data_write_receive(&callid, &length) ||
    184181                            (length != lengths[index])) {
    185182                                free(*data);
     
    188185                                return EINVAL;
    189186                        }
    190                         ERROR_PROPAGATE(async_data_write_finalize(callid, next,
    191                             lengths[index]));
     187                        rc = async_data_write_finalize(callid, next,
     188                            lengths[index]);
     189                        if (rc != EOK) {
     190                                free(*data);
     191                                free(*strings);
     192                                free(lengths);
     193                                return rc;
     194                        }
    192195                        (*strings)[index].value = next;
    193196                        next += lengths[index];
    194                         *next = '\0';
    195                         ++next;
     197                        *next++ = '\0';
    196198                } else {
    197199                        (*strings)[index].value = NULL;
     
    207209 * @param[in] strings   The measured strings array to be processed.
    208210 * @param[in] count     The measured strings array size.
    209  * @returns             The computed sizes array.
    210  * @returns             NULL if there is not enough memory left.
    211  */
    212 static size_t *prepare_lengths(const measured_string_ref strings, size_t count)
     211 * @return              The computed sizes array.
     212 * @return              NULL if there is not enough memory left.
     213 */
     214static size_t *prepare_lengths(const measured_string_t *strings, size_t count)
    213215{
    214216        size_t *lengths;
     
    221223
    222224        length = 0;
    223         for (index = 0; index < count; ++ index) {
     225        for (index = 0; index < count; index++) {
    224226                lengths[index] = strings[index].length;
    225227                length += lengths[index] + 1;
     
    236238 * @param[in] strings   The measured strings array to be transferred.
    237239 * @param[in] count     The measured strings array size.
    238  * @returns             EOK on success.
    239  * @returns             EINVAL if the strings parameter is NULL.
    240  * @returns             EINVAL if the count parameter is zero (0).
    241  * @returns             EINVAL if the calling module does not accept the given
     240 * @return              EOK on success.
     241 * @return              EINVAL if the strings parameter is NULL.
     242 * @return              EINVAL if the count parameter is zero (0).
     243 * @return              EINVAL if the calling module does not accept the given
    242244 *                      array size.
    243  * @returns             EINVAL if there is inconsistency in sent measured
     245 * @return              EINVAL if there is inconsistency in sent measured
    244246 *                      strings' lengths (should not occur).
    245  * @returns             Other error codes as defined for the
     247 * @return              Other error codes as defined for the
    246248 *                      async_data_read_finalize() function.
    247249 */
    248 int measured_strings_reply(const measured_string_ref strings, size_t count)
    249 {
    250         ERROR_DECLARE;
    251 
     250int measured_strings_reply(const measured_string_t *strings, size_t count)
     251{
    252252        size_t *lengths;
    253253        size_t index;
    254254        size_t length;
    255255        ipc_callid_t callid;
     256        int rc;
    256257
    257258        if ((!strings) || (count <= 0))
     
    262263                return ENOMEM;
    263264
    264         if ((!async_data_read_receive(&callid, &length)) ||
     265        if (!async_data_read_receive(&callid, &length) ||
    265266            (length != sizeof(size_t) * (count + 1))) {
    266267                free(lengths);
    267268                return EINVAL;
    268269        }
    269         if (ERROR_OCCURRED(async_data_read_finalize(callid, lengths,
    270             sizeof(size_t) * (count + 1)))) {
    271                 free(lengths);
    272                 return ERROR_CODE;
     270        rc = async_data_read_finalize(callid, lengths, length);
     271        if (rc != EOK) {
     272                free(lengths);
     273                return rc;
    273274        }
    274275        free(lengths);
    275276
    276         for (index = 0; index < count; ++ index) {
     277        for (index = 0; index < count; index++) {
    277278                if (strings[index].length > 0) {
    278                         if((!async_data_read_receive(&callid, &length)) ||
     279                        if (!async_data_read_receive(&callid, &length) ||
    279280                            (length != strings[index].length)) {
    280281                                return EINVAL;
    281282                        }
    282                         ERROR_PROPAGATE(async_data_read_finalize(callid,
    283                             strings[index].value, strings[index].length));
     283                        rc = async_data_read_finalize(callid,
     284                            strings[index].value, strings[index].length);
     285                        if (rc != EOK)
     286                                return rc;
    284287                }
    285288        }
     
    299302 *                      actual character strings.
    300303 * @param[in] count     The size of the measured strings array.
    301  * @returns             EOK on success.
    302  * @returns             EINVAL if the strings or data parameter is NULL.
    303  * @returns             EINVAL if the phone or count parameter is not positive.
    304  * @returns             EINVAL if the sent array differs in size.
    305  * @returns             ENOMEM if there is not enough memory left.
    306  * @returns             Other error codes as defined for the
     304 * @return              EOK on success.
     305 * @return              EINVAL if the strings or data parameter is NULL.
     306 * @return              EINVAL if the phone or count parameter is not positive.
     307 * @return              EINVAL if the sent array differs in size.
     308 * @return              ENOMEM if there is not enough memory left.
     309 * @return              Other error codes as defined for the
    307310 *                      async_data_read_start() function.
    308311 */
    309312int
    310 measured_strings_return(int phone, measured_string_ref *strings, char **data,
     313measured_strings_return(int phone, measured_string_t **strings, char **data,
    311314    size_t count)
    312315{
    313         ERROR_DECLARE;
    314 
    315316        size_t *lengths;
    316317        size_t index;
    317318        char *next;
    318 
    319         if ((phone <= 0) || (!strings) || (!data) || (count <= 0))
     319        int rc;
     320
     321        if ((phone < 0) || (!strings) || (!data) || (count <= 0))
    320322                return EINVAL;
    321323
     
    324326                return ENOMEM;
    325327
    326         if (ERROR_OCCURRED(async_data_read_start(phone, lengths,
    327             sizeof(size_t) * (count + 1)))) {
    328                 free(lengths);
    329                 return ERROR_CODE;
     328        rc = async_data_read_start(phone, lengths,
     329            sizeof(size_t) * (count + 1));
     330        if (rc != EOK) {
     331                free(lengths);
     332                return rc;
    330333        }
    331334
    332335        *data = malloc(lengths[count]);
    333         if (!(*data)) {
    334                 free(lengths);
    335                 return ENOMEM;
    336         }
    337 
    338         *strings = (measured_string_ref) malloc(sizeof(measured_string_t) *
     336        if (!*data) {
     337                free(lengths);
     338                return ENOMEM;
     339        }
     340
     341        *strings = (measured_string_t *) malloc(sizeof(measured_string_t) *
    339342            count);
    340         if (!(*strings)) {
     343        if (!*strings) {
    341344                free(lengths);
    342345                free(*data);
     
    345348
    346349        next = *data;
    347         for (index = 0; index < count; ++ index) {
     350        for (index = 0; index < count; index++) {
    348351                (*strings)[index].length = lengths[index];
    349352                if (lengths[index] > 0) {
    350                         ERROR_PROPAGATE(async_data_read_start(phone, next,
    351                             lengths[index]));
     353                        rc = async_data_read_start(phone, next, lengths[index]);
     354                        if (rc != EOK) {
     355                                free(lengths);
     356                                free(data);
     357                                free(strings);
     358                                return rc;
     359                        }
    352360                        (*strings)[index].value = next;
    353361                        next += lengths[index];
    354                         *next = '\0';
    355                         ++ next;
     362                        *next++ = '\0';
    356363                } else {
    357364                        (*strings)[index].value = NULL;
     
    371378 * @param[in] strings   The measured strings array to be transferred.
    372379 * @param[in] count     The measured strings array size.
    373  * @returns             EOK on success.
    374  * @returns             EINVAL if the strings parameter is NULL.
    375  * @returns             EINVAL if the phone or count parameter is not positive.
    376  * @returns             Other error codes as defined for the
     380 * @return              EOK on success.
     381 * @return              EINVAL if the strings parameter is NULL.
     382 * @return              EINVAL if the phone or count parameter is not positive.
     383 * @return              Other error codes as defined for the
    377384 *                      async_data_write_start() function.
    378385 */
    379386int
    380 measured_strings_send(int phone, const measured_string_ref strings,
     387measured_strings_send(int phone, const measured_string_t *strings,
    381388    size_t count)
    382389{
    383         ERROR_DECLARE;
    384 
    385390        size_t *lengths;
    386391        size_t index;
    387 
    388         if ((phone <= 0) || (!strings) || (count <= 0))
     392        int rc;
     393
     394        if ((phone < 0) || (!strings) || (count <= 0))
    389395                return EINVAL;
    390396
     
    393399                return ENOMEM;
    394400
    395         if (ERROR_OCCURRED(async_data_write_start(phone, lengths,
    396             sizeof(size_t) * (count + 1)))) {
    397                 free(lengths);
    398                 return ERROR_CODE;
     401        rc = async_data_write_start(phone, lengths,
     402            sizeof(size_t) * (count + 1));
     403        if (rc != EOK) {
     404                free(lengths);
     405                return rc;
    399406        }
    400407
    401408        free(lengths);
    402409
    403         for (index = 0; index < count; ++index) {
     410        for (index = 0; index < count; index++) {
    404411                if (strings[index].length > 0) {
    405                         ERROR_PROPAGATE(async_data_write_start(phone,
    406                             strings[index].value, strings[index].length));
     412                        rc = async_data_write_start(phone, strings[index].value,
     413                            strings[index].length);
     414                        if (rc != EOK)
     415                                return rc;
    407416                }
    408417        }
  • uspace/lib/c/generic/async.c

    ra93d79a r8fb1bf82  
    536536                if (callid)
    537537                        ipc_answer_0(callid, ENOMEM);
    538                 return NULL;
     538                return (uintptr_t) NULL;
    539539        }
    540540       
     
    556556                if (callid)
    557557                        ipc_answer_0(callid, ENOMEM);
    558                 return NULL;
     558                return (uintptr_t) NULL;
    559559        }
    560560       
  • uspace/lib/c/generic/ddi.c

    ra93d79a r8fb1bf82  
    9696}
    9797
     98/** Enable an interrupt.
     99 *
     100 * @param irq the interrupt.
     101 *
     102 * @return Zero on success, negative error code otherwise.
     103 */
     104int interrupt_enable(int irq)
     105{
     106        return __SYSCALL2(SYS_INTERRUPT_ENABLE, (sysarg_t) irq, 1);
     107}
     108
     109/** Disable an interrupt.
     110 *
     111 * @param irq the interrupt.
     112 *
     113 * @return Zero on success, negative error code otherwise.
     114 */
     115int interrupt_disable(int irq)
     116{
     117        return __SYSCALL2(SYS_INTERRUPT_ENABLE, (sysarg_t) irq, 0);
     118}
     119
    98120/** Enable PIO for specified I/O range.
    99121 *
  • uspace/lib/c/generic/devmap.c

    ra93d79a r8fb1bf82  
    132132 *
    133133 */
    134 int devmap_device_register(const char *fqdn, dev_handle_t *handle)
     134int devmap_device_register(const char *fqdn, devmap_handle_t *handle)
    135135{
    136136        int phone = devmap_get_phone(DEVMAP_DRIVER, IPC_FLAG_BLOCKING);
     
    163163       
    164164        if (handle != NULL)
    165                 *handle = (dev_handle_t) IPC_GET_ARG1(answer);
     165                *handle = (devmap_handle_t) IPC_GET_ARG1(answer);
    166166       
    167167        return retval;
    168168}
    169169
    170 int devmap_device_get_handle(const char *fqdn, dev_handle_t *handle, unsigned int flags)
     170int devmap_device_get_handle(const char *fqdn, devmap_handle_t *handle, unsigned int flags)
    171171{
    172172        int phone = devmap_get_phone(DEVMAP_CLIENT, flags);
     
    194194        if (retval != EOK) {
    195195                if (handle != NULL)
    196                         *handle = (dev_handle_t) -1;
     196                        *handle = (devmap_handle_t) -1;
    197197                return retval;
    198198        }
    199199       
    200200        if (handle != NULL)
    201                 *handle = (dev_handle_t) IPC_GET_ARG1(answer);
     201                *handle = (devmap_handle_t) IPC_GET_ARG1(answer);
    202202       
    203203        return retval;
    204204}
    205205
    206 int devmap_namespace_get_handle(const char *name, dev_handle_t *handle, unsigned int flags)
     206int devmap_namespace_get_handle(const char *name, devmap_handle_t *handle, unsigned int flags)
    207207{
    208208        int phone = devmap_get_phone(DEVMAP_CLIENT, flags);
     
    230230        if (retval != EOK) {
    231231                if (handle != NULL)
    232                         *handle = (dev_handle_t) -1;
     232                        *handle = (devmap_handle_t) -1;
    233233                return retval;
    234234        }
    235235       
    236236        if (handle != NULL)
    237                 *handle = (dev_handle_t) IPC_GET_ARG1(answer);
     237                *handle = (devmap_handle_t) IPC_GET_ARG1(answer);
    238238       
    239239        return retval;
    240240}
    241241
    242 devmap_handle_type_t devmap_handle_probe(dev_handle_t handle)
     242devmap_handle_type_t devmap_handle_probe(devmap_handle_t handle)
    243243{
    244244        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     
    255255}
    256256
    257 int devmap_device_connect(dev_handle_t handle, unsigned int flags)
     257int devmap_device_connect(devmap_handle_t handle, unsigned int flags)
    258258{
    259259        int phone;
     
    305305}
    306306
    307 static size_t devmap_count_devices_internal(int phone, dev_handle_t ns_handle)
     307static size_t devmap_count_devices_internal(int phone, devmap_handle_t ns_handle)
    308308{
    309309        ipcarg_t count;
     
    325325}
    326326
    327 size_t devmap_count_devices(dev_handle_t ns_handle)
     327size_t devmap_count_devices(devmap_handle_t ns_handle)
    328328{
    329329        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
     
    387387}
    388388
    389 size_t devmap_get_devices(dev_handle_t ns_handle, dev_desc_t **data)
     389size_t devmap_get_devices(devmap_handle_t ns_handle, dev_desc_t **data)
    390390{
    391391        int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING);
  • uspace/lib/c/generic/fibril.c

    ra93d79a r8fb1bf82  
    275275        fibril->func = func;
    276276        fibril->arg = arg;
     277
     278        fibril->waits_for = NULL;
    277279       
    278280        context_save(&fibril->ctx);
  • uspace/lib/c/generic/fibril_synch.c

    ra93d79a r8fb1bf82  
    4242#include <errno.h>
    4343#include <assert.h>
     44#include <stacktrace.h>
     45#include <stdlib.h>
    4446
    4547static void optimize_execution_power(void)
     
    5658}
    5759
     60static void print_deadlock(fibril_owner_info_t *oi)
     61{
     62        fibril_t *f = (fibril_t *) fibril_get_id();
     63
     64        printf("Deadlock detected.\n");
     65        stacktrace_print();
     66
     67        printf("Fibril %p waits for primitive %p.\n", f, oi);
     68
     69        while (oi && oi->owned_by) {
     70                printf("Primitive %p is owned by fibril %p.\n",
     71                    oi, oi->owned_by);
     72                if (oi->owned_by == f)
     73                        break;
     74                stacktrace_print_fp_pc(context_get_fp(&oi->owned_by->ctx),
     75                    oi->owned_by->ctx.pc);
     76                printf("Fibril %p waits for primitive %p.\n",
     77                     oi->owned_by, oi->owned_by->waits_for);
     78                oi = oi->owned_by->waits_for;
     79        }
     80}
     81
     82
     83static void check_for_deadlock(fibril_owner_info_t *oi)
     84{
     85        while (oi && oi->owned_by) {
     86                if (oi->owned_by == (fibril_t *) fibril_get_id()) {
     87                        print_deadlock(oi);
     88                        abort();
     89                }
     90                oi = oi->owned_by->waits_for;
     91        }
     92}
     93
     94
    5895void fibril_mutex_initialize(fibril_mutex_t *fm)
    5996{
     97        fm->oi.owned_by = NULL;
    6098        fm->counter = 1;
    6199        list_initialize(&fm->waiters);
     
    64102void fibril_mutex_lock(fibril_mutex_t *fm)
    65103{
     104        fibril_t *f = (fibril_t *) fibril_get_id();
     105
    66106        futex_down(&async_futex);
    67107        if (fm->counter-- <= 0) {
     
    73113                link_initialize(&wdata.wu_event.link);
    74114                list_append(&wdata.wu_event.link, &fm->waiters);
     115                check_for_deadlock(&fm->oi);
     116                f->waits_for = &fm->oi;
    75117                fibril_switch(FIBRIL_TO_MANAGER);
    76118        } else {
     119                fm->oi.owned_by = f;
    77120                futex_up(&async_futex);
    78121        }
     
    86129        if (fm->counter > 0) {
    87130                fm->counter--;
     131                fm->oi.owned_by = (fibril_t *) fibril_get_id();
    88132                locked = true;
    89133        }
     
    99143                link_t *tmp;
    100144                awaiter_t *wdp;
     145                fibril_t *f;
    101146       
    102147                assert(!list_empty(&fm->waiters));
     
    105150                wdp->active = true;
    106151                wdp->wu_event.inlist = false;
     152
     153                f = (fibril_t *) wdp->fid;
     154                fm->oi.owned_by = f;
     155                f->waits_for = NULL;
     156
    107157                list_remove(&wdp->wu_event.link);
    108158                fibril_add_ready(wdp->fid);
    109159                optimize_execution_power();
     160        } else {
     161                fm->oi.owned_by = NULL;
    110162        }
    111163}
     
    120172void fibril_rwlock_initialize(fibril_rwlock_t *frw)
    121173{
     174        frw->oi.owned_by = NULL;
    122175        frw->writers = 0;
    123176        frw->readers = 0;
     
    127180void fibril_rwlock_read_lock(fibril_rwlock_t *frw)
    128181{
     182        fibril_t *f = (fibril_t *) fibril_get_id();
     183       
    129184        futex_down(&async_futex);
    130185        if (frw->writers) {
    131                 fibril_t *f = (fibril_t *) fibril_get_id();
    132186                awaiter_t wdata;
    133187
     
    138192                f->flags &= ~FIBRIL_WRITER;
    139193                list_append(&wdata.wu_event.link, &frw->waiters);
     194                check_for_deadlock(&frw->oi);
     195                f->waits_for = &frw->oi;
    140196                fibril_switch(FIBRIL_TO_MANAGER);
    141197        } else {
    142                 frw->readers++;
     198                /* Consider the first reader the owner. */
     199                if (frw->readers++ == 0)
     200                        frw->oi.owned_by = f;
    143201                futex_up(&async_futex);
    144202        }
     
    147205void fibril_rwlock_write_lock(fibril_rwlock_t *frw)
    148206{
     207        fibril_t *f = (fibril_t *) fibril_get_id();
     208       
    149209        futex_down(&async_futex);
    150210        if (frw->writers || frw->readers) {
    151                 fibril_t *f = (fibril_t *) fibril_get_id();
    152211                awaiter_t wdata;
    153212
     
    158217                f->flags |= FIBRIL_WRITER;
    159218                list_append(&wdata.wu_event.link, &frw->waiters);
     219                check_for_deadlock(&frw->oi);
     220                f->waits_for = &frw->oi;
    160221                fibril_switch(FIBRIL_TO_MANAGER);
    161222        } else {
     223                frw->oi.owned_by = f;
    162224                frw->writers++;
    163225                futex_up(&async_futex);
     
    170232        assert(frw->readers || (frw->writers == 1));
    171233        if (frw->readers) {
    172                 if (--frw->readers)
     234                if (--frw->readers) {
     235                        if (frw->oi.owned_by == (fibril_t *) fibril_get_id()) {
     236                                /*
     237                                 * If this reader firbril was considered the
     238                                 * owner of this rwlock, clear the ownership
     239                                 * information even if there are still more
     240                                 * readers.
     241                                 *
     242                                 * This is the limitation of the detection
     243                                 * mechanism rooted in the fact that tracking
     244                                 * all readers would require dynamically
     245                                 * allocated memory for keeping linkage info.
     246                                 */
     247                                frw->oi.owned_by = NULL;
     248                        }
    173249                        goto out;
     250                }
    174251        } else {
    175252                frw->writers--;
     
    177254       
    178255        assert(!frw->readers && !frw->writers);
     256       
     257        frw->oi.owned_by = NULL;
    179258       
    180259        while (!list_empty(&frw->waiters)) {
     
    185264                wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
    186265                f = (fibril_t *) wdp->fid;
     266               
     267                f->waits_for = NULL;
    187268               
    188269                if (f->flags & FIBRIL_WRITER) {
     
    194275                        fibril_add_ready(wdp->fid);
    195276                        frw->writers++;
     277                        frw->oi.owned_by = f;
    196278                        optimize_execution_power();
    197279                        break;
     
    201283                        list_remove(&wdp->wu_event.link);
    202284                        fibril_add_ready(wdp->fid);
    203                         frw->readers++;
     285                        if (frw->readers++ == 0) {
     286                                /* Consider the first reader the owner. */
     287                                frw->oi.owned_by = f;
     288                        }
    204289                        optimize_execution_power();
    205290                }
  • uspace/lib/c/generic/io/klog.c

    ra93d79a r8fb1bf82  
    5252void klog_update(void)
    5353{
    54         (void) __SYSCALL3(SYS_KLOG, 1, NULL, 0);
     54        (void) __SYSCALL3(SYS_KLOG, 1, (uintptr_t) NULL, 0);
    5555}
    5656
  • uspace/lib/c/generic/net/icmp_api.c

    ra93d79a r8fb1bf82  
    6666 * @param[in] addr      The target host address.
    6767 * @param[in] addrlen   The torget host address length.
    68  * @returns             ICMP_ECHO on success.
    69  * @returns             ETIMEOUT if the reply has not arrived before the
     68 * @return              ICMP_ECHO on success.
     69 * @return              ETIMEOUT if the reply has not arrived before the
    7070 *                      timeout.
    71  * @returns             ICMP type of the received error notification.
    72  * @returns             EINVAL if the addrlen parameter is less or equal to
     71 * @return              ICMP type of the received error notification.
     72 * @return              EINVAL if the addrlen parameter is less or equal to
    7373 *                      zero.
    74  * @returns             ENOMEM if there is not enough memory left.
    75  * @returns             EPARTY if there was an internal error.
     74 * @return              ENOMEM if there is not enough memory left.
     75 * @return              EPARTY if there was an internal error.
    7676 */
    7777int
  • uspace/lib/c/generic/net/icmp_common.c

    ra93d79a r8fb1bf82  
    5050 * @param[in] timeout   The connection timeout in microseconds. No timeout if
    5151 *                      set to zero.
    52  * @returns             The ICMP module phone on success.
    53  * @returns             ETIMEOUT if the connection timeouted.
     52 * @return              The ICMP module phone on success.
     53 * @return              ETIMEOUT if the connection timeouted.
    5454 */
    5555int icmp_connect_module(services_t service, suseconds_t timeout)
  • uspace/lib/c/generic/net/inet.c

    ra93d79a r8fb1bf82  
    5151 *  @param[out] address The character buffer to be filled.
    5252 *  @param[in] length   The buffer length.
    53  *  @returns            EOK on success.
    54  *  @returns            EINVAL if the data or address parameter is NULL.
    55  *  @returns            ENOMEM if the character buffer is not long enough.
    56  *  @returns            ENOTSUP if the address family is not supported.
     53 *  @return             EOK on success.
     54 *  @return             EINVAL if the data or address parameter is NULL.
     55 *  @return             ENOMEM if the character buffer is not long enough.
     56 *  @return             ENOTSUP if the address family is not supported.
    5757 */
    5858int
     
    101101 *  @param[in] address  The character buffer to be parsed.
    102102 *  @param[out] data    The address data to be filled.
    103  *  @returns            EOK on success.
    104  *  @returns            EINVAL if the data parameter is NULL.
    105  *  @returns            ENOENT if the address parameter is NULL.
    106  *  @returns            ENOTSUP if the address family is not supported.
     103 *  @return             EOK on success.
     104 *  @return             EINVAL if the data parameter is NULL.
     105 *  @return             ENOENT if the address parameter is NULL.
     106 *  @return             ENOTSUP if the address family is not supported.
    107107 */
    108108int inet_pton(uint16_t family, const char *address, uint8_t *data)
  • uspace/lib/c/generic/net/modules.c

    ra93d79a r8fb1bf82  
    4141#include <async.h>
    4242#include <malloc.h>
    43 #include <err.h>
     43#include <errno.h>
    4444#include <sys/time.h>
    4545
     
    137137    ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
    138138{
    139         ERROR_DECLARE;
     139        int rc;
    140140       
    141141        /* Connect to the needed service */
     
    144144                /* Request the bidirectional connection */
    145145                ipcarg_t phonehash;
    146                 if (ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3,
    147                     &phonehash))) {
     146               
     147                rc = ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash);
     148                if (rc != EOK) {
    148149                        ipc_hangup(phone);
    149                         return ERROR_CODE;
     150                        return rc;
    150151                }
    151152                async_new_connection(phonehash, 0, NULL, client_receiver);
     
    158159 *
    159160 * @param[in] need      The needed module service.
    160  * @returns             The phone of the needed service.
     161 * @return              The phone of the needed service.
    161162 */
    162163int connect_to_service(services_t need)
     
    170171 *  @param[in] timeout  The connection timeout in microseconds. No timeout if
    171172 *                      set to zero (0).
    172  *  @returns            The phone of the needed service.
    173  *  @returns            ETIMEOUT if the connection timeouted.
     173 *  @return             The phone of the needed service.
     174 *  @return             ETIMEOUT if the connection timeouted.
    174175 */
    175176int connect_to_service_timeout(services_t need, suseconds_t timeout)
     
    203204 * @param[out] data     The data buffer to be filled.
    204205 * @param[out] length   The buffer length.
    205  * @returns             EOK on success.
    206  * @returns             EBADMEM if the data or the length parameter is NULL.
    207  * @returns             EINVAL if the client does not send data.
    208  * @returns             ENOMEM if there is not enough memory left.
    209  * @returns             Other error codes as defined for the
     206 * @return              EOK on success.
     207 * @return              EBADMEM if the data or the length parameter is NULL.
     208 * @return              EINVAL if the client does not send data.
     209 * @return              ENOMEM if there is not enough memory left.
     210 * @return              Other error codes as defined for the
    210211 *                      async_data_write_finalize() function.
    211212 */
    212213int data_receive(void **data, size_t *length)
    213214{
    214         ERROR_DECLARE;
    215 
    216215        ipc_callid_t callid;
     216        int rc;
    217217
    218218        if (!data || !length)
     
    229229
    230230        // fetch the data
    231         if (ERROR_OCCURRED(async_data_write_finalize(callid, *data, *length))) {
     231        rc = async_data_write_finalize(callid, *data, *length);
     232        if (rc != EOK) {
    232233                free(data);
    233                 return ERROR_CODE;
     234                return rc;
    234235        }
    235236
     
    241242 * @param[in] data      The data buffer to be sent.
    242243 * @param[in] data_length The buffer length.
    243  * @returns             EOK on success.
    244  * @returns             EINVAL if the client does not expect the data.
    245  * @returns             EOVERFLOW if the client does not expect all the data.
     244 * @return              EOK on success.
     245 * @return              EINVAL if the client does not expect the data.
     246 * @return              EOVERFLOW if the client does not expect all the data.
    246247 *                      Only partial data are transfered.
    247  * @returns             Other error codes as defined for the
     248 * @return              Other error codes as defined for the
    248249 *                      async_data_read_finalize() function.
    249250 */
  • uspace/lib/c/generic/net/packet.c

    ra93d79a r8fb1bf82  
    4141#include <unistd.h>
    4242#include <errno.h>
    43 #include <err.h>
    4443
    4544#include <sys/mman.h>
     
    6362
    6463/** Type definition of the packet map page. */
    65 typedef packet_t packet_map_t[PACKET_MAP_SIZE];
    66 
    67 /** Type definition of the packet map page pointer. */
    68 typedef packet_map_t * packet_map_ref;
     64typedef packet_t *packet_map_t[PACKET_MAP_SIZE];
    6965
    7066/** Packet map.
     
    8682/** Initializes the packet map.
    8783 *
    88  * @returns             EOK on success.
    89  * @returns             ENOMEM if there is not enough memory left.
     84 * @return              EOK on success.
     85 * @return              ENOMEM if there is not enough memory left.
    9086 */
    9187int pm_init(void)
    9288{
    93         ERROR_DECLARE;
     89        int rc;
    9490
    9591        fibril_rwlock_initialize(&pm_globals.lock);
     92       
    9693        fibril_rwlock_write_lock(&pm_globals.lock);
    97         ERROR_PROPAGATE(gpm_initialize(&pm_globals.packet_map));
     94        rc = gpm_initialize(&pm_globals.packet_map);
    9895        fibril_rwlock_write_unlock(&pm_globals.lock);
    99         return EOK;
     96       
     97        return rc;
    10098}
    10199
     
    103101 *
    104102 * @param[in] packet_id The packet identifier to be found.
    105  * @returns             The found packet reference.
    106  * @returns             NULL if the mapping does not exist.
    107  */
    108 packet_t pm_find(packet_id_t packet_id)
    109 {
    110         packet_map_ref map;
    111         packet_t packet;
     103 * @return              The found packet reference.
     104 * @return              NULL if the mapping does not exist.
     105 */
     106packet_t *pm_find(packet_id_t packet_id)
     107{
     108        packet_map_t *map;
     109        packet_t *packet;
    112110
    113111        if (!packet_id)
     
    132130 *
    133131 * @param[in] packet    The packet to be remembered.
    134  * @returns             EOK on success.
    135  * @returns             EINVAL if the packet is not valid.
    136  * @returns             EINVAL if the packet map is not initialized.
    137  * @returns             ENOMEM if there is not enough memory left.
    138  */
    139 int pm_add(packet_t packet)
    140 {
    141         ERROR_DECLARE;
    142 
    143         packet_map_ref map;
     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.
     136 */
     137int pm_add(packet_t *packet)
     138{
     139        packet_map_t *map;
     140        int rc;
    144141
    145142        if (!packet_is_valid(packet))
     
    154151        } else {
    155152                do {
    156                         map = (packet_map_ref) malloc(sizeof(packet_map_t));
     153                        map = (packet_map_t *) malloc(sizeof(packet_map_t));
    157154                        if (!map) {
    158155                                fibril_rwlock_write_unlock(&pm_globals.lock);
     
    160157                        }
    161158                        bzero(map, sizeof(packet_map_t));
    162                         if ((ERROR_CODE =
    163                             gpm_add(&pm_globals.packet_map, map)) < 0) {
     159                        rc = gpm_add(&pm_globals.packet_map, map);
     160                        if (rc < 0) {
    164161                                fibril_rwlock_write_unlock(&pm_globals.lock);
    165162                                free(map);
    166                                 return ERROR_CODE;
     163                                return rc;
    167164                        }
    168165                } while (PACKET_MAP_PAGE(packet->packet_id) >=
     
    180177        int count;
    181178        int index;
    182         packet_map_ref map;
    183         packet_t packet;
     179        packet_map_t *map;
     180        packet_t *packet;
    184181
    185182        fibril_rwlock_write_lock(&pm_globals.lock);
     
    208205 * @param[in] order     The packet order value.
    209206 * @param[in] metric    The metric value of the packet.
    210  * @returns             EOK on success.
    211  * @returns             EINVAL if the first parameter is NULL.
    212  * @returns             EINVAL if the packet is not valid.
    213  */
    214 int pq_add(packet_t * first, packet_t packet, size_t order, size_t metric)
    215 {
    216         packet_t item;
     207 * @return              EOK on success.
     208 * @return              EINVAL if the first parameter is NULL.
     209 * @return              EINVAL if the packet is not valid.
     210 */
     211int pq_add(packet_t **first, packet_t *packet, size_t order, size_t metric)
     212{
     213        packet_t *item;
    217214
    218215        if (!first || !packet_is_valid(packet))
     
    252249 * @param[in] first     The first packet of the queue.
    253250 * @param[in] order     The packet order value.
    254  * @returns             The packet with the given order.
    255  * @returns             NULL if the first packet is not valid.
    256  * @returns             NULL if the packet is not found.
    257  */
    258 packet_t pq_find(packet_t packet, size_t order)
    259 {
    260         packet_t item;
     251 * @return              The packet with the given order.
     252 * @return              NULL if the first packet is not valid.
     253 * @return              NULL if the packet is not found.
     254 */
     255packet_t *pq_find(packet_t *packet, size_t order)
     256{
     257        packet_t *item;
    261258
    262259        if (!packet_is_valid(packet))
     
    278275 * @param[in] packet    The packet in the queue.
    279276 * @param[in] new_packet The new packet to be inserted.
    280  * @returns             EOK on success.
    281  * @returns             EINVAL if etiher of the packets is invalid.
    282  */
    283 int pq_insert_after(packet_t packet, packet_t new_packet)
    284 {
    285         packet_t item;
     277 * @return              EOK on success.
     278 * @return              EINVAL if etiher of the packets is invalid.
     279 */
     280int pq_insert_after(packet_t *packet, packet_t *new_packet)
     281{
     282        packet_t *item;
    286283
    287284        if (!packet_is_valid(packet) || !packet_is_valid(new_packet))
     
    301298 *
    302299 * @param[in] packet    The packet to be detached.
    303  * @returns             The next packet in the queue. If the packet is the first
     300 * @return              The next packet in the queue. If the packet is the first
    304301 *                      one of the queue, this becomes the new first one.
    305  * @returns             NULL if there is no packet left.
    306  * @returns             NULL if the packet is not valid.
    307  */
    308 packet_t pq_detach(packet_t packet)
    309 {
    310         packet_t next;
    311         packet_t previous;
     302 * @return              NULL if there is no packet left.
     303 * @return              NULL if the packet is not valid.
     304 */
     305packet_t *pq_detach(packet_t *packet)
     306{
     307        packet_t *next;
     308        packet_t *previous;
    312309
    313310        if (!packet_is_valid(packet))
     
    331328 * @param[in] order     The packet order value.
    332329 * @param[in] metric    The metric value of the packet.
    333  * @returns             EOK on success.
    334  * @returns             EINVAL if the packet is invalid.
    335  */
    336 int pq_set_order(packet_t packet, size_t order, size_t metric)
     330 * @return              EOK on success.
     331 * @return              EINVAL if the packet is invalid.
     332 */
     333int pq_set_order(packet_t *packet, size_t order, size_t metric)
    337334{
    338335        if (!packet_is_valid(packet))
     
    349346 * @param[out] order    The packet order value.
    350347 * @param[out] metric   The metric value of the packet.
    351  * @returns             EOK on success.
    352  * @returns             EINVAL if the packet is invalid.
    353  */
    354 int pq_get_order(packet_t packet, size_t *order, size_t *metric)
     348 * @return              EOK on success.
     349 * @return              EINVAL if the packet is invalid.
     350 */
     351int pq_get_order(packet_t *packet, size_t *order, size_t *metric)
    355352{
    356353        if (!packet_is_valid(packet))
     
    375372 *                      packets after its detachment.
    376373 */
    377 void pq_destroy(packet_t first, void (*packet_release)(packet_t packet))
    378 {
    379         packet_t actual;
    380         packet_t next;
     374void pq_destroy(packet_t *first, void (*packet_release)(packet_t *packet))
     375{
     376        packet_t *actual;
     377        packet_t *next;
    381378
    382379        actual = first;
     
    394391 *
    395392 * @param[in] packet    The packet queue member.
    396  * @returns             The next packet in the queue.
    397  * @returns             NULL if there is no next packet.
    398  * @returns             NULL if the packet is not valid.
    399  */
    400 packet_t pq_next(packet_t packet)
     393 * @return              The next packet in the queue.
     394 * @return              NULL if there is no next packet.
     395 * @return              NULL if the packet is not valid.
     396 */
     397packet_t *pq_next(packet_t *packet)
    401398{
    402399        if (!packet_is_valid(packet))
     
    409406 *
    410407 * @param[in] packet    The packet queue member.
    411  * @returns             The previous packet in the queue.
    412  * @returns             NULL if there is no previous packet.
    413  * @returns             NULL if the packet is not valid.
    414  */
    415 packet_t pq_previous(packet_t packet)
     408 * @return              The previous packet in the queue.
     409 * @return              NULL if there is no previous packet.
     410 * @return              NULL if the packet is not valid.
     411 */
     412packet_t *pq_previous(packet_t *packet)
    416413{
    417414        if (!packet_is_valid(packet))
  • uspace/lib/c/generic/net/socket_client.c

    ra93d79a r8fb1bf82  
    4343#include <stdlib.h>
    4444#include <errno.h>
    45 #include <err.h>
    4645
    4746#include <ipc/services.h>
     
    7978 */
    8079typedef struct socket socket_t;
    81 
    82 /** Type definition of the socket specific data pointer.
    83  * @see socket
    84  */
    85 typedef socket_t *socket_ref;
    8680
    8781/** Socket specific data.
     
    163157
    164158        /** Active sockets. */
    165         sockets_ref sockets;
     159        sockets_t *sockets;
    166160
    167161        /** Safety lock.
     
    184178/** Returns the active sockets.
    185179 *
    186  *  @returns            The active sockets.
    187  */
    188 static sockets_ref socket_get_sockets(void)
     180 *  @return             The active sockets.
     181 */
     182static sockets_t *socket_get_sockets(void)
    189183{
    190184        if (!socket_globals.sockets) {
    191185                socket_globals.sockets =
    192                     (sockets_ref) malloc(sizeof(sockets_t));
     186                    (sockets_t *) malloc(sizeof(sockets_t));
    193187                if (!socket_globals.sockets)
    194188                        return NULL;
     
    212206static void socket_connection(ipc_callid_t iid, ipc_call_t * icall)
    213207{
    214         ERROR_DECLARE;
    215 
    216208        ipc_callid_t callid;
    217209        ipc_call_t call;
    218         socket_ref socket;
     210        socket_t *socket;
     211        int rc;
    219212
    220213loop:
     
    231224                    SOCKET_GET_SOCKET_ID(call));
    232225                if (!socket) {
    233                         ERROR_CODE = ENOTSOCK;
     226                        rc = ENOTSOCK;
    234227                        fibril_rwlock_read_unlock(&socket_globals.lock);
    235228                        break;
     
    240233                        fibril_mutex_lock(&socket->receive_lock);
    241234                        // push the number of received packet fragments
    242                         if (!ERROR_OCCURRED(dyn_fifo_push(&socket->received,
     235                        rc = dyn_fifo_push(&socket->received,
    243236                            SOCKET_GET_DATA_FRAGMENTS(call),
    244                             SOCKET_MAX_RECEIVED_SIZE))) {
     237                            SOCKET_MAX_RECEIVED_SIZE);
     238                        if (rc == EOK) {
    245239                                // signal the received packet
    246240                                fibril_condvar_signal(&socket->receive_signal);
     
    252246                        // push the new socket identifier
    253247                        fibril_mutex_lock(&socket->accept_lock);
    254                         if (!ERROR_OCCURRED(dyn_fifo_push(&socket->accepted,
    255                             1, SOCKET_MAX_ACCEPTED_SIZE))) {
     248                        rc = dyn_fifo_push(&socket->accepted, 1,
     249                            SOCKET_MAX_ACCEPTED_SIZE);
     250                        if (rc == EOK) {
    256251                                // signal the accepted socket
    257252                                fibril_condvar_signal(&socket->accept_signal);
     
    261256
    262257                default:
    263                         ERROR_CODE = ENOTSUP;
     258                        rc = ENOTSUP;
    264259                }
    265260
     
    280275
    281276        default:
    282                 ERROR_CODE = ENOTSUP;
    283         }
    284 
    285         ipc_answer_0(callid, (ipcarg_t) ERROR_CODE);
     277                rc = ENOTSUP;
     278        }
     279
     280        ipc_answer_0(callid, (ipcarg_t) rc);
    286281        goto loop;
    287282}
     
    291286 * Connects to the TCP module if necessary.
    292287 *
    293  * @returns             The TCP module phone.
    294  * @returns             Other error codes as defined for the
     288 * @return              The TCP module phone.
     289 * @return              Other error codes as defined for the
    295290 *                      bind_service_timeout() function.
    296291 */
     
    310305 * Connects to the UDP module if necessary.
    311306 *
    312  * @returns             The UDP module phone.
    313  * @returns             Other error codes as defined for the
     307 * @return              The UDP module phone.
     308 * @return              Other error codes as defined for the
    314309 *                      bind_service_timeout() function.
    315310 */
     
    327322/** Tries to find a new free socket identifier.
    328323 *
    329  * @returns             The new socket identifier.
    330  * @returns             ELIMIT if there is no socket identifier available.
     324 * @return              The new socket identifier.
     325 * @return              ELIMIT if there is no socket identifier available.
    331326 */
    332327static int socket_generate_new_id(void)
    333328{
    334         sockets_ref sockets;
     329        sockets_t *sockets;
    335330        int socket_id = 0;
    336331        int count;
     
    372367 */
    373368static void
    374 socket_initialize(socket_ref socket, int socket_id, int phone,
     369socket_initialize(socket_t *socket, int socket_id, int phone,
    375370    services_t service)
    376371{
     
    392387 * @param[in] type      Socket type.
    393388 * @param[in] protocol  Socket protocol.
    394  * @returns             The socket identifier on success.
    395  * @returns             EPFNOTSUPPORT if the protocol family is not supported.
    396  * @returns             ESOCKNOTSUPPORT if the socket type is not supported.
    397  * @returns             EPROTONOSUPPORT if the protocol is not supported.
    398  * @returns             ENOMEM if there is not enough memory left.
    399  * @returns             ELIMIT if there was not a free socket identifier found
     389 * @return              The socket identifier on success.
     390 * @return              EPFNOTSUPPORT if the protocol family is not supported.
     391 * @return              ESOCKNOTSUPPORT if the socket type is not supported.
     392 * @return              EPROTONOSUPPORT if the protocol is not supported.
     393 * @return              ENOMEM if there is not enough memory left.
     394 * @return              ELIMIT if there was not a free socket identifier found
    400395 *                      this time.
    401  * @returns             Other error codes as defined for the NET_SOCKET message.
    402  * @returns             Other error codes as defined for the
     396 * @return              Other error codes as defined for the NET_SOCKET message.
     397 * @return              Other error codes as defined for the
    403398 *                      bind_service_timeout() function.
    404399 */
    405400int socket(int domain, int type, int protocol)
    406401{
    407         ERROR_DECLARE;
    408 
    409         socket_ref socket;
     402        socket_t *socket;
    410403        int phone;
    411404        int socket_id;
     
    413406        ipcarg_t fragment_size;
    414407        ipcarg_t header_size;
     408        int rc;
    415409
    416410        // find the appropriate service
     
    464458
    465459        // create a new socket structure
    466         socket = (socket_ref) malloc(sizeof(socket_t));
     460        socket = (socket_t *) malloc(sizeof(socket_t));
    467461        if (!socket)
    468462                return ENOMEM;
     
    479473        }
    480474
    481         if (ERROR_OCCURRED((int) async_req_3_3(phone, NET_SOCKET, socket_id, 0,
    482             service, NULL, &fragment_size, &header_size))) {
     475        rc = (int) async_req_3_3(phone, NET_SOCKET, socket_id, 0, service, NULL,
     476            &fragment_size, &header_size);
     477        if (rc != EOK) {
    483478                fibril_rwlock_write_unlock(&socket_globals.lock);
    484479                free(socket);
    485                 return ERROR_CODE;
     480                return rc;
    486481        }
    487482
     
    492487        socket_initialize(socket, socket_id, phone, service);
    493488        // store the new socket
    494         ERROR_CODE = sockets_add(socket_get_sockets(), socket_id, socket);
     489        rc = sockets_add(socket_get_sockets(), socket_id, socket);
    495490
    496491        fibril_rwlock_write_unlock(&socket_globals.lock);
    497         if (ERROR_CODE < 0) {
     492        if (rc < 0) {
    498493                dyn_fifo_destroy(&socket->received);
    499494                dyn_fifo_destroy(&socket->accepted);
     
    501496                async_msg_3(phone, NET_SOCKET_CLOSE, (ipcarg_t) socket_id, 0,
    502497                    service);
    503                 return ERROR_CODE;
     498                return rc;
    504499        }
    505500
     
    514509 * @param[in] data      The data to be sent.
    515510 * @param[in] datalength The data length.
    516  * @returns             EOK on success.
    517  * @returns             ENOTSOCK if the socket is not found.
    518  * @returns             EBADMEM if the data parameter is NULL.
    519  * @returns             NO_DATA if the datalength parameter is zero (0).
    520  * @returns             Other error codes as defined for the spcific message.
     511 * @return              EOK on success.
     512 * @return              ENOTSOCK if the socket is not found.
     513 * @return              EBADMEM if the data parameter is NULL.
     514 * @return              NO_DATA if the datalength parameter is zero (0).
     515 * @return              Other error codes as defined for the spcific message.
    521516 */
    522517static int
     
    524519    const void *data, size_t datalength)
    525520{
    526         socket_ref socket;
     521        socket_t *socket;
    527522        aid_t message_id;
    528523        ipcarg_t result;
     
    559554 * @param[in] my_addr   The port address.
    560555 * @param[in] addrlen   The address length.
    561  * @returns             EOK on success.
    562  * @returns             ENOTSOCK if the socket is not found.
    563  * @returns             EBADMEM if the my_addr parameter is NULL.
    564  * @returns             NO_DATA if the addlen parameter is zero.
    565  * @returns             Other error codes as defined for the NET_SOCKET_BIND
     556 * @return              EOK on success.
     557 * @return              ENOTSOCK if the socket is not found.
     558 * @return              EBADMEM if the my_addr parameter is NULL.
     559 * @return              NO_DATA if the addlen parameter is zero.
     560 * @return              Other error codes as defined for the NET_SOCKET_BIND
    566561 *                      message.
    567562 */
     
    580575 * @param[in] socket_id Socket identifier.
    581576 * @param[in] backlog   The maximum number of waiting sockets to be accepted.
    582  * @returns             EOK on success.
    583  * @returns             EINVAL if the backlog parameter is not positive (<=0).
    584  * @returns             ENOTSOCK if the socket is not found.
    585  * @returns             Other error codes as defined for the NET_SOCKET_LISTEN
     577 * @return              EOK on success.
     578 * @return              EINVAL if the backlog parameter is not positive (<=0).
     579 * @return              ENOTSOCK if the socket is not found.
     580 * @return              Other error codes as defined for the NET_SOCKET_LISTEN
    586581 *                      message.
    587582 */
    588583int listen(int socket_id, int backlog)
    589584{
    590         socket_ref socket;
     585        socket_t *socket;
    591586        int result;
    592587
     
    618613 * @param[out] cliaddr  The remote client address.
    619614 * @param[in] addrlen   The address length.
    620  * @returns             EOK on success.
    621  * @returns             EBADMEM if the cliaddr or addrlen parameter is NULL.
    622  * @returns             EINVAL if the backlog parameter is not positive (<=0).
    623  * @returns             ENOTSOCK if the socket is not found.
    624  * @returns             Other error codes as defined for the NET_SOCKET_ACCEPT
     615 * @return              EOK on success.
     616 * @return              EBADMEM if the cliaddr or addrlen parameter is NULL.
     617 * @return              EINVAL if the backlog parameter is not positive (<=0).
     618 * @return              ENOTSOCK if the socket is not found.
     619 * @return              Other error codes as defined for the NET_SOCKET_ACCEPT
    625620 *                      message.
    626621 */
    627622int accept(int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen)
    628623{
    629         socket_ref socket;
    630         socket_ref new_socket;
     624        socket_t *socket;
     625        socket_t *new_socket;
    631626        aid_t message_id;
    632627        ipcarg_t ipc_result;
     
    661656
    662657        // create a new scoket
    663         new_socket = (socket_ref) malloc(sizeof(socket_t));
     658        new_socket = (socket_t *) malloc(sizeof(socket_t));
    664659        if (!new_socket) {
    665660                fibril_mutex_unlock(&socket->accept_lock);
     
    721716 * @param[in] serv_addr The remote server address.
    722717 * @param[in] addrlen   The address length.
    723  * @returns             EOK on success.
    724  * @returns             EBADMEM if the serv_addr parameter is NULL.
    725  * @returns             NO_DATA if the addlen parameter is zero.
    726  * @returns             ENOTSOCK if the socket is not found.
    727  * @returns             Other error codes as defined for the NET_SOCKET_CONNECT
     718 * @return              EOK on success.
     719 * @return              EBADMEM if the serv_addr parameter is NULL.
     720 * @return              NO_DATA if the addlen parameter is zero.
     721 * @return              ENOTSOCK if the socket is not found.
     722 * @return              Other error codes as defined for the NET_SOCKET_CONNECT
    728723 *                      message.
    729724 */
     
    745740 * @param[in] socket    The socket to be destroyed.
    746741 */
    747 static void socket_destroy(socket_ref socket)
     742static void socket_destroy(socket_t *socket)
    748743{
    749744        int accepted_id;
     
    761756 *
    762757 * @param[in] socket_id Socket identifier.
    763  * @returns             EOK on success.
    764  * @returns             ENOTSOCK if the socket is not found.
    765  * @returns             EINPROGRESS if there is another blocking function in
     758 * @return              EOK on success.
     759 * @return              ENOTSOCK if the socket is not found.
     760 * @return              EINPROGRESS if there is another blocking function in
    766761 *                      progress.
    767  * @returns             Other error codes as defined for the NET_SOCKET_CLOSE
     762 * @return              Other error codes as defined for the NET_SOCKET_CLOSE
    768763 *                      message.
    769764 */
    770765int closesocket(int socket_id)
    771766{
    772         ERROR_DECLARE;
    773 
    774         socket_ref socket;
     767        socket_t *socket;
     768        int rc;
    775769
    776770        fibril_rwlock_write_lock(&socket_globals.lock);
     
    787781
    788782        // request close
    789         ERROR_PROPAGATE((int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE,
    790             (ipcarg_t) socket->socket_id, 0, socket->service));
     783        rc = (int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE,
     784            (ipcarg_t) socket->socket_id, 0, socket->service);
     785        if (rc != EOK) {
     786                fibril_rwlock_write_unlock(&socket_globals.lock);
     787                return rc;
     788        }
    791789        // free the socket structure
    792790        socket_destroy(socket);
     
    808806 *                      sockets.
    809807 * @param[in] addrlen   The address length. Used only if toaddr is not NULL.
    810  * @returns             EOK on success.
    811  * @returns             ENOTSOCK if the socket is not found.
    812  * @returns             EBADMEM if the data or toaddr parameter is NULL.
    813  * @returns             NO_DATA if the datalength or the addrlen parameter is
     808 * @return              EOK on success.
     809 * @return              ENOTSOCK if the socket is not found.
     810 * @return              EBADMEM if the data or toaddr parameter is NULL.
     811 * @return              NO_DATA if the datalength or the addrlen parameter is
    814812 *                      zero (0).
    815  * @returns             Other error codes as defined for the NET_SOCKET_SENDTO
     813 * @return              Other error codes as defined for the NET_SOCKET_SENDTO
    816814 *                      message.
    817815 */
     
    821819    socklen_t addrlen)
    822820{
    823         socket_ref socket;
     821        socket_t *socket;
    824822        aid_t message_id;
    825823        ipcarg_t result;
     
    910908 * @param[in] datalength The data length.
    911909 * @param[in] flags     Various send flags.
    912  * @returns             EOK on success.
    913  * @returns             ENOTSOCK if the socket is not found.
    914  * @returns             EBADMEM if the data parameter is NULL.
    915  * @returns             NO_DATA if the datalength parameter is zero.
    916  * @returns             Other error codes as defined for the NET_SOCKET_SEND
     910 * @return              EOK on success.
     911 * @return              ENOTSOCK if the socket is not found.
     912 * @return              EBADMEM if the data parameter is NULL.
     913 * @return              NO_DATA if the datalength parameter is zero.
     914 * @return              Other error codes as defined for the NET_SOCKET_SEND
    917915 *                      message.
    918916 */
     
    934932 * @param[in] toaddr    The destination address.
    935933 * @param[in] addrlen   The address length.
    936  * @returns             EOK on success.
    937  * @returns             ENOTSOCK if the socket is not found.
    938  * @returns             EBADMEM if the data or toaddr parameter is NULL.
    939  * @returns             NO_DATA if the datalength or the addrlen parameter is
     934 * @return              EOK on success.
     935 * @return              ENOTSOCK if the socket is not found.
     936 * @return              EBADMEM if the data or toaddr parameter is NULL.
     937 * @return              NO_DATA if the datalength or the addrlen parameter is
    940938 *                      zero.
    941  * @returns             Other error codes as defined for the NET_SOCKET_SENDTO
     939 * @return              Other error codes as defined for the NET_SOCKET_SENDTO
    942940 *                      message.
    943941 */
     
    968966 *                      read. The actual address length is set. Used only if
    969967 *                      fromaddr is not NULL.
    970  * @returns             EOK on success.
    971  * @returns             ENOTSOCK if the socket is not found.
    972  * @returns             EBADMEM if the data parameter is NULL.
    973  * @returns             NO_DATA if the datalength or addrlen parameter is zero.
    974  * @returns             Other error codes as defined for the spcific message.
     968 * @return              EOK on success.
     969 * @return              ENOTSOCK if the socket is not found.
     970 * @return              EBADMEM if the data parameter is NULL.
     971 * @return              NO_DATA if the datalength or addrlen parameter is zero.
     972 * @return              Other error codes as defined for the spcific message.
    975973 */
    976974static int
     
    978976    int flags, struct sockaddr *fromaddr, socklen_t *addrlen)
    979977{
    980         socket_ref socket;
     978        socket_t *socket;
    981979        aid_t message_id;
    982980        ipcarg_t ipc_result;
     
    10971095 * @param[in] datalength The data length.
    10981096 * @param[in] flags     Various receive flags.
    1099  * @returns             EOK on success.
    1100  * @returns             ENOTSOCK if the socket is not found.
    1101  * @returns             EBADMEM if the data parameter is NULL.
    1102  * @returns             NO_DATA if the datalength parameter is zero.
    1103  * @returns             Other error codes as defined for the NET_SOCKET_RECV
     1097 * @return              EOK on success.
     1098 * @return              ENOTSOCK if the socket is not found.
     1099 * @return              EBADMEM if the data parameter is NULL.
     1100 * @return              NO_DATA if the datalength parameter is zero.
     1101 * @return              Other error codes as defined for the NET_SOCKET_RECV
    11041102 *                      message.
    11051103 */
     
    11201118 * @param[in,out] addrlen The address length. The maximum address length is
    11211119 *                      read. The actual address length is set.
    1122  * @returns             EOK on success.
    1123  * @returns             ENOTSOCK if the socket is not found.
    1124  * @returns             EBADMEM if the data or fromaddr parameter is NULL.
    1125  * @returns             NO_DATA if the datalength or addrlen parameter is zero.
    1126  * @returns             Other error codes as defined for the NET_SOCKET_RECVFROM
     1120 * @return              EOK on success.
     1121 * @return              ENOTSOCK if the socket is not found.
     1122 * @return              EBADMEM if the data or fromaddr parameter is NULL.
     1123 * @return              NO_DATA if the datalength or addrlen parameter is zero.
     1124 * @return              Other error codes as defined for the NET_SOCKET_RECVFROM
    11271125 *                      message.
    11281126 */
     
    11501148 * @param[in,out] optlen The value buffer length. The maximum length is read.
    11511149 *                      The actual length is set.
    1152  * @returns             EOK on success.
    1153  * @returns             ENOTSOCK if the socket is not found.
    1154  * @returns             EBADMEM if the value or optlen parameter is NULL.
    1155  * @returns             NO_DATA if the optlen parameter is zero.
    1156  * @returns             Other error codes as defined for the
     1150 * @return              EOK on success.
     1151 * @return              ENOTSOCK if the socket is not found.
     1152 * @return              EBADMEM if the value or optlen parameter is NULL.
     1153 * @return              NO_DATA if the optlen parameter is zero.
     1154 * @return              Other error codes as defined for the
    11571155 *                      NET_SOCKET_GETSOCKOPT message.
    11581156 */
     
    11601158getsockopt(int socket_id, int level, int optname, void *value, size_t *optlen)
    11611159{
    1162         socket_ref socket;
     1160        socket_t *socket;
    11631161        aid_t message_id;
    11641162        ipcarg_t result;
     
    12031201 * @param[in] value     The value to be set.
    12041202 * @param[in] optlen    The value length.
    1205  * @returns             EOK on success.
    1206  * @returns             ENOTSOCK if the socket is not found.
    1207  * @returns             EBADMEM if the value parameter is NULL.
    1208  * @returns             NO_DATA if the optlen parameter is zero.
    1209  * @returns             Other error codes as defined for the
     1203 * @return              EOK on success.
     1204 * @return              ENOTSOCK if the socket is not found.
     1205 * @return              EBADMEM if the value parameter is NULL.
     1206 * @return              NO_DATA if the optlen parameter is zero.
     1207 * @return              Other error codes as defined for the
    12101208 *                      NET_SOCKET_SETSOCKOPT message.
    12111209 */
  • uspace/lib/c/generic/task.c

    ra93d79a r8fb1bf82  
    3939#include <errno.h>
    4040#include <loader/loader.h>
     41#include <stdarg.h>
    4142#include <str.h>
    4243#include <ipc/ns.h>
     
    6869 *
    6970 * This is really just a convenience wrapper over the more complicated
    70  * loader API.
    71  *
    72  * @param path Pathname of the binary to execute.
    73  * @param argv Command-line arguments.
    74  * @param err  If not NULL, the error value is stored here.
    75  *
    76  * @return ID of the newly created task or zero on error.
    77  *
    78  */
    79 task_id_t task_spawn(const char *path, const char *const args[], int *err)
    80 {
     71 * loader API. Arguments are passed as a null-terminated array of strings.
     72 *
     73 * @param id    If not NULL, the ID of the task is stored here on success.
     74 * @param path  Pathname of the binary to execute.
     75 * @param argv  Command-line arguments.
     76 *
     77 * @return      Zero on success or negative error code.
     78 */
     79int task_spawnv(task_id_t *id, const char *path, const char *const args[])
     80{
     81        loader_t *ldr;
     82        task_id_t task_id;
     83        int rc;
     84
    8185        /* Connect to a program loader. */
    82         loader_t *ldr = loader_connect();
    83         if (ldr == NULL) {
    84                 if (err != NULL)
    85                         *err = EREFUSED;
    86                
    87                 return 0;
    88         }
     86        ldr = loader_connect();
     87        if (ldr == NULL)
     88                return EREFUSED;
    8989       
    9090        /* Get task ID. */
    91         task_id_t task_id;
    92         int rc = loader_get_task_id(ldr, &task_id);
     91        rc = loader_get_task_id(ldr, &task_id);
    9392        if (rc != EOK)
    9493                goto error;
     
    149148        free(ldr);
    150149       
    151         if (err != NULL)
    152                 *err = EOK;
    153        
    154         return task_id;
     150        if (id != NULL)
     151                *id = task_id;
     152       
     153        return EOK;
    155154       
    156155error:
     
    158157        loader_abort(ldr);
    159158        free(ldr);
    160        
    161         if (err != NULL)
    162                 *err = rc;
    163        
    164         return 0;
     159        return rc;
     160}
     161
     162/** Create a new task by running an executable from the filesystem.
     163 *
     164 * This is really just a convenience wrapper over the more complicated
     165 * loader API. Arguments are passed as a null-terminated list of arguments.
     166 *
     167 * @param id    If not NULL, the ID of the task is stored here on success.
     168 * @param path  Pathname of the binary to execute.
     169 * @param ...   Command-line arguments.
     170 *
     171 * @return      Zero on success or negative error code.
     172 */
     173int task_spawnl(task_id_t *task_id, const char *path, ...)
     174{
     175        va_list ap;
     176        int rc, cnt;
     177        const char *arg;
     178        const char **arglist;
     179
     180        /* Count the number of arguments. */
     181        cnt = 0;
     182        va_start(ap, path);
     183        do {
     184                arg = va_arg(ap, const char *);
     185                cnt++;
     186        } while (arg != NULL);
     187        va_end(ap);
     188
     189        /* Allocate argument list. */
     190        arglist = malloc(cnt * sizeof(const char *));
     191        if (arglist == NULL)
     192                return ENOMEM;
     193
     194        /* Fill in arguments. */
     195        cnt = 0;
     196        va_start(ap, path);
     197        do {
     198                arg = va_arg(ap, const char *);
     199                arglist[cnt++] = arg;
     200        } while (arg != NULL);
     201        va_end(ap);
     202
     203        /* Spawn task. */
     204        rc = task_spawnv(task_id, path, arglist);
     205
     206        /* Free argument list. */
     207        free(arglist);
     208        return rc;
    165209}
    166210
  • uspace/lib/c/generic/vfs/vfs.c

    ra93d79a r8fb1bf82  
    136136        }
    137137       
    138         dev_handle_t dev_handle;
    139         int res = devmap_device_get_handle(fqdn, &dev_handle, flags);
     138        devmap_handle_t devmap_handle;
     139        int res = devmap_device_get_handle(fqdn, &devmap_handle, flags);
    140140        if (res != EOK) {
    141141                if (null_id != -1)
     
    159159       
    160160        ipcarg_t rc_orig;
    161         aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
     161        aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, devmap_handle, flags, NULL);
    162162        ipcarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    163163        if (rc != EOK) {
     
    328328        ipc_call_t answer;
    329329        aid_t req = async_send_4(vfs_phone, VFS_IN_OPEN_NODE, node->fs_handle,
    330             node->dev_handle, node->index, oflag, &answer);
     330            node->devmap_handle, node->index, oflag, &answer);
    331331       
    332332        ipcarg_t rc;
     
    797797        if (rc == EOK) {
    798798                node->fs_handle = stat.fs_handle;
    799                 node->dev_handle = stat.dev_handle;
     799                node->devmap_handle = stat.devmap_handle;
    800800                node->index = stat.index;
    801801        }
  • uspace/lib/c/include/adt/char_map.h

    ra93d79a r8fb1bf82  
    4848typedef struct char_map char_map_t;
    4949
    50 /** Type definition of the character string to integer map pointer.
    51  *  @see char_map
    52  */
    53 typedef char_map_t *char_map_ref;
    54 
    5550/** Character string to integer map item.
    5651 *
     
    6964        int next;
    7065        /** Next character array. */
    71         char_map_ref *items;
     66        char_map_t **items;
    7267        /** Consistency check magic value. */
    7368        int magic;
    7469};
    7570
    76 extern int char_map_initialize(char_map_ref);
    77 extern void char_map_destroy(char_map_ref);
    78 extern int char_map_exclude(char_map_ref, const char *, size_t);
    79 extern int char_map_add(char_map_ref, const char *, size_t, const int);
    80 extern int char_map_find(const char_map_ref, const char *, size_t);
    81 extern int char_map_update(char_map_ref, const char *, size_t, const int);
     71extern int char_map_initialize(char_map_t *);
     72extern void char_map_destroy(char_map_t *);
     73extern int char_map_exclude(char_map_t *, const char *, size_t);
     74extern int char_map_add(char_map_t *, const char *, size_t, const int);
     75extern int char_map_find(const char_map_t *, const char *, size_t);
     76extern int char_map_update(char_map_t *, const char *, size_t, const int);
    8277
    8378#endif
  • uspace/lib/c/include/adt/dynamic_fifo.h

    ra93d79a r8fb1bf82  
    4444typedef struct dyn_fifo dyn_fifo_t;
    4545
    46 /** Type definition of the dynamic fifo queue pointer.
    47  *  @see dyn_fifo
    48  */
    49 typedef dyn_fifo_t *dyn_fifo_ref;
    50 
    5146/** Dynamic first in first out positive integer queue.
    5247 * Possitive integer values only.
     
    6661};
    6762
    68 extern int dyn_fifo_initialize(dyn_fifo_ref, int);
    69 extern int dyn_fifo_destroy(dyn_fifo_ref);
    70 extern int dyn_fifo_push(dyn_fifo_ref, int, int);
    71 extern int dyn_fifo_pop(dyn_fifo_ref);
    72 extern int dyn_fifo_value(dyn_fifo_ref);
     63extern int dyn_fifo_initialize(dyn_fifo_t *, int);
     64extern int dyn_fifo_destroy(dyn_fifo_t *);
     65extern int dyn_fifo_push(dyn_fifo_t *, int, int);
     66extern int dyn_fifo_pop(dyn_fifo_t *);
     67extern int dyn_fifo_value(dyn_fifo_t *);
    7368
    7469#endif
  • uspace/lib/c/include/adt/generic_char_map.h

    ra93d79a r8fb1bf82  
    4040#include <unistd.h>
    4141#include <errno.h>
    42 #include <err.h>
    4342
    4443#include <adt/char_map.h>
     
    5655        \
    5756        typedef struct name name##_t; \
    58         typedef name##_t *name##_ref; \
    5957        \
    6058        struct  name { \
     
    6462        }; \
    6563        \
    66         int name##_add(name##_ref, const char *, const size_t, type *); \
    67         int name##_count(name##_ref); \
    68         void name##_destroy(name##_ref); \
    69         void name##_exclude(name##_ref, const char *, const size_t); \
    70         type *name##_find(name##_ref, const char *, const size_t); \
    71         int name##_initialize(name##_ref); \
    72         int name##_is_valid(name##_ref);
     64        int name##_add(name##_t *, const char *, const size_t, type *); \
     65        int name##_count(name##_t *); \
     66        void name##_destroy(name##_t *); \
     67        void name##_exclude(name##_t *, const char *, const size_t); \
     68        type *name##_find(name##_t *, const char *, const size_t); \
     69        int name##_initialize(name##_t *); \
     70        int name##_is_valid(name##_t *);
    7371
    7472/** Character string to generic type map implementation.
     
    8280        GENERIC_FIELD_IMPLEMENT(name##_items, type) \
    8381        \
    84         int name##_add(name##_ref map, const char *name, const size_t length, \
     82        int name##_add(name##_t *map, const char *name, const size_t length, \
    8583             type *value) \
    8684        { \
    87                 ERROR_DECLARE; \
     85                int rc; \
    8886                int index; \
    8987                if (!name##_is_valid(map)) \
     
    9290                if (index < 0) \
    9391                        return index; \
    94                 if (ERROR_OCCURRED(char_map_add(&map->names, name, length, \
    95                     index))) { \
     92                rc = char_map_add(&map->names, name, length, index); \
     93                if (rc != EOK) { \
    9694                        name##_items_exclude_index(&map->values, index); \
    97                         return ERROR_CODE; \
     95                        return rc; \
    9896                } \
    9997                return EOK; \
    10098        } \
    10199        \
    102         int name##_count(name##_ref map) \
     100        int name##_count(name##_t *map) \
    103101        { \
    104102                return name##_is_valid(map) ? \
     
    106104        } \
    107105        \
    108         void name##_destroy(name##_ref map) \
     106        void name##_destroy(name##_t *map) \
    109107        { \
    110108                if (name##_is_valid(map)) { \
     
    114112        } \
    115113        \
    116         void name##_exclude(name##_ref map, const char *name, \
     114        void name##_exclude(name##_t *map, const char *name, \
    117115            const size_t length) \
    118116        { \
     
    126124        } \
    127125        \
    128         type *name##_find(name##_ref map, const char *name, \
     126        type *name##_find(name##_t *map, const char *name, \
    129127            const size_t length) \
    130128        { \
     
    139137        } \
    140138        \
    141         int name##_initialize(name##_ref map) \
     139        int name##_initialize(name##_t *map) \
    142140        { \
    143                 ERROR_DECLARE; \
     141                int rc; \
    144142                if (!map) \
    145143                        return EINVAL; \
    146                 ERROR_PROPAGATE(char_map_initialize(&map->names)); \
    147                 if (ERROR_OCCURRED(name##_items_initialize(&map->values))) { \
     144                rc = char_map_initialize(&map->names); \
     145                if (rc != EOK) \
     146                        return rc; \
     147                rc = name##_items_initialize(&map->values); \
     148                if (rc != EOK) { \
    148149                        char_map_destroy(&map->names); \
    149                         return ERROR_CODE; \
     150                        return rc; \
    150151                } \
    151152                map->magic = GENERIC_CHAR_MAP_MAGIC_VALUE; \
     
    153154        } \
    154155        \
    155         int name##_is_valid(name##_ref map) \
     156        int name##_is_valid(name##_t *map) \
    156157        { \
    157158                return map && (map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE); \
  • uspace/lib/c/include/adt/generic_field.h

    ra93d79a r8fb1bf82  
    5353#define GENERIC_FIELD_DECLARE(name, type) \
    5454        typedef struct name name##_t; \
    55         typedef name##_t *name##_ref; \
    5655        \
    5756        struct  name { \
     
    6261        }; \
    6362        \
    64         int name##_add(name##_ref, type *); \
    65         int name##_count(name##_ref); \
    66         void name##_destroy(name##_ref); \
    67         void name##_exclude_index(name##_ref, int); \
    68         type **name##_get_field(name##_ref); \
    69         type *name##_get_index(name##_ref, int); \
    70         int name##_initialize(name##_ref); \
    71         int name##_is_valid(name##_ref);
     63        int name##_add(name##_t *, type *); \
     64        int name##_count(name##_t *); \
     65        void name##_destroy(name##_t *); \
     66        void name##_exclude_index(name##_t *, int); \
     67        type **name##_get_field(name##_t *); \
     68        type *name##_get_index(name##_t *, int); \
     69        int name##_initialize(name##_t *); \
     70        int name##_is_valid(name##_t *);
    7271
    7372/** Generic type field implementation.
     
    7978 */
    8079#define GENERIC_FIELD_IMPLEMENT(name, type) \
    81         int name##_add(name##_ref field, type *value) \
     80        int name##_add(name##_t *field, type *value) \
    8281        { \
    8382                if (name##_is_valid(field)) { \
     
    9998        } \
    10099        \
    101         int name##_count(name##_ref field) \
     100        int name##_count(name##_t *field) \
    102101        { \
    103102                return name##_is_valid(field) ? field->next : -1; \
    104103        } \
    105104        \
    106         void name##_destroy(name##_ref field) \
     105        void name##_destroy(name##_t *field) \
    107106        { \
    108107                if (name##_is_valid(field)) { \
     
    117116        } \
    118117         \
    119         void name##_exclude_index(name##_ref field, int index) \
     118        void name##_exclude_index(name##_t *field, int index) \
    120119        { \
    121120                if (name##_is_valid(field) && (index >= 0) && \
     
    126125        } \
    127126         \
    128         type *name##_get_index(name##_ref field, int index) \
     127        type *name##_get_index(name##_t *field, int index) \
    129128        { \
    130129                if (name##_is_valid(field) && (index >= 0) && \
     
    134133        } \
    135134        \
    136         type **name##_get_field(name##_ref field) \
     135        type **name##_get_field(name##_t *field) \
    137136        { \
    138137                return name##_is_valid(field) ? field->items : NULL; \
    139138        } \
    140139        \
    141         int name##_initialize(name##_ref field) \
     140        int name##_initialize(name##_t *field) \
    142141        { \
    143142                if (!field) \
     
    153152        } \
    154153        \
    155         int name##_is_valid(name##_ref field) \
     154        int name##_is_valid(name##_t *field) \
    156155        { \
    157156                return field && (field->magic == GENERIC_FIELD_MAGIC_VALUE); \
  • uspace/lib/c/include/adt/int_map.h

    ra93d79a r8fb1bf82  
    5656#define INT_MAP_DECLARE(name, type) \
    5757        typedef struct name name##_t; \
    58         typedef name##_t *name##_ref; \
    5958        typedef struct name##_item name##_item_t; \
    60         typedef name##_item_t *name##_item_ref; \
    6159        \
    6260        struct  name##_item { \
     
    6967                int size; \
    7068                int next; \
    71                 name##_item_ref items; \
     69                name##_item_t *items; \
    7270                int magic; \
    7371        }; \
    7472        \
    75         int name##_add(name##_ref, int, type *); \
    76         void name##_clear(name##_ref); \
    77         int name##_count(name##_ref); \
    78         void name##_destroy(name##_ref); \
    79         void name##_exclude(name##_ref, int); \
    80         void name##_exclude_index(name##_ref, int); \
    81         type *name##_find(name##_ref, int); \
    82         int name##_update(name##_ref, int, int); \
    83         type *name##_get_index(name##_ref, int); \
    84         int name##_initialize(name##_ref); \
    85         int name##_is_valid(name##_ref); \
    86         void name##_item_destroy(name##_item_ref); \
    87         int name##_item_is_valid(name##_item_ref);
     73        int name##_add(name##_t *, int, type *); \
     74        void name##_clear(name##_t *); \
     75        int name##_count(name##_t *); \
     76        void name##_destroy(name##_t *); \
     77        void name##_exclude(name##_t *, int); \
     78        void name##_exclude_index(name##_t *, int); \
     79        type *name##_find(name##_t *, int); \
     80        int name##_update(name##_t *, int, int); \
     81        type *name##_get_index(name##_t *, int); \
     82        int name##_initialize(name##_t *); \
     83        int name##_is_valid(name##_t *); \
     84        void name##_item_destroy(name##_item_t *); \
     85        int name##_item_is_valid(name##_item_t *);
    8886
    8987/** Integer to generic type map implementation.
     
    9593 */
    9694#define INT_MAP_IMPLEMENT(name, type) \
    97         int name##_add(name##_ref map, int key, type *value) \
     95        int name##_add(name##_t *map, int key, type *value) \
    9896        { \
    9997                if (name##_is_valid(map)) { \
    10098                        if (map->next == (map->size - 1)) { \
    101                                 name##_item_ref tmp; \
    102                                 tmp = (name##_item_ref) realloc(map->items, \
     99                                name##_item_t *tmp; \
     100                                tmp = (name##_item_t *) realloc(map->items, \
    103101                                    sizeof(name##_item_t) * 2 * map->size); \
    104102                                if (!tmp) \
     
    117115        } \
    118116        \
    119         void name##_clear(name##_ref map) \
     117        void name##_clear(name##_t *map) \
    120118        { \
    121119                if (name##_is_valid(map)) { \
     
    132130        } \
    133131        \
    134         int name##_count(name##_ref map) \
     132        int name##_count(name##_t *map) \
    135133        { \
    136134                return name##_is_valid(map) ? map->next : -1; \
    137135        } \
    138136        \
    139         void name##_destroy(name##_ref map) \
     137        void name##_destroy(name##_t *map) \
    140138        { \
    141139                if (name##_is_valid(map)) { \
     
    152150        } \
    153151        \
    154         void name##_exclude(name##_ref map, int key) \
     152        void name##_exclude(name##_t *map, int key) \
    155153        { \
    156154                if (name##_is_valid(map)) { \
     
    166164        } \
    167165        \
    168         void name##_exclude_index(name##_ref map, int index) \
     166        void name##_exclude_index(name##_t *map, int index) \
    169167        { \
    170168                if (name##_is_valid(map) && (index >= 0) && \
     
    175173        } \
    176174        \
    177         type *name##_find(name##_ref map, int key) \
     175        type *name##_find(name##_t *map, int key) \
    178176        { \
    179177                if (name##_is_valid(map)) { \
     
    189187        } \
    190188        \
    191         int name##_update(name##_ref map, int key, int new_key) \
     189        int name##_update(name##_t *map, int key, int new_key) \
    192190        { \
    193191                if (name##_is_valid(map)) { \
     
    208206        } \
    209207        \
    210         type *name##_get_index(name##_ref map, int index) \
     208        type *name##_get_index(name##_t *map, int index) \
    211209        { \
    212210                if (name##_is_valid(map) && (index >= 0) && \
     
    218216        } \
    219217        \
    220         int name##_initialize(name##_ref map) \
     218        int name##_initialize(name##_t *map) \
    221219        { \
    222220                if (!map) \
     
    224222                map->size = 2; \
    225223                map->next = 0; \
    226                 map->items = (name##_item_ref) malloc(sizeof(name##_item_t) * \
     224                map->items = (name##_item_t *) malloc(sizeof(name##_item_t) * \
    227225                    map->size); \
    228226                if (!map->items) \
     
    233231        } \
    234232        \
    235         int name##_is_valid(name##_ref map) \
     233        int name##_is_valid(name##_t *map) \
    236234        { \
    237235                return map && (map->magic == INT_MAP_MAGIC_VALUE); \
    238236        } \
    239237        \
    240         void name##_item_destroy(name##_item_ref item) \
     238        void name##_item_destroy(name##_item_t *item) \
    241239        { \
    242240                if (name##_item_is_valid(item)) { \
     
    249247        } \
    250248        \
    251         int name##_item_is_valid(name##_item_ref item) \
     249        int name##_item_is_valid(name##_item_t *item) \
    252250        { \
    253251                return item && (item->magic == INT_MAP_ITEM_MAGIC_VALUE); \
  • uspace/lib/c/include/adt/measured_strings.h

    ra93d79a r8fb1bf82  
    4343
    4444/** Type definition of the character string with measured length.
    45  *  @see measured_string
     45 * @see measured_string
    4646 */
    4747typedef struct measured_string measured_string_t;
    48 
    49 /** Type definition of the character string with measured length pointer.
    50  *  @see measured_string
    51  */
    52 typedef measured_string_t *measured_string_ref;
    5348
    5449/** Character string with measured length.
     
    5954struct measured_string {
    6055        /** Character string data. */
    61         char * value;
     56        char *value;
    6257        /** Character string length. */
    6358        size_t length;
    6459};
    6560
    66 extern measured_string_ref measured_string_create_bulk(const char *, size_t);
    67 extern measured_string_ref measured_string_copy(measured_string_ref);
    68 extern int measured_strings_receive(measured_string_ref *, char **, size_t);
    69 extern int measured_strings_reply(const measured_string_ref, size_t);
    70 extern int measured_strings_return(int, measured_string_ref *, char **, size_t);
    71 extern int measured_strings_send(int, const measured_string_ref, size_t);
     61extern measured_string_t *measured_string_create_bulk(const char *, size_t);
     62extern measured_string_t *measured_string_copy(measured_string_t *);
     63extern int measured_strings_receive(measured_string_t **, char **, size_t);
     64extern int measured_strings_reply(const measured_string_t *, size_t);
     65extern int measured_strings_return(int, measured_string_t **, char **, size_t);
     66extern int measured_strings_send(int, const measured_string_t *, size_t);
    7267
    7368#endif
  • uspace/lib/c/include/ddi.h

    ra93d79a r8fb1bf82  
    4242extern int iospace_enable(task_id_t, void *, unsigned long);
    4343extern int pio_enable(void *, size_t, void **);
     44extern int interrupt_enable(int);
     45extern int interrupt_disable(int);
    4446
    4547#endif
  • uspace/lib/c/include/device/char.h

    ra93d79a r8fb1bf82  
    11/*
    2  * Copyright (c) 2009 Lukas Mejdrech
     2 * Copyright (c) 2010 Lenka Trochtova
    33 * All rights reserved.
    44 *
     
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
    28 
    29 /** @addtogroup packet
    30  *  @{
     28 
     29 /** @addtogroup libc
     30 * @{
    3131 */
    32 
    3332/** @file
    3433 */
     34 
     35#ifndef LIBC_DEVICE_HW_RES_H_
     36#define LIBC_DEVICE_HW_RES_H_
    3537
    36 #ifndef __NET_PACKET_LOCAL_H__
    37 #define __NET_PACKET_LOCAL_H__
     38typedef enum {
     39        CHAR_READ_DEV = 0,
     40        CHAR_WRITE_DEV 
     41} hw_res_funcs_t;
    3842
    39 #include <net/packet.h>
    40 
    41 /** @name Packet local interface
    42  */
    43 /*@{*/
    44 
    45 extern int packet_translate_local(int, packet_ref, packet_id_t);
    46 extern packet_t packet_get_4_local(int, size_t, size_t, size_t, size_t);
    47 extern packet_t packet_get_1_local(int, size_t);
    48 extern void pq_release_local(int, packet_id_t);
    49 
    50 /*@}*/
     43int read_dev(int dev_phone, void *buf, size_t len);
     44int write_dev(int dev_phone, void *buf, size_t len);
    5145
    5246#endif
  • uspace/lib/c/include/devman.h

    ra93d79a r8fb1bf82  
    11/*
    2  * Copyright (c) 2009 Lukas Mejdrech
     2 * Copyright (c) 2009 Jiri Svoboda
     3 * Copyright (c) 2010 Lenka Trochtova
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
    29 /** @addtogroup ip
     30/** @addtogroup libc
    3031 * @{
    3132 */
     33/** @file
     34 */
    3235
    33 #ifndef NET_IP_LOCAL_H_
    34 #define NET_IP_LOCAL_H_
     36#ifndef LIBC_DEVMAN_H_
     37#define LIBC_DEVMAN_H_
    3538
     39#include <ipc/devman.h>
    3640#include <async.h>
    37 #include <ipc/services.h>
     41#include <bool.h>
    3842
    39 #include <net/ip_codes.h>
    40 #include <net/inet.h>
    41 #include <net/in.h>
    4243
    43 extern int ip_received_error_msg_local(int, device_id_t, packet_t, services_t,
    44     services_t);
    45 extern int ip_set_gateway_req_local(int, device_id_t, in_addr_t);
    46 extern int ip_packet_size_req_local(int, device_id_t, packet_dimension_ref);
    47 extern int ip_received_error_msg_local(int, device_id_t, packet_t, services_t,
    48     services_t);
    49 extern int ip_device_req_local(int, device_id_t, services_t);
    50 extern int ip_add_route_req_local(int, device_id_t, in_addr_t, in_addr_t,
    51     in_addr_t);
    52 extern int ip_send_msg_local(int, device_id_t, packet_t, services_t,
    53     services_t);
    54 extern int ip_get_route_req_local(int, ip_protocol_t, const struct sockaddr *,
    55     socklen_t, device_id_t *, void **, size_t *);
     44extern int devman_get_phone(devman_interface_t, unsigned int);
     45extern void devman_hangup_phone(devman_interface_t);
     46
     47extern int devman_driver_register(const char *, async_client_conn_t);
     48extern int devman_child_device_register(const char *, match_id_list_t *,
     49    devman_handle_t, devman_handle_t *);
     50
     51extern int devman_device_connect(devman_handle_t, unsigned int);
     52extern int devman_parent_device_connect(devman_handle_t, unsigned int);
     53
     54extern int devman_device_get_handle(const char *, devman_handle_t *,
     55    unsigned int);
     56
     57extern int devman_add_device_to_class(devman_handle_t, const char *);
    5658
    5759#endif
  • uspace/lib/c/include/devmap.h

    ra93d79a r8fb1bf82  
    4444
    4545extern int devmap_driver_register(const char *, async_client_conn_t);
    46 extern int devmap_device_register(const char *, dev_handle_t *);
     46extern int devmap_device_register(const char *, devmap_handle_t *);
    4747
    48 extern int devmap_device_get_handle(const char *, dev_handle_t *, unsigned int);
    49 extern int devmap_namespace_get_handle(const char *, dev_handle_t *, unsigned int);
    50 extern devmap_handle_type_t devmap_handle_probe(dev_handle_t);
     48extern int devmap_device_get_handle(const char *, devmap_handle_t *, unsigned int);
     49extern int devmap_namespace_get_handle(const char *, devmap_handle_t *, unsigned int);
     50extern devmap_handle_type_t devmap_handle_probe(devmap_handle_t);
    5151
    52 extern int devmap_device_connect(dev_handle_t, unsigned int);
     52extern int devmap_device_connect(devmap_handle_t, unsigned int);
    5353
    5454extern int devmap_null_create(void);
     
    5656
    5757extern size_t devmap_count_namespaces(void);
    58 extern size_t devmap_count_devices(dev_handle_t);
     58extern size_t devmap_count_devices(devmap_handle_t);
    5959
    6060extern size_t devmap_get_namespaces(dev_desc_t **);
    61 extern size_t devmap_get_devices(dev_handle_t, dev_desc_t **);
     61extern size_t devmap_get_devices(devmap_handle_t, dev_desc_t **);
    6262
    6363#endif
  • uspace/lib/c/include/err.h

    ra93d79a r8fb1bf82  
    3737
    3838#include <stdio.h>
    39 #include <errno.h>
    40 
    41 #ifdef CONFIG_DEBUG
    42 #include <str_error.h>
    43 #endif
    4439
    4540#define errx(status, fmt, ...) { \
     
    4843}
    4944
    50 
    51 /** An actual stored error code.  */
    52 #define ERROR_CODE  error_check_return_value
    53 
    54 /** An error processing routines declaration.
    55  *
    56  * This has to be declared in the block where the error processing
    57  * is desired.
    58  */
    59 #define ERROR_DECLARE  int ERROR_CODE
    60 
    61 /** Store the value as an error code and checks if an error occurred.
    62  *
    63  * @param[in] value     The value to be checked. May be a function call.
    64  * @return              False if the value indicates success (EOK).
    65  * @return              True otherwise.
    66  */
    67 #ifdef CONFIG_DEBUG
    68 
    69 #define ERROR_OCCURRED(value) \
    70         (((ERROR_CODE = (value)) != EOK) && \
    71         ({ \
    72                 fprintf(stderr, "libsocket error at %s:%d (%s)\n", \
    73                 __FILE__, __LINE__, str_error(ERROR_CODE)); \
    74                 1; \
    75         }))
    76 
    77 #else
    78 
    79 #define ERROR_OCCURRED(value)   ((ERROR_CODE = (value)) != EOK)
    80 
    81 #endif
    82 
    83 #define ERROR_NONE(value)       !ERROR_OCCURRED((value))
    84 
    85 /** Error propagation
    86  *
    87  * Check if an error occurred and immediately exit the actual
    88  * function returning the error code.
    89  *
    90  * @param[in] value     The value to be checked. May be a function call.
    91  *
    92  */
    93 
    94 #define ERROR_PROPAGATE(value) \
    95         if (ERROR_OCCURRED(value)) \
    96                 return ERROR_CODE
    97 
    9845#endif
    9946
    10047/** @}
    10148 */
     49
  • uspace/lib/c/include/fibril.h

    ra93d79a r8fb1bf82  
    4848#define FIBRIL_WRITER      2
    4949
     50struct fibril;
     51
     52typedef struct {
     53        struct fibril *owned_by;
     54} fibril_owner_info_t;
     55
    5056typedef enum {
    5157        FIBRIL_PREEMPT,
     
    6874        int retval;
    6975        int flags;
     76
     77        fibril_owner_info_t *waits_for;
    7078} fibril_t;
    7179
  • uspace/lib/c/include/fibril_synch.h

    ra93d79a r8fb1bf82  
    4343
    4444typedef struct {
     45        fibril_owner_info_t oi;         /* Keep this the first thing. */
    4546        int counter;
    4647        link_t waiters;
     
    4950#define FIBRIL_MUTEX_INITIALIZER(name) \
    5051        { \
     52                .oi = { \
     53                        .owned_by = NULL \
     54                }, \
    5155                .counter = 1, \
    5256                .waiters = { \
     
    6064
    6165typedef struct {
     66        fibril_owner_info_t oi; /* Keep this the first thing. */
    6267        unsigned writers;
    6368        unsigned readers;
     
    6772#define FIBRIL_RWLOCK_INITIALIZER(name) \
    6873        { \
     74                .oi = { \
     75                        .owned_by = NULL \
     76                }, \
    6977                .readers = 0, \
    7078                .writers = 0, \
  • uspace/lib/c/include/ipc/devmap.h

    ra93d79a r8fb1bf82  
    4040#define DEVMAP_NAME_MAXLEN  255
    4141
    42 typedef ipcarg_t dev_handle_t;
     42typedef ipcarg_t devmap_handle_t;
    4343
    4444typedef enum {
     
    8181
    8282typedef struct {
    83         dev_handle_t handle;
     83        devmap_handle_t handle;
    8484        char name[DEVMAP_NAME_MAXLEN + 1];
    8585} dev_desc_t;
  • uspace/lib/c/include/ipc/services.h

    ra93d79a r8fb1bf82  
    3939
    4040typedef enum {
    41         SERVICE_LOAD = 1,
     41        SERVICE_NONE = 0,
     42        SERVICE_LOAD,
    4243        SERVICE_PCI,
    4344        SERVICE_VIDEO,
     
    4546        SERVICE_VFS,
    4647        SERVICE_DEVMAP,
     48        SERVICE_DEVMAN,
    4749        SERVICE_FHC,
    4850        SERVICE_OBIO,
  • uspace/lib/c/include/net/device.h

    ra93d79a r8fb1bf82  
    5959 */
    6060typedef struct device_stats device_stats_t;
    61 
    62 /** Type definition of the device usage statistics pointer.
    63  * @see device_stats
    64  */
    65 typedef device_stats_t *device_stats_ref;
    6661
    6762/** Device state. */
  • uspace/lib/c/include/net/icmp_codes.h

    ra93d79a r8fb1bf82  
    4242#define LIBC_ICMP_CODES_H_
    4343
     44#include <sys/types.h>
     45
    4446/** ICMP type type definition. */
    4547typedef uint8_t icmp_type_t;
  • uspace/lib/c/include/net/modules.h

    ra93d79a r8fb1bf82  
    6969 *
    7070 * @param[in] need      The needed module service.
    71  * @returns             The phone of the needed service.
     71 * @return              The phone of the needed service.
    7272 */
    7373typedef int connect_module_t(services_t need);
  • uspace/lib/c/include/net/packet.h

    ra93d79a r8fb1bf82  
    4646 * @see packet
    4747 */
    48 typedef struct packet * packet_t;
    49 
    50 /** Type definition of the packet pointer.
    51  * @see packet
    52  */
    53 typedef packet_t * packet_ref;
     48typedef struct packet packet_t;
    5449
    5550/** Type definition of the packet dimension.
     
    5752 */
    5853typedef struct packet_dimension packet_dimension_t;
    59 
    60 /** Type definition of the packet dimension pointer.
    61  * @see packet_dimension
    62  */
    63 typedef packet_dimension_t * packet_dimension_ref;
    6454
    6555/** Packet dimension. */
     
    7969/*@{*/
    8070
    81 extern packet_t pm_find(packet_id_t);
    82 extern int pm_add(packet_t);
     71extern packet_t *pm_find(packet_id_t);
     72extern int pm_add(packet_t *);
    8373extern int pm_init(void);
    8474extern void pm_destroy(void);
    8575
    86 extern int pq_add(packet_t *, packet_t, size_t, size_t);
    87 extern packet_t pq_find(packet_t, size_t);
    88 extern int pq_insert_after(packet_t, packet_t);
    89 extern packet_t pq_detach(packet_t);
    90 extern int pq_set_order(packet_t, size_t, size_t);
    91 extern int pq_get_order(packet_t, size_t *, size_t *);
    92 extern void pq_destroy(packet_t, void (*)(packet_t));
    93 extern packet_t pq_next(packet_t);
    94 extern packet_t pq_previous(packet_t);
     76extern int pq_add(packet_t **, packet_t *, size_t, size_t);
     77extern packet_t *pq_find(packet_t *, size_t);
     78extern int pq_insert_after(packet_t *, packet_t *);
     79extern packet_t *pq_detach(packet_t *);
     80extern int pq_set_order(packet_t *, size_t, size_t);
     81extern int pq_get_order(packet_t *, size_t *, size_t *);
     82extern void pq_destroy(packet_t *, void (*)(packet_t *));
     83extern packet_t *pq_next(packet_t *);
     84extern packet_t *pq_previous(packet_t *);
    9585
    9686/*@}*/
  • uspace/lib/c/include/net/packet_header.h

    ra93d79a r8fb1bf82  
    124124/** Returns whether the packet is valid.
    125125 * @param[in] packet    The packet to be checked.
    126  * @returns             True if the packet is not NULL and the magic value is
     126 * @return              True if the packet is not NULL and the magic value is
    127127 *                      correct.
    128  * @returns             False otherwise.
     128 * @return              False otherwise.
    129129 */
    130 static inline int packet_is_valid(const packet_t packet)
     130static inline int packet_is_valid(const packet_t *packet)
    131131{
    132132        return packet && (packet->magic_value == PACKET_MAGIC_VALUE);
  • uspace/lib/c/include/stdio.h

    ra93d79a r8fb1bf82  
    4646#define BUFSIZ  4096
    4747
    48 #define DEBUG(fmt, ...)se\
     48#define DEBUG(fmt, ...) \
    4949        { \
    5050                char _buf[256]; \
  • uspace/lib/c/include/sys/stat.h

    ra93d79a r8fb1bf82  
    4343struct stat {
    4444        fs_handle_t fs_handle;
    45         dev_handle_t dev_handle;
     45        devmap_handle_t devmap_handle;
    4646        fs_index_t index;
    4747        unsigned int lnkcnt;
     
    4949        bool is_directory;
    5050        aoff64_t size;
    51         dev_handle_t device;
     51        devmap_handle_t device;
    5252};
    5353
  • uspace/lib/c/include/task.h

    ra93d79a r8fb1bf82  
    4848extern int task_set_name(const char *);
    4949extern task_id_t task_spawn(const char *, const char *const[], int *);
     50extern int task_spawnv(task_id_t *, const char *path, const char *const []);
     51extern int task_spawnl(task_id_t *, const char *path, ...);
     52
    5053extern int task_wait(task_id_t id, task_exit_t *, int *);
    5154extern int task_retval(int);
  • uspace/lib/c/include/unistd.h

    ra93d79a r8fb1bf82  
    4141
    4242#ifndef NULL
    43         #define NULL  0
     43        #define NULL    ((void *) 0)
    4444#endif
    4545
  • uspace/lib/c/include/vfs/vfs.h

    ra93d79a r8fb1bf82  
    4747typedef struct {
    4848        fs_handle_t fs_handle;
    49         dev_handle_t dev_handle;
     49        devmap_handle_t devmap_handle;
    5050        fs_index_t index;
    5151} fdi_node_t;
Note: See TracChangeset for help on using the changeset viewer.