kernel: Zero physical frames instead of virtual pages
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
The memset() happens a bit earlier, and we don't have to remap the mapped virtual memory.
This commit is contained in:
parent
3b1219ecf2
commit
af26dce038
@ -151,6 +151,16 @@ namespace MemoryManager
|
||||
return index * ARCH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
Result<u64> alloc_zeroed_frame()
|
||||
{
|
||||
const u64 frame = TRY(alloc_frame());
|
||||
|
||||
const u64 address = MMU::translate_physical_address(frame);
|
||||
memset((void*)address, 0, ARCH_PAGE_SIZE);
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
Result<void> free_frame(u64 frame)
|
||||
{
|
||||
const u64 index = frame / ARCH_PAGE_SIZE;
|
||||
@ -263,15 +273,24 @@ namespace MemoryManager
|
||||
|
||||
Result<u64> alloc_at_zeroed(u64 virt, usize count, int flags)
|
||||
{
|
||||
u64 address = TRY(alloc_at(virt, count, MMU::ReadWrite));
|
||||
CHECK_PAGE_ALIGNED(virt);
|
||||
|
||||
memset((void*)address, 0, count * ARCH_PAGE_SIZE);
|
||||
u64 start = virt;
|
||||
usize pages_mapped = 0;
|
||||
|
||||
// This should never fail (we just mapped memory at that address) but we don't want to crash the kernel if it
|
||||
// does.
|
||||
TRY(remap(address, count, flags));
|
||||
auto guard = make_scope_guard([=, &pages_mapped] { unmap_owned(start, pages_mapped); });
|
||||
|
||||
return address;
|
||||
while (pages_mapped < count)
|
||||
{
|
||||
const u64 frame = TRY(alloc_zeroed_frame());
|
||||
TRY(MMU::map(virt, frame, flags, MMU::UseHugePages::No));
|
||||
virt += ARCH_PAGE_SIZE;
|
||||
pages_mapped++;
|
||||
}
|
||||
|
||||
guard.deactivate();
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
Result<u64> alloc_for_kernel(usize count, int flags)
|
||||
|
@ -13,6 +13,7 @@ namespace MemoryManager
|
||||
Result<void> protect_kernel_sections();
|
||||
|
||||
Result<u64> alloc_frame();
|
||||
Result<u64> alloc_zeroed_frame();
|
||||
Result<void> free_frame(u64 frame);
|
||||
Result<void> free_frames(u64 address, usize count);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user