[8e8c1a5] | 1 | /*
|
---|
[0c42638] | 2 | * Copyright (c) 2010 Jakub Jermar
|
---|
[f761f1eb] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[174156fd] | 29 | /** @addtogroup kernel_generic_proc
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[06e1e95] | 35 | #ifndef KERN_TASK_H_
|
---|
| 36 | #define KERN_TASK_H_
|
---|
[f761f1eb] | 37 |
|
---|
[40eab9f] | 38 | #include <abi/proc/task.h>
|
---|
| 39 | #include <abi/sysinfo.h>
|
---|
[5c9a08b] | 40 | #include <adt/list.h>
|
---|
[ef1eab7] | 41 | #include <adt/odict.h>
|
---|
[b3f8fb7] | 42 | #include <arch/context.h>
|
---|
| 43 | #include <arch/cpu.h>
|
---|
[40eab9f] | 44 | #include <arch/fpu_context.h>
|
---|
| 45 | #include <arch/proc/task.h>
|
---|
| 46 | #include <arch/proc/thread.h>
|
---|
| 47 | #include <arch.h>
|
---|
| 48 | #include <cap/cap.h>
|
---|
| 49 | #include <cpu.h>
|
---|
| 50 | #include <debug/sections.h>
|
---|
| 51 | #include <ipc/event.h>
|
---|
| 52 | #include <ipc/ipc.h>
|
---|
| 53 | #include <ipc/kbox.h>
|
---|
| 54 | #include <mm/as.h>
|
---|
[b3f8fb7] | 55 | #include <mm/tlb.h>
|
---|
| 56 | #include <proc/scheduler.h>
|
---|
[40eab9f] | 57 | #include <security/perm.h>
|
---|
| 58 | #include <synch/mutex.h>
|
---|
| 59 | #include <synch/spinlock.h>
|
---|
[9a1b20c] | 60 | #include <udebug/udebug.h>
|
---|
[1066041] | 61 |
|
---|
[a6e55886] | 62 | #define TASK CURRENT->task
|
---|
[1066041] | 63 |
|
---|
[b3f8fb7] | 64 | struct thread;
|
---|
[3f74275] | 65 | struct cap;
|
---|
[b3f8fb7] | 66 |
|
---|
[20d50a1] | 67 | /** Task structure. */
|
---|
[b3f8fb7] | 68 | typedef struct task {
|
---|
[ef1eab7] | 69 | /** Link to @c tasks ordered dictionary */
|
---|
| 70 | odlink_t ltasks;
|
---|
[a35b458] | 71 |
|
---|
[7509ddc] | 72 | /** Task lock.
|
---|
| 73 | *
|
---|
[80bcaed] | 74 | * Must be acquired before threads_lock and thread lock of any of its
|
---|
| 75 | * threads.
|
---|
[7509ddc] | 76 | */
|
---|
[da1bafb] | 77 | IRQ_SPINLOCK_DECLARE(lock);
|
---|
[a35b458] | 78 |
|
---|
[24345a5] | 79 | char name[TASK_NAME_BUFLEN];
|
---|
[80bcaed] | 80 | /** List of threads contained in this task. */
|
---|
[55b77d9] | 81 | list_t threads;
|
---|
[80bcaed] | 82 | /** Address space. */
|
---|
| 83 | as_t *as;
|
---|
| 84 | /** Unique identity of task. */
|
---|
| 85 | task_id_t taskid;
|
---|
[26aafe8] | 86 | /** Task security container. */
|
---|
| 87 | container_id_t container;
|
---|
[a35b458] | 88 |
|
---|
[80bcaed] | 89 | /** Number of references (i.e. threads). */
|
---|
[07d4271] | 90 | atomic_refcount_t refcount;
|
---|
[ea7890e7] | 91 | /** Number of threads that haven't exited yet. */
|
---|
[11d2c983] | 92 | // TODO: remove
|
---|
[31e15be] | 93 | atomic_size_t lifecount;
|
---|
[a35b458] | 94 |
|
---|
[719a208] | 95 | /** Task permissions. */
|
---|
| 96 | perm_t perms;
|
---|
[c8cec85] | 97 |
|
---|
[3f74275] | 98 | /** Capabilities */
|
---|
[9e87562] | 99 | cap_info_t *cap_info;
|
---|
[a35b458] | 100 |
|
---|
[5f62ef9] | 101 | /* IPC stuff */
|
---|
[86939b1] | 102 |
|
---|
| 103 | /** Receiving communication endpoint */
|
---|
| 104 | answerbox_t answerbox;
|
---|
| 105 |
|
---|
| 106 | /** Spinlock protecting the active_calls list. */
|
---|
| 107 | SPINLOCK_DECLARE(active_calls_lock);
|
---|
| 108 |
|
---|
| 109 | /**
|
---|
| 110 | * List of all calls sent by this task that have not yet been
|
---|
| 111 | * answered.
|
---|
| 112 | */
|
---|
| 113 | list_t active_calls;
|
---|
| 114 |
|
---|
[5d0500c] | 115 | event_t events[EVENT_TASK_END - EVENT_END];
|
---|
[86939b1] | 116 |
|
---|
| 117 | /** IPC statistics */
|
---|
| 118 | stats_ipc_t ipc_info;
|
---|
[a35b458] | 119 |
|
---|
[9a1b20c] | 120 | #ifdef CONFIG_UDEBUG
|
---|
[31696b4f] | 121 | /** Debugging stuff. */
|
---|
[9a1b20c] | 122 | udebug_task_t udebug;
|
---|
[a35b458] | 123 |
|
---|
[31696b4f] | 124 | /** Kernel answerbox. */
|
---|
| 125 | kbox_t kb;
|
---|
[da1bafb] | 126 | #endif /* CONFIG_UDEBUG */
|
---|
[a35b458] | 127 |
|
---|
[80bcaed] | 128 | /** Architecture specific task data. */
|
---|
[201abde] | 129 | task_arch_t arch;
|
---|
[a35b458] | 130 |
|
---|
[80bcaed] | 131 | /** Accumulated accounting. */
|
---|
[a2a00e8] | 132 | uint64_t ucycles;
|
---|
| 133 | uint64_t kcycles;
|
---|
[40eab9f] | 134 |
|
---|
| 135 | debug_sections_t *debug_sections;
|
---|
[b3f8fb7] | 136 | } task_t;
|
---|
| 137 |
|
---|
[ef1eab7] | 138 | /** Synchronize access to @c tasks */
|
---|
[da1bafb] | 139 | IRQ_SPINLOCK_EXTERN(tasks_lock);
|
---|
[ef1eab7] | 140 | /** Ordered dictionary of all tasks by ID (of task_t structures) */
|
---|
| 141 | extern odict_t tasks;
|
---|
[f761f1eb] | 142 |
|
---|
| 143 | extern void task_init(void);
|
---|
[f74bbaf] | 144 | extern void task_done(void);
|
---|
[0c42638] | 145 | extern task_t *task_create(as_t *, const char *);
|
---|
[278b4a30] | 146 | extern void task_hold(task_t *);
|
---|
| 147 | extern void task_release(task_t *);
|
---|
[0c42638] | 148 | extern task_t *task_find_by_id(task_id_t);
|
---|
[aab5e46] | 149 | extern size_t task_count(void);
|
---|
| 150 | extern task_t *task_first(void);
|
---|
| 151 | extern task_t *task_next(task_t *);
|
---|
[b7fd2a0] | 152 | extern errno_t task_kill(task_id_t);
|
---|
[5bcf1f9] | 153 | extern void task_kill_self(bool) __attribute__((noreturn));
|
---|
[0c42638] | 154 | extern void task_get_accounting(task_t *, uint64_t *, uint64_t *);
|
---|
[c0f13d2] | 155 | extern void task_print_list(bool);
|
---|
[7509ddc] | 156 |
|
---|
[719a208] | 157 | extern void perm_set(task_t *, perm_t);
|
---|
| 158 | extern perm_t perm_get(task_t *);
|
---|
[b3f8fb7] | 159 |
|
---|
[963074b3] | 160 | #ifndef task_create_arch
|
---|
[0c42638] | 161 | extern void task_create_arch(task_t *);
|
---|
[963074b3] | 162 | #endif
|
---|
| 163 |
|
---|
[31e8ddd] | 164 | #ifndef task_destroy_arch
|
---|
[0c42638] | 165 | extern void task_destroy_arch(task_t *);
|
---|
[31e8ddd] | 166 | #endif
|
---|
| 167 |
|
---|
[dd8d5a7] | 168 | #ifdef __32_BITS__
|
---|
[5a5269d] | 169 | extern sys_errno_t sys_task_get_id(uspace_ptr_sysarg64_t);
|
---|
[dd8d5a7] | 170 | #endif
|
---|
| 171 |
|
---|
| 172 | #ifdef __64_BITS__
|
---|
| 173 | extern sysarg_t sys_task_get_id(void);
|
---|
| 174 | #endif
|
---|
| 175 |
|
---|
[5a5269d] | 176 | extern sys_errno_t sys_task_set_name(uspace_ptr_const_char, size_t);
|
---|
| 177 | extern sys_errno_t sys_task_kill(uspace_ptr_task_id_t);
|
---|
[b7fd2a0] | 178 | extern sys_errno_t sys_task_exit(sysarg_t);
|
---|
[ec55358] | 179 |
|
---|
[f761f1eb] | 180 | #endif
|
---|
[b45c443] | 181 |
|
---|
[06e1e95] | 182 | /** @}
|
---|
[b45c443] | 183 | */
|
---|