Skip to content

Commit 29277d9

Browse files
committed
fix(mm): make virtualmem and physicalmem functions unsafe as appropriate
1 parent 4fbb248 commit 29277d9

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/mm/physicalmem.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ pub struct FrameAlloc;
2222

2323
impl PageRangeAllocator for FrameAlloc {
2424
unsafe fn init() {
25-
init();
25+
unsafe {
26+
init();
27+
}
2628
}
2729

2830
fn allocate(layout: PageLayout) -> Result<PageRange, AllocError> {
@@ -99,7 +101,7 @@ pub unsafe fn map_frame_range(frame_range: PageRange) {
99101
}
100102
}
101103

102-
fn detect_from_fdt() -> Result<(), ()> {
104+
unsafe fn detect_from_fdt() -> Result<(), ()> {
103105
let fdt = env::fdt().ok_or(())?;
104106

105107
let all_regions = fdt
@@ -198,7 +200,7 @@ impl PageRangeExt for PageRange {
198200
}
199201

200202
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
201-
fn detect_from_limits() -> Result<(), ()> {
203+
unsafe fn detect_from_limits() -> Result<(), ()> {
202204
let limit = crate::arch::kernel::get_limit();
203205
if limit == 0 {
204206
return Err(());
@@ -220,19 +222,19 @@ fn detect_from_limits() -> Result<(), ()> {
220222
Ok(())
221223
}
222224

223-
fn init() {
225+
unsafe fn init() {
224226
if env::is_uefi() && DeviceAlloc.phys_offset() != VirtAddr::zero() {
225227
let start = DeviceAlloc.phys_offset();
226228
let count = DeviceAlloc.phys_offset().as_u64() / HugePageSize::SIZE;
227229
let count = usize::try_from(count).unwrap();
228230
paging::unmap::<HugePageSize>(start, count);
229231
}
230232

231-
if let Err(_err) = detect_from_fdt() {
233+
if let Err(_err) = unsafe { detect_from_fdt() } {
232234
cfg_if::cfg_if! {
233235
if #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] {
234236
error!("Could not detect physical memory from FDT");
235-
detect_from_limits().unwrap();
237+
unsafe { detect_from_limits().unwrap(); }
236238
} else {
237239
panic!("Could not detect physical memory from FDT");
238240
}

src/mm/virtualmem.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ pub struct PageAlloc;
1414

1515
impl PageRangeAllocator for PageAlloc {
1616
unsafe fn init() {
17-
init();
17+
unsafe {
18+
init();
19+
}
1820
}
1921

2022
fn allocate(layout: PageLayout) -> Result<PageRange, AllocError> {
@@ -47,7 +49,7 @@ impl fmt::Display for PageAlloc {
4749

4850
pub type PageBox = PageRangeBox<PageAlloc>;
4951

50-
fn init() {
52+
unsafe fn init() {
5153
let range = PageRange::new(
5254
kernel_heap_end().as_usize().div_ceil(2),
5355
kernel_heap_end().as_usize() + 1,

0 commit comments

Comments
 (0)