5 #include <lwk/idspace.h>
6 #include <lwk/cpumask.h>
9 * Valid user-space created task IDs are in interval
10 * [TASK_MIN_ID, TASK_MAX_ID].
13 #define TASK_MAX_ID 4094
16 * The task ID to use for the init_task.
17 * Put it at the top of the space to keep it out of the way.
19 #define INIT_TASK_ID TASK_MAX_ID
24 #define TASKSTATE_READY (1 << 0)
25 #define TASKSTATE_UNINTERRUPTIBLE (1 << 1)
26 #define TASKSTATE_INTERRUPTIBLE (1 << 2)
27 #define TASKSTATE_EXIT_ZOMBIE (1 << 3)
28 typedef unsigned int taskstate_t;
31 * Events that tasks may wait for and be sent.
33 #define LWKEVENT_CHILD_TASK_EXITED (1 << 0)
34 #define LWKEVENT_PORTALS_EVENT_POSTED (1 << 1)
35 typedef unsigned long event_t;
38 * Initial conditions to use for new task.
47 const user_cpumask_t * cpumask;
51 * Core task management API.
52 * These are accessible from both kernel-space and user-space (via syscalls).
54 extern int task_get_myid(id_t *id);
55 extern int task_create(id_t id_request, const char *name,
56 const start_state_t *start_state, id_t *id);
57 extern int task_exit(int status);
58 extern int task_yield(void);
62 #include <lwk/types.h>
64 #include <lwk/spinlock.h>
66 #include <lwk/seqlock.h>
67 #include <lwk/signal.h>
68 #include <lwk/idspace.h>
69 #include <arch/atomic.h>
70 #include <arch/page.h>
71 #include <arch/processor.h>
72 #include <arch/task.h>
73 #include <arch/current.h>
77 * Flags for task_struct.flags field.
79 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
82 * Signal handler structure.
84 struct sighand_struct {
86 struct k_sigaction action[_NSIG];
88 struct list_head signalfd_list;
92 * Task structure (aka Process Control Block).
93 * There is one of these for each OS-managed thread of execution in the
94 * system. A task is a generic "context of execution"... it either
95 * represents a user-level process, user-level thread, or kernel thread.
98 id_t id; /* The task's ID */
99 char name[16]; /* The task's name */
100 struct hlist_node ht_link; /* Task hash table linkage */
102 taskstate_t state; /* The task's current state */
104 uid_t uid; /* user ID */
105 gid_t gid; /* group ID */
107 struct aspace * aspace; /* Address space task is in */
108 struct sighand_struct * sighand; /* signal handler info */
110 cpumask_t cpumask; /* CPUs this task may migrate
111 to and create tasks on */
112 id_t cpu_id; /* CPU this task is bound to */
114 struct list_head sched_link; /* For per-CPU scheduling lists */
116 unsigned long ptrace;
119 int exit_status; /* Reason the task exited */
121 struct arch_task arch; /* arch specific task info */
125 struct task_struct task_info;
126 unsigned long stack[TASK_SIZE/sizeof(long)];
129 extern union task_union bootstrap_task_union;
130 extern struct aspace bootstrap_aspace;
133 * Valid task IDs are in interval [__TASK_MIN_ID, __TASK_MAX_ID].
135 #define __TASK_MIN_ID TASK_MIN_ID
136 #define __TASK_MAX_ID TASK_MAX_ID+1 /* +1 for IDLE_TASK_ID */
139 * ID of the idle task.
141 #define IDLE_TASK_ID TASK_MAX_ID+1
144 * Checks to see if a task structure is the init task.
145 * The init task is the first user-space task created by the kernel.
148 is_init(struct task_struct *tsk)
150 return (tsk->id == 1);
153 #define clear_stopped_child_used_math(child) do { (child)->flags &= ~PF_USED_MATH; } while (0)
154 #define set_stopped_child_used_math(child) do { (child)->flags |= PF_USED_MATH; } while (0)
155 #define clear_used_math() clear_stopped_child_used_math(current)
156 #define set_used_math() set_stopped_child_used_math(current)
157 #define conditional_stopped_child_used_math(condition, child) \
158 do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= (condition) ? PF_USED_MATH : 0; } while (0)
159 #define conditional_used_math(condition) \
160 conditional_stopped_child_used_math(condition, current)
161 #define copy_to_stopped_child_used_math(child) \
162 do { (child)->flags &= ~PF_USED_MATH, (child)->flags |= current->flags & PF_USED_MATH; } while (0)
163 /* NOTE: this will return 0 or PF_USED_MATH, it will never return 1 */
164 #define tsk_used_math(p) ((p)->flags & PF_USED_MATH)
165 #define used_math() tsk_used_math(current)
167 extern int __init task_subsys_init(void);
169 extern int arch_task_create(struct task_struct *task,
170 const start_state_t *start_state);
172 extern int sys_task_get_myid(id_t __user *id);
173 extern int sys_task_create(id_t id_request, const char __user *name,
174 const start_state_t __user *start_state,
176 extern int sys_task_exit(int status);
177 extern int sys_task_yield(void);
179 extern int __task_reserve_id(id_t id);
180 extern int __task_create(id_t id, const char *name,
181 const start_state_t *start_state,
182 struct task_struct **task);