Changeset af2a76c in mainline


Ignore:
Timestamp:
2014-07-13T17:25:15Z (10 years ago)
Author:
Agnieszka Tabaka <nufcia@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7493e7b
Parents:
b8e75319 (diff), 78192cc7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Files:
3 added
2 deleted
55 edited
2 moved

Legend:

Unmodified
Added
Removed
  • .bzrignore

    rb8e75319 raf2a76c  
    4545uspace/app/nettest2/nettest2
    4646uspace/app/nettest3/nettest3
     47uspace/app/nic/nic
    4748uspace/app/nterm/nterm
    4849uspace/app/ping/ping
     
    9495uspace/dist/app/nettest2
    9596uspace/dist/app/nettest3
     97uspace/dist/app/nic
    9698uspace/dist/app/nterm
    9799uspace/dist/app/ping
  • boot/Makefile.common

    rb8e75319 raf2a76c  
    190190        $(USPACE_PATH)/app/mkexfat/mkexfat \
    191191        $(USPACE_PATH)/app/mkmfs/mkmfs \
     192        $(USPACE_PATH)/app/nic/nic \
    192193        $(USPACE_PATH)/app/sbi/sbi \
    193194        $(USPACE_PATH)/app/sportdmp/sportdmp \
  • kernel/arch/amd64/Makefile.inc

    rb8e75319 raf2a76c  
    3232
    3333FPU_NO_CFLAGS = -mno-sse -mno-sse2
    34 CMN1 = -m64 -mcmodel=large -mno-red-zone -fno-unwind-tables -fno-omit-frame-pointer
     34CMN1 = -m64 -mcmodel=kernel -mno-red-zone -fno-unwind-tables -fno-omit-frame-pointer
    3535GCC_CFLAGS += $(CMN1)
    3636ICC_CFLAGS += $(CMN1)
  • kernel/arch/amd64/include/arch/mm/km.h

    rb8e75319 raf2a76c  
    3838#include <typedefs.h>
    3939
    40 #define KM_AMD64_IDENTITY_START         UINT64_C(0xffff800000000000)
    41 #define KM_AMD64_IDENTITY_SIZE          UINT64_C(0x0000400000000000)
     40#define KM_AMD64_IDENTITY_START         UINT64_C(0xffffffff80000000)
     41#define KM_AMD64_IDENTITY_SIZE          UINT64_C(0x0000000080000000)
    4242
    43 #define KM_AMD64_NON_IDENTITY_START     UINT64_C(0xffffc00000000000)
    44 #define KM_AMD64_NON_IDENTITY_SIZE      UINT64_C(0x0000400000000000)
     43#define KM_AMD64_NON_IDENTITY_START     UINT64_C(0xffff800000000000)
     44#define KM_AMD64_NON_IDENTITY_SIZE      UINT64_C(0x00007fff80000000)
    4545
    4646extern void km_identity_arch_init(void);
  • kernel/arch/amd64/include/arch/mm/page.h

    rb8e75319 raf2a76c  
    4444#ifndef __ASM__
    4545
    46 #define KA2PA(x)  (((uintptr_t) (x)) - UINT64_C(0xffff800000000000))
    47 #define PA2KA(x)  (((uintptr_t) (x)) + UINT64_C(0xffff800000000000))
     46#define KA2PA(x)  (((uintptr_t) (x)) - UINT64_C(0xffffffff80000000))
     47#define PA2KA(x)  (((uintptr_t) (x)) + UINT64_C(0xffffffff80000000))
    4848
    4949#else /* __ASM__ */
    5050
    51 #define KA2PA(x)  ((x) - 0xffff800000000000)
    52 #define PA2KA(x)  ((x) + 0xffff800000000000)
     51#define KA2PA(x)  ((x) - 0xffffffff80000000)
     52#define PA2KA(x)  ((x) + 0xffffffff80000000)
    5353
    5454#endif /* __ASM__ */
  • kernel/arch/amd64/src/boot/multiboot.S

    rb8e75319 raf2a76c  
    428428       
    429429        /* Call arch_pre_main(multiboot_eax, multiboot_ebx) */
    430         xorq %rdi, %rdi
    431430        movl multiboot_eax, %edi
    432         xorq %rsi, %rsi
    433431        movl multiboot_ebx, %esi
    434        
    435         movabsq $arch_pre_main, %rax
    436         callq *%rax
    437        
     432        callq arch_pre_main
     433
    438434        long_status $status_main
    439435       
    440436        /* Call main_bsp() */
    441         movabsq $main_bsp, %rax
    442         call *%rax
     437        callq main_bsp
    443438       
    444439        /* Not reached */
     
    638633        .quad ptl_2_6g + (PTL_WRITABLE | PTL_PRESENT)
    639634        .quad ptl_2_7g + (PTL_WRITABLE | PTL_PRESENT)
    640         .fill 504, 8, 0
     635        .fill 502, 8, 0
     636        /* Mapping of [0; 2G) at -2G */
     637        .quad ptl_2_0g + (PTL_WRITABLE | PTL_PRESENT)
     638        .quad ptl_2_1g + (PTL_WRITABLE | PTL_PRESENT)
     639
    641640
    642641.align 4096
     
    644643ptl_0:
    645644        .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
    646         .fill 255, 8, 0
     645        .fill 510, 8, 0
    647646        .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
    648         .fill 255, 8, 0
    649647
    650648.section K_DATA_START, "aw", @progbits
  • kernel/arch/amd64/src/boot/multiboot2.S

    rb8e75319 raf2a76c  
    244244       
    245245        /* Call arch_pre_main(multiboot_eax, multiboot_ebx) */
    246         xorq %rdi, %rdi
    247246        movl multiboot_eax, %edi
    248         xorq %rsi, %rsi
    249247        movl multiboot_ebx, %esi
    250        
    251         movabsq $arch_pre_main, %rax
    252         callq *%rax
     248        callq arch_pre_main
    253249       
    254250        /* Call main_bsp() */
    255         movabsq $main_bsp, %rax
    256         call *%rax
     251        callq main_bsp
    257252       
    258253        /* Not reached */
  • kernel/arch/amd64/src/mm/km.c

    rb8e75319 raf2a76c  
    4040{
    4141        config.identity_base = KM_AMD64_IDENTITY_START;
    42         config.identity_size = KM_AMD64_IDENTITY_SIZE; 
     42        config.identity_size = KM_AMD64_IDENTITY_SIZE;
    4343}
    4444
  • kernel/genarch/src/mm/page_pt.c

    rb8e75319 raf2a76c  
    384384            addr - 1 < base + size - 1;
    385385            addr += ptl0_step) {
     386                if (GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(addr))) {
     387                        ASSERT(overlaps(addr, ptl0_step,
     388                            config.identity_base, config.identity_size));
     389
     390                        /*
     391                         * This PTL0 entry also maps the kernel identity region,
     392                         * so it is already global and initialized.
     393                         */
     394                        continue;
     395                }
     396
    386397                uintptr_t l1 = PA2KA(frame_alloc(frames, FRAME_LOWMEM, 0));
    387398                memsetb((void *) l1, FRAMES2SIZE(frames), 0);
  • uspace/Makefile

    rb8e75319 raf2a76c  
    7777        app/nettest2 \
    7878        app/nettest3 \
     79        app/nic \
    7980        app/ping \
    8081        app/sysinfo \
  • uspace/app/mixerctl/mixerctl.c

    rb8e75319 raf2a76c  
    3535#include <assert.h>
    3636#include <errno.h>
     37#include <loc.h>
    3738#include <str_error.h>
    3839#include <str.h>
    39 #include <devman.h>
    4040#include <audio_mixer_iface.h>
    4141#include <stdio.h>
    4242
    43 #define DEFAULT_DEVICE "/hw/pci0/00:01.0/sb16/control"
     43#define DEFAULT_SERVICE "devices/\\hw\\pci0\\00:01.0\\sb16\\control"
    4444
    4545/**
     
    128128int main(int argc, char *argv[])
    129129{
    130         const char *device = DEFAULT_DEVICE;
     130        const char *service = DEFAULT_SERVICE;
    131131        void (*command)(async_exch_t *, int, char*[]) = NULL;
    132132
     
    134134                command = set_level;
    135135                if (argc == 5)
    136                         device = argv[1];
     136                        service = argv[1];
    137137        }
    138138
     
    140140                command = get_level;
    141141                if (argc == 4)
    142                         device = argv[1];
     142                        service = argv[1];
    143143        }
    144144
    145145        if ((argc == 2 && command == NULL))
    146                 device = argv[1];
     146                service = argv[1];
    147147
    148148
    149         devman_handle_t mixer_handle;
    150         int ret = devman_fun_get_handle(device, &mixer_handle, 0);
    151         if (ret != EOK) {
    152                 printf("Failed to get device(%s) handle: %s.\n",
    153                     device, str_error(ret));
     149        service_id_t mixer_sid;
     150        int rc = loc_service_get_id(service, &mixer_sid, 0);
     151        if (rc != EOK) {
     152                printf("Failed to resolve service '%s': %s.\n",
     153                    service, str_error(rc));
    154154                return 1;
    155155        }
    156156
    157         async_sess_t *session = devman_device_connect(
    158             EXCHANGE_ATOMIC, mixer_handle, IPC_FLAG_BLOCKING);
     157        async_sess_t *session = loc_service_connect(
     158            EXCHANGE_ATOMIC, mixer_sid, 0);
    159159        if (!session) {
    160                 printf("Failed to connect to device.\n");
     160                printf("Failed connecting mixer service '%s'.\n", service);
    161161                return 1;
    162162        }
  • uspace/app/taskdump/Makefile

    rb8e75319 raf2a76c  
    3333SOURCES = \
    3434        elf_core.c \
     35        fibrildump.c \
    3536        taskdump.c \
    3637        symtab.c
  • uspace/app/taskdump/include/fibrildump.h

    rb8e75319 raf2a76c  
    11/*
    2  * Copyright (c) 2011 Petr Koupy
     2 * Copyright (c) 2014 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libc
     29/** @addtogroup edit
    3030 * @{
    3131 */
    32 /** @file
     32/**
     33 * @file
    3334 */
    3435
    35 #ifndef LIBC_DEVICE_GRAPH_DEV_H_
    36 #define LIBC_DEVICE_GRAPH_DEV_H_
     36#ifndef FIBRILDUMP_H
     37#define FIBRILDUMP_H
    3738
    3839#include <async.h>
     40#include <symtab.h>
    3941
    40 extern int graph_dev_connect(async_sess_t *);
     42extern int fibrils_dump(symtab_t *, async_sess_t *sess);
    4143
    4244#endif
  • uspace/app/taskdump/include/symtab.h

    rb8e75319 raf2a76c  
    5050extern int symtab_load(const char *file_name, symtab_t **symtab);
    5151extern void symtab_delete(symtab_t *st);
    52 extern int symtab_name_to_addr(symtab_t *st, char *name, uintptr_t *addr);
     52extern int symtab_name_to_addr(symtab_t *st, const char *name, uintptr_t *addr);
    5353extern int symtab_addr_to_name(symtab_t *symtab, uintptr_t addr, char **name,
    5454    size_t *offs);
  • uspace/app/taskdump/include/taskdump.h

    rb8e75319 raf2a76c  
    11/*
    2  * Copyright (c) 2011 Petr Koupy
     2 * Copyright (c) 2014 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libdrv
     29/** @addtogroup edit
    3030 * @{
    3131 */
    32 /** @file
     32/**
     33 * @file
    3334 */
    3435
    35 #ifndef LIBDRV_REMOTE_GRAPH_DEV_H_
    36 #define LIBDRV_REMOTE_GRAPH_DEV_H_
     36#ifndef TASKDUMP_H
     37#define TASKDUMP_H
    3738
    38 extern remote_iface_t remote_graph_dev_iface;
     39#include <stdint.h>
     40
     41extern int td_stacktrace(uintptr_t, uintptr_t);
    3942
    4043#endif
    4144
    42 /**
    43  * @}
     45/** @}
    4446 */
  • uspace/app/taskdump/symtab.c

    rb8e75319 raf2a76c  
    202202 * @return      EOK on success, ENOENT if no such symbol was found.
    203203 */
    204 int symtab_name_to_addr(symtab_t *st, char *name, uintptr_t *addr)
     204int symtab_name_to_addr(symtab_t *st, const char *name, uintptr_t *addr)
    205205{
    206206        size_t i;
  • uspace/app/taskdump/taskdump.c

    rb8e75319 raf2a76c  
    3535#include <async.h>
    3636#include <elf/elf_linux.h>
     37#include <fibrildump.h>
    3738#include <stdio.h>
    3839#include <stdlib.h>
     
    5253#include <elf_core.h>
    5354#include <stacktrace.h>
     55#include <taskdump.h>
    5456
    5557#define LINE_BYTES 16
     
    7678static istate_t reg_state;
    7779
     80static stacktrace_ops_t td_stacktrace_ops = {
     81        .read_uintptr = td_read_uintptr
     82};
     83
    7884int main(int argc, char *argv[])
    7985{
     
    106112        if (rc < 0)
    107113                printf("Failed dumping address space areas.\n");
     114
     115        rc = fibrils_dump(app_symtab, sess);
     116        if (rc < 0)
     117                printf("Failed dumping fibrils.\n");
    108118
    109119        udebug_end(sess);
     
    311321}
    312322
     323int td_stacktrace(uintptr_t fp, uintptr_t pc)
     324{
     325        uintptr_t nfp;
     326        stacktrace_t st;
     327        char *sym_pc;
     328        int rc;
     329
     330        st.op_arg = NULL;
     331        st.ops = &td_stacktrace_ops;
     332
     333        while (stacktrace_fp_valid(&st, fp)) {
     334                sym_pc = fmt_sym_address(pc);
     335                printf("  %p: %s\n", (void *) fp, sym_pc);
     336                free(sym_pc);
     337
     338                rc = stacktrace_ra_get(&st, fp, &pc);
     339                if (rc != EOK)
     340                        return rc;
     341
     342                rc = stacktrace_fp_prev(&st, fp, &nfp);
     343                if (rc != EOK)
     344                        return rc;
     345
     346                fp = nfp;
     347        }
     348
     349        return EOK;
     350}
     351
    313352static int thread_dump(uintptr_t thash)
    314353{
    315354        istate_t istate;
    316         uintptr_t pc, fp, nfp;
    317         stacktrace_t st;
     355        uintptr_t pc, fp;
    318356        char *sym_pc;
    319357        int rc;
     
    336374        free(sym_pc);
    337375
    338         st.op_arg = NULL;
    339         st.read_uintptr = td_read_uintptr;
    340 
    341         while (stacktrace_fp_valid(&st, fp)) {
    342                 sym_pc = fmt_sym_address(pc);
    343                 printf("  %p: %s\n", (void *) fp, sym_pc);
    344                 free(sym_pc);
    345 
    346                 rc = stacktrace_ra_get(&st, fp, &pc);
    347                 if (rc != EOK)
    348                         return rc;
    349 
    350                 rc = stacktrace_fp_prev(&st, fp, &nfp);
    351                 if (rc != EOK)
    352                         return rc;
    353 
    354                 fp = nfp;
    355         }
     376        (void) td_stacktrace(fp, pc);
    356377
    357378        return EOK;
  • uspace/app/vlaunch/vlaunch.c

    rb8e75319 raf2a76c  
    200200        }
    201201       
    202         timer = fibril_timer_create();
     202        timer = fibril_timer_create(NULL);
    203203        if (!timer) {
    204204                printf("Unable to create timer.\n");
  • uspace/drv/bus/isa/isa.c

    rb8e75319 raf2a76c  
    355355
    356356        /* Get the name part of the rest of the line. */
    357         strtok(line, ":");
     357        str_tok(line, ":", NULL);
    358358        return line;
    359359}
  • uspace/drv/fb/amdm37x_dispc/amdm37x_dispc.c

    rb8e75319 raf2a76c  
    3434 */
    3535
     36#include <align.h>
    3637#include <assert.h>
    3738#include <errno.h>
  • uspace/drv/fb/amdm37x_dispc/main.c

    rb8e75319 raf2a76c  
    3535 */
    3636
     37#include <ddf/driver.h>
    3738#include <ddf/log.h>
    3839#include <errno.h>
    3940#include <str_error.h>
    4041#include <stdio.h>
    41 #include <ops/graph_dev.h>
    4242#include <graph.h>
    4343
     
    4646#define NAME  "amdm37x_dispc"
    4747
    48 static graph_dev_ops_t graph_vsl_dev_ops = {
    49         .connect = (connect_func) &graph_visualizer_connection
    50 };
     48static void graph_vsl_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     49{
     50        visualizer_t *vsl;
    5151
    52 static ddf_dev_ops_t graph_fun_ops = {
    53         .interfaces[GRAPH_DEV_IFACE] = &graph_vsl_dev_ops
    54 };
     52        vsl = (visualizer_t *) ddf_fun_data_get((ddf_fun_t *)arg);
     53        graph_visualizer_connection(vsl, iid, icall, NULL);
     54}
    5555
    5656static int amdm37x_dispc_dev_add(ddf_dev_t *dev)
     
    7474        vis->reg_svc_handle = ddf_fun_get_handle(fun);
    7575
    76         ddf_fun_set_ops(fun, &graph_fun_ops);
     76        ddf_fun_set_conn_handler(fun, graph_vsl_connection);
    7777        /* Hw part */
    7878        amdm37x_dispc_t *dispc =
  • uspace/drv/fb/kfb/kfb.c

    rb8e75319 raf2a76c  
    4040#include <task.h>
    4141#include <graph.h>
    42 #include <ops/graph_dev.h>
    4342#include "port.h"
    4443#include "kfb.h"
     
    6059};
    6160
    62 static graph_dev_ops_t graph_vsl_dev_ops = {
    63         .connect = (connect_func) &graph_visualizer_connection
    64 };
    65 
    66 ddf_dev_ops_t graph_vsl_device_ops = {
    67         .interfaces[GRAPH_DEV_IFACE] = &graph_vsl_dev_ops
    68 };
    69 
    70 static graph_dev_ops_t graph_rnd_dev_ops = {
    71         .connect = (connect_func) &graph_renderer_connection
    72 };
    73 
    74 ddf_dev_ops_t graph_rnd_device_ops = {
    75         .interfaces[GRAPH_DEV_IFACE] = &graph_rnd_dev_ops
    76 };
    77 
    7861int main(int argc, char *argv[])
    7962{
  • uspace/drv/fb/kfb/port.c

    rb8e75319 raf2a76c  
    207207};
    208208
     209static void graph_vsl_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     210{
     211        visualizer_t *vsl;
     212
     213        vsl = (visualizer_t *) ddf_fun_data_get((ddf_fun_t *)arg);
     214        graph_visualizer_connection(vsl, iid, icall, NULL);
     215}
     216
    209217int port_init(ddf_dev_t *dev)
    210218{
     
    346354                return ENOMEM;
    347355        }
    348         ddf_fun_set_ops(fun_vs, &graph_vsl_device_ops);
     356        ddf_fun_set_conn_handler(fun_vs, &graph_vsl_connection);
    349357
    350358        visualizer_t *vs = ddf_fun_data_alloc(fun_vs, sizeof(visualizer_t));
  • uspace/lib/c/arch/amd64/src/stacktrace.c

    rb8e75319 raf2a76c  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/arm32/src/stacktrace.c

    rb8e75319 raf2a76c  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/ia32/src/stacktrace.c

    rb8e75319 raf2a76c  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/ppc32/src/stacktrace.c

    rb8e75319 raf2a76c  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/sparc32/src/stacktrace.c

    rb8e75319 raf2a76c  
    5353{
    5454        uintptr_t bprev;
    55         int rc = (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV,
     55        int rc = (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV,
    5656            &bprev);
    5757        if (rc == EOK)
     
    6363int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    6464{
    65         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     65        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    6666}
    6767
  • uspace/lib/c/arch/sparc64/src/stacktrace.c

    rb8e75319 raf2a76c  
    5555        int rc;
    5656
    57         rc = (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, &bprev);
     57        rc = (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, &bprev);
    5858        if (rc == EOK)
    5959                *prev = bprev + STACK_BIAS;
     
    6363int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    6464{
    65         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     65        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    6666}
    6767
  • uspace/lib/c/generic/fibril.c

    rb8e75319 raf2a76c  
    5959static LIST_INITIALIZE(serialized_list);
    6060static LIST_INITIALIZE(manager_list);
     61static LIST_INITIALIZE(fibril_list);
    6162
    6263/** Number of threads that are executing a manager fibril. */
     
    116117       
    117118        fibril->waits_for = NULL;
     119        list_append(&fibril->all_link, &fibril_list);
    118120       
    119121        return fibril;
     
    122124void fibril_teardown(fibril_t *fibril)
    123125{
     126        list_remove(&fibril->all_link);
    124127        tls_free(fibril->tcb);
    125128        free(fibril);
  • uspace/lib/c/generic/fibril_synch.c

    rb8e75319 raf2a76c  
    448448        int rc;
    449449
    450         fibril_mutex_lock(&timer->lock);
    451 
    452         while (true) {
    453                 while (timer->state != fts_active &&
    454                     timer->state != fts_cleanup) {
    455 
    456                         if (timer->state == fts_cleanup)
    457                                 break;
    458 
    459                         fibril_condvar_wait(&timer->cv, &timer->lock);
     450        fibril_mutex_lock(timer->lockp);
     451
     452        while (timer->state != fts_cleanup) {
     453                switch (timer->state) {
     454                case fts_not_set:
     455                case fts_fired:
     456                        fibril_condvar_wait(&timer->cv, timer->lockp);
     457                        break;
     458                case fts_active:
     459                        rc = fibril_condvar_wait_timeout(&timer->cv,
     460                            timer->lockp, timer->delay);
     461                        if (rc == ETIMEOUT && timer->state == fts_active) {
     462                                timer->state = fts_fired;
     463                                timer->handler_running = true;
     464                                fibril_mutex_unlock(timer->lockp);
     465                                timer->fun(timer->arg);
     466                                fibril_mutex_lock(timer->lockp);
     467                                timer->handler_running = false;
     468                        }
     469                        break;
     470                case fts_cleanup:
     471                case fts_clean:
     472                        assert(false);
     473                        break;
    460474                }
    461 
    462                 if (timer->state == fts_cleanup)
    463                         break;
    464 
    465                 rc = fibril_condvar_wait_timeout(&timer->cv, &timer->lock,
    466                     timer->delay);
    467                 if (rc == ETIMEOUT) {
    468                         timer->state = fts_fired;
    469                         fibril_mutex_unlock(&timer->lock);
    470                         timer->fun(timer->arg);
    471                         fibril_mutex_lock(&timer->lock);
    472                 }
    473         }
    474 
    475         fibril_mutex_unlock(&timer->lock);
     475        }
     476
     477        /* Acknowledge timer fibril has finished cleanup. */
     478        timer->state = fts_clean;
     479        fibril_mutex_unlock(timer->lockp);
     480        free(timer);
     481
    476482        return 0;
    477483}
     
    481487 * @return              New timer on success, @c NULL if out of memory.
    482488 */
    483 fibril_timer_t *fibril_timer_create(void)
     489fibril_timer_t *fibril_timer_create(fibril_mutex_t *lock)
    484490{
    485491        fid_t fid;
     
    501507        timer->fibril = fid;
    502508        timer->state = fts_not_set;
     509        timer->lockp = (lock != NULL) ? lock : &timer->lock;
    503510
    504511        fibril_add_ready(fid);
    505 
    506512        return timer;
    507513}
     
    513519void fibril_timer_destroy(fibril_timer_t *timer)
    514520{
    515         fibril_mutex_lock(&timer->lock);
    516         assert(timer->state != fts_active);
     521        fibril_mutex_lock(timer->lockp);
     522        assert(timer->state == fts_not_set || timer->state == fts_fired);
     523
     524        /* Request timer fibril to terminate. */
    517525        timer->state = fts_cleanup;
    518526        fibril_condvar_broadcast(&timer->cv);
    519         fibril_mutex_unlock(&timer->lock);
     527        fibril_mutex_unlock(timer->lockp);
    520528}
    521529
     
    533541    fibril_timer_fun_t fun, void *arg)
    534542{
    535         fibril_mutex_lock(&timer->lock);
     543        fibril_mutex_lock(timer->lockp);
     544        fibril_timer_set_locked(timer, delay, fun, arg);
     545        fibril_mutex_unlock(timer->lockp);
     546}
     547
     548/** Set locked timer.
     549 *
     550 * Set timer to execute a callback function after the specified
     551 * interval. Must be called when the timer is locked.
     552 *
     553 * @param timer         Timer
     554 * @param delay         Delay in microseconds
     555 * @param fun           Callback function
     556 * @param arg           Argument for @a fun
     557 */
     558void fibril_timer_set_locked(fibril_timer_t *timer, suseconds_t delay,
     559    fibril_timer_fun_t fun, void *arg)
     560{
     561        assert(fibril_mutex_is_locked(timer->lockp));
     562        assert(timer->state == fts_not_set || timer->state == fts_fired);
    536563        timer->state = fts_active;
    537564        timer->delay = delay;
     
    539566        timer->arg = arg;
    540567        fibril_condvar_broadcast(&timer->cv);
    541         fibril_mutex_unlock(&timer->lock);
    542568}
    543569
     
    557583        fibril_timer_state_t old_state;
    558584
    559         fibril_mutex_lock(&timer->lock);
     585        fibril_mutex_lock(timer->lockp);
     586        old_state = fibril_timer_clear_locked(timer);
     587        fibril_mutex_unlock(timer->lockp);
     588
     589        return old_state;
     590}
     591
     592/** Clear locked timer.
     593 *
     594 * Clears (cancels) timer and returns last state of the timer.
     595 * This can be one of:
     596 *    - fts_not_set     If the timer has not been set or has been cleared
     597 *    - fts_active      Timer was set but did not fire
     598 *    - fts_fired       Timer fired
     599 * Must be called when the timer is locked.
     600 *
     601 * @param timer         Timer
     602 * @return              Last timer state
     603 */
     604fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *timer)
     605{
     606        fibril_timer_state_t old_state;
     607
     608        assert(fibril_mutex_is_locked(timer->lockp));
     609
     610        while (timer->handler_running)
     611                fibril_condvar_wait(&timer->cv, timer->lockp);
     612
    560613        old_state = timer->state;
    561614        timer->state = fts_not_set;
     
    565618        timer->arg = NULL;
    566619        fibril_condvar_broadcast(&timer->cv);
    567         fibril_mutex_unlock(&timer->lock);
    568620
    569621        return old_state;
  • uspace/lib/c/generic/inet.c

    rb8e75319 raf2a76c  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2013 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3434#include <ipc/services.h>
    3535#include <loc.h>
     36#include <stdlib.h>
    3637
    3738static void inet_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     
    224225       
    225226        rc = inet_ev_ops->recv(&dgram);
     227        free(dgram.data);
    226228        async_answer_0(iid, rc);
    227229}
  • uspace/lib/c/generic/stacktrace.c

    rb8e75319 raf2a76c  
    4242static int stacktrace_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data);
    4343
    44 void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc)
     44static stacktrace_ops_t basic_ops = {
     45        .read_uintptr = stacktrace_read_uintptr
     46};
     47
     48void stacktrace_print_generic(stacktrace_ops_t *ops, void *arg, uintptr_t fp,
     49    uintptr_t pc)
    4550{
    4651        stacktrace_t st;
    4752        uintptr_t nfp;
     53        int rc;
    4854
    49         st.op_arg = NULL;
    50         st.read_uintptr = stacktrace_read_uintptr;
     55        st.op_arg = arg;
     56        st.ops = ops;
    5157
    5258        while (stacktrace_fp_valid(&st, fp)) {
    5359                printf("%p: %p()\n", (void *) fp, (void *) pc);
    54                 (void) stacktrace_ra_get(&st, fp, &pc);
    55                 (void) stacktrace_fp_prev(&st, fp, &nfp);
     60                rc =  stacktrace_ra_get(&st, fp, &pc);
     61                if (rc != EOK)
     62                        break;
     63                rc = stacktrace_fp_prev(&st, fp, &nfp);
     64                if (rc != EOK)
     65                        break;
    5666                fp = nfp;
    5767        }
     68}
     69
     70void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc)
     71{
     72        stacktrace_print_generic(&basic_ops, NULL, fp, pc);
    5873}
    5974
  • uspace/lib/c/generic/str.c

    rb8e75319 raf2a76c  
    13601360}
    13611361
    1362 char *strtok(char *s, const char *delim)
    1363 {
    1364         static char *next;
    1365 
    1366         return strtok_r(s, delim, &next);
    1367 }
    1368 
    1369 char *strtok_r(char *s, const char *delim, char **next)
     1362/** Split string by delimiters.
     1363 *
     1364 * @param s             String to be tokenized. May not be NULL.
     1365 * @param delim         String with the delimiters.
     1366 * @param next          Variable which will receive the pointer to the
     1367 *                      continuation of the string following the first
     1368 *                      occurrence of any of the delimiter characters.
     1369 *                      May be NULL.
     1370 * @return              Pointer to the prefix of @a s before the first
     1371 *                      delimiter character. NULL if no such prefix
     1372 *                      exists.
     1373 */
     1374char *str_tok(char *s, const char *delim, char **next)
    13701375{
    13711376        char *start, *end;
    13721377
    1373         if (s == NULL)
    1374                 s = *next;
     1378        if (!s)
     1379                return NULL;
     1380       
     1381        size_t len = str_size(s);
     1382        size_t cur;
     1383        size_t tmp;
     1384        wchar_t ch;
    13751385
    13761386        /* Skip over leading delimiters. */
    1377         while (*s && (str_chr(delim, *s) != NULL)) ++s;
    1378         start = s;
     1387        for (tmp = cur = 0;
     1388            (ch = str_decode(s, &tmp, len)) && str_chr(delim, ch); /**/)
     1389                cur = tmp;
     1390        start = &s[cur];
    13791391
    13801392        /* Skip over token characters. */
    1381         while (*s && (str_chr(delim, *s) == NULL)) ++s;
    1382         end = s;
    1383         *next = (*s ? s + 1 : s);
    1384 
    1385         if (start == end) {
     1393        for (tmp = cur;
     1394            (ch = str_decode(s, &tmp, len)) && !str_chr(delim, ch); /**/)
     1395                cur = tmp;
     1396        end = &s[cur];
     1397        if (next)
     1398                *next = (ch ? &s[tmp] : &s[cur]);
     1399
     1400        if (start == end)
    13861401                return NULL;    /* No more tokens. */
    1387         }
    13881402
    13891403        /* Overwrite delimiter with NULL terminator. */
  • uspace/lib/c/include/fibril.h

    rb8e75319 raf2a76c  
    6767typedef struct fibril {
    6868        link_t link;
     69        link_t all_link;
    6970        context_t ctx;
    7071        void *stack;
  • uspace/lib/c/include/fibril_synch.h

    rb8e75319 raf2a76c  
    116116        /** Timer has fired and has not been cleared since */
    117117        fts_fired,
    118         /** Timer is being destroyed */
    119         fts_cleanup
     118        /** Timer fibril is requested to terminate */
     119        fts_cleanup,
     120        /** Timer fibril acknowledged termination */
     121        fts_clean
    120122} fibril_timer_state_t;
    121123
     
    129131typedef struct {
    130132        fibril_mutex_t lock;
     133        fibril_mutex_t *lockp;
    131134        fibril_condvar_t cv;
    132135        fid_t fibril;
    133136        fibril_timer_state_t state;
     137        bool handler_running;
    134138
    135139        suseconds_t delay;
     
    160164extern void fibril_condvar_broadcast(fibril_condvar_t *);
    161165
    162 extern fibril_timer_t *fibril_timer_create(void);
     166extern fibril_timer_t *fibril_timer_create(fibril_mutex_t *);
    163167extern void fibril_timer_destroy(fibril_timer_t *);
    164168extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t,
    165169    void *);
     170extern void fibril_timer_set_locked(fibril_timer_t *, suseconds_t,
     171    fibril_timer_fun_t, void *);
    166172extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *);
     173extern fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *);
    167174
    168175#endif
  • uspace/lib/c/include/ipc/dev_iface.h

    rb8e75319 raf2a76c  
    4040        /** Character device interface */
    4141        CHAR_DEV_IFACE,
    42 
    43         /** Graphic device interface */
    44         GRAPH_DEV_IFACE,
    4542
    4643        /** Audio device mixer interface */
  • uspace/lib/c/include/stacktrace.h

    rb8e75319 raf2a76c  
    4141
    4242typedef struct {
     43        int (*read_uintptr)(void *, uintptr_t, uintptr_t *);
     44} stacktrace_ops_t;
     45
     46typedef struct {
    4347        void *op_arg;
    44         int (*read_uintptr)(void *, uintptr_t, uintptr_t *);
     48        stacktrace_ops_t *ops;
    4549} stacktrace_t;
    4650
    4751extern void stacktrace_print(void);
    4852extern void stacktrace_print_fp_pc(uintptr_t, uintptr_t);
     53extern void stacktrace_print_generic(stacktrace_ops_t *, void *, uintptr_t,
     54    uintptr_t);
    4955
    5056/*
  • uspace/lib/c/include/str.h

    rb8e75319 raf2a76c  
    109109extern char *str_ndup(const char *, size_t max_size);
    110110
     111extern char *str_tok(char *, const char *, char **);
     112
    111113extern int str_uint8_t(const char *, const char **, unsigned int, bool,
    112114    uint8_t *);
     
    132134extern unsigned long strtoul(const char *, char **, int);
    133135
    134 extern char * strtok_r(char *, const char *, char **);
    135 extern char * strtok(char *, const char *);
    136 
    137136#endif
    138137
  • uspace/lib/drv/Makefile

    rb8e75319 raf2a76c  
    4747        generic/remote_pio_window.c \
    4848        generic/remote_char_dev.c \
    49         generic/remote_graph_dev.c \
    5049        generic/remote_nic.c \
    5150        generic/remote_usb.c \
  • uspace/lib/drv/generic/dev_iface.c

    rb8e75319 raf2a76c  
    4545#include "remote_led_dev.h"
    4646#include "remote_battery_dev.h"
    47 #include "remote_graph_dev.h"
    4847#include "remote_nic.h"
    4948#include "remote_usb.h"
     
    6261                [PIO_WINDOW_DEV_IFACE] = &remote_pio_window_iface,
    6362                [CHAR_DEV_IFACE] = &remote_char_dev_iface,
    64                 [GRAPH_DEV_IFACE] = &remote_graph_dev_iface,
    6563                [NIC_DEV_IFACE] = &remote_nic_iface,
    6664                [PCI_DEV_IFACE] = &remote_pci_iface,
  • uspace/lib/graph/graph.c

    rb8e75319 raf2a76c  
    5858visualizer_t *graph_alloc_visualizer(void)
    5959{
    60         visualizer_t *vs = (visualizer_t *) malloc(sizeof(visualizer_t));
    61         if (vs == NULL) {
    62                 return NULL;
    63         }
    64        
    65         return vs;
     60        return ((visualizer_t *) malloc(sizeof(visualizer_t)));
    6661}
    6762
     
    6964{
    7065        // TODO
    71         renderer_t *rnd = (renderer_t *) malloc(sizeof(renderer_t));
    72         if (rnd == NULL) {
    73                 return NULL;
    74         }
    75 
    76         return rnd;
     66        return ((renderer_t *) malloc(sizeof(renderer_t)));
    7767}
    7868
     
    9888int graph_register_visualizer(visualizer_t *vs)
    9989{
    100         int rc = EOK;
    101        
    10290        char node[LOC_NAME_MAXLEN + 1];
    10391        snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
    10492            namespace_idx, VISUALIZER_NAME, visualizer_idx++);
    105 
     93       
    10694        category_id_t cat;
    107         rc = loc_category_get_id("visualizer", &cat, 0);
    108         if (rc != EOK) {
     95        int rc = loc_category_get_id("visualizer", &cat, 0);
     96        if (rc != EOK)
    10997                return rc;
    110         }
    111 
     98       
    11299        rc = loc_service_register(node, &vs->reg_svc_handle);
    113         if (rc != EOK) {
     100        if (rc != EOK)
    114101                return rc;
    115         }
    116 
     102       
    117103        rc = loc_service_add_to_cat(vs->reg_svc_handle, cat);
    118104        if (rc != EOK) {
     
    120106                return rc;
    121107        }
    122 
     108       
    123109        fibril_mutex_lock(&visualizer_list_mtx);
    124110        list_append(&vs->link, &visualizer_list);
    125111        fibril_mutex_unlock(&visualizer_list_mtx);
    126 
     112       
    127113        return rc;
    128114}
     
    130116int graph_register_renderer(renderer_t *rnd)
    131117{
    132         int rc = EOK;
    133 
    134118        char node[LOC_NAME_MAXLEN + 1];
    135119        snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
    136120            namespace_idx, RENDERER_NAME, renderer_idx++);
    137 
     121       
    138122        category_id_t cat;
    139         rc = loc_category_get_id("renderer", &cat, 0);
    140         if (rc != EOK) {
     123        int rc = loc_category_get_id("renderer", &cat, 0);
     124        if (rc != EOK)
    141125                return rc;
    142         }
    143 
     126       
    144127        rc = loc_service_register(node, &rnd->reg_svc_handle);
    145         if (rc != EOK) {
     128        if (rc != EOK)
    146129                return rc;
    147         }
    148 
     130       
    149131        rc = loc_service_add_to_cat(rnd->reg_svc_handle, cat);
    150132        if (rc != EOK) {
     
    152134                return rc;
    153135        }
    154 
     136       
    155137        fibril_mutex_lock(&renderer_list_mtx);
    156138        list_append(&rnd->link, &renderer_list);
    157139        fibril_mutex_unlock(&renderer_list_mtx);
    158 
     140       
    159141        return rc;
    160142}
     
    163145{
    164146        visualizer_t *vs = NULL;
    165 
     147       
    166148        fibril_mutex_lock(&visualizer_list_mtx);
     149       
    167150        list_foreach(visualizer_list, link, visualizer_t, vcur) {
    168151                if (vcur->reg_svc_handle == handle) {
     
    171154                }
    172155        }
     156       
    173157        fibril_mutex_unlock(&visualizer_list_mtx);
    174 
     158       
    175159        return vs;
    176160}
     
    179163{
    180164        renderer_t *rnd = NULL;
    181 
     165       
    182166        fibril_mutex_lock(&renderer_list_mtx);
     167       
    183168        list_foreach(renderer_list, link, renderer_t, rcur) {
    184169                if (rcur->reg_svc_handle == handle) {
     
    187172                }
    188173        }
     174       
    189175        fibril_mutex_unlock(&renderer_list_mtx);
    190 
     176       
    191177        return rnd;
    192178}
     
    194180int graph_unregister_visualizer(visualizer_t *vs)
    195181{
    196         int rc = EOK;
    197 
    198182        fibril_mutex_lock(&visualizer_list_mtx);
    199         rc = loc_service_unregister(vs->reg_svc_handle);
     183        int rc = loc_service_unregister(vs->reg_svc_handle);
    200184        list_remove(&vs->link);
    201185        fibril_mutex_unlock(&visualizer_list_mtx);
    202 
     186       
    203187        return rc;
    204188}
     
    206190int graph_unregister_renderer(renderer_t *rnd)
    207191{
    208         int rc = EOK;
    209 
    210192        fibril_mutex_lock(&renderer_list_mtx);
    211         rc = loc_service_unregister(rnd->reg_svc_handle);
     193        int rc = loc_service_unregister(rnd->reg_svc_handle);
    212194        list_remove(&rnd->link);
    213195        fibril_mutex_unlock(&renderer_list_mtx);
    214 
     196       
    215197        return rc;
    216198}
     
    225207        assert(vs->cells.data == NULL);
    226208        assert(vs->dev_ctx == NULL);
    227 
     209       
    228210        free(vs);
    229211}
     
    233215        // TODO
    234216        assert(atomic_get(&rnd->ref_cnt) == 0);
    235 
     217       
    236218        free(rnd);
    237219}
     
    242224        int ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx);
    243225        async_exchange_end(exch);
    244 
     226       
    245227        return ret;
    246228}
     
    251233        int ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle);
    252234        async_exchange_end(exch);
    253 
     235       
    254236        async_hangup(sess);
    255 
     237       
    256238        return ret;
    257239}
     
    273255                }
    274256        }
    275 
     257       
    276258        /* Driver might also deallocate resources for the current mode. */
    277259        int rc = vs->ops.yield(vs);
    278 
     260       
    279261        /* Now that the driver was given a chance to deallocate resources,
    280262         * current mode can be unset. */
    281         if (vs->mode_set) {
     263        if (vs->mode_set)
    282264                vs->mode_set = false;
    283         }
    284 
     265       
    285266        async_answer_0(iid, rc);
    286267}
     
    288269static void vs_enumerate_modes(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    289270{
     271        ipc_callid_t callid;
     272        size_t len;
     273       
     274        if (!async_data_read_receive(&callid, &len)) {
     275                async_answer_0(callid, EREFUSED);
     276                async_answer_0(iid, EREFUSED);
     277                return;
     278        }
     279       
    290280        fibril_mutex_lock(&vs->mode_mtx);
    291281        link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall));
    292 
     282       
    293283        if (link != NULL) {
    294284                vslmode_list_element_t *mode_elem =
    295285                    list_get_instance(link, vslmode_list_element_t, link);
    296                 vslmode_t mode = mode_elem->mode;
    297                 fibril_mutex_unlock(&vs->mode_mtx);
    298 
    299                 ipc_callid_t callid;
    300                 size_t len;
    301 
    302         if (!async_data_read_receive(&callid, &len)) {
    303                         async_answer_0(iid, EINVAL);
    304                         return;
    305         }
    306         int rc = async_data_read_finalize(callid, &mode, len);
    307                 if (rc != EOK) {
    308                         async_answer_0(iid, ENOMEM);
    309                         return;
    310                 }
    311 
    312                 async_answer_0(iid, EOK);
     286               
     287                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     288                async_answer_0(iid, rc);
    313289        } else {
     290                async_answer_0(callid, ENOENT);
    314291                async_answer_0(iid, ENOENT);
    315292        }
     293       
     294        fibril_mutex_unlock(&vs->mode_mtx);
    316295}
    317296
    318297static void vs_get_default_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    319298{
     299        ipc_callid_t callid;
     300        size_t len;
     301       
     302        if (!async_data_read_receive(&callid, &len)) {
     303                async_answer_0(callid, EREFUSED);
     304                async_answer_0(iid, EREFUSED);
     305                return;
     306        }
     307       
    320308        fibril_mutex_lock(&vs->mode_mtx);
    321309        vslmode_list_element_t *mode_elem = NULL;
     310       
    322311        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    323312                if (cur->mode.index == vs->def_mode_idx) {
     
    326315                }
    327316        }
    328 
    329         vslmode_t mode;
     317       
    330318        if (mode_elem != NULL) {
    331                 mode = mode_elem->mode;
    332                 fibril_mutex_unlock(&vs->mode_mtx);
    333 
    334                 ipc_callid_t callid;
    335                 size_t len;
    336 
    337                 if (!async_data_read_receive(&callid, &len)) {
    338                         async_answer_0(iid, EINVAL);
    339                         return;
    340                 }
    341                 int rc = async_data_read_finalize(callid, &mode, len);
    342                 if (rc != EOK) {
    343                         async_answer_0(iid, ENOMEM);
    344                         return;
    345                 }
    346                 async_answer_0(iid, EOK);
     319                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     320                async_answer_0(iid, rc);
    347321        } else {
    348322                fibril_mutex_unlock(&vs->mode_mtx);
     323                async_answer_0(callid, ENOENT);
    349324                async_answer_0(iid, ENOENT);
    350325        }
     326       
     327        fibril_mutex_unlock(&vs->mode_mtx);
    351328}
    352329
    353330static void vs_get_current_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    354331{
     332        ipc_callid_t callid;
     333        size_t len;
     334       
     335        if (!async_data_read_receive(&callid, &len)) {
     336                async_answer_0(callid, EREFUSED);
     337                async_answer_0(iid, EREFUSED);
     338                return;
     339        }
     340       
    355341        if (vs->mode_set) {
    356                 ipc_callid_t callid;
    357                 size_t len;
    358 
    359                 if (!async_data_read_receive(&callid, &len)) {
    360                         async_answer_0(iid, EINVAL);
    361                         return;
    362                 }
    363342                int rc = async_data_read_finalize(callid, &vs->cur_mode, len);
    364                 if (rc != EOK) {
    365                         async_answer_0(iid, ENOMEM);
    366                         return;
    367                 }
    368 
    369                 async_answer_0(iid, EOK);
     343                async_answer_0(iid, rc);
    370344        } else {
     345                async_answer_0(callid, ENOENT);
    371346                async_answer_0(iid, ENOENT);
    372347        }
     
    375350static void vs_get_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    376351{
     352        ipc_callid_t callid;
     353        size_t len;
     354       
     355        if (!async_data_read_receive(&callid, &len)) {
     356                async_answer_0(callid, EREFUSED);
     357                async_answer_0(iid, EREFUSED);
     358                return;
     359        }
     360       
    377361        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    378 
     362       
    379363        fibril_mutex_lock(&vs->mode_mtx);
    380364        vslmode_list_element_t *mode_elem = NULL;
     365       
    381366        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    382367                if (cur->mode.index == mode_idx) {
     
    385370                }
    386371        }
    387 
    388         vslmode_t mode;
     372       
    389373        if (mode_elem != NULL) {
    390                 mode = mode_elem->mode;
    391                 fibril_mutex_unlock(&vs->mode_mtx);
    392 
    393                 ipc_callid_t callid;
    394                 size_t len;
    395 
    396                 if (!async_data_read_receive(&callid, &len)) {
    397                         async_answer_0(iid, EINVAL);
    398                         return;
    399                 }
    400                 int rc = async_data_read_finalize(callid, &mode, len);
    401                 if (rc != EOK) {
    402                         async_answer_0(iid, ENOMEM);
    403                         return;
    404                 }
    405                 async_answer_0(iid, EOK);
     374                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     375                async_answer_0(iid, rc);
    406376        } else {
    407                 fibril_mutex_unlock(&vs->mode_mtx);
     377                async_answer_0(callid, ENOENT);
    408378                async_answer_0(iid, ENOENT);
    409379        }
     380       
     381        fibril_mutex_unlock(&vs->mode_mtx);
    410382}
    411383
    412384static void vs_set_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    413385{
    414         int rc = EOK;
    415 
     386        ipc_callid_t callid;
     387        size_t size;
     388        unsigned int flags;
     389       
     390        /* Retrieve the shared cell storage for the new mode. */
     391        if (!async_share_out_receive(&callid, &size, &flags)) {
     392                async_answer_0(callid, EREFUSED);
     393                async_answer_0(iid, EREFUSED);
     394                return;
     395        }
     396       
    416397        /* Retrieve mode index and version. */
    417398        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    418399        sysarg_t mode_version = IPC_GET_ARG2(*icall);
    419 
     400       
    420401        /* Find mode in the list. */
    421402        fibril_mutex_lock(&vs->mode_mtx);
    422403        vslmode_list_element_t *mode_elem = NULL;
     404       
    423405        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    424406                if (cur->mode.index == mode_idx) {
     
    427409                }
    428410        }
    429 
     411       
     412        if (mode_elem == NULL) {
     413                fibril_mutex_unlock(&vs->mode_mtx);
     414                async_answer_0(callid, ENOENT);
     415                async_answer_0(iid, ENOENT);
     416                return;
     417        }
     418       
    430419        /* Extract mode description from the list node. */
    431         vslmode_t new_mode;
    432         if (mode_elem != NULL) {
    433                 new_mode = mode_elem->mode;
    434                 fibril_mutex_unlock(&vs->mode_mtx);
    435         } else {
    436                 fibril_mutex_unlock(&vs->mode_mtx);
    437                 async_answer_0(iid, ENOENT);
    438                 return;
    439         }
    440 
     420        vslmode_t new_mode = mode_elem->mode;
     421        fibril_mutex_unlock(&vs->mode_mtx);
     422       
    441423        /* Check whether the mode is still up-to-date. */
    442424        if (new_mode.version != mode_version) {
     425                async_answer_0(callid, EINVAL);
    443426                async_answer_0(iid, EINVAL);
    444427                return;
    445428        }
    446 
    447         ipc_callid_t callid;
    448         size_t size;
    449         unsigned int flags;
    450 
    451         /* Retrieve the shared cell storage for the new mode. */
    452         if (!async_share_out_receive(&callid, &size, &flags)) {
    453                 async_answer_0(iid, EINVAL);
    454                 return;
    455         }
     429       
    456430        void *new_cell_storage;
    457         rc = async_share_out_finalize(callid, &new_cell_storage);
     431        int rc = async_share_out_finalize(callid, &new_cell_storage);
    458432        if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
    459433                async_answer_0(iid, ENOMEM);
    460434                return;
    461435        }
    462 
     436       
    463437        /* Change device internal state. */
    464438        rc = vs->ops.change_mode(vs, new_mode);
    465 
     439       
    466440        /* Device driver could not establish new mode. Rollback. */
    467441        if (rc != EOK) {
     
    470444                return;
    471445        }
    472 
    473         /* Because resources for the new mode were successfully claimed,
    474          * it is finally possible to free resources allocated for the old mode. */
     446       
     447        /*
     448         * Because resources for the new mode were successfully
     449         * claimed, it is finally possible to free resources
     450         * allocated for the old mode.
     451         */
    475452        if (vs->mode_set) {
    476453                if (vs->cells.data != NULL) {
     
    479456                }
    480457        }
    481 
     458       
    482459        /* Insert new mode into the visualizer. */
    483460        vs->cells.width = new_mode.screen_width;
     
    486463        vs->cur_mode = new_mode;
    487464        vs->mode_set = true;
    488 
     465       
    489466        async_answer_0(iid, EOK);
    490467}
     
    499476        sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0xffffffff);
    500477#endif
    501 
     478       
    502479        int rc = vs->ops.handle_damage(vs,
    503480            IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
    504481            IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall),
    505                 x_offset, y_offset);
     482            x_offset, y_offset);
    506483        async_answer_0(iid, rc);
    507484}
     
    524501        ipc_call_t call;
    525502        ipc_callid_t callid;
    526 
     503       
    527504        /* Claim the visualizer. */
    528505        if (!cas(&vs->ref_cnt, 0, 1)) {
     
    530507                return;
    531508        }
    532 
     509       
    533510        /* Accept the connection. */
    534511        async_answer_0(iid, EOK);
    535 
     512       
    536513        /* Establish callback session. */
    537514        callid = async_get_call(&call);
    538515        vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
    539         if (vs->notif_sess != NULL) {
     516        if (vs->notif_sess != NULL)
    540517                async_answer_0(callid, EOK);
    541         } else {
     518        else
    542519                async_answer_0(callid, ELIMIT);
    543         }
    544 
     520       
    545521        /* Enter command loop. */
    546522        while (true) {
    547523                callid = async_get_call(&call);
    548 
     524               
    549525                if (!IPC_GET_IMETHOD(call)) {
    550526                        async_answer_0(callid, EINVAL);
    551527                        break;
    552528                }
    553 
     529               
    554530                switch (IPC_GET_IMETHOD(call)) {
    555531                case VISUALIZER_CLAIM:
     
    588564                }
    589565        }
    590 
     566       
    591567terminate:
    592568        async_hangup(vs->notif_sess);
     
    599575{
    600576        // TODO
    601 
     577       
    602578        ipc_call_t call;
    603579        ipc_callid_t callid;
    604 
     580       
    605581        /* Accept the connection. */
    606582        atomic_inc(&rnd->ref_cnt);
    607583        async_answer_0(iid, EOK);
    608 
     584       
    609585        /* Enter command loop. */
    610586        while (true) {
    611587                callid = async_get_call(&call);
    612 
     588               
    613589                if (!IPC_GET_IMETHOD(call)) {
    614590                        async_answer_0(callid, EINVAL);
    615591                        break;
    616592                }
    617 
     593               
    618594                switch (IPC_GET_IMETHOD(call)) {
    619595                default:
     
    622598                }
    623599        }
    624 
     600       
    625601terminate:
    626602        atomic_dec(&rnd->ref_cnt);
     
    632608        visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG1(*icall));
    633609        renderer_t *rnd = graph_get_renderer(IPC_GET_ARG1(*icall));
    634 
    635         if (vs != NULL) {
     610       
     611        if (vs != NULL)
    636612                graph_visualizer_connection(vs, iid, icall, arg);
    637         } else if (rnd != NULL) {
     613        else if (rnd != NULL)
    638614                graph_renderer_connection(rnd, iid, icall, arg);
    639         } else {
     615        else
    640616                async_answer_0(iid, ENOENT);
    641         }
    642617}
    643618
  • uspace/srv/devman/main.c

    rb8e75319 raf2a76c  
    116116               
    117117                fwd_h = dev->pfun->handle;
    118         } else if (dev->state == DEVICE_USABLE) {
     118        } else {
    119119                /* Connect to the specified function */
    120120                driver = dev->drv;
    121                 assert(driver != NULL);
    122                
    123121                fwd_h = handle;
    124122        }
  • uspace/srv/fs/fat/fat_ops.c

    rb8e75319 raf2a76c  
    930930        /* Parse mount options. */
    931931        char *mntopts = (char *) opts;
    932         char *saveptr;
    933932        char *opt;
    934         while ((opt = strtok_r(mntopts, " ,", &saveptr)) != NULL) {
     933        while ((opt = str_tok(mntopts, " ,", &mntopts)) != NULL) {
    935934                if (str_cmp(opt, "wtcache") == 0)
    936935                        cmode = CACHE_MODE_WT;
    937936                else if (str_cmp(opt, "nolfn") == 0)
    938937                        instance->lfn_enabled = false;
    939                 mntopts = NULL;
    940938        }
    941939
  • uspace/srv/hid/compositor/compositor.c

    rb8e75319 raf2a76c  
    5555#include <async.h>
    5656#include <loc.h>
    57 #include <devman.h>
    5857
    5958#include <event.h>
    60 #include <graph_iface.h>
    6159#include <io/keycode.h>
    6260#include <io/mode.h>
     
    11491147}
    11501148
    1151 static async_sess_t *vsl_connect(const char *svc)
     1149static async_sess_t *vsl_connect(service_id_t sid, const char *svc)
    11521150{
    11531151        int rc;
    11541152        async_sess_t *sess;
    1155         service_id_t dsid;
    1156         devman_handle_t handle;
    1157 
    1158         rc = loc_service_get_id(svc, &dsid, 0);
    1159         if (rc != EOK) {
     1153
     1154        sess = loc_service_connect(EXCHANGE_SERIALIZE, sid, 0);
     1155        if (sess == NULL) {
     1156                printf("%s: Unable to connect to visualizer %s\n", NAME, svc);
    11601157                return NULL;
    11611158        }
    11621159
    1163         rc = devman_fun_sid_to_handle(dsid, &handle);
    1164         if (rc == EOK) {
    1165                 sess = devman_device_connect(EXCHANGE_SERIALIZE, handle, 0);
    1166                 if (sess == NULL) {
    1167                         printf("%s: Unable to connect to visualizer %s\n", NAME, svc);
    1168                         return NULL;
    1169                 }
    1170                 rc = graph_dev_connect(sess);
    1171                 if (rc != EOK) {
    1172                         return NULL;
    1173                 }
    1174         } else if (rc == ENOENT) {
    1175                 sess = loc_service_connect(EXCHANGE_SERIALIZE, dsid, 0);
    1176                 if (sess == NULL) {
    1177                         printf("%s: Unable to connect to visualizer %s\n", NAME, svc);
    1178                         return NULL;
    1179                 }
    1180         } else {
    1181                 return NULL;
    1182         }
    1183 
    11841160        async_exch_t *exch = async_exchange_begin(sess);
    1185         rc = async_connect_to_me(exch, dsid, 0, 0, vsl_notifications, NULL);
     1161        rc = async_connect_to_me(exch, sid, 0, 0, vsl_notifications, NULL);
    11861162        async_exchange_end(exch);
    11871163
     
    11961172}
    11971173
    1198 static viewport_t *viewport_create(const char *vsl_name)
     1174static viewport_t *viewport_create(service_id_t sid)
    11991175{
    12001176        int rc;
    1201 
    1202         viewport_t *vp = (viewport_t *) malloc(sizeof(viewport_t));
    1203         if (!vp) {
    1204                 return NULL;
    1205         }
     1177        char *vsl_name = NULL;
     1178        viewport_t *vp = NULL;
     1179        bool claimed = false;
     1180
     1181        rc = loc_service_get_name(sid, &vsl_name);
     1182        if (rc != EOK)
     1183                goto error;
     1184
     1185        vp = (viewport_t *) calloc(1, sizeof(viewport_t));
     1186        if (!vp)
     1187                goto error;
    12061188
    12071189        link_initialize(&vp->link);
     
    12101192
    12111193        /* Establish output bidirectional connection. */
    1212         vp->sess = vsl_connect(vsl_name);
    1213         rc = loc_service_get_id(vsl_name, &vp->dsid, 0);
    1214         if (vp->sess == NULL || rc != EOK) {
    1215                 free(vp);
    1216                 return NULL;
    1217         }
     1194        vp->dsid = sid;
     1195        vp->sess = vsl_connect(sid, vsl_name);
     1196        if (vp->sess == NULL)
     1197                goto error;
    12181198
    12191199        /* Claim the given visualizer. */
    12201200        rc = visualizer_claim(vp->sess, 0);
    12211201        if (rc != EOK) {
    1222                 async_hangup(vp->sess);
    1223                 free(vp);
    12241202                printf("%s: Unable to claim visualizer (%s)\n", NAME, str_error(rc));
    1225                 return NULL;
    1226         }
     1203                goto error;
     1204        }
     1205
     1206        claimed = true;
    12271207
    12281208        /* Retrieve the default mode. */
    12291209        rc = visualizer_get_default_mode(vp->sess, &vp->mode);
    12301210        if (rc != EOK) {
    1231                 visualizer_yield(vp->sess);
    1232                 async_hangup(vp->sess);
    1233                 free(vp);
    12341211                printf("%s: Unable to retrieve mode (%s)\n", NAME, str_error(rc));
    1235                 return NULL;
     1212                goto error;
    12361213        }
    12371214
     
    12401217            NULL, SURFACE_FLAG_SHARED);
    12411218        if (vp->surface == NULL) {
    1242                 visualizer_yield(vp->sess);
    1243                 async_hangup(vp->sess);
    1244                 free(vp);
    12451219                printf("%s: Unable to create surface (%s)\n", NAME, str_error(rc));
    1246                 return NULL;
     1220                goto error;
    12471221        }
    12481222
     
    12511225                vp->mode.index, vp->mode.version, surface_direct_access(vp->surface));
    12521226        if (rc != EOK) {
     1227                printf("%s: Unable to set mode (%s)\n", NAME, str_error(rc));
     1228                goto error;
     1229        }
     1230
     1231        return vp;
     1232error:
     1233        if (claimed)
    12531234                visualizer_yield(vp->sess);
    1254                 surface_destroy(vp->surface);
     1235        if (vp->sess != NULL)
    12551236                async_hangup(vp->sess);
    1256                 free(vp);
    1257                 printf("%s: Unable to set mode (%s)\n", NAME, str_error(rc));
    1258                 return NULL;
    1259         }
    1260 
    1261         return vp;
     1237        free(vp);
     1238        free(vsl_name);
     1239        return NULL;
    12621240}
    12631241
     
    21902168                        continue;
    21912169               
    2192                 char *svc_name;
    2193                 rc = loc_service_get_name(svcs[i], &svc_name);
    2194                 if (rc == EOK) {
    2195                         viewport_t *vp = viewport_create(svc_name);
    2196                         if (vp != NULL) {
    2197                                 list_append(&vp->link, &viewport_list);
    2198                         }
    2199                 }
     2170                viewport_t *vp = viewport_create(svcs[i]);
     2171                if (vp != NULL)
     2172                        list_append(&vp->link, &viewport_list);
    22002173        }
    22012174        fibril_mutex_unlock(&viewport_list_mtx);
  • uspace/srv/logger/initlvl.c

    rb8e75319 raf2a76c  
    4444{
    4545        char *tmp;
    46         char *key = strtok_r(setting, "=", &tmp);
    47         char *value = strtok_r(NULL, "=", &tmp);
     46        char *key = str_tok(setting, "=", &tmp);
     47        char *value = str_tok(tmp, "=", &tmp);
    4848        if (key == NULL)
    4949                return;
     
    7676{
    7777        char *tmp;
    78         char *single_setting = strtok_r(settings, " ", &tmp);
     78        char *single_setting = str_tok(settings, " ", &tmp);
    7979        while (single_setting != NULL) {
    8080                parse_single_level_setting(single_setting);
    81                 single_setting = strtok_r(NULL, " ", &tmp);
     81                single_setting = str_tok(tmp, " ", &tmp);
    8282        }
    8383}
  • uspace/srv/net/dhcp/dhcp.c

    rb8e75319 raf2a76c  
    304304                        break;
    305305                case opt_dns_server:
    306                         if (opt_len != 4)
     306                        if (opt_len < 4 || opt_len % 4 != 0)
    307307                                return EINVAL;
     308                        /* XXX Handle multiple DNS servers properly */
    308309                        inet_addr_set(dhcp_uint32_decode(&msgb[i]),
    309310                            &offer->dns_server);
     
    435436
    436437        dlink->link_id = link_id;
    437         dlink->timeout = fibril_timer_create();
     438        dlink->timeout = fibril_timer_create(NULL);
    438439        if (dlink->timeout == NULL) {
    439440                rc = ENOMEM;
  • uspace/srv/net/inetsrv/inetsrv.c

    rb8e75319 raf2a76c  
    296296       
    297297        uint8_t ttl = IPC_GET_ARG3(*icall);
    298         int df = IPC_GET_ARG3(*icall);
     298        int df = IPC_GET_ARG4(*icall);
    299299       
    300300        ipc_callid_t callid;
  • uspace/srv/net/tcp/conn.c

    rb8e75319 raf2a76c  
    7878                goto error;
    7979
    80         conn->tw_timer = fibril_timer_create();
     80        fibril_mutex_initialize(&conn->lock);
     81
     82        conn->tw_timer = fibril_timer_create(&conn->lock);
    8183        if (conn->tw_timer == NULL)
    8284                goto error;
    83 
    84         fibril_mutex_initialize(&conn->lock);
    8585
    8686        /* One for the user, one for not being in closed state */
     
    200200        if (atomic_predec(&conn->refcnt) == 0)
    201201                tcp_conn_free(conn);
     202}
     203
     204/** Lock connection.
     205 *
     206 * Must be called before any other connection-manipulating function,
     207 * except tcp_conn_{add|del}ref(). Locks the connection including
     208 * its timers. Must not be called inside any of the connection
     209 * timer handlers.
     210 *
     211 * @param conn          Connection
     212 */
     213void tcp_conn_lock(tcp_conn_t *conn)
     214{
     215        fibril_mutex_lock(&conn->lock);
     216}
     217
     218/** Unlock connection.
     219 *
     220 * @param conn          Connection
     221 */
     222void tcp_conn_unlock(tcp_conn_t *conn)
     223{
     224        fibril_mutex_unlock(&conn->lock);
    202225}
    203226
     
    11831206        log_msg(LOG_DEFAULT, LVL_DEBUG, "tw_timeout_func(%p)", conn);
    11841207
    1185         fibril_mutex_lock(&conn->lock);
     1208        tcp_conn_lock(conn);
    11861209
    11871210        if (conn->cstate == st_closed) {
    11881211                log_msg(LOG_DEFAULT, LVL_DEBUG, "Connection already closed.");
    1189                 fibril_mutex_unlock(&conn->lock);
     1212                tcp_conn_unlock(conn);
    11901213                tcp_conn_delref(conn);
    11911214                return;
     
    11961219        tcp_conn_state_set(conn, st_closed);
    11971220
    1198         fibril_mutex_unlock(&conn->lock);
     1221        tcp_conn_unlock(conn);
    11991222        tcp_conn_delref(conn);
     1223
     1224        log_msg(LOG_DEFAULT, LVL_DEBUG, "tw_timeout_func(%p) end", conn);
    12001225}
    12011226
     
    12061231void tcp_conn_tw_timer_set(tcp_conn_t *conn)
    12071232{
     1233        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_set() begin");
    12081234        tcp_conn_addref(conn);
    1209         fibril_timer_set(conn->tw_timer, TIME_WAIT_TIMEOUT, tw_timeout_func,
    1210             (void *)conn);
     1235        fibril_timer_set_locked(conn->tw_timer, TIME_WAIT_TIMEOUT,
     1236            tw_timeout_func, (void *)conn);
     1237        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_set() end");
    12111238}
    12121239
     
    12171244void tcp_conn_tw_timer_clear(tcp_conn_t *conn)
    12181245{
    1219         if (fibril_timer_clear(conn->tw_timer) == fts_active)
     1246        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_clear() begin");
     1247        if (fibril_timer_clear_locked(conn->tw_timer) == fts_active)
    12201248                tcp_conn_delref(conn);
     1249        log_msg(LOG_DEFAULT, LVL_DEBUG2, "tcp_conn_tw_timer_clear() end");
    12211250}
    12221251
  • uspace/srv/net/tcp/conn.h

    rb8e75319 raf2a76c  
    5050extern void tcp_conn_addref(tcp_conn_t *);
    5151extern void tcp_conn_delref(tcp_conn_t *);
     52extern void tcp_conn_lock(tcp_conn_t *);
     53extern void tcp_conn_unlock(tcp_conn_t *);
    5254extern bool tcp_conn_got_syn(tcp_conn_t *);
    5355extern void tcp_conn_segment_arrived(tcp_conn_t *, tcp_segment_t *);
  • uspace/srv/net/tcp/iqueue.c

    rb8e75319 raf2a76c  
    148148        list_remove(&iqe->link);
    149149        *seg = iqe->seg;
     150        free(iqe);
    150151
    151152        return EOK;
  • uspace/srv/net/tcp/rqueue.c

    rb8e75319 raf2a76c  
    141141
    142142                tcp_as_segment_arrived(&rqe->sp, rqe->seg);
     143                free(rqe);
    143144        }
    144145
  • uspace/srv/net/tcp/segment.c

    rb8e75319 raf2a76c  
    5151void tcp_segment_delete(tcp_segment_t *seg)
    5252{
     53        free(seg->dfptr);
    5354        free(seg);
    5455}
  • uspace/srv/net/tcp/tcp.c

    rb8e75319 raf2a76c  
    151151        if (rc != EOK)
    152152                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to transmit PDU.");
     153
     154        free(pdu_raw);
    153155}
    154156
  • uspace/srv/net/tcp/tqueue.c

    rb8e75319 raf2a76c  
    5959static void tcp_tqueue_timer_clear(tcp_conn_t *conn);
    6060
     61#include <stdio.h>
    6162int tcp_tqueue_init(tcp_tqueue_t *tqueue, tcp_conn_t *conn)
    6263{
     64        printf("tcp_tqueue_init\n");
    6365        tqueue->conn = conn;
    64         tqueue->timer = fibril_timer_create();
     66        tqueue->timer = fibril_timer_create(&conn->lock);
    6567        if (tqueue->timer == NULL)
    6668                return ENOMEM;
     
    7880void tcp_tqueue_fini(tcp_tqueue_t *tqueue)
    7981{
     82        printf("tcp_tqueue_fini\n");
    8083        if (tqueue->timer != NULL) {
    8184                fibril_timer_destroy(tqueue->timer);
     
    9295        seg = tcp_segment_make_ctrl(ctrl);
    9396        tcp_tqueue_seg(conn, seg);
     97        tcp_segment_delete(seg);
    9498}
    9599
     
    212216
    213217        tcp_tqueue_seg(conn, seg);
     218        tcp_segment_delete(seg);
    214219}
    215220
     
    317322        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: retransmit_timeout_func(%p)", conn->name, conn);
    318323
    319         fibril_mutex_lock(&conn->lock);
     324        tcp_conn_lock(conn);
    320325
    321326        if (conn->cstate == st_closed) {
    322327                log_msg(LOG_DEFAULT, LVL_DEBUG, "Connection already closed.");
    323                 fibril_mutex_unlock(&conn->lock);
     328                tcp_conn_unlock(conn);
    324329                tcp_conn_delref(conn);
    325330                return;
     
    329334        if (link == NULL) {
    330335                log_msg(LOG_DEFAULT, LVL_DEBUG, "Nothing to retransmit");
    331                 fibril_mutex_unlock(&conn->lock);
     336                tcp_conn_unlock(conn);
    332337                tcp_conn_delref(conn);
    333338                return;
     
    339344        if (rt_seg == NULL) {
    340345                log_msg(LOG_DEFAULT, LVL_ERROR, "Memory allocation failed.");
    341                 fibril_mutex_unlock(&conn->lock);
     346                tcp_conn_unlock(conn);
    342347                tcp_conn_delref(conn);
    343348                /* XXX Handle properly */
     
    351356        tcp_tqueue_timer_set(tqe->conn);
    352357
    353         fibril_mutex_unlock(&conn->lock);
     358        tcp_conn_unlock(conn);
    354359        tcp_conn_delref(conn);
     360
     361        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: retransmit_timeout_func(%p) end", conn->name, conn);
    355362}
    356363
     
    358365static void tcp_tqueue_timer_set(tcp_conn_t *conn)
    359366{
    360         log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set()", conn->name);
     367        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set() begin", conn->name);
    361368
    362369        /* Clear first to make sure we update refcnt correctly */
     
    364371
    365372        tcp_conn_addref(conn);
    366         fibril_timer_set(conn->retransmit.timer, RETRANSMIT_TIMEOUT,
     373        fibril_timer_set_locked(conn->retransmit.timer, RETRANSMIT_TIMEOUT,
    367374            retransmit_timeout_func, (void *) conn);
     375
     376        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_set() end", conn->name);
    368377}
    369378
     
    371380static void tcp_tqueue_timer_clear(tcp_conn_t *conn)
    372381{
    373         log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear()", conn->name);
    374 
    375         if (fibril_timer_clear(conn->retransmit.timer) == fts_active)
     382        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear() begin", conn->name);
     383
     384        if (fibril_timer_clear_locked(conn->retransmit.timer) == fts_active)
    376385                tcp_conn_delref(conn);
     386
     387        log_msg(LOG_DEFAULT, LVL_DEBUG, "### %s: tcp_tqueue_timer_clear() end", conn->name);
    377388}
    378389
  • uspace/srv/net/tcp/ucall.c

    rb8e75319 raf2a76c  
    9090        /* Wait for connection to be established or reset */
    9191        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Wait for connection.");
    92         fibril_mutex_lock(&nconn->lock);
     92        tcp_conn_lock(nconn);
    9393        while (nconn->cstate == st_listen ||
    9494            nconn->cstate == st_syn_sent ||
     
    100100                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Connection was reset.");
    101101                assert(nconn->cstate == st_closed);
    102                 fibril_mutex_unlock(&nconn->lock);
     102                tcp_conn_unlock(nconn);
    103103                return TCP_ERESET;
    104104        }
    105105
    106         fibril_mutex_unlock(&nconn->lock);
     106        tcp_conn_unlock(nconn);
    107107        log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_open: Connection was established.");
    108108
     
    121121        log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_send()", conn->name);
    122122
    123         fibril_mutex_lock(&conn->lock);
     123        tcp_conn_lock(conn);
    124124
    125125        if (conn->cstate == st_closed) {
    126                 fibril_mutex_unlock(&conn->lock);
     126                tcp_conn_unlock(conn);
    127127                return TCP_ENOTEXIST;
    128128        }
     
    135135
    136136        if (conn->snd_buf_fin) {
    137                 fibril_mutex_unlock(&conn->lock);
     137                tcp_conn_unlock(conn);
    138138                return TCP_ECLOSING;
    139139        }
     
    149149
    150150                if (conn->reset) {
    151                         fibril_mutex_unlock(&conn->lock);
     151                        tcp_conn_unlock(conn);
    152152                        return TCP_ERESET;
    153153                }
     
    165165
    166166        tcp_tqueue_new_data(conn);
    167         fibril_mutex_unlock(&conn->lock);
     167        tcp_conn_unlock(conn);
    168168
    169169        return TCP_EOK;
     
    178178        log_msg(LOG_DEFAULT, LVL_DEBUG, "%s: tcp_uc_receive()", conn->name);
    179179
    180         fibril_mutex_lock(&conn->lock);
     180        tcp_conn_lock(conn);
    181181
    182182        if (conn->cstate == st_closed) {
    183                 fibril_mutex_unlock(&conn->lock);
     183                tcp_conn_unlock(conn);
    184184                return TCP_ENOTEXIST;
    185185        }
     
    197197                if (conn->rcv_buf_fin) {
    198198                        /* End of data, peer closed connection */
    199                         fibril_mutex_unlock(&conn->lock);
     199                        tcp_conn_unlock(conn);
    200200                        return TCP_ECLOSING;
    201201                } else {
    202202                        /* Connection was reset */
    203203                        assert(conn->reset);
    204                         fibril_mutex_unlock(&conn->lock);
     204                        tcp_conn_unlock(conn);
    205205                        return TCP_ERESET;
    206206                }
     
    227227            conn->name, xfer_size);
    228228
    229         fibril_mutex_unlock(&conn->lock);
     229        tcp_conn_unlock(conn);
    230230
    231231        return TCP_EOK;
     
    238238            conn);
    239239
    240         fibril_mutex_lock(&conn->lock);
     240        tcp_conn_lock(conn);
    241241
    242242        if (conn->cstate == st_closed) {
    243243                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - ENOTEXIST");
    244                 fibril_mutex_unlock(&conn->lock);
     244                tcp_conn_unlock(conn);
    245245                return TCP_ENOTEXIST;
    246246        }
     
    250250                tcp_conn_reset(conn);
    251251                tcp_conn_remove(conn);
     252                tcp_conn_unlock(conn);
    252253                return TCP_EOK;
    253254        }
     
    255256        if (conn->snd_buf_fin) {
    256257                log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_uc_close - ECLOSING");
    257                 fibril_mutex_unlock(&conn->lock);
     258                tcp_conn_unlock(conn);
    258259                return TCP_ECLOSING;
    259260        }
     
    263264        tcp_tqueue_new_data(conn);
    264265
    265         fibril_mutex_unlock(&conn->lock);
     266        tcp_conn_unlock(conn);
    266267        return TCP_EOK;
    267268}
     
    321322        }
    322323
    323         fibril_mutex_lock(&conn->lock);
     324        tcp_conn_lock(conn);
    324325
    325326        if (conn->cstate == st_closed) {
    326327                log_msg(LOG_DEFAULT, LVL_WARN, "Connection is closed.");
    327328                tcp_unexpected_segment(sp, seg);
    328                 fibril_mutex_unlock(&conn->lock);
     329                tcp_conn_unlock(conn);
    329330                tcp_conn_delref(conn);
    330331                return;
     
    342343        tcp_conn_segment_arrived(conn, seg);
    343344
    344         fibril_mutex_unlock(&conn->lock);
     345        tcp_conn_unlock(conn);
    345346        tcp_conn_delref(conn);
    346347}
  • uspace/srv/net/udp/udp_inet.c

    rb8e75319 raf2a76c  
    7171
    7272        udp_received_pdu(pdu);
     73
     74        /* We don't want udp_pdu_delete() to free dgram->data */
     75        pdu->data = NULL;
    7376        udp_pdu_delete(pdu);
    7477
Note: See TracChangeset for help on using the changeset viewer.