Add sbrk syscall and heap management from ch4 address space design#169
Draft
Add sbrk syscall and heap management from ch4 address space design#169
Conversation
Agent-Logs-Url: https://github.com/rcore-os/rCore-Tutorial-v3/sessions/fb1af46c-2914-42a7-a1f3-18095776466e Co-authored-by: chyyuu <2077445+chyyuu@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Analyze user space application address space layout in ch4 branch
Add sbrk syscall and heap management from ch4 address space design
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ch4 branch's user-mode address space layout includes dynamic heap management via
sbrk, but the main branch was missing the entire heap infrastructure. This adds it.User address space layout (ch4 design)
The heap starts at
ustack_base + USER_STACK_SIZE, initialized as an emptyMapArea, and grows/shrinks viasbrk.Kernel changes
mm/memory_set.rs: Addshrink_to/append_toon bothMemorySetandMapAreato support page-granular heap resizetask/process.rs: Addheap_bottom+program_brktoProcessControlBlockInner; addchange_program_brk()method; initialize empty heapMapAreainnew()andexec(), copy fields infork()task/mod.rs: Exposechange_program_brk(size: i32) -> Option<usize>as a public APIsyscall/mod.rs: AddSYSCALL_SBRK = 214and dispatch tosys_sbrksyscall/process.rs: Implementsys_sbrkUser-space changes
user/src/syscall.rs: AddSYSCALL_SBRK+sys_sbrkuser/src/task.rs: Addsbrk(size: i32) -> isizewrapperuser/src/bin/sbrk_test.rs: Add test covering allocate, write, bulk grow, bulk shrink, and underflow guardWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/repos/rcore-os/riscv/commits/HEAD/home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo build(http block)/home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo build --release rustc /lib64/ld-linux-x86-64.so.2 -pie -z ib.rs -fuse-ld=lld -z relro -o n-li�� n-linux-gnu/lib/OUTPUT debug/build/os-5-d debug/build/os-5168.63.129.16 debug/build/os-5/home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/lib/--edition=2015 debug/build/os-5-plugin debug/build/os-5/usr/libexec/gcc/x86_64-linux-gnu/13/liblto_plugin.so debug/build/os-5-plugin-opt=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper(http block)https://api.github.com/repos/rcore-os/virtio-drivers/commits/4ee80e5/home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo build(http block)https://api.github.com/repos/yfblock/lose-net-stack/commits/db42380/home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo /home/REDACTED/.rustup/toolchains/nightly-2025-02-18-x86_64-REDACTED-linux-gnu/bin/cargo build(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.