Repository navigation
Add mmap allocator + pure-Silver memory intrinsics (Wave 1 unit 2) - #7
Merged
Merged
Conversation
Rewrite std/mem/alloc.ag over sys_mmap/sys_munmap with a page-aligned free-list, add std/mem/memory.ag (memset/memcpy/memmove/strlen), and export the frozen silver_rt_alloc* / silver_rt_mem* ABI surface. Internal alloc<T>() signature is unchanged so Vec/String/Box stay stable. Co-Authored-By: Claude Fable 5 <[email protected]>
…oc overflow guard
…ling sentinel cap
CierCier
added a commit
that referenced
this pull request
Aug 1, 2026
Add mmap allocator + pure-Silver memory intrinsics (Wave 1 unit 2)
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.
Summary
Wave 1 unit 2 of
docs/runtime-migration.md.std/mem/alloc.ag— page-aligned free-list allocator oversys_mmap/sys_munmapstd/mem/memory.ag— pure-Silvermemset/memcpy/memmove/strlensilver_rt_alloc,silver_rt_alloc_zeroed,silver_rt_realloc,silver_rt_dealloc,silver_rt_memset,silver_rt_memcpy,silver_rt_memmove,silver_rt_strlen(size-0 → dangling non-null; null-tolerant dealloc)alloc<T>()generic API signature unchangedtests/mem_test.ag— 49 cases covering free-list reuse, huge allocs, ABI edge cases, arena alignmentTest plan
agc tests/mem_test.ag→ 49/49 PASSagc tests/memory_pentest.ag→ 16/16 PASSGreptile Summary
This wave adds a pure-Silver, libc-free allocator (
std/mem/alloc.ag) built onsys_mmap/sys_munmap, and pure-Silver memory intrinsics (std/mem/memory.ag). The allocation surface (silver_rt_alloc,silver_rt_alloc_zeroed,silver_rt_realloc,silver_rt_dealloc) plus libc-compatible shims (malloc,calloc,realloc,free,memset,memcpy,memmove,strlen) replace the formerextern \"C\"stubs.std/mem/alloc.ag: page-aligned free-list allocator with 9 size classes (16\u20134096 bytes), dedicatedmmapfor huge/over-aligned allocations, and a lazily-initialized single-page head table. Themem_danglingcap atMEM_MIN_VALID_ADDRresolves the prior dangling-pointer detection issues from earlier review threads.std/mem/memory.ag: plain byte-loop implementations ofmemset,memcpy,memmove, andstrlen; all null-tolerant;memmovedirection logic is correct for both overlap directions.tests/mem_test.ag: 49 new cases covering zeroed-block recycling, free-list reuse, huge-alloc realloc, frozen ABI edge cases, and the aligned zero-sized free regression.Confidence Score: 5/5
The allocator and intrinsic logic is correct; the prior dangling-pointer and calloc-overflow issues are resolved. Both findings are cosmetic.
The core allocation, free, and realloc paths have been traced through all tag combinations and the arithmetic checks out. The mem_dangling cap correctly keeps all sentinels below MEM_MIN_VALID_ADDR, mem_free_impl safely ignores them, huge-block offset encoding and recovery are symmetric, and the memmove direction logic is sound. The only findings are a stale doc comment on mem_dangling and three redundant extern C declarations that were not cleaned up alongside malloc/calloc/free/realloc.
The two findings are both in std/mem/alloc.ag: the mem_dangling doc comment and the leftover extern C block for memset/memcpy/memmove.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["silver_rt_alloc(size, align)"] --> B{size <= 0?} B -- yes --> C["mem_dangling: return ptr in 0..32MiB"] B -- no --> D{align<=16 AND size<=4096?} D -- yes --> E["size-class path: idx=ceil-log2(size/16)"] E --> F{heads-idx empty?} F -- yes --> G["mem_refill: mmap 64KiB chunk, carve blocks"] G --> H["pop head block from free list"] F -- no --> H D -- no --> I["huge path: mmap page-rounded(size+16+align)"] I --> J["place header at aligned offset, tag=-1-offset"] H --> K["return user ptr"] J --> K L["mem_free_impl(ptr)"] --> M{ptr < 32MiB?} M -- yes --> N["no-op: null or dangling sentinel"] M -- no --> O{tag in 0..8?} O -- yes --> P["push to free-list heads-tag"] O -- no --> Q{tag < 0?} Q -- yes --> R["munmap base, huge block released"] Q -- no --> S["unknown tag: defensive no-op"]%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A["silver_rt_alloc(size, align)"] --> B{size <= 0?} B -- yes --> C["mem_dangling: return ptr in 0..32MiB"] B -- no --> D{align<=16 AND size<=4096?} D -- yes --> E["size-class path: idx=ceil-log2(size/16)"] E --> F{heads-idx empty?} F -- yes --> G["mem_refill: mmap 64KiB chunk, carve blocks"] G --> H["pop head block from free list"] F -- no --> H D -- no --> I["huge path: mmap page-rounded(size+16+align)"] I --> J["place header at aligned offset, tag=-1-offset"] H --> K["return user ptr"] J --> K L["mem_free_impl(ptr)"] --> M{ptr < 32MiB?} M -- yes --> N["no-op: null or dangling sentinel"] M -- no --> O{tag in 0..8?} O -- yes --> P["push to free-list heads-tag"] O -- no --> Q{tag < 0?} Q -- yes --> R["munmap base, huge block released"] Q -- no --> S["unknown tag: defensive no-op"]Reviews (3): Last reviewed commit: "Merge origin/main into std/mmap-allocato..." | Re-trigger Greptile