Changeset 8b655705 in mainline for kernel/generic/src


Ignore:
Timestamp:
2011-04-15T19:38:07Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9dd730d1
Parents:
6b9e85b (diff), b2fb47f (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/generic/src
Files:
24 edited
1 moved

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/adt/avl.c

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

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

    r6b9e85b r8b655705  
    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

    r6b9e85b r8b655705  
    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

    r6b9e85b r8b655705  
    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

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

    r6b9e85b r8b655705  
    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

    r6b9e85b r8b655705  
    248248                        /* The connection was accepted */
    249249                        phone_connect(phoneid, &answer->sender->answerbox);
     250                        /* Set 'task hash' as arg4 of response */
     251                        IPC_SET_ARG4(answer->data, (sysarg_t) TASK);
    250252                        /* Set 'phone hash' as arg5 of response */
    251253                        IPC_SET_ARG5(answer->data,
     
    424426        case IPC_M_DATA_READ: {
    425427                size_t size = IPC_GET_ARG2(call->data);
    426                 if ((size <= 0 || (size > DATA_XFER_LIMIT)))
     428                if (size <= 0)
    427429                        return ELIMIT;
    428                
     430                if (size > DATA_XFER_LIMIT) {
     431                        int flags = IPC_GET_ARG3(call->data);
     432                        if (flags & IPC_XF_RESTRICT)
     433                                IPC_SET_ARG2(call->data, DATA_XFER_LIMIT);
     434                        else
     435                                return ELIMIT;
     436                }
    429437                break;
    430438        }
     
    433441                size_t size = IPC_GET_ARG2(call->data);
    434442               
    435                 if (size > DATA_XFER_LIMIT)
    436                         return ELIMIT;
     443                if (size > DATA_XFER_LIMIT) {
     444                        int flags = IPC_GET_ARG3(call->data);
     445                        if (flags & IPC_XF_RESTRICT) {
     446                                size = DATA_XFER_LIMIT;
     447                                IPC_SET_ARG2(call->data, size);
     448                        } else
     449                                return ELIMIT;
     450                }
    437451               
    438452                call->buffer = (uint8_t *) malloc(size, 0);
     
    11031117 *
    11041118 */
    1105 sysarg_t sys_ipc_register_irq(inr_t inr, devno_t devno, sysarg_t imethod,
     1119sysarg_t sys_register_irq(inr_t inr, devno_t devno, sysarg_t imethod,
    11061120    irq_code_t *ucode)
    11071121{
     
    11201134 *
    11211135 */
    1122 sysarg_t sys_ipc_unregister_irq(inr_t inr, devno_t devno)
     1136sysarg_t sys_unregister_irq(inr_t inr, devno_t devno)
    11231137{
    11241138        if (!(cap_get(TASK) & CAP_IRQ_REG))
  • kernel/generic/src/lib/elf.c

    r6b9e85b r8b655705  
    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/memfnc.c

    r6b9e85b r8b655705  
    1 /*
    2  * Copyright (c) 2007 Jan Hudecek
    3  * Copyright (c) 2008 Martin Decky
     1        /*
     2 * Copyright (c) 2011 Martin Decky
    43 * All rights reserved.
    54 *
     
    2827 */
    2928
    30 /** @addtogroup genericproc
     29/** @addtogroup generic
    3130 * @{
    3231 */
    33 /** @file tasklet.h
    34  * @brief Tasklets declarations
     32
     33/**
     34 * @file
     35 * @brief Memory string functions.
     36 *
     37 * This file provides architecture independent functions to manipulate blocks
     38 * of memory. These functions are optimized as much as generic functions of
     39 * this type can be.
    3540 */
    3641
    37 #ifndef KERN_TASKLET_H_
    38 #define KERN_TASKLET_H_
     42#include <lib/memfnc.h>
     43#include <typedefs.h>
    3944
    40 #include <adt/list.h>
     45/** Fill block of memory.
     46 *
     47 * Fill cnt bytes at dst address with the value val.
     48 *
     49 * @param dst Destination address to fill.
     50 * @param val Value to fill.
     51 * @param cnt Number of bytes to fill.
     52 *
     53 * @return Destination address.
     54 *
     55 */
     56void *memset(void *dst, int val, size_t cnt)
     57{
     58        size_t i;
     59        uint8_t *ptr = (uint8_t *) dst;
     60       
     61        for (i = 0; i < cnt; i++)
     62                ptr[i] = val;
     63       
     64        return dst;
     65}
    4166
    42 /** Tasklet callback type */
    43 typedef void (* tasklet_callback_t)(void *arg);
    44 
    45 /** Tasklet state */
    46 typedef enum {
    47         NotActive,
    48         Scheduled,
    49         InProgress,
    50         Disabled
    51 } tasklet_state_t;
    52 
    53 /** Structure describing a tasklet */
    54 typedef struct tasklet_descriptor {
    55         link_t link;
     67/** Move memory block without overlapping.
     68 *
     69 * Copy cnt bytes from src address to dst address. The source
     70 * and destination memory areas cannot overlap.
     71 *
     72 * @param dst Destination address to copy to.
     73 * @param src Source address to copy from.
     74 * @param cnt Number of bytes to copy.
     75 *
     76 * @return Destination address.
     77 *
     78 */
     79void *memcpy(void *dst, const void *src, size_t cnt)
     80{
     81        uint8_t *dp = (uint8_t *) dst;
     82        const uint8_t *sp = (uint8_t *) src;
    5683       
    57         /** Callback to call */
    58         tasklet_callback_t callback;
     84        while (cnt-- != 0)
     85                        *dp++ = *sp++;
    5986       
    60         /** Argument passed to the callback */
    61         void *arg;
    62        
    63         /** State of the tasklet */
    64         tasklet_state_t state;
    65 } tasklet_descriptor_t;
    66 
    67 
    68 extern void tasklet_init(void);
    69 
    70 #endif
     87        return dst;
     88}
    7189
    7290/** @}
  • kernel/generic/src/lib/memstr.c

    r6b9e85b r8b655705  
    2828 */
    2929
    30 /** @addtogroup generic 
     30/** @addtogroup generic
    3131 * @{
    3232 */
     
    3434/**
    3535 * @file
    36  * @brief       Memory string operations.
     36 * @brief Memory string operations.
    3737 *
    38  * This file provides architecture independent functions to manipulate blocks of
    39  * memory. These functions are optimized as much as generic functions of this
    40  * type can be. However, architectures are free to provide even more optimized
    41  * versions of these functions.
     38 * This file provides architecture independent functions to manipulate blocks
     39 * of memory. These functions are optimized as much as generic functions of
     40 * this type can be.
    4241 */
    4342
    4443#include <memstr.h>
    4544#include <typedefs.h>
    46 #include <align.h>
    4745
    48 /** Copy block of memory.
     46/** Fill block of memory.
    4947 *
    50  * Copy cnt bytes from src address to dst address.  The copying is done
    51  * word-by-word and then byte-by-byte.  The source and destination memory areas
    52  * cannot overlap.
     48 * Fill cnt bytes at dst address with the value val.
    5349 *
    54  * @param src           Source address to copy from.
    55  * @param dst           Destination address to copy to.
    56  * @param cnt           Number of bytes to copy.
     50 * @param dst Destination address to fill.
     51 * @param cnt Number of bytes to fill.
     52 * @param val Value to fill.
    5753 *
    58  * @return              Destination address.
    5954 */
    60 void *_memcpy(void *dst, const void *src, size_t cnt)
     55void memsetb(void *dst, size_t cnt, uint8_t val)
    6156{
    62         unsigned int i, j;
     57        memset(dst, val, cnt);
     58}
     59
     60/** Fill block of memory.
     61 *
     62 * Fill cnt words at dst address with the value val. The filling
     63 * is done word-by-word.
     64 *
     65 * @param dst Destination address to fill.
     66 * @param cnt Number of words to fill.
     67 * @param val Value to fill.
     68 *
     69 */
     70void memsetw(void *dst, size_t cnt, uint16_t val)
     71{
     72        size_t i;
     73        uint16_t *ptr = (uint16_t *) dst;
    6374       
    64         if (ALIGN_UP((uintptr_t) src, sizeof(sysarg_t)) != (uintptr_t) src ||
    65             ALIGN_UP((uintptr_t) dst, sizeof(sysarg_t)) != (uintptr_t) dst) {
    66                 for (i = 0; i < cnt; i++)
    67                         ((uint8_t *) dst)[i] = ((uint8_t *) src)[i];
    68         } else {
    69                 for (i = 0; i < cnt / sizeof(sysarg_t); i++)
    70                         ((sysarg_t *) dst)[i] = ((sysarg_t *) src)[i];
    71                
    72                 for (j = 0; j < cnt % sizeof(sysarg_t); j++)
    73                         ((uint8_t *)(((sysarg_t *) dst) + i))[j] =
    74                             ((uint8_t *)(((sysarg_t *) src) + i))[j];
    75         }
    76                
    77         return (char *) dst;
     75        for (i = 0; i < cnt; i++)
     76                ptr[i] = val;
    7877}
    7978
    8079/** Move memory block with possible overlapping.
    8180 *
    82  * Copy cnt bytes from src address to dst address. The source and destination
    83  * memory areas may overlap.
     81 * Copy cnt bytes from src address to dst address. The source
     82 * and destination memory areas may overlap.
    8483 *
    85  * @param src           Source address to copy from.
    86  * @param dst           Destination address to copy to.
    87  * @param cnt           Number of bytes to copy.
     84 * @param dst Destination address to copy to.
     85 * @param src Source address to copy from.
     86 * @param cnt Number of bytes to copy.
    8887 *
    89  * @return              Destination address.
     88 * @return Destination address.
     89 *
    9090 */
    91 void *memmove(void *dst, const void *src, size_t n)
     91void *memmove(void *dst, const void *src, size_t cnt)
    9292{
    93         const uint8_t *sp;
    94         uint8_t *dp;
    95 
    9693        /* Nothing to do? */
    9794        if (src == dst)
    9895                return dst;
    99 
     96       
    10097        /* Non-overlapping? */
    101         if (dst >= src + n || src >= dst + n) {
    102                 return memcpy(dst, src, n);
    103         }
    104 
     98        if ((dst >= src + cnt) || (src >= dst + cnt))
     99                return memcpy(dst, src, cnt);
     100       
     101        uint8_t *dp;
     102        const uint8_t *sp;
     103       
    105104        /* Which direction? */
    106105        if (src > dst) {
    107106                /* Forwards. */
     107                dp = dst;
    108108                sp = src;
    109                 dp = dst;
    110 
    111                 while (n-- != 0)
     109               
     110                while (cnt-- != 0)
    112111                        *dp++ = *sp++;
    113112        } else {
    114113                /* Backwards. */
    115                 sp = src + (n - 1);
    116                 dp = dst + (n - 1);
    117 
    118                 while (n-- != 0)
     114                dp = dst + (cnt - 1);
     115                sp = src + (cnt - 1);
     116               
     117                while (cnt-- != 0)
    119118                        *dp-- = *sp--;
    120119        }
    121 
     120       
    122121        return dst;
    123 }
    124 
    125 /** Fill block of memory
    126  *
    127  * Fill cnt bytes at dst address with the value x.  The filling is done
    128  * byte-by-byte.
    129  *
    130  * @param dst           Destination address to fill.
    131  * @param cnt           Number of bytes to fill.
    132  * @param x             Value to fill.
    133  *
    134  */
    135 void _memsetb(void *dst, size_t cnt, uint8_t x)
    136 {
    137         unsigned int i;
    138         uint8_t *p = (uint8_t *) dst;
    139        
    140         for (i = 0; i < cnt; i++)
    141                 p[i] = x;
    142 }
    143 
    144 /** Fill block of memory.
    145  *
    146  * Fill cnt words at dst address with the value x.  The filling is done
    147  * word-by-word.
    148  *
    149  * @param dst           Destination address to fill.
    150  * @param cnt           Number of words to fill.
    151  * @param x             Value to fill.
    152  *
    153  */
    154 void _memsetw(void *dst, size_t cnt, uint16_t x)
    155 {
    156         unsigned int i;
    157         uint16_t *p = (uint16_t *) dst;
    158        
    159         for (i = 0; i < cnt; i++)
    160                 p[i] = x;       
    161122}
    162123
  • kernel/generic/src/lib/rd.c

    r6b9e85b r8b655705  
    9090            FRAME_SIZE);
    9191        rd_parea.frames = SIZE2FRAMES(dsize);
     92        rd_parea.unpriv = false;
    9293        ddi_parea_register(&rd_parea);
    9394
  • kernel/generic/src/main/main.c

    r6b9e85b r8b655705  
    5858#include <proc/thread.h>
    5959#include <proc/task.h>
    60 #include <proc/tasklet.h>
    6160#include <main/kinit.h>
    6261#include <main/version.h>
     
    217216        tlb_init();
    218217        ddi_init();
    219         tasklet_init();
    220218        arch_post_mm_init();
    221219        arch_pre_smp_init();
  • kernel/generic/src/mm/as.c

    r6b9e85b r8b655705  
    7171#include <memstr.h>
    7272#include <macros.h>
     73#include <bitops.h>
    7374#include <arch.h>
    7475#include <errno.h>
     
    8283 * Each architecture decides what functions will be used to carry out
    8384 * address space operations such as creating or locking page tables.
    84  *
    8585 */
    8686as_operations_t *as_operations = NULL;
    8787
    88 /**
    89  * Slab for as_t objects.
     88/** Slab for as_t objects.
    9089 *
    9190 */
    9291static slab_cache_t *as_slab;
    9392
    94 /**
    95  * This lock serializes access to the ASID subsystem.
    96  * It protects:
     93/** ASID subsystem lock.
     94 *
     95 * This lock protects:
    9796 * - inactive_as_with_asid_head list
    9897 * - as->asid for each as of the as_t type
     
    103102
    104103/**
    105  * This list contains address spaces that are not active on any
    106  * processor and that have valid ASID.
    107  *
     104 * Inactive address spaces (on all processors)
     105 * that have valid ASID.
    108106 */
    109107LIST_INITIALIZE(inactive_as_with_asid_head);
     
    119117        mutex_initialize(&as->lock, MUTEX_PASSIVE);
    120118       
    121         int rc = as_constructor_arch(as, flags);
    122        
    123         return rc;
     119        return as_constructor_arch(as, flags);
    124120}
    125121
    126122NO_TRACE static size_t as_destructor(void *obj)
    127123{
    128         as_t *as = (as_t *) obj;
    129         return as_destructor_arch(as);
     124        return as_destructor_arch((as_t *) obj);
    130125}
    131126
     
    142137                panic("Cannot create kernel address space.");
    143138       
    144         /* Make sure the kernel address space
     139        /*
     140         * Make sure the kernel address space
    145141         * reference count never drops to zero.
    146142         */
     
    191187{
    192188        DEADLOCK_PROBE_INIT(p_asidlock);
    193 
     189       
    194190        ASSERT(as != AS);
    195191        ASSERT(atomic_get(&as->refcount) == 0);
     
    199195         * lock its mutex.
    200196         */
    201 
     197       
    202198        /*
    203199         * We need to avoid deadlock between TLB shootdown and asidlock.
     
    206202         * disabled to prevent nested context switches. We also depend on the
    207203         * fact that so far no spinlocks are held.
    208          *
    209204         */
    210205        preemption_disable();
     
    231226        spinlock_unlock(&asidlock);
    232227        interrupts_restore(ipl);
    233 
     228       
    234229       
    235230        /*
     
    237232         * The B+tree must be walked carefully because it is
    238233         * also being destroyed.
    239          *
    240234         */
    241235        bool cond = true;
     
    264258/** Hold a reference to an address space.
    265259 *
    266  * Holding a reference to an address space prevents destruction of that address
    267  * space.
     260 * Holding a reference to an address space prevents destruction
     261 * of that address space.
    268262 *
    269263 * @param as Address space to be held.
     
    277271/** Release a reference to an address space.
    278272 *
    279  * The last one to release a reference to an address space destroys the address
    280  * space.
     273 * The last one to release a reference to an address space
     274 * destroys the address space.
    281275 *
    282276 * @param asAddress space to be released.
     
    291285/** Check area conflicts with other areas.
    292286 *
    293  * @param as         Address space.
    294  * @param va         Starting virtual address of the area being tested.
    295  * @param size       Size of the area being tested.
    296  * @param avoid_area Do not touch this area.
     287 * @param as    Address space.
     288 * @param addr  Starting virtual address of the area being tested.
     289 * @param count Number of pages in the area being tested.
     290 * @param avoid Do not touch this area.
    297291 *
    298292 * @return True if there is no conflict, false otherwise.
    299293 *
    300294 */
    301 NO_TRACE static bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,
    302     as_area_t *avoid_area)
    303 {
     295NO_TRACE static bool check_area_conflicts(as_t *as, uintptr_t addr,
     296    size_t count, as_area_t *avoid)
     297{
     298        ASSERT((addr % PAGE_SIZE) == 0);
    304299        ASSERT(mutex_locked(&as->lock));
    305300       
    306301        /*
    307302         * We don't want any area to have conflicts with NULL page.
    308          *
    309          */
    310         if (overlaps(va, size, (uintptr_t) NULL, PAGE_SIZE))
     303         */
     304        if (overlaps(addr, count << PAGE_WIDTH, (uintptr_t) NULL, PAGE_SIZE))
    311305                return false;
    312306       
     
    317311         * record in the left neighbour, the leftmost record in the right
    318312         * neighbour and all records in the leaf node itself.
    319          *
    320313         */
    321314        btree_node_t *leaf;
    322315        as_area_t *area =
    323             (as_area_t *) btree_search(&as->as_area_btree, va, &leaf);
     316            (as_area_t *) btree_search(&as->as_area_btree, addr, &leaf);
    324317        if (area) {
    325                 if (area != avoid_area)
     318                if (area != avoid)
    326319                        return false;
    327320        }
     
    333326                area = (as_area_t *) node->value[node->keys - 1];
    334327               
    335                 mutex_lock(&area->lock);
    336                
    337                 if (overlaps(va, size, area->base, area->pages * PAGE_SIZE)) {
     328                if (area != avoid) {
     329                        mutex_lock(&area->lock);
     330                       
     331                        if (overlaps(addr, count << PAGE_WIDTH,
     332                            area->base, area->pages << PAGE_WIDTH)) {
     333                                mutex_unlock(&area->lock);
     334                                return false;
     335                        }
     336                       
    338337                        mutex_unlock(&area->lock);
    339                         return false;
    340                 }
    341                
    342                 mutex_unlock(&area->lock);
     338                }
    343339        }
    344340       
     
    347343                area = (as_area_t *) node->value[0];
    348344               
    349                 mutex_lock(&area->lock);
    350                
    351                 if (overlaps(va, size, area->base, area->pages * PAGE_SIZE)) {
     345                if (area != avoid) {
     346                        mutex_lock(&area->lock);
     347                       
     348                        if (overlaps(addr, count << PAGE_WIDTH,
     349                            area->base, area->pages << PAGE_WIDTH)) {
     350                                mutex_unlock(&area->lock);
     351                                return false;
     352                        }
     353                       
    352354                        mutex_unlock(&area->lock);
    353                         return false;
    354                 }
    355                
    356                 mutex_unlock(&area->lock);
     355                }
    357356        }
    358357       
     
    362361                area = (as_area_t *) leaf->value[i];
    363362               
    364                 if (area == avoid_area)
     363                if (area == avoid)
    365364                        continue;
    366365               
    367366                mutex_lock(&area->lock);
    368367               
    369                 if (overlaps(va, size, area->base, area->pages * PAGE_SIZE)) {
     368                if (overlaps(addr, count << PAGE_WIDTH,
     369                    area->base, area->pages << PAGE_WIDTH)) {
    370370                        mutex_unlock(&area->lock);
    371371                        return false;
     
    378378         * So far, the area does not conflict with other areas.
    379379         * Check if it doesn't conflict with kernel address space.
    380          *
    381380         */
    382381        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    383                 return !overlaps(va, size,
     382                return !overlaps(addr, count << PAGE_WIDTH,
    384383                    KERNEL_ADDRESS_SPACE_START,
    385384                    KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START);
     
    408407    mem_backend_data_t *backend_data)
    409408{
    410         if (base % PAGE_SIZE)
     409        if ((base % PAGE_SIZE) != 0)
    411410                return NULL;
    412411       
    413         if (!size)
     412        if (size == 0)
    414413                return NULL;
     414       
     415        size_t pages = SIZE2FRAMES(size);
    415416       
    416417        /* Writeable executable areas are not supported. */
     
    420421        mutex_lock(&as->lock);
    421422       
    422         if (!check_area_conflicts(as, base, size, NULL)) {
     423        if (!check_area_conflicts(as, base, pages, NULL)) {
    423424                mutex_unlock(&as->lock);
    424425                return NULL;
     
    432433        area->flags = flags;
    433434        area->attributes = attrs;
    434         area->pages = SIZE2FRAMES(size);
     435        area->pages = pages;
     436        area->resident = 0;
    435437        area->base = base;
    436438        area->sh_info = NULL;
     
    475477         * to find out whether this is a miss or va belongs to an address
    476478         * space area found there.
    477          *
    478479         */
    479480       
     
    486487                mutex_lock(&area->lock);
    487488               
    488                 if ((area->base <= va) && (va < area->base + area->pages * PAGE_SIZE))
     489                if ((area->base <= va) &&
     490                    (va < area->base + (area->pages << PAGE_WIDTH)))
    489491                        return area;
    490492               
     
    495497         * Second, locate the left neighbour and test its last record.
    496498         * Because of its position in the B+tree, it must have base < va.
    497          *
    498499         */
    499500        btree_node_t *lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf);
     
    503504                mutex_lock(&area->lock);
    504505               
    505                 if (va < area->base + area->pages * PAGE_SIZE)
     506                if (va < area->base + (area->pages << PAGE_WIDTH))
    506507                        return area;
    507508               
     
    530531        /*
    531532         * Locate the area.
    532          *
    533533         */
    534534        as_area_t *area = find_area_and_lock(as, address);
     
    542542                 * Remapping of address space areas associated
    543543                 * with memory mapped devices is not supported.
    544                  *
    545544                 */
    546545                mutex_unlock(&area->lock);
     
    553552                 * Remapping of shared address space areas
    554553                 * is not supported.
    555                  *
    556554                 */
    557555                mutex_unlock(&area->lock);
     
    564562                /*
    565563                 * Zero size address space areas are not allowed.
    566                  *
    567564                 */
    568565                mutex_unlock(&area->lock);
     
    572569       
    573570        if (pages < area->pages) {
    574                 uintptr_t start_free = area->base + pages * PAGE_SIZE;
     571                uintptr_t start_free = area->base + (pages << PAGE_WIDTH);
    575572               
    576573                /*
    577574                 * Shrinking the area.
    578575                 * No need to check for overlaps.
    579                  *
    580576                 */
    581577               
     
    584580                /*
    585581                 * Start TLB shootdown sequence.
    586                  *
    587582                 */
    588583                ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid,
    589                     area->base + pages * PAGE_SIZE, area->pages - pages);
     584                    area->base + (pages << PAGE_WIDTH), area->pages - pages);
    590585               
    591586                /*
     
    595590                 * is also the right way to remove part of the used_space
    596591                 * B+tree leaf list.
    597                  *
    598592                 */
    599593                bool cond = true;
     
    611605                                size_t i = 0;
    612606                               
    613                                 if (overlaps(ptr, size * PAGE_SIZE, area->base,
    614                                     pages * PAGE_SIZE)) {
     607                                if (overlaps(ptr, size << PAGE_WIDTH, area->base,
     608                                    pages << PAGE_WIDTH)) {
    615609                                       
    616                                         if (ptr + size * PAGE_SIZE <= start_free) {
     610                                        if (ptr + (size << PAGE_WIDTH) <= start_free) {
    617611                                                /*
    618612                                                 * The whole interval fits
    619613                                                 * completely in the resized
    620614                                                 * address space area.
    621                                                  *
    622615                                                 */
    623616                                                break;
     
    628621                                         * to b and c overlaps with the resized
    629622                                         * address space area.
    630                                          *
    631623                                         */
    632624                                       
     
    648640                                for (; i < size; i++) {
    649641                                        pte_t *pte = page_mapping_find(as, ptr +
    650                                             i * PAGE_SIZE);
     642                                            (i << PAGE_WIDTH));
    651643                                       
    652644                                        ASSERT(pte);
     
    657649                                            (area->backend->frame_free)) {
    658650                                                area->backend->frame_free(area,
    659                                                     ptr + i * PAGE_SIZE,
     651                                                    ptr + (i << PAGE_WIDTH),
    660652                                                    PTE_GET_FRAME(pte));
    661653                                        }
    662654                                       
    663655                                        page_mapping_remove(as, ptr +
    664                                             i * PAGE_SIZE);
     656                                            (i << PAGE_WIDTH));
    665657                                }
    666658                        }
     
    669661                /*
    670662                 * Finish TLB shootdown sequence.
    671                  *
    672                  */
    673                
    674                 tlb_invalidate_pages(as->asid, area->base + pages * PAGE_SIZE,
     663                 */
     664               
     665                tlb_invalidate_pages(as->asid, area->base + (pages << PAGE_WIDTH),
    675666                    area->pages - pages);
    676667               
    677668                /*
    678669                 * Invalidate software translation caches (e.g. TSB on sparc64).
    679                  *
    680670                 */
    681671                as_invalidate_translation_cache(as, area->base +
    682                     pages * PAGE_SIZE, area->pages - pages);
     672                    (pages << PAGE_WIDTH), area->pages - pages);
    683673                tlb_shootdown_finalize(ipl);
    684674               
     
    688678                 * Growing the area.
    689679                 * Check for overlaps with other address space areas.
    690                  *
    691                  */
    692                 if (!check_area_conflicts(as, address, pages * PAGE_SIZE,
    693                     area)) {
     680                 */
     681                if (!check_area_conflicts(as, address, pages, area)) {
    694682                        mutex_unlock(&area->lock);
    695683                        mutex_unlock(&as->lock);
     
    790778                       
    791779                        for (size = 0; size < (size_t) node->value[i]; size++) {
    792                                 pte_t *pte = page_mapping_find(as, ptr + size * PAGE_SIZE);
     780                                pte_t *pte =
     781                                    page_mapping_find(as, ptr + (size << PAGE_WIDTH));
    793782                               
    794783                                ASSERT(pte);
     
    799788                                    (area->backend->frame_free)) {
    800789                                        area->backend->frame_free(area,
    801                                             ptr + size * PAGE_SIZE, PTE_GET_FRAME(pte));
     790                                            ptr + (size << PAGE_WIDTH), PTE_GET_FRAME(pte));
    802791                                }
    803792                               
    804                                 page_mapping_remove(as, ptr + size * PAGE_SIZE);
     793                                page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
    805794                        }
    806795                }
     
    809798        /*
    810799         * Finish TLB shootdown sequence.
    811          *
    812800         */
    813801       
     
    817805         * Invalidate potential software translation caches (e.g. TSB on
    818806         * sparc64).
    819          *
    820807         */
    821808        as_invalidate_translation_cache(as, area->base, area->pages);
     
    835822        /*
    836823         * Remove the empty area from address space.
    837          *
    838824         */
    839825        btree_remove(&as->as_area_btree, base, NULL);
     
    877863                /*
    878864                 * Could not find the source address space area.
    879                  *
    880865                 */
    881866                mutex_unlock(&src_as->lock);
     
    887872                 * There is no backend or the backend does not
    888873                 * know how to share the area.
    889                  *
    890874                 */
    891875                mutex_unlock(&src_area->lock);
     
    894878        }
    895879       
    896         size_t src_size = src_area->pages * PAGE_SIZE;
     880        size_t src_size = src_area->pages << PAGE_WIDTH;
    897881        unsigned int src_flags = src_area->flags;
    898882        mem_backend_t *src_backend = src_area->backend;
     
    914898         * First, prepare the area for sharing.
    915899         * Then it will be safe to unlock it.
    916          *
    917900         */
    918901        share_info_t *sh_info = src_area->sh_info;
     
    926909                /*
    927910                 * Call the backend to setup sharing.
    928                  *
    929911                 */
    930912                src_area->backend->share(src_area);
     
    945927         * The flags of the source area are masked against dst_flags_mask
    946928         * to support sharing in less privileged mode.
    947          *
    948929         */
    949930        as_area_t *dst_area = as_area_create(dst_as, dst_flags_mask, src_size,
     
    962943         * fully initialized. Clear the AS_AREA_ATTR_PARTIAL
    963944         * attribute and set the sh_info.
    964          *
    965945         */
    966946        mutex_lock(&dst_as->lock);
     
    985965NO_TRACE bool as_area_check_access(as_area_t *area, pf_access_t access)
    986966{
     967        ASSERT(mutex_locked(&area->lock));
     968       
    987969        int flagmap[] = {
    988970                [PF_ACCESS_READ] = AS_AREA_READ,
     
    990972                [PF_ACCESS_EXEC] = AS_AREA_EXEC
    991973        };
    992 
    993         ASSERT(mutex_locked(&area->lock));
    994974       
    995975        if (!(area->flags & flagmap[access]))
     
    10621042        /*
    10631043         * Compute total number of used pages in the used_space B+tree
    1064          *
    10651044         */
    10661045        size_t used_pages = 0;
     
    10841063        /*
    10851064         * Start TLB shootdown sequence.
    1086          *
    10871065         */
    10881066        ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid, area->base,
     
    10921070         * Remove used pages from page tables and remember their frame
    10931071         * numbers.
    1094          *
    10951072         */
    10961073        size_t frame_idx = 0;
     
    11071084                       
    11081085                        for (size = 0; size < (size_t) node->value[i]; size++) {
    1109                                 pte_t *pte = page_mapping_find(as, ptr + size * PAGE_SIZE);
     1086                                pte_t *pte =
     1087                                    page_mapping_find(as, ptr + (size << PAGE_WIDTH));
    11101088                               
    11111089                                ASSERT(pte);
     
    11161094                               
    11171095                                /* Remove old mapping */
    1118                                 page_mapping_remove(as, ptr + size * PAGE_SIZE);
     1096                                page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
    11191097                        }
    11201098                }
     
    11231101        /*
    11241102         * Finish TLB shootdown sequence.
    1125          *
    11261103         */
    11271104       
     
    11311108         * Invalidate potential software translation caches (e.g. TSB on
    11321109         * sparc64).
    1133          *
    11341110         */
    11351111        as_invalidate_translation_cache(as, area->base, area->pages);
     
    11641140                               
    11651141                                /* Insert the new mapping */
    1166                                 page_mapping_insert(as, ptr + size * PAGE_SIZE,
     1142                                page_mapping_insert(as, ptr + (size << PAGE_WIDTH),
    11671143                                    old_frame[frame_idx++], page_flags);
    11681144                               
     
    12131189                 * No area contained mapping for 'page'.
    12141190                 * Signal page fault to low-level handler.
    1215                  *
    12161191                 */
    12171192                mutex_unlock(&AS->lock);
     
    12331208                 * The address space area is not backed by any backend
    12341209                 * or the backend cannot handle page faults.
    1235                  *
    12361210                 */
    12371211                mutex_unlock(&area->lock);
     
    12451219         * To avoid race condition between two page faults on the same address,
    12461220         * we need to make sure the mapping has not been already inserted.
    1247          *
    12481221         */
    12491222        pte_t *pte;
     
    12631236        /*
    12641237         * Resort to the backend page fault handler.
    1265          *
    12661238         */
    12671239        if (area->backend->page_fault(area, page, access) != AS_PF_OK) {
     
    13181290                 * preemption is disabled. We should not be
    13191291                 * holding any other lock.
    1320                  *
    13211292                 */
    13221293                (void) interrupts_enable();
     
    13381309                         * list of inactive address spaces with assigned
    13391310                         * ASID.
    1340                          *
    13411311                         */
    13421312                        ASSERT(old_as->asid != ASID_INVALID);
     
    13491319                 * Perform architecture-specific tasks when the address space
    13501320                 * is being removed from the CPU.
    1351                  *
    13521321                 */
    13531322                as_deinstall_arch(old_as);
     
    13561325        /*
    13571326         * Second, prepare the new address space.
    1358          *
    13591327         */
    13601328        if ((new_as->cpu_refcount++ == 0) && (new_as != AS_KERNEL)) {
     
    13721340         * Perform architecture-specific steps.
    13731341         * (e.g. write ASID to hardware register etc.)
    1374          *
    13751342         */
    13761343        as_install_arch(new_as);
     
    13911358{
    13921359        ASSERT(mutex_locked(&area->lock));
    1393 
     1360       
    13941361        return area_flags_to_page_flags(area->flags);
    13951362}
     
    14951462       
    14961463        if (src_area) {
    1497                 size = src_area->pages * PAGE_SIZE;
     1464                size = src_area->pages << PAGE_WIDTH;
    14981465                mutex_unlock(&src_area->lock);
    14991466        } else
     
    15121479 * @param count Number of page to be marked.
    15131480 *
    1514  * @return Zero on failure and non-zero on success.
    1515  *
    1516  */
    1517 int used_space_insert(as_area_t *area, uintptr_t page, size_t count)
     1481 * @return False on failure or true on success.
     1482 *
     1483 */
     1484bool used_space_insert(as_area_t *area, uintptr_t page, size_t count)
    15181485{
    15191486        ASSERT(mutex_locked(&area->lock));
     
    15261493                /*
    15271494                 * We hit the beginning of some used space.
    1528                  *
    1529                  */
    1530                 return 0;
     1495                 */
     1496                return false;
    15311497        }
    15321498       
    15331499        if (!leaf->keys) {
    15341500                btree_insert(&area->used_space, page, (void *) count, leaf);
    1535                 return 1;
     1501                goto success;
    15361502        }
    15371503       
     
    15471513                 * somewhere between the rightmost interval of
    15481514                 * the left neigbour and the first interval of the leaf.
    1549                  *
    15501515                 */
    15511516               
    15521517                if (page >= right_pg) {
    15531518                        /* Do nothing. */
    1554                 } else if (overlaps(page, count * PAGE_SIZE, left_pg,
    1555                     left_cnt * PAGE_SIZE)) {
     1519                } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1520                    left_cnt << PAGE_WIDTH)) {
    15561521                        /* The interval intersects with the left interval. */
    1557                         return 0;
    1558                 } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    1559                     right_cnt * PAGE_SIZE)) {
     1522                        return false;
     1523                } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1524                    right_cnt << PAGE_WIDTH)) {
    15601525                        /* The interval intersects with the right interval. */
    1561                         return 0;
    1562                 } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    1563                     (page + count * PAGE_SIZE == right_pg)) {
     1526                        return false;
     1527                } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
     1528                    (page + (count << PAGE_WIDTH) == right_pg)) {
    15641529                        /*
    15651530                         * The interval can be added by merging the two already
    15661531                         * present intervals.
    1567                          *
    15681532                         */
    15691533                        node->value[node->keys - 1] += count + right_cnt;
    15701534                        btree_remove(&area->used_space, right_pg, leaf);
    1571                         return 1;
    1572                 } else if (page == left_pg + left_cnt * PAGE_SIZE) {
     1535                        goto success;
     1536                } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
    15731537                        /*
    15741538                         * The interval can be added by simply growing the left
    15751539                         * interval.
    1576                          *
    15771540                         */
    15781541                        node->value[node->keys - 1] += count;
    1579                         return 1;
    1580                 } else if (page + count * PAGE_SIZE == right_pg) {
     1542                        goto success;
     1543                } else if (page + (count << PAGE_WIDTH) == right_pg) {
    15811544                        /*
    15821545                         * The interval can be addded by simply moving base of
    15831546                         * the right interval down and increasing its size
    15841547                         * accordingly.
    1585                          *
    15861548                         */
    15871549                        leaf->value[0] += count;
    15881550                        leaf->key[0] = page;
    1589                         return 1;
     1551                        goto success;
    15901552                } else {
    15911553                        /*
    15921554                         * The interval is between both neigbouring intervals,
    15931555                         * but cannot be merged with any of them.
    1594                          *
    15951556                         */
    15961557                        btree_insert(&area->used_space, page, (void *) count,
    15971558                            leaf);
    1598                         return 1;
     1559                        goto success;
    15991560                }
    16001561        } else if (page < leaf->key[0]) {
     
    16051566                 * Investigate the border case in which the left neighbour does
    16061567                 * not exist but the interval fits from the left.
    1607                  *
    1608                  */
    1609                
    1610                 if (overlaps(page, count * PAGE_SIZE, right_pg,
    1611                     right_cnt * PAGE_SIZE)) {
     1568                 */
     1569               
     1570                if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1571                    right_cnt << PAGE_WIDTH)) {
    16121572                        /* The interval intersects with the right interval. */
    1613                         return 0;
    1614                 } else if (page + count * PAGE_SIZE == right_pg) {
     1573                        return false;
     1574                } else if (page + (count << PAGE_WIDTH) == right_pg) {
    16151575                        /*
    16161576                         * The interval can be added by moving the base of the
    16171577                         * right interval down and increasing its size
    16181578                         * accordingly.
    1619                          *
    16201579                         */
    16211580                        leaf->key[0] = page;
    16221581                        leaf->value[0] += count;
    1623                         return 1;
     1582                        goto success;
    16241583                } else {
    16251584                        /*
    16261585                         * The interval doesn't adjoin with the right interval.
    16271586                         * It must be added individually.
    1628                          *
    16291587                         */
    16301588                        btree_insert(&area->used_space, page, (void *) count,
    16311589                            leaf);
    1632                         return 1;
     1590                        goto success;
    16331591                }
    16341592        }
     
    16451603                 * somewhere between the leftmost interval of
    16461604                 * the right neigbour and the last interval of the leaf.
    1647                  *
    16481605                 */
    16491606               
    16501607                if (page < left_pg) {
    16511608                        /* Do nothing. */
    1652                 } else if (overlaps(page, count * PAGE_SIZE, left_pg,
    1653                     left_cnt * PAGE_SIZE)) {
     1609                } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1610                    left_cnt << PAGE_WIDTH)) {
    16541611                        /* The interval intersects with the left interval. */
    1655                         return 0;
    1656                 } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    1657                     right_cnt * PAGE_SIZE)) {
     1612                        return false;
     1613                } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1614                    right_cnt << PAGE_WIDTH)) {
    16581615                        /* The interval intersects with the right interval. */
    1659                         return 0;
    1660                 } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    1661                     (page + count * PAGE_SIZE == right_pg)) {
     1616                        return false;
     1617                } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
     1618                    (page + (count << PAGE_WIDTH) == right_pg)) {
    16621619                        /*
    16631620                         * The interval can be added by merging the two already
    16641621                         * present intervals.
    1665                          *
    16661622                         */
    16671623                        leaf->value[leaf->keys - 1] += count + right_cnt;
    16681624                        btree_remove(&area->used_space, right_pg, node);
    1669                         return 1;
    1670                 } else if (page == left_pg + left_cnt * PAGE_SIZE) {
     1625                        goto success;
     1626                } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
    16711627                        /*
    16721628                         * The interval can be added by simply growing the left
    16731629                         * interval.
    1674                          *
    16751630                         */
    1676                         leaf->value[leaf->keys - 1] +=  count;
    1677                         return 1;
    1678                 } else if (page + count * PAGE_SIZE == right_pg) {
     1631                        leaf->value[leaf->keys - 1] += count;
     1632                        goto success;
     1633                } else if (page + (count << PAGE_WIDTH) == right_pg) {
    16791634                        /*
    16801635                         * The interval can be addded by simply moving base of
    16811636                         * the right interval down and increasing its size
    16821637                         * accordingly.
    1683                          *
    16841638                         */
    16851639                        node->value[0] += count;
    16861640                        node->key[0] = page;
    1687                         return 1;
     1641                        goto success;
    16881642                } else {
    16891643                        /*
    16901644                         * The interval is between both neigbouring intervals,
    16911645                         * but cannot be merged with any of them.
    1692                          *
    16931646                         */
    16941647                        btree_insert(&area->used_space, page, (void *) count,
    16951648                            leaf);
    1696                         return 1;
     1649                        goto success;
    16971650                }
    16981651        } else if (page >= leaf->key[leaf->keys - 1]) {
     
    17031656                 * Investigate the border case in which the right neighbour
    17041657                 * does not exist but the interval fits from the right.
    1705                  *
    1706                  */
    1707                
    1708                 if (overlaps(page, count * PAGE_SIZE, left_pg,
    1709                     left_cnt * PAGE_SIZE)) {
     1658                 */
     1659               
     1660                if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1661                    left_cnt << PAGE_WIDTH)) {
    17101662                        /* The interval intersects with the left interval. */
    1711                         return 0;
    1712                 } else if (left_pg + left_cnt * PAGE_SIZE == page) {
     1663                        return false;
     1664                } else if (left_pg + (left_cnt << PAGE_WIDTH) == page) {
    17131665                        /*
    17141666                         * The interval can be added by growing the left
    17151667                         * interval.
    1716                          *
    17171668                         */
    17181669                        leaf->value[leaf->keys - 1] += count;
    1719                         return 1;
     1670                        goto success;
    17201671                } else {
    17211672                        /*
    17221673                         * The interval doesn't adjoin with the left interval.
    17231674                         * It must be added individually.
    1724                          *
    17251675                         */
    17261676                        btree_insert(&area->used_space, page, (void *) count,
    17271677                            leaf);
    1728                         return 1;
     1678                        goto success;
    17291679                }
    17301680        }
     
    17341684         * only between two other intervals of the leaf. The two border cases
    17351685         * were already resolved.
    1736          *
    17371686         */
    17381687        btree_key_t i;
     
    17461695                        /*
    17471696                         * The interval fits between left_pg and right_pg.
    1748                          *
    17491697                         */
    17501698                       
    1751                         if (overlaps(page, count * PAGE_SIZE, left_pg,
    1752                             left_cnt * PAGE_SIZE)) {
     1699                        if (overlaps(page, count << PAGE_WIDTH, left_pg,
     1700                            left_cnt << PAGE_WIDTH)) {
    17531701                                /*
    17541702                                 * The interval intersects with the left
    17551703                                 * interval.
    1756                                  *
    17571704                                 */
    1758                                 return 0;
    1759                         } else if (overlaps(page, count * PAGE_SIZE, right_pg,
    1760                             right_cnt * PAGE_SIZE)) {
     1705                                return false;
     1706                        } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
     1707                            right_cnt << PAGE_WIDTH)) {
    17611708                                /*
    17621709                                 * The interval intersects with the right
    17631710                                 * interval.
    1764                                  *
    17651711                                 */
    1766                                 return 0;
    1767                         } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
    1768                             (page + count * PAGE_SIZE == right_pg)) {
     1712                                return false;
     1713                        } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
     1714                            (page + (count << PAGE_WIDTH) == right_pg)) {
    17691715                                /*
    17701716                                 * The interval can be added by merging the two
    17711717                                 * already present intervals.
    1772                                  *
    17731718                                 */
    17741719                                leaf->value[i - 1] += count + right_cnt;
    17751720                                btree_remove(&area->used_space, right_pg, leaf);
    1776                                 return 1;
    1777                         } else if (page == left_pg + left_cnt * PAGE_SIZE) {
     1721                                goto success;
     1722                        } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
    17781723                                /*
    17791724                                 * The interval can be added by simply growing
    17801725                                 * the left interval.
    1781                                  *
    17821726                                 */
    17831727                                leaf->value[i - 1] += count;
    1784                                 return 1;
    1785                         } else if (page + count * PAGE_SIZE == right_pg) {
     1728                                goto success;
     1729                        } else if (page + (count << PAGE_WIDTH) == right_pg) {
    17861730                                /*
    17871731                                 * The interval can be addded by simply moving
    17881732                                 * base of the right interval down and
    17891733                                 * increasing its size accordingly.
    1790                                  *
    17911734                                 */
    17921735                                leaf->value[i] += count;
    17931736                                leaf->key[i] = page;
    1794                                 return 1;
     1737                                goto success;
    17951738                        } else {
    17961739                                /*
     
    17981741                                 * intervals, but cannot be merged with any of
    17991742                                 * them.
    1800                                  *
    18011743                                 */
    18021744                                btree_insert(&area->used_space, page,
    18031745                                    (void *) count, leaf);
    1804                                 return 1;
     1746                                goto success;
    18051747                        }
    18061748                }
     
    18091751        panic("Inconsistency detected while adding %zu pages of used "
    18101752            "space at %p.", count, (void *) page);
     1753       
     1754success:
     1755        area->resident += count;
     1756        return true;
    18111757}
    18121758
     
    18191765 * @param count Number of page to be marked.
    18201766 *
    1821  * @return Zero on failure and non-zero on success.
    1822  *
    1823  */
    1824 int used_space_remove(as_area_t *area, uintptr_t page, size_t count)
     1767 * @return False on failure or true on success.
     1768 *
     1769 */
     1770bool used_space_remove(as_area_t *area, uintptr_t page, size_t count)
    18251771{
    18261772        ASSERT(mutex_locked(&area->lock));
     
    18331779                /*
    18341780                 * We are lucky, page is the beginning of some interval.
    1835                  *
    18361781                 */
    18371782                if (count > pages) {
    1838                         return 0;
     1783                        return false;
    18391784                } else if (count == pages) {
    18401785                        btree_remove(&area->used_space, page, leaf);
    1841                         return 1;
     1786                        goto success;
    18421787                } else {
    18431788                        /*
    18441789                         * Find the respective interval.
    18451790                         * Decrease its size and relocate its start address.
    1846                          *
    18471791                         */
    18481792                        btree_key_t i;
    18491793                        for (i = 0; i < leaf->keys; i++) {
    18501794                                if (leaf->key[i] == page) {
    1851                                         leaf->key[i] += count * PAGE_SIZE;
     1795                                        leaf->key[i] += count << PAGE_WIDTH;
    18521796                                        leaf->value[i] -= count;
    1853                                         return 1;
     1797                                        goto success;
    18541798                                }
    18551799                        }
     1800                       
    18561801                        goto error;
    18571802                }
     
    18631808                size_t left_cnt = (size_t) node->value[node->keys - 1];
    18641809               
    1865                 if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
    1866                     count * PAGE_SIZE)) {
    1867                         if (page + count * PAGE_SIZE ==
    1868                             left_pg + left_cnt * PAGE_SIZE) {
     1810                if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
     1811                    count << PAGE_WIDTH)) {
     1812                        if (page + (count << PAGE_WIDTH) ==
     1813                            left_pg + (left_cnt << PAGE_WIDTH)) {
    18691814                                /*
    18701815                                 * The interval is contained in the rightmost
     
    18721817                                 * removed by updating the size of the bigger
    18731818                                 * interval.
    1874                                  *
    18751819                                 */
    18761820                                node->value[node->keys - 1] -= count;
    1877                                 return 1;
    1878                         } else if (page + count * PAGE_SIZE <
    1879                             left_pg + left_cnt*PAGE_SIZE) {
     1821                                goto success;
     1822                        } else if (page + (count << PAGE_WIDTH) <
     1823                            left_pg + (left_cnt << PAGE_WIDTH)) {
    18801824                                /*
    18811825                                 * The interval is contained in the rightmost
     
    18841828                                 * the original interval and also inserting a
    18851829                                 * new interval.
    1886                                  *
    18871830                                 */
    1888                                 size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
    1889                                     (page + count*PAGE_SIZE)) >> PAGE_WIDTH;
     1831                                size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
     1832                                    (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
    18901833                                node->value[node->keys - 1] -= count + new_cnt;
    18911834                                btree_insert(&area->used_space, page +
    1892                                     count * PAGE_SIZE, (void *) new_cnt, leaf);
    1893                                 return 1;
     1835                                    (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1836                                goto success;
    18941837                        }
    18951838                }
    1896                 return 0;
     1839               
     1840                return false;
    18971841        } else if (page < leaf->key[0])
    1898                 return 0;
     1842                return false;
    18991843       
    19001844        if (page > leaf->key[leaf->keys - 1]) {
     
    19021846                size_t left_cnt = (size_t) leaf->value[leaf->keys - 1];
    19031847               
    1904                 if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
    1905                     count * PAGE_SIZE)) {
    1906                         if (page + count * PAGE_SIZE ==
    1907                             left_pg + left_cnt * PAGE_SIZE) {
     1848                if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
     1849                    count << PAGE_WIDTH)) {
     1850                        if (page + (count << PAGE_WIDTH) ==
     1851                            left_pg + (left_cnt << PAGE_WIDTH)) {
    19081852                                /*
    19091853                                 * The interval is contained in the rightmost
    19101854                                 * interval of the leaf and can be removed by
    19111855                                 * updating the size of the bigger interval.
    1912                                  *
    19131856                                 */
    19141857                                leaf->value[leaf->keys - 1] -= count;
    1915                                 return 1;
    1916                         } else if (page + count * PAGE_SIZE < left_pg +
    1917                             left_cnt * PAGE_SIZE) {
     1858                                goto success;
     1859                        } else if (page + (count << PAGE_WIDTH) < left_pg +
     1860                            (left_cnt << PAGE_WIDTH)) {
    19181861                                /*
    19191862                                 * The interval is contained in the rightmost
     
    19221865                                 * original interval and also inserting a new
    19231866                                 * interval.
    1924                                  *
    19251867                                 */
    1926                                 size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
    1927                                     (page + count * PAGE_SIZE)) >> PAGE_WIDTH;
     1868                                size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
     1869                                    (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
    19281870                                leaf->value[leaf->keys - 1] -= count + new_cnt;
    19291871                                btree_insert(&area->used_space, page +
    1930                                     count * PAGE_SIZE, (void *) new_cnt, leaf);
    1931                                 return 1;
     1872                                    (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1873                                goto success;
    19321874                        }
    19331875                }
    1934                 return 0;
     1876               
     1877                return false;
    19351878        }
    19361879       
    19371880        /*
    19381881         * The border cases have been already resolved.
    1939          * Now the interval can be only between intervals of the leaf. 
     1882         * Now the interval can be only between intervals of the leaf.
    19401883         */
    19411884        btree_key_t i;
     
    19491892                         * to (i - 1) and i.
    19501893                         */
    1951                         if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
    1952                             count * PAGE_SIZE)) {
    1953                                 if (page + count * PAGE_SIZE ==
    1954                                     left_pg + left_cnt*PAGE_SIZE) {
     1894                        if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
     1895                            count << PAGE_WIDTH)) {
     1896                                if (page + (count << PAGE_WIDTH) ==
     1897                                    left_pg + (left_cnt << PAGE_WIDTH)) {
    19551898                                        /*
    19561899                                         * The interval is contained in the
     
    19581901                                         * be removed by updating the size of
    19591902                                         * the bigger interval.
    1960                                          *
    19611903                                         */
    19621904                                        leaf->value[i - 1] -= count;
    1963                                         return 1;
    1964                                 } else if (page + count * PAGE_SIZE <
    1965                                     left_pg + left_cnt * PAGE_SIZE) {
     1905                                        goto success;
     1906                                } else if (page + (count << PAGE_WIDTH) <
     1907                                    left_pg + (left_cnt << PAGE_WIDTH)) {
    19661908                                        /*
    19671909                                         * The interval is contained in the
     
    19721914                                         */
    19731915                                        size_t new_cnt = ((left_pg +
    1974                                             left_cnt * PAGE_SIZE) -
    1975                                             (page + count * PAGE_SIZE)) >>
     1916                                            (left_cnt << PAGE_WIDTH)) -
     1917                                            (page + (count << PAGE_WIDTH))) >>
    19761918                                            PAGE_WIDTH;
    19771919                                        leaf->value[i - 1] -= count + new_cnt;
    19781920                                        btree_insert(&area->used_space, page +
    1979                                             count * PAGE_SIZE, (void *) new_cnt,
     1921                                            (count << PAGE_WIDTH), (void *) new_cnt,
    19801922                                            leaf);
    1981                                         return 1;
     1923                                        goto success;
    19821924                                }
    19831925                        }
    1984                         return 0;
     1926                       
     1927                        return false;
    19851928                }
    19861929        }
     
    19891932        panic("Inconsistency detected while removing %zu pages of used "
    19901933            "space from %p.", count, (void *) page);
     1934       
     1935success:
     1936        area->resident -= count;
     1937        return true;
    19911938}
    19921939
     
    20231970}
    20241971
     1972/** Return pointer to unmapped address space area
     1973 *
     1974 * @param base Lowest address bound.
     1975 * @param size Requested size of the allocation.
     1976 *
     1977 * @return Pointer to the beginning of unmapped address space area.
     1978 *
     1979 */
     1980sysarg_t sys_as_get_unmapped_area(uintptr_t base, size_t size)
     1981{
     1982        if (size == 0)
     1983                return 0;
     1984       
     1985        /*
     1986         * Make sure we allocate from page-aligned
     1987         * address. Check for possible overflow in
     1988         * each step.
     1989         */
     1990       
     1991        size_t pages = SIZE2FRAMES(size);
     1992        uintptr_t ret = 0;
     1993       
     1994        /*
     1995         * Find the lowest unmapped address aligned on the sz
     1996         * boundary, not smaller than base and of the required size.
     1997         */
     1998       
     1999        mutex_lock(&AS->lock);
     2000       
     2001        /* First check the base address itself */
     2002        uintptr_t addr = ALIGN_UP(base, PAGE_SIZE);
     2003        if ((addr >= base) &&
     2004            (check_area_conflicts(AS, addr, pages, NULL)))
     2005                ret = addr;
     2006       
     2007        /* Eventually check the addresses behind each area */
     2008        link_t *cur;
     2009        for (cur = AS->as_area_btree.leaf_head.next;
     2010            (ret == 0) && (cur != &AS->as_area_btree.leaf_head);
     2011            cur = cur->next) {
     2012                btree_node_t *node =
     2013                    list_get_instance(cur, btree_node_t, leaf_link);
     2014               
     2015                btree_key_t i;
     2016                for (i = 0; (ret == 0) && (i < node->keys); i++) {
     2017                        as_area_t *area = (as_area_t *) node->value[i];
     2018                       
     2019                        mutex_lock(&area->lock);
     2020                       
     2021                        uintptr_t addr =
     2022                            ALIGN_UP(area->base + (area->pages << PAGE_WIDTH),
     2023                            PAGE_SIZE);
     2024                       
     2025                        if ((addr >= base) && (addr >= area->base) &&
     2026                            (check_area_conflicts(AS, addr, pages, area)))
     2027                                ret = addr;
     2028                       
     2029                        mutex_unlock(&area->lock);
     2030                }
     2031        }
     2032       
     2033        mutex_unlock(&AS->lock);
     2034       
     2035        return (sysarg_t) ret;
     2036}
     2037
    20252038/** Get list of adress space areas.
    20262039 *
     
    20892102        mutex_lock(&as->lock);
    20902103       
    2091         /* print out info about address space areas */
     2104        /* Print out info about address space areas */
    20922105        link_t *cur;
    20932106        for (cur = as->as_area_btree.leaf_head.next;
  • kernel/generic/src/mm/backend_elf.c

    r6b9e85b r8b655705  
    213213        if (!as_area_check_access(area, access))
    214214                return AS_PF_FAULT;
    215 
    216         ASSERT((addr >= ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) &&
    217             (addr < entry->p_vaddr + entry->p_memsz));
     215       
     216        if (addr < ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE))
     217                return AS_PF_FAULT;
     218       
     219        if (addr >= entry->p_vaddr + entry->p_memsz)
     220                return AS_PF_FAULT;
     221       
    218222        i = (addr - ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) >> PAGE_WIDTH;
    219223        base = (uintptr_t)
  • kernel/generic/src/mm/backend_phys.c

    r6b9e85b r8b655705  
    112112        page_mapping_insert(AS, addr, base + (addr - area->base),
    113113            as_area_get_flags(area));
    114         if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
    115                 panic("Cannot insert used space.");
     114       
     115        if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))
     116                panic("Cannot insert used space.");
    116117
    117118        return AS_PF_OK;
  • kernel/generic/src/proc/program.c

    r6b9e85b r8b655705  
    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/scheduler.c

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

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

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

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

    r6b9e85b r8b655705  
    8686        } else {
    8787                printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id);
    88                 task_kill(TASK->taskid);
    89                 thread_exit();
     88                task_kill_self(true);
    9089        }
    9190       
     
    131130        (syshandler_t) sys_task_set_name,
    132131        (syshandler_t) sys_task_kill,
     132        (syshandler_t) sys_task_exit,
    133133        (syshandler_t) sys_program_spawn_loader,
    134134       
     
    143143        (syshandler_t) sys_as_area_change_flags,
    144144        (syshandler_t) sys_as_area_destroy,
     145        (syshandler_t) sys_as_get_unmapped_area,
    145146       
    146147        /* IPC related syscalls. */
     
    156157        (syshandler_t) sys_ipc_poke,
    157158        (syshandler_t) sys_ipc_hangup,
    158         (syshandler_t) sys_ipc_register_irq,
    159         (syshandler_t) sys_ipc_unregister_irq,
    160159        (syshandler_t) sys_ipc_connect_kbox,
    161160       
     
    171170        (syshandler_t) sys_physmem_map,
    172171        (syshandler_t) sys_iospace_enable,
     172        (syshandler_t) sys_register_irq,
     173        (syshandler_t) sys_unregister_irq,
    173174       
    174175        /* Sysinfo syscalls */
  • kernel/generic/src/sysinfo/stats.c

    r6b9e85b r8b655705  
    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 here 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 */
     
    189185                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
    190186                                continue;
    191                         result += area->pages;
     187                       
     188                        pages += area->pages;
    192189                        mutex_unlock(&area->lock);
    193190                }
     
    196193        mutex_unlock(&as->lock);
    197194       
    198         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);
    199241}
    200242
     
    215257        str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name);
    216258        stats_task->virtmem = get_task_virtmem(task->as);
     259        stats_task->resmem = get_task_resmem(task->as);
    217260        stats_task->threads = atomic_get(&task->refcount);
    218261        task_get_accounting(task, &(stats_task->ucycles),
  • kernel/generic/src/sysinfo/sysinfo.c

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

    r6b9e85b r8b655705  
    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.