mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
Fix sys_mmap_metal() for non-MAP_FIXED case (#651)
- 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
This commit is contained in:
parent
7bc24888fe
commit
bc353f454b
1 changed files with 3 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue