MCPcopy Create free account
hub / github.com/bendudson/EuraliOS / create_empty_pagetable

Function create_empty_pagetable

kernel/src/memory.rs:111–128  ·  view source on GitHub ↗

Create a new page table Returns ------- - A pointer to the PageTable (virtual address in kernel mapped pages) - The physical address which can be written to cr3

()

Source from the content-addressed store, hash-verified

109/// - The physical address which can be written to cr3
110///
111fn create_empty_pagetable() -> (*mut PageTable, u64) {
112 // Need to borrow as mutable so that we can allocate new frames
113 // and so modify the frame allocator
114 let memory_info = unsafe {MEMORY_INFO.as_mut().unwrap()};
115
116 // Get a frame to store the level 4 table
117 let level_4_table_frame = memory_info.frame_allocator.allocate_frame().unwrap();
118 let phys = level_4_table_frame.start_address(); // Physical address
119 let virt = memory_info.physical_memory_offset + phys.as_u64(); // Kernel virtual address
120 let page_table_ptr: *mut PageTable = virt.as_mut_ptr();
121
122 // Clear all entries in the page table
123 unsafe {
124 (*page_table_ptr).zero();
125 }
126
127 (page_table_ptr, phys.as_u64())
128}
129
130/// Copy a set of pagetables
131fn copy_pagetables(level_4_table: &PageTable) -> (*mut PageTable, u64) {

Callers 5

copy_pagetablesFunction · 0.85
copy_pages_recFunction · 0.85
put_page_chunkFunction · 0.85
allocate_user_stackFunction · 0.85

Calls 3

allocate_frameMethod · 0.80
as_mut_ptrMethod · 0.80
as_u64Method · 0.45

Tested by

no test coverage detected