Changeset 5bcf1f9 in mainline


Ignore:
Timestamp:
2011-01-29T22:52:25Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fd483ce
Parents:
fc5f7a8
Message:

add syscall for properly terminating the currently running task (including abort() functionality)

Location:
kernel/generic
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/ipc/event_types.h

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

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

    rfc5f7a8 r5bcf1f9  
    4848        SYS_TASK_SET_NAME,
    4949        SYS_TASK_KILL,
     50        SYS_TASK_EXIT,
    5051        SYS_PROGRAM_SPAWN_LOADER,
    5152       
  • kernel/generic/src/interrupt/interrupt.c

    rfc5f7a8 r5bcf1f9  
    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/proc/task.c

    rfc5f7a8 r5bcf1f9  
    384384{
    385385        task_id_t taskid;
    386         int rc;
    387 
    388         rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
     386        int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(taskid));
    389387        if (rc != 0)
    390388                return (sysarg_t) rc;
    391 
     389       
    392390        return (sysarg_t) task_kill(taskid);
    393391}
     
    520518}
    521519
     520/** Kill the currently running task.
     521 *
     522 * @param notify Send out fault notifications.
     523 *
     524 * @return Zero on success or an error code from errno.h.
     525 *
     526 */
     527void task_kill_self(bool notify)
     528{
     529        /*
     530         * User space can subscribe for FAULT events to take action
     531         * whenever a task faults (to take a dump, run a debugger, etc.).
     532         * The notification is always available, but unless udebug is enabled,
     533         * that's all you get.
     534        */
     535        if (notify) {
     536                if (event_is_subscribed(EVENT_FAULT)) {
     537                        /* Notify the subscriber that a fault occurred. */
     538                        event_notify_3(EVENT_FAULT, LOWER32(TASK->taskid),
     539                            UPPER32(TASK->taskid), (sysarg_t) THREAD);
     540               
     541#ifdef CONFIG_UDEBUG
     542                        /* Wait for a debugging session. */
     543                        udebug_thread_fault();
     544#endif
     545                }
     546        }
     547       
     548        irq_spinlock_lock(&tasks_lock, true);
     549        task_kill_internal(TASK);
     550        irq_spinlock_unlock(&tasks_lock, true);
     551       
     552        thread_exit();
     553}
     554
     555/** Process syscall to terminate the current task.
     556 *
     557 * @param notify Send out fault notifications.
     558 *
     559 */
     560sysarg_t sys_task_exit(sysarg_t notify)
     561{
     562        task_kill_self(notify);
     563       
     564        /* Unreachable */
     565        return EOK;
     566}
     567
    522568static bool task_print_walker(avltree_node_t *node, void *arg)
    523569{
  • kernel/generic/src/syscall/syscall.c

    rfc5f7a8 r5bcf1f9  
    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       
Note: See TracChangeset for help on using the changeset viewer.