Skip to content

Commit

Permalink
[metal] Fix regression causing early crash in __new_page( ) (#900)
Browse files Browse the repository at this point in the history
There was a glitch in the refactoring of __map_phdrs( ) in
commit ec480f5, which caused it to try to map the PT_NOTE
program segment into virtual memory, which in turn caused the
memory page at BANE to be wrongly remapped to the start of
the program image (0x100000) rather than physical address 0.
This affected subsequent page allocation operations because
the `struct mman` was located at BANE + 0x0500.

Co-authored-by: tkchia <[email protected]>
  • Loading branch information
tkchia and tkchia authored Oct 3, 2023
1 parent b01282e commit fcdda40
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libc/intrin/mman.greg.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ static textreal uint64_t __map_phdr(struct mman *mm, uint64_t *pml4t,
uint64_t b, uint64_t m,
struct Elf64_Phdr *p) {
uint64_t i, f, v;
if (p->p_type != PT_LOAD) return m;
f = PAGE_RSRV | PAGE_U;
if (p->p_flags & PF_W)
f |= PAGE_V | PAGE_RW;
Expand Down Expand Up @@ -303,6 +304,7 @@ textreal void __map_phdrs(struct mman *mm, uint64_t *pml4t, uint64_t b,
}
m = __map_phdr(mm, pml4t, b, m,
&(struct Elf64_Phdr){
.p_type = PT_LOAD,
.p_flags = (uintptr_t)ape_stack_pf,
.p_offset = (uintptr_t)ape_stack_offset,
.p_vaddr = ABS64(ape_stack_vaddr),
Expand Down

0 comments on commit fcdda40

Please sign in to comment.