summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-14 20:55:54 -0400
committerIan Moffett <ian@osmora.org>2024-03-14 20:55:54 -0400
commit7a32267fcc81af31d595373884911d503b0a9df8 (patch)
tree31c3393499f598d74c47fc8b3479c5782100b93a /sys
parent5a8915f5b36cf3b21c843ef7959c24ac39318aca (diff)
kernel: sched: Keep track of stack and privilege
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/include/sys/proc.h2
-rw-r--r--sys/kern/kern_sched.c16
2 files changed, 12 insertions, 6 deletions
diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h
index 34a5037..7181ecb 100644
--- a/sys/include/sys/proc.h
+++ b/sys/include/sys/proc.h
@@ -47,6 +47,8 @@ struct proc {
struct trapframe *tf;
struct pcb pcb;
struct vas addrsp;
+ uintptr_t stack_base;
+ uint8_t is_user;
TAILQ_ENTRY(proc) link;
};
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index bc96146..f985f62 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -208,7 +208,7 @@ sched_init_stack(void *stack_top, char *argvp[], char *envp[], struct auxval aux
static uintptr_t
sched_create_stack(struct vas vas, bool user, char *argvp[],
- char *envp[], struct auxval auxv)
+ char *envp[], struct auxval auxv, struct proc *td)
{
int status;
uintptr_t stack;
@@ -216,10 +216,12 @@ sched_create_stack(struct vas vas, bool user, char *argvp[],
if (!user) {
stack = (uintptr_t)dynalloc(STACK_SIZE);
+ td->stack_base = (uintptr_t)stack;
return sched_init_stack((void *)(stack + STACK_SIZE), argvp, envp, auxv);
}
stack = vm_alloc_pageframe(STACK_PAGES);
+ td->stack_base = stack;
status = vm_map_create(vas, stack, stack, USER_STACK_PROT, STACK_SIZE);
if (status != 0) {
@@ -244,16 +246,17 @@ sched_create_td(uintptr_t rip, char *argvp[], char *envp[], struct auxval auxv,
return NULL;
}
- stack = sched_create_stack(vas, is_user, argvp, envp, auxv);
- if (stack == 0) {
+ td = dynalloc(sizeof(struct proc));
+ if (td == NULL) {
+ /* TODO: Free stack */
dynfree(tf);
return NULL;
}
- td = dynalloc(sizeof(struct proc));
- if (td == NULL) {
- /* TODO: Free stack */
+ stack = sched_create_stack(vas, is_user, argvp, envp, auxv, td);
+ if (stack == 0) {
dynfree(tf);
+ dynfree(td);
return NULL;
}
@@ -265,6 +268,7 @@ sched_create_td(uintptr_t rip, char *argvp[], char *envp[], struct auxval auxv,
td->cpu = NULL; /* Not yet assigned a core */
td->tf = tf;
td->addrsp = vas;
+ td->is_user = is_user;
processor_init_pcb(td);
/* Setup trapframe */