Changeset 17aca1c in mainline for kernel


Ignore:
Timestamp:
2011-02-04T20:56:52Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0397e5a4, e29e09cf
Parents:
e778543 (diff), 0b37882 (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:
27 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/arm32/src/mach/gta02/gta02.c

    re778543 r17aca1c  
    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

    re778543 r17aca1c  
    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

    re778543 r17aca1c  
    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/mips32/src/mm/tlb.c

    re778543 r17aca1c  
    557557        entry_hi_t hi, hi_save;
    558558        tlb_index_t index;
    559 
    560         ASSERT(asid != ASID_INVALID);
     559       
     560        if (asid == ASID_INVALID)
     561                return;
    561562
    562563        hi_save.value = cp0_entry_hi_read();
  • kernel/arch/sparc64/src/drivers/niagara.c

    re778543 r17aca1c  
    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

    re778543 r17aca1c  
    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
     
    6061extern int ddi_iospace_enable_arch(task_t *, uintptr_t, size_t);
    6162
    62 
    6363#endif
    6464
  • kernel/generic/include/ipc/event_types.h

    re778543 r17aca1c  
    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/sysipc.h

    re778543 r17aca1c  
    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/mm/as.h

    re778543 r17aca1c  
    115115       
    116116        /**
    117          * Number of processors on wich is this address space active.
    118          * Protected by asidlock.
     117         * Number of processors on which this
     118         * address space is active. Protected by
     119         * asidlock.
    119120         */
    120121        size_t cpu_refcount;
    121122       
    122         /**
    123          * Address space identifier.
    124          * Constant on architectures that do not support ASIDs.
    125          * Protected by asidlock.
     123        /** Address space identifier.
     124         *
     125         * Constant on architectures that do not
     126         * support ASIDs. Protected by asidlock.
     127         *
    126128         */
    127129        asid_t asid;
    128130       
    129         /** Number of references (i.e tasks that reference this as). */
     131        /** Number of references (i.e. tasks that reference this as). */
    130132        atomic_t refcount;
    131133       
     
    199201typedef struct {
    200202        mutex_t lock;
     203       
    201204        /** Containing address space. */
    202205        as_t *as;
    203206       
    204         /**
    205          * Flags related to the memory represented by the address space area.
    206          */
     207        /** Memory flags. */
    207208        unsigned int flags;
    208209       
    209         /** Attributes related to the address space area itself. */
     210        /** Address space area attributes. */
    210211        unsigned int attributes;
    211         /** Size of this area in multiples of PAGE_SIZE. */
     212       
     213        /** Number of pages in the area. */
    212214        size_t pages;
     215       
     216        /** Number of resident pages in the area. */
     217        size_t resident;
     218       
    213219        /** Base address of this area. */
    214220        uintptr_t base;
     221       
    215222        /** Map of used space. */
    216223        btree_t used_space;
    217224       
    218225        /**
    219          * If the address space area has been shared, this pointer will
    220          * reference the share info structure.
     226         * If the address space area is shared. this is
     227         * a reference to the share info structure.
    221228         */
    222229        share_info_t *sh_info;
     
    261268extern bool as_area_check_access(as_area_t *, pf_access_t);
    262269extern size_t as_area_get_size(uintptr_t);
    263 extern int used_space_insert(as_area_t *, uintptr_t, size_t);
    264 extern int used_space_remove(as_area_t *, uintptr_t, size_t);
    265 
     270extern bool used_space_insert(as_area_t *, uintptr_t, size_t);
     271extern bool used_space_remove(as_area_t *, uintptr_t, size_t);
    266272
    267273/* Interface to be implemented by architectures. */
     
    307313extern sysarg_t sys_as_area_change_flags(uintptr_t, unsigned int);
    308314extern sysarg_t sys_as_area_destroy(uintptr_t);
     315extern sysarg_t sys_as_get_unmapped_area(uintptr_t, size_t);
    309316
    310317/* Introspection functions. */
  • kernel/generic/include/proc/task.h

    re778543 r17aca1c  
    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/syscall/syscall.h

    re778543 r17aca1c  
    4848        SYS_TASK_SET_NAME,
    4949        SYS_TASK_KILL,
     50        SYS_TASK_EXIT,
    5051        SYS_PROGRAM_SPAWN_LOADER,
    5152       
     
    5859        SYS_AS_AREA_CHANGE_FLAGS,
    5960        SYS_AS_AREA_DESTROY,
     61        SYS_AS_GET_UNMAPPED_AREA,
    6062       
    6163        SYS_PAGE_FIND_MAPPING,
     
    7274        SYS_IPC_POKE,
    7375        SYS_IPC_HANGUP,
    74         SYS_IPC_REGISTER_IRQ,
    75         SYS_IPC_UNREGISTER_IRQ,
    7676        SYS_IPC_CONNECT_KBOX,
    7777       
     
    8484        SYS_PHYSMEM_MAP,
    8585        SYS_IOSPACE_ENABLE,
     86        SYS_REGISTER_IRQ,
     87        SYS_UNREGISTER_IRQ,
    8688       
    8789        SYS_SYSINFO_GET_TAG,
  • kernel/generic/include/udebug/udebug.h

    re778543 r17aca1c  
    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/console/cmd.c

    re778543 r17aca1c  
    553553        for (i = 0; basic_commands[i]; i++) {
    554554                cmd_initialize(basic_commands[i]);
    555                 if (!cmd_register(basic_commands[i]))
    556                         printf("Cannot register command %s\n", basic_commands[i]->name);
     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                }
    557562        }
    558563}
  • kernel/generic/src/console/console.c

    re778543 r17aca1c  
    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

    re778543 r17aca1c  
    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       
  • kernel/generic/src/interrupt/interrupt.c

    re778543 r17aca1c  
    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

    re778543 r17aca1c  
    787787        }
    788788       
    789         printf(" --- outgoing answers ---\n");
     789        printf(" --- incoming answers ---\n");
    790790        for (cur = task->answerbox.answers.next;
    791791            cur != &task->answerbox.answers;
  • kernel/generic/src/ipc/irq.c

    re778543 r17aca1c  
    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

    re778543 r17aca1c  
    11051105 *
    11061106 */
    1107 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,
    11081108    irq_code_t *ucode)
    11091109{
     
    11221122 *
    11231123 */
    1124 sysarg_t sys_ipc_unregister_irq(inr_t inr, devno_t devno)
     1124sysarg_t sys_unregister_irq(inr_t inr, devno_t devno)
    11251125{
    11261126        if (!(cap_get(TASK) & CAP_IRQ_REG))
  • kernel/generic/src/lib/elf.c

    re778543 r17aca1c  
    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

    re778543 r17aca1c  
    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/as.c

    re778543 r17aca1c  
    7171#include <memstr.h>
    7272#include <macros.h>
     73#include <bitops.h>
    7374#include <arch.h>
    7475#include <errno.h>
     
    8687 * Each architecture decides what functions will be used to carry out
    8788 * address space operations such as creating or locking page tables.
    88  *
    8989 */
    9090as_operations_t *as_operations = NULL;
    9191
    92 /**
    93  * Slab for as_t objects.
     92/** Slab for as_t objects.
    9493 *
    9594 */
    9695static slab_cache_t *as_slab;
    9796
    98 /**
    99  * This lock serializes access to the ASID subsystem.
    100  * It protects:
     97/** ASID subsystem lock.
     98 *
     99 * This lock protects:
    101100 * - inactive_as_with_asid_head list
    102101 * - as->asid for each as of the as_t type
     
    107106
    108107/**
    109  * This list contains address spaces that are not active on any
    110  * processor and that have valid ASID.
    111  *
     108 * Inactive address spaces (on all processors)
     109 * that have valid ASID.
    112110 */
    113111LIST_INITIALIZE(inactive_as_with_asid_head);
     
    123121        mutex_initialize(&as->lock, MUTEX_PASSIVE);
    124122       
    125         int rc = as_constructor_arch(as, flags);
    126        
    127         return rc;
     123        return as_constructor_arch(as, flags);
    128124}
    129125
    130126NO_TRACE static size_t as_destructor(void *obj)
    131127{
    132         as_t *as = (as_t *) obj;
    133         return as_destructor_arch(as);
     128        return as_destructor_arch((as_t *) obj);
    134129}
    135130
     
    146141                panic("Cannot create kernel address space.");
    147142       
    148         /* Make sure the kernel address space
     143        /*
     144         * Make sure the kernel address space
    149145         * reference count never drops to zero.
    150146         */
     
    195191{
    196192        DEADLOCK_PROBE_INIT(p_asidlock);
    197 
     193       
    198194        ASSERT(as != AS);
    199195        ASSERT(atomic_get(&as->refcount) == 0);
     
    203199         * lock its mutex.
    204200         */
    205 
     201       
    206202        /*
    207203         * We need to avoid deadlock between TLB shootdown and asidlock.
     
    210206         * disabled to prevent nested context switches. We also depend on the
    211207         * fact that so far no spinlocks are held.
    212          *
    213208         */
    214209        preemption_disable();
     
    235230        spinlock_unlock(&asidlock);
    236231        interrupts_restore(ipl);
    237 
     232       
    238233       
    239234        /*
     
    241236         * The B+tree must be walked carefully because it is
    242237         * also being destroyed.
    243          *
    244238         */
    245239        bool cond = true;
     
    268262/** Hold a reference to an address space.
    269263 *
    270  * Holding a reference to an address space prevents destruction of that address
    271  * space.
     264 * Holding a reference to an address space prevents destruction
     265 * of that address space.
    272266 *
    273267 * @param as Address space to be held.
     
    281275/** Release a reference to an address space.
    282276 *
    283  * The last one to release a reference to an address space destroys the address
    284  * space.
     277 * The last one to release a reference to an address space
     278 * destroys the address space.
    285279 *
    286280 * @param asAddress space to be released.
     
    295289/** Check area conflicts with other areas.
    296290 *
    297  * @param as         Address space.
    298  * @param va         Starting virtual address of the area being tested.
    299  * @param size       Size of the area being tested.
    300  * @param avoid_area Do not touch this area.
     291 * @param as    Address space.
     292 * @param addr  Starting virtual address of the area being tested.
     293 * @param count Number of pages in the area being tested.
     294 * @param avoid Do not touch this area.
    301295 *
    302296 * @return True if there is no conflict, false otherwise.
    303297 *
    304298 */
    305 NO_TRACE static bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,
    306     as_area_t *avoid_area)
    307 {
     299NO_TRACE static bool check_area_conflicts(as_t *as, uintptr_t addr,
     300    size_t count, as_area_t *avoid)
     301{
     302        ASSERT((addr % PAGE_SIZE) == 0);
    308303        ASSERT(mutex_locked(&as->lock));
    309304       
    310305        /*
    311306         * We don't want any area to have conflicts with NULL page.
    312          *
    313          */
    314         if (overlaps(va, size, (uintptr_t) NULL, PAGE_SIZE))
     307         */
     308        if (overlaps(addr, count << PAGE_WIDTH, (uintptr_t) NULL, PAGE_SIZE))
    315309                return false;
    316310       
     
    321315         * record in the left neighbour, the leftmost record in the right
    322316         * neighbour and all records in the leaf node itself.
    323          *
    324317         */
    325318        btree_node_t *leaf;
    326319        as_area_t *area =
    327             (as_area_t *) btree_search(&as->as_area_btree, va, &leaf);
     320            (as_area_t *) btree_search(&as->as_area_btree, addr, &leaf);
    328321        if (area) {
    329                 if (area != avoid_area)
     322                if (area != avoid)
    330323                        return false;
    331324        }
     
    337330                area = (as_area_t *) node->value[node->keys - 1];
    338331               
    339                 mutex_lock(&area->lock);
    340                
    341                 if (overlaps(va, size, area->base, area->pages * PAGE_SIZE)) {
     332                if (area != avoid) {
     333                        mutex_lock(&area->lock);
     334                       
     335                        if (overlaps(addr, count << PAGE_WIDTH,
     336                            area->base, area->pages << PAGE_WIDTH)) {
     337                                mutex_unlock(&area->lock);
     338                                return false;
     339                        }
     340                       
    342341                        mutex_unlock(&area->lock);
    343                         return false;
    344                 }
    345                
    346                 mutex_unlock(&area->lock);
     342                }
    347343        }
    348344       
     
    351347                area = (as_area_t *) node->value[0];
    352348               
    353                 mutex_lock(&area->lock);
    354                
    355                 if (overlaps(va, size, area->base, area->pages * PAGE_SIZE)) {
     349                if (area != avoid) {
     350                        mutex_lock(&area->lock);
     351                       
     352                        if (overlaps(addr, count << PAGE_WIDTH,
     353                            area->base, area->pages << PAGE_WIDTH)) {
     354                                mutex_unlock(&area->lock);
     355                                return false;
     356                        }
     357                       
    356358                        mutex_unlock(&area->lock);
    357                         return false;
    358                 }
    359                
    360                 mutex_unlock(&area->lock);
     359                }
    361360        }
    362361       
     
    366365                area = (as_area_t *) leaf->value[i];
    367366               
    368                 if (area == avoid_area)
     367                if (area == avoid)
    369368                        continue;
    370369               
    371370                mutex_lock(&area->lock);
    372371               
    373                 if (overlaps(va, size, area->base, area->pages * PAGE_SIZE)) {
     372                if (overlaps(addr, count << PAGE_WIDTH,
     373                    area->base, area->pages << PAGE_WIDTH)) {
    374374                        mutex_unlock(&area->lock);
    375375                        return false;
     
    382382         * So far, the area does not conflict with other areas.
    383383         * Check if it doesn't conflict with kernel address space.
    384          *
    385384         */
    386385        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    387                 return !overlaps(va, size,
     386                return !overlaps(addr, count << PAGE_WIDTH,
    388387                    KERNEL_ADDRESS_SPACE_START,
    389388                    KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START);
     
    412411    mem_backend_data_t *backend_data)
    413412{
    414         if (base % PAGE_SIZE)
     413        if ((base % PAGE_SIZE) != 0)
    415414                return NULL;
    416415       
    417         if (!size)
     416        if (size == 0)
    418417                return NULL;
     418       
     419        size_t pages = SIZE2FRAMES(size);
    419420       
    420421        /* Writeable executable areas are not supported. */
     
    424425        mutex_lock(&as->lock);
    425426       
    426         if (!check_area_conflicts(as, base, size, NULL)) {
     427        if (!check_area_conflicts(as, base, pages, NULL)) {
    427428                mutex_unlock(&as->lock);
    428429                return NULL;
     
    436437        area->flags = flags;
    437438        area->attributes = attrs;
    438         area->pages = SIZE2FRAMES(size);
     439        area->pages = pages;
     440        area->resident = 0;
    439441        area->base = base;
    440442        area->sh_info = NULL;
     
    479481         * to find out whether this is a miss or va belongs to an address
    480482         * space area found there.
    481          *
    482483         */
    483484       
     
    490491                mutex_lock(&area->lock);
    491492               
    492                 if ((area->base <= va) && (va < area->base + area->pages * PAGE_SIZE))
     493                if ((area->base <= va) &&
     494                    (va < area->base + (area->pages << PAGE_WIDTH)))
    493495                        return area;
    494496               
     
    499501         * Second, locate the left neighbour and test its last record.
    500502         * Because of its position in the B+tree, it must have base < va.
    501          *
    502503         */
    503504        btree_node_t *lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf);
     
    507508                mutex_lock(&area->lock);
    508509               
    509                 if (va < area->base + area->pages * PAGE_SIZE)
     510                if (va < area->base + (area->pages << PAGE_WIDTH))
    510511                        return area;
    511512               
     
    534535        /*
    535536         * Locate the area.
    536          *
    537537         */
    538538        as_area_t *area = find_area_and_lock(as, address);
     
    546546                 * Remapping of address space areas associated
    547547                 * with memory mapped devices is not supported.
    548                  *
    549548                 */
    550549                mutex_unlock(&area->lock);
     
    557556                 * Remapping of shared address space areas
    558557                 * is not supported.
    559                  *
    560558                 */
    561559                mutex_unlock(&area->lock);
     
    568566                /*
    569567                 * Zero size address space areas are not allowed.
    570                  *
    571568                 */
    572569                mutex_unlock(&area->lock);
     
    576573       
    577574        if (pages < area->pages) {
    578                 uintptr_t start_free = area->base + pages * PAGE_SIZE;
     575                uintptr_t start_free = area->base + (pages << PAGE_WIDTH);
    579576               
    580577                /*
    581578                 * Shrinking the area.
    582579                 * No need to check for overlaps.
    583                  *
    584580                 */
    585581               
     
    588584                /*
    589585                 * Start TLB shootdown sequence.
    590                  *
    591586                 */
    592587                ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid,
    593                     area->base + pages * PAGE_SIZE, area->pages - pages);
     588                    area->base + (pages << PAGE_WIDTH), area->pages - pages);
    594589               
    595590                /*
     
    599594                 * is also the right way to remove part of the used_space
    600595                 * B+tree leaf list.
    601                  *
    602596                 */
    603597                bool cond = true;
     
    615609                                size_t i = 0;
    616610                               
    617                                 if (overlaps(ptr, size * PAGE_SIZE, area->base,
    618                                     pages * PAGE_SIZE)) {
     611                                if (overlaps(ptr, size << PAGE_WIDTH, area->base,
     612                                    pages << PAGE_WIDTH)) {
    619613                                       
    620                                         if (ptr + size * PAGE_SIZE <= start_free) {
     614                                        if (ptr + (size << PAGE_WIDTH) <= start_free) {
    621615                                                /*
    622616                                                 * The whole interval fits
    623617                                                 * completely in the resized
    624618                                                 * address space area.
    625                                                  *
    626619                                                 */
    627620                                                break;
     
    632625                                         * to b and c overlaps with the resized
    633626                                         * address space area.
    634                                          *
    635627                                         */
    636628                                       
     
    652644                                for (; i < size; i++) {
    653645                                        pte_t *pte = page_mapping_find(as, ptr +
    654                                             i * PAGE_SIZE);
     646                                            (i << PAGE_WIDTH));
    655647                                       
    656648                                        ASSERT(pte);
     
    661653                                            (area->backend->frame_free)) {
    662654                                                area->backend->frame_free(area,
    663                                                     ptr + i * PAGE_SIZE,
     655                                                    ptr + (i << PAGE_WIDTH),
    664656                                                    PTE_GET_FRAME(pte));
    665657                                        }
    666658                                       
    667659                                        page_mapping_remove(as, ptr +
    668                                             i * PAGE_SIZE);
     660                                            (i << PAGE_WIDTH));
    669661                                }
    670662                        }
     
    673665                /*
    674666                 * Finish TLB shootdown sequence.
    675                  *
    676                  */
    677                
    678                 tlb_invalidate_pages(as->asid, area->base + pages * PAGE_SIZE,
     667                 */
     668               
     669                tlb_invalidate_pages(as->asid, area->base + (pages << PAGE_WIDTH),
    679670                    area->pages - pages);
    680671               
    681672                /*
    682673                 * Invalidate software translation caches (e.g. TSB on sparc64).
    683                  *
    684674                 */
    685675                as_invalidate_translation_cache(as, area->base +
    686                     pages * PAGE_SIZE, area->pages - pages);
     676                    (pages << PAGE_WIDTH), area->pages - pages);
    687677                tlb_shootdown_finalize(ipl);
    688678               
     
    692682                 * Growing the area.
    693683                 * Check for overlaps with other address space areas.
    694                  *
    695                  */
    696                 if (!check_area_conflicts(as, address, pages * PAGE_SIZE,
    697                     area)) {
     684                 */
     685                if (!check_area_conflicts(as, address, pages, area)) {
    698686                        mutex_unlock(&area->lock);
    699687                        mutex_unlock(&as->lock);
     
    794782                       
    795783                        for (size = 0; size < (size_t) node->value[i]; size++) {
    796                                 pte_t *pte = page_mapping_find(as, ptr + size * PAGE_SIZE);
     784                                pte_t *pte =
     785                                    page_mapping_find(as, ptr + (size << PAGE_WIDTH));
    797786                               
    798787                                ASSERT(pte);
     
    803792                                    (area->backend->frame_free)) {
    804793                                        area->backend->frame_free(area,
    805                                             ptr + size * PAGE_SIZE, PTE_GET_FRAME(pte));
     794                                            ptr + (size << PAGE_WIDTH), PTE_GET_FRAME(pte));
    806795                                }
    807796                               
    808                                 page_mapping_remove(as, ptr + size * PAGE_SIZE);
     797                                page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
    809798                        }
    810799                }
     
    813802        /*
    814803         * Finish TLB shootdown sequence.
    815          *
    816804         */
    817805       
     
    821809         * Invalidate potential software translation caches (e.g. TSB on
    822810         * sparc64).
    823          *
    824811         */
    825812        as_invalidate_translation_cache(as, area->base, area->pages);
     
    839826        /*
    840827         * Remove the empty area from address space.
    841          *
    842828         */
    843829        btree_remove(&as->as_area_btree, base, NULL);
     
    881867                /*
    882868                 * Could not find the source address space area.
    883                  *
    884869                 */
    885870                mutex_unlock(&src_as->lock);
     
    891876                 * There is no backend or the backend does not
    892877                 * know how to share the area.
    893                  *
    894878                 */
    895879                mutex_unlock(&src_area->lock);
     
    898882        }
    899883       
    900         size_t src_size = src_area->pages * PAGE_SIZE;
     884        size_t src_size = src_area->pages << PAGE_WIDTH;
    901885        unsigned int src_flags = src_area->flags;
    902886        mem_backend_t *src_backend = src_area->backend;
     
    918902         * First, prepare the area for sharing.
    919903         * Then it will be safe to unlock it.
    920          *
    921904         */
    922905        share_info_t *sh_info = src_area->sh_info;
     
    930913                /*
    931914                 * Call the backend to setup sharing.
    932                  *
    933915                 */
    934916                src_area->backend->share(src_area);
     
    949931         * The flags of the source area are masked against dst_flags_mask
    950932         * to support sharing in less privileged mode.
    951          *
    952933         */
    953934        as_area_t *dst_area = as_area_create(dst_as, dst_flags_mask, src_size,
     
    966947         * fully initialized. Clear the AS_AREA_ATTR_PARTIAL
    967948         * attribute and set the sh_info.
    968          *
    969949         */
    970950        mutex_lock(&dst_as->lock);
     
    989969NO_TRACE bool as_area_check_access(as_area_t *area, pf_access_t access)
    990970{
     971        ASSERT(mutex_locked(&area->lock));
     972       
    991973        int flagmap[] = {
    992974                [PF_ACCESS_READ] = AS_AREA_READ,
     
    994976                [PF_ACCESS_EXEC] = AS_AREA_EXEC
    995977        };
    996 
    997         ASSERT(mutex_locked(&area->lock));
    998978       
    999979        if (!(area->flags & flagmap[access]))
     
    10661046        /*
    10671047         * Compute total number of used pages in the used_space B+tree
    1068          *
    10691048         */
    10701049        size_t used_pages = 0;
     
    10881067        /*
    10891068         * Start TLB shootdown sequence.
    1090          *
    10911069         */
    10921070        ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid, area->base,
     
    10961074         * Remove used pages from page tables and remember their frame
    10971075         * numbers.
    1098          *
    10991076         */
    11001077        size_t frame_idx = 0;
     
    11111088                       
    11121089                        for (size = 0; size < (size_t) node->value[i]; size++) {
    1113                                 pte_t *pte = page_mapping_find(as, ptr + size * PAGE_SIZE);
     1090                                pte_t *pte =
     1091                                    page_mapping_find(as, ptr + (size << PAGE_WIDTH));
    11141092                               
    11151093                                ASSERT(pte);
     
    11201098                               
    11211099                                /* Remove old mapping */
    1122                                 page_mapping_remove(as, ptr + size * PAGE_SIZE);
     1100                                page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
    11231101                        }
    11241102                }
     
    11271105        /*
    11281106         * Finish TLB shootdown sequence.
    1129          *
    11301107         */
    11311108       
     
    11351112         * Invalidate potential software translation caches (e.g. TSB on
    11361113         * sparc64).
    1137          *
    11381114         */
    11391115        as_invalidate_translation_cache(as, area->base, area->pages);
     
    11681144                               
    11691145                                /* Insert the new mapping */
    1170                                 page_mapping_insert(as, ptr + size * PAGE_SIZE,
     1146                                page_mapping_insert(as, ptr + (size << PAGE_WIDTH),
    11711147                                    old_frame[frame_idx++], page_flags);
    11721148                               
     
    12171193                 * No area contained mapping for 'page'.
    12181194                 * Signal page fault to low-level handler.
    1219                  *
    12201195                 */
    12211196                mutex_unlock(&AS->lock);
     
    12371212                 * The address space area is not backed by any backend
    12381213                 * or the backend cannot handle page faults.
    1239                  *
    12401214                 */
    12411215                mutex_unlock(&area->lock);
     
    12491223         * To avoid race condition between two page faults on the same address,
    12501224         * we need to make sure the mapping has not been already inserted.
    1251          *
    12521225         */
    12531226        pte_t *pte;
     
    12671240        /*
    12681241         * Resort to the backend page fault handler.
    1269          *
    12701242         */
    12711243        if (area->backend->page_fault(area, page, access) != AS_PF_OK) {
     
    13221294                 * preemption is disabled. We should not be
    13231295                 * holding any other lock.
    1324                  *
    13251296                 */
    13261297                (void) interrupts_enable();
     
    13421313                         * list of inactive address spaces with assigned
    13431314                         * ASID.
    1344                          *
    13451315                         */
    13461316                        ASSERT(old_as->asid != ASID_INVALID);
     
    13531323                 * Perform architecture-specific tasks when the address space
    13541324                 * is being removed from the CPU.
    1355                  *
    13561325                 */
    13571326                as_deinstall_arch(old_as);
     
    13601329        /*
    13611330         * Second, prepare the new address space.
    1362          *
    13631331         */
    13641332        if ((new_as->cpu_refcount++ == 0) && (new_as != AS_KERNEL)) {
     
    13761344         * Perform architecture-specific steps.
    13771345         * (e.g. write ASID to hardware register etc.)
    1378          *
    13791346         */
    13801347        as_install_arch(new_as);
     
    13951362{
    13961363        ASSERT(mutex_locked(&area->lock));
    1397 
     1364       
    13981365        return area_flags_to_page_flags(area->flags);
    13991366}
     
    14991466       
    15001467        if (src_area) {
    1501                 size = src_area->pages * PAGE_SIZE;
     1468                size = src_area->pages << PAGE_WIDTH;
    15021469                mutex_unlock(&src_area->lock);
    15031470        } else
     
    15161483 * @param count Number of page to be marked.
    15171484 *
    1518  * @return Zero on failure and non-zero on success.
    1519  *
    1520  */
    1521 int used_space_insert(as_area_t *area, uintptr_t page, size_t count)
     1485 * @return False on failure or true on success.
     1486 *
     1487 */
     1488bool used_space_insert(as_area_t *area, uintptr_t page, size_t count)
    15221489{
    15231490        ASSERT(mutex_locked(&area->lock));
     
    15301497                /*
    15311498                 * We hit the beginning of some used space.
    1532                  *
    1533                  */
    1534                 return 0;
     1499                 */
     1500                return false;
    15351501        }
    15361502       
    15371503        if (!leaf->keys) {
    15381504                btree_insert(&area->used_space, page, (void *) count, leaf);
    1539                 return 1;
     1505                goto success;
    15401506        }
    15411507       
     
    15511517                 * somewhere between the rightmost interval of
    15521518                 * the left neigbour and the first interval of the leaf.
    1553                  *
    15541519                 */
    15551520               
    15561521                if (page >= right_pg) {
    15571522                        /* Do nothing. */
    1558                 } else if (overlaps(page, count * PAGE_SIZE, left_pg,
    1559                     left_cnt * PAGE_SIZE)) {
     1523                } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1524                    left_cnt << PAGE_WIDTH)) {
    15601525                        /* The interval intersects with the left interval. */
    1561                         return 0;
    1562                 } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    1563                     right_cnt * PAGE_SIZE)) {
     1526                        return false;
     1527                } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1528                    right_cnt << PAGE_WIDTH)) {
    15641529                        /* The interval intersects with the right interval. */
    1565                         return 0;
    1566                 } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    1567                     (page + count * PAGE_SIZE == right_pg)) {
     1530                        return false;
     1531                } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
     1532                    (page + (count << PAGE_WIDTH) == right_pg)) {
    15681533                        /*
    15691534                         * The interval can be added by merging the two already
    15701535                         * present intervals.
    1571                          *
    15721536                         */
    15731537                        node->value[node->keys - 1] += count + right_cnt;
    15741538                        btree_remove(&area->used_space, right_pg, leaf);
    1575                         return 1;
    1576                 } else if (page == left_pg + left_cnt * PAGE_SIZE) {
     1539                        goto success;
     1540                } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
    15771541                        /*
    15781542                         * The interval can be added by simply growing the left
    15791543                         * interval.
    1580                          *
    15811544                         */
    15821545                        node->value[node->keys - 1] += count;
    1583                         return 1;
    1584                 } else if (page + count * PAGE_SIZE == right_pg) {
     1546                        goto success;
     1547                } else if (page + (count << PAGE_WIDTH) == right_pg) {
    15851548                        /*
    15861549                         * The interval can be addded by simply moving base of
    15871550                         * the right interval down and increasing its size
    15881551                         * accordingly.
    1589                          *
    15901552                         */
    15911553                        leaf->value[0] += count;
    15921554                        leaf->key[0] = page;
    1593                         return 1;
     1555                        goto success;
    15941556                } else {
    15951557                        /*
    15961558                         * The interval is between both neigbouring intervals,
    15971559                         * but cannot be merged with any of them.
    1598                          *
    15991560                         */
    16001561                        btree_insert(&area->used_space, page, (void *) count,
    16011562                            leaf);
    1602                         return 1;
     1563                        goto success;
    16031564                }
    16041565        } else if (page < leaf->key[0]) {
     
    16091570                 * Investigate the border case in which the left neighbour does
    16101571                 * not exist but the interval fits from the left.
    1611                  *
    1612                  */
    1613                
    1614                 if (overlaps(page, count * PAGE_SIZE, right_pg,
    1615                     right_cnt * PAGE_SIZE)) {
     1572                 */
     1573               
     1574                if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1575                    right_cnt << PAGE_WIDTH)) {
    16161576                        /* The interval intersects with the right interval. */
    1617                         return 0;
    1618                 } else if (page + count * PAGE_SIZE == right_pg) {
     1577                        return false;
     1578                } else if (page + (count << PAGE_WIDTH) == right_pg) {
    16191579                        /*
    16201580                         * The interval can be added by moving the base of the
    16211581                         * right interval down and increasing its size
    16221582                         * accordingly.
    1623                          *
    16241583                         */
    16251584                        leaf->key[0] = page;
    16261585                        leaf->value[0] += count;
    1627                         return 1;
     1586                        goto success;
    16281587                } else {
    16291588                        /*
    16301589                         * The interval doesn't adjoin with the right interval.
    16311590                         * It must be added individually.
    1632                          *
    16331591                         */
    16341592                        btree_insert(&area->used_space, page, (void *) count,
    16351593                            leaf);
    1636                         return 1;
     1594                        goto success;
    16371595                }
    16381596        }
     
    16491607                 * somewhere between the leftmost interval of
    16501608                 * the right neigbour and the last interval of the leaf.
    1651                  *
    16521609                 */
    16531610               
    16541611                if (page < left_pg) {
    16551612                        /* Do nothing. */
    1656                 } else if (overlaps(page, count * PAGE_SIZE, left_pg,
    1657                     left_cnt * PAGE_SIZE)) {
     1613                } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1614                    left_cnt << PAGE_WIDTH)) {
    16581615                        /* The interval intersects with the left interval. */
    1659                         return 0;
    1660                 } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    1661                     right_cnt * PAGE_SIZE)) {
     1616                        return false;
     1617                } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1618                    right_cnt << PAGE_WIDTH)) {
    16621619                        /* The interval intersects with the right interval. */
    1663                         return 0;
    1664                 } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    1665                     (page + count * PAGE_SIZE == right_pg)) {
     1620                        return false;
     1621                } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
     1622                    (page + (count << PAGE_WIDTH) == right_pg)) {
    16661623                        /*
    16671624                         * The interval can be added by merging the two already
    16681625                         * present intervals.
    1669                          *
    16701626                         */
    16711627                        leaf->value[leaf->keys - 1] += count + right_cnt;
    16721628                        btree_remove(&area->used_space, right_pg, node);
    1673                         return 1;
    1674                 } else if (page == left_pg + left_cnt * PAGE_SIZE) {
     1629                        goto success;
     1630                } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
    16751631                        /*
    16761632                         * The interval can be added by simply growing the left
    16771633                         * interval.
    1678                          *
    16791634                         */
    1680                         leaf->value[leaf->keys - 1] +=  count;
    1681                         return 1;
    1682                 } else if (page + count * PAGE_SIZE == right_pg) {
     1635                        leaf->value[leaf->keys - 1] += count;
     1636                        goto success;
     1637                } else if (page + (count << PAGE_WIDTH) == right_pg) {
    16831638                        /*
    16841639                         * The interval can be addded by simply moving base of
    16851640                         * the right interval down and increasing its size
    16861641                         * accordingly.
    1687                          *
    16881642                         */
    16891643                        node->value[0] += count;
    16901644                        node->key[0] = page;
    1691                         return 1;
     1645                        goto success;
    16921646                } else {
    16931647                        /*
    16941648                         * The interval is between both neigbouring intervals,
    16951649                         * but cannot be merged with any of them.
    1696                          *
    16971650                         */
    16981651                        btree_insert(&area->used_space, page, (void *) count,
    16991652                            leaf);
    1700                         return 1;
     1653                        goto success;
    17011654                }
    17021655        } else if (page >= leaf->key[leaf->keys - 1]) {
     
    17071660                 * Investigate the border case in which the right neighbour
    17081661                 * does not exist but the interval fits from the right.
    1709                  *
    1710                  */
    1711                
    1712                 if (overlaps(page, count * PAGE_SIZE, left_pg,
    1713                     left_cnt * PAGE_SIZE)) {
     1662                 */
     1663               
     1664                if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1665                    left_cnt << PAGE_WIDTH)) {
    17141666                        /* The interval intersects with the left interval. */
    1715                         return 0;
    1716                 } else if (left_pg + left_cnt * PAGE_SIZE == page) {
     1667                        return false;
     1668                } else if (left_pg + (left_cnt << PAGE_WIDTH) == page) {
    17171669                        /*
    17181670                         * The interval can be added by growing the left
    17191671                         * interval.
    1720                          *
    17211672                         */
    17221673                        leaf->value[leaf->keys - 1] += count;
    1723                         return 1;
     1674                        goto success;
    17241675                } else {
    17251676                        /*
    17261677                         * The interval doesn't adjoin with the left interval.
    17271678                         * It must be added individually.
    1728                          *
    17291679                         */
    17301680                        btree_insert(&area->used_space, page, (void *) count,
    17311681                            leaf);
    1732                         return 1;
     1682                        goto success;
    17331683                }
    17341684        }
     
    17381688         * only between two other intervals of the leaf. The two border cases
    17391689         * were already resolved.
    1740          *
    17411690         */
    17421691        btree_key_t i;
     
    17501699                        /*
    17511700                         * The interval fits between left_pg and right_pg.
    1752                          *
    17531701                         */
    17541702                       
    1755                         if (overlaps(page, count * PAGE_SIZE, left_pg,
    1756                             left_cnt * PAGE_SIZE)) {
     1703                        if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1704                            left_cnt << PAGE_WIDTH)) {
    17571705                                /*
    17581706                                 * The interval intersects with the left
    17591707                                 * interval.
    1760                                  *
    17611708                                 */
    1762                                 return 0;
    1763                         } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    1764                             right_cnt * PAGE_SIZE)) {
     1709                                return false;
     1710                        } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1711                            right_cnt << PAGE_WIDTH)) {
    17651712                                /*
    17661713                                 * The interval intersects with the right
    17671714                                 * interval.
    1768                                  *
    17691715                                 */
    1770                                 return 0;
    1771                         } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    1772                             (page + count * PAGE_SIZE == right_pg)) {
     1716                                return false;
     1717                        } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
     1718                            (page + (count << PAGE_WIDTH) == right_pg)) {
    17731719                                /*
    17741720                                 * The interval can be added by merging the two
    17751721                                 * already present intervals.
    1776                                  *
    17771722                                 */
    17781723                                leaf->value[i - 1] += count + right_cnt;
    17791724                                btree_remove(&area->used_space, right_pg, leaf);
    1780                                 return 1;
    1781                         } else if (page == left_pg + left_cnt * PAGE_SIZE) {
     1725                                goto success;
     1726                        } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
    17821727                                /*
    17831728                                 * The interval can be added by simply growing
    17841729                                 * the left interval.
    1785                                  *
    17861730                                 */
    17871731                                leaf->value[i - 1] += count;
    1788                                 return 1;
    1789                         } else if (page + count * PAGE_SIZE == right_pg) {
     1732                                goto success;
     1733                        } else if (page + (count << PAGE_WIDTH) == right_pg) {
    17901734                                /*
    17911735                                 * The interval can be addded by simply moving
    17921736                                 * base of the right interval down and
    17931737                                 * increasing its size accordingly.
    1794                                  *
    17951738                                 */
    17961739                                leaf->value[i] += count;
    17971740                                leaf->key[i] = page;
    1798                                 return 1;
     1741                                goto success;
    17991742                        } else {
    18001743                                /*
     
    18021745                                 * intervals, but cannot be merged with any of
    18031746                                 * them.
    1804                                  *
    18051747                                 */
    18061748                                btree_insert(&area->used_space, page,
    18071749                                    (void *) count, leaf);
    1808                                 return 1;
     1750                                goto success;
    18091751                        }
    18101752                }
     
    18131755        panic("Inconsistency detected while adding %zu pages of used "
    18141756            "space at %p.", count, (void *) page);
     1757       
     1758success:
     1759        area->resident += count;
     1760        return true;
    18151761}
    18161762
     
    18231769 * @param count Number of page to be marked.
    18241770 *
    1825  * @return Zero on failure and non-zero on success.
    1826  *
    1827  */
    1828 int used_space_remove(as_area_t *area, uintptr_t page, size_t count)
     1771 * @return False on failure or true on success.
     1772 *
     1773 */
     1774bool used_space_remove(as_area_t *area, uintptr_t page, size_t count)
    18291775{
    18301776        ASSERT(mutex_locked(&area->lock));
     
    18371783                /*
    18381784                 * We are lucky, page is the beginning of some interval.
    1839                  *
    18401785                 */
    18411786                if (count > pages) {
    1842                         return 0;
     1787                        return false;
    18431788                } else if (count == pages) {
    18441789                        btree_remove(&area->used_space, page, leaf);
    1845                         return 1;
     1790                        goto success;
    18461791                } else {
    18471792                        /*
    18481793                         * Find the respective interval.
    18491794                         * Decrease its size and relocate its start address.
    1850                          *
    18511795                         */
    18521796                        btree_key_t i;
    18531797                        for (i = 0; i < leaf->keys; i++) {
    18541798                                if (leaf->key[i] == page) {
    1855                                         leaf->key[i] += count * PAGE_SIZE;
     1799                                        leaf->key[i] += count << PAGE_WIDTH;
    18561800                                        leaf->value[i] -= count;
    1857                                         return 1;
     1801                                        goto success;
    18581802                                }
    18591803                        }
     1804                       
    18601805                        goto error;
    18611806                }
     
    18671812                size_t left_cnt = (size_t) node->value[node->keys - 1];
    18681813               
    1869                 if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
    1870                     count * PAGE_SIZE)) {
    1871                         if (page + count * PAGE_SIZE ==
    1872                             left_pg + left_cnt * PAGE_SIZE) {
     1814                if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
     1815                    count << PAGE_WIDTH)) {
     1816                        if (page + (count << PAGE_WIDTH) ==
     1817                            left_pg + (left_cnt << PAGE_WIDTH)) {
    18731818                                /*
    18741819                                 * The interval is contained in the rightmost
     
    18761821                                 * removed by updating the size of the bigger
    18771822                                 * interval.
    1878                                  *
    18791823                                 */
    18801824                                node->value[node->keys - 1] -= count;
    1881                                 return 1;
    1882                         } else if (page + count * PAGE_SIZE <
    1883                             left_pg + left_cnt*PAGE_SIZE) {
     1825                                goto success;
     1826                        } else if (page + (count << PAGE_WIDTH) <
     1827                            left_pg + (left_cnt << PAGE_WIDTH)) {
    18841828                                /*
    18851829                                 * The interval is contained in the rightmost
     
    18881832                                 * the original interval and also inserting a
    18891833                                 * new interval.
    1890                                  *
    18911834                                 */
    1892                                 size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
    1893                                     (page + count*PAGE_SIZE)) >> PAGE_WIDTH;
     1835                                size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
     1836                                    (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
    18941837                                node->value[node->keys - 1] -= count + new_cnt;
    18951838                                btree_insert(&area->used_space, page +
    1896                                     count * PAGE_SIZE, (void *) new_cnt, leaf);
    1897                                 return 1;
     1839                                    (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1840                                goto success;
    18981841                        }
    18991842                }
    1900                 return 0;
     1843               
     1844                return false;
    19011845        } else if (page < leaf->key[0])
    1902                 return 0;
     1846                return false;
    19031847       
    19041848        if (page > leaf->key[leaf->keys - 1]) {
     
    19061850                size_t left_cnt = (size_t) leaf->value[leaf->keys - 1];
    19071851               
    1908                 if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
    1909                     count * PAGE_SIZE)) {
    1910                         if (page + count * PAGE_SIZE ==
    1911                             left_pg + left_cnt * PAGE_SIZE) {
     1852                if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
     1853                    count << PAGE_WIDTH)) {
     1854                        if (page + (count << PAGE_WIDTH) ==
     1855                            left_pg + (left_cnt << PAGE_WIDTH)) {
    19121856                                /*
    19131857                                 * The interval is contained in the rightmost
    19141858                                 * interval of the leaf and can be removed by
    19151859                                 * updating the size of the bigger interval.
    1916                                  *
    19171860                                 */
    19181861                                leaf->value[leaf->keys - 1] -= count;
    1919                                 return 1;
    1920                         } else if (page + count * PAGE_SIZE < left_pg +
    1921                             left_cnt * PAGE_SIZE) {
     1862                                goto success;
     1863                        } else if (page + (count << PAGE_WIDTH) < left_pg +
     1864                            (left_cnt << PAGE_WIDTH)) {
    19221865                                /*
    19231866                                 * The interval is contained in the rightmost
     
    19261869                                 * original interval and also inserting a new
    19271870                                 * interval.
    1928                                  *
    19291871                                 */
    1930                                 size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
    1931                                     (page + count * PAGE_SIZE)) >> PAGE_WIDTH;
     1872                                size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
     1873                                    (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
    19321874                                leaf->value[leaf->keys - 1] -= count + new_cnt;
    19331875                                btree_insert(&area->used_space, page +
    1934                                     count * PAGE_SIZE, (void *) new_cnt, leaf);
    1935                                 return 1;
     1876                                    (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1877                                goto success;
    19361878                        }
    19371879                }
    1938                 return 0;
     1880               
     1881                return false;
    19391882        }
    19401883       
    19411884        /*
    19421885         * The border cases have been already resolved.
    1943          * Now the interval can be only between intervals of the leaf. 
     1886         * Now the interval can be only between intervals of the leaf.
    19441887         */
    19451888        btree_key_t i;
     
    19531896                         * to (i - 1) and i.
    19541897                         */
    1955                         if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
    1956                             count * PAGE_SIZE)) {
    1957                                 if (page + count * PAGE_SIZE ==
    1958                                     left_pg + left_cnt*PAGE_SIZE) {
     1898                        if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
     1899                            count << PAGE_WIDTH)) {
     1900                                if (page + (count << PAGE_WIDTH) ==
     1901                                    left_pg + (left_cnt << PAGE_WIDTH)) {
    19591902                                        /*
    19601903                                         * The interval is contained in the
     
    19621905                                         * be removed by updating the size of
    19631906                                         * the bigger interval.
    1964                                          *
    19651907                                         */
    19661908                                        leaf->value[i - 1] -= count;
    1967                                         return 1;
    1968                                 } else if (page + count * PAGE_SIZE <
    1969                                     left_pg + left_cnt * PAGE_SIZE) {
     1909                                        goto success;
     1910                                } else if (page + (count << PAGE_WIDTH) <
     1911                                    left_pg + (left_cnt << PAGE_WIDTH)) {
    19701912                                        /*
    19711913                                         * The interval is contained in the
     
    19761918                                         */
    19771919                                        size_t new_cnt = ((left_pg +
    1978                                             left_cnt * PAGE_SIZE) -
    1979                                             (page + count * PAGE_SIZE)) >>
     1920                                            (left_cnt << PAGE_WIDTH)) -
     1921                                            (page + (count << PAGE_WIDTH))) >>
    19801922                                            PAGE_WIDTH;
    19811923                                        leaf->value[i - 1] -= count + new_cnt;
    19821924                                        btree_insert(&area->used_space, page +
    1983                                             count * PAGE_SIZE, (void *) new_cnt,
     1925                                            (count << PAGE_WIDTH), (void *) new_cnt,
    19841926                                            leaf);
    1985                                         return 1;
     1927                                        goto success;
    19861928                                }
    19871929                        }
    1988                         return 0;
     1930                       
     1931                        return false;
    19891932                }
    19901933        }
     
    19931936        panic("Inconsistency detected while removing %zu pages of used "
    19941937            "space from %p.", count, (void *) page);
     1938       
     1939success:
     1940        area->resident -= count;
     1941        return true;
    19951942}
    19961943
     
    20271974}
    20281975
     1976/** Return pointer to unmapped address space area
     1977 *
     1978 * @param base Lowest address bound.
     1979 * @param size Requested size of the allocation.
     1980 *
     1981 * @return Pointer to the beginning of unmapped address space area.
     1982 *
     1983 */
     1984sysarg_t sys_as_get_unmapped_area(uintptr_t base, size_t size)
     1985{
     1986        if (size == 0)
     1987                return 0;
     1988       
     1989        /*
     1990         * Make sure we allocate from page-aligned
     1991         * address. Check for possible overflow in
     1992         * each step.
     1993         */
     1994       
     1995        size_t pages = SIZE2FRAMES(size);
     1996        uintptr_t ret = 0;
     1997       
     1998        /*
     1999         * Find the lowest unmapped address aligned on the sz
     2000         * boundary, not smaller than base and of the required size.
     2001         */
     2002       
     2003        mutex_lock(&AS->lock);
     2004       
     2005        /* First check the base address itself */
     2006        uintptr_t addr = ALIGN_UP(base, PAGE_SIZE);
     2007        if ((addr >= base) &&
     2008            (check_area_conflicts(AS, addr, pages, NULL)))
     2009                ret = addr;
     2010       
     2011        /* Eventually check the addresses behind each area */
     2012        link_t *cur;
     2013        for (cur = AS->as_area_btree.leaf_head.next;
     2014            (ret == 0) && (cur != &AS->as_area_btree.leaf_head);
     2015            cur = cur->next) {
     2016                btree_node_t *node =
     2017                    list_get_instance(cur, btree_node_t, leaf_link);
     2018               
     2019                btree_key_t i;
     2020                for (i = 0; (ret == 0) && (i < node->keys); i++) {
     2021                        as_area_t *area = (as_area_t *) node->value[i];
     2022                       
     2023                        mutex_lock(&area->lock);
     2024                       
     2025                        uintptr_t addr =
     2026                            ALIGN_UP(area->base + (area->pages << PAGE_WIDTH),
     2027                            PAGE_SIZE);
     2028                       
     2029                        if ((addr >= base) && (addr >= area->base) &&
     2030                            (check_area_conflicts(AS, addr, pages, area)))
     2031                                ret = addr;
     2032                       
     2033                        mutex_unlock(&area->lock);
     2034                }
     2035        }
     2036       
     2037        mutex_unlock(&AS->lock);
     2038       
     2039        return (sysarg_t) ret;
     2040}
     2041
    20292042/** Get list of adress space areas.
    20302043 *
     
    20932106        mutex_lock(&as->lock);
    20942107       
    2095         /* print out info about address space areas */
     2108        /* Print out info about address space areas */
    20962109        link_t *cur;
    20972110        for (cur = as->as_area_btree.leaf_head.next;
  • kernel/generic/src/proc/program.c

    re778543 r17aca1c  
    171171        void *loader = program_loader;
    172172        if (!loader) {
     173                as_destroy(as);
    173174                printf("Cannot spawn loader as none was registered\n");
    174175                return ENOENT;
     
    179180        if (rc != EE_OK) {
    180181                as_destroy(as);
     182                printf("Cannot spawn loader (%s)\n", elf_error(rc));
    181183                return ENOENT;
    182184        }
  • kernel/generic/src/proc/task.c

    re778543 r17aca1c  
    384384{
    385385        task_id_t taskid;
    386         int rc;
    387 
    388         rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
     386        int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
    389387        if (rc != 0)
    390388                return (sysarg_t) rc;
    391 
     389       
    392390        return (sysarg_t) task_kill(taskid);
    393391}
     
    520518}
    521519
     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 */
     565        return EOK;
     566}
     567
    522568static bool task_print_walker(avltree_node_t *node, void *arg)
    523569{
  • kernel/generic/src/syscall/syscall.c

    re778543 r17aca1c  
    8787        } else {
    8888                printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
    89                 task_kill(TASK->taskid);
    90                 thread_exit();
     89                task_kill_self(true);
    9190        }
    9291       
     
    132131        (syshandler_t) sys_task_set_name,
    133132        (syshandler_t) sys_task_kill,
     133        (syshandler_t) sys_task_exit,
    134134        (syshandler_t) sys_program_spawn_loader,
    135135       
     
    144144        (syshandler_t) sys_as_area_change_flags,
    145145        (syshandler_t) sys_as_area_destroy,
     146        (syshandler_t) sys_as_get_unmapped_area,
    146147       
    147148        /* Page mapping related syscalls. */
     
    160161        (syshandler_t) sys_ipc_poke,
    161162        (syshandler_t) sys_ipc_hangup,
    162         (syshandler_t) sys_ipc_register_irq,
    163         (syshandler_t) sys_ipc_unregister_irq,
    164163        (syshandler_t) sys_ipc_connect_kbox,
    165164       
     
    175174        (syshandler_t) sys_physmem_map,
    176175        (syshandler_t) sys_iospace_enable,
     176        (syshandler_t) sys_register_irq,
     177        (syshandler_t) sys_unregister_irq,
    177178       
    178179        /* Sysinfo syscalls */
  • kernel/generic/src/sysinfo/stats.c

    re778543 r17aca1c  
    160160static size_t get_task_virtmem(as_t *as)
    161161{
    162         size_t result = 0;
    163 
    164162        /*
    165          * We are holding some spinlocks here and therefore are not allowed to
    166          * block. Only attempt to lock the address space and address space area
    167          * mutexes conditionally. If it is not possible to lock either object,
    168          * allow the statistics to be inexact by skipping the respective object.
    169          *
    170          * Note that it may be infinitely better to let the address space
    171          * management code compute these statistics as it proceeds instead of
    172          * having them calculated over and over again here.
     163         * We are holding spinlocks here and therefore are not allowed to
     164         * block. Only attempt to lock the address space and address space
     165         * area mutexes conditionally. If it is not possible to lock either
     166         * object, return inexact statistics by skipping the respective object.
    173167         */
    174 
     168       
    175169        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
    176                 return result * PAGE_SIZE;
     170                return 0;
     171       
     172        size_t pages = 0;
    177173       
    178174        /* Walk the B+ tree and count pages */
    179         link_t *cur;
    180         for (cur = as->as_area_btree.leaf_head.next;
    181             cur != &as->as_area_btree.leaf_head; cur = cur->next) {
    182                 btree_node_t *node =
    183                     list_get_instance(cur, btree_node_t, leaf_link);
    184                
    185                 unsigned int i;
    186                 for (i = 0; i < node->keys; i++) {
    187                         as_area_t *area = node->value[i];
    188                        
    189                         if (SYNCH_FAILED(mutex_trylock(&area->lock)))
    190                                 continue;
    191                         result += area->pages;
    192                         mutex_unlock(&area->lock);
    193                 }
    194         }
    195        
    196         mutex_unlock(&as->lock);
    197        
    198         return result * PAGE_SIZE;
    199 }
    200 
    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  */
    208 static 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 */
    227175        link_t *cur;
    228176        for (cur = as->as_area_btree.leaf_head.next;
     
    238186                                continue;
    239187                       
    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                        
     188                        pages += area->pages;
    252189                        mutex_unlock(&area->lock);
    253190                }
     
    256193        mutex_unlock(&as->lock);
    257194       
    258         return result * PAGE_SIZE;
     195        return (pages << PAGE_WIDTH);
     196}
     197
     198/** Get the resident (used) size of a virtual address space
     199 *
     200 * @param as Address space.
     201 *
     202 * @return Size of the resident (used) virtual address space (bytes).
     203 *
     204 */
     205static size_t get_task_resmem(as_t *as)
     206{
     207        /*
     208         * We are holding spinlocks here and therefore are not allowed to
     209         * block. Only attempt to lock the address space and address space
     210         * area mutexes conditionally. If it is not possible to lock either
     211         * object, return inexact statistics by skipping the respective object.
     212         */
     213       
     214        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
     215                return 0;
     216       
     217        size_t pages = 0;
     218       
     219        /* Walk the B+ tree and count pages */
     220        link_t *cur;
     221        for (cur = as->as_area_btree.leaf_head.next;
     222            cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     223                btree_node_t *node =
     224                    list_get_instance(cur, btree_node_t, leaf_link);
     225               
     226                unsigned int i;
     227                for (i = 0; i < node->keys; i++) {
     228                        as_area_t *area = node->value[i];
     229                       
     230                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
     231                                continue;
     232                       
     233                        pages += area->resident;
     234                        mutex_unlock(&area->lock);
     235                }
     236        }
     237       
     238        mutex_unlock(&as->lock);
     239       
     240        return (pages << PAGE_WIDTH);
    259241}
    260242
  • kernel/generic/src/time/clock.c

    re778543 r17aca1c  
    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.