This repository was archived by the owner on Aug 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Resolve all known deadlock issues with PIT scheduling #6
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ca8ae13
Disable interrupts then restore to original state
robert-w-gries 5eaaa8c
Prevent exceptions from being interrupted
robert-w-gries 8daceab
Wrap allocator to disable interrupts
robert-w-gries 00ceeae
Remove unnecessary wrapper for printing
robert-w-gries 4144ec3
Remove unnecessary comment
robert-w-gries File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use alloc::allocator::{Alloc, AllocErr, Layout}; | ||
use linked_list_allocator::LockedHeap; | ||
use utils::disable_interrupts_and_then; | ||
|
||
pub const HEAP_START: usize = 0o_000_001_000_000_0000; | ||
pub const HEAP_SIZE: usize = 500 * 1024; | ||
|
||
pub struct HeapAllocator { | ||
inner: LockedHeap, | ||
} | ||
|
||
impl HeapAllocator { | ||
/// Creates an empty heap. All allocate calls will return `None`. | ||
pub const fn new() -> Self { | ||
HeapAllocator { | ||
inner: LockedHeap::empty(), | ||
} | ||
} | ||
|
||
/// Initializes an empty heap | ||
/// | ||
/// # Unsafety | ||
/// | ||
/// This function must be called at most once and must only be used on an | ||
/// empty heap. Also, it is assumed that interrupts are disabled. | ||
pub unsafe fn init(&self, heap_bottom: usize, heap_size: usize) { | ||
self.inner.lock().init(heap_bottom, heap_size); | ||
} | ||
} | ||
|
||
/// Wrappers for inner Alloc implementation | ||
unsafe impl<'a> Alloc for &'a HeapAllocator { | ||
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> { | ||
disable_interrupts_and_then(|| -> Result<*mut u8, AllocErr> { | ||
self.inner.lock().alloc(layout) | ||
}) | ||
} | ||
|
||
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) { | ||
disable_interrupts_and_then(|| { | ||
self.inner.lock().dealloc(ptr, layout); | ||
}); | ||
} | ||
|
||
fn oom(&mut self, _: AllocErr) -> ! { | ||
panic!("Out of memory"); | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this to being under
src/memory/mod.rs
? I dislike there being too much clutter insrc/lib.rs
and feel it would be more appropriate to keep it in the memory module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but there's unfortunately a bug in rust where global allocators need to be defined in
src/lib.rs
rust-lang/rust#44113