source: mainline/kernel/generic/include/proc/task.h

Last change on this file was f35749e, checked in by Jiri Svoboda <jiri@…>, 4 months ago

System restart via shutdown -r

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