aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/core/thread.c
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-03-02 18:16:15 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-03-02 18:16:15 +0100
commitceb687b02964197133fd2236cdbc74bf3948d034 (patch)
treeb34b7aeec70990978c2562aa2d7b00202a223926 /src/kernel/core/thread.c
parentb68881abc4c50bbc8ee9e81b4e18b0ea011b83b7 (diff)
downloadkogata-ceb687b02964197133fd2236cdbc74bf3948d034.tar.gz
kogata-ceb687b02964197133fd2236cdbc74bf3948d034.zip
No lazy allocation of kernel memory. Placeholder for pmem freeing routine.
Diffstat (limited to 'src/kernel/core/thread.c')
-rw-r--r--src/kernel/core/thread.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c
index 5d2abae..cd46891 100644
--- a/src/kernel/core/thread.c
+++ b/src/kernel/core/thread.c
@@ -128,13 +128,15 @@ thread_t *new_thread(entry_t entry, void* data) {
thread_t *t = (thread_t*)malloc(sizeof(thread_t));
if (t == 0) return 0;
- void* stack = region_alloc(KPROC_STACK_SIZE, "Stack", 0);
+ void* stack = region_alloc(KPROC_STACK_SIZE + PAGE_SIZE, "Stack", pf_handler_stackoverflow);
if (stack == 0) {
free(t);
return 0;
}
+ void* stack_low = stack + PAGE_SIZE;
+ void* stack_high = stack_low + KPROC_STACK_SIZE;
- for (void* i = stack + PAGE_SIZE; i < stack + KPROC_STACK_SIZE; i += PAGE_SIZE) {
+ for (void* i = stack_low; i < stack_high; i += PAGE_SIZE) {
uint32_t f = frame_alloc(1);
if (f == 0) {
PANIC("TODO (OOM could not create kernel stack for new thread)");
@@ -146,8 +148,9 @@ thread_t *new_thread(entry_t entry, void* data) {
}
t->stack_region = find_region(stack);
+ ASSERT(stack_high == t->stack_region->addr + t->stack_region->size);
- t->ctx.esp = (uint32_t*)(t->stack_region->addr + t->stack_region->size);
+ t->ctx.esp = (uint32_t*)stack_high;
*(--t->ctx.esp) = (uint32_t)data; // push second argument : data
*(--t->ctx.esp) = (uint32_t)entry; // push first argument : entry point
*(--t->ctx.esp) = 0; // push invalid return address (the run_thread function never returns)