Skip to content
Snippets Groups Projects
Commit 9a1efda1 authored by Ahmed Abd El Mawgood's avatar Ahmed Abd El Mawgood
Browse files

Initial allocator structure

parent 04f77881
No related branches found
No related tags found
No related merge requests found
...@@ -59,10 +59,10 @@ pub mod platform; ...@@ -59,10 +59,10 @@ pub mod platform;
pub mod start; pub mod start;
pub mod sync; pub mod sync;
use crate::platform::{Allocator, Pal, Sys}; use crate::platform::{Allocator, Pal, Sys, NEWALLOCATOR};
#[global_allocator] #[global_allocator]
static ALLOCATOR: Allocator = Allocator; static ALLOCATOR: Allocator = NEWALLOCATOR;
#[no_mangle] #[no_mangle]
pub extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! { pub extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! {
......
use core::alloc::{GlobalAlloc, Layout}; use core::{
alloc::{GlobalAlloc, Layout},
sync::atomic::{AtomicUsize, Ordering},
};
use super::types::*; use super::types::*;
...@@ -9,8 +12,22 @@ extern "C" { ...@@ -9,8 +12,22 @@ extern "C" {
fn dlfree(mem: *mut c_void); fn dlfree(mem: *mut c_void);
} }
pub struct Allocator; pub struct Allocator {
mstate: AtomicUsize,
}
pub const NEWALLOCATOR:Allocator = Allocator{
mstate: AtomicUsize::new(0),
};
impl Allocator {
pub fn set_bookkeeper(&self, mstate: usize) {
self.mstate.store(mstate, Ordering::Relaxed);
}
fn get_bookKeeper(&self) ->usize {
self.mstate.load(Ordering::Relaxed)
}
}
unsafe impl<'a> GlobalAlloc for Allocator { unsafe impl<'a> GlobalAlloc for Allocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
alloc_align(layout.size(), layout.align()) as *mut u8 alloc_align(layout.size(), layout.align()) as *mut u8
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment