mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Fix corner case in Linux stack mappings
We need to make sure no existing mappings exist between the MAP_GROWSDOWN page and the guard page, since otherwise it's not going to be able to grow down thus causing difficult to troubleshoot failures.
This commit is contained in:
parent
6ba3b448f3
commit
3b4fcd8575
9 changed files with 14 additions and 16 deletions
|
@ -361,6 +361,10 @@ static noasan inline void *Mmap(void *addr, size_t size, int prot, int flags,
|
|||
f |= MAP_STACK_openbsd;
|
||||
needguard = true;
|
||||
} else if (IsLinux()) {
|
||||
// make sure there's no existing stuff existing between our stack
|
||||
// starting page and the bottom guard page, since that would stop
|
||||
// our stack page from growing down.
|
||||
_npassert(!sys_munmap(p, size));
|
||||
// by default MAP_GROWSDOWN will auto-allocate 10mb of pages. it's
|
||||
// supposed to stop growing if an adjacent allocation exists, to
|
||||
// prevent your stacks from overlapping on each other. we're not
|
||||
|
@ -376,8 +380,9 @@ static noasan inline void *Mmap(void *addr, size_t size, int prot, int flags,
|
|||
.addr == MAP_FAILED) {
|
||||
return MAP_FAILED;
|
||||
}
|
||||
sys_mmap(p, PAGESIZE, PROT_NONE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
|
||||
-1, 0);
|
||||
_npassert(sys_mmap(p, PAGESIZE, PROT_NONE,
|
||||
MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)
|
||||
.addr == p);
|
||||
dm.addr = p;
|
||||
return FinishMemory(p, size, prot, flags, fd, off, f, x, n, dm);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue