diff --git a/Cargo.toml b/Cargo.toml index f89fb5e..d2d3873 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,14 +6,5 @@ edition = "2021" # 此Cargo.toml仅用于rust-analyzer识别rust部分的代码 # 不应使用cargo编译 -[build] -type = "staticlib" -rustflags = [ - "-C", "embed-bitcode=no", - "-C", "code-model=large", - "-C", "relocation-model=static", - "-L", "crate=${PWD}/../rustlib/${ARCH}/src/" -] - [target.'cfg(target_arch = "x86_64")'] target = "x86_64-unknown-none" diff --git a/include/kernel/memm.h b/include/kernel/memm.h index d3f730f..f4714ae 100644 --- a/include/kernel/memm.h +++ b/include/kernel/memm.h @@ -139,9 +139,9 @@ allocator对象在进程与内核之间传递时一律使用内核空间的映 */ void *memm_allocate(usize size, usize pid); #define memm_addr_set_allocator(mem, allocator) \ - *(allocator_t **)(mem - 16) = allocator; + *(allocator_t **)((void *)(mem) - 16) = allocator; #define memm_addr_get_allocator(mem) \ - ((*(allocator_t **)(mem - 16))) + ((*(allocator_t **)((void *)(mem) - 16))) void *memm_kernel_allocate(usize size); diff --git a/src/kernel/memm/memm.c b/src/kernel/memm/memm.c index 2b152e6..787befa 100644 --- a/src/kernel/memm/memm.c +++ b/src/kernel/memm/memm.c @@ -200,7 +200,8 @@ void *memm_allocate(usize size, usize pid) ptr = new_allocator->allocate(&new_allocator->allocator_instance, orgsize, 0); after_allocation: - memm_addr_set_allocator(ptr, allocator); + if (ptr != nullptr) + memm_addr_set_allocator(ptr, allocator); return ptr; } diff --git a/src/kernel/memm/memm.rs b/src/kernel/memm/memm.rs index 3995400..fea17bf 100644 --- a/src/kernel/memm/memm.rs +++ b/src/kernel/memm/memm.rs @@ -1,6 +1,9 @@ extern crate core; -use core::alloc::{GlobalAlloc, Layout}; +use core::{ + alloc::{GlobalAlloc, Layout}, + ptr::null_mut, +}; extern "C" { pub fn memm_kernel_allocate(size: usize) -> *mut u8; @@ -12,7 +15,14 @@ pub struct KernelAllocator {} unsafe impl GlobalAlloc for KernelAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - memm_kernel_allocate(layout.size()) + let res = memm_kernel_allocate(layout.size()); + if res == null_mut() { + panic!( + "Kernel allocator failed to allocate {} byte(s) memory.", + layout.size() + ); + } + res } unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) { diff --git a/src/metaverse.lds b/src/metaverse.lds index 3ef868d..87da7f2 100644 --- a/src/metaverse.lds +++ b/src/metaverse.lds @@ -96,6 +96,10 @@ SECTIONS { { *(.debug_pubtypes) } + .debug_frame : + { + *(.debug_frame) + } .kend : { *(.kend)