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
RevLine 
[8e8c1a5]1/*
[f35749e]2 * Copyright (c) 2025 Jiri Svoboda
[0c42638]3 * Copyright (c) 2010 Jakub Jermar
[f761f1eb]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
[174156fd]30/** @addtogroup kernel_generic_proc
[b45c443]31 * @{
32 */
33/** @file
34 */
35
[06e1e95]36#ifndef KERN_TASK_H_
37#define KERN_TASK_H_
[f761f1eb]38
[40eab9f]39#include <abi/proc/task.h>
40#include <abi/sysinfo.h>
[5c9a08b]41#include <adt/list.h>
[ef1eab7]42#include <adt/odict.h>
[b3f8fb7]43#include <arch/context.h>
44#include <arch/cpu.h>
[40eab9f]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>
[b3f8fb7]56#include <mm/tlb.h>
57#include <proc/scheduler.h>
[40eab9f]58#include <security/perm.h>
59#include <synch/mutex.h>
60#include <synch/spinlock.h>
[9a1b20c]61#include <udebug/udebug.h>
[1066041]62
[a6e55886]63#define TASK CURRENT->task
[1066041]64
[b3f8fb7]65struct thread;
[3f74275]66struct cap;
[b3f8fb7]67
[20d50a1]68/** Task structure. */
[b3f8fb7]69typedef struct task {
[ef1eab7]70 /** Link to @c tasks ordered dictionary */
71 odlink_t ltasks;
[a35b458]72
[7509ddc]73 /** Task lock.
74 *
[80bcaed]75 * Must be acquired before threads_lock and thread lock of any of its
76 * threads.
[7509ddc]77 */
[da1bafb]78 IRQ_SPINLOCK_DECLARE(lock);
[a35b458]79
[24345a5]80 char name[TASK_NAME_BUFLEN];
[80bcaed]81 /** List of threads contained in this task. */
[55b77d9]82 list_t threads;
[80bcaed]83 /** Address space. */
84 as_t *as;
85 /** Unique identity of task. */
86 task_id_t taskid;
[26aafe8]87 /** Task security container. */
88 container_id_t container;
[a35b458]89
[80bcaed]90 /** Number of references (i.e. threads). */
[07d4271]91 atomic_refcount_t refcount;
[ea7890e7]92 /** Number of threads that haven't exited yet. */
[11d2c983]93 // TODO: remove
[31e15be]94 atomic_size_t lifecount;
[a35b458]95
[719a208]96 /** Task permissions. */
97 perm_t perms;
[c8cec85]98
[3f74275]99 /** Capabilities */
[9e87562]100 cap_info_t *cap_info;
[a35b458]101
[5f62ef9]102 /* IPC stuff */
[86939b1]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
[5d0500c]116 event_t events[EVENT_TASK_END - EVENT_END];
[86939b1]117
118 /** IPC statistics */
119 stats_ipc_t ipc_info;
[a35b458]120
[9a1b20c]121#ifdef CONFIG_UDEBUG
[31696b4f]122 /** Debugging stuff. */
[9a1b20c]123 udebug_task_t udebug;
[a35b458]124
[31696b4f]125 /** Kernel answerbox. */
126 kbox_t kb;
[da1bafb]127#endif /* CONFIG_UDEBUG */
[a35b458]128
[80bcaed]129 /** Architecture specific task data. */
[201abde]130 task_arch_t arch;
[a35b458]131
[80bcaed]132 /** Accumulated accounting. */
[a2a00e8]133 uint64_t ucycles;
134 uint64_t kcycles;
[40eab9f]135
136 debug_sections_t *debug_sections;
[b3f8fb7]137} task_t;
138
[ef1eab7]139/** Synchronize access to @c tasks */
[da1bafb]140IRQ_SPINLOCK_EXTERN(tasks_lock);
[ef1eab7]141/** Ordered dictionary of all tasks by ID (of task_t structures) */
142extern odict_t tasks;
[f761f1eb]143
144extern void task_init(void);
[f35749e]145extern void task_done(task_t *);
[0c42638]146extern task_t *task_create(as_t *, const char *);
[278b4a30]147extern void task_hold(task_t *);
148extern void task_release(task_t *);
[0c42638]149extern task_t *task_find_by_id(task_id_t);
[aab5e46]150extern size_t task_count(void);
151extern task_t *task_first(void);
152extern task_t *task_next(task_t *);
[b7fd2a0]153extern errno_t task_kill(task_id_t);
[5bcf1f9]154extern void task_kill_self(bool) __attribute__((noreturn));
[0c42638]155extern void task_get_accounting(task_t *, uint64_t *, uint64_t *);
[c0f13d2]156extern void task_print_list(bool);
[7509ddc]157
[719a208]158extern void perm_set(task_t *, perm_t);
159extern perm_t perm_get(task_t *);
[b3f8fb7]160
[963074b3]161#ifndef task_create_arch
[0c42638]162extern void task_create_arch(task_t *);
[963074b3]163#endif
164
[31e8ddd]165#ifndef task_destroy_arch
[0c42638]166extern void task_destroy_arch(task_t *);
[31e8ddd]167#endif
168
[dd8d5a7]169#ifdef __32_BITS__
[5a5269d]170extern sys_errno_t sys_task_get_id(uspace_ptr_sysarg64_t);
[dd8d5a7]171#endif
172
173#ifdef __64_BITS__
174extern sysarg_t sys_task_get_id(void);
175#endif
176
[5a5269d]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);
[b7fd2a0]179extern sys_errno_t sys_task_exit(sysarg_t);
[ec55358]180
[f761f1eb]181#endif
[b45c443]182
[06e1e95]183/** @}
[b45c443]184 */
Note: See TracBrowser for help on using the repository browser.