process: Rewrite ELF loading, processes
This commit is contained in:
+21
-9
@@ -4,6 +4,7 @@
|
||||
#include <zinnia/assert.h>
|
||||
#include <zinnia/atomic.h>
|
||||
#include <zinnia/errno.h>
|
||||
#include <zinnia/process.h>
|
||||
#include <zinnia/sched.h>
|
||||
#include <zinnia/spin.h>
|
||||
#include <zinnia/stack.h>
|
||||
@@ -25,7 +26,9 @@ void sched_to_user(uintptr_t info_ptr) {
|
||||
}
|
||||
|
||||
void sched_to_user_context(uintptr_t ctx) {
|
||||
arch_sched_jump_to_context((struct arch_context*)ctx);
|
||||
struct arch_context context = *(struct arch_context*)ctx;
|
||||
mem_free((void*)ctx);
|
||||
arch_sched_jump_to_context(&context);
|
||||
}
|
||||
|
||||
static struct spinlock task_cache_lock;
|
||||
@@ -54,20 +57,25 @@ static void task_release(struct task* task) {
|
||||
spin_unlock(&task_cache_lock);
|
||||
}
|
||||
|
||||
static void task_init_common(struct task* task, const char* name, struct vma* space) {
|
||||
task->space = space;
|
||||
static void task_init_common(struct task* task, const char* name, struct process* proc) {
|
||||
task->process = proc;
|
||||
task->space = proc->space;
|
||||
process_ref(proc);
|
||||
if (task->space != &kernel_vma)
|
||||
vma_ref(task->space);
|
||||
spin_init(&task->lock);
|
||||
atomic_store(&task->lockp, &task->lock, ATOMIC_RELAXED);
|
||||
strncpy(task->name, name, sizeof(task->name));
|
||||
task->base_prio = SCHED_PRIO_DEFAULT;
|
||||
task->base_prio = process_priority(proc);
|
||||
task->time_slice = SCHED_TIME_SLICE_NS;
|
||||
task->penalty = 0;
|
||||
task->feedback_epoch = 0;
|
||||
atomic_store(&task->priority, SCHED_PRIO_DEFAULT, ATOMIC_RELAXED);
|
||||
atomic_store(&task->priority, task->base_prio, ATOMIC_RELAXED);
|
||||
tailq_init(&task->pi_lenders);
|
||||
process_attach_task(proc, task);
|
||||
}
|
||||
|
||||
errno_t task_create_current(const char* name, struct vma* space, struct task** out) {
|
||||
errno_t task_create_current(const char* name, struct process* proc, struct task** out) {
|
||||
struct task* task = task_alloc();
|
||||
if (task == nullptr)
|
||||
return ENOMEM;
|
||||
@@ -78,14 +86,14 @@ errno_t task_create_current(const char* name, struct vma* space, struct task** o
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
task_init_common(task, name, space);
|
||||
task_init_common(task, name, proc);
|
||||
*out = task;
|
||||
return 0;
|
||||
}
|
||||
|
||||
constexpr size_t KERNEL_STACK_SIZE = 16 * 1024;
|
||||
|
||||
errno_t task_create(const char* name, struct vma* space, task_fn_t entry, uintptr_t arg0, struct task** out) {
|
||||
errno_t task_create(const char* name, struct process* proc, task_fn_t entry, uintptr_t arg0, struct task** out) {
|
||||
if (!out)
|
||||
return EINVAL;
|
||||
|
||||
@@ -119,7 +127,7 @@ errno_t task_create(const char* name, struct vma* space, task_fn_t entry, uintpt
|
||||
return s;
|
||||
}
|
||||
|
||||
task_init_common(new_task, name, space);
|
||||
task_init_common(new_task, name, proc);
|
||||
*out = new_task;
|
||||
return 0;
|
||||
}
|
||||
@@ -129,6 +137,10 @@ void task_destroy(struct task* task) {
|
||||
turnstile_free(task->turnstile);
|
||||
arch_task_fini(&task->context);
|
||||
stack_destroy(&task->kernel_stack);
|
||||
process_detach_task(task->process, task);
|
||||
if (task->space != &kernel_vma)
|
||||
vma_unref(task->space);
|
||||
process_unref(task->process);
|
||||
task_release(task);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user