fix(mm): fix brk syscall to properly map heap pages #92
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The original brk implementation had several issues:
Implementation
File:
api/src/syscall/mm/brk.rsBug Description:
The original
brkimplementation did not properly track the initial heap region that was already mapped during ELF loading. When a process calledbrkto expand the heap, it would attempt to map pages that were already mapped, causingAlreadyExistserrors.Fix:
initial_heap_end(USER_HEAP_BASE + USER_HEAP_SIZE) as the end of the pre-mapped regioninitial_heap_end.max(current_top_aligned)as the expansion start pointsaturating_subto avoid negative sizesFiles:
core/src/config/aarch64.rscore/src/config/loongarch64.rscore/src/config/riscv64.rscore/src/config/x86_64.rsDescription:
Added
USER_HEAP_SIZE_MAX(512MB) constant to limit maximum heap expansion viabrk. This prevents unlimited heap growth.