-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements stage 2 kernel heap activation (#960)
- Loading branch information
1 parent
2528bef
commit e2c7151
Showing
7 changed files
with
119 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
use super::Context; | ||
use crate::proc::Thread; | ||
|
||
pub unsafe fn activate(_: *mut Context) { | ||
todo!(); | ||
} | ||
|
||
pub unsafe fn thread() -> *const Thread { | ||
todo!(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,36 @@ | ||
use crate::context::Context; | ||
use core::alloc::Layout; | ||
|
||
/// Stage 2 kernel heap. | ||
/// | ||
/// This stage allocate a memory from a virtual memory management system. | ||
/// This stage allocate a memory from a virtual memory management system. This struct is a merge of | ||
/// `malloc_type` and `malloc_type_internal` structure. | ||
pub struct Stage2 {} | ||
|
||
impl Stage2 { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
/// See `malloc` on the PS4 for a reference. | ||
/// | ||
/// # Safety | ||
/// `layout` must be nonzero. | ||
pub unsafe fn alloc(&self, _: Layout) -> *mut u8 { | ||
// Our implementation imply M_WAITOK. | ||
let td = Context::thread(); | ||
|
||
if td.active_interrupts() != 0 { | ||
panic!("heap allocation in an interrupt handler is not supported"); | ||
} | ||
|
||
todo!() | ||
} | ||
|
||
/// # Safety | ||
/// `ptr` must be obtained with [`Self::alloc()`] and `layout` must be the same one that was | ||
/// passed to that method. | ||
pub unsafe fn dealloc(&self, _: *mut u8, _: Layout) { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
/// Implementation of `thread` structure. | ||
pub struct Thread {} | ||
/// | ||
/// All thread **must** run to completion once execution has been started otherwise resource will be | ||
/// leak if the thread is dropped while its execution currently in the kernel space. | ||
pub struct Thread { | ||
active_interrupts: usize, // td_intr_nesting_level | ||
} | ||
|
||
impl Thread { | ||
/// # Safety | ||
/// This function does not do anything except initialize the struct memory. It is the caller | ||
/// responsibility to configure the thread after this so it have a proper states and trigger | ||
/// necessary events. | ||
pub unsafe fn new_bare() -> Self { | ||
Self {} | ||
Self { | ||
active_interrupts: 0, | ||
} | ||
} | ||
|
||
pub fn active_interrupts(&self) -> usize { | ||
self.active_interrupts | ||
} | ||
} |