1 | /*
|
---|
2 | * Copyright (c) 2010 Jakub Jermar
|
---|
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 |
|
---|
29 | /** @addtogroup kernel_generic_proc
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | */
|
---|
34 |
|
---|
35 | #ifndef KERN_TASK_H_
|
---|
36 | #define KERN_TASK_H_
|
---|
37 |
|
---|
38 | #include <abi/proc/task.h>
|
---|
39 | #include <abi/sysinfo.h>
|
---|
40 | #include <adt/list.h>
|
---|
41 | #include <adt/odict.h>
|
---|
42 | #include <arch/context.h>
|
---|
43 | #include <arch/cpu.h>
|
---|
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>
|
---|
55 | #include <mm/tlb.h>
|
---|
56 | #include <proc/scheduler.h>
|
---|
57 | #include <security/perm.h>
|
---|
58 | #include <synch/mutex.h>
|
---|
59 | #include <synch/spinlock.h>
|
---|
60 | #include <udebug/udebug.h>
|
---|
61 |
|
---|
62 | #define TASK CURRENT->task
|
---|
63 |
|
---|
64 | struct thread;
|
---|
65 | struct cap;
|
---|
66 |
|
---|
67 | /** Task structure. */
|
---|
68 | typedef struct task {
|
---|
69 | /** Link to @c tasks ordered dictionary */
|
---|
70 | odlink_t ltasks;
|
---|
71 |
|
---|
72 | /** Task lock.
|
---|
73 | *
|
---|
74 | * Must be acquired before threads_lock and thread lock of any of its
|
---|
75 | * threads.
|
---|
76 | */
|
---|
77 | IRQ_SPINLOCK_DECLARE(lock);
|
---|
78 |
|
---|
79 | char name[TASK_NAME_BUFLEN];
|
---|
80 | /** List of threads contained in this task. */
|
---|
81 | list_t threads;
|
---|
82 | /** Address space. */
|
---|
83 | as_t *as;
|
---|
84 | /** Unique identity of task. */
|
---|
85 | task_id_t taskid;
|
---|
86 | /** Task security container. */
|
---|
87 | container_id_t container;
|
---|
88 |
|
---|
89 | /** Number of references (i.e. threads). */
|
---|
90 | atomic_size_t refcount;
|
---|
91 | /** Number of threads that haven't exited yet. */
|
---|
92 | // TODO: remove
|
---|
93 | atomic_size_t lifecount;
|
---|
94 |
|
---|
95 | /** Task permissions. */
|
---|
96 | perm_t perms;
|
---|
97 |
|
---|
98 | /** Capabilities */
|
---|
99 | cap_info_t *cap_info;
|
---|
100 |
|
---|
101 | /* IPC stuff */
|
---|
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 |
|
---|
115 | event_t events[EVENT_TASK_END - EVENT_END];
|
---|
116 |
|
---|
117 | /** IPC statistics */
|
---|
118 | stats_ipc_t ipc_info;
|
---|
119 |
|
---|
120 | #ifdef CONFIG_UDEBUG
|
---|
121 | /** Debugging stuff. */
|
---|
122 | udebug_task_t udebug;
|
---|
123 |
|
---|
124 | /** Kernel answerbox. */
|
---|
125 | kbox_t kb;
|
---|
126 | #endif /* CONFIG_UDEBUG */
|
---|
127 |
|
---|
128 | /** Architecture specific task data. */
|
---|
129 | task_arch_t arch;
|
---|
130 |
|
---|
131 | /** Accumulated accounting. */
|
---|
132 | uint64_t ucycles;
|
---|
133 | uint64_t kcycles;
|
---|
134 |
|
---|
135 | debug_sections_t *debug_sections;
|
---|
136 | } task_t;
|
---|
137 |
|
---|
138 | /** Synchronize access to @c tasks */
|
---|
139 | IRQ_SPINLOCK_EXTERN(tasks_lock);
|
---|
140 | /** Ordered dictionary of all tasks by ID (of task_t structures) */
|
---|
141 | extern odict_t tasks;
|
---|
142 |
|
---|
143 | extern void task_init(void);
|
---|
144 | extern void task_done(void);
|
---|
145 | extern task_t *task_create(as_t *, const char *);
|
---|
146 | extern void task_destroy(task_t *);
|
---|
147 | extern void task_hold(task_t *);
|
---|
148 | extern void task_release(task_t *);
|
---|
149 | extern task_t *task_find_by_id(task_id_t);
|
---|
150 | extern size_t task_count(void);
|
---|
151 | extern task_t *task_first(void);
|
---|
152 | extern task_t *task_next(task_t *);
|
---|
153 | extern errno_t task_kill(task_id_t);
|
---|
154 | extern void task_kill_self(bool) __attribute__((noreturn));
|
---|
155 | extern void task_get_accounting(task_t *, uint64_t *, uint64_t *);
|
---|
156 | extern void task_print_list(bool);
|
---|
157 |
|
---|
158 | extern void perm_set(task_t *, perm_t);
|
---|
159 | extern perm_t perm_get(task_t *);
|
---|
160 |
|
---|
161 | #ifndef task_create_arch
|
---|
162 | extern void task_create_arch(task_t *);
|
---|
163 | #endif
|
---|
164 |
|
---|
165 | #ifndef task_destroy_arch
|
---|
166 | extern void task_destroy_arch(task_t *);
|
---|
167 | #endif
|
---|
168 |
|
---|
169 | #ifdef __32_BITS__
|
---|
170 | extern sys_errno_t sys_task_get_id(uspace_ptr_sysarg64_t);
|
---|
171 | #endif
|
---|
172 |
|
---|
173 | #ifdef __64_BITS__
|
---|
174 | extern sysarg_t sys_task_get_id(void);
|
---|
175 | #endif
|
---|
176 |
|
---|
177 | extern sys_errno_t sys_task_set_name(uspace_ptr_const_char, size_t);
|
---|
178 | extern sys_errno_t sys_task_kill(uspace_ptr_task_id_t);
|
---|
179 | extern sys_errno_t sys_task_exit(sysarg_t);
|
---|
180 |
|
---|
181 | #endif
|
---|
182 |
|
---|
183 | /** @}
|
---|
184 | */
|
---|