sched: implement user-mode task and thread creation
This commit is contained in:
60
sched/task.c
60
sched/task.c
@@ -145,7 +145,7 @@ kern_status_t setup_idle_task(void)
|
||||
|
||||
idle_thread->tr_id = 0;
|
||||
idle_thread->tr_parent = __idle_task;
|
||||
thread_init(idle_thread, (uintptr_t)idle);
|
||||
thread_init_kernel(idle_thread, (uintptr_t)idle);
|
||||
|
||||
queue_push_back(&__idle_task->t_threads, &idle_thread->tr_parent_entry);
|
||||
|
||||
@@ -170,6 +170,50 @@ struct task *task_alloc(void)
|
||||
return t;
|
||||
}
|
||||
|
||||
struct task *task_create(struct task *parent, const char *name)
|
||||
{
|
||||
struct task *task = task_alloc();
|
||||
if (!task) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pmap_t pmap = pmap_create();
|
||||
if (pmap == PMAP_INVALID) {
|
||||
object_unref(&task->t_base);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
task->t_id = pid_alloc();
|
||||
task->t_pmap = pmap;
|
||||
vm_region_create(
|
||||
NULL,
|
||||
"root",
|
||||
VM_USER_BASE,
|
||||
VM_USER_LIMIT - VM_USER_BASE,
|
||||
VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXEC | VM_PROT_USER,
|
||||
&task->t_address_space);
|
||||
|
||||
task->t_address_space->vr_pmap = pmap;
|
||||
task->t_state = TASK_STOPPED;
|
||||
task->t_handles = handle_table_create();
|
||||
|
||||
if (name) {
|
||||
strncpy(task->t_name, name, sizeof task->t_name);
|
||||
task->t_name[sizeof task->t_name - 1] = '\0';
|
||||
}
|
||||
|
||||
unsigned long flags;
|
||||
task_lock_irqsave(parent, &flags);
|
||||
queue_push_back(&parent->t_children, &task->t_child_entry);
|
||||
task_unlock_irqrestore(parent, flags);
|
||||
|
||||
spin_lock_irqsave(&task_list_lock, &flags);
|
||||
task_list_insert(&task_list, task);
|
||||
spin_unlock_irqrestore(&task_list_lock, flags);
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
struct task *task_from_pid(unsigned int pid)
|
||||
{
|
||||
unsigned long flags;
|
||||
@@ -179,6 +223,20 @@ struct task *task_from_pid(unsigned int pid)
|
||||
return t;
|
||||
}
|
||||
|
||||
struct thread *task_create_thread(struct task *parent)
|
||||
{
|
||||
struct thread *thread = thread_alloc();
|
||||
thread->tr_id = parent->t_next_thread_id++;
|
||||
thread->tr_prio = PRIO_NORMAL;
|
||||
thread->tr_state = THREAD_STOPPED;
|
||||
thread->tr_parent = parent;
|
||||
thread->tr_quantum_target = default_quantum();
|
||||
|
||||
queue_push_back(&parent->t_threads, &thread->tr_parent_entry);
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
struct task *current_task(void)
|
||||
{
|
||||
struct thread *thr = current_thread();
|
||||
|
||||
Reference in New Issue
Block a user