From 1b315de830d7b88d0cbfd439e32ce4388179a201 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sun, 15 Aug 2021 19:26:11 +0800 Subject: [PATCH] kernel: make init proces stack grown downwards Previously, we were creating a stack beginning at the initial page, and then growing it upwards. The correct behavior is to begin it at the top and grow it downwards. In order to do this, subtract the size of the stack from the initial pointer. Signed-off-by: Sean Cross --- kernel/src/services.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/src/services.rs b/kernel/src/services.rs index f5fa9581f..84d43426c 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -360,7 +360,11 @@ impl SystemServices { process.state = ProcessState::Setup(ThreadInit::new( unsafe { core::mem::transmute::(init.entrypoint) }, unsafe { - MemoryRange::new(init.sp, crate::arch::process::DEFAULT_STACK_SIZE).unwrap() + MemoryRange::new( + init.sp - crate::arch::process::DEFAULT_STACK_SIZE, + crate::arch::process::DEFAULT_STACK_SIZE, + ) + .unwrap() }, pid, 0,