Changes in / [d42976c:393bef1] in mainline


Ignore:
Files:
3 added
2 deleted
45 edited

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    rd42976c r393bef1  
    310310
    311311% Support for SMP
    312 ! [(PLATFORM=ia32&PROCESSOR!=athlon_xp)|PLATFORM=amd64|PLATFORM=sparc64|PLATFORM=ia64|(PLATFORM=mips32&MACHINE=msim)|PLATFORM=abs32le] CONFIG_SMP (y/n)
     312! [(PLATFORM=ia32&PROCESSOR!=athlon_xp)|PLATFORM=amd64|PLATFORM=sparc64|PLATFORM=ia64|(PLATFORM=mips32&MACHINE=msim)] CONFIG_SMP (y/n)
    313313
    314314% Debug build
  • defaults/special/Makefile.config

    rd42976c r393bef1  
    44# Compiler
    55COMPILER = gcc_native
    6 
    7 # Support for SMP
    8 CONFIG_SMP = y
    96
    107# Debug build
  • kernel/arch/abs32le/Makefile.inc

    rd42976c r393bef1  
    4141        arch/$(KARCH)/src/userspace.c \
    4242        arch/$(KARCH)/src/cpu/cpu.c \
    43         arch/$(KARCH)/src/ddi/ddi.c \
    44         arch/$(KARCH)/src/smp/smp.c \
    4543        arch/$(KARCH)/src/mm/as.c \
    4644        arch/$(KARCH)/src/mm/frame.c \
  • kernel/arch/abs32le/include/asm.h

    rd42976c r393bef1  
    4949
    5050
    51 static inline __attribute__((noreturn)) void cpu_halt(void)
     51static inline void cpu_halt(void)
    5252{
    5353        /* On real hardware this should stop processing further
  • kernel/arch/abs32le/include/context.h

    rd42976c r393bef1  
    3636#define KERN_abs32le_CONTEXT_H_
    3737
     38#ifdef KERNEL
     39#include <arch/types.h>
     40
    3841#define STACK_ITEM_SIZE  4
    3942#define SP_DELTA         0
    4043
    41 #define context_set(ctx, pc, stack, size) \
    42     context_set_generic(ctx, pc, stack, size)
     44#define context_set(c, _pc, stack, size) \
     45        do { \
     46                (c)->pc = (uintptr_t) (_pc); \
     47        } while (0)
     48
     49#endif /* KERNEL */
    4350
    4451/*
  • kernel/arch/abs32le/include/interrupt.h

    rd42976c r393bef1  
    4040#define IVT_ITEMS  0
    4141#define IVT_FIRST  0
    42 
    43 #define VECTOR_TLB_SHOOTDOWN_IPI  0
    4442
    4543/*
  • kernel/arch/abs32le/src/abs32le.c

    rd42976c r393bef1  
    3939#include <arch/asm.h>
    4040
    41 #include <func.h>
    4241#include <config.h>
    43 #include <context.h>
    4442#include <interrupt.h>
    4543#include <ddi/irq.h>
     
    109107}
    110108
    111 void memsetb(void *dst, size_t cnt, uint8_t val)
    112 {
    113         _memsetb(dst, cnt, val);
    114 }
    115 
    116 void memsetw(void *dst, size_t cnt, uint16_t val)
    117 {
    118         _memsetw(dst, cnt, val);
    119 }
    120 
    121 void panic_printf(char *fmt, ...)
    122 {
    123         va_list args;
    124        
    125         va_start(args, fmt);
    126         vprintf(fmt, args);
    127         va_end(args);
    128        
    129         halt();
    130 }
    131 
    132 int context_save_arch(context_t *ctx)
    133 {
    134         return 1;
    135 }
    136 
    137 void context_restore_arch(context_t *ctx)
    138 {
    139         while (true);
    140 }
    141 
    142109/** @}
    143110 */
  • kernel/arch/abs32le/src/debug/stacktrace.c

    rd42976c r393bef1  
    2727 */
    2828
    29 /** @addtogroup abs32le
     29/** @addtogroup ia32
    3030 * @{
    3131 */
     
    3838#include <typedefs.h>
    3939
     40#define FRAME_OFFSET_FP_PREV    0
     41#define FRAME_OFFSET_RA         1
     42
    4043bool kernel_frame_pointer_validate(uintptr_t fp)
    4144{
    42         return true;;
     45        return fp != 0;
    4346}
    4447
    4548bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
    4649{
     50        uint32_t *stack = (void *) fp;
     51        *prev = stack[FRAME_OFFSET_FP_PREV];
    4752        return true;
    4853}
     
    5055bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
    5156{
     57        uint32_t *stack = (void *) fp;
     58        *ra = stack[FRAME_OFFSET_RA];
    5259        return true;
    5360}
     
    5562bool uspace_frame_pointer_validate(uintptr_t fp)
    5663{
    57         return true;
     64        return fp != 0;
    5865}
    5966
    6067bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
    6168{
    62         return true;
     69        return !copy_from_uspace((void *) prev,
     70            (uint32_t *) fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));
    6371}
    6472
    6573bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
    6674{
    67         return true;
    68 }
    69 
    70 uintptr_t frame_pointer_get(void)
    71 {
    72         return 0;
    73 }
    74 
    75 uintptr_t program_counter_get(void)
    76 {
    77         return 0;
     75        return !copy_from_uspace((void *) ra, (uint32_t *) fp + FRAME_OFFSET_RA,
     76            sizeof(*ra));
    7877}
    7978
  • kernel/arch/amd64/include/asm.h

    rd42976c r393bef1  
    6868}
    6969
    70 static inline void __attribute__((noreturn)) cpu_halt(void)
    71 {
    72         while (true) {
    73                 asm volatile (
    74                         "hlt\n"
    75                 );
    76         }
     70static inline void cpu_halt(void)
     71{
     72        asm volatile (
     73                "0:\n"
     74                "       hlt\n"
     75                "       jmp 0b\n"
     76        );
    7777}
    7878
  • kernel/arch/arm32/include/asm.h

    rd42976c r393bef1  
    9696}
    9797
    98 extern void cpu_halt(void) __attribute__((noreturn));
     98extern void cpu_halt(void);
    9999extern void asm_delay_loop(uint32_t t);
    100100extern void userspace_asm(uintptr_t ustack, uintptr_t uspace_uarg,
  • kernel/arch/arm32/src/arm32.c

    rd42976c r393bef1  
    155155void cpu_halt(void)
    156156{
    157         while (true)
    158                 machine_cpu_halt();
     157        machine_cpu_halt();
    159158}
    160159
     
    163162{
    164163        /* not implemented */
    165         while (true);
     164        while (1);
    166165}
    167166
  • kernel/arch/ia32/include/asm.h

    rd42976c r393bef1  
    6060 *
    6161 */
    62 static inline __attribute__((noreturn)) void cpu_halt(void)
    63 {
    64         while (true) {
    65                 asm volatile (
    66                         "hlt\n"
    67                 );
    68         }
     62static inline void cpu_halt(void)
     63{
     64        asm volatile (
     65                "0:\n"
     66                "       hlt\n"
     67                "       jmp 0b\n"
     68        );
    6969}
    7070
  • kernel/arch/ia64/include/asm.h

    rd42976c r393bef1  
    428428}
    429429
    430 extern void cpu_halt(void) __attribute__((noreturn));
     430extern void cpu_halt(void);
    431431extern void cpu_sleep(void);
    432432extern void asm_delay_loop(uint32_t t);
  • kernel/arch/ia64/include/context.h

    rd42976c r393bef1  
    4848 */
    4949#define SP_DELTA        (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     50
     51#ifdef context_set
     52#undef context_set
     53#endif
    5054
    5155/* RSE stack starts at the bottom of memory stack. */
  • kernel/arch/mips32/include/asm.h

    rd42976c r393bef1  
    6666}
    6767
    68 extern void cpu_halt(void) __attribute__((noreturn));
     68extern void cpu_halt(void);
    6969extern void asm_delay_loop(uint32_t t);
    7070extern void userspace_asm(uintptr_t ustack, uintptr_t uspace_uarg,
  • kernel/arch/mips32/include/context.h

    rd42976c r393bef1  
    2727 */
    2828
    29 /** @addtogroup mips32
     29/** @addtogroup mips32 
    3030 * @{
    3131 */
     
    4242 * Put one item onto the stack to support get_stack_base() and align it up.
    4343 */
    44 #define SP_DELTA  (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     44#define SP_DELTA        (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     45
    4546
    4647#ifndef __ASM__
    4748
    4849#include <arch/types.h>
    49 
    50 #define context_set(ctx, pc, stack, size) \
    51     context_set_generic(ctx, pc, stack, size)
    5250
    5351/*
  • kernel/arch/ppc32/include/asm.h

    rd42976c r393bef1  
    2727 */
    2828
    29 /** @addtogroup ppc32
     29/** @addtogroup ppc32   
    3030 * @{
    3131 */
     
    146146}
    147147
    148 extern void cpu_halt(void) __attribute__((noreturn));
    149 extern void asm_delay_loop(uint32_t t);
     148void cpu_halt(void);
     149void asm_delay_loop(uint32_t t);
     150
    150151extern void userspace_asm(uintptr_t uspace_uarg, uintptr_t stack, uintptr_t entry);
    151152
    152153static inline void pio_write_8(ioport8_t *port, uint8_t v)
    153154{
    154         *port = v;
     155        *port = v;     
    155156}
    156157
    157158static inline void pio_write_16(ioport16_t *port, uint16_t v)
    158159{
    159         *port = v;
     160        *port = v;     
    160161}
    161162
    162163static inline void pio_write_32(ioport32_t *port, uint32_t v)
    163164{
    164         *port = v;
     165        *port = v;     
    165166}
    166167
    167168static inline uint8_t pio_read_8(ioport8_t *port)
    168169{
    169         return *port;
     170        return *port; 
    170171}
    171172
    172173static inline uint16_t pio_read_16(ioport16_t *port)
    173174{
    174         return *port;
     175        return *port; 
    175176}
    176177
    177178static inline uint32_t pio_read_32(ioport32_t *port)
    178179{
    179         return *port;
     180        return *port; 
    180181}
    181182
  • kernel/arch/ppc32/include/context.h

    rd42976c r393bef1  
    2727 */
    2828
    29 /** @addtogroup ppc32
     29/** @addtogroup ppc32   
    3030 * @{
    3131 */
     
    3838#include <arch/types.h>
    3939
    40 #define SP_DELTA  16
    41 
    42 #define context_set(ctx, pc, stack, size) \
    43     context_set_generic(ctx, pc, stack, size)
     40#define SP_DELTA        16
    4441
    4542typedef struct {
     
    7168       
    7269        ipl_t ipl;
    73 } __attribute__((packed)) context_t;
     70} __attribute__ ((packed)) context_t;
    7471
    7572#endif
  • kernel/arch/sparc64/include/asm.h

    rd42976c r393bef1  
    430430}
    431431
    432 extern void cpu_halt(void) __attribute__((noreturn));
     432extern void cpu_halt(void);
    433433extern void cpu_sleep(void);
    434434extern void asm_delay_loop(const uint32_t usec);
  • kernel/arch/sparc64/include/context.h

    rd42976c r393bef1  
    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
    4448#define context_set(c, _pc, stack, size)                        \
    4549        (c)->pc = ((uintptr_t) _pc) - 8;                        \
  • kernel/generic/include/context.h

    rd42976c r393bef1  
    2727 */
    2828
    29 /** @addtogroup generic
     29/** @addtogroup generic 
    3030 * @{
    3131 */
     
    3939#include <arch/context.h>
    4040
    41 #define context_set_generic(ctx, _pc, stack, size) \
    42         (ctx)->pc = (uintptr_t) (_pc); \
    43         (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA;
    4441
    45 extern int context_save_arch(context_t *ctx) __attribute__((returns_twice));
    46 extern void context_restore_arch(context_t *ctx) __attribute__((noreturn));
     42#ifndef context_set
     43#define context_set(c, _pc, stack, size)        \
     44        (c)->pc = (uintptr_t) (_pc);            \
     45        (c)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA;
     46#endif /* context_set */
     47
     48extern int context_save_arch(context_t *c) __attribute__ ((returns_twice));
     49extern void context_restore_arch(context_t *c) __attribute__ ((noreturn));
    4750
    4851/** Save register context.
     
    7073 * saved like that would therefore lead to a disaster.
    7174 *
    72  * @param ctx Context structure.
     75 * @param c             Context structure.
    7376 *
    74  * @return context_save() returns 1, context_restore() returns 0.
    75  *
     77 * @return              context_save() returns 1, context_restore() returns 0.
    7678 */
    77 #define context_save(ctx)  context_save_arch(ctx)
     79#define context_save(c)   context_save_arch(c)
    7880
    7981/** Restore register context.
     
    8688 * being return value.
    8789 *
    88  * @param ctx Context structure.
     90 * @param c             Context structure.
    8991 */
    90 static inline void context_restore(context_t *ctx)
     92static inline void context_restore(context_t *c)
    9193{
    92         context_restore_arch(ctx);
     94        context_restore_arch(c);
    9395}
    9496
  • kernel/generic/include/func.h

    rd42976c r393bef1  
    4141extern atomic_t haltstate;
    4242
    43 extern void halt(void) __attribute__((noreturn));
     43extern void halt(void);
    4444extern unative_t atoi(const char *text);
    4545extern void order(const uint64_t val, uint64_t *rv, char *suffix);
  • kernel/generic/include/stacktrace.h

    rd42976c r393bef1  
    6060 */
    6161extern uintptr_t frame_pointer_get(void);
    62 extern uintptr_t program_counter_get(void);
     62extern uintptr_t program_counter_get();
    6363
    6464extern bool kernel_frame_pointer_validate(uintptr_t);
  • tools/toolchain.sh

    rd42976c r393bef1  
    142142       
    143143        BINUTILS_VERSION="2.20"
    144         GCC_VERSION="4.4.3"
     144        GCC_VERSION="4.4.2"
    145145       
    146146        BINUTILS="binutils-${BINUTILS_VERSION}.tar.bz2"
     
    165165        echo ">>> Downloading tarballs"
    166166        download_check "${BINUTILS_SOURCE}" "${BINUTILS}" "ee2d3e996e9a2d669808713360fa96f8"
    167         download_check "${GCC_SOURCE}" "${GCC_CORE}" "054b66f315b3d04ad06544ce26e72365"
    168         download_check "${GCC_SOURCE}" "${GCC_OBJC}" "34711c4de46eaf79aa018206dbec4389"
    169         download_check "${GCC_SOURCE}" "${GCC_CPP}" "cd179ec4f05ee17ce76464da25a2674c"
     167        download_check "${GCC_SOURCE}" "${GCC_CORE}" "d50ec5af20508974411d0c83c5f4e396"
     168        download_check "${GCC_SOURCE}" "${GCC_OBJC}" "d8d26187d386a0591222a580b5a5b3d3"
     169        download_check "${GCC_SOURCE}" "${GCC_CPP}" "43b1e4879eb282dc4b05e4c016d356d7"
    170170       
    171171        echo ">>> Removing previous content"
  • uspace/app/init/init.c

    rd42976c r393bef1  
    9494static bool mount_devfs(void)
    9595{
    96         int rc = mount("devfs", DEVFS_MOUNT_POINT, "", "", IPC_FLAG_BLOCKING);
     96        char null[MAX_DEVICE_NAME];
     97        int null_id = devmap_null_create();
     98       
     99        if (null_id == -1) {
     100                printf(NAME ": Unable to create null device\n");
     101                return false;
     102        }
     103       
     104        snprintf(null, MAX_DEVICE_NAME, "null/%d", null_id);
     105        int rc = mount("devfs", DEVFS_MOUNT_POINT, null, "", IPC_FLAG_BLOCKING);
    97106       
    98107        switch (rc) {
     
    102111        case EBUSY:
    103112                printf(NAME ": Device filesystem already mounted\n");
     113                devmap_null_destroy(null_id);
    104114                return false;
    105115        case ELIMIT:
    106116                printf(NAME ": Unable to mount device filesystem\n");
     117                devmap_null_destroy(null_id);
    107118                return false;
    108119        case ENOENT:
    109120                printf(NAME ": Unknown filesystem type (devfs)\n");
     121                devmap_null_destroy(null_id);
    110122                return false;
    111123        default:
    112124                printf(NAME ": Error mounting device filesystem (%d)\n", rc);
     125                devmap_null_destroy(null_id);
    113126                return false;
    114127        }
     
    171184{
    172185        char *argv[3];
    173         char hid_in[DEVMAP_NAME_MAXLEN];
     186        char hid_in[MAX_DEVICE_NAME];
    174187        int rc;
    175188       
    176         snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
     189        snprintf(hid_in, MAX_DEVICE_NAME, "%s/%s", DEVFS_MOUNT_POINT, dev);
    177190       
    178191        printf(NAME ": Spawning %s with %s\n", SRV_CONSOLE, hid_in);
     
    196209{
    197210        char *argv[4];
    198         char term[DEVMAP_NAME_MAXLEN];
     211        char term[MAX_DEVICE_NAME];
    199212        int rc;
    200213       
    201         snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
     214        snprintf(term, MAX_DEVICE_NAME, "%s/%s", DEVFS_MOUNT_POINT, dev);
    202215       
    203216        printf(NAME ": Spawning %s with %s %s\n", APP_GETTERM, term, app);
  • uspace/app/init/init.h

    rd42976c r393bef1  
    3939#define NAME  "init"
    4040
     41#define MAX_DEVICE_NAME  32
     42
    4143#endif
    4244
  • uspace/app/tester/vfs/vfs1.c

    rd42976c r393bef1  
    7979        TPRINTF("Created directory %s\n", MOUNT_POINT);
    8080       
    81         int rc = mount(FS_TYPE, MOUNT_POINT, "", OPTIONS, FLAGS);
     81        char null[MAX_DEVICE_NAME];
     82        int null_id = devmap_null_create();
     83       
     84        if (null_id == -1)
     85                return "Unable to create null device";
     86       
     87        snprintf(null, MAX_DEVICE_NAME, "null/%d", null_id);
     88        int rc = mount(FS_TYPE, MOUNT_POINT, null, OPTIONS, FLAGS);
    8289        switch (rc) {
    8390        case EOK:
    84                 TPRINTF("Mounted %s on %s\n", FS_TYPE, MOUNT_POINT);
     91                TPRINTF("Mounted /dev/%s as %s on %s\n", null, FS_TYPE, MOUNT_POINT);
    8592                break;
    8693        case EBUSY:
  • uspace/lib/libc/arch/ia64/include/fibril.h

    rd42976c r393bef1  
    5252/* Stack is divided into two equal parts (for memory stack and register stack). */
    5353#define PSTHREAD_INITIAL_STACK_DIVISION 2 
     54
     55#ifdef context_set
     56#undef context_set
     57#endif
    5458
    5559#define context_set(c, _pc, stack, size, tls)                                                           \
  • uspace/lib/libc/arch/sparc64/include/fibril.h

    rd42976c r393bef1  
    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
    4448#define context_set(c, _pc, stack, size, ptls) \
    4549        do { \
  • uspace/lib/libc/generic/async.c

    rd42976c r393bef1  
    12871287}
    12881288
    1289 /** Wrapper for forwarding any read request
    1290  *
    1291  *
    1292  */
    1293 int 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                 ipc_answer_0(callid, retval);
    1313                 return retval;
    1314         }
    1315        
    1316         ipcarg_t rc;
    1317         async_wait_for(msg, &rc);
    1318        
    1319         return (int) rc;
    1320 }
    1321 
    13221289/** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
    13231290 *
    1324  * @param phoneid Phone that will be used to contact the receiving side.
    1325  * @param src     Address of the beginning of the source buffer.
    1326  * @param size    Size of the source buffer.
    1327  *
    1328  * @return Zero on success or a negative error code from errno.h.
    1329  *
     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.
    13301296 */
    13311297int async_data_write_start(int phoneid, const void *src, size_t size)
     
    13421308 * So far, this wrapper is to be used from within a connection fibril.
    13431309 *
    1344  * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will
    1345  *               be stored.
    1346  * @param size   Storage where the suggested size will be stored. May be
    1347  *               NULL
    1348  *
    1349  * @return Non-zero on success, zero on failure.
    1350  *
     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.
    13511316 */
    13521317int async_data_write_receive(ipc_callid_t *callid, size_t *size)
     
    13551320       
    13561321        assert(callid);
    1357        
     1322
    13581323        *callid = async_get_call(&data);
    13591324        if (IPC_GET_METHOD(data) != IPC_M_DATA_WRITE)
    13601325                return 0;
    1361        
    13621326        if (size)
    13631327                *size = (size_t) IPC_GET_ARG2(data);
    1364        
    13651328        return 1;
    13661329}
     
    13711334 * so that the user doesn't have to remember the meaning of each IPC argument.
    13721335 *
    1373  * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
    1374  * @param dst    Final destination address for the IPC_M_DATA_WRITE call.
    1375  * @param size   Final size for the IPC_M_DATA_WRITE call.
     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.
     1341 */
     1342int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
     1343{
     1344        return ipc_data_write_finalize(callid, dst, size);
     1345}
     1346
     1347/** Wrapper for receiving blobs via the async_data_write_*
     1348 *
     1349 * 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.
    13761358 *
    13771359 * @return Zero on success or a value from @ref errno.h on failure.
    13781360 *
    13791361 */
    1380 int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
    1381 {
    1382         return ipc_data_write_finalize(callid, dst, size);
    1383 }
    1384 
    1385 /** Wrapper for receiving binary data or strings
    1386  *
    1387  * This wrapper only makes it more comfortable to use async_data_write_*
    1388  * functions to receive binary data or strings.
    1389  *
    1390  * @param data       Pointer to data pointer (which should be later disposed
    1391  *                   by free()). If the operation fails, the pointer is not
    1392  *                   touched.
    1393  * @param nullterm   If true then the received data is always zero terminated.
    1394  *                   This also causes to allocate one extra byte beyond the
    1395  *                   raw transmitted data.
    1396  * @param min_size   Minimum size (in bytes) of the data to receive.
    1397  * @param max_size   Maximum size (in bytes) of the data to receive. 0 means
    1398  *                   no limit.
    1399  * @param granulariy If non-zero then the size of the received data has to
    1400  *                   be divisible by this value.
    1401  * @param received   If not NULL, the size of the received data is stored here.
    1402  *
    1403  * @return Zero on success or a value from @ref errno.h on failure.
    1404  *
    1405  */
    1406 int async_data_write_accept(void **data, const bool nullterm,
    1407     const size_t min_size, const size_t max_size, const size_t granularity,
    1408     size_t *received)
     1362int async_data_blob_receive(char **blob, const size_t max_size, size_t *received)
    14091363{
    14101364        ipc_callid_t callid;
     
    14151369        }
    14161370       
    1417         if (size < min_size) {
    1418                 ipc_answer_0(callid, EINVAL);
    1419                 return EINVAL;
    1420         }
    1421        
    14221371        if ((max_size > 0) && (size > max_size)) {
    14231372                ipc_answer_0(callid, EINVAL);
     
    14251374        }
    14261375       
    1427         if ((granularity > 0) && ((size % granularity) != 0)) {
     1376        char *data = (char *) malloc(size);
     1377        if (data == NULL) {
     1378                ipc_answer_0(callid, ENOMEM);
     1379                return ENOMEM;
     1380        }
     1381       
     1382        int rc = async_data_write_finalize(callid, data, size);
     1383        if (rc != EOK) {
     1384                free(data);
     1385                return rc;
     1386        }
     1387       
     1388        *blob = data;
     1389        if (received != NULL)
     1390                *received = size;
     1391       
     1392        return EOK;
     1393}
     1394
     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 */
     1409int async_data_string_receive(char **str, const size_t max_size)
     1410{
     1411        ipc_callid_t callid;
     1412        size_t size;
     1413        if (!async_data_write_receive(&callid, &size)) {
    14281414                ipc_answer_0(callid, EINVAL);
    14291415                return EINVAL;
    14301416        }
    14311417       
    1432         void *_data;
    1433        
    1434         if (nullterm)
    1435                 _data = malloc(size + 1);
    1436         else
    1437                 _data = malloc(size);
    1438        
    1439         if (_data == NULL) {
     1418        if ((max_size > 0) && (size > max_size)) {
     1419                ipc_answer_0(callid, EINVAL);
     1420                return EINVAL;
     1421        }
     1422       
     1423        char *data = (char *) malloc(size + 1);
     1424        if (data == NULL) {
    14401425                ipc_answer_0(callid, ENOMEM);
    14411426                return ENOMEM;
    14421427        }
    14431428       
    1444         int rc = async_data_write_finalize(callid, _data, size);
     1429        int rc = async_data_write_finalize(callid, data, size);
    14451430        if (rc != EOK) {
    1446                 free(_data);
     1431                free(data);
    14471432                return rc;
    14481433        }
    14491434       
    1450         if (nullterm)
    1451                 ((char *) _data)[size] = 0;
    1452        
    1453         *data = _data;
    1454         if (received != NULL)
    1455                 *received = size;
    1456        
     1435        data[size] = 0;
     1436        *str = data;
    14571437        return EOK;
    14581438}
    14591439
    1460 /** Wrapper for voiding any data that is about to be received
    1461  *
    1462  * This wrapper can be used to void any pending data
    1463  *
    1464  * @param retval Error value from @ref errno.h to be returned to the caller.
    1465  *
    1466  */
    1467 void async_data_write_void(const int retval)
    1468 {
    1469         ipc_callid_t callid;
    1470         async_data_write_receive(&callid, NULL);
    1471         ipc_answer_0(callid, retval);
    1472 }
    1473 
    1474 /** Wrapper for forwarding any data that is about to be received
    1475  *
    1476  *
    1477  */
    1478 int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
    1479     ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr)
    1480 {
    1481         ipc_callid_t callid;
    1482         if (!async_data_write_receive(&callid, NULL)) {
    1483                 ipc_answer_0(callid, EINVAL);
    1484                 return EINVAL;
    1485         }
    1486        
    1487         aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4,
    1488             dataptr);
    1489         if (msg == 0) {
    1490                 ipc_answer_0(callid, EINVAL);
    1491                 return EINVAL;
    1492         }
    1493        
    1494         int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0,
    1495             IPC_FF_ROUTE_FROM_ME);
    1496         if (retval != EOK) {
    1497                 ipc_answer_0(callid, retval);
    1498                 return retval;
    1499         }
    1500        
    1501         ipcarg_t rc;
    1502         async_wait_for(msg, &rc);
    1503        
    1504         return (int) rc;
    1505 }
    1506 
    15071440/** @}
    15081441 */
  • uspace/lib/libc/generic/clipboard.c

    rd42976c r393bef1  
    8484                clip_connect();
    8585               
    86                 aid_t req = async_send_1(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_DATA, NULL);
     86                aid_t req = async_send_1(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_BLOB, 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_DATA:
     141                case CLIPBOARD_TAG_BLOB:
    142142                        sbuf = malloc(size + 1);
    143143                        if (sbuf == NULL)
  • uspace/lib/libc/generic/vfs/vfs.c

    rd42976c r393bef1  
    120120    const char *opts, unsigned int flags)
    121121{
    122         int null_id = -1;
    123         char null[DEVMAP_NAME_MAXLEN];
    124        
    125         if (str_cmp(fqdn, "") == 0) {
    126                 /* No device specified, create a fresh
    127                    null/%d device instead */
    128                 null_id = devmap_null_create();
    129                
    130                 if (null_id == -1)
    131                         return ENOMEM;
    132                
    133                 snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id);
    134                 fqdn = null;
    135         }
    136        
     122        int res;
     123        ipcarg_t rc;
     124        ipcarg_t rc_orig;
     125        aid_t req;
    137126        dev_handle_t dev_handle;
    138         int res = devmap_device_get_handle(fqdn, &dev_handle, flags);
    139         if (res != EOK) {
    140                 if (null_id != -1)
    141                         devmap_null_destroy(null_id);
    142                
     127       
     128        res = devmap_device_get_handle(fqdn, &dev_handle, flags);
     129        if (res != EOK)
    143130                return res;
    144         }
    145131       
    146132        size_t mpa_size;
    147133        char *mpa = absolutize(mp, &mpa_size);
    148         if (!mpa) {
    149                 if (null_id != -1)
    150                         devmap_null_destroy(null_id);
    151                
    152                 return ENOMEM;
    153         }
    154        
    155         futex_down(&vfs_phone_futex);
    156         async_serialize_start();
    157         vfs_connect();
    158        
    159         ipcarg_t rc_orig;
    160         aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
    161         ipcarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
     134        if (!mpa)
     135                return ENOMEM;
     136       
     137        futex_down(&vfs_phone_futex);
     138        async_serialize_start();
     139        vfs_connect();
     140       
     141        req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
     142        rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    162143        if (rc != EOK) {
    163144                async_wait_for(req, &rc_orig);
     
    165146                futex_up(&vfs_phone_futex);
    166147                free(mpa);
    167                
    168                 if (null_id != -1)
    169                         devmap_null_destroy(null_id);
    170                
    171148                if (rc_orig == EOK)
    172149                        return (int) rc;
     
    181158                futex_up(&vfs_phone_futex);
    182159                free(mpa);
    183                
    184                 if (null_id != -1)
    185                         devmap_null_destroy(null_id);
    186                
    187                 if (rc_orig == EOK)
    188                         return (int) rc;
    189                 else
    190                         return (int) rc_orig;
    191         }
    192        
     160                if (rc_orig == EOK)
     161                        return (int) rc;
     162                else
     163                        return (int) rc_orig;
     164        }
     165
    193166        rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
    194167        if (rc != EOK) {
     
    197170                futex_up(&vfs_phone_futex);
    198171                free(mpa);
    199                
    200                 if (null_id != -1)
    201                         devmap_null_destroy(null_id);
    202                
    203                 if (rc_orig == EOK)
    204                         return (int) rc;
    205                 else
    206                         return (int) rc_orig;
    207         }
    208        
     172                if (rc_orig == EOK)
     173                        return (int) rc;
     174                else
     175                        return (int) rc_orig;
     176        }
     177
    209178        /* Ask VFS whether it likes fs_name. */
    210179        rc = async_req_0_0(vfs_phone, IPC_M_PING);
     
    214183                futex_up(&vfs_phone_futex);
    215184                free(mpa);
    216                
    217                 if (null_id != -1)
    218                         devmap_null_destroy(null_id);
    219                
    220185                if (rc_orig == EOK)
    221186                        return (int) rc;
     
    228193        futex_up(&vfs_phone_futex);
    229194        free(mpa);
    230        
    231         if ((rc != EOK) && (null_id != -1))
    232                 devmap_null_destroy(null_id);
    233195       
    234196        return (int) rc;
  • uspace/lib/libc/include/async.h

    rd42976c r393bef1  
    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 
    309279extern int async_data_read_start(int, void *, size_t);
    310280extern int async_data_read_receive(ipc_callid_t *, size_t *);
    311281extern int async_data_read_finalize(ipc_callid_t, const void *, size_t);
    312 
    313 extern 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 
    347282extern int async_data_write_start(int, const void *, size_t);
    348283extern int async_data_write_receive(ipc_callid_t *, size_t *);
    349284extern int async_data_write_finalize(ipc_callid_t, void *, size_t);
    350285
    351 extern int async_data_write_accept(void **, const bool, const size_t,
    352     const size_t, const size_t, size_t *);
    353 extern void async_data_write_void(const int);
    354 
    355 extern int async_data_write_forward_fast(int, ipcarg_t, ipcarg_t, ipcarg_t,
    356     ipcarg_t, ipcarg_t, ipc_call_t *);
     286extern int async_data_blob_receive(char **, const size_t, size_t *);
     287extern int async_data_string_receive(char **, const size_t);
    357288
    358289#endif
  • uspace/lib/libc/include/fibril.h

    rd42976c r393bef1  
    4040#include <libarch/tls.h>
    4141
    42 #define context_set_generic(c, _pc, stack, size, ptls) \
     42#ifndef context_set
     43#define context_set(c, _pc, stack, size, ptls) \
    4344        (c)->pc = (sysarg_t) (_pc); \
    4445        (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
    4546        (c)->tls = (sysarg_t) (ptls);
     47#endif /* context_set */
    4648
    47 #define FIBRIL_SERIALIZED  1
    48 #define FIBRIL_WRITER      2
     49#define FIBRIL_SERIALIZED       1
     50#define FIBRIL_WRITER           2
    4951
    5052typedef enum {
     
    5759typedef sysarg_t fid_t;
    5860
    59 typedef struct fibril {
     61struct fibril {
    6062        link_t link;
    6163        context_t ctx;
     
    6870        int retval;
    6971        int flags;
    70 } fibril_t;
     72};
     73typedef struct fibril fibril_t;
    7174
    7275/** Fibril-local variable specifier */
    7376#define fibril_local __thread
    7477
    75 extern int context_save(context_t *ctx) __attribute__((returns_twice));
    76 extern void context_restore(context_t *ctx) __attribute__((noreturn));
     78extern int context_save(context_t *c) __attribute__ ((returns_twice));
     79extern void context_restore(context_t *c) __attribute__ ((noreturn));
    7780
    7881extern fid_t fibril_create(int (*func)(void *), void *arg);
     
    8790extern void fibril_dec_sercount(void);
    8891
    89 static inline int fibril_yield(void)
    90 {
     92static inline int fibril_yield(void) {
    9193        return fibril_switch(FIBRIL_PREEMPT);
    9294}
  • uspace/lib/libc/include/ipc/clipboard.h

    rd42976c r393bef1  
    4646typedef enum {
    4747        CLIPBOARD_TAG_NONE,
    48         CLIPBOARD_TAG_DATA
     48        CLIPBOARD_TAG_BLOB
    4949} clipboard_tag_t;
    5050
  • uspace/lib/libfs/libfs.c

    rd42976c r393bef1  
    161161        /* Accept the phone */
    162162        callid = async_get_call(&call);
    163         int mountee_phone = (int) IPC_GET_ARG1(call);
     163        int mountee_phone = (int)IPC_GET_ARG1(call);
    164164        if ((IPC_GET_METHOD(call) != IPC_M_CONNECTION_CLONE) ||
    165165            (mountee_phone < 0)) {
     
    172172        ipc_answer_0(callid, EOK);
    173173       
     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       
    174182        fs_node_t *fn;
    175183        res = ops->node_get(&fn, mp_dev_handle, mp_fs_index);
    176184        if ((res != EOK) || (!fn)) {
    177185                ipc_hangup(mountee_phone);
    178                 async_data_write_void(combine_rc(res, ENOENT));
     186                ipc_answer_0(callid, combine_rc(res, ENOENT));
    179187                ipc_answer_0(rid, combine_rc(res, ENOENT));
    180188                return;
     
    184192                ipc_hangup(mountee_phone);
    185193                (void) ops->node_put(fn);
    186                 async_data_write_void(EBUSY);
     194                ipc_answer_0(callid, EBUSY);
    187195                ipc_answer_0(rid, EBUSY);
    188196                return;
     
    193201                ipc_hangup(mountee_phone);
    194202                (void) ops->node_put(fn);
    195                 async_data_write_void(rc);
     203                ipc_answer_0(callid, rc);
    196204                ipc_answer_0(rid, rc);
    197205                return;
     
    199207       
    200208        ipc_call_t answer;
    201         rc = async_data_write_forward_1_1(mountee_phone, VFS_OUT_MOUNTED,
    202             mr_dev_handle, &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);
    203213       
    204214        if (rc == EOK) {
  • uspace/srv/clip/clip.c

    rd42976c r393bef1  
    6464                ipc_answer_0(rid, EOK);
    6565                break;
    66         case CLIPBOARD_TAG_DATA:
    67                 rc = async_data_write_accept((void **) &data, false, 0, 0, 0, &size);
     66        case CLIPBOARD_TAG_BLOB:
     67                rc = async_data_blob_receive(&data, 0, &size);
    6868                if (rc != EOK) {
    6969                        ipc_answer_0(rid, rc);
     
    7878                clip_data = data;
    7979                clip_size = size;
    80                 clip_tag = CLIPBOARD_TAG_DATA;
     80                clip_tag = CLIPBOARD_TAG_BLOB;
    8181               
    8282                fibril_mutex_unlock(&clip_mtx);
     
    9797        /* Check for clipboard data tag compatibility */
    9898        switch (IPC_GET_ARG1(*request)) {
    99         case CLIPBOARD_TAG_DATA:
     99        case CLIPBOARD_TAG_BLOB:
    100100                if (!async_data_read_receive(&callid, &size)) {
    101101                        ipc_answer_0(callid, EINVAL);
     
    104104                }
    105105               
    106                 if (clip_tag != CLIPBOARD_TAG_DATA) {
    107                         /* So far we only understand binary data */
     106                if (clip_tag != CLIPBOARD_TAG_BLOB) {
     107                        /* So far we only understand BLOB */
    108108                        ipc_answer_0(callid, EOVERFLOW);
    109109                        ipc_answer_0(rid, EOVERFLOW);
  • uspace/srv/devmap/devmap.c

    rd42976c r393bef1  
    396396         * Get driver name
    397397         */
    398         int rc = async_data_write_accept((void **) &driver->name, true, 0,
    399             DEVMAP_NAME_MAXLEN, 0, NULL);
     398        int rc = async_data_string_receive(&driver->name, DEVMAP_NAME_MAXLEN);
    400399        if (rc != EOK) {
    401400                free(driver);
     
    511510        /* Get fqdn */
    512511        char *fqdn;
    513         int rc = async_data_write_accept((void **) &fqdn, true, 0,
    514             DEVMAP_NAME_MAXLEN, 0, NULL);
     512        int rc = async_data_string_receive(&fqdn, DEVMAP_NAME_MAXLEN);
    515513        if (rc != EOK) {
    516514                free(device);
     
    624622       
    625623        /* Get fqdn */
    626         int rc = async_data_write_accept((void **) &fqdn, true, 0,
    627             DEVMAP_NAME_MAXLEN, 0, NULL);
     624        int rc = async_data_string_receive(&fqdn, DEVMAP_NAME_MAXLEN);
    628625        if (rc != EOK) {
    629626                ipc_answer_0(iid, rc);
     
    686683       
    687684        /* Get device name */
    688         int rc = async_data_write_accept((void **) &name, true, 0,
    689             DEVMAP_NAME_MAXLEN, 0, NULL);
     685        int rc = async_data_string_receive(&name, DEVMAP_NAME_MAXLEN);
    690686        if (rc != EOK) {
    691687                ipc_answer_0(iid, rc);
  • uspace/srv/fs/devfs/devfs_ops.c

    rd42976c r393bef1  
    419419       
    420420        /* Accept the mount options */
    421         ipcarg_t retval = async_data_write_accept((void **) &opts, true, 0, 0,
    422             0, NULL);
     421        ipcarg_t retval = async_data_string_receive(&opts, 0);
    423422        if (retval != EOK) {
    424423                ipc_answer_0(rid, retval);
  • uspace/srv/fs/fat/fat_ops.c

    rd42976c r393bef1  
    974974        uint16_t bps;
    975975        uint16_t rde;
    976        
    977         /* Accept the mount options */
    978         char *opts;
    979         int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
    980        
    981         if (rc != EOK) {
    982                 ipc_answer_0(rid, rc);
    983                 return;
    984         }
     976        int rc;
     977
     978        /* accept the mount options */
     979        ipc_callid_t callid;
     980        size_t size;
     981        if (!async_data_write_receive(&callid, &size)) {
     982                ipc_answer_0(callid, EINVAL);
     983                ipc_answer_0(rid, EINVAL);
     984                return;
     985        }
     986        char *opts = malloc(size + 1);
     987        if (!opts) {
     988                ipc_answer_0(callid, ENOMEM);
     989                ipc_answer_0(rid, ENOMEM);
     990                return;
     991        }
     992        ipcarg_t retval = async_data_write_finalize(callid, opts, size);
     993        if (retval != EOK) {
     994                ipc_answer_0(rid, retval);
     995                free(opts);
     996                return;
     997        }
     998        opts[size] = '\0';
    985999
    9861000        /* Check for option enabling write through. */
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    rd42976c r393bef1  
    443443        fs_node_t *rootfn;
    444444        int rc;
    445        
    446         /* Accept the mount options. */
    447         char *opts;
    448         rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL);
    449         if (rc != EOK) {
    450                 ipc_answer_0(rid, rc);
    451                 return;
    452         }
    453 
    454         /* Check if this device is not already mounted. */
     445
     446        /* accept the mount options */
     447        ipc_callid_t callid;
     448        size_t size;
     449        if (!async_data_write_receive(&callid, &size)) {
     450                ipc_answer_0(callid, EINVAL);
     451                ipc_answer_0(rid, EINVAL);
     452                return;
     453        }
     454        char *opts = malloc(size + 1);
     455        if (!opts) {
     456                ipc_answer_0(callid, ENOMEM);
     457                ipc_answer_0(rid, ENOMEM);
     458                return;
     459        }
     460        ipcarg_t retval = async_data_write_finalize(callid, opts, size);
     461        if (retval != EOK) {
     462                ipc_answer_0(rid, retval);
     463                free(opts);
     464                return;
     465        }
     466        opts[size] = '\0';
     467
     468        /*
     469         * Check if this device is not already mounted.
     470         */
    455471        rc = tmpfs_root_get(&rootfn, dev_handle);
    456472        if ((rc == EOK) && (rootfn)) {
  • uspace/srv/hid/console/console.c

    rd42976c r393bef1  
    475475static void cons_write(console_t *cons, ipc_callid_t rid, ipc_call_t *request)
    476476{
    477         void *buf;
     477        ipc_callid_t callid;
    478478        size_t size;
    479         int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size);
    480        
    481         if (rc != EOK) {
    482                 ipc_answer_0(rid, rc);
     479        if (!async_data_write_receive(&callid, &size)) {
     480                ipc_answer_0(callid, EINVAL);
     481                ipc_answer_0(rid, EINVAL);
    483482                return;
    484483        }
     484       
     485        char *buf = (char *) malloc(size);
     486        if (buf == NULL) {
     487                ipc_answer_0(callid, ENOMEM);
     488                ipc_answer_0(rid, ENOMEM);
     489                return;
     490        }
     491       
     492        (void) async_data_write_finalize(callid, buf, size);
    485493       
    486494        async_serialize_start();
  • uspace/srv/loader/main.c

    rd42976c r393bef1  
    125125static void ldr_set_cwd(ipc_callid_t rid, ipc_call_t *request)
    126126{
    127         char *buf;
    128         int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL);
    129        
    130         if (rc == EOK) {
    131                 if (cwd != NULL)
    132                         free(cwd);
    133                
    134                 cwd = buf;
    135         }
    136        
    137         ipc_answer_0(rid, rc);
     127        ipc_callid_t callid;
     128        size_t len;
     129       
     130        if (!async_data_write_receive(&callid, &len)) {
     131                ipc_answer_0(callid, EINVAL);
     132                ipc_answer_0(rid, EINVAL);
     133                return;
     134        }
     135       
     136        cwd = malloc(len + 1);
     137        if (!cwd) {
     138                ipc_answer_0(callid, ENOMEM);
     139                ipc_answer_0(rid, ENOMEM);
     140                return;
     141        }
     142       
     143        async_data_write_finalize(callid, cwd, len);
     144        cwd[len] = '\0';
     145       
     146        ipc_answer_0(rid, EOK);
    138147}
    139148
     
    145154static void ldr_set_pathname(ipc_callid_t rid, ipc_call_t *request)
    146155{
    147         char *buf;
    148         int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL);
    149        
    150         if (rc == EOK) {
    151                 if (pathname != NULL)
    152                         free(pathname);
    153                
    154                 pathname = buf;
    155         }
    156        
    157         ipc_answer_0(rid, rc);
     156        ipc_callid_t callid;
     157        size_t len;
     158        char *name_buf;
     159       
     160        if (!async_data_write_receive(&callid, &len)) {
     161                ipc_answer_0(callid, EINVAL);
     162                ipc_answer_0(rid, EINVAL);
     163                return;
     164        }
     165       
     166        name_buf = malloc(len + 1);
     167        if (!name_buf) {
     168                ipc_answer_0(callid, ENOMEM);
     169                ipc_answer_0(rid, ENOMEM);
     170                return;
     171        }
     172       
     173        async_data_write_finalize(callid, name_buf, len);
     174        ipc_answer_0(rid, EOK);
     175       
     176        if (pathname != NULL) {
     177                free(pathname);
     178                pathname = NULL;
     179        }
     180       
     181        name_buf[len] = '\0';
     182        pathname = name_buf;
    158183}
    159184
     
    165190static void ldr_set_args(ipc_callid_t rid, ipc_call_t *request)
    166191{
    167         char *buf;
    168         size_t buf_size;
    169         int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, &buf_size);
    170        
    171         if (rc == EOK) {
    172                 /*
    173                  * Count number of arguments
    174                  */
    175                 char *cur = buf;
    176                 int count = 0;
     192        ipc_callid_t callid;
     193        size_t buf_size, arg_size;
     194        char *p;
     195        int n;
     196       
     197        if (!async_data_write_receive(&callid, &buf_size)) {
     198                ipc_answer_0(callid, EINVAL);
     199                ipc_answer_0(rid, EINVAL);
     200                return;
     201        }
     202       
     203        if (arg_buf != NULL) {
     204                free(arg_buf);
     205                arg_buf = NULL;
     206        }
     207       
     208        if (argv != NULL) {
     209                free(argv);
     210                argv = NULL;
     211        }
     212       
     213        arg_buf = malloc(buf_size + 1);
     214        if (!arg_buf) {
     215                ipc_answer_0(callid, ENOMEM);
     216                ipc_answer_0(rid, ENOMEM);
     217                return;
     218        }
     219       
     220        async_data_write_finalize(callid, arg_buf, buf_size);
     221       
     222        arg_buf[buf_size] = '\0';
     223       
     224        /*
     225         * Count number of arguments
     226         */
     227        p = arg_buf;
     228        n = 0;
     229        while (p < arg_buf + buf_size) {
     230                arg_size = str_size(p);
     231                p = p + arg_size + 1;
     232                ++n;
     233        }
     234       
     235        /* Allocate argv */
     236        argv = malloc((n + 1) * sizeof(char *));
     237       
     238        if (argv == NULL) {
     239                free(arg_buf);
     240                ipc_answer_0(rid, ENOMEM);
     241                return;
     242        }
     243
     244        /*
     245         * Fill argv with argument pointers
     246         */
     247        p = arg_buf;
     248        n = 0;
     249        while (p < arg_buf + buf_size) {
     250                argv[n] = p;
    177251               
    178                 while (cur < buf + buf_size) {
    179                         size_t arg_size = str_size(cur);
    180                         cur += arg_size + 1;
    181                         count++;
    182                 }
    183                
    184                 /*
    185                  * Allocate new argv
    186                  */
    187                 char **_argv = (char **) malloc((count + 1) * sizeof(char *));
    188                 if (_argv == NULL) {
    189                         free(buf);
    190                         ipc_answer_0(rid, ENOMEM);
    191                         return;
    192                 }
    193                
    194                 /*
    195                  * Fill the new argv with argument pointers
    196                  */
    197                 cur = buf;
    198                 count = 0;
    199                 while (cur < buf + buf_size) {
    200                         _argv[count] = cur;
    201                        
    202                         size_t arg_size = str_size(cur);
    203                         cur += arg_size + 1;
    204                         count++;
    205                 }
    206                 _argv[count] = NULL;
    207                
    208                 /*
    209                  * Copy temporary data to global variables
    210                  */
    211                 if (arg_buf != NULL)
    212                         free(arg_buf);
    213                
    214                 if (argv != NULL)
    215                         free(argv);
    216                
    217                 argc = count;
    218                 arg_buf = buf;
    219                 argv = _argv;
    220         }
    221        
    222         ipc_answer_0(rid, rc);
     252                arg_size = str_size(p);
     253                p = p + arg_size + 1;
     254                ++n;
     255        }
     256       
     257        argc = n;
     258        argv[n] = NULL;
     259
     260        ipc_answer_0(rid, EOK);
    223261}
    224262
     
    230268static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request)
    231269{
    232         fdi_node_t *buf;
     270        ipc_callid_t callid;
    233271        size_t buf_size;
    234         int rc = async_data_write_accept((void **) &buf, false, 0, 0,
    235             sizeof(fdi_node_t), &buf_size);
    236        
    237         if (rc == EOK) {
    238                 int count = buf_size / sizeof(fdi_node_t);
    239                
    240                 /*
    241                  * Allocate new filv
    242                  */
    243                 fdi_node_t **_filv = (fdi_node_t *) malloc((count + 1) * sizeof(fdi_node_t *));
    244                 if (_filv == NULL) {
    245                         free(buf);
    246                         ipc_answer_0(rid, ENOMEM);
    247                         return;
    248                 }
    249                
    250                 /*
    251                  * Fill the new filv with argument pointers
    252                  */
    253                 int i;
    254                 for (i = 0; i < count; i++)
    255                         _filv[i] = &buf[i];
    256                
    257                 _filv[count] = NULL;
    258                
    259                 /*
    260                  * Copy temporary data to global variables
    261                  */
    262                 if (fil_buf != NULL)
    263                         free(fil_buf);
    264                
    265                 if (filv != NULL)
    266                         free(filv);
    267                
    268                 filc = count;
    269                 fil_buf = buf;
    270                 filv = _filv;
    271         }
     272        if (!async_data_write_receive(&callid, &buf_size)) {
     273                ipc_answer_0(callid, EINVAL);
     274                ipc_answer_0(rid, EINVAL);
     275                return;
     276        }
     277       
     278        if ((buf_size % sizeof(fdi_node_t)) != 0) {
     279                ipc_answer_0(callid, EINVAL);
     280                ipc_answer_0(rid, EINVAL);
     281                return;
     282        }
     283       
     284        if (fil_buf != NULL) {
     285                free(fil_buf);
     286                fil_buf = NULL;
     287        }
     288       
     289        if (filv != NULL) {
     290                free(filv);
     291                filv = NULL;
     292        }
     293       
     294        fil_buf = malloc(buf_size);
     295        if (!fil_buf) {
     296                ipc_answer_0(callid, ENOMEM);
     297                ipc_answer_0(rid, ENOMEM);
     298                return;
     299        }
     300       
     301        async_data_write_finalize(callid, fil_buf, buf_size);
     302       
     303        int count = buf_size / sizeof(fdi_node_t);
     304       
     305        /* Allocate filvv */
     306        filv = malloc((count + 1) * sizeof(fdi_node_t *));
     307       
     308        if (filv == NULL) {
     309                free(fil_buf);
     310                ipc_answer_0(rid, ENOMEM);
     311                return;
     312        }
     313       
     314        /*
     315         * Fill filv with argument pointers
     316         */
     317        int i;
     318        for (i = 0; i < count; i++)
     319                filv[i] = &fil_buf[i];
     320       
     321        filc = count;
     322        filv[count] = NULL;
    272323       
    273324        ipc_answer_0(rid, EOK);
  • uspace/srv/vfs/vfs_ops.c

    rd42976c r393bef1  
    266266       
    267267        /* We want the client to send us the mount point. */
    268         char *mp;
    269         int rc = async_data_write_accept((void **) &mp, true, 0, MAX_PATH_LEN,
    270             0, NULL);
    271         if (rc != EOK) {
    272                 ipc_answer_0(rid, rc);
    273                 return;
    274         }
     268        ipc_callid_t callid;
     269        size_t size;
     270        if (!async_data_write_receive(&callid, &size)) {
     271                ipc_answer_0(callid, EINVAL);
     272                ipc_answer_0(rid, EINVAL);
     273                return;
     274        }
     275       
     276        /* Check whether size is reasonable wrt. the mount point. */
     277        if ((size < 1) || (size > MAX_PATH_LEN)) {
     278                ipc_answer_0(callid, EINVAL);
     279                ipc_answer_0(rid, EINVAL);
     280                return;
     281        }
     282       
     283        /* Allocate buffer for the mount point data being received. */
     284        char *mp = malloc(size + 1);
     285        if (!mp) {
     286                ipc_answer_0(callid, ENOMEM);
     287                ipc_answer_0(rid, ENOMEM);
     288                return;
     289        }
     290       
     291        /* Deliver the mount point. */
     292        ipcarg_t retval = async_data_write_finalize(callid, mp, size);
     293        if (retval != EOK) {
     294                ipc_answer_0(rid, retval);
     295                free(mp);
     296                return;
     297        }
     298        mp[size] = '\0';
    275299       
    276300        /* Now we expect to receive the mount options. */
    277         char *opts;
    278         rc = async_data_write_accept((void **) &opts, true, 0, MAX_MNTOPTS_LEN,
    279             0, NULL);
    280         if (rc != EOK) {
     301        if (!async_data_write_receive(&callid, &size)) {
     302                ipc_answer_0(callid, EINVAL);
     303                ipc_answer_0(rid, EINVAL);
    281304                free(mp);
    282                 ipc_answer_0(rid, rc);
    283                 return;
    284         }
     305                return;
     306        }
     307
     308        /* Check the offered options size. */
     309        if (size > MAX_MNTOPTS_LEN) {
     310                ipc_answer_0(callid, EINVAL);
     311                ipc_answer_0(rid, EINVAL);
     312                free(mp);
     313                return;
     314        }
     315
     316        /* Allocate buffer for the mount options. */
     317        char *opts = (char *) malloc(size + 1);
     318        if (!opts) {
     319                ipc_answer_0(callid, ENOMEM);
     320                ipc_answer_0(rid, ENOMEM);
     321                free(mp);
     322                return;
     323        }
     324
     325        /* Deliver the mount options. */
     326        retval = async_data_write_finalize(callid, opts, size);
     327        if (retval != EOK) {
     328                ipc_answer_0(rid, retval);
     329                free(mp);
     330                free(opts);
     331                return;
     332        }
     333        opts[size] = '\0';
    285334       
    286335        /*
     
    288337         * system.
    289338         */
    290         char *fs_name;
    291         rc = async_data_write_accept((void **) &fs_name, true, 0, FS_NAME_MAXLEN,
    292             0, NULL);
    293         if (rc != EOK) {
     339        if (!async_data_write_receive(&callid, &size)) {
     340                ipc_answer_0(callid, EINVAL);
     341                ipc_answer_0(rid, EINVAL);
    294342                free(mp);
    295343                free(opts);
    296                 ipc_answer_0(rid, rc);
    297                 return;
    298         }
    299        
     344                return;
     345        }
     346       
     347        /*
     348         * Don't receive more than is necessary for storing a full file system
     349         * name.
     350         */
     351        if ((size < 1) || (size > FS_NAME_MAXLEN)) {
     352                ipc_answer_0(callid, EINVAL);
     353                ipc_answer_0(rid, EINVAL);
     354                free(mp);
     355                free(opts);
     356                return;
     357        }
     358       
     359        /*
     360         * Allocate buffer for file system name.
     361         */
     362        char *fs_name = (char *) malloc(size + 1);
     363        if (fs_name == NULL) {
     364                ipc_answer_0(callid, ENOMEM);
     365                ipc_answer_0(rid, ENOMEM);
     366                free(mp);
     367                free(opts);
     368                return;
     369        }
     370       
     371        /* Deliver the file system name. */
     372        retval = async_data_write_finalize(callid, fs_name, size);
     373        if (retval != EOK) {
     374                ipc_answer_0(rid, retval);
     375                free(mp);
     376                free(opts);
     377                free(fs_name);
     378                return;
     379        }
     380        fs_name[size] = '\0';
     381
    300382        /*
    301383         * Wait for IPC_M_PING so that we can return an error if we don't know
     
    303385         */
    304386        ipc_call_t data;
    305         ipc_callid_t callid = async_get_call(&data);
     387        callid = async_get_call(&data);
    306388        if (IPC_GET_METHOD(data) != IPC_M_PING) {
    307389                ipc_answer_0(callid, ENOTSUP);
     
    360442         * Receive the mount point path.
    361443         */
    362         rc = async_data_write_accept((void **) &mp, true, 0, MAX_PATH_LEN,
    363             0, NULL);
     444        rc = async_data_string_receive(&mp, MAX_PATH_LEN);
    364445        if (rc != EOK)
    365446                ipc_answer_0(rid, rc);
     
    525606                lflag |= L_EXCLUSIVE;
    526607       
    527         char *path;
    528         int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
    529         if (rc != EOK) {
    530                 ipc_answer_0(rid, rc);
    531                 return;
    532         }
     608        ipc_callid_t callid;
     609        if (!async_data_write_receive(&callid, &len)) {
     610                ipc_answer_0(callid, EINVAL);
     611                ipc_answer_0(rid, EINVAL);
     612                return;
     613        }
     614       
     615        char *path = malloc(len + 1);
     616        if (!path) {
     617                ipc_answer_0(callid, ENOMEM);
     618                ipc_answer_0(rid, ENOMEM);
     619                return;
     620        }
     621       
     622        int rc;
     623        if ((rc = async_data_write_finalize(callid, path, len))) {
     624                ipc_answer_0(rid, rc);
     625                free(path);
     626                return;
     627        }
     628        path[len] = '\0';
    533629       
    534630        /*
     
    798894       
    799895        /*
     896         * Now we need to receive a call with client's
     897         * IPC_M_DATA_READ/IPC_M_DATA_WRITE request.
     898         */
     899        ipc_callid_t callid;
     900        int res;
     901        if (read)
     902                res = async_data_read_receive(&callid, NULL);
     903        else
     904                res = async_data_write_receive(&callid, NULL);
     905        if (!res) {
     906                ipc_answer_0(callid, EINVAL);
     907                ipc_answer_0(rid, EINVAL);
     908                return;
     909        }
     910       
     911        /*
    800912         * Lock the open file structure so that no other thread can manipulate
    801913         * the same open file at a time.
     
    821933        }
    822934       
    823         int fs_phone = vfs_grab_phone(file->node->fs_handle);
    824        
    825         /*
    826          * Make a VFS_READ/VFS_WRITE request at the destination FS server
    827          * and forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the
     935        int fs_phone = vfs_grab_phone(file->node->fs_handle);   
     936       
     937        /* Make a VFS_READ/VFS_WRITE request at the destination FS server. */
     938        aid_t msg;
     939        ipc_call_t answer;
     940        if (!read && file->append)
     941                file->pos = file->node->size;
     942        msg = async_send_3(fs_phone, read ? VFS_OUT_READ : VFS_OUT_WRITE,
     943            file->node->dev_handle, file->node->index, file->pos, &answer);
     944       
     945        /*
     946         * Forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the
    828947         * destination FS server. The call will be routed as if sent by
    829948         * ourselves. Note that call arguments are immutable in this case so we
    830949         * don't have to bother.
    831950         */
     951        ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
     952
     953        /* Wait for reply from the FS server. */
    832954        ipcarg_t rc;
    833         ipc_call_t answer;
    834         if (read) {
    835                 if (file->append)
    836                         file->pos = file->node->size;
    837                
    838                 rc = async_data_read_forward_3_1(fs_phone, VFS_OUT_READ,
    839                     file->node->dev_handle, file->node->index, file->pos,
    840                     &answer);
    841         } else {
    842                 rc = async_data_write_forward_3_1(fs_phone, VFS_OUT_WRITE,
    843                     file->node->dev_handle, file->node->index, file->pos,
    844                     &answer);
    845         }
     955        async_wait_for(msg, &rc);
    846956       
    847957        vfs_release_phone(fs_phone);
    848958       
    849959        size_t bytes = IPC_GET_ARG1(answer);
    850        
     960
    851961        if (file->node->type == VFS_NODE_DIRECTORY)
    852962                fibril_rwlock_read_unlock(&namespace_rwlock);
     
    10101120void vfs_stat(ipc_callid_t rid, ipc_call_t *request)
    10111121{
    1012         char *path;
    1013         int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
    1014         if (rc != EOK) {
    1015                 ipc_answer_0(rid, rc);
    1016                 return;
    1017         }
    1018        
     1122        size_t len;
    10191123        ipc_callid_t callid;
     1124
     1125        if (!async_data_write_receive(&callid, &len)) {
     1126                ipc_answer_0(callid, EINVAL);
     1127                ipc_answer_0(rid, EINVAL);
     1128                return;
     1129        }
     1130        char *path = malloc(len + 1);
     1131        if (!path) {
     1132                ipc_answer_0(callid, ENOMEM);
     1133                ipc_answer_0(rid, ENOMEM);
     1134                return;
     1135        }
     1136        int rc;
     1137        if ((rc = async_data_write_finalize(callid, path, len))) {
     1138                ipc_answer_0(rid, rc);
     1139                free(path);
     1140                return;
     1141        }
     1142        path[len] = '\0';
     1143
    10201144        if (!async_data_read_receive(&callid, NULL)) {
    10211145                free(path);
     
    10631187{
    10641188        int mode = IPC_GET_ARG1(*request);
    1065        
    1066         char *path;
    1067         int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
    1068         if (rc != EOK) {
    1069                 ipc_answer_0(rid, rc);
    1070                 return;
    1071         }
    1072        
     1189
     1190        size_t len;
     1191        ipc_callid_t callid;
     1192
     1193        if (!async_data_write_receive(&callid, &len)) {
     1194                ipc_answer_0(callid, EINVAL);
     1195                ipc_answer_0(rid, EINVAL);
     1196                return;
     1197        }
     1198        char *path = malloc(len + 1);
     1199        if (!path) {
     1200                ipc_answer_0(callid, ENOMEM);
     1201                ipc_answer_0(rid, ENOMEM);
     1202                return;
     1203        }
     1204        int rc;
     1205        if ((rc = async_data_write_finalize(callid, path, len))) {
     1206                ipc_answer_0(rid, rc);
     1207                free(path);
     1208                return;
     1209        }
     1210        path[len] = '\0';
     1211
    10731212        /* Ignore mode for now. */
    10741213        (void) mode;
     
    10851224{
    10861225        int lflag = IPC_GET_ARG1(*request);
    1087        
    1088         char *path;
    1089         int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
    1090         if (rc != EOK) {
    1091                 ipc_answer_0(rid, rc);
    1092                 return;
    1093         }
     1226
     1227        size_t len;
     1228        ipc_callid_t callid;
     1229
     1230        if (!async_data_write_receive(&callid, &len)) {
     1231                ipc_answer_0(callid, EINVAL);
     1232                ipc_answer_0(rid, EINVAL);
     1233                return;
     1234        }
     1235        char *path = malloc(len + 1);
     1236        if (!path) {
     1237                ipc_answer_0(callid, ENOMEM);
     1238                ipc_answer_0(rid, ENOMEM);
     1239                return;
     1240        }
     1241        int rc;
     1242        if ((rc = async_data_write_finalize(callid, path, len))) {
     1243                ipc_answer_0(rid, rc);
     1244                free(path);
     1245                return;
     1246        }
     1247        path[len] = '\0';
    10941248       
    10951249        fibril_rwlock_write_lock(&namespace_rwlock);
     
    11201274void vfs_rename(ipc_callid_t rid, ipc_call_t *request)
    11211275{
     1276        size_t olen, nlen;
     1277        ipc_callid_t callid;
     1278        int rc;
     1279
    11221280        /* Retrieve the old path. */
    1123         char *old;
    1124         int rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL);
    1125         if (rc != EOK) {
    1126                 ipc_answer_0(rid, rc);
    1127                 return;
    1128         }
     1281        if (!async_data_write_receive(&callid, &olen)) {
     1282                ipc_answer_0(callid, EINVAL);
     1283                ipc_answer_0(rid, EINVAL);
     1284                return;
     1285        }
     1286        char *old = malloc(olen + 1);
     1287        if (!old) {
     1288                ipc_answer_0(callid, ENOMEM);
     1289                ipc_answer_0(rid, ENOMEM);
     1290                return;
     1291        }
     1292        if ((rc = async_data_write_finalize(callid, old, olen))) {
     1293                ipc_answer_0(rid, rc);
     1294                free(old);
     1295                return;
     1296        }
     1297        old[olen] = '\0';
    11291298       
    11301299        /* Retrieve the new path. */
    1131         char *new;
    1132         rc = async_data_write_accept((void **) &new, true, 0, 0, 0, NULL);
    1133         if (rc != EOK) {
     1300        if (!async_data_write_receive(&callid, &nlen)) {
     1301                ipc_answer_0(callid, EINVAL);
     1302                ipc_answer_0(rid, EINVAL);
    11341303                free(old);
    1135                 ipc_answer_0(rid, rc);
    1136                 return;
    1137         }
    1138        
    1139         size_t olen;
    1140         size_t nlen;
     1304                return;
     1305        }
     1306        char *new = malloc(nlen + 1);
     1307        if (!new) {
     1308                ipc_answer_0(callid, ENOMEM);
     1309                ipc_answer_0(rid, ENOMEM);
     1310                free(old);
     1311                return;
     1312        }
     1313        if ((rc = async_data_write_finalize(callid, new, nlen))) {
     1314                ipc_answer_0(rid, rc);
     1315                free(old);
     1316                free(new);
     1317                return;
     1318        }
     1319        new[nlen] = '\0';
     1320
    11411321        char *oldc = canonify(old, &olen);
    11421322        char *newc = canonify(new, &nlen);
    1143        
    1144         if ((!oldc) || (!newc)) {
     1323        if (!oldc || !newc) {
    11451324                ipc_answer_0(rid, EINVAL);
    11461325                free(old);
     
    11481327                return;
    11491328        }
    1150        
    11511329        oldc[olen] = '\0';
    11521330        newc[nlen] = '\0';
    1153        
    11541331        if ((!str_lcmp(newc, oldc, str_length(oldc))) &&
    11551332            ((newc[str_length(oldc)] == '/') ||
     
    11721349        vfs_lookup_res_t new_par_lr;
    11731350        fibril_rwlock_write_lock(&namespace_rwlock);
    1174        
    11751351        /* Lookup the node belonging to the old file name. */
    11761352        rc = vfs_lookup_internal(oldc, L_NONE, &old_lr, NULL);
     
    11821358                return;
    11831359        }
    1184        
    11851360        vfs_node_t *old_node = vfs_node_get(&old_lr);
    11861361        if (!old_node) {
     
    11911366                return;
    11921367        }
    1193        
    11941368        /* Determine the path to the parent of the node with the new name. */
    11951369        char *parentc = str_dup(newc);
     
    12011375                return;
    12021376        }
    1203        
    12041377        char *lastsl = str_rchr(parentc + 1, '/');
    12051378        if (lastsl)
     
    12071380        else
    12081381                parentc[1] = '\0';
    1209        
    12101382        /* Lookup parent of the new file name. */
    12111383        rc = vfs_lookup_internal(parentc, L_NONE, &new_par_lr, NULL);
     
    12181390                return;
    12191391        }
    1220        
    12211392        /* Check whether linking to the same file system instance. */
    12221393        if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) ||
     
    12281399                return;
    12291400        }
    1230        
    12311401        /* Destroy the old link for the new name. */
    12321402        vfs_node_t *new_node = NULL;
    12331403        rc = vfs_lookup_internal(newc, L_UNLINK, &new_lr, NULL);
    1234        
    12351404        switch (rc) {
    12361405        case ENOENT:
     
    12571426                return;
    12581427        }
    1259        
    12601428        /* Create the new link for the new name. */
    12611429        rc = vfs_lookup_internal(newc, L_LINK, NULL, NULL, old_node->index);
     
    12691437                return;
    12701438        }
    1271        
    12721439        fibril_mutex_lock(&nodes_mutex);
    12731440        old_node->lnkcnt++;
    12741441        fibril_mutex_unlock(&nodes_mutex);
    1275        
    12761442        /* Destroy the link for the old name. */
    12771443        rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL);
     
    12861452                return;
    12871453        }
    1288        
    12891454        fibril_mutex_lock(&nodes_mutex);
    12901455        old_node->lnkcnt--;
     
    12921457        fibril_rwlock_write_unlock(&namespace_rwlock);
    12931458        vfs_node_put(old_node);
    1294        
    12951459        if (new_node)
    12961460                vfs_node_put(new_node);
    1297        
    12981461        free(old);
    12991462        free(new);
  • uspace/srv/vfs/vfs_register.c

    rd42976c r393bef1  
    110110void vfs_register(ipc_callid_t rid, ipc_call_t *request)
    111111{
     112        ipc_callid_t callid;
     113        ipc_call_t call;
     114        int rc;
     115        size_t size;
     116
    112117        dprintf("Processing VFS_REGISTER request received from %p.\n",
    113118            request->in_phone_hash);
    114        
    115         vfs_info_t *vfs_info;
    116         int rc = async_data_write_accept((void **) &vfs_info, false,
    117             sizeof(vfs_info_t), sizeof(vfs_info_t), 0, NULL);
    118        
     119
     120        /*
     121         * The first call has to be IPC_M_DATA_SEND in which we receive the
     122         * VFS info structure from the client FS.
     123         */
     124        if (!async_data_write_receive(&callid, &size)) {
     125                /*
     126                 * The client doesn't obey the same protocol as we do.
     127                 */
     128                dprintf("Receiving of VFS info failed.\n");
     129                ipc_answer_0(callid, EINVAL);
     130                ipc_answer_0(rid, EINVAL);
     131                return;
     132        }
     133       
     134        dprintf("VFS info received, size = %d\n", size);
     135       
     136        /*
     137         * We know the size of the VFS info structure. See if the client
     138         * understands this easy concept too.
     139         */
     140        if (size != sizeof(vfs_info_t)) {
     141                /*
     142                 * The client is sending us something, which cannot be
     143                 * the info structure.
     144                 */
     145                dprintf("Received VFS info has bad size.\n");
     146                ipc_answer_0(callid, EINVAL);
     147                ipc_answer_0(rid, EINVAL);
     148                return;
     149        }
     150
     151        /*
     152         * Allocate and initialize a buffer for the fs_info structure.
     153         */
     154        fs_info_t *fs_info;
     155        fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
     156        if (!fs_info) {
     157                dprintf("Could not allocate memory for FS info.\n");
     158                ipc_answer_0(callid, ENOMEM);
     159                ipc_answer_0(rid, ENOMEM);
     160                return;
     161        }
     162        link_initialize(&fs_info->fs_link);
     163        fibril_mutex_initialize(&fs_info->phone_lock);
     164               
     165        rc = async_data_write_finalize(callid, &fs_info->vfs_info, size);
    119166        if (rc != EOK) {
    120167                dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n",
    121168                    rc);
     169                free(fs_info);
     170                ipc_answer_0(callid, rc);
    122171                ipc_answer_0(rid, rc);
    123172                return;
    124173        }
    125        
    126         /*
    127          * Allocate and initialize a buffer for the fs_info structure.
    128          */
    129         fs_info_t *fs_info = (fs_info_t *) malloc(sizeof(fs_info_t));
    130         if (!fs_info) {
    131                 dprintf("Could not allocate memory for FS info.\n");
    132                 ipc_answer_0(rid, ENOMEM);
    133                 return;
    134         }
    135        
    136         link_initialize(&fs_info->fs_link);
    137         fibril_mutex_initialize(&fs_info->phone_lock);
    138         fs_info->vfs_info = *vfs_info;
    139         free(vfs_info);
    140        
     174
    141175        dprintf("VFS info delivered.\n");
    142        
     176               
    143177        if (!vfs_info_sane(&fs_info->vfs_info)) {
    144178                free(fs_info);
    145                 ipc_answer_0(rid, EINVAL);
    146                 return;
    147         }
    148        
     179                ipc_answer_0(callid, EINVAL);
     180                ipc_answer_0(rid, EINVAL);
     181                return;
     182        }
     183               
    149184        fibril_mutex_lock(&fs_head_lock);
    150        
     185
    151186        /*
    152187         * Check for duplicit registrations.
     
    159194                fibril_mutex_unlock(&fs_head_lock);
    160195                free(fs_info);
     196                ipc_answer_0(callid, EEXISTS);
    161197                ipc_answer_0(rid, EEXISTS);
    162198                return;
    163199        }
    164        
     200
    165201        /*
    166202         * Add fs_info to the list of registered FS's.
     
    174210         * which to forward VFS requests to it.
    175211         */
    176         ipc_call_t call;
    177         ipc_callid_t callid = async_get_call(&call);
     212        callid = async_get_call(&call);
    178213        if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
    179214                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
     
    187222        fs_info->phone = IPC_GET_ARG5(call);
    188223        ipc_answer_0(callid, EOK);
    189        
     224
    190225        dprintf("Callback connection to FS created.\n");
    191        
     226
    192227        /*
    193228         * The client will want us to send him the address space area with PLB.
    194229         */
    195        
    196         size_t size;
     230
    197231        if (!async_share_in_receive(&callid, &size)) {
    198232                dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call));
     
    219253                return;
    220254        }
    221        
     255
    222256        /*
    223257         * Commit to read-only sharing the PLB with the client.
     
    225259        (void) async_share_in_finalize(callid, plb,
    226260            AS_AREA_READ | AS_AREA_CACHEABLE);
    227        
     261
    228262        dprintf("Sharing PLB.\n");
    229        
     263
    230264        /*
    231265         * That was it. The FS has been registered.
Note: See TracChangeset for help on using the changeset viewer.