Harden Foundations memory and concurrency contracts - #116
Open
tdecroyere wants to merge 93 commits into
Open
Conversation
tdecroyere
force-pushed
the
refactor/memory-pop-cleanup
branch
from
September 4, 2026 20:13
abe5a63 to
7eca504
Compare
tdecroyere
force-pushed
the
refactor/memory-pop-cleanup
branch
from
September 4, 2026 20:48
d027210 to
3bb224b
Compare
tdecroyere
marked this pull request as ready for review
September 10, 2026 08:07
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.
Goal
Harden the low-level Foundations runtime around explicit memory, lifetime, and concurrency contracts. This keeps the existing arena/stack design intact while fixing correctness bugs that could otherwise lead to out-of-bounds allocations, races, stale handles, corrupted free lists, or unsafe access to uncommitted memory.
MemoryArena
SystemPopMemoryand keep rollback internal to the stack-memory implementation;SystemClearMemoryArena/SystemFreeMemoryArenaas explicit exclusive lifetime operations;SystemBeginStackMemoryArena()/SystemEndStackMemoryArena()operate on a plainStackMemoryArenaScopetoken with no automatic language-level lifetime behavior;SystemGetStackMemoryArena()/StackMemoryArena::~StackMemoryArena()as the C++ convenience layer over the explicit begin/end primitives;SystemReleaseThreadMemory()so language runtimes/wrappers can explicitly release the current thread's lazily-created stack-memory backing once no scopes remain active;SystemReleaseThreadMemory();StackExtraStoragecapacity checks to use the actual working arena;PageInfo, committed-state bits, or page counts;SystemCommitMemoryreport success/failure and prevent committed pushes from returning a pointer when the platform commit fails;SystemClearMemoryArenadirectly decommit committed data pages and reset all page tracking instead of relying on conservative range bookkeeping;alignof(T)while keeping raw byte pushes on the Foundations default alignment;PROT_NONEmappings so physical backing is released while the virtual address range remains reserved;DataPool
T/TFullstorage as raw-storage-compatible data only: DataPool does not construct, destroy, retain, release, or otherwise manage language-level object lifetime;Dictionary
ReadOnlySpan<T>hashing soLengthis converted to bytes withsizeof(T);SystemGetDictionaryValuereturnnullptras documented while preserving the zero-valueoperator[]convenience;Span and string buffers
Span/ReadOnlySpanlightweight, non-owning pointer-and-length views;Lengthas logical characters excluding the null terminator;SystemDuplicateBuffer<char>to preserve that logical length;SystemDuplicateBuffer<wchar_t>follow the same null-terminated backing-storage convention;Regression coverage
Adds focused tests for:
alignof(T)allocation after a deliberately misaligned bump position;StackExtraStorageancestor allocations;StackExtraStoragebacking;Intentional follow-ups outside the final SystemMemory review: replace C++ lifetime-owning payloads such as DX12
ComPtrvalues stored in Foundations raw containers with raw handles/pointers, and harden the platform-specific descriptor/query free lists in the graphics backends.