Added privilidges
This commit is contained in:
42
task.h
42
task.h
@@ -27,11 +27,28 @@
|
||||
|
||||
typedef enum {
|
||||
TASK_STATE_FREE = 0, /* PCB slot is unused */
|
||||
TASK_STATE_READY, /* runnable, waiting to be scheduled */
|
||||
TASK_STATE_RUNNING, /* currently executing on the CPU */
|
||||
TASK_STATE_TERMINATED /* finished; slot will be recycled */
|
||||
TASK_STATE_READY, /* runnable, waiting to be scheduled */
|
||||
TASK_STATE_RUNNING, /* currently executing on the CPU */
|
||||
TASK_STATE_TERMINATED /* finished; slot will be recycled */
|
||||
} TaskState;
|
||||
|
||||
/*
|
||||
* Logical privilege level for a task.
|
||||
*
|
||||
* Higher numeric values are more privileged:
|
||||
* USER (0) – least privileged
|
||||
* DRIVER (1) – mid-level, can talk to hardware-facing subsystems
|
||||
* KERNEL (2) – most privileged, core kernel and management threads
|
||||
*
|
||||
* All tasks still execute in ring 0 today; this is a software
|
||||
* hierarchy used for access control decisions and future paging work.
|
||||
*/
|
||||
typedef enum {
|
||||
TASK_PRIV_USER = 0,
|
||||
TASK_PRIV_DRIVER = 1,
|
||||
TASK_PRIV_KERNEL = 2,
|
||||
} TaskPrivilege;
|
||||
|
||||
/* ================================================================
|
||||
* Task entry function
|
||||
* ================================================================ */
|
||||
@@ -44,9 +61,10 @@ typedef void (*TaskEntryFn)(void *arg);
|
||||
* ================================================================ */
|
||||
|
||||
typedef struct Task {
|
||||
UINT32 pid; /* unique process ID */
|
||||
TaskState state; /* current lifecycle state */
|
||||
CHAR16 name[TASK_NAME_LEN]; /* human-readable label */
|
||||
UINT32 pid; /* unique process ID */
|
||||
TaskState state; /* current lifecycle state */
|
||||
TaskPrivilege privilege; /* logical privilege level */
|
||||
CHAR16 name[TASK_NAME_LEN]; /* human-readable label */
|
||||
|
||||
/* Context switch state */
|
||||
UINT64 saved_rsp; /* RSP saved by context_switch() */
|
||||
@@ -66,11 +84,21 @@ typedef struct Task {
|
||||
* ================================================================ */
|
||||
|
||||
void task_init(BootInfo *Boot); /* initialise scheduler */
|
||||
Task *task_create(const CHAR16 *name, /* spawn a new task */
|
||||
|
||||
/* Spawn a new task with a specific privilege level. */
|
||||
Task *task_create_with_priv(const CHAR16 *name,
|
||||
TaskEntryFn entry,
|
||||
void *arg,
|
||||
TaskPrivilege privilege);
|
||||
|
||||
/* Backwards-compatible helper: creates a kernel-privileged task. */
|
||||
Task *task_create(const CHAR16 *name,
|
||||
TaskEntryFn entry, void *arg);
|
||||
void task_yield(void); /* voluntarily give up the CPU */
|
||||
void task_exit(void); /* terminate the current task */
|
||||
Task *task_current(void); /* return the running task's PCB */
|
||||
TaskPrivilege task_get_privilege(Task *t);
|
||||
void task_set_privilege(Task *t, TaskPrivilege privilege);
|
||||
UINTN task_count(void); /* number of non-FREE tasks */
|
||||
void task_print_list(BootInfo *Boot); /* print task table (for `ps`) */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user