aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-04-26 22:34:38 -0400
committerIan Moffett <ian@osmora.org>2024-04-26 22:34:38 -0400
commit70b046a032404d0fc7dc27e761b6ee7e693afb5f (patch)
treeba256cb57e2f2847036f5d0906c80f4498aa9a13
parent00f779ab42468ce761d65a44f61c3e28212ef4d2 (diff)
kernel: sched: Move sched stack macros to sched.h
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/include/sys/proc.h17
-rw-r--r--sys/kern/kern_sched.c35
2 files changed, 26 insertions, 26 deletions
diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h
index 8c1b959..85dd912 100644
--- a/sys/include/sys/proc.h
+++ b/sys/include/sys/proc.h
@@ -44,6 +44,23 @@
#define PROC_MAX_FDS 256
#define PROC_MAX_ADDR_RANGE 4
+#define PROC_STACK_PAGES 8
+#define PROC_STACK_SIZE (PROC_STACK_PAGES*vm_get_page_size())
+
+/*
+ * The PHYS_TO_VIRT/VIRT_TO_PHYS macros convert
+ * addresses to lower and higher half addresses.
+ * Userspace addresses are on the lower half,
+ * therefore, we can just wrap over these to
+ * keep things simple.
+ *
+ * XXX: TODO: This won't work when not identity mapping
+ * lowerhalf addresses. Once that is updated,
+ * get rid of this.
+ */
+#define USER_TO_KERN(user) PHYS_TO_VIRT(user)
+#define KERN_TO_USER(kern) VIRT_TO_PHYS(kern)
+
struct exec_args {
char **argp, **envp;
struct auxval auxv;
diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c
index c073224..c362b98 100644
--- a/sys/kern/kern_sched.c
+++ b/sys/kern/kern_sched.c
@@ -48,23 +48,6 @@
#include <assert.h>
#include <string.h>
-#define STACK_PAGES 8
-#define STACK_SIZE (STACK_PAGES*vm_get_page_size())
-
-/*
- * The PHYS_TO_VIRT/VIRT_TO_PHYS macros convert
- * addresses to lower and higher half addresses.
- * Userspace addresses are on the lower half,
- * therefore, we can just wrap over these to
- * keep things simple.
- *
- * XXX: TODO: This won't work when not identity mapping
- * lowerhalf addresses. Once that is updated,
- * get rid of this.
- */
-#define USER_TO_KERN(user) PHYS_TO_VIRT(user)
-#define KERN_TO_USER(kern) VIRT_TO_PHYS(kern)
-
/*
* Thread ready queue - all threads ready to be
* scheduled should be added to this queue.
@@ -222,24 +205,24 @@ sched_create_stack(struct vas vas, bool user, struct exec_args args,
struct vm_range *stack_range = &td->addr_range[ADDR_RANGE_STACK];
if (!user) {
- stack = (uintptr_t)dynalloc(STACK_SIZE);
+ stack = (uintptr_t)dynalloc(PROC_STACK_SIZE);
stack_range->start = (uintptr_t)stack;
- stack_range->end = (uintptr_t)stack + STACK_SIZE;
- return sched_init_stack((void *)(stack + STACK_SIZE), args);
+ stack_range->end = (uintptr_t)stack + PROC_STACK_SIZE;
+ return sched_init_stack((void *)(stack + PROC_STACK_SIZE), args);
}
- stack = vm_alloc_pageframe(STACK_PAGES);
+ stack = vm_alloc_pageframe(PROC_STACK_PAGES);
stack_range->start = stack;
- stack_range->end = stack + STACK_SIZE;
- status = vm_map_create(vas, stack, stack, USER_STACK_PROT, STACK_SIZE);
+ stack_range->end = stack + PROC_STACK_SIZE;
+ status = vm_map_create(vas, stack, stack, USER_STACK_PROT, PROC_STACK_SIZE);
if (status != 0) {
return 0;
}
- memset(USER_TO_KERN(stack), 0, STACK_SIZE);
- stack = sched_init_stack((void *)USER_TO_KERN(stack + STACK_SIZE), args);
+ memset(USER_TO_KERN(stack), 0, PROC_STACK_SIZE);
+ stack = sched_init_stack((void *)USER_TO_KERN(stack + PROC_STACK_SIZE), args);
return stack;
}
@@ -320,7 +303,7 @@ sched_destroy_td(struct proc *td)
* program to perform the proper deallocation method.
*/
if (td->is_user) {
- vm_free_pageframe(stack_range->start, STACK_PAGES);
+ vm_free_pageframe(stack_range->start, PROC_STACK_PAGES);
} else {
dynfree((void *)stack_range->start);
}