-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Add new UnsafePhysFrame type and use it in Mapper::map_to"
This reverts commit 0c8756f.
- Loading branch information
Showing
5 changed files
with
41 additions
and
77 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,54 +1,18 @@ | ||
//! Traits for abstracting away frame allocation and deallocation. | ||
use crate::structures::paging::{PageSize, PhysFrame, Size4KiB}; | ||
use core::ops::{Deref, DerefMut}; | ||
use crate::structures::paging::{PageSize, PhysFrame}; | ||
|
||
/// A trait for types that can allocate a frame of memory. | ||
/// | ||
/// This trait is unsafe to implement because the implementer must guarantee that | ||
/// the `allocate_frame` method returns only unique unused frames. | ||
pub unsafe trait FrameAllocator<S: PageSize> { | ||
/// Allocate a frame of the appropriate size and return it if possible. | ||
fn allocate_frame(&mut self) -> Option<UnusedPhysFrame<S>>; | ||
fn allocate_frame(&mut self) -> Option<PhysFrame<S>>; | ||
} | ||
|
||
/// A trait for types that can deallocate a frame of memory. | ||
pub trait FrameDeallocator<S: PageSize> { | ||
/// Deallocate the given frame of memory. | ||
fn deallocate_frame(&mut self, frame: UnusedPhysFrame<S>); | ||
} | ||
|
||
/// Represents a physical frame that is not used for any mapping. | ||
#[derive(Debug)] | ||
pub struct UnusedPhysFrame<S: PageSize = Size4KiB>(PhysFrame<S>); | ||
|
||
impl<S: PageSize> UnusedPhysFrame<S> { | ||
/// Creates a new UnusedPhysFrame from the given frame. | ||
/// | ||
/// ## Safety | ||
/// | ||
/// This method is unsafe because the caller must guarantee | ||
/// that the given frame is unused. | ||
pub unsafe fn new(frame: PhysFrame<S>) -> Self { | ||
Self(frame) | ||
} | ||
|
||
/// Returns the physical frame as `PhysFrame` type. | ||
pub fn frame(self) -> PhysFrame<S> { | ||
self.0 | ||
} | ||
} | ||
|
||
impl<S: PageSize> Deref for UnusedPhysFrame<S> { | ||
type Target = PhysFrame<S>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl<S: PageSize> DerefMut for UnusedPhysFrame<S> { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.0 | ||
} | ||
fn deallocate_frame(&mut self, frame: PhysFrame<S>); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
phil-opp
Author
Member
|
||
} |
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
Shouldn't
FrameDeallocator::deallocate_frame
be unsafe now, now that it's no longer protected byUnusedPhysFrame
being unsafe to make?