From d396da5f3c4dca3b60332565d1f001611a1299fb Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 15 Nov 2023 19:37:52 +0100 Subject: [PATCH] Stack grows downwards, baka. --- kernel/src/holeybytes/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/src/holeybytes/mod.rs b/kernel/src/holeybytes/mod.rs index fa3bb72..cbf56f7 100644 --- a/kernel/src/holeybytes/mod.rs +++ b/kernel/src/holeybytes/mod.rs @@ -1,12 +1,10 @@ -use core::ptr::NonNull; - mod ecah; mod mem; use { crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS}, alloc::boxed::Box, - core::{default, future::Future, marker::PhantomData, task::Poll}, + core::{default, future::Future, marker::PhantomData, ptr::NonNull, task::Poll}, hbvm::{ mem::{ softpaging::{icache::ICache, HandlePageFault, SoftPagedMem}, @@ -17,6 +15,7 @@ use { log::{debug, error, info, trace, warn}, }; +const STACK_SIZE: usize = 1024 * 1024; const TIMER_QUOTIENT: usize = 100; type Vm = hbvm::Vm; @@ -41,7 +40,7 @@ impl<'p> ExecThread<'p> { ) }; - let stack_top = allocate_stack().as_ptr(); + let stack_top = unsafe { allocate_stack().as_ptr().add(STACK_SIZE - 1) }; vm.write_reg(254, stack_top as u64); ExecThread { @@ -54,7 +53,7 @@ impl<'p> ExecThread<'p> { impl<'p> Drop for ExecThread<'p> { fn drop(&mut self) { - unsafe { alloc::alloc::dealloc(self.stack_top, stack_layout()) }; + unsafe { alloc::alloc::dealloc(self.stack_top.sub(STACK_SIZE - 1), stack_layout()) }; } } @@ -111,7 +110,7 @@ impl HandlePageFault for PageFaultHandler { } const fn stack_layout() -> core::alloc::Layout { - unsafe { alloc::alloc::Layout::from_size_align_unchecked(1024 * 1024, 4096) } + unsafe { alloc::alloc::Layout::from_size_align_unchecked(STACK_SIZE, 4096) } } fn allocate_stack() -> NonNull {