Changeset 5cde90f in mainline for uspace/lib


Ignore:
Timestamp:
2010-02-19T17:16:46Z (16 years ago)
Author:
Pavel Rimsky <pavel@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
617652f
Parents:
b86d436 (diff), f41aa81 (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:

Synchronizing with head (which has just been synchronized with this branch).

Location:
uspace/lib
Files:
27 added
1 deleted
62 edited
6 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/libblock/libblock.c

    rb86d436 r5cde90f  
    11/*
    2  * Copyright (c) 2008 Jakub Jermar 
    3  * Copyright (c) 2008 Martin Decky 
     2 * Copyright (c) 2008 Jakub Jermar
     3 * Copyright (c) 2008 Martin Decky
    44 * All rights reserved.
    55 *
     
    5252#include <macros.h>
    5353#include <mem.h>
     54#include <sys/typefmt.h>
     55#include <stacktrace.h>
    5456
    5557/** Lock protecting the device connection list */
     
    7981        size_t comm_size;
    8082        void *bb_buf;
    81         bn_t bb_addr;
     83        aoff64_t bb_addr;
    8284        size_t pblock_size;             /**< Physical block size. */
    8385        cache_t *cache;
    8486} devcon_t;
    8587
    86 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
    87 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
     88static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt);
     89static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt);
    8890static int get_block_size(int dev_phone, size_t *bsize);
    89 static int get_num_blocks(int dev_phone, bn_t *nblocks);
     91static int get_num_blocks(int dev_phone, aoff64_t *nblocks);
    9092
    9193static devcon_t *devcon_search(dev_handle_t dev_handle)
     
    198200        assert(devcon);
    199201       
     202        if (devcon->cache)
     203                (void) block_cache_fini(dev_handle);
     204
    200205        devcon_remove(devcon);
    201206
     
    203208                free(devcon->bb_buf);
    204209
    205         if (devcon->cache) {
    206                 hash_table_destroy(&devcon->cache->block_hash);
    207                 free(devcon->cache);
    208         }
    209 
    210210        munmap(devcon->comm_area, devcon->comm_size);
    211211        ipc_hangup(devcon->dev_phone);
     
    214214}
    215215
    216 int block_bb_read(dev_handle_t dev_handle, bn_t ba)
     216int block_bb_read(dev_handle_t dev_handle, aoff64_t ba)
    217217{
    218218        void *bb_buf;
     
    305305}
    306306
     307int block_cache_fini(dev_handle_t dev_handle)
     308{
     309        devcon_t *devcon = devcon_search(dev_handle);
     310        cache_t *cache;
     311        int rc;
     312
     313        if (!devcon)
     314                return ENOENT;
     315        if (!devcon->cache)
     316                return EOK;
     317        cache = devcon->cache;
     318       
     319        /*
     320         * We are expecting to find all blocks for this device handle on the
     321         * free list, i.e. the block reference count should be zero. Do not
     322         * bother with the cache and block locks because we are single-threaded.
     323         */
     324        while (!list_empty(&cache->free_head)) {
     325                block_t *b = list_get_instance(cache->free_head.next,
     326                    block_t, free_link);
     327
     328                list_remove(&b->free_link);
     329                if (b->dirty) {
     330                        memcpy(devcon->comm_area, b->data, b->size);
     331                        rc = write_blocks(devcon, b->boff, 1);
     332                        if (rc != EOK)
     333                                return rc;
     334                }
     335
     336                unsigned long key = b->boff;
     337                hash_table_remove(&cache->block_hash, &key, 1);
     338               
     339                free(b->data);
     340                free(b);
     341        }
     342
     343        hash_table_destroy(&cache->block_hash);
     344        devcon->cache = NULL;
     345        free(cache);
     346
     347        return EOK;
     348}
     349
    307350#define CACHE_LO_WATERMARK      10     
    308351#define CACHE_HI_WATERMARK      20     
     
    339382 * @return                      EOK on success or a negative error code.
    340383 */
    341 int block_get(block_t **block, dev_handle_t dev_handle, bn_t boff, int flags)
     384int block_get(block_t **block, dev_handle_t dev_handle, aoff64_t boff, int flags)
    342385{
    343386        devcon_t *devcon;
     
    614657 * @return              EOK on success or a negative return code on failure.
    615658 */
    616 int block_seqread(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen,
    617     off_t *pos, void *dst, size_t size)
    618 {
    619         off_t offset = 0;
     659int block_seqread(dev_handle_t dev_handle, size_t *bufpos, size_t *buflen,
     660    aoff64_t *pos, void *dst, size_t size)
     661{
     662        size_t offset = 0;
    620663        size_t left = size;
    621664        size_t block_size;
     
    647690                }
    648691               
    649                 if (*bufpos == (off_t) *buflen) {
     692                if (*bufpos == *buflen) {
    650693                        /* Refill the communication buffer with a new block. */
    651694                        int rc;
     
    675718 * @return              EOK on success or negative error code on failure.
    676719 */
    677 int block_read_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt, void *buf)
     720int block_read_direct(dev_handle_t dev_handle, aoff64_t ba, size_t cnt, void *buf)
    678721{
    679722        devcon_t *devcon;
     
    703746 * @return              EOK on success or negative error code on failure.
    704747 */
    705 int block_write_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt,
     748int block_write_direct(dev_handle_t dev_handle, aoff64_t ba, size_t cnt,
    706749    const void *data)
    707750{
     
    746789 * @return              EOK on success or negative error code on failure.
    747790 */
    748 int block_get_nblocks(dev_handle_t dev_handle, bn_t *nblocks)
     791int block_get_nblocks(dev_handle_t dev_handle, aoff64_t *nblocks)
    749792{
    750793        devcon_t *devcon;
     
    765808 * @return              EOK on success or negative error code on failure.
    766809 */
    767 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
     810static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt)
    768811{
    769812        int rc;
     
    772815        rc = async_req_3_0(devcon->dev_phone, BD_READ_BLOCKS, LOWER32(ba),
    773816            UPPER32(ba), cnt);
     817        if (rc != EOK) {
     818                printf("Error %d reading %d blocks starting at block %" PRIuOFF64
     819                    " from device handle %d\n", rc, cnt, ba,
     820                    devcon->dev_handle);
     821#ifndef NDEBUG
     822                stacktrace_print();
     823#endif
     824        }
    774825        return rc;
    775826}
     
    784835 * @return              EOK on success or negative error code on failure.
    785836 */
    786 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
     837static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt)
    787838{
    788839        int rc;
     
    791842        rc = async_req_3_0(devcon->dev_phone, BD_WRITE_BLOCKS, LOWER32(ba),
    792843            UPPER32(ba), cnt);
     844        if (rc != EOK) {
     845                printf("Error %d writing %d blocks starting at block %" PRIuOFF64
     846                    " to device handle %d\n", rc, cnt, ba, devcon->dev_handle);
     847#ifndef NDEBUG
     848                stacktrace_print();
     849#endif
     850        }
    793851        return rc;
    794852}
     
    808866
    809867/** Get total number of blocks on block device. */
    810 static int get_num_blocks(int dev_phone, bn_t *nblocks)
     868static int get_num_blocks(int dev_phone, aoff64_t *nblocks)
    811869{
    812870        ipcarg_t nb_l, nb_h;
     
    815873        rc = async_req_0_2(dev_phone, BD_GET_NUM_BLOCKS, &nb_l, &nb_h);
    816874        if (rc == EOK) {
    817                 *nblocks = (bn_t) MERGE_LOUP32(nb_l, nb_h);
     875                *nblocks = (aoff64_t) MERGE_LOUP32(nb_l, nb_h);
    818876        }
    819877
  • uspace/lib/libblock/libblock.h

    rb86d436 r5cde90f  
    7474        dev_handle_t dev_handle;
    7575        /** Block offset on the block device. Counted in 'size'-byte blocks. */
    76         bn_t boff;
     76        aoff64_t boff;
    7777        /** Size of the block. */
    7878        size_t size;
     
    9696extern void block_fini(dev_handle_t);
    9797
    98 extern int block_bb_read(dev_handle_t, bn_t);
     98extern int block_bb_read(dev_handle_t, aoff64_t);
    9999extern void *block_bb_get(dev_handle_t);
    100100
    101101extern int block_cache_init(dev_handle_t, size_t, unsigned, enum cache_mode);
     102extern int block_cache_fini(dev_handle_t);
    102103
    103 extern int block_get(block_t **, dev_handle_t, bn_t, int);
     104extern int block_get(block_t **, dev_handle_t, aoff64_t, int);
    104105extern int block_put(block_t *);
    105106
    106 extern int block_seqread(dev_handle_t, off_t *, size_t *, off_t *, void *,
     107extern int block_seqread(dev_handle_t, size_t *, size_t *, aoff64_t *, void *,
    107108    size_t);
    108109
    109110extern int block_get_bsize(dev_handle_t, size_t *);
    110 extern int block_get_nblocks(dev_handle_t, bn_t *);
    111 extern int block_read_direct(dev_handle_t, bn_t, size_t, void *);
    112 extern int block_write_direct(dev_handle_t, bn_t, size_t, const void *);
     111extern int block_get_nblocks(dev_handle_t, aoff64_t *);
     112extern int block_read_direct(dev_handle_t, aoff64_t, size_t, void *);
     113extern int block_write_direct(dev_handle_t, aoff64_t, size_t, const void *);
    113114
    114115#endif
  • uspace/lib/libc/Makefile.toolchain

    rb86d436 r5cde90f  
    3030        -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
    3131        -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
    32         -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
    33         -Werror-implicit-function-declaration -pipe -g -D__$(ENDIANESS)__
     32        -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
     33        -Werror-implicit-function-declaration -Werror -pipe -g -D__$(ENDIANESS)__
    3434
    3535ICC_CFLAGS = -I$(LIBC_PREFIX)/include -O3 -imacros $(LIBC_PREFIX)/../../../config.h \
     
    3737        -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
    3838        -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
    39         -Werror-implicit-function-declaration -pipe -g -D__$(ENDIANESS)__
     39        -Werror-implicit-function-declaration -Werror -pipe -g -D__$(ENDIANESS)__
    4040
    4141CLANG_CFLAGS = -I$(LIBC_PREFIX)/include -O3 -imacros $(LIBC_PREFIX)/../../../config.h \
  • uspace/lib/libc/arch/amd64/Makefile.inc

    rb86d436 r5cde90f  
    3737        arch/$(UARCH)/src/fibril.S \
    3838        arch/$(UARCH)/src/tls.c \
    39         arch/$(UARCH)/src/stacktrace.S
     39        arch/$(UARCH)/src/stacktrace.c \
     40        arch/$(UARCH)/src/stacktrace_asm.S
    4041
    4142GCC_CFLAGS += -fno-omit-frame-pointer
  • uspace/lib/libc/arch/amd64/include/limits.h

    rb86d436 r5cde90f  
    3636#define LIBC_amd64_LIMITS_H_
    3737
    38 # define LONG_MIN MIN_INT64
    39 # define LONG_MAX MAX_INT64
    40 # define ULONG_MIN MIN_UINT64
    41 # define ULONG_MAX MAX_UINT64
     38#define LONG_MIN MIN_INT64
     39#define LONG_MAX MAX_INT64
     40#define ULONG_MIN MIN_UINT64
     41#define ULONG_MAX MAX_UINT64
     42
     43#define SIZE_MIN MIN_UINT64
     44#define SIZE_MAX MAX_UINT64
     45#define SSIZE_MIN MIN_INT64
     46#define SSIZE_MAX MAX_INT64
    4247
    4348#endif
  • uspace/lib/libc/arch/amd64/include/types.h

    rb86d436 r5cde90f  
    3636#define LIBC_amd64_TYPES_H_
    3737
     38#define __64_BITS__
     39
    3840typedef unsigned long long sysarg_t;
    3941
  • uspace/lib/libc/arch/amd64/src/stacktrace_asm.S

    rb86d436 r5cde90f  
    2929.text
    3030
    31 .global frame_pointer_get
    32 .global frame_pointer_prev
    33 .global frame_pointer_validate
    34 .global return_address_get
    35 .global program_counter_get
     31.global stacktrace_prepare
     32.global stacktrace_fp_get
     33.global stacktrace_pc_get
    3634
    37 frame_pointer_get:
     35stacktrace_prepare:
     36        ret
     37
     38stacktrace_fp_get:
    3839        movq %rbp, %rax
    3940        ret
    4041
    41 frame_pointer_prev:
    42         movq (%rdi), %rax
    43         ret
    44 
    45 frame_pointer_validate:
    46         movq %rdi, %rax
    47         ret
    48 
    49 return_address_get:
    50         movq 8(%rdi), %rax
    51         ret
    52 
    53 program_counter_get:
     42stacktrace_pc_get:
    5443        movq (%rsp), %rax
    5544        ret
  • uspace/lib/libc/arch/arm32/Makefile.inc

    rb86d436 r5cde90f  
    3838        arch/$(UARCH)/src/tls.c \
    3939        arch/$(UARCH)/src/eabi.S \
    40         arch/$(UARCH)/src/stacktrace.S
     40        arch/$(UARCH)/src/stacktrace.c \
     41        arch/$(UARCH)/src/stacktrace_asm.S
    4142
    4243GCC_CFLAGS += -ffixed-r9 -mtp=soft -mapcs-frame -fno-omit-frame-pointer
  • uspace/lib/libc/arch/arm32/include/limits.h

    rb86d436 r5cde90f  
    2727 */
    2828
    29 /** @addtogroup libcarm32       
     29/** @addtogroup libcarm32
    3030 * @{
    3131 */
    32 /** @file 
     32/** @file
    3333 *  @brief Limits declarations.
    3434 */
     
    4242#define ULONG_MAX MAX_UINT32
    4343
     44#define SIZE_MIN MIN_UINT32
     45#define SIZE_MAX MAX_UINT32
     46#define SSIZE_MIN MIN_INT32
     47#define SSIZE_MAX MAX_INT32
     48
    4449#endif
    4550
  • uspace/lib/libc/arch/arm32/include/types.h

    rb86d436 r5cde90f  
    3737#define LIBC_arm32_TYPES_H_
    3838
     39#define __32_BITS__
     40
    3941typedef unsigned int sysarg_t;
    4042
  • uspace/lib/libc/arch/arm32/src/stacktrace_asm.S

    rb86d436 r5cde90f  
    2929.text
    3030
    31 .global frame_pointer_get
    32 .global frame_pointer_prev
    33 .global frame_pointer_validate
    34 .global return_address_get
    35 .global program_counter_get
     31.global stacktrace_prepare
     32.global stacktrace_fp_get
     33.global stacktrace_pc_get
    3634
    37 frame_pointer_get:
     35stacktrace_prepare:
     36        mov pc, lr
     37
     38stacktrace_fp_get:
    3839        mov r0, fp
    3940        mov pc, lr
    4041
    41 frame_pointer_prev:
    42         ldr r0, [r0, #-12]
    43         mov pc, lr
    44 
    45 frame_pointer_validate:
    46         mov pc, lr
    47 
    48 return_address_get:
    49         ldr r0, [r0, #-4]
    50         mov pc, lr
    51 
    52 program_counter_get:
     42stacktrace_pc_get:
    5343        mov r0, lr
    5444        mov pc, lr
    55 
  • uspace/lib/libc/arch/ia32/Makefile.inc

    rb86d436 r5cde90f  
    3838        arch/$(UARCH)/src/tls.c \
    3939        arch/$(UARCH)/src/setjmp.S \
    40         arch/$(UARCH)/src/stacktrace.S
     40        arch/$(UARCH)/src/stacktrace.c \
     41        arch/$(UARCH)/src/stacktrace_asm.S
    4142
    4243GCC_CFLAGS += -march=pentium
  • uspace/lib/libc/arch/ia32/include/limits.h

    rb86d436 r5cde90f  
    3636#define LIBC_ia32__LIMITS_H_
    3737
    38 # define LONG_MIN MIN_INT32
    39 # define LONG_MAX MAX_INT32
    40 # define ULONG_MIN MIN_UINT32
    41 # define ULONG_MAX MAX_UINT32
     38#define LONG_MIN MIN_INT32
     39#define LONG_MAX MAX_INT32
     40#define ULONG_MIN MIN_UINT32
     41#define ULONG_MAX MAX_UINT32
     42
     43#define SIZE_MIN MIN_UINT32
     44#define SIZE_MAX MAX_UINT32
     45#define SSIZE_MIN MIN_INT32
     46#define SSIZE_MAX MAX_INT32
    4247
    4348#endif
  • uspace/lib/libc/arch/ia32/include/syscall.h

    rb86d436 r5cde90f  
    4040#include <kernel/syscall/syscall.h>
    4141
    42 #define __syscall0      __syscall_fast_func
    43 #define __syscall1      __syscall_fast_func
    44 #define __syscall2      __syscall_fast_func
    45 #define __syscall3      __syscall_fast_func
    46 #define __syscall4      __syscall_fast_func
    47 #define __syscall5      __syscall_slow
    48 #define __syscall6      __syscall_slow
     42#define __syscall0  __syscall_fast_func
     43#define __syscall1  __syscall_fast_func
     44#define __syscall2  __syscall_fast_func
     45#define __syscall3  __syscall_fast_func
     46#define __syscall4  __syscall_fast_func
     47#define __syscall5  __syscall_slow
     48#define __syscall6  __syscall_slow
    4949
    50 extern sysarg_t
    51 (* __syscall_fast_func)(const sysarg_t, const sysarg_t, const sysarg_t,
     50extern sysarg_t (* __syscall_fast_func)(const sysarg_t, const sysarg_t,
     51    const sysarg_t, const sysarg_t, const sysarg_t, const sysarg_t,
     52    const syscall_t);
     53
     54extern sysarg_t __syscall_slow(const sysarg_t, const sysarg_t, const sysarg_t,
    5255    const sysarg_t, const sysarg_t, const sysarg_t, const syscall_t);
    53 
    54 extern sysarg_t
    55 __syscall_slow(const sysarg_t, const sysarg_t, const sysarg_t, const sysarg_t,
    56     const sysarg_t, const sysarg_t, const syscall_t);
    5756
    5857#endif
  • uspace/lib/libc/arch/ia32/include/tls.h

    rb86d436 r5cde90f  
    5353{
    5454        void *retval;
    55 
    56         asm ("movl %%gs:0, %0" : "=r"(retval));
     55       
     56        asm (
     57                "movl %%gs:0, %0"
     58                : "=r" (retval)
     59        );
     60       
    5761        return retval;
    5862}
  • uspace/lib/libc/arch/ia32/include/types.h

    rb86d436 r5cde90f  
    3636#define LIBC_ia32_TYPES_H_
    3737
     38#define __32_BITS__
     39
    3840typedef unsigned int sysarg_t;
    3941
  • uspace/lib/libc/arch/ia32/src/stacktrace_asm.S

    rb86d436 r5cde90f  
    2929.text
    3030
    31 .global frame_pointer_get
    32 .global frame_pointer_prev
    33 .global frame_pointer_validate
    34 .global return_address_get
    35 .global program_counter_get
     31.global stacktrace_prepare
     32.global stacktrace_fp_get
     33.global stacktrace_pc_get
    3634
    37 frame_pointer_get:
     35stacktrace_prepare:
     36        ret
     37
     38stacktrace_fp_get:
    3839        movl %ebp, %eax
    3940        ret
    4041
    41 frame_pointer_prev:
    42         movl 4(%esp), %eax
    43         movl (%eax), %eax
    44         ret
    45 
    46 frame_pointer_validate:
    47         movl 4(%esp), %eax
    48         ret
    49 
    50 return_address_get:
    51         movl 4(%esp), %eax
    52         movl 4(%eax), %eax
    53         ret
    54 
    55 program_counter_get:
     42stacktrace_pc_get:
    5643        movl (%esp), %eax
    5744        ret
  • uspace/lib/libc/arch/ia64/Makefile.inc

    rb86d436 r5cde90f  
    3737        arch/$(UARCH)/src/tls.c \
    3838        arch/$(UARCH)/src/ddi.c \
    39         arch/$(UARCH)/src/stacktrace.S
     39        arch/$(UARCH)/src/stacktrace.c \
     40        arch/$(UARCH)/src/stacktrace_asm.S
    4041
    4142GCC_CFLAGS += -fno-unwind-tables
  • uspace/lib/libc/arch/ia64/include/ddi.h

    rb86d436 r5cde90f  
    3939#include <libarch/types.h>
    4040
    41 #define IO_SPACE_BOUNDARY       (64 * 1024)
     41#define IO_SPACE_BOUNDARY       ((void *) (64 * 1024))
    4242
    4343uint64_t get_ia64_iospace_address(void);
  • uspace/lib/libc/arch/ia64/include/faddr.h

    rb86d436 r5cde90f  
    2727 */
    2828
    29 /** @addtogroup libcia64       
     29/** @addtogroup libcia64
    3030 * @{
    3131 */
     
    3838#include <libarch/types.h>
    3939
    40 /** 
     40/**
    4141 *
    4242 * Calculate absolute address of function
    4343 * referenced by fptr pointer.
    4444 *
    45  * @param f Function pointer.
     45 * @param fptr Function pointer.
    4646 *
    4747 */
    48 #define FADDR(f)         (*((uintptr_t *)(f)));
     48#define FADDR(fptr)  (((fncptr_t *) (fptr))->fnc)
    4949
    5050#endif
  • uspace/lib/libc/arch/ia64/include/fibril.h

    rb86d436 r5cde90f  
    5353#define PSTHREAD_INITIAL_STACK_DIVISION 2 
    5454
    55 #ifdef context_set
    56 #undef context_set
    57 #endif
    58 
    5955#define context_set(c, _pc, stack, size, tls)                                                           \
    6056        do {                                                                                            \
     
    110106        uint64_t pr;
    111107
    112         __r128 f2 __attribute__ ((aligned(16)));
    113         __r128 f3;
    114         __r128 f4;
    115         __r128 f5;
     108        uint128_t f2 __attribute__ ((aligned(16)));
     109        uint128_t f3;
     110        uint128_t f4;
     111        uint128_t f5;
    116112
    117         __r128 f16;
    118         __r128 f17;
    119         __r128 f18;
    120         __r128 f19;
    121         __r128 f20;
    122         __r128 f21;
    123         __r128 f22;
    124         __r128 f23;
    125         __r128 f24;
    126         __r128 f25;
    127         __r128 f26;
    128         __r128 f27;
    129         __r128 f28;
    130         __r128 f29;
    131         __r128 f30;
    132         __r128 f31;
     113        uint128_t f16;
     114        uint128_t f17;
     115        uint128_t f18;
     116        uint128_t f19;
     117        uint128_t f20;
     118        uint128_t f21;
     119        uint128_t f22;
     120        uint128_t f23;
     121        uint128_t f24;
     122        uint128_t f25;
     123        uint128_t f26;
     124        uint128_t f27;
     125        uint128_t f28;
     126        uint128_t f29;
     127        uint128_t f30;
     128        uint128_t f31;
    133129
    134130} context_t;
  • uspace/lib/libc/arch/ia64/include/limits.h

    rb86d436 r5cde90f  
    2727 */
    2828
    29 /** @addtogroup libcia64       
     29/** @addtogroup libcia64
    3030 * @{
    3131 */
     
    3636#define LIBC_ia64_LIMITS_H_
    3737
    38 # define LONG_MIN MIN_INT64
    39 # define LONG_MAX MAX_INT64
    40 # define ULONG_MIN MIN_UINT64
    41 # define ULONG_MAX MAX_UINT64
     38#define LONG_MIN MIN_INT64
     39#define LONG_MAX MAX_INT64
     40#define ULONG_MIN MIN_UINT64
     41#define ULONG_MAX MAX_UINT64
     42
     43#define SIZE_MIN MIN_UINT64
     44#define SIZE_MAX MAX_UINT64
     45#define SSIZE_MIN MIN_INT64
     46#define SSIZE_MAX MAX_INT64
    4247
    4348#endif
  • uspace/lib/libc/arch/ia64/include/types.h

    rb86d436 r5cde90f  
    2727 */
    2828
    29 /** @addtogroup libcia64       
     29/** @addtogroup libcia64
    3030 * @{
    3131 */
     
    3535#ifndef LIBC_ia64_TYPES_H_
    3636#define LIBC_ia64_TYPES_H_
     37
     38#define __64_BITS__
    3739
    3840typedef unsigned long long sysarg_t;
     
    4850typedef unsigned long int uint64_t;
    4951
     52typedef struct {
     53        uint64_t lo;
     54        uint64_t hi;
     55} uint128_t;
     56
    5057typedef int64_t ssize_t;
    5158typedef uint64_t size_t;
     
    5360typedef uint64_t uintptr_t;
    5461
    55 typedef unsigned char __r8;                     /* Reserve byte */
    56 typedef unsigned short __r16;
    57 typedef unsigned int __r32;
    58 typedef unsigned long __r64;
    59 
    60 typedef struct __r128{
    61         __r64 lo;
    62         __r64 hi;
    63 } __r128;
     62typedef struct {
     63        uintptr_t fnc;
     64        uintptr_t gp;
     65} __attribute__((may_alias)) fncptr_t;
    6466
    6567#endif
  • uspace/lib/libc/arch/ia64/src/stacktrace_asm.S

    rb86d436 r5cde90f  
    2929.text
    3030
    31 .global frame_pointer_get
    32 .global frame_pointer_prev
    33 .global frame_pointer_validate
    34 .global return_address_get
    35 .global program_counter_get
     31.global stacktrace_prepare
     32.global stacktrace_fp_get
     33.global stacktrace_pc_get
    3634
    37 frame_pointer_get:
    38 frame_pointer_prev:
    39 frame_pointer_validate:
    40 return_address_get:
    41 program_counter_get:
     35stacktrace_prepare:
     36        br.ret.sptk.many b0
     37
     38stacktrace_fp_get:
     39stacktrace_pc_get:
    4240        mov r8 = r0
    4341        br.ret.sptk.many b0
  • uspace/lib/libc/arch/mips32/Makefile.inc

    rb86d436 r5cde90f  
    3636        arch/$(UARCH)/src/fibril.S \
    3737        arch/$(UARCH)/src/tls.c \
    38         arch/$(UARCH)/src/stacktrace.S
     38        arch/$(UARCH)/src/stacktrace.c \
     39        arch/$(UARCH)/src/stacktrace_asm.S
    3940
    4041GCC_CFLAGS += -mips3
  • uspace/lib/libc/arch/mips32/include/limits.h

    rb86d436 r5cde90f  
    2727 */
    2828
    29 /** @addtogroup libcmips32     
     29/** @addtogroup libcmips32
    3030 * @{
    3131 */
    3232/** @file
    33  * @ingroup libcmips32eb       
     33 * @ingroup libcmips32eb
    3434 */
    3535
     
    3737#define LIBC_mips32__LIMITS_H_
    3838
    39 # define LONG_MIN MIN_INT32
    40 # define LONG_MAX MAX_INT32
    41 # define ULONG_MIN MIN_UINT32
    42 # define ULONG_MAX MAX_UINT32
     39#define LONG_MIN MIN_INT32
     40#define LONG_MAX MAX_INT32
     41#define ULONG_MIN MIN_UINT32
     42#define ULONG_MAX MAX_UINT32
     43
     44#define SIZE_MIN MIN_UINT32
     45#define SIZE_MAX MAX_UINT32
     46#define SSIZE_MIN MIN_INT32
     47#define SSIZE_MAX MAX_INT32
    4348
    4449#endif
  • uspace/lib/libc/arch/mips32/include/types.h

    rb86d436 r5cde90f  
    3737#define LIBC_mips32_TYPES_H_
    3838
     39#define __32_BITS__
     40
    3941typedef unsigned int sysarg_t;
    4042
  • uspace/lib/libc/arch/mips32/src/stacktrace_asm.S

    rb86d436 r5cde90f  
    3232.set noreorder
    3333
    34 .global frame_pointer_get
    35 .global frame_pointer_prev
    36 .global frame_pointer_validate
    37 .global return_address_get
    38 .global program_counter_get
     34.global stacktrace_prepare
     35.global stacktrace_fp_get
     36.global stacktrace_pc_get
    3937
    40 frame_pointer_get:
    41 frame_pointer_prev:
    42 frame_pointer_validate:
    43 return_address_get:
    44 program_counter_get:
     38stacktrace_prepare:
     39stacktrace_fp_get:
     40stacktrace_pc_get:
    4541        j $ra
    4642        xor $v0, $v0
  • uspace/lib/libc/arch/mips32eb/Makefile.inc

    rb86d436 r5cde90f  
    3636        arch/$(UARCH)/src/fibril.S \
    3737        arch/$(UARCH)/src/tls.c \
    38         arch/$(UARCH)/src/stacktrace.S
     38        arch/$(UARCH)/src/stacktrace.c \
     39        arch/$(UARCH)/src/stacktrace_asm.S
    3940
    4041GCC_CFLAGS += -mips3
  • uspace/lib/libc/arch/ppc32/Makefile.inc

    rb86d436 r5cde90f  
    3636        arch/$(UARCH)/src/fibril.S \
    3737        arch/$(UARCH)/src/tls.c \
    38         arch/$(UARCH)/src/stacktrace.S
     38        arch/$(UARCH)/src/stacktrace.c \
     39        arch/$(UARCH)/src/stacktrace_asm.S
    3940
    4041GCC_CFLAGS += -mcpu=powerpc -msoft-float -m32
  • uspace/lib/libc/arch/ppc32/include/limits.h

    rb86d436 r5cde90f  
    2727 */
    2828
    29 /** @addtogroup libcppc32       
     29/** @addtogroup libcppc32
    3030 * @{
    3131 */
     
    4141#define ULONG_MAX MAX_UINT32
    4242
     43#define SIZE_MIN MIN_UINT32
     44#define SIZE_MAX MAX_UINT32
     45#define SSIZE_MIN MIN_INT32
     46#define SSIZE_MAX MAX_INT32
     47
    4348#endif
    4449
  • uspace/lib/libc/arch/ppc32/include/types.h

    rb86d436 r5cde90f  
    3636#define LIBC_ppc32_TYPES_H_
    3737
     38#define __32_BITS__
     39
    3840typedef unsigned int sysarg_t;
    3941
  • uspace/lib/libc/arch/ppc32/src/stacktrace_asm.S

    rb86d436 r5cde90f  
    3131#include <libarch/regname.h>
    3232
    33 .global frame_pointer_get
    34 .global frame_pointer_prev
    35 .global frame_pointer_validate
    36 .global return_address_get
    37 .global program_counter_get
     33.global stacktrace_prepare
     34.global stacktrace_fp_get
     35.global stacktrace_pc_get
    3836
    39 frame_pointer_get:
     37stacktrace_prepare:
     38        blr
     39
     40stacktrace_fp_get:
    4041        mr r3, sp
    4142        blr
    4243
    43 frame_pointer_prev:
    44         lwz r3, 0(r3)
    45         blr
    46 
    47 frame_pointer_validate:
    48         blr
    49 
    50 return_address_get:
    51         lwz r3, 4(r3)
    52         blr
    53 
    54 program_counter_get:
     44stacktrace_pc_get:
    5545        mflr r3
    5646        blr
  • uspace/lib/libc/arch/sparc64/Makefile.inc

    rb86d436 r5cde90f  
    3535ARCH_SOURCES += arch/$(UARCH)/src/fibril.S \
    3636        arch/$(UARCH)/src/tls.c \
    37         arch/$(UARCH)/src/stacktrace.S
     37        arch/$(UARCH)/src/stacktrace.c \
     38        arch/$(UARCH)/src/stacktrace_asm.S
    3839
    3940GCC_CFLAGS += -mcpu=ultrasparc -m64
  • uspace/lib/libc/arch/sparc64/include/ddi.h

    rb86d436 r5cde90f  
    3737#include <libarch/types.h>
    3838
    39 static inline memory_barrier(void)
     39static inline void memory_barrier(void)
    4040{
    41         asm volatile ("membar #LoadLoad | #StoreStore\n" ::: "memory");
     41        asm volatile (
     42                "membar #LoadLoad | #StoreStore\n"
     43                ::: "memory"
     44        );
    4245}
    4346
  • uspace/lib/libc/arch/sparc64/include/fibril.h

    rb86d436 r5cde90f  
    4242#define SP_DELTA        (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE)
    4343
    44 #ifdef context_set
    45 #undef context_set
    46 #endif
    47 
    4844#define context_set(c, _pc, stack, size, ptls) \
    4945        do { \
     
    5248                    STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA); \
    5349                (c)->fp = -STACK_BIAS; \
    54                 (c)->tp = ptls; \
     50                (c)->tp = (uint64_t) ptls; \
    5551        } while (0)
    5652       
  • uspace/lib/libc/arch/sparc64/include/limits.h

    rb86d436 r5cde90f  
    2727 */
    2828
    29 /** @addtogroup libcsparc64     
     29/** @addtogroup libcsparc64
    3030 * @{
    3131 */
     
    4141#define ULONG_MAX MAX_UINT64
    4242
     43#define SIZE_MIN MIN_UINT64
     44#define SIZE_MAX MAX_UINT64
     45#define SSIZE_MIN MIN_INT64
     46#define SSIZE_MAX MAX_INT64
     47
    4348#endif
    4449
  • uspace/lib/libc/arch/sparc64/include/types.h

    rb86d436 r5cde90f  
    2727 */
    2828
    29 /** @addtogroup libcsparc64     
     29/** @addtogroup libcsparc64
    3030 * @{
    3131 */
     
    3535#ifndef LIBC_sparc64_TYPES_H_
    3636#define LIBC_sparc64_TYPES_H_
     37
     38#define __64_BITS__
    3739
    3840typedef unsigned long sysarg_t;
  • uspace/lib/libc/generic/adt/hash_table.c

    rb86d436 r5cde90f  
    193193}
    194194
     195/** Apply fucntion to all items in hash table.
     196 *
     197 * @param h             Hash table.
     198 * @param f             Function to be applied.
     199 * @param arg           Argument to be passed to the function.
     200 */
     201void
     202hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg)
     203{
     204        hash_index_t bucket;
     205        link_t *cur;
     206
     207        for (bucket = 0; bucket < h->entries; bucket++) {
     208                for (cur = h->entry[bucket].next; cur != &h->entry[bucket];
     209                    cur = cur->next) {
     210                        f(cur, arg);
     211                }
     212        }
     213}
     214
    195215/** @}
    196216 */
  • uspace/lib/libc/generic/async.c

    rb86d436 r5cde90f  
    12871287}
    12881288
     1289/** Wrapper for forwarding any read request
     1290 *
     1291 *
     1292 */
     1293int async_data_read_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
     1294    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr)
     1295{
     1296        ipc_callid_t callid;
     1297        if (!async_data_read_receive(&callid, NULL)) {
     1298                ipc_answer_0(callid, EINVAL);
     1299                return EINVAL;
     1300        }
     1301       
     1302        aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4,
     1303            dataptr);
     1304        if (msg == 0) {
     1305                ipc_answer_0(callid, EINVAL);
     1306                return EINVAL;
     1307        }
     1308       
     1309        int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0,
     1310            IPC_FF_ROUTE_FROM_ME);
     1311        if (retval != EOK) {
     1312                async_wait_for(msg, NULL);
     1313                ipc_answer_0(callid, retval);
     1314                return retval;
     1315        }
     1316       
     1317        ipcarg_t rc;
     1318        async_wait_for(msg, &rc);
     1319       
     1320        return (int) rc;
     1321}
     1322
    12891323/** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
    12901324 *
    1291  * @param phoneid       Phone that will be used to contact the receiving side.
    1292  * @param src           Address of the beginning of the source buffer.
    1293  * @param size          Size of the source buffer.
    1294  *
    1295  * @return              Zero on success or a negative error code from errno.h.
     1325 * @param phoneid Phone that will be used to contact the receiving side.
     1326 * @param src     Address of the beginning of the source buffer.
     1327 * @param size    Size of the source buffer.
     1328 *
     1329 * @return Zero on success or a negative error code from errno.h.
     1330 *
    12961331 */
    12971332int async_data_write_start(int phoneid, const void *src, size_t size)
     
    13081343 * So far, this wrapper is to be used from within a connection fibril.
    13091344 *
    1310  * @param callid        Storage where the hash of the IPC_M_DATA_WRITE call will
    1311  *                      be stored.
    1312  * @param size          Storage where the suggested size will be stored. May be
    1313  *                      NULL
    1314  *
    1315  * @return              Non-zero on success, zero on failure.
     1345 * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will
     1346 *               be stored.
     1347 * @param size   Storage where the suggested size will be stored. May be
     1348 *               NULL
     1349 *
     1350 * @return Non-zero on success, zero on failure.
     1351 *
    13161352 */
    13171353int async_data_write_receive(ipc_callid_t *callid, size_t *size)
     
    13201356       
    13211357        assert(callid);
    1322 
     1358       
    13231359        *callid = async_get_call(&data);
    13241360        if (IPC_GET_METHOD(data) != IPC_M_DATA_WRITE)
    13251361                return 0;
     1362       
    13261363        if (size)
    13271364                *size = (size_t) IPC_GET_ARG2(data);
     1365       
    13281366        return 1;
    13291367}
     
    13341372 * so that the user doesn't have to remember the meaning of each IPC argument.
    13351373 *
    1336  * @param callid        Hash of the IPC_M_DATA_WRITE call to answer.
    1337  * @param dst           Final destination address for the IPC_M_DATA_WRITE call.
    1338  * @param size          Final size for the IPC_M_DATA_WRITE call.
    1339  *
    1340  * @return              Zero on success or a value from @ref errno.h on failure.
     1374 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     1375 * @param dst    Final destination address for the IPC_M_DATA_WRITE call.
     1376 * @param size   Final size for the IPC_M_DATA_WRITE call.
     1377 *
     1378 * @return Zero on success or a value from @ref errno.h on failure.
     1379 *
    13411380 */
    13421381int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
     
    13451384}
    13461385
    1347 /** Wrapper for receiving blobs via the async_data_write_*
     1386/** Wrapper for receiving binary data or strings
    13481387 *
    13491388 * This wrapper only makes it more comfortable to use async_data_write_*
    1350  * functions to receive blobs.
    1351  *
    1352  * @param blob     Pointer to data pointer (which should be later disposed
    1353  *                 by free()). If the operation fails, the pointer is not
    1354  *                 touched.
    1355  * @param max_size Maximum size (in bytes) of the blob to receive. 0 means
    1356  *                 no limit.
    1357  * @param received If not NULL, the size of the received data is stored here.
     1389 * functions to receive binary data or strings.
     1390 *
     1391 * @param data       Pointer to data pointer (which should be later disposed
     1392 *                   by free()). If the operation fails, the pointer is not
     1393 *                   touched.
     1394 * @param nullterm   If true then the received data is always zero terminated.
     1395 *                   This also causes to allocate one extra byte beyond the
     1396 *                   raw transmitted data.
     1397 * @param min_size   Minimum size (in bytes) of the data to receive.
     1398 * @param max_size   Maximum size (in bytes) of the data to receive. 0 means
     1399 *                   no limit.
     1400 * @param granulariy If non-zero then the size of the received data has to
     1401 *                   be divisible by this value.
     1402 * @param received   If not NULL, the size of the received data is stored here.
    13581403 *
    13591404 * @return Zero on success or a value from @ref errno.h on failure.
    13601405 *
    13611406 */
    1362 int async_data_blob_receive(char **blob, const size_t max_size, size_t *received)
     1407int async_data_write_accept(void **data, const bool nullterm,
     1408    const size_t min_size, const size_t max_size, const size_t granularity,
     1409    size_t *received)
    13631410{
    13641411        ipc_callid_t callid;
     
    13691416        }
    13701417       
     1418        if (size < min_size) {
     1419                ipc_answer_0(callid, EINVAL);
     1420                return EINVAL;
     1421        }
     1422       
    13711423        if ((max_size > 0) && (size > max_size)) {
    13721424                ipc_answer_0(callid, EINVAL);
     
    13741426        }
    13751427       
    1376         char *data = (char *) malloc(size);
    1377         if (data == NULL) {
     1428        if ((granularity > 0) && ((size % granularity) != 0)) {
     1429                ipc_answer_0(callid, EINVAL);
     1430                return EINVAL;
     1431        }
     1432       
     1433        void *_data;
     1434       
     1435        if (nullterm)
     1436                _data = malloc(size + 1);
     1437        else
     1438                _data = malloc(size);
     1439       
     1440        if (_data == NULL) {
    13781441                ipc_answer_0(callid, ENOMEM);
    13791442                return ENOMEM;
    13801443        }
    13811444       
    1382         int rc = async_data_write_finalize(callid, data, size);
     1445        int rc = async_data_write_finalize(callid, _data, size);
    13831446        if (rc != EOK) {
    1384                 free(data);
     1447                free(_data);
    13851448                return rc;
    13861449        }
    13871450       
    1388         *blob = data;
     1451        if (nullterm)
     1452                ((char *) _data)[size] = 0;
     1453       
     1454        *data = _data;
    13891455        if (received != NULL)
    13901456                *received = size;
     
    13931459}
    13941460
    1395 /** Wrapper for receiving strings via the async_data_write_*
    1396  *
    1397  * This wrapper only makes it more comfortable to use async_data_write_*
    1398  * functions to receive strings.
    1399  *
    1400  * @param str      Pointer to string pointer (which should be later disposed
    1401  *                 by free()). If the operation fails, the pointer is not
    1402  *                 touched.
    1403  * @param max_size Maximum size (in bytes) of the string to receive. 0 means
    1404  *                 no limit.
    1405  *
    1406  * @return Zero on success or a value from @ref errno.h on failure.
    1407  *
    1408  */
    1409 int async_data_string_receive(char **str, const size_t max_size)
     1461/** Wrapper for voiding any data that is about to be received
     1462 *
     1463 * This wrapper can be used to void any pending data
     1464 *
     1465 * @param retval Error value from @ref errno.h to be returned to the caller.
     1466 *
     1467 */
     1468void async_data_write_void(const int retval)
    14101469{
    14111470        ipc_callid_t callid;
    1412         size_t size;
    1413         if (!async_data_write_receive(&callid, &size)) {
     1471        async_data_write_receive(&callid, NULL);
     1472        ipc_answer_0(callid, retval);
     1473}
     1474
     1475/** Wrapper for forwarding any data that is about to be received
     1476 *
     1477 *
     1478 */
     1479int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
     1480    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr)
     1481{
     1482        ipc_callid_t callid;
     1483        if (!async_data_write_receive(&callid, NULL)) {
    14141484                ipc_answer_0(callid, EINVAL);
    14151485                return EINVAL;
    14161486        }
    14171487       
    1418         if ((max_size > 0) && (size > max_size)) {
     1488        aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4,
     1489            dataptr);
     1490        if (msg == 0) {
    14191491                ipc_answer_0(callid, EINVAL);
    14201492                return EINVAL;
    14211493        }
    14221494       
    1423         char *data = (char *) malloc(size + 1);
    1424         if (data == NULL) {
    1425                 ipc_answer_0(callid, ENOMEM);
    1426                 return ENOMEM;
    1427         }
    1428        
    1429         int rc = async_data_write_finalize(callid, data, size);
    1430         if (rc != EOK) {
    1431                 free(data);
    1432                 return rc;
    1433         }
    1434        
    1435         data[size] = 0;
    1436         *str = data;
    1437         return EOK;
     1495        int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0,
     1496            IPC_FF_ROUTE_FROM_ME);
     1497        if (retval != EOK) {
     1498                async_wait_for(msg, NULL);
     1499                ipc_answer_0(callid, retval);
     1500                return retval;
     1501        }
     1502       
     1503        ipcarg_t rc;
     1504        async_wait_for(msg, &rc);
     1505       
     1506        return (int) rc;
    14381507}
    14391508
  • uspace/lib/libc/generic/clipboard.c

    rb86d436 r5cde90f  
    8484                clip_connect();
    8585               
    86                 aid_t req = async_send_1(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_BLOB, NULL);
     86                aid_t req = async_send_1(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_DATA, NULL);
    8787                ipcarg_t rc = async_data_write_start(clip_phone, (void *) str, size);
    8888                if (rc != EOK) {
     
    139139                        *str = sbuf;
    140140                        return EOK;
    141                 case CLIPBOARD_TAG_BLOB:
     141                case CLIPBOARD_TAG_DATA:
    142142                        sbuf = malloc(size + 1);
    143143                        if (sbuf == NULL)
     
    148148                        aid_t req = async_send_1(clip_phone, CLIPBOARD_GET_DATA, tag, NULL);
    149149                        rc = async_data_read_start(clip_phone, (void *) sbuf, size);
    150                         if (rc == EOVERFLOW) {
     150                        if ((int) rc == EOVERFLOW) {
    151151                                /*
    152152                                 * The data in the clipboard has changed since
  • uspace/lib/libc/generic/fibril.c

    rb86d436 r5cde90f  
    4141#include <unistd.h>
    4242#include <stdio.h>
     43#include <arch/barrier.h>
    4344#include <libarch/faddr.h>
    4445#include <futex.h>
     
    133134int fibril_switch(fibril_switch_type_t stype)
    134135{
    135         fibril_t *srcf, *dstf;
    136136        int retval = 0;
    137137       
    138138        futex_down(&fibril_futex);
    139 
     139       
    140140        if (stype == FIBRIL_PREEMPT && list_empty(&ready_list))
    141141                goto ret_0;
    142 
     142       
    143143        if (stype == FIBRIL_FROM_MANAGER) {
    144                 if (list_empty(&ready_list) && list_empty(&serialized_list))
     144                if ((list_empty(&ready_list)) && (list_empty(&serialized_list)))
    145145                        goto ret_0;
     146               
    146147                /*
    147148                 * Do not preempt if there is not enough threads to run the
    148149                 * ready fibrils which are not serialized.
    149150                 */
    150                 if (list_empty(&serialized_list) &&
    151                     threads_in_manager <= serialized_threads) {
     151                if ((list_empty(&serialized_list)) &&
     152                    (threads_in_manager <= serialized_threads)) {
    152153                        goto ret_0;
    153154                }
    154155        }
     156       
    155157        /* If we are going to manager and none exists, create it */
    156         if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {
     158        if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) {
    157159                while (list_empty(&manager_list)) {
    158160                        futex_up(&fibril_futex);
     
    162164        }
    163165       
    164         srcf = __tcb_get()->fibril_data;
     166        fibril_t *srcf = __tcb_get()->fibril_data;
    165167        if (stype != FIBRIL_FROM_DEAD) {
     168               
    166169                /* Save current state */
    167170                if (!context_save(&srcf->ctx)) {
    168171                        if (serialization_count)
    169172                                srcf->flags &= ~FIBRIL_SERIALIZED;
     173                       
    170174                        if (srcf->clean_after_me) {
    171175                                /*
     
    173177                                 * restored context here.
    174178                                 */
    175                                 void *stack = srcf->clean_after_me->stack; 
     179                                void *stack = srcf->clean_after_me->stack;
    176180                                if (stack) {
    177181                                        /*
     
    188192                                srcf->clean_after_me = NULL;
    189193                        }
     194                       
    190195                        return 1;       /* futex_up already done here */
    191196                }
    192 
     197               
    193198                /* Save myself to the correct run list */
    194199                if (stype == FIBRIL_PREEMPT)
     
    197202                        list_append(&srcf->link, &manager_list);
    198203                        threads_in_manager--;
    199                 } else {       
     204                } else {
    200205                        /*
    201206                         * If stype == FIBRIL_TO_MANAGER, don't put ourselves to
     
    207212       
    208213        /* Choose a new fibril to run */
    209         if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {
     214        fibril_t *dstf;
     215        if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) {
    210216                dstf = list_get_instance(manager_list.next, fibril_t, link);
    211217                if (serialization_count && stype == FIBRIL_TO_MANAGER) {
     
    214220                }
    215221                threads_in_manager++;
    216 
     222               
    217223                if (stype == FIBRIL_FROM_DEAD)
    218224                        dstf->clean_after_me = srcf;
     
    228234        }
    229235        list_remove(&dstf->link);
    230 
     236       
    231237        futex_up(&fibril_futex);
    232238        context_restore(&dstf->ctx);
    233239        /* not reached */
    234 
     240       
    235241ret_0:
    236242        futex_up(&fibril_futex);
  • uspace/lib/libc/generic/io/io.c

    rb86d436 r5cde90f  
    541541}
    542542
    543 int fseek(FILE *stream, long offset, int origin)
    544 {
    545         off_t rc = lseek(stream->fd, offset, origin);
    546         if (rc == (off_t) (-1)) {
    547                 /* errno has been set by lseek. */
     543int fseek(FILE *stream, off64_t offset, int whence)
     544{
     545        off64_t rc = lseek(stream->fd, offset, whence);
     546        if (rc == (off64_t) (-1)) {
     547                /* errno has been set by lseek64. */
    548548                return -1;
    549549        }
     
    554554}
    555555
    556 int ftell(FILE *stream)
    557 {
    558         off_t rc = lseek(stream->fd, 0, SEEK_CUR);
    559         if (rc == (off_t) (-1)) {
    560                 /* errno has been set by lseek. */
    561                 return -1;
    562         }
    563 
    564         return rc;
     556off64_t ftell(FILE *stream)
     557{
     558        return lseek(stream->fd, 0, SEEK_CUR);
    565559}
    566560
  • uspace/lib/libc/generic/ipc.c

    rb86d436 r5cde90f  
    728728    int *flags)
    729729{
    730         int res;
    731         sysarg_t tmp_flags;
    732         res = ipc_call_sync_3_2(phoneid, IPC_M_SHARE_IN, (ipcarg_t) dst,
     730        sysarg_t tmp_flags = 0;
     731        int res = ipc_call_sync_3_2(phoneid, IPC_M_SHARE_IN, (ipcarg_t) dst,
    733732            (ipcarg_t) size, arg, NULL, &tmp_flags);
     733       
    734734        if (flags)
    735735                *flags = tmp_flags;
     736       
    736737        return res;
    737738}
  • uspace/lib/libc/generic/malloc.c

    rb86d436 r5cde90f  
    164164{
    165165        if (size == 0)
     166                return false;
     167
     168        if ((heap_start + size < heap_start) || (heap_end + size < heap_end))
    166169                return false;
    167170       
  • uspace/lib/libc/generic/mman.c

    rb86d436 r5cde90f  
    3939
    4040void *mmap(void *start, size_t length, int prot, int flags, int fd,
    41     off_t offset)
     41    aoff64_t offset)
    4242{
    4343        if (!start)
  • uspace/lib/libc/generic/stacktrace.c

    rb86d436 r5cde90f  
    11/*
    22 * Copyright (c) 2009 Jakub Jermar
     3 * Copyright (c) 2010 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    3637#include <stdio.h>
    3738#include <sys/types.h>
     39#include <errno.h>
    3840
    39 void stack_trace_fp_pc(uintptr_t fp, uintptr_t pc)
     41static int stacktrace_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data);
     42
     43void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc)
    4044{
    41         while (frame_pointer_validate(fp)) {
     45        stacktrace_t st;
     46        uintptr_t nfp;
     47
     48        st.op_arg = NULL;
     49        st.read_uintptr = stacktrace_read_uintptr;
     50
     51        while (stacktrace_fp_valid(&st, fp)) {
    4252                printf("%p: %p()\n", fp, pc);
    43                 pc = return_address_get(fp);
    44                 fp = frame_pointer_prev(fp);
     53                (void) stacktrace_ra_get(&st, fp, &pc);
     54                (void) stacktrace_fp_prev(&st, fp, &nfp);
     55                fp = nfp;
    4556        }
    4657}
    4758
    48 void stack_trace(void)
     59void stacktrace_print(void)
    4960{
    50         stack_trace_fp_pc(frame_pointer_get(), program_counter_get());
     61        stacktrace_prepare();
     62        stacktrace_print_fp_pc(stacktrace_fp_get(), stacktrace_pc_get());
    5163        /*
    5264         * Prevent the tail call optimization of the previous call by
    5365         * making it a non-tail call.
    5466         */
    55         (void) frame_pointer_get();
     67        (void) stacktrace_fp_get();
     68}
     69
     70static int stacktrace_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data)
     71{
     72        (void) arg;
     73        *data = *((uintptr_t *) addr);
     74        return EOK;
    5675}
    5776
  • uspace/lib/libc/generic/udebug.c

    rb86d436 r5cde90f  
    6969}
    7070
     71int udebug_name_read(int phoneid, void *buffer, size_t n,
     72        size_t *copied, size_t *needed)
     73{
     74        ipcarg_t a_copied, a_needed;
     75        int rc;
     76
     77        rc = async_req_3_3(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_NAME_READ,
     78                (sysarg_t)buffer, n, NULL, &a_copied, &a_needed);
     79
     80        *copied = (size_t)a_copied;
     81        *needed = (size_t)a_needed;
     82
     83        return rc;
     84}
     85
     86int udebug_areas_read(int phoneid, void *buffer, size_t n,
     87        size_t *copied, size_t *needed)
     88{
     89        ipcarg_t a_copied, a_needed;
     90        int rc;
     91
     92        rc = async_req_3_3(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_AREAS_READ,
     93                (sysarg_t)buffer, n, NULL, &a_copied, &a_needed);
     94
     95        *copied = (size_t)a_copied;
     96        *needed = (size_t)a_needed;
     97
     98        return rc;
     99}
     100
    71101int udebug_mem_read(int phoneid, void *buffer, uintptr_t addr, size_t n)
    72102{
     
    78108{
    79109        return async_req_3_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_ARGS_READ,
     110            tid, (sysarg_t)buffer);
     111}
     112
     113int udebug_regs_read(int phoneid, thash_t tid, void *buffer)
     114{
     115        return async_req_3_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_REGS_READ,
    80116            tid, (sysarg_t)buffer);
    81117}
  • uspace/lib/libc/generic/vfs/vfs.c

    rb86d436 r5cde90f  
    3535#include <vfs/vfs.h>
    3636#include <vfs/canonify.h>
     37#include <macros.h>
    3738#include <stdlib.h>
    3839#include <unistd.h>
     
    120121    const char *opts, unsigned int flags)
    121122{
    122         int res;
     123        int null_id = -1;
     124        char null[DEVMAP_NAME_MAXLEN];
     125       
     126        if (str_cmp(fqdn, "") == 0) {
     127                /* No device specified, create a fresh
     128                   null/%d device instead */
     129                null_id = devmap_null_create();
     130               
     131                if (null_id == -1)
     132                        return ENOMEM;
     133               
     134                snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id);
     135                fqdn = null;
     136        }
     137       
     138        dev_handle_t dev_handle;
     139        int res = devmap_device_get_handle(fqdn, &dev_handle, flags);
     140        if (res != EOK) {
     141                if (null_id != -1)
     142                        devmap_null_destroy(null_id);
     143               
     144                return res;
     145        }
     146       
     147        size_t mpa_size;
     148        char *mpa = absolutize(mp, &mpa_size);
     149        if (!mpa) {
     150                if (null_id != -1)
     151                        devmap_null_destroy(null_id);
     152               
     153                return ENOMEM;
     154        }
     155       
     156        futex_down(&vfs_phone_futex);
     157        async_serialize_start();
     158        vfs_connect();
     159       
     160        ipcarg_t rc_orig;
     161        aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
     162        ipcarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
     163        if (rc != EOK) {
     164                async_wait_for(req, &rc_orig);
     165                async_serialize_end();
     166                futex_up(&vfs_phone_futex);
     167                free(mpa);
     168               
     169                if (null_id != -1)
     170                        devmap_null_destroy(null_id);
     171               
     172                if (rc_orig == EOK)
     173                        return (int) rc;
     174                else
     175                        return (int) rc_orig;
     176        }
     177       
     178        rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts));
     179        if (rc != EOK) {
     180                async_wait_for(req, &rc_orig);
     181                async_serialize_end();
     182                futex_up(&vfs_phone_futex);
     183                free(mpa);
     184               
     185                if (null_id != -1)
     186                        devmap_null_destroy(null_id);
     187               
     188                if (rc_orig == EOK)
     189                        return (int) rc;
     190                else
     191                        return (int) rc_orig;
     192        }
     193       
     194        rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
     195        if (rc != EOK) {
     196                async_wait_for(req, &rc_orig);
     197                async_serialize_end();
     198                futex_up(&vfs_phone_futex);
     199                free(mpa);
     200               
     201                if (null_id != -1)
     202                        devmap_null_destroy(null_id);
     203               
     204                if (rc_orig == EOK)
     205                        return (int) rc;
     206                else
     207                        return (int) rc_orig;
     208        }
     209       
     210        /* Ask VFS whether it likes fs_name. */
     211        rc = async_req_0_0(vfs_phone, IPC_M_PING);
     212        if (rc != EOK) {
     213                async_wait_for(req, &rc_orig);
     214                async_serialize_end();
     215                futex_up(&vfs_phone_futex);
     216                free(mpa);
     217               
     218                if (null_id != -1)
     219                        devmap_null_destroy(null_id);
     220               
     221                if (rc_orig == EOK)
     222                        return (int) rc;
     223                else
     224                        return (int) rc_orig;
     225        }
     226       
     227        async_wait_for(req, &rc);
     228        async_serialize_end();
     229        futex_up(&vfs_phone_futex);
     230        free(mpa);
     231       
     232        if ((rc != EOK) && (null_id != -1))
     233                devmap_null_destroy(null_id);
     234       
     235        return (int) rc;
     236}
     237
     238int unmount(const char *mp)
     239{
    123240        ipcarg_t rc;
    124241        ipcarg_t rc_orig;
    125242        aid_t req;
    126         dev_handle_t dev_handle;
    127        
    128         res = devmap_device_get_handle(fqdn, &dev_handle, flags);
    129         if (res != EOK)
    130                 return res;
    131        
    132243        size_t mpa_size;
    133         char *mpa = absolutize(mp, &mpa_size);
     244        char *mpa;
     245       
     246        mpa = absolutize(mp, &mpa_size);
    134247        if (!mpa)
    135248                return ENOMEM;
     
    139252        vfs_connect();
    140253       
    141         req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
     254        req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL);
    142255        rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    143256        if (rc != EOK) {
     
    152265        }
    153266       
    154         rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts));
    155         if (rc != EOK) {
    156                 async_wait_for(req, &rc_orig);
    157                 async_serialize_end();
    158                 futex_up(&vfs_phone_futex);
    159                 free(mpa);
    160                 if (rc_orig == EOK)
    161                         return (int) rc;
    162                 else
    163                         return (int) rc_orig;
    164         }
    165 
    166         rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
    167         if (rc != EOK) {
    168                 async_wait_for(req, &rc_orig);
    169                 async_serialize_end();
    170                 futex_up(&vfs_phone_futex);
    171                 free(mpa);
    172                 if (rc_orig == EOK)
    173                         return (int) rc;
    174                 else
    175                         return (int) rc_orig;
    176         }
    177 
    178         /* Ask VFS whether it likes fs_name. */
    179         rc = async_req_0_0(vfs_phone, IPC_M_PING);
    180         if (rc != EOK) {
    181                 async_wait_for(req, &rc_orig);
    182                 async_serialize_end();
    183                 futex_up(&vfs_phone_futex);
    184                 free(mpa);
    185                 if (rc_orig == EOK)
    186                         return (int) rc;
    187                 else
    188                         return (int) rc_orig;
    189         }
    190        
     267
    191268        async_wait_for(req, &rc);
    192269        async_serialize_end();
     
    358435}
    359436
    360 off_t lseek(int fildes, off_t offset, int whence)
    361 {
    362         ipcarg_t rc;
    363 
    364         futex_down(&vfs_phone_futex);
    365         async_serialize_start();
    366         vfs_connect();
    367        
    368         ipcarg_t newoffs;
    369         rc = async_req_3_1(vfs_phone, VFS_IN_SEEK, fildes, offset, whence,
    370             &newoffs);
    371 
    372         async_serialize_end();
    373         futex_up(&vfs_phone_futex);
    374 
     437off64_t lseek(int fildes, off64_t offset, int whence)
     438{
     439        futex_down(&vfs_phone_futex);
     440        async_serialize_start();
     441        vfs_connect();
     442       
     443        ipcarg_t newoff_lo;
     444        ipcarg_t newoff_hi;
     445        ipcarg_t rc = async_req_4_2(vfs_phone, VFS_IN_SEEK, fildes,
     446            LOWER32(offset), UPPER32(offset), whence,
     447            &newoff_lo, &newoff_hi);
     448       
     449        async_serialize_end();
     450        futex_up(&vfs_phone_futex);
     451       
    375452        if (rc != EOK)
    376                 return (off_t) -1;
    377        
    378         return (off_t) newoffs;
    379 }
    380 
    381 int ftruncate(int fildes, off_t length)
    382 {
    383         ipcarg_t rc;
    384        
    385         futex_down(&vfs_phone_futex);
    386         async_serialize_start();
    387         vfs_connect();
    388        
    389         rc = async_req_2_0(vfs_phone, VFS_IN_TRUNCATE, fildes, length);
    390         async_serialize_end();
    391         futex_up(&vfs_phone_futex);
     453                return (off64_t) -1;
     454       
     455        return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi);
     456}
     457
     458int ftruncate(int fildes, aoff64_t length)
     459{
     460        ipcarg_t rc;
     461       
     462        futex_down(&vfs_phone_futex);
     463        async_serialize_start();
     464        vfs_connect();
     465       
     466        rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes,
     467            LOWER32(length), UPPER32(length));
     468        async_serialize_end();
     469        futex_up(&vfs_phone_futex);
     470       
    392471        return (int) rc;
    393472}
     
    403482       
    404483        req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL);
    405         rc = async_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat));
     484        rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat));
    406485        if (rc != EOK) {
    407486                ipcarg_t rc_orig;
     
    477556        if (!abs) {
    478557                free(dirp);
    479                 return ENOMEM;
     558                return NULL;
    480559        }
    481560       
  • uspace/lib/libc/include/adt/hash_table.h

    rb86d436 r5cde90f  
    8888extern void hash_table_remove(hash_table_t *, unsigned long [], hash_count_t);
    8989extern void hash_table_destroy(hash_table_t *);
     90extern void hash_table_apply(hash_table_t *, void (*)(link_t *, void *),
     91    void *);
    9092
    9193#endif
  • uspace/lib/libc/include/async.h

    rb86d436 r5cde90f  
    277277extern int async_share_out_receive(ipc_callid_t *, size_t *, int *);
    278278extern int async_share_out_finalize(ipc_callid_t, void *);
     279
     280/*
     281 * User-friendly wrappers for async_data_read_forward_fast().
     282 */
     283#define async_data_read_forward_0_0(phoneid, method, answer) \
     284        async_data_read_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL)
     285#define async_data_read_forward_0_1(phoneid, method, answer) \
     286        async_data_read_forward_fast((phoneid), (method), 0, 0, 0, 0, (answer))
     287#define async_data_read_forward_1_0(phoneid, method, arg1, answer) \
     288        async_data_read_forward_fast((phoneid), (method), (arg1), 0, 0, 0, NULL)
     289#define async_data_read_forward_1_1(phoneid, method, arg1, answer) \
     290        async_data_read_forward_fast((phoneid), (method), (arg1), 0, 0, 0, (answer))
     291#define async_data_read_forward_2_0(phoneid, method, arg1, arg2, answer) \
     292        async_data_read_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, NULL)
     293#define async_data_read_forward_2_1(phoneid, method, arg1, arg2, answer) \
     294        async_data_read_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
     295            (answer))
     296#define async_data_read_forward_3_0(phoneid, method, arg1, arg2, arg3, answer) \
     297        async_data_read_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \
     298            NULL)
     299#define async_data_read_forward_3_1(phoneid, method, arg1, arg2, arg3, answer) \
     300        async_data_read_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \
     301            (answer))
     302#define async_data_read_forward_4_0(phoneid, method, arg1, arg2, arg3, arg4, answer) \
     303        async_data_read_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     304            (arg4), NULL)
     305#define async_data_read_forward_4_1(phoneid, method, arg1, arg2, arg3, arg4, answer) \
     306        async_data_read_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     307            (arg4), (answer))
     308
    279309extern int async_data_read_start(int, void *, size_t);
    280310extern int async_data_read_receive(ipc_callid_t *, size_t *);
    281311extern int async_data_read_finalize(ipc_callid_t, const void *, size_t);
     312
     313extern int async_data_read_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t,
     314    ipcarg_t, ipcarg_t, ipc_call_t *);
     315
     316/*
     317 * User-friendly wrappers for async_data_write_forward_fast().
     318 */
     319#define async_data_write_forward_0_0(phoneid, method, answer) \
     320        async_data_write_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL)
     321#define async_data_write_forward_0_1(phoneid, method, answer) \
     322        async_data_write_forward_fast((phoneid), (method), 0, 0, 0, 0, (answer))
     323#define async_data_write_forward_1_0(phoneid, method, arg1, answer) \
     324        async_data_write_forward_fast((phoneid), (method), (arg1), 0, 0, 0, NULL)
     325#define async_data_write_forward_1_1(phoneid, method, arg1, answer) \
     326        async_data_write_forward_fast((phoneid), (method), (arg1), 0, 0, 0, \
     327            (answer))
     328#define async_data_write_forward_2_0(phoneid, method, arg1, arg2, answer) \
     329        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
     330            NULL)
     331#define async_data_write_forward_2_1(phoneid, method, arg1, arg2, answer) \
     332        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
     333            (answer))
     334#define async_data_write_forward_3_0(phoneid, method, arg1, arg2, arg3, answer) \
     335        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     336            0, NULL)
     337#define async_data_write_forward_3_1(phoneid, method, arg1, arg2, arg3, answer) \
     338        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     339            0, (answer))
     340#define async_data_write_forward_4_0(phoneid, method, arg1, arg2, arg3, arg4, answer) \
     341        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     342            (arg4), NULL)
     343#define async_data_write_forward_4_1(phoneid, method, arg1, arg2, arg3, arg4, answer) \
     344        async_data_write_forward_fast((phoneid), (method), (arg1), (arg2), (arg3), \
     345            (arg4), (answer))
     346
    282347extern int async_data_write_start(int, const void *, size_t);
    283348extern int async_data_write_receive(ipc_callid_t *, size_t *);
    284349extern int async_data_write_finalize(ipc_callid_t, void *, size_t);
    285350
    286 extern int async_data_blob_receive(char **, const size_t, size_t *);
    287 extern int async_data_string_receive(char **, const size_t);
     351extern int async_data_write_accept(void **, const bool, const size_t,
     352    const size_t, const size_t, size_t *);
     353extern void async_data_write_void(const int);
     354
     355extern int async_data_write_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t,
     356    ipcarg_t, ipcarg_t, ipc_call_t *);
    288357
    289358#endif
  • uspace/lib/libc/include/fibril.h

    rb86d436 r5cde90f  
    4040#include <libarch/tls.h>
    4141
    42 #ifndef context_set
    43 #define context_set(c, _pc, stack, size, ptls) \
     42#define context_set_generic(c, _pc, stack, size, ptls) \
    4443        (c)->pc = (sysarg_t) (_pc); \
    4544        (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
    4645        (c)->tls = (sysarg_t) (ptls);
    47 #endif /* context_set */
    4846
    49 #define FIBRIL_SERIALIZED       1
    50 #define FIBRIL_WRITER           2
     47#define FIBRIL_SERIALIZED  1
     48#define FIBRIL_WRITER      2
    5149
    5250typedef enum {
     
    5957typedef sysarg_t fid_t;
    6058
    61 struct fibril {
     59typedef struct fibril {
    6260        link_t link;
    6361        context_t ctx;
     
    7068        int retval;
    7169        int flags;
    72 };
    73 typedef struct fibril fibril_t;
     70} fibril_t;
    7471
    7572/** Fibril-local variable specifier */
    7673#define fibril_local __thread
    7774
    78 extern int context_save(context_t *c) __attribute__ ((returns_twice));
    79 extern void context_restore(context_t *c) __attribute__ ((noreturn));
     75extern int context_save(context_t *ctx) __attribute__((returns_twice));
     76extern void context_restore(context_t *ctx) __attribute__((noreturn));
    8077
    8178extern fid_t fibril_create(int (*func)(void *), void *arg);
     
    9087extern void fibril_dec_sercount(void);
    9188
    92 static inline int fibril_yield(void) {
     89static inline int fibril_yield(void)
     90{
    9391        return fibril_switch(FIBRIL_PREEMPT);
    9492}
  • uspace/lib/libc/include/ipc/clipboard.h

    rb86d436 r5cde90f  
    4646typedef enum {
    4747        CLIPBOARD_TAG_NONE,
    48         CLIPBOARD_TAG_BLOB
     48        CLIPBOARD_TAG_DATA
    4949} clipboard_tag_t;
    5050
  • uspace/lib/libc/include/ipc/vfs.h

    rb86d436 r5cde90f  
    8686        VFS_OUT_MOUNTED,
    8787        VFS_OUT_UNMOUNT,
     88        VFS_OUT_UNMOUNTED,
    8889        VFS_OUT_SYNC,
    8990        VFS_OUT_STAT,
     
    100101 * No lookup flags used.
    101102 */
    102 #define L_NONE  0
     103#define L_NONE                  0
    103104
    104105/**
     
    107108 * with L_DIRECTORY.
    108109 */
    109 #define L_FILE  1
     110#define L_FILE                  1
    110111
    111112/**
    112  * Lookup wil succeed only if the object is a directory. If L_CREATE is
     113 * Lookup will succeed only if the object is a directory. If L_CREATE is
    113114 * specified, an empty directory will be created. This flag is mutually
    114115 * exclusive with L_FILE.
    115116 */
    116 #define L_DIRECTORY  2
     117#define L_DIRECTORY             2
     118
     119/**
     120 * Lookup will succeed only if the object is a root directory. The flag is
     121 * mutually exclusive with L_FILE and L_MP.
     122 */
     123#define L_ROOT                  4
     124
     125/**
     126 * Lookup will succeed only if the object is a mount point. The flag is mutually
     127 * exclusive with L_FILE and L_ROOT.
     128 */
     129#define L_MP                    8
     130
    117131
    118132/**
     
    120134 * object already exists. L_EXCLUSIVE is implied when L_DIRECTORY is used.
    121135 */
    122 #define L_EXCLUSIVE  4
     136#define L_EXCLUSIVE             16
    123137
    124138/**
    125139 * L_CREATE is used for creating both regular files and directories.
    126140 */
    127 #define L_CREATE  8
     141#define L_CREATE                32
    128142
    129143/**
    130144 * L_LINK is used for linking to an already existing nodes.
    131145 */
    132 #define L_LINK  16
     146#define L_LINK                  64
    133147
    134148/**
     
    137151 * VFS_UNLINK.
    138152 */
    139 #define L_UNLINK  32
     153#define L_UNLINK                128
    140154
    141155/**
    142  * L_OPEN is used to indicate that the lookup operation is a part of VFS_OPEN
     156 * L_OPEN is used to indicate that the lookup operation is a part of VFS_IN_OPEN
    143157 * call from the client. This means that the server might allocate some
    144158 * resources for the opened file. This flag cannot be passed directly by the
    145159 * client.
    146160 */
    147 #define L_OPEN  64
     161#define L_OPEN                  256
    148162
    149163#endif
  • uspace/lib/libc/include/limits.h

    rb86d436 r5cde90f  
    4646
    4747#ifdef __CHAR_UNSIGNED__
    48 # define CHAR_MIN UCHAR_MIN
    49 # define CHAR_MAX UCHAR_MAX
     48        #define CHAR_MIN UCHAR_MIN
     49        #define CHAR_MAX UCHAR_MAX
    5050#else
    51 # define CHAR_MIN SCHAR_MIN
    52 # define CHAR_MAX SCHAR_MAX
     51        #define CHAR_MIN SCHAR_MIN
     52        #define CHAR_MAX SCHAR_MAX
    5353#endif
    5454
     
    5959#define USHRT_MAX MAX_UINT16
    6060
     61/* int */
    6162#define INT_MIN MIN_INT32
    6263#define INT_MAX MAX_INT32
     
    6465#define UINT_MAX MAX_UINT32
    6566
     67/* long long int */
    6668#define LLONG_MIN MIN_INT64
    6769#define LLONG_MAX MAX_INT64
     
    6971#define ULLONG_MAX MAX_UINT64
    7072
     73/* off64_t */
     74#define OFF64_MIN MIN_INT64
     75#define OFF64_MAX MAX_INT64
     76
     77/* aoff64_t */
     78#define AOFF64_MIN MIN_UINT64
     79#define AOFF64_MAX MAX_UINT64
     80
    7181#endif
    7282
  • uspace/lib/libc/include/macros.h

    rb86d436 r5cde90f  
    4848#define STRING_ARG(arg)  #arg
    4949
    50 #define LOWER32(arg)  ((arg) & 0xffffffff)
    51 #define UPPER32(arg)  (((arg) >> 32) & 0xffffffff)
     50#define LOWER32(arg)  (((uint64_t) (arg)) & 0xffffffff)
     51#define UPPER32(arg)  (((((uint64_t) arg)) >> 32) & 0xffffffff)
    5252
    5353#define MERGE_LOUP32(lo, up) \
  • uspace/lib/libc/include/stacktrace.h

    rb86d436 r5cde90f  
    11/*
    22 * Copyright (c) 2009 Jakub Jermar
     3 * Copyright (c) 2010 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    3940#include <bool.h>
    4041
    41 extern void stack_trace(void);
    42 extern void stack_trace_fp_pc(uintptr_t, uintptr_t);
     42typedef struct {
     43        void *op_arg;
     44        int (*read_uintptr)(void *, uintptr_t, uintptr_t *);
     45} stacktrace_t;
     46
     47extern void stacktrace_print(void);
     48extern void stacktrace_print_fp_pc(uintptr_t, uintptr_t);
    4349
    4450/*
    4551 * The following interface is to be implemented by each architecture.
    4652 */
    47 extern bool frame_pointer_validate(uintptr_t);
    48 extern uintptr_t frame_pointer_get(void);
    49 extern uintptr_t frame_pointer_prev(uintptr_t);
    50 extern uintptr_t return_address_get(uintptr_t);
    51 extern uintptr_t program_counter_get();
     53extern bool stacktrace_fp_valid(stacktrace_t *, uintptr_t);
     54extern int stacktrace_fp_prev(stacktrace_t *, uintptr_t, uintptr_t *);
     55extern int stacktrace_ra_get(stacktrace_t *, uintptr_t, uintptr_t *);
     56
     57extern void stacktrace_prepare(void);
     58extern uintptr_t stacktrace_fp_get(void);
     59extern uintptr_t stacktrace_pc_get();
    5260
    5361#endif
  • uspace/lib/libc/include/stdio.h

    rb86d436 r5cde90f  
    4646#define BUFSIZ  4096
    4747
    48 #define DEBUG(fmt, ...) \
     48#define DEBUG(fmt, ...)se\
    4949        { \
    5050                char _buf[256]; \
     
    5656#ifndef SEEK_SET
    5757        #define SEEK_SET  0
     58#endif
     59
     60#ifndef SEEK_CUR
    5861        #define SEEK_CUR  1
     62#endif
     63
     64#ifndef SEEK_END
    5965        #define SEEK_END  2
    6066#endif
     
    135141extern size_t fwrite(const void *, size_t, size_t, FILE *);
    136142
    137 extern int fseek(FILE *, long, int);
     143extern int fseek(FILE *, off64_t, int);
    138144extern void rewind(FILE *);
    139 extern int ftell(FILE *);
     145extern off64_t ftell(FILE *);
    140146extern int feof(FILE *);
    141147
  • uspace/lib/libc/include/stdlib.h

    rb86d436 r5cde90f  
    4242#define abort() \
    4343        do { \
    44                 stack_trace(); \
     44                stacktrace_print(); \
    4545                _exit(1); \
    4646        } while (0)
  • uspace/lib/libc/include/sys/mman.h

    rb86d436 r5cde90f  
    4141#define MAP_FAILED  ((void *) -1)
    4242
    43 #define MAP_SHARED       (1 << 0)
    44 #define MAP_PRIVATE      (1 << 1)
    45 #define MAP_FIXED        (1 << 2)
    46 #define MAP_ANONYMOUS    (1 << 3)
     43#define MAP_SHARED     (1 << 0)
     44#define MAP_PRIVATE    (1 << 1)
     45#define MAP_FIXED      (1 << 2)
     46#define MAP_ANONYMOUS  (1 << 3)
    4747
    4848#define PROTO_READ   AS_AREA_READ
     
    5050#define PROTO_EXEC   AS_AREA_EXEC
    5151
    52 extern void *mmap(void  *start, size_t length, int prot, int flags, int fd,
    53     off_t offset);
     52extern void *mmap(void *start, size_t length, int prot, int flags, int fd,
     53    aoff64_t offset);
    5454extern int munmap(void *start, size_t length);
    5555
  • uspace/lib/libc/include/sys/stat.h

    rb86d436 r5cde90f  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#ifndef LIBC_SYS_STAT_H_
     
    4848        bool is_file;
    4949        bool is_directory;
    50         off_t size;
     50        aoff64_t size;
    5151        dev_handle_t device;
    5252};
  • uspace/lib/libc/include/sys/time.h

    rb86d436 r5cde90f  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#ifndef LIBC_SYS_TIME_H_
     
    4444
    4545struct timeval {
    46         time_t         tv_sec;        /* seconds */
    47         suseconds_t    tv_usec;  /* microseconds */
     46        time_t tv_sec;        /* seconds */
     47        suseconds_t tv_usec;  /* microseconds */
    4848};
    4949
    5050struct timezone {
    51         int  tz_minuteswest; /* minutes W of Greenwich */
    52         int  tz_dsttime;     /* type of dst correction */
     51        int tz_minuteswest; /* minutes W of Greenwich */
     52        int tz_dsttime;      /* type of dst correction */
    5353};
    5454
  • uspace/lib/libc/include/sys/types.h

    rb86d436 r5cde90f  
    3838#include <libarch/types.h>
    3939
    40 typedef long off_t;
    41 typedef int mode_t;
    42 typedef uint64_t bn_t;  /**< Block number type. */
     40typedef unsigned int mode_t;
    4341
     42/** Relative offset */
     43typedef int64_t off64_t;
     44
     45/** Absolute offset */
     46typedef uint64_t aoff64_t;
     47
     48/** Unicode code point */
    4449typedef int32_t wchar_t;
    4550
  • uspace/lib/libc/include/udebug.h

    rb86d436 r5cde90f  
    4747int udebug_thread_read(int phoneid, void *buffer, size_t n,
    4848        size_t *copied, size_t *needed);
     49int udebug_name_read(int phoneid, void *buffer, size_t n,
     50        size_t *copied, size_t *needed);
     51int udebug_areas_read(int phoneid, void *buffer, size_t n,
     52        size_t *copied, size_t *needed);
    4953int udebug_mem_read(int phoneid, void *buffer, uintptr_t addr, size_t n);
    5054int udebug_args_read(int phoneid, thash_t tid, sysarg_t *buffer);
     55int udebug_regs_read(int phoneid, thash_t tid, void *buffer);
    5156int udebug_go(int phoneid, thash_t tid, udebug_event_t *ev_type,
    5257        sysarg_t *val0, sysarg_t *val1);
  • uspace/lib/libc/include/unistd.h

    rb86d436 r5cde90f  
    4747#ifndef SEEK_SET
    4848        #define SEEK_SET  0
     49#endif
     50
     51#ifndef SEEK_CUR
    4952        #define SEEK_CUR  1
     53#endif
     54
     55#ifndef SEEK_END
    5056        #define SEEK_END  2
    5157#endif
     
    5864extern ssize_t read(int, void *, size_t);
    5965
    60 extern off_t lseek(int, off_t, int);
    61 extern int ftruncate(int, off_t);
     66extern off64_t lseek(int, off64_t, int);
     67extern int ftruncate(int, aoff64_t);
    6268
    6369extern int close(int);
     
    6975extern int chdir(const char *);
    7076
    71 extern void _exit(int status) __attribute__ ((noreturn));
    72 extern int usleep(useconds_t uses);
    73 extern unsigned int sleep(unsigned int se);
     77extern void _exit(int) __attribute__((noreturn));
     78extern int usleep(useconds_t);
     79extern unsigned int sleep(unsigned int);
    7480
    7581#endif
  • uspace/lib/libc/include/vfs/vfs.h

    rb86d436 r5cde90f  
    5555extern int mount(const char *, const char *, const char *, const char *,
    5656    unsigned int);
     57extern int unmount(const char *);
    5758
    5859extern void __stdio_init(int filc, fdi_node_t *filv[]);
  • uspace/lib/libfs/libfs.c

    rb86d436 r5cde90f  
    3737#include "libfs.h"
    3838#include "../../srv/vfs/vfs.h"
     39#include <macros.h>
    3940#include <errno.h>
    4041#include <async.h>
     
    161162        /* Accept the phone */
    162163        callid = async_get_call(&call);
    163         int mountee_phone = (int)IPC_GET_ARG1(call);
     164        int mountee_phone = (int) IPC_GET_ARG1(call);
    164165        if ((IPC_GET_METHOD(call) != IPC_M_CONNECTION_CLONE) ||
    165166            (mountee_phone < 0)) {
     
    172173        ipc_answer_0(callid, EOK);
    173174       
    174         res = async_data_write_receive(&callid, NULL);
    175         if (!res) {
    176                 ipc_hangup(mountee_phone);
    177                 ipc_answer_0(callid, EINVAL);
    178                 ipc_answer_0(rid, EINVAL);
    179                 return;
    180         }
    181        
    182175        fs_node_t *fn;
    183176        res = ops->node_get(&fn, mp_dev_handle, mp_fs_index);
    184177        if ((res != EOK) || (!fn)) {
    185178                ipc_hangup(mountee_phone);
    186                 ipc_answer_0(callid, combine_rc(res, ENOENT));
     179                async_data_write_void(combine_rc(res, ENOENT));
    187180                ipc_answer_0(rid, combine_rc(res, ENOENT));
    188181                return;
     
    192185                ipc_hangup(mountee_phone);
    193186                (void) ops->node_put(fn);
    194                 ipc_answer_0(callid, EBUSY);
     187                async_data_write_void(EBUSY);
    195188                ipc_answer_0(rid, EBUSY);
    196189                return;
     
    201194                ipc_hangup(mountee_phone);
    202195                (void) ops->node_put(fn);
    203                 ipc_answer_0(callid, rc);
     196                async_data_write_void(rc);
    204197                ipc_answer_0(rid, rc);
    205198                return;
     
    207200       
    208201        ipc_call_t answer;
    209         aid_t msg = async_send_1(mountee_phone, VFS_OUT_MOUNTED, mr_dev_handle,
    210             &answer);
    211         ipc_forward_fast(callid, mountee_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
    212         async_wait_for(msg, &rc);
     202        rc = async_data_write_forward_1_1(mountee_phone, VFS_OUT_MOUNTED,
     203            mr_dev_handle, &answer);
    213204       
    214205        if (rc == EOK) {
     
    224215        ipc_answer_3(rid, rc, IPC_GET_ARG1(answer), IPC_GET_ARG2(answer),
    225216            IPC_GET_ARG3(answer));
     217}
     218
     219void libfs_unmount(libfs_ops_t *ops, ipc_callid_t rid, ipc_call_t *request)
     220{
     221        dev_handle_t mp_dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);
     222        fs_index_t mp_fs_index = (fs_index_t) IPC_GET_ARG2(*request);
     223        fs_node_t *fn;
     224        int res;
     225
     226        res = ops->node_get(&fn, mp_dev_handle, mp_fs_index);
     227        if ((res != EOK) || (!fn)) {
     228                ipc_answer_0(rid, combine_rc(res, ENOENT));
     229                return;
     230        }
     231
     232        /*
     233         * We are clearly expecting to find the mount point active.
     234         */
     235        if (!fn->mp_data.mp_active) {
     236                (void) ops->node_put(fn);
     237                ipc_answer_0(rid, EINVAL);
     238                return;
     239        }
     240
     241        /*
     242         * Tell the mounted file system to unmount.
     243         */
     244        res = async_req_1_0(fn->mp_data.phone, VFS_OUT_UNMOUNTED,
     245            fn->mp_data.dev_handle);
     246
     247        /*
     248         * If everything went well, perform the clean-up on our side.
     249         */
     250        if (res == EOK) {
     251                ipc_hangup(fn->mp_data.phone);
     252                fn->mp_data.mp_active = false;
     253                fn->mp_data.fs_handle = 0;
     254                fn->mp_data.dev_handle = 0;
     255                fn->mp_data.phone = 0;
     256                /* Drop the reference created in libfs_mount(). */
     257                (void) ops->node_put(fn);
     258        }
     259
     260        (void) ops->node_put(fn);
     261        ipc_answer_0(rid, res);
    226262}
    227263
     
    304340                on_error(rc, goto out_with_answer);
    305341               
    306                 if ((tmp) && (tmp->mp_data.mp_active)) {
     342                /*
     343                 * If the matching component is a mount point, there are two
     344                 * legitimate semantics of the lookup operation. The first is
     345                 * the commonly used one in which the lookup crosses each mount
     346                 * point into the mounted file system. The second semantics is
     347                 * used mostly during unmount() and differs from the first one
     348                 * only in that the last mount point in the looked up path,
     349                 * which is also its last component, is not crossed.
     350                 */
     351
     352                if ((tmp) && (tmp->mp_data.mp_active) &&
     353                    (!(lflag & L_MP) || (next <= last))) {
    307354                        if (next > last)
    308355                                next = last = first;
     
    352399                                                ipc_answer_0(rid, rc);
    353400                                        } else {
    354                                                 ipc_answer_5(rid, EOK,
    355                                                     fs_handle, dev_handle,
     401                                                aoff64_t size = ops->size_get(fn);
     402                                                ipc_answer_5(rid, fs_handle,
     403                                                    dev_handle,
    356404                                                    ops->index_get(fn),
    357                                                     ops->size_get(fn),
     405                                                    LOWER32(size),
     406                                                    UPPER32(size),
    358407                                                    ops->lnkcnt_get(fn));
    359408                                                (void) ops->node_put(fn);
     
    432481                                        ipc_answer_0(rid, rc);
    433482                                } else {
    434                                         ipc_answer_5(rid, EOK,
    435                                             fs_handle, dev_handle,
     483                                        aoff64_t size = ops->size_get(fn);
     484                                        ipc_answer_5(rid, fs_handle,
     485                                            dev_handle,
    436486                                            ops->index_get(fn),
    437                                             ops->size_get(fn),
     487                                            LOWER32(size),
     488                                            UPPER32(size),
    438489                                            ops->lnkcnt_get(fn));
    439490                                        (void) ops->node_put(fn);
     
    455506                unsigned int old_lnkcnt = ops->lnkcnt_get(cur);
    456507                rc = ops->unlink(par, cur, component);
    457                 ipc_answer_5(rid, (ipcarg_t) rc, fs_handle, dev_handle,
    458                     ops->index_get(cur), ops->size_get(cur), old_lnkcnt);
     508               
     509                if (rc == EOK) {
     510                        aoff64_t size = ops->size_get(cur);
     511                        ipc_answer_5(rid, fs_handle, dev_handle,
     512                            ops->index_get(cur), LOWER32(size), UPPER32(size),
     513                            old_lnkcnt);
     514                } else
     515                        ipc_answer_0(rid, rc);
     516               
    459517                goto out;
    460518        }
     
    475533                goto out;
    476534        }
     535
     536        if ((lflag & L_ROOT) && par) {
     537                ipc_answer_0(rid, EINVAL);
     538                goto out;
     539        }
    477540       
    478541out_with_answer:
     
    482545                        rc = ops->node_open(cur);
    483546               
    484                 ipc_answer_5(rid, rc, fs_handle, dev_handle,
    485                     ops->index_get(cur), ops->size_get(cur),
    486                     ops->lnkcnt_get(cur));
     547                if (rc == EOK) {
     548                        aoff64_t size = ops->size_get(cur);
     549                        ipc_answer_5(rid, fs_handle, dev_handle,
     550                            ops->index_get(cur), LOWER32(size), UPPER32(size),
     551                            ops->lnkcnt_get(cur));
     552                } else
     553                        ipc_answer_0(rid, rc);
     554               
    487555        } else
    488556                ipc_answer_0(rid, rc);
     
    551619        dev_handle_t dev_handle = IPC_GET_ARG1(*request);
    552620        fs_index_t index = IPC_GET_ARG2(*request);
     621       
    553622        fs_node_t *fn;
    554         int rc;
    555        
    556         rc = ops->node_get(&fn, dev_handle, index);
     623        int rc = ops->node_get(&fn, dev_handle, index);
    557624        on_error(rc, answer_and_return(rid, rc));
    558625       
     
    563630       
    564631        rc = ops->node_open(fn);
    565         ipc_answer_3(rid, rc, ops->size_get(fn), ops->lnkcnt_get(fn),
     632        aoff64_t size = ops->size_get(fn);
     633        ipc_answer_4(rid, rc, LOWER32(size), UPPER32(size), ops->lnkcnt_get(fn),
    566634            (ops->is_file(fn) ? L_FILE : 0) | (ops->is_directory(fn) ? L_DIRECTORY : 0));
    567635       
  • uspace/lib/libfs/libfs.h

    rb86d436 r5cde90f  
    7676         */
    7777        fs_index_t (* index_get)(fs_node_t *);
    78         size_t (* size_get)(fs_node_t *);
     78        aoff64_t (* size_get)(fs_node_t *);
    7979        unsigned int (* lnkcnt_get)(fs_node_t *);
    8080        char (* plb_get_char)(unsigned pos);
     
    9595
    9696extern void libfs_mount(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *);
     97extern void libfs_unmount(libfs_ops_t *, ipc_callid_t, ipc_call_t *);
    9798extern void libfs_lookup(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *);
    9899extern void libfs_stat(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *);
Note: See TracChangeset for help on using the changeset viewer.