mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Unsafe operations in unsafe functions require an unsafe block since Rust 2024
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
||||||
use x86_64::{
|
use x86_64::{
|
||||||
|
PhysAddr, VirtAddr,
|
||||||
structures::paging::{
|
structures::paging::{
|
||||||
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB,
|
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB,
|
||||||
},
|
},
|
||||||
PhysAddr, VirtAddr,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Initialize a new OffsetPageTable.
|
/// Initialize a new OffsetPageTable.
|
||||||
@@ -13,8 +13,10 @@ use x86_64::{
|
|||||||
/// `physical_memory_offset`. Also, this function must be only called once
|
/// `physical_memory_offset`. Also, this function must be only called once
|
||||||
/// to avoid aliasing `&mut` references (which is undefined behavior).
|
/// to avoid aliasing `&mut` references (which is undefined behavior).
|
||||||
pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static> {
|
pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static> {
|
||||||
let level_4_table = active_level_4_table(physical_memory_offset);
|
unsafe {
|
||||||
OffsetPageTable::new(level_4_table, physical_memory_offset)
|
let level_4_table = active_level_4_table(physical_memory_offset);
|
||||||
|
OffsetPageTable::new(level_4_table, physical_memory_offset)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a mutable reference to the active level 4 table.
|
/// Returns a mutable reference to the active level 4 table.
|
||||||
@@ -32,7 +34,7 @@ unsafe fn active_level_4_table(physical_memory_offset: VirtAddr) -> &'static mut
|
|||||||
let virt = physical_memory_offset + phys.as_u64();
|
let virt = physical_memory_offset + phys.as_u64();
|
||||||
let page_table_ptr: *mut PageTable = virt.as_mut_ptr();
|
let page_table_ptr: *mut PageTable = virt.as_mut_ptr();
|
||||||
|
|
||||||
&mut *page_table_ptr // unsafe
|
unsafe { &mut *page_table_ptr }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an example mapping for the given page to frame `0xb8000`.
|
/// Creates an example mapping for the given page to frame `0xb8000`.
|
||||||
|
|||||||
Reference in New Issue
Block a user