error: `#[alloc_error_handler]` function required, but not found
error: aborting due to previous error
error: Could not compile `os`.
To learn more, run the command again with --verbose.
Makefile:30: recipe for target 'kernel' failed
make: *** [kernel] Error 101
FIX error: #[alloc_error_handler] function required, but not found
pubfntest() {let frame1:Frame=alloc_frame().expect("failed to alloc frame");println!("test frame_allocator: {:#x}", frame1.start_address().as_usize());let frame2:Frame=alloc_frame().expect("failed to alloc frame");println!("test frame_allocator: {:#x}", frame2.start_address().as_usize());dealloc_frame(frame1);let frame3:Frame=alloc_frame().expect("failed to alloc frame");println!("test frame_allocator: {:#x}", frame3.start_address().as_usize());dealloc_frame(frame2);dealloc_frame(frame3);}
然后修改 memory/mod.rs 的 init() :
pubmod frame_allocator;use frame_allocator::{ init as init_frame_allocator, test as test_frame_allocator };usecrate::consts::*;usecrate::HEAP_ALLOCATOR;pubfninit(dtb:usize) {use riscv::register::sstatus;unsafe {// Allow user memory access sstatus::set_sum(); }init_heap();ifletSome((addr, mem_size)) = device_tree::DeviceTree::dtb_query_memory(dtb) {assert_eq!(addr, MEMORY_OFFSET);let KERNEL_END = dtb - KERNEL_OFFSET + MEMORY_OFFSET + PAGE_SIZE;let KERNEL_SIZE = KERNEL_END - addr;init_frame_allocator(KERNEL_END, KERNEL_SIZE); } else {panic!("failed to query memory"); }test_frame_allocator();}
执行 make run ,出现了如下错误:
error[E0152]: duplicate lang item found: `oom`.
--> src/memory/mod.rs:49:1
|
49 | / fn foo(_: core::alloc::Layout) -> ! {
50 | | panic!("DO NOTHING alloc_error_handler set by kernel");
51 | | }
| |_^
|
= note: first defined in crate `buddy_allocator`.
error: aborting due to previous error
For more information about this error, try `rustc --explain E0152`.
error: Could not compile `os`.