Create dummy allocator

This commit is contained in:
Yash Karandikar 2021-09-19 13:59:28 -05:00
parent e51b3a53e7
commit 4600a8c774
Signed by: karx
GPG key ID: A794DA2529474BA5
4 changed files with 28 additions and 2 deletions

View file

@ -1,6 +1,6 @@
[unstable]
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins"]
build-std = ["core", "compiler_builtins", "alloc"]
[build]
target = "x86_64-karxos.json"

17
src/allocator.rs Normal file
View file

@ -0,0 +1,17 @@
use alloc::alloc::{GlobalAlloc, Layout};
use core::ptr::null_mut;
pub struct Dummy;
unsafe impl GlobalAlloc for Dummy {
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
null_mut()
}
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
panic!("dealloc should never be called");
}
}
#[global_allocator]
static ALLOCATOR: Dummy = Dummy;

View file

@ -5,22 +5,31 @@
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
#![feature(abi_x86_interrupt)]
#![feature(alloc_error_handler)]
mod gdt;
mod interrupts;
mod shell;
mod vga_buffer;
mod memory;
mod allocator;
use core::panic::PanicInfo;
use bootloader::BootInfo;
extern crate alloc;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("{}", info);
loop {}
}
#[alloc_error_handler]
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
panic!("allocation error: {:?}", layout)
}
fn init() {
gdt::init_gdt();
interrupts::init();

View file

@ -1,4 +1,4 @@
use x86_64::{PhysAddr, VirtAddr, structures::paging::{FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB}};
use x86_64::{PhysAddr, VirtAddr, structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB}};
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static> {