Skip to content

Commit

Permalink
Fix sys_mmap_metal() for non-MAP_FIXED case (#651)
Browse files Browse the repository at this point in the history
- correctly check that virtual region we want to use is
  unmapped, rather than accidentally clobbering existing pages
- avoid placing mmap'd memory at null virtual address
  • Loading branch information
tkchia authored Oct 6, 2022
1 parent 7bc2488 commit bc353f4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libc/intrin/directmap-metal.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ noasan struct DirectMap sys_mmap_metal(void *paddr, size_t size, int prot,
size = ROUNDUP(size, 4096);
addr = (uint64_t)paddr;
if (!(flags & MAP_FIXED)) {
if (!addr)
addr = 4096;
for (i = 0; i < size; i += 4096) {
pte = __get_virtual(mm, pml4t, addr, false);
pte = __get_virtual(mm, pml4t, addr + i, false);
if (pte && (*pte & PAGE_V)) {
addr = MAX(addr, sys_mmap_metal_break) + i + 4096;
i = 0;
Expand Down

0 comments on commit bc353f4

Please sign in to comment.