1
0
Fork 0
forked from AbleOS/ableos

Moved allocator to the kernel

This commit is contained in:
Erin 2022-05-07 14:08:34 +02:00 committed by ondra05
parent 351236159f
commit ae70548cc0
8 changed files with 39 additions and 10 deletions

1
Cargo.lock generated
View file

@ -384,6 +384,7 @@ dependencies = [
name = "kernel" name = "kernel"
version = "0.1.2" version = "0.1.2"
dependencies = [ dependencies = [
"linked_list_allocator",
"log", "log",
"versioning", "versioning",
] ]

View file

@ -1,4 +1,4 @@
use crate::allocator::{HEAP_SIZE, HEAP_START}; use kernel::allocator::{HEAP_SIZE, HEAP_START};
use alloc::alloc::{GlobalAlloc, Layout}; use alloc::alloc::{GlobalAlloc, Layout};
use core::ptr::null_mut; use core::ptr::null_mut;
use x86_64::{ use x86_64::{
@ -39,7 +39,7 @@ pub fn init_heap(
} }
unsafe { unsafe {
crate::allocator::ALLOCATOR kernel::allocator::ALLOCATOR
.lock() .lock()
.init(HEAP_START, HEAP_SIZE); .init(HEAP_START, HEAP_SIZE);
} }

View file

@ -1,6 +1,7 @@
use super::systeminfo::SystemMemory; use super::systeminfo::SystemMemory;
use crate::{arch::drivers::sysinfo::master, ALLOCATOR}; use crate::arch::drivers::sysinfo::master;
use core::fmt::Display; use core::fmt::Display;
use kernel::allocator::ALLOCATOR;
use versioning::Version; use versioning::Version;
use x86_64::instructions::interrupts::{disable, enable}; use x86_64::instructions::interrupts::{disable, enable};

View file

@ -40,7 +40,6 @@ pub mod print;
#[macro_use] #[macro_use]
pub mod serial_print; pub mod serial_print;
pub mod allocator;
pub mod boot_conf; pub mod boot_conf;
pub mod devices; pub mod devices;
pub mod driver_traits; pub mod driver_traits;
@ -68,7 +67,6 @@ mod unicode_utils;
#[prelude_import] #[prelude_import]
pub use prelude::rust_2021::*; pub use prelude::rust_2021::*;
pub use allocator::*;
pub use driver_traits::*; pub use driver_traits::*;
pub use experiments::*; pub use experiments::*;
pub use graphics::*; pub use graphics::*;

View file

@ -2,13 +2,13 @@ use crate::arch::drivers::sysinfo::master;
use crate::filesystem::FILE_SYSTEM; use crate::filesystem::FILE_SYSTEM;
use crate::time::fetch_time; use crate::time::fetch_time;
use crate::wasm_jumploader::interp; use crate::wasm_jumploader::interp;
use crate::ALLOCATOR;
use crate::{ use crate::{
arch::{shutdown, sloop}, arch::{shutdown, sloop},
systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
KERNEL_STATE, KERNEL_STATE,
}; };
use genfs::{Fs, OpenOptions}; use genfs::{Fs, OpenOptions};
use kernel::allocator::ALLOCATOR;
use rhai::Engine; use rhai::Engine;
use spin::Lazy; use spin::Lazy;
use x86_64::instructions::interrupts::{disable, enable}; use x86_64::instructions::interrupts::{disable, enable};

View file

@ -4,6 +4,7 @@ name = "kernel"
version = "0.1.2" version = "0.1.2"
[dependencies] [dependencies]
linked_list_allocator = "0.9"
log = "0.4.14" log = "0.4.14"
[dependencies.versioning] [dependencies.versioning]

24
kernel/src/allocator.rs Normal file
View file

@ -0,0 +1,24 @@
//! Memory allocator
use linked_list_allocator::LockedHeap;
///
pub const HEAP_START: usize = 0x_4444_4444_0000;
///
pub const HEAP_MULTIPLIER: usize = 100000;
///
pub const HEAP_BASE: usize = 100;
///
pub const HEAP_SIZE: usize = HEAP_BASE * HEAP_MULTIPLIER;
/// Global allocator
#[global_allocator]
pub static ALLOCATOR: LockedHeap = LockedHeap::empty();
#[alloc_error_handler]
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
panic!("allocation error: {:?}", layout)
}

View file

@ -1,10 +1,14 @@
//! The ableOS kernel. //! The ableOS kernel.
#![deny(missing_docs)] #![feature(alloc_error_handler)]
#![no_std]
#![feature(prelude_import)]
#![feature(arbitrary_enum_discriminant)] #![feature(arbitrary_enum_discriminant)]
#![feature(prelude_import)]
#![no_std]
#![deny(missing_docs)]
extern crate alloc;
pub mod allocator;
pub mod device_interface; pub mod device_interface;
pub mod messaging; pub mod messaging;
pub mod panic; pub mod panic;