Changeset 8b5690f in mainline for kernel


Ignore:
Timestamp:
2011-02-03T05:11:01Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ba38f72c
Parents:
22027b6e (diff), 86d7bfa (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
kernel
Files:
41 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/interrupt.h

    r22027b6e r8b5690f  
    5555#define IRQ_PIC_SPUR  7
    5656#define IRQ_MOUSE     12
    57 #define IRQ_DP8390    9
     57#define IRQ_NE2000    9
    5858
    5959/* This one must have four least significant bits set to ones */
  • kernel/arch/amd64/src/amd64.c

    r22027b6e r8b5690f  
    238238                sysinfo_set_item_val(irqs_info, NULL, true);
    239239       
    240         sysinfo_set_item_val("netif.dp8390.inr", NULL, IRQ_DP8390);
     240        sysinfo_set_item_val("netif.ne2000.inr", NULL, IRQ_NE2000);
    241241}
    242242
  • kernel/arch/arm32/src/mach/gta02/gta02.c

    r22027b6e r8b5690f  
    174174                fb_parea.pbase = GTA02_FB_BASE;
    175175                fb_parea.frames = 150;
     176                fb_parea.unpriv = false;
    176177                ddi_parea_register(&fb_parea);
    177178        }
  • kernel/arch/arm32/src/mach/integratorcp/integratorcp.c

    r22027b6e r8b5690f  
    300300                fb_parea.pbase = ICP_FB;
    301301                fb_parea.frames = 300;
     302                fb_parea.unpriv = false;
    302303                ddi_parea_register(&fb_parea);
    303304        }
  • kernel/arch/ia32/_link.ld.in

    r22027b6e r8b5690f  
    4949        }
    5050       
     51#ifdef CONFIG_LINE_DEBUG
     52        .comment 0 : { *(.comment); }
     53        .debug_abbrev 0 : { *(.debug_abbrev); }
     54        .debug_aranges 0 : { *(.debug_aranges); }
     55        .debug_info 0 : { *(.debug_info); }
     56        .debug_line 0 : { *(.debug_line); }
     57        .debug_loc 0 : { *(.debug_loc); }
     58        .debug_pubnames 0 : { *(.debug_pubnames); }
     59        .debug_pubtypes 0 : { *(.debug_pubtypes); }
     60        .debug_ranges 0 : { *(.debug_ranges); }
     61        .debug_str 0 : { *(.debug_str); }
     62#endif
     63       
    5164        /DISCARD/ : {
    52                 *(.note.GNU-stack);
    53                 *(.comment);
     65                *(*);
    5466        }
    5567       
  • kernel/arch/ia32/include/interrupt.h

    r22027b6e r8b5690f  
    5555#define IRQ_PIC_SPUR  7
    5656#define IRQ_MOUSE     12
    57 #define IRQ_DP8390    5
     57#define IRQ_NE2000    5
    5858
    5959/* This one must have four least significant bits set to ones */
  • kernel/arch/ia32/src/ia32.c

    r22027b6e r8b5690f  
    196196                sysinfo_set_item_val(irqs_info, NULL, true);
    197197       
    198         sysinfo_set_item_val("netif.dp8390.inr", NULL, IRQ_DP8390);
     198        sysinfo_set_item_val("netif.ne2000.inr", NULL, IRQ_NE2000);
    199199}
    200200
  • kernel/arch/ia64/include/interrupt.h

    r22027b6e r8b5690f  
    6161#define IRQ_KBD    (0x01 + LEGACY_INTERRUPT_BASE)
    6262#define IRQ_MOUSE  (0x0c + LEGACY_INTERRUPT_BASE)
    63 #define IRQ_DP8390 (0x09 + LEGACY_INTERRUPT_BASE)
     63#define IRQ_NE2000 (0x09 + LEGACY_INTERRUPT_BASE)
    6464
    6565/** General Exception codes. */
  • kernel/arch/ia64/src/ia64.c

    r22027b6e r8b5690f  
    222222#endif
    223223
    224         sysinfo_set_item_val("netif.dp8390.inr", NULL, IRQ_DP8390);
     224        sysinfo_set_item_val("netif.ne2000.inr", NULL, IRQ_NE2000);
    225225
    226226        sysinfo_set_item_val("ia64_iospace", NULL, true);
  • kernel/arch/sparc64/src/drivers/niagara.c

    r22027b6e r8b5690f  
    216216        outbuf_parea.pbase = (uintptr_t) (KA2PA(&output_buffer));
    217217        outbuf_parea.frames = 1;
     218        outbuf_parea.unpriv = false;
    218219        ddi_parea_register(&outbuf_parea);
    219220
     
    221222        inbuf_parea.pbase = (uintptr_t) (KA2PA(&input_buffer));
    222223        inbuf_parea.frames = 1;
     224        inbuf_parea.unpriv = false;
    223225        ddi_parea_register(&inbuf_parea);
    224226
  • kernel/generic/include/ddi/ddi.h

    r22027b6e r8b5690f  
    4343/** Structure representing contiguous physical memory area. */
    4444typedef struct {
    45         uintptr_t pbase;    /**< Physical base of the area. */
    46         pfn_t frames;       /**< Number of frames in the area. */
     45        link_t link;      /**< Linked list link */
    4746       
    48         link_t link;        /**< Linked list link */
     47        uintptr_t pbase;  /**< Physical base of the area. */
     48        pfn_t frames;     /**< Number of frames in the area. */
     49        bool unpriv;      /**< Allow mapping by unprivileged tasks. */
    4950} parea_t;
    5051
     
    5455extern sysarg_t sys_physmem_map(sysarg_t, sysarg_t, sysarg_t, sysarg_t);
    5556extern sysarg_t sys_iospace_enable(ddi_ioarg_t *);
    56 extern sysarg_t sys_interrupt_enable(int irq, int enable);
    5757
    5858/*
     
    6161extern int ddi_iospace_enable_arch(task_t *, uintptr_t, size_t);
    6262
    63 
    6463#endif
    6564
  • kernel/generic/include/debug.h

    r22027b6e r8b5690f  
    5555        do { \
    5656                if (!(expr)) \
    57                         panic_assert("%s", #expr); \
     57                        panic_assert("%s() at %s:%u:\n%s", \
     58                            __func__, __FILE__, __LINE__, #expr); \
    5859        } while (0)
    5960
     
    7273        do { \
    7374                if (!(expr)) \
    74                         panic_assert("%s, %s", #expr, msg); \
     75                        panic_assert("%s() at %s:%u:\n%s, %s", \
     76                            __func__, __FILE__, __LINE__, #expr, msg); \
    7577        } while (0)
    7678
  • kernel/generic/include/ipc/event_types.h

    r22027b6e r8b5690f  
    4141        /** Returning from kernel console to userspace */
    4242        EVENT_KCONSOLE,
    43         /** A thread has faulted and will be terminated */
     43        /** A task/thread has faulted and will be terminated */
    4444        EVENT_FAULT,
    4545        EVENT_END
  • kernel/generic/include/ipc/ipc.h

    r22027b6e r8b5690f  
    165165 *                       error is sent back to caller. Otherwise
    166166 *                       the call is accepted and the response is sent back.
    167  *                     - the allocated phoneid is passed to userspace
     167 *                     - the hash of the client task is passed to userspace
     168 *                       (on the receiving side) as ARG4 of the call.
     169 *                     - the hash of the allocated phone is passed to userspace
    168170 *                       (on the receiving side) as ARG5 of the call.
    169171 *
     
    319321typedef struct {
    320322        sysarg_t args[IPC_CALL_LEN];
     323        /** Task which made or forwarded the call with IPC_FF_ROUTE_FROM_ME. */
     324        struct task *task;
     325        /** Phone which made or last masqueraded this call. */
    321326        phone_t *phone;
    322327} ipc_data_t;
     
    333338         * The caller box is different from sender->answerbox
    334339         * for synchronous calls.
    335          *
    336340         */
    337341        answerbox_t *callerbox;
     
    350354         * cases, we must keep it aside so that the answer is processed
    351355         * correctly.
    352          *
    353356         */
    354357        phone_t *caller_phone;
  • kernel/generic/include/ipc/sysipc.h

    r22027b6e r8b5690f  
    5656    unsigned int);
    5757extern sysarg_t sys_ipc_hangup(sysarg_t);
    58 extern sysarg_t sys_ipc_register_irq(inr_t, devno_t, sysarg_t, irq_code_t *);
    59 extern sysarg_t sys_ipc_unregister_irq(inr_t, devno_t);
     58extern sysarg_t sys_register_irq(inr_t, devno_t, sysarg_t, irq_code_t *);
     59extern sysarg_t sys_unregister_irq(inr_t, devno_t);
    6060
    6161#ifdef __32_BITS__
  • kernel/generic/include/proc/task.h

    r22027b6e r8b5690f  
    131131extern task_t *task_find_by_id(task_id_t);
    132132extern int task_kill(task_id_t);
     133extern void task_kill_self(bool) __attribute__((noreturn));
    133134extern void task_get_accounting(task_t *, uint64_t *, uint64_t *);
    134135extern void task_print_list(bool);
     
    155156extern sysarg_t sys_task_set_name(const char *, size_t);
    156157extern sysarg_t sys_task_kill(task_id_t *);
     158extern sysarg_t sys_task_exit(sysarg_t);
    157159
    158160#endif
  • kernel/generic/include/proc/thread.h

    r22027b6e r8b5690f  
    9191       
    9292        /** Function implementing the thread. */
    93         void (* thread_code)(void *);
     93        void (*thread_code)(void *);
    9494        /** Argument passed to thread_code() function. */
    9595        void *thread_arg;
    9696       
    9797        /**
    98          * From here, the stored context is restored when the thread is
    99          * scheduled.
     98         * From here, the stored context is restored
     99         * when the thread is scheduled.
    100100         */
    101101        context_t saved_context;
    102         /**
    103          * From here, the stored timeout context is restored when sleep times
    104          * out.
     102       
     103        /**
     104         * From here, the stored timeout context
     105         * is restored when sleep times out.
    105106         */
    106107        context_t sleep_timeout_context;
    107         /**
    108          * From here, the stored interruption context is restored when sleep is
    109          * interrupted.
     108       
     109        /**
     110         * From here, the stored interruption context
     111         * is restored when sleep is interrupted.
    110112         */
    111113        context_t sleep_interruption_context;
     
    125127         */
    126128        bool in_copy_from_uspace;
     129       
    127130        /**
    128131         * True if this thread is executing copy_to_uspace().
     
    187190       
    188191#ifdef CONFIG_UDEBUG
     192        /**
     193         * If true, the scheduler will print a stack trace
     194         * to the kernel console upon scheduling this thread.
     195         */
     196        bool btrace;
     197       
    189198        /** Debugging stuff */
    190199        udebug_thread_t udebug;
     
    237246extern bool thread_exists(thread_t *);
    238247
     248#ifdef CONFIG_UDEBUG
     249extern void thread_stack_trace(thread_id_t);
     250#endif
     251
    239252/** Fpu context slab cache. */
    240253extern slab_cache_t *fpu_context_slab;
  • kernel/generic/include/syscall/syscall.h

    r22027b6e r8b5690f  
    4848        SYS_TASK_SET_NAME,
    4949        SYS_TASK_KILL,
     50        SYS_TASK_EXIT,
    5051        SYS_PROGRAM_SPAWN_LOADER,
    5152       
     
    7071        SYS_IPC_POKE,
    7172        SYS_IPC_HANGUP,
    72         SYS_IPC_REGISTER_IRQ,
    73         SYS_IPC_UNREGISTER_IRQ,
    7473        SYS_IPC_CONNECT_KBOX,
    7574       
     
    8281        SYS_PHYSMEM_MAP,
    8382        SYS_IOSPACE_ENABLE,
    84         SYS_INTERRUPT_ENABLE,
     83        SYS_REGISTER_IRQ,
     84        SYS_UNREGISTER_IRQ,
    8585       
    8686        SYS_SYSINFO_GET_TAG,
  • kernel/generic/include/sysinfo/abi.h

    r22027b6e r8b5690f  
    104104        char name[TASK_NAME_BUFLEN];  /**< Task name (in kernel) */
    105105        size_t virtmem;               /**< Size of VAS (bytes) */
     106        size_t resmem;                /**< Size of resident (used) memory (bytes) */
    106107        size_t threads;               /**< Number of threads */
    107108        uint64_t ucycles;             /**< Number of CPU cycles in user space */
  • kernel/generic/include/sysinfo/sysinfo.h

    r22027b6e r8b5690f  
    148148extern sysarg_t sys_sysinfo_get_value(void *, size_t, void *);
    149149extern sysarg_t sys_sysinfo_get_data_size(void *, size_t, void *);
    150 extern sysarg_t sys_sysinfo_get_data(void *, size_t, void *, size_t);
     150extern sysarg_t sys_sysinfo_get_data(void *, size_t, void *, size_t, size_t *);
    151151
    152152#endif
  • kernel/generic/include/udebug/udebug.h

    r22027b6e r8b5690f  
    3636#define KERN_UDEBUG_H_
    3737
     38#define UDEBUG_EVMASK(event)  (1 << ((event) - 1))
     39
     40typedef enum { /* udebug_method_t */
     41       
     42        /** Start debugging the recipient.
     43         *
     44         * Causes all threads in the receiving task to stop. When they
     45         * are all stoped, an answer with retval 0 is generated.
     46         *
     47         */
     48        UDEBUG_M_BEGIN = 1,
     49       
     50        /** Finish debugging the recipient.
     51         *
     52         * Answers all pending GO and GUARD messages.
     53         *
     54         */
     55        UDEBUG_M_END,
     56       
     57        /** Set which events should be captured. */
     58        UDEBUG_M_SET_EVMASK,
     59       
     60        /** Make sure the debugged task is still there.
     61         *
     62         * This message is answered when the debugged task dies
     63         * or the debugging session ends.
     64         *
     65         */
     66        UDEBUG_M_GUARD,
     67       
     68        /** Run a thread until a debugging event occurs.
     69         *
     70         * This message is answered when the thread stops
     71         * in a debugging event.
     72         *
     73         * - ARG2 - id of the thread to run
     74         *
     75         */
     76        UDEBUG_M_GO,
     77       
     78        /** Stop a thread being debugged.
     79         *
     80         * Creates a special STOP event in the thread, causing
     81         * it to answer a pending GO message (if any).
     82         *
     83         */
     84        UDEBUG_M_STOP,
     85       
     86        /** Read arguments of a syscall.
     87         *
     88         * - ARG2 - thread identification
     89         * - ARG3 - destination address in the caller's address space
     90         *
     91         */
     92        UDEBUG_M_ARGS_READ,
     93       
     94        /** Read thread's userspace register state (istate_t).
     95         *
     96         * - ARG2 - thread identification
     97         * - ARG3 - destination address in the caller's address space
     98         *
     99         * or, on error, retval will be
     100         * - ENOENT - thread does not exist
     101         * - EBUSY - register state not available
     102         */
     103        UDEBUG_M_REGS_READ,
     104       
     105        /** Read the list of the debugged tasks's threads.
     106         *
     107         * - ARG2 - destination address in the caller's address space
     108         * - ARG3 - size of receiving buffer in bytes
     109         *
     110         * The kernel fills the buffer with a series of sysarg_t values
     111         * (thread ids). On answer, the kernel will set:
     112         *
     113         * - ARG2 - number of bytes that were actually copied
     114         * - ARG3 - number of bytes of the complete data
     115         *
     116         */
     117        UDEBUG_M_THREAD_READ,
     118       
     119        /** Read the name of the debugged task.
     120         *
     121         * - ARG2 - destination address in the caller's address space
     122         * - ARG3 - size of receiving buffer in bytes
     123         *
     124         * The kernel fills the buffer with a non-terminated string.
     125         *
     126         * - ARG2 - number of bytes that were actually copied
     127         * - ARG3 - number of bytes of the complete data
     128         *
     129         */
     130        UDEBUG_M_NAME_READ,
     131       
     132        /** Read the list of the debugged task's address space areas.
     133         *
     134         * - ARG2 - destination address in the caller's address space
     135         * - ARG3 - size of receiving buffer in bytes
     136         *
     137         * The kernel fills the buffer with a series of as_area_info_t structures.
     138         * Upon answer, the kernel will set:
     139         *
     140         * - ARG2 - number of bytes that were actually copied
     141         * - ARG3 - number of bytes of the complete data
     142         *
     143         */
     144        UDEBUG_M_AREAS_READ,
     145       
     146        /** Read the debugged tasks's memory.
     147         *
     148         * - ARG2 - destination address in the caller's address space
     149         * - ARG3 - source address in the recipient's address space
     150         * - ARG4 - size of receiving buffer in bytes
     151         *
     152         */
     153        UDEBUG_M_MEM_READ
     154} udebug_method_t;
     155
     156typedef enum {
     157        UDEBUG_EVENT_FINISHED = 1,  /**< Debuging session has finished */
     158        UDEBUG_EVENT_STOP,          /**< Stopped on DEBUG_STOP request */
     159        UDEBUG_EVENT_SYSCALL_B,     /**< Before beginning syscall execution */
     160        UDEBUG_EVENT_SYSCALL_E,     /**< After finishing syscall execution */
     161        UDEBUG_EVENT_THREAD_B,      /**< The task created a new thread */
     162        UDEBUG_EVENT_THREAD_E       /**< A thread exited */
     163} udebug_event_t;
     164
     165typedef enum {
     166        UDEBUG_EM_FINISHED = UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED),
     167        UDEBUG_EM_STOP = UDEBUG_EVMASK(UDEBUG_EVENT_STOP),
     168        UDEBUG_EM_SYSCALL_B = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B),
     169        UDEBUG_EM_SYSCALL_E = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E),
     170        UDEBUG_EM_THREAD_B = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B),
     171        UDEBUG_EM_THREAD_E = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E),
     172        UDEBUG_EM_ALL =
     173            (UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED) |
     174            UDEBUG_EVMASK(UDEBUG_EVENT_STOP) |
     175            UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B) |
     176            UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E) |
     177            UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B) |
     178            UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E))
     179} udebug_evmask_t;
     180
     181#ifdef KERNEL
     182
    38183#include <ipc/ipc.h>
    39 
    40 typedef enum { /* udebug_method_t */
    41 
    42 /** Start debugging the recipient.
    43  * Causes all threads in the receiving task to stop. When they
    44  * are all stoped, an answer with retval 0 is generated.
    45  */
    46 UDEBUG_M_BEGIN = 1,
    47 
    48 /** Finish debugging the recipient.
    49  * Answers all pending GO and GUARD messages.
    50  */
    51 UDEBUG_M_END,
    52 
    53 /** Set which events should be captured.
    54  */
    55 UDEBUG_M_SET_EVMASK,
    56 
    57 /** Make sure the debugged task is still there.
    58  * This message is answered when the debugged task dies
    59  * or the debugging session ends.
    60  */
    61 UDEBUG_M_GUARD,
    62 
    63 /** Run a thread until a debugging event occurs.
    64  * This message is answered when the thread stops
    65  * in a debugging event.
    66  *
    67  * - ARG2 - id of the thread to run
    68  */
    69 UDEBUG_M_GO,
    70 
    71 /** Stop a thread being debugged.
    72  * Creates a special STOP event in the thread, causing
    73  * it to answer a pending GO message (if any).
    74  */
    75 UDEBUG_M_STOP,
    76 
    77 /** Read arguments of a syscall.
    78  *
    79  * - ARG2 - thread identification
    80  * - ARG3 - destination address in the caller's address space
    81  *
    82  */
    83 UDEBUG_M_ARGS_READ,
    84 
    85 /** Read thread's userspace register state (istate_t).
    86  *
    87  * - ARG2 - thread identification
    88  * - ARG3 - destination address in the caller's address space
    89  *
    90  * or, on error, retval will be
    91  * - ENOENT - thread does not exist
    92  * - EBUSY - register state not available
    93  */
    94 UDEBUG_M_REGS_READ,
    95 
    96 /** Read the list of the debugged tasks's threads.
    97  *
    98  * - ARG2 - destination address in the caller's address space
    99  * - ARG3 - size of receiving buffer in bytes
    100  *
    101  * The kernel fills the buffer with a series of sysarg_t values
    102  * (thread ids). On answer, the kernel will set:
    103  *
    104  * - ARG2 - number of bytes that were actually copied
    105  * - ARG3 - number of bytes of the complete data
    106  *
    107  */
    108 UDEBUG_M_THREAD_READ,
    109 
    110 /** Read the name of the debugged task.
    111  *
    112  * - ARG2 - destination address in the caller's address space
    113  * - ARG3 - size of receiving buffer in bytes
    114  *
    115  * The kernel fills the buffer with a non-terminated string.
    116  *
    117  * - ARG2 - number of bytes that were actually copied
    118  * - ARG3 - number of bytes of the complete data
    119  *
    120  */
    121 UDEBUG_M_NAME_READ,
    122 
    123 /** Read the list of the debugged task's address space areas.
    124  *
    125  * - ARG2 - destination address in the caller's address space
    126  * - ARG3 - size of receiving buffer in bytes
    127  *
    128  * The kernel fills the buffer with a series of as_area_info_t structures.
    129  * Upon answer, the kernel will set:
    130  *
    131  * - ARG2 - number of bytes that were actually copied
    132  * - ARG3 - number of bytes of the complete data
    133  *
    134  */
    135 UDEBUG_M_AREAS_READ,
    136 
    137 /** Read the debugged tasks's memory.
    138  *
    139  * - ARG2 - destination address in the caller's address space
    140  * - ARG3 - source address in the recipient's address space
    141  * - ARG4 - size of receiving buffer in bytes
    142  *
    143  */
    144 UDEBUG_M_MEM_READ,
    145 
    146 } udebug_method_t;
    147 
    148 
    149 typedef enum {
    150         UDEBUG_EVENT_FINISHED = 1,      /**< Debuging session has finished */
    151         UDEBUG_EVENT_STOP,              /**< Stopped on DEBUG_STOP request */
    152         UDEBUG_EVENT_SYSCALL_B,         /**< Before beginning syscall execution */
    153         UDEBUG_EVENT_SYSCALL_E,         /**< After finishing syscall execution */
    154         UDEBUG_EVENT_THREAD_B,          /**< The task created a new thread */
    155         UDEBUG_EVENT_THREAD_E           /**< A thread exited */
    156 } udebug_event_t;
    157 
    158 #define UDEBUG_EVMASK(event) (1 << ((event) - 1))
    159 
    160 typedef enum {
    161         UDEBUG_EM_FINISHED      = UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED),
    162         UDEBUG_EM_STOP          = UDEBUG_EVMASK(UDEBUG_EVENT_STOP),
    163         UDEBUG_EM_SYSCALL_B     = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B),
    164         UDEBUG_EM_SYSCALL_E     = UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E),
    165         UDEBUG_EM_THREAD_B      = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B),
    166         UDEBUG_EM_THREAD_E      = UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E),
    167         UDEBUG_EM_ALL           =
    168                 UDEBUG_EVMASK(UDEBUG_EVENT_FINISHED) |
    169                 UDEBUG_EVMASK(UDEBUG_EVENT_STOP) |
    170                 UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_B) |
    171                 UDEBUG_EVMASK(UDEBUG_EVENT_SYSCALL_E) |
    172                 UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_B) |
    173                 UDEBUG_EVMASK(UDEBUG_EVENT_THREAD_E)
    174 } udebug_evmask_t;
    175 
    176 #ifdef KERNEL
    177 
    178184#include <synch/mutex.h>
    179185#include <synch/condvar.h>
     
    196202        mutex_t lock;
    197203        char *lock_owner;
    198 
     204       
    199205        udebug_task_state_t dt_state;
    200206        call_t *begin_call;
     
    209215        /** Synchronize debug ops on this thread / access to this structure. */
    210216        mutex_t lock;
    211 
     217       
    212218        waitq_t go_wq;
    213219        call_t *go_call;
    214220        sysarg_t syscall_args[6];
    215221        istate_t *uspace_state;
    216 
     222       
    217223        /** What type of event are we stopped in or 0 if none. */
    218224        udebug_event_t cur_event;
    219         bool go;                /**< thread is GO */
    220         bool stoppable;         /**< thread is stoppable */
    221         bool active;            /**< thread is in a debugging session */
     225        bool go;         /**< Thread is GO */
     226        bool stoppable;  /**< Thread is stoppable */
     227        bool active;     /**< Thread is in a debugging session */
    222228        condvar_t active_cv;
    223229} udebug_thread_t;
     
    226232struct thread;
    227233
    228 void udebug_task_init(udebug_task_t *ut);
    229 void udebug_thread_initialize(udebug_thread_t *ut);
    230 
    231 void udebug_syscall_event(sysarg_t a1, sysarg_t a2, sysarg_t a3,
    232     sysarg_t a4, sysarg_t a5, sysarg_t a6, sysarg_t id, sysarg_t rc,
    233     bool end_variant);
    234 
    235 void udebug_thread_b_event_attach(struct thread *t, struct task *ta);
     234void udebug_task_init(udebug_task_t *);
     235void udebug_thread_initialize(udebug_thread_t *);
     236
     237void udebug_syscall_event(sysarg_t, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
     238    sysarg_t, sysarg_t, sysarg_t, bool);
     239
     240void udebug_thread_b_event_attach(struct thread *, struct task *);
    236241void udebug_thread_e_event(void);
    237242
     
    241246void udebug_before_thread_runs(void);
    242247
    243 int udebug_task_cleanup(struct task *ta);
     248int udebug_task_cleanup(struct task *);
    244249void udebug_thread_fault(void);
    245250
  • kernel/generic/src/adt/avl.c

    r22027b6e r8b5690f  
    723723void avltree_walk(avltree_t *t, avltree_walker_t walker, void *arg)
    724724{
    725         _avltree_walk(t->root, walker, arg);
     725        if (t->root)
     726                _avltree_walk(t->root, walker, arg);
    726727}
    727728
  • kernel/generic/src/console/cmd.c

    r22027b6e r8b5690f  
    7878static cmd_info_t help_info = {
    7979        .name = "help",
    80         .description = "List of supported commands.",
     80        .description = "List supported commands.",
    8181        .func = cmd_help,
    8282        .argc = 0
    8383};
    8484
     85/* Data and methods for 'reboot' command. */
    8586static int cmd_reboot(cmd_arg_t *argv);
    8687static cmd_info_t reboot_info = {
    8788        .name = "reboot",
    88         .description = "Reboot.",
     89        .description = "Reboot system.",
    8990        .func = cmd_reboot,
    9091        .argc = 0
    9192};
    9293
     94/* Data and methods for 'uptime' command. */
    9395static int cmd_uptime(cmd_arg_t *argv);
    9496static cmd_info_t uptime_info = {
    9597        .name = "uptime",
    96         .description = "Print uptime information.",
     98        .description = "Show system uptime.",
    9799        .func = cmd_uptime,
    98100        .argc = 0
    99101};
    100102
     103/* Data and methods for 'continue' command. */
    101104static int cmd_continue(cmd_arg_t *argv);
    102105static cmd_info_t continue_info = {
     
    108111
    109112#ifdef CONFIG_TEST
     113
     114/* Data and methods for 'test' command. */
    110115static char test_buf[MAX_CMDLINE + 1];
    111116static int cmd_test(cmd_arg_t *argv);
     
    119124static cmd_info_t test_info = {
    120125        .name = "test",
    121         .description = "Print list of kernel tests or run a test.",
     126        .description = "<test> List kernel tests or run a test.",
    122127        .func = cmd_test,
    123128        .argc = 1,
     
    125130};
    126131
     132/* Data and methods for 'bench' command. */
    127133static int cmd_bench(cmd_arg_t *argv);
    128134static cmd_arg_t bench_argv[] = {
     
    138144static cmd_info_t bench_info = {
    139145        .name = "bench",
    140         .description = "Run kernel test as benchmark.",
     146        .description = "<test> <count> Run kernel test as benchmark.",
    141147        .func = cmd_bench,
    142148        .argc = 2,
    143149        .argv = bench_argv
    144150};
    145 #endif
     151
     152#endif /* CONFIG_TEST */
    146153
    147154/* Data and methods for 'description' command. */
    148155static int cmd_desc(cmd_arg_t *argv);
    149156static void desc_help(void);
    150 static char desc_buf[MAX_CMDLINE+1];
     157static char desc_buf[MAX_CMDLINE + 1];
    151158static cmd_arg_t desc_argv = {
    152159        .type = ARG_TYPE_STRING,
     
    156163static cmd_info_t desc_info = {
    157164        .name = "describe",
    158         .description = "Describe specified command.",
     165        .description = "<command> Describe specified command.",
    159166        .help = desc_help,
    160167        .func = cmd_desc,
     
    165172/* Data and methods for 'symaddr' command. */
    166173static int cmd_symaddr(cmd_arg_t *argv);
    167 static char symaddr_buf[MAX_CMDLINE+1];
     174static char symaddr_buf[MAX_CMDLINE + 1];
    168175static cmd_arg_t symaddr_argv = {
    169176        .type = ARG_TYPE_STRING,
     
    173180static cmd_info_t symaddr_info = {
    174181        .name = "symaddr",
    175         .description = "Return symbol address.",
     182        .description = "<symbol> Return symbol address.",
    176183        .func = cmd_symaddr,
    177184        .argc = 1,
     
    179186};
    180187
    181 static char set_buf[MAX_CMDLINE+1];
     188/* Data and methods for 'set4' command. */
     189static char set_buf[MAX_CMDLINE + 1];
    182190static int cmd_set4(cmd_arg_t *argv);
    183191static cmd_arg_t set4_argv[] = {
     
    193201static cmd_info_t set4_info = {
    194202        .name = "set4",
    195         .description = "set <dest_addr> <value> - 4byte version",
     203        .description = "<addr> <value> Set 4B memory location to a value.",
    196204        .func = cmd_set4,
    197205        .argc = 2,
     
    213221static cmd_info_t call0_info = {
    214222        .name = "call0",
    215         .description = "call0 <function> -> call function().",
     223        .description = "<function> Call function().",
    216224        .func = cmd_call0,
    217225        .argc = 1,
     
    228236static cmd_info_t mcall0_info = {
    229237        .name = "mcall0",
    230         .description = "mcall0 <function> -> call function() on each CPU.",
     238        .description = "<function> Call function() on each CPU.",
    231239        .func = cmd_mcall0,
    232240        .argc = 1,
     
    250258static cmd_info_t call1_info = {
    251259        .name = "call1",
    252         .description = "call1 <function> <arg1> -> call function(arg1).",
     260        .description = "<function> <arg1> Call function(arg1).",
    253261        .func = cmd_call1,
    254262        .argc = 2,
     
    277285static cmd_info_t call2_info = {
    278286        .name = "call2",
    279         .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).",
     287        .description = "<function> <arg1> <arg2> Call function(arg1, arg2).",
    280288        .func = cmd_call2,
    281289        .argc = 3,
     
    310318static cmd_info_t call3_info = {
    311319        .name = "call3",
    312         .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).",
     320        .description = "<function> <arg1> <arg2> <arg3> Call function(arg1, arg2, arg3).",
    313321        .func = cmd_call3,
    314322        .argc = 4,
     
    340348cmd_info_t tlb_info = {
    341349        .name = "tlb",
    342         .description = "Print TLB of current processor.",
     350        .description = "Print TLB of the current CPU.",
    343351        .help = NULL,
    344352        .func = cmd_tlb,
     
    377385};
    378386
     387#ifdef CONFIG_UDEBUG
     388
     389/* Data and methods for 'btrace' command */
     390static int cmd_btrace(cmd_arg_t *argv);
     391static cmd_arg_t btrace_argv = {
     392        .type = ARG_TYPE_INT,
     393};
     394static cmd_info_t btrace_info = {
     395        .name = "btrace",
     396        .description = "<threadid> Show thread stack trace.",
     397        .func = cmd_btrace,
     398        .argc = 1,
     399        .argv = &btrace_argv
     400};
     401
     402#endif /* CONFIG_UDEBUG */
    379403
    380404static int cmd_sched(cmd_arg_t *argv);
    381405static cmd_info_t sched_info = {
    382406        .name = "scheduler",
    383         .description = "List all scheduler information.",
     407        .description = "Show scheduler information.",
    384408        .func = cmd_sched,
    385409        .argc = 0
     
    406430static cmd_info_t zones_info = {
    407431        .name = "zones",
    408         .description = "List of memory zones.",
     432        .description = "List memory zones.",
    409433        .func = cmd_zones,
    410434        .argc = 0
     435};
     436
     437/* Data and methods for 'zone' command */
     438static int cmd_zone(cmd_arg_t *argv);
     439static cmd_arg_t zone_argv = {
     440        .type = ARG_TYPE_INT,
     441};
     442
     443static cmd_info_t zone_info = {
     444        .name = "zone",
     445        .description = "<zone> Show memory zone structure.",
     446        .func = cmd_zone,
     447        .argc = 1,
     448        .argv = &zone_argv
    411449};
    412450
     
    418456static cmd_info_t ipc_info = {
    419457        .name = "ipc",
    420         .description = "ipc <taskid> Show IPC information of given task.",
     458        .description = "<taskid> Show IPC information of a task.",
    421459        .func = cmd_ipc,
    422460        .argc = 1,
     
    431469static cmd_info_t kill_info = {
    432470        .name = "kill",
    433         .description = "kill <taskid> Kill a task.",
     471        .description = "<taskid> Kill a task.",
    434472        .func = cmd_kill,
    435473        .argc = 1,
    436474        .argv = &kill_argv
    437 };
    438 
    439 /* Data and methods for 'zone' command */
    440 static int cmd_zone(cmd_arg_t *argv);
    441 static cmd_arg_t zone_argv = {
    442         .type = ARG_TYPE_INT,
    443 };
    444 
    445 static cmd_info_t zone_info = {
    446         .name = "zone",
    447         .description = "Show memory zone structure.",
    448         .func = cmd_zone,
    449         .argc = 1,
    450         .argv = &zone_argv
    451475};
    452476
     
    482506        &cpus_info,
    483507        &desc_info,
    484         &reboot_info,
    485         &uptime_info,
    486508        &halt_info,
    487509        &help_info,
    488510        &ipc_info,
    489511        &kill_info,
     512        &physmem_info,
     513        &reboot_info,
     514        &sched_info,
    490515        &set4_info,
    491516        &slabs_info,
     517        &symaddr_info,
    492518        &sysinfo_info,
    493         &symaddr_info,
    494         &sched_info,
     519        &tasks_info,
    495520        &threads_info,
    496         &tasks_info,
    497         &physmem_info,
    498521        &tlb_info,
     522        &uptime_info,
    499523        &version_info,
    500524        &zones_info,
     
    504528        &bench_info,
    505529#endif
     530#ifdef CONFIG_UDEBUG
     531        &btrace_info,
     532#endif
    506533        NULL
    507534};
     
    526553        for (i = 0; basic_commands[i]; i++) {
    527554                cmd_initialize(basic_commands[i]);
    528                 if (!cmd_register(basic_commands[i]))
    529                         printf("Cannot register command %s\n", basic_commands[i]->name);
    530         }
    531 }
    532 
     555        }
     556
     557        for (i = 0; basic_commands[i]; i++) {
     558                if (!cmd_register(basic_commands[i])) {
     559                        printf("Cannot register command %s\n",
     560                            basic_commands[i]->name);
     561                }
     562        }
     563}
    533564
    534565/** List supported commands.
     
    574605}
    575606
    576 
    577607/** Reboot the system.
    578608 *
     
    588618        return 1;
    589619}
    590 
    591620
    592621/** Print system uptime information.
     
    824853}
    825854
    826 
    827855/** Print detailed description of 'describe' command. */
    828856void desc_help(void)
     
    911939 * @return Always 1
    912940 */
    913 int cmd_slabs(cmd_arg_t * argv)
     941int cmd_slabs(cmd_arg_t *argv)
    914942{
    915943        slab_print_list();
     
    923951 * @return Always 1
    924952 */
    925 int cmd_sysinfo(cmd_arg_t * argv)
     953int cmd_sysinfo(cmd_arg_t *argv)
    926954{
    927955        sysinfo_dump(NULL);
     
    929957}
    930958
    931 
    932 /** Command for listings Thread information
     959/** Command for listing thread information
    933960 *
    934961 * @param argv Ignored
     
    948975}
    949976
    950 /** Command for listings Task information
     977/** Command for listing task information
    951978 *
    952979 * @param argv Ignored
     
    966993}
    967994
    968 /** Command for listings Thread information
     995#ifdef CONFIG_UDEBUG
     996
     997/** Command for printing thread stack trace
     998 *
     999 * @param argv Integer argument from cmdline expected
     1000 *
     1001 * return Always 1
     1002 *
     1003 */
     1004int cmd_btrace(cmd_arg_t *argv)
     1005{
     1006        thread_stack_trace(argv[0].intval);
     1007        return 1;
     1008}
     1009
     1010#endif /* CONFIG_UDEBUG */
     1011
     1012/** Command for printing scheduler information
    9691013 *
    9701014 * @param argv Ignores
     
    9721016 * @return Always 1
    9731017 */
    974 int cmd_sched(cmd_arg_t * argv)
     1018int cmd_sched(cmd_arg_t *argv)
    9751019{
    9761020        sched_print_list();
     
    9841028 * return Always 1
    9851029 */
    986 int cmd_zones(cmd_arg_t * argv)
     1030int cmd_zones(cmd_arg_t *argv)
    9871031{
    9881032        zones_print_list();
     
    9961040 * return Always 1
    9971041 */
    998 int cmd_zone(cmd_arg_t * argv)
     1042int cmd_zone(cmd_arg_t *argv)
    9991043{
    10001044        zone_print_one(argv[0].intval);
     
    10021046}
    10031047
    1004 /** Command for printing task ipc details
     1048/** Command for printing task IPC details
    10051049 *
    10061050 * @param argv Integer argument from cmdline expected
     
    10081052 * return Always 1
    10091053 */
    1010 int cmd_ipc(cmd_arg_t * argv)
     1054int cmd_ipc(cmd_arg_t *argv)
    10111055{
    10121056        ipc_print_task(argv[0].intval);
     
    10201064 * return 0 on failure, 1 on success.
    10211065 */
    1022 int cmd_kill(cmd_arg_t * argv)
     1066int cmd_kill(cmd_arg_t *argv)
    10231067{
    10241068        if (task_kill(argv[0].intval) != EOK)
  • kernel/generic/src/console/console.c

    r22027b6e r8b5690f  
    160160        klog_parea.pbase = (uintptr_t) faddr;
    161161        klog_parea.frames = SIZE2FRAMES(sizeof(klog));
     162        klog_parea.unpriv = false;
    162163        ddi_parea_register(&klog_parea);
    163164       
  • kernel/generic/src/ddi/ddi.c

    r22027b6e r8b5690f  
    104104{
    105105        ASSERT(TASK);
    106         ASSERT((pf % FRAME_SIZE) == 0);
    107         ASSERT((vp % PAGE_SIZE) == 0);
    108        
    109         /*
    110          * Make sure the caller is authorised to make this syscall.
    111          */
    112         cap_t caps = cap_get(TASK);
    113         if (!(caps & CAP_MEM_MANAGER))
    114                 return EPERM;
     106       
     107        if ((pf % FRAME_SIZE) != 0)
     108                return EBADMEM;
     109       
     110        if ((vp % PAGE_SIZE) != 0)
     111                return EBADMEM;
     112       
     113        /*
     114         * Unprivileged tasks are only allowed to map pareas
     115         * which are explicitly marked as such.
     116         */
     117        bool priv =
     118            ((cap_get(TASK) & CAP_MEM_MANAGER) == CAP_MEM_MANAGER);
    115119       
    116120        mem_backend_data_t backend_data;
     
    123127       
    124128        if (znum == (size_t) -1) {
    125                 /* Frames not found in any zones
    126                  * -> assume it is hardware device and allow mapping
     129                /*
     130                 * Frames not found in any zone
     131                 * -> assume it is a hardware device and allow mapping
     132                 *    for privileged tasks.
    127133                 */
    128134                irq_spinlock_unlock(&zones.lock, true);
     135               
     136                if (!priv)
     137                        return EPERM;
     138               
    129139                goto map;
    130140        }
    131141       
    132142        if (zones.info[znum].flags & ZONE_FIRMWARE) {
    133                 /* Frames are part of firmware */
     143                /*
     144                 * Frames are part of firmware
     145                 * -> allow mapping for privileged tasks.
     146                 */
    134147                irq_spinlock_unlock(&zones.lock, true);
     148               
     149                if (!priv)
     150                        return EPERM;
     151               
    135152                goto map;
    136153        }
     
    138155        if (zone_flags_available(zones.info[znum].flags)) {
    139156                /*
    140                  * Frames are part of physical memory, check if the memory
    141                  * region is enabled for mapping.
     157                 * Frames are part of physical memory, check
     158                 * if the memory region is enabled for mapping.
    142159                 */
    143160                irq_spinlock_unlock(&zones.lock, true);
     
    150167                if ((!parea) || (parea->frames < pages)) {
    151168                        mutex_unlock(&parea_lock);
    152                         goto err;
     169                        return ENOENT;
     170                }
     171               
     172                if (!priv) {
     173                        if (!parea->unpriv) {
     174                                mutex_unlock(&parea_lock);
     175                                return EPERM;
     176                        }
    153177                }
    154178               
     
    158182       
    159183        irq_spinlock_unlock(&zones.lock, true);
    160        
    161 err:
    162184        return ENOENT;
    163185       
     
    258280}
    259281
    260 /** Disable or enable specified interrupts.
    261  *
    262  * @param irq the interrupt to be enabled/disabled.
    263  * @param enable if true enable the interrupt, disable otherwise.
    264  *
    265  * @retutn Zero on success, error code otherwise.
    266  */
    267 sysarg_t sys_interrupt_enable(int irq, int enable)
    268 {
    269 /* FIXME: this needs to be generic code, or better not be in kernel at all. */
    270 #if 0
    271         cap_t task_cap = cap_get(TASK);
    272         if (!(task_cap & CAP_IRQ_REG))
    273                 return EPERM;
    274                
    275         if (irq < 0 || irq > 16) {
    276                 return EINVAL;
    277         }
    278        
    279         uint16_t irq_mask = (uint16_t)(1 << irq);
    280         if (enable) {
    281                 trap_virtual_enable_irqs(irq_mask);
    282         } else {
    283                 trap_virtual_disable_irqs(irq_mask);
    284         }
    285        
    286 #endif
    287         return 0;
    288 }
    289 
    290282/** @}
    291283 */
  • kernel/generic/src/interrupt/interrupt.c

    r22027b6e r8b5690f  
    4545#include <console/console.h>
    4646#include <console/cmd.h>
    47 #include <ipc/event.h>
    4847#include <synch/mutex.h>
    4948#include <time/delay.h>
     
    188187        printf("\n");
    189188       
    190         /*
    191          * Userspace can subscribe for FAULT events to take action
    192          * whenever a thread faults. (E.g. take a dump, run a debugger).
    193          * The notification is always available, but unless Udebug is enabled,
    194          * that's all you get.
    195          */
    196         if (event_is_subscribed(EVENT_FAULT)) {
    197                 /* Notify the subscriber that a fault occurred. */
    198                 event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
    199                     UPPER32(TASK->taskid), (sysarg_t) THREAD);
    200                
    201 #ifdef CONFIG_UDEBUG
    202                 /* Wait for a debugging session. */
    203                 udebug_thread_fault();
    204 #endif
    205         }
    206        
    207         task_kill(TASK->taskid);
    208         thread_exit();
     189        task_kill_self(true);
    209190}
    210191
  • kernel/generic/src/ipc/ipc.c

    r22027b6e r8b5690f  
    295295                atomic_inc(&phone->active_calls);
    296296                call->data.phone = phone;
     297                call->data.task = TASK;
    297298        }
    298299       
     
    406407                        call->caller_phone = call->data.phone;
    407408                call->data.phone = newphone;
     409                call->data.task = TASK;
    408410        }
    409411       
     
    688690        irq_spinlock_exchange(&tasks_lock, &task->lock);
    689691       
    690         /* Print opened phones & details */
    691         printf("PHONE:\n");
     692        printf("[phone id] [calls] [state\n");
    692693       
    693694        size_t i;
    694695        for (i = 0; i < IPC_MAX_PHONES; i++) {
    695696                if (SYNCH_FAILED(mutex_trylock(&task->phones[i].lock))) {
    696                         printf("%zu: mutex busy\n", i);
     697                        printf("%-10zu (mutex busy)\n", i);
    697698                        continue;
    698699                }
    699700               
    700701                if (task->phones[i].state != IPC_PHONE_FREE) {
    701                         printf("%zu: ", i);
     702                        printf("%-10zu %7" PRIun " ", i,
     703                            atomic_get(&task->phones[i].active_calls));
    702704                       
    703705                        switch (task->phones[i].state) {
    704706                        case IPC_PHONE_CONNECTING:
    705                                 printf("connecting ");
     707                                printf("connecting");
    706708                                break;
    707709                        case IPC_PHONE_CONNECTED:
    708                                 printf("connected to: %p (%" PRIu64 ") ",
    709                                     task->phones[i].callee,
    710                                     task->phones[i].callee->task->taskid);
     710                                printf("connected to %" PRIu64 " (%s)",
     711                                    task->phones[i].callee->task->taskid,
     712                                    task->phones[i].callee->task->name);
    711713                                break;
    712714                        case IPC_PHONE_SLAMMED:
    713                                 printf("slammed by: %p ",
     715                                printf("slammed by %p",
    714716                                    task->phones[i].callee);
    715717                                break;
    716718                        case IPC_PHONE_HUNGUP:
    717                                 printf("hung up - was: %p ",
     719                                printf("hung up by %p",
    718720                                    task->phones[i].callee);
    719721                                break;
     
    722724                        }
    723725                       
    724                         printf("active: %" PRIun "\n",
    725                             atomic_get(&task->phones[i].active_calls));
     726                        printf("\n");
    726727                }
    727728               
     
    731732        irq_spinlock_lock(&task->answerbox.lock, false);
    732733       
     734#ifdef __32_BITS__
     735        printf("[call id ] [method] [arg1] [arg2] [arg3] [arg4] [arg5]"
     736            " [flags] [sender\n");
     737#endif
     738       
     739#ifdef __64_BITS__
     740        printf("[call id         ] [method] [arg1] [arg2] [arg3] [arg4]"
     741            " [arg5] [flags] [sender\n");
     742#endif
     743       
    733744        link_t *cur;
    734745       
    735         /* Print answerbox - calls */
    736         printf("ABOX - CALLS:\n");
     746        printf(" --- incomming calls ---\n");
    737747        for (cur = task->answerbox.calls.next; cur != &task->answerbox.calls;
    738748            cur = cur->next) {
    739749                call_t *call = list_get_instance(cur, call_t, link);
    740                 printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun
    741                     " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun
    742                     " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call,
    743                     call->sender->taskid,
     750               
     751#ifdef __32_BITS__
     752                printf("%10p ", call);
     753#endif
     754               
     755#ifdef __64_BITS__
     756                printf("%18p ", call);
     757#endif
     758               
     759                printf("%-8" PRIun " %-6" PRIun " %-6" PRIun " %-6" PRIun
     760                    " %-6" PRIun " %-6" PRIun " %-7x %" PRIu64 " (%s)\n",
    744761                    IPC_GET_IMETHOD(call->data), IPC_GET_ARG1(call->data),
    745762                    IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
    746763                    IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
    747                     call->flags);
    748         }
    749        
    750         /* Print answerbox - dispatched calls */
    751         printf("ABOX - DISPATCHED CALLS:\n");
     764                    call->flags, call->sender->taskid, call->sender->name);
     765        }
     766       
     767        printf(" --- dispatched calls ---\n");
    752768        for (cur = task->answerbox.dispatched_calls.next;
    753769            cur != &task->answerbox.dispatched_calls;
    754770            cur = cur->next) {
    755771                call_t *call = list_get_instance(cur, call_t, link);
    756                 printf("Callid: %p Srctask:%" PRIu64 " M:%" PRIun
    757                     " A1:%" PRIun " A2:%" PRIun " A3:%" PRIun
    758                     " A4:%" PRIun " A5:%" PRIun " Flags:%x\n", call,
    759                     call->sender->taskid,
     772               
     773#ifdef __32_BITS__
     774                printf("%10p ", call);
     775#endif
     776               
     777#ifdef __64_BITS__
     778                printf("%18p ", call);
     779#endif
     780               
     781                printf("%-8" PRIun " %-6" PRIun " %-6" PRIun " %-6" PRIun
     782                    " %-6" PRIun " %-6" PRIun " %-7x %" PRIu64 " (%s)\n",
    760783                    IPC_GET_IMETHOD(call->data), IPC_GET_ARG1(call->data),
    761784                    IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
    762785                    IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
    763                     call->flags);
    764         }
    765        
    766         /* Print answerbox - answers */
    767         printf("ABOX - ANSWERS:\n");
     786                    call->flags, call->sender->taskid, call->sender->name);
     787        }
     788       
     789        printf(" --- incoming answers ---\n");
    768790        for (cur = task->answerbox.answers.next;
    769791            cur != &task->answerbox.answers;
    770792            cur = cur->next) {
    771793                call_t *call = list_get_instance(cur, call_t, link);
    772                 printf("Callid:%p M:%" PRIun " A1:%" PRIun " A2:%" PRIun
    773                     " A3:%" PRIun " A4:%" PRIun " A5:%" PRIun " Flags:%x\n",
    774                     call, IPC_GET_IMETHOD(call->data), IPC_GET_ARG1(call->data),
     794               
     795#ifdef __32_BITS__
     796                printf("%10p ", call);
     797#endif
     798               
     799#ifdef __64_BITS__
     800                printf("%18p ", call);
     801#endif
     802               
     803                printf("%-8" PRIun " %-6" PRIun " %-6" PRIun " %-6" PRIun
     804                    " %-6" PRIun " %-6" PRIun " %-7x %" PRIu64 " (%s)\n",
     805                    IPC_GET_IMETHOD(call->data), IPC_GET_ARG1(call->data),
    775806                    IPC_GET_ARG2(call->data), IPC_GET_ARG3(call->data),
    776807                    IPC_GET_ARG4(call->data), IPC_GET_ARG5(call->data),
    777                     call->flags);
     808                    call->flags, call->sender->taskid, call->sender->name);
    778809        }
    779810       
  • kernel/generic/src/ipc/irq.c

    r22027b6e r8b5690f  
    4242 *
    4343 * The structure of a notification message is as follows:
    44  * - IMETHOD: interface and method as registered by the SYS_IPC_REGISTER_IRQ
     44 * - IMETHOD: interface and method as registered by the SYS_REGISTER_IRQ
    4545 *            syscall
    4646 * - ARG1: payload modified by a 'top-half' handler
  • kernel/generic/src/ipc/sysipc.c

    r22027b6e r8b5690f  
    248248                        /* The connection was accepted */
    249249                        phone_connect(phoneid, &answer->sender->answerbox);
     250                        /* Set 'task hash' as arg4 of response */
     251                        IPC_SET_ARG4(answer->data, (sysarg_t) TASK);
    250252                        /* Set 'phone hash' as arg5 of response */
    251253                        IPC_SET_ARG5(answer->data,
     
    11031105 *
    11041106 */
    1105 sysarg_t sys_ipc_register_irq(inr_t inr, devno_t devno, sysarg_t imethod,
     1107sysarg_t sys_register_irq(inr_t inr, devno_t devno, sysarg_t imethod,
    11061108    irq_code_t *ucode)
    11071109{
     
    11201122 *
    11211123 */
    1122 sysarg_t sys_ipc_unregister_irq(inr_t inr, devno_t devno)
     1124sysarg_t sys_unregister_irq(inr_t inr, devno_t devno)
    11231125{
    11241126        if (!(cap_get(TASK) & CAP_IRQ_REG))
  • kernel/generic/src/lib/elf.c

    r22027b6e r8b5690f  
    157157        case PT_NULL:
    158158        case PT_PHDR:
     159        case PT_NOTE:
    159160                break;
    160161        case PT_LOAD:
     
    173174                break;
    174175        case PT_SHLIB:
    175         case PT_NOTE:
    176176        case PT_LOPROC:
    177177        case PT_HIPROC:
  • kernel/generic/src/lib/rd.c

    r22027b6e r8b5690f  
    9090            FRAME_SIZE);
    9191        rd_parea.frames = SIZE2FRAMES(dsize);
     92        rd_parea.unpriv = false;
    9293        ddi_parea_register(&rd_parea);
    9394
  • kernel/generic/src/mm/backend_phys.c

    r22027b6e r8b5690f  
    8181        page_mapping_insert(AS, addr, base + (addr - area->base),
    8282            as_area_get_flags(area));
    83         if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
    84                 panic("Cannot insert used space.");
     83       
     84        if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
     85                panic("Cannot insert used space.");
    8586
    8687        return AS_PF_OK;
  • kernel/generic/src/mm/slab.c

    r22027b6e r8b5690f  
    806806}
    807807
    808 /** Go through all caches and reclaim what is possible
    809  *
    810  * Interrupts must be disabled before calling this function,
    811  * otherwise  memory allocation from interrupts can deadlock.
    812  *
    813  */
     808/** Go through all caches and reclaim what is possible */
    814809size_t slab_reclaim(unsigned int flags)
    815810{
    816         irq_spinlock_lock(&slab_cache_lock, false);
     811        irq_spinlock_lock(&slab_cache_lock, true);
    817812       
    818813        size_t frames = 0;
     
    824819        }
    825820       
    826         irq_spinlock_unlock(&slab_cache_lock, false);
     821        irq_spinlock_unlock(&slab_cache_lock, true);
    827822       
    828823        return frames;
  • kernel/generic/src/proc/scheduler.c

    r22027b6e r8b5690f  
    6262#include <print.h>
    6363#include <debug.h>
    64 
    65 static void before_task_runs(void);
    66 static void before_thread_runs(void);
    67 static void after_thread_ran(void);
     64#include <stacktrace.h>
     65
    6866static void scheduler_separated_stack(void);
    6967
     
    7169
    7270/** Carry out actions before new task runs. */
    73 void before_task_runs(void)
     71static void before_task_runs(void)
    7472{
    7573        before_task_runs_arch();
     
    8078 * Perform actions that need to be
    8179 * taken before the newly selected
    82  * tread is passed control.
     80 * thread is passed control.
    8381 *
    8482 * THREAD->lock is locked on entry
    8583 *
    8684 */
    87 void before_thread_runs(void)
     85static void before_thread_runs(void)
    8886{
    8987        before_thread_runs_arch();
     88       
    9089#ifdef CONFIG_FPU_LAZY
    91         if(THREAD == CPU->fpu_owner)
     90        if (THREAD == CPU->fpu_owner)
    9291                fpu_enable();
    9392        else
     
    102101        }
    103102#endif
     103       
     104#ifdef CONFIG_UDEBUG
     105        if (THREAD->btrace) {
     106                istate_t *istate = THREAD->udebug.uspace_state;
     107                if (istate != NULL) {
     108                        printf("Thread %" PRIu64 " stack trace:\n", THREAD->tid);
     109                        stack_trace_istate(istate);
     110                }
     111               
     112                THREAD->btrace = false;
     113        }
     114#endif
    104115}
    105116
     
    113124 *
    114125 */
    115 void after_thread_ran(void)
     126static void after_thread_ran(void)
    116127{
    117128        after_thread_ran_arch();
     
    391402         * possible destruction should thread_destroy() be called on this or any
    392403         * other processor while the scheduler is still using them.
    393          *
    394404         */
    395405        if (old_task)
     
    417427                                 * The thread structure is kept allocated until
    418428                                 * somebody calls thread_detach() on it.
    419                                  *
    420429                                 */
    421430                                if (!irq_spinlock_trylock(&THREAD->join_wq.lock)) {
    422431                                        /*
    423432                                         * Avoid deadlock.
    424                                          *
    425433                                         */
    426434                                        irq_spinlock_unlock(&THREAD->lock, false);
     
    443451                        /*
    444452                         * Prefer the thread after it's woken up.
    445                          *
    446453                         */
    447454                        THREAD->priority = -1;
     
    451458                         * waitq_sleep(). Address of wq->lock is kept in
    452459                         * THREAD->sleep_queue.
    453                          *
    454460                         */
    455461                        irq_spinlock_unlock(&THREAD->sleep_queue->lock, false);
     
    461467                        /*
    462468                         * Entering state is unexpected.
    463                          *
    464469                         */
    465470                        panic("tid%" PRIu64 ": unexpected state %s.",
     
    480485       
    481486        /*
    482          * If both the old and the new task are the same, lots of work is
    483          * avoided.
    484          *
     487         * If both the old and the new task are the same,
     488         * lots of work is avoided.
    485489         */
    486490        if (TASK != THREAD->task) {
     
    488492               
    489493                /*
    490                  * Note that it is possible for two tasks to share one address
    491                  * space.
    492                  (
     494                 * Note that it is possible for two tasks
     495                 * to share one address space.
    493496                 */
    494497                if (old_as != new_as) {
     
    496499                         * Both tasks and address spaces are different.
    497500                         * Replace the old one with the new one.
    498                          *
    499501                         */
    500502                        as_switch(old_as, new_as);
     
    527529         * necessary, is to be mapped in before_thread_runs(). This
    528530         * function must be executed before the switch to the new stack.
    529          *
    530531         */
    531532        before_thread_runs();
     
    534535         * Copy the knowledge of CPU, TASK, THREAD and preemption counter to
    535536         * thread's stack.
    536          *
    537537         */
    538538        the_copy(THE, (the_t *) THREAD->kstack);
     
    658658                                /*
    659659                                 * Ready thread on local CPU
    660                                  *
    661660                                 */
    662661                               
  • kernel/generic/src/proc/task.c

    r22027b6e r8b5690f  
    342342sysarg_t sys_task_set_name(const char *uspace_name, size_t name_len)
    343343{
    344         int rc;
    345344        char namebuf[TASK_NAME_BUFLEN];
    346345       
    347346        /* Cap length of name and copy it from userspace. */
    348        
    349347        if (name_len > TASK_NAME_BUFLEN - 1)
    350348                name_len = TASK_NAME_BUFLEN - 1;
    351349       
    352         rc = copy_from_uspace(namebuf, uspace_name, name_len);
     350        int rc = copy_from_uspace(namebuf, uspace_name, name_len);
    353351        if (rc != 0)
    354352                return (sysarg_t) rc;
    355353       
    356354        namebuf[name_len] = '\0';
     355       
     356        /*
     357         * As the task name is referenced also from the
     358         * threads, lock the threads' lock for the course
     359         * of the update.
     360         */
     361       
     362        irq_spinlock_lock(&tasks_lock, true);
     363        irq_spinlock_lock(&TASK->lock, false);
     364        irq_spinlock_lock(&threads_lock, false);
     365       
     366        /* Set task name */
    357367        str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
    358368       
     369        irq_spinlock_unlock(&threads_lock, false);
     370        irq_spinlock_unlock(&TASK->lock, false);
     371        irq_spinlock_unlock(&tasks_lock, true);
     372       
    359373        return EOK;
    360374}
     
    370384{
    371385        task_id_t taskid;
    372         int rc;
    373 
    374         rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
     386        int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
    375387        if (rc != 0)
    376388                return (sysarg_t) rc;
    377 
     389       
    378390        return (sysarg_t) task_kill(taskid);
    379391}
     
    449461static void task_kill_internal(task_t *task)
    450462{
     463        irq_spinlock_lock(&task->lock, false);
     464        irq_spinlock_lock(&threads_lock, false);
     465       
     466        /*
     467         * Interrupt all threads.
     468         */
     469       
    451470        link_t *cur;
    452        
    453         /*
    454          * Interrupt all threads.
    455          */
    456         irq_spinlock_lock(&task->lock, false);
    457471        for (cur = task->th_head.next; cur != &task->th_head; cur = cur->next) {
    458472                thread_t *thread = list_get_instance(cur, thread_t, th_link);
     
    471485        }
    472486       
     487        irq_spinlock_unlock(&threads_lock, false);
    473488        irq_spinlock_unlock(&task->lock, false);
    474489}
     
    500515        irq_spinlock_unlock(&tasks_lock, true);
    501516       
     517        return EOK;
     518}
     519
     520/** Kill the currently running task.
     521 *
     522 * @param notify Send out fault notifications.
     523 *
     524 * @return Zero on success or an error code from errno.h.
     525 *
     526 */
     527void task_kill_self(bool notify)
     528{
     529        /*
     530         * User space can subscribe for FAULT events to take action
     531         * whenever a task faults (to take a dump, run a debugger, etc.).
     532         * The notification is always available, but unless udebug is enabled,
     533         * that's all you get.
     534        */
     535        if (notify) {
     536                if (event_is_subscribed(EVENT_FAULT)) {
     537                        /* Notify the subscriber that a fault occurred. */
     538                        event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
     539                            UPPER32(TASK->taskid), (sysarg_t) THREAD);
     540               
     541#ifdef CONFIG_UDEBUG
     542                        /* Wait for a debugging session. */
     543                        udebug_thread_fault();
     544#endif
     545                }
     546        }
     547       
     548        irq_spinlock_lock(&tasks_lock, true);
     549        task_kill_internal(TASK);
     550        irq_spinlock_unlock(&tasks_lock, true);
     551       
     552        thread_exit();
     553}
     554
     555/** Process syscall to terminate the current task.
     556 *
     557 * @param notify Send out fault notifications.
     558 *
     559 */
     560sysarg_t sys_task_exit(sysarg_t notify)
     561{
     562        task_kill_self(notify);
     563       
     564        /* Unreachable */
    502565        return EOK;
    503566}
  • kernel/generic/src/proc/thread.c

    r22027b6e r8b5690f  
    239239 * Switch thread to the ready state.
    240240 *
    241  * @param t Thread to make ready.
     241 * @param thread Thread to make ready.
    242242 *
    243243 */
     
    246246        irq_spinlock_lock(&thread->lock, true);
    247247       
    248         ASSERT(!(thread->state == Ready));
     248        ASSERT(thread->state != Ready);
    249249       
    250250        int i = (thread->priority < RQ_COUNT - 1)
     
    350350       
    351351#ifdef CONFIG_UDEBUG
    352         /* Init debugging stuff */
     352        /* Initialize debugging stuff */
     353        thread->btrace = false;
    353354        udebug_thread_initialize(&thread->udebug);
    354355#endif
     
    535536/** Detach thread.
    536537 *
    537  * Mark the thread as detached, if the thread is already in the Lingering
    538  * state, deallocate its resources.
     538 * Mark the thread as detached. If the thread is already
     539 * in the Lingering state, deallocate its resources.
    539540 *
    540541 * @param thread Thread to be detached.
     
    590591        order_suffix(thread->kcycles, &kcycles, &ksuffix);
    591592       
     593        char *name;
     594        if (str_cmp(thread->name, "uinit") == 0)
     595                name = thread->task->name;
     596        else
     597                name = thread->name;
     598       
    592599#ifdef __32_BITS__
    593600        if (*additional)
    594                 printf("%-8" PRIu64" %10p %9" PRIu64 "%c %9" PRIu64 "%c ",
    595                     thread->tid, thread->kstack, ucycles, usuffix,
    596                     kcycles, ksuffix);
     601                printf("%-8" PRIu64 " %10p %10p %9" PRIu64 "%c %9" PRIu64 "%c ",
     602                    thread->tid, thread->thread_code, thread->kstack,
     603                    ucycles, usuffix, kcycles, ksuffix);
    597604        else
    598                 printf("%-8" PRIu64" %-14s %10p %-8s %10p %-5" PRIu32 " %10p\n",
    599                     thread->tid, thread->name, thread, thread_states[thread->state],
    600                     thread->task, thread->task->context, thread->thread_code);
     605                printf("%-8" PRIu64 " %-14s %10p %-8s %10p %-5" PRIu32 "\n",
     606                    thread->tid, name, thread, thread_states[thread->state],
     607                    thread->task, thread->task->context);
    601608#endif
    602609       
    603610#ifdef __64_BITS__
    604611        if (*additional)
    605                 printf("%-8" PRIu64" %18p %18p\n"
     612                printf("%-8" PRIu64 " %18p %18p\n"
    606613                    "         %9" PRIu64 "%c %9" PRIu64 "%c ",
    607614                    thread->tid, thread->thread_code, thread->kstack,
    608615                    ucycles, usuffix, kcycles, ksuffix);
    609616        else
    610                 printf("%-8" PRIu64" %-14s %18p %-8s %18p %-5" PRIu32 "\n",
    611                     thread->tid, thread->name, thread, thread_states[thread->state],
     617                printf("%-8" PRIu64 " %-14s %18p %-8s %18p %-5" PRIu32 "\n",
     618                    thread->tid, name, thread, thread_states[thread->state],
    612619                    thread->task, thread->task->context);
    613620#endif
     
    647654#ifdef __32_BITS__
    648655        if (additional)
    649                 printf("[id    ] [stack   ] [ucycles ] [kcycles ] [cpu]"
    650                     " [waitqueue]\n");
     656                printf("[id    ] [code    ] [stack   ] [ucycles ] [kcycles ]"
     657                    " [cpu] [waitqueue]\n");
    651658        else
    652659                printf("[id    ] [name        ] [address ] [state ] [task    ]"
    653                     " [ctx] [code    ]\n");
     660                    " [ctx]\n");
    654661#endif
    655662       
     
    740747        ASSERT(interrupts_disabled());
    741748        ASSERT(irq_spinlock_locked(&threads_lock));
    742 
     749       
    743750        thread_iterator_t iterator;
    744751       
     
    751758}
    752759
     760#ifdef CONFIG_UDEBUG
     761
     762void thread_stack_trace(thread_id_t thread_id)
     763{
     764        irq_spinlock_lock(&threads_lock, true);
     765       
     766        thread_t *thread = thread_find_by_id(thread_id);
     767        if (thread == NULL) {
     768                printf("No such thread.\n");
     769                irq_spinlock_unlock(&threads_lock, true);
     770                return;
     771        }
     772       
     773        irq_spinlock_lock(&thread->lock, false);
     774       
     775        /*
     776         * Schedule a stack trace to be printed
     777         * just before the thread is scheduled next.
     778         *
     779         * If the thread is sleeping then try to interrupt
     780         * the sleep. Any request for printing an uspace stack
     781         * trace from within the kernel should be always
     782         * considered a last resort debugging means, therefore
     783         * forcing the thread's sleep to be interrupted
     784         * is probably justifiable.
     785         */
     786       
     787        bool sleeping = false;
     788        istate_t *istate = thread->udebug.uspace_state;
     789        if (istate != NULL) {
     790                printf("Scheduling thread stack trace.\n");
     791                thread->btrace = true;
     792                if (thread->state == Sleeping)
     793                        sleeping = true;
     794        } else
     795                printf("Thread interrupt state not available.\n");
     796       
     797        irq_spinlock_unlock(&thread->lock, false);
     798       
     799        if (sleeping)
     800                waitq_interrupt_sleep(thread);
     801       
     802        irq_spinlock_unlock(&threads_lock, true);
     803}
     804
     805#endif /* CONFIG_UDEBUG */
    753806
    754807/** Process syscall to create new thread.
     
    793846                                 * has already been created. We need to undo its
    794847                                 * creation now.
    795                                  *
    796848                                 */
    797849                               
     
    815867                 * THREAD_B events for threads that already existed
    816868                 * and could be detected with THREAD_READ before.
    817                  *
    818869                 */
    819870                udebug_thread_b_event_attach(thread, TASK);
  • kernel/generic/src/synch/waitq.c

    r22027b6e r8b5690f  
    127127/** Interrupt sleeping thread.
    128128 *
    129  * This routine attempts to interrupt a thread from its sleep in a waitqueue.
    130  * If the thread is not found sleeping, no action is taken.
     129 * This routine attempts to interrupt a thread from its sleep in
     130 * a waitqueue. If the thread is not found sleeping, no action
     131 * is taken.
     132 *
     133 * The threads_lock must be already held and interrupts must be
     134 * disabled upon calling this function.
    131135 *
    132136 * @param thread Thread to be interrupted.
     
    138142        DEADLOCK_PROBE_INIT(p_wqlock);
    139143       
    140         irq_spinlock_lock(&threads_lock, true);
    141         if (!thread_exists(thread))
    142                 goto out;
     144        /*
     145         * The thread is quaranteed to exist because
     146         * threads_lock is held.
     147         */
    143148       
    144149grab_locks:
     
    150155                        /*
    151156                         * The sleep cannot be interrupted.
    152                          *
    153157                         */
    154158                        irq_spinlock_unlock(&thread->lock, false);
    155                         goto out;
     159                        return;
    156160                }
    157161               
    158162                if (!irq_spinlock_trylock(&wq->lock)) {
     163                        /* Avoid deadlock */
    159164                        irq_spinlock_unlock(&thread->lock, false);
    160165                        DEADLOCK_PROBE(p_wqlock, DEADLOCK_THRESHOLD);
    161                         /* Avoid deadlock */
    162166                        goto grab_locks;
    163167                }
     
    173177                irq_spinlock_unlock(&wq->lock, false);
    174178        }
     179       
    175180        irq_spinlock_unlock(&thread->lock, false);
    176181       
    177182        if (do_wakeup)
    178183                thread_ready(thread);
    179        
    180 out:
    181         irq_spinlock_unlock(&threads_lock, true);
    182184}
    183185
     
    370372                 * If the thread was already interrupted,
    371373                 * don't go to sleep at all.
    372                  *
    373374                 */
    374375                if (THREAD->interrupted) {
     
    381382                 * Set context that will be restored if the sleep
    382383                 * of this thread is ever interrupted.
    383                  *
    384384                 */
    385385                THREAD->sleep_interruptible = true;
  • kernel/generic/src/syscall/syscall.c

    r22027b6e r8b5690f  
    8686        } else {
    8787                printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
    88                 task_kill(TASK->taskid);
    89                 thread_exit();
     88                task_kill_self(true);
    9089        }
    9190       
     
    131130        (syshandler_t) sys_task_set_name,
    132131        (syshandler_t) sys_task_kill,
     132        (syshandler_t) sys_task_exit,
    133133        (syshandler_t) sys_program_spawn_loader,
    134134       
     
    156156        (syshandler_t) sys_ipc_poke,
    157157        (syshandler_t) sys_ipc_hangup,
    158         (syshandler_t) sys_ipc_register_irq,
    159         (syshandler_t) sys_ipc_unregister_irq,
    160158        (syshandler_t) sys_ipc_connect_kbox,
    161159       
     
    171169        (syshandler_t) sys_physmem_map,
    172170        (syshandler_t) sys_iospace_enable,
    173         (syshandler_t) sys_interrupt_enable,
     171        (syshandler_t) sys_register_irq,
     172        (syshandler_t) sys_unregister_irq,
    174173       
    175174        /* Sysinfo syscalls */
  • kernel/generic/src/sysinfo/stats.c

    r22027b6e r8b5690f  
    170170         * Note that it may be infinitely better to let the address space
    171171         * management code compute these statistics as it proceeds instead of
    172          * having them calculated here over and over again here.
     172         * having them calculated over and over again here.
    173173         */
    174174
     
    199199}
    200200
     201/** Get the resident (used) size of a virtual address space
     202 *
     203 * @param as Address space.
     204 *
     205 * @return Size of the resident (used) virtual address space (bytes).
     206 *
     207 */
     208static size_t get_task_resmem(as_t *as)
     209{
     210        size_t result = 0;
     211       
     212        /*
     213         * We are holding some spinlocks here and therefore are not allowed to
     214         * block. Only attempt to lock the address space and address space area
     215         * mutexes conditionally. If it is not possible to lock either object,
     216         * allow the statistics to be inexact by skipping the respective object.
     217         *
     218         * Note that it may be infinitely better to let the address space
     219         * management code compute these statistics as it proceeds instead of
     220         * having them calculated over and over again here.
     221         */
     222       
     223        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
     224                return result * PAGE_SIZE;
     225       
     226        /* Walk the B+ tree of AS areas */
     227        link_t *cur;
     228        for (cur = as->as_area_btree.leaf_head.next;
     229            cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     230                btree_node_t *node =
     231                    list_get_instance(cur, btree_node_t, leaf_link);
     232               
     233                unsigned int i;
     234                for (i = 0; i < node->keys; i++) {
     235                        as_area_t *area = node->value[i];
     236                       
     237                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
     238                                continue;
     239                       
     240                        /* Walk the B+ tree of resident pages */
     241                        link_t *rcur;
     242                        for (rcur = area->used_space.leaf_head.next;
     243                            rcur != &area->used_space.leaf_head; rcur = rcur->next) {
     244                                btree_node_t *rnode =
     245                                    list_get_instance(rcur, btree_node_t, leaf_link);
     246                               
     247                                unsigned int j;
     248                                for (j = 0; j < rnode->keys; j++)
     249                                        result += (size_t) rnode->value[i];
     250                        }
     251                       
     252                        mutex_unlock(&area->lock);
     253                }
     254        }
     255       
     256        mutex_unlock(&as->lock);
     257       
     258        return result * PAGE_SIZE;
     259}
     260
    201261/* Produce task statistics
    202262 *
     
    215275        str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name);
    216276        stats_task->virtmem = get_task_virtmem(task->as);
     277        stats_task->resmem = get_task_resmem(task->as);
    217278        stats_task->threads = atomic_get(&task->refcount);
    218279        task_get_accounting(task, &(stats_task->ucycles),
  • kernel/generic/src/sysinfo/sysinfo.c

    r22027b6e r8b5690f  
    4040#include <arch/asm.h>
    4141#include <errno.h>
     42#include <macros.h>
    4243
    4344/** Maximal sysinfo path length */
     
    761762 * character must be null).
    762763 *
    763  * The user space buffer must be sized exactly according
    764  * to the size of the binary data, otherwise the request
    765  * fails.
     764 * If the user space buffer size does not equal
     765 * the actual size of the returned data, the data
     766 * is truncated. Whether this is actually a fatal
     767 * error or the data can be still interpreted as valid
     768 * depends on the nature of the data and has to be
     769 * decided by the user space.
     770 *
     771 * The actual size of data returned is stored to
     772 * size_ptr.
    766773 *
    767774 * @param path_ptr    Sysinfo path in the user address space.
     
    770777 *                    to store the binary data.
    771778 * @param buffer_size User space buffer size.
     779 * @param size_ptr    User space pointer where to store the
     780 *                    binary data size.
    772781 *
    773782 * @return Error code (EOK in case of no error).
     
    775784 */
    776785sysarg_t sys_sysinfo_get_data(void *path_ptr, size_t path_size,
    777     void *buffer_ptr, size_t buffer_size)
     786    void *buffer_ptr, size_t buffer_size, size_t *size_ptr)
    778787{
    779788        int rc;
    780789       
    781790        /* Get the item */
    782         sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, false);
    783 
     791        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size,
     792            false);
     793       
    784794        /* Only constant or generated binary data is considered */
    785         if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
    786                 /* Check destination buffer size */
    787                 if (ret.data.size == buffer_size)
    788                         rc = copy_to_uspace(buffer_ptr, ret.data.data,
    789                             ret.data.size);
    790                 else
    791                         rc = ENOMEM;
     795        if ((ret.tag == SYSINFO_VAL_DATA) ||
     796            (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
     797                size_t size = min(ret.data.size, buffer_size);
     798                rc = copy_to_uspace(buffer_ptr, ret.data.data, size);
     799                if (rc == EOK)
     800                        rc = copy_to_uspace(size_ptr, &size, sizeof(size));
    792801        } else
    793802                rc = EINVAL;
  • kernel/generic/src/time/clock.c

    r22027b6e r8b5690f  
    9393        clock_parea.pbase = (uintptr_t) faddr;
    9494        clock_parea.frames = 1;
     95        clock_parea.unpriv = true;
    9596        ddi_parea_register(&clock_parea);
    9697       
     
    100101         *
    101102         */
    102         sysinfo_set_item_val("clock.cacheable", NULL, (sysarg_t) true);
    103103        sysinfo_set_item_val("clock.faddr", NULL, (sysarg_t) faddr);
    104104}
Note: See TracChangeset for help on using the changeset viewer.