mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Use linked list allocator instead of bump allocator
This commit is contained in:
@@ -14,3 +14,4 @@ multiboot2 = "0.1.0"
|
|||||||
bitflags = "0.7.0"
|
bitflags = "0.7.0"
|
||||||
x86_64 = "0.1.2"
|
x86_64 = "0.1.2"
|
||||||
once = "0.3.3"
|
once = "0.3.3"
|
||||||
|
linked_list_allocator = "0.4.2"
|
||||||
|
|||||||
15
src/lib.rs
15
src/lib.rs
@@ -20,6 +20,7 @@ extern crate bitflags;
|
|||||||
extern crate x86_64;
|
extern crate x86_64;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate once;
|
extern crate once;
|
||||||
|
extern crate linked_list_allocator;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod vga_buffer;
|
mod vga_buffer;
|
||||||
@@ -40,8 +41,13 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
|
|||||||
// set up guard page and map the heap pages
|
// set up guard page and map the heap pages
|
||||||
memory::init(boot_info);
|
memory::init(boot_info);
|
||||||
|
|
||||||
use alloc::boxed::Box;
|
unsafe {
|
||||||
let heap_test = Box::new(42);
|
HEAP_ALLOCATOR.lock().init(HEAP_START, HEAP_START + HEAP_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..10000 {
|
||||||
|
format!("Some String");
|
||||||
|
}
|
||||||
|
|
||||||
println!("It did not crash!");
|
println!("It did not crash!");
|
||||||
|
|
||||||
@@ -74,11 +80,10 @@ pub extern fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: u32
|
|||||||
loop{}
|
loop{}
|
||||||
}
|
}
|
||||||
|
|
||||||
use memory::heap_allocator::BumpAllocator;
|
use linked_list_allocator::LockedHeap;
|
||||||
|
|
||||||
pub const HEAP_START: usize = 0o_000_001_000_000_0000;
|
pub const HEAP_START: usize = 0o_000_001_000_000_0000;
|
||||||
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
|
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static HEAP_ALLOCATOR: BumpAllocator = BumpAllocator::new(HEAP_START,
|
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();
|
||||||
HEAP_START + HEAP_SIZE);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user