From f7aa7185962113ba4e19e9445f9e9ac406f161ea Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Fri, 12 Dec 2025 17:43:23 +1100 Subject: [PATCH] fix(redox-rt/proc): `min_mmap_addr` being set too low `cmp::min` -> `cmp::max` Want to make sure we set the `min_mmap_addr` to the top of the executable. `update_min_mmap_addr(STACK_TOP - STACK_SIZE, STACK_SIZE);` needs to be removed since we cannot allocate above that. Reverts to the old behaviour. In future may want to consider loading the executeable here instead of the dynamic linker (and before the dynamic linker) to avoid any further conflicts. Fixes `gcc` crashing at "failed to map /usr/libexec/gcc/x86_64-unknown-redox/13.2.0/cc1. errno: 17" (where 17 -> EEXIST). Co-authored-by: @bjorn3 Signed-off-by: Anhad Singh --- redox-rt/src/proc.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/redox-rt/src/proc.rs b/redox-rt/src/proc.rs index f2c1571818..470609dc1f 100644 --- a/redox-rt/src/proc.rs +++ b/redox-rt/src/proc.rs @@ -104,7 +104,7 @@ pub fn fexec_impl( // TODO: Remove clone, but this would require more as_refs and as_muts let mut min_mmap_addr = PAGE_SIZE; let mut update_min_mmap_addr = |addr: usize, size: usize| { - min_mmap_addr = cmp::min(min_mmap_addr, (addr + size).next_multiple_of(PAGE_SIZE)); + min_mmap_addr = cmp::max(min_mmap_addr, (addr + size).next_multiple_of(PAGE_SIZE)); }; pread_all(&image_file, u64::from(header.e_phoff), phs).map_err(|_| Error::new(EIO))?; @@ -195,7 +195,6 @@ pub fn fexec_impl( STACK_SIZE, MapFlags::PROT_READ | MapFlags::PROT_WRITE | MapFlags::MAP_FIXED_NOREPLACE, )?; - update_min_mmap_addr(STACK_TOP - STACK_SIZE, STACK_SIZE); let mut sp = STACK_TOP; let mut stack_page = Option::::None;