Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3bb224b
Simplify memory arena page layout
tdecroyere Sep 4, 2026
4a59f74
Document memory arena contracts
tdecroyere Sep 5, 2026
4963500
Harden span contracts and const usage
tdecroyere Sep 5, 2026
e33cb7e
Fix duplicated string span length
tdecroyere Sep 5, 2026
dc95ea7
Add span and string buffer tests
tdecroyere Sep 5, 2026
7ad19b2
Include span tests in FoundationsTests
tdecroyere Sep 5, 2026
884051d
Fix bounded concurrent memory arena pushes
tdecroyere Sep 5, 2026
f908752
Add memory arena overflow regression tests
tdecroyere Sep 5, 2026
9f51444
Serialize memory arena page bookkeeping
tdecroyere Sep 5, 2026
3569935
Add concurrent commit regression coverage
tdecroyere Sep 5, 2026
029fba8
Finalize memory arena synchronization invariants
tdecroyere Sep 5, 2026
e5b2250
Write shader string terminators explicitly
tdecroyere Sep 5, 2026
39769f4
Report platform memory operation failures
tdecroyere Sep 5, 2026
4e5e5d8
Make Windows VM accounting thread-safe
tdecroyere Sep 5, 2026
12d5da1
Make POSIX VM accounting thread-safe
tdecroyere Sep 5, 2026
16f6580
Harden memory arena size and VM failure handling
tdecroyere Sep 5, 2026
b80f7e3
Add VM accounting and overflow regression tests
tdecroyere Sep 5, 2026
7e71549
Track committed bytes when freeing VM ranges
tdecroyere Sep 5, 2026
405715e
Account committed bytes on Windows VM release
tdecroyere Sep 5, 2026
5dee42f
Account committed bytes on POSIX VM release
tdecroyere Sep 5, 2026
b6f5139
Validate memory accounting after arena release
tdecroyere Sep 5, 2026
ffc7ad1
Run memory robustness regressions
tdecroyere Sep 5, 2026
c2c90bb
Track committed bytes when freeing arenas
tdecroyere Sep 5, 2026
550613f
Harden concurrent data pool allocation
tdecroyere Sep 5, 2026
82dcb04
Add concurrent data pool regressions
tdecroyere Sep 5, 2026
6753494
Run data pool robustness regressions
tdecroyere Sep 5, 2026
1169584
Harden dictionary concurrency
tdecroyere Sep 5, 2026
d4dbec0
Add dictionary robustness regressions
tdecroyere Sep 5, 2026
b7d9aeb
Run dictionary robustness regressions
tdecroyere Sep 5, 2026
d96df7b
Document data pool concurrency contract
tdecroyere Sep 5, 2026
40c9fd7
Document dictionary concurrency contract
tdecroyere Sep 5, 2026
a2c7556
Document memory commit failure contract
tdecroyere Sep 5, 2026
7dc6b32
Propagate memory commit failures
tdecroyere Sep 5, 2026
495afc1
Handle data pool commit failures
tdecroyere Sep 5, 2026
5636200
Handle dictionary commit failures
tdecroyere Sep 5, 2026
873f7cf
Test memory commit result contract
tdecroyere Sep 5, 2026
bb5073b
Fix commit result regression call
tdecroyere Sep 5, 2026
a585f8c
Document remaining SystemMemory helpers
tdecroyere Sep 6, 2026
748cde3
Separate memory concurrency tests
tdecroyere Sep 6, 2026
9ea9f88
Separate data pool concurrency tests
tdecroyere Sep 6, 2026
0342fab
Separate dictionary concurrency tests
tdecroyere Sep 6, 2026
f98e132
Keep memory tests focused on sequential behavior
tdecroyere Sep 6, 2026
6c9fba8
Keep data pool tests focused on sequential behavior
tdecroyere Sep 6, 2026
98ddbb2
Keep dictionary tests focused on sequential behavior
tdecroyere Sep 6, 2026
79d81c6
Organize Foundations tests by concurrency contract
tdecroyere Sep 6, 2026
6efb753
Remove obsolete memory robustness tests
tdecroyere Sep 6, 2026
edd4f18
Remove obsolete dictionary robustness tests
tdecroyere Sep 6, 2026
ead3758
Remove obsolete data pool robustness tests
tdecroyere Sep 6, 2026
82e0130
Document memory data structures
tdecroyere Sep 6, 2026
01d00ed
Add assertion messages to span tests
tdecroyere Sep 6, 2026
d3375e5
Add assertion messages to math tests
tdecroyere Sep 6, 2026
7beb84d
Add assertion messages to string tests
tdecroyere Sep 6, 2026
a69d13e
Add assertion messages to IO tests
tdecroyere Sep 6, 2026
9527cfd
Add assertion messages to process tests
tdecroyere Sep 6, 2026
ff83b68
Add assertion messages to data pool tests
tdecroyere Sep 6, 2026
4946045
Add assertion messages to concurrent data pool tests
tdecroyere Sep 6, 2026
702aa81
Add assertion messages to dictionary tests
tdecroyere Sep 6, 2026
a8981ca
Add assertion messages to concurrent dictionary tests
tdecroyere Sep 6, 2026
ac0bfbf
Add assertion messages to memory tests
tdecroyere Sep 6, 2026
9ec166f
Add assertion messages to concurrent memory tests
tdecroyere Sep 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ElementalTools/Shaders/ShaderCompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ void WriteShaderData(Span<uint8_t> data, uint32_t* currentOffset, ReadOnlySpan<c
{
auto dataSpan = ReadOnlySpan<uint8_t>((uint8_t*)value.Pointer, value.Length);
SystemCopyBuffer(data.Slice(*currentOffset), dataSpan);
*currentOffset += value.Length + 1;
*currentOffset += value.Length;
data[*currentOffset] = 0;
*currentOffset += 1;
}

template<typename T>
Expand Down Expand Up @@ -160,4 +162,4 @@ ReadOnlySpan<ShaderPart> ReadShaderParts(MemoryArena memoryArena, ReadOnlySpan<u
}

return shaderParts;
}
}
48 changes: 36 additions & 12 deletions src/Foundations/Microsoft/SystemPlatformFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,55 @@ size_t SystemPlatformGetPageSize()

SystemPlatformAllocationInfos SystemPlatformGetAllocationInfos()
{
return systemPlatformAllocationInfos;
SystemPlatformAllocationInfos result = {};
SystemAtomicLoad(systemPlatformAllocationInfos.CommittedBytes, result.CommittedBytes);
SystemAtomicLoad(systemPlatformAllocationInfos.ReservedBytes, result.ReservedBytes);
return result;
}

void* SystemPlatformReserveMemory(size_t sizeInBytes)
{
systemPlatformAllocationInfos.ReservedBytes += sizeInBytes;
return VirtualAlloc2(nullptr, nullptr, sizeInBytes, MEM_RESERVE, PAGE_NOACCESS, nullptr, 0);
auto result = VirtualAlloc2(nullptr, nullptr, sizeInBytes, MEM_RESERVE, PAGE_NOACCESS, nullptr, 0);

if (result != nullptr)
{
SystemAtomicAdd(systemPlatformAllocationInfos.ReservedBytes, sizeInBytes);
}

return result;
}

void SystemPlatformFreeMemory(void* pointer, size_t sizeInBytes)
void SystemPlatformFreeMemory(void* pointer, size_t sizeInBytes, size_t committedSizeInBytes)
{
systemPlatformAllocationInfos.ReservedBytes -= sizeInBytes;
VirtualFree(pointer, 0, MEM_RELEASE);
if (VirtualFree(pointer, 0, MEM_RELEASE))
{
SystemAtomicSubstract(systemPlatformAllocationInfos.ReservedBytes, sizeInBytes);
SystemAtomicSubstract(systemPlatformAllocationInfos.CommittedBytes, committedSizeInBytes);
}
}

void SystemPlatformCommitMemory(void* pointer, size_t sizeInBytes)
bool SystemPlatformCommitMemory(void* pointer, size_t sizeInBytes)
{
systemPlatformAllocationInfos.CommittedBytes += sizeInBytes;
VirtualAlloc2(nullptr, pointer, sizeInBytes, MEM_COMMIT, PAGE_READWRITE, nullptr, 0);
auto result = VirtualAlloc2(nullptr, pointer, sizeInBytes, MEM_COMMIT, PAGE_READWRITE, nullptr, 0);

if (result == nullptr)
{
return false;
}

SystemAtomicAdd(systemPlatformAllocationInfos.CommittedBytes, sizeInBytes);
return true;
}

void SystemPlatformDecommitMemory(void* pointer, size_t sizeInBytes)
bool SystemPlatformDecommitMemory(void* pointer, size_t sizeInBytes)
{
systemPlatformAllocationInfos.CommittedBytes -= sizeInBytes;
VirtualFree(pointer, sizeInBytes, MEM_DECOMMIT);
if (!VirtualFree(pointer, sizeInBytes, MEM_DECOMMIT))
{
return false;
}

SystemAtomicSubstract(systemPlatformAllocationInfos.CommittedBytes, sizeInBytes);
return true;
}

void SystemPlatformClearMemory(void* pointer, size_t sizeInBytes)
Expand Down
50 changes: 37 additions & 13 deletions src/Foundations/PosixPlatformFunctions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "SystemPlatformFunctions.h"
#include "SystemFunctions.h"

#ifdef ElemAPI
#include "SystemLogging.h"
Expand Down Expand Up @@ -76,31 +77,54 @@ size_t SystemPlatformGetPageSize()

SystemPlatformAllocationInfos SystemPlatformGetAllocationInfos()
{
return systemPlatformAllocationInfos;
SystemPlatformAllocationInfos result = {};
SystemAtomicLoad(systemPlatformAllocationInfos.CommittedBytes, result.CommittedBytes);
SystemAtomicLoad(systemPlatformAllocationInfos.ReservedBytes, result.ReservedBytes);
return result;
}

void* SystemPlatformReserveMemory(size_t sizeInBytes)
{
systemPlatformAllocationInfos.ReservedBytes += sizeInBytes;
return mmap(nullptr, sizeInBytes, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
auto result = mmap(nullptr, sizeInBytes, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);

if (result == MAP_FAILED)
{
return nullptr;
}

SystemAtomicAdd(systemPlatformAllocationInfos.ReservedBytes, sizeInBytes);
return result;
}

void SystemPlatformFreeMemory(void* pointer, size_t sizeInBytes)
void SystemPlatformFreeMemory(void* pointer, size_t sizeInBytes, size_t committedSizeInBytes)
{
systemPlatformAllocationInfos.ReservedBytes -= sizeInBytes;
munmap(pointer, sizeInBytes);
if (munmap(pointer, sizeInBytes) == 0)
{
SystemAtomicSubstract(systemPlatformAllocationInfos.ReservedBytes, sizeInBytes);
SystemAtomicSubstract(systemPlatformAllocationInfos.CommittedBytes, committedSizeInBytes);
}
}

void SystemPlatformCommitMemory(void* pointer, size_t sizeInBytes)
bool SystemPlatformCommitMemory(void* pointer, size_t sizeInBytes)
{
systemPlatformAllocationInfos.CommittedBytes += sizeInBytes;
mprotect(pointer, sizeInBytes, PROT_READ | PROT_WRITE);
if (mprotect(pointer, sizeInBytes, PROT_READ | PROT_WRITE) != 0)
{
return false;
}

SystemAtomicAdd(systemPlatformAllocationInfos.CommittedBytes, sizeInBytes);
return true;
}

void SystemPlatformDecommitMemory(void* pointer, size_t sizeInBytes)
bool SystemPlatformDecommitMemory(void* pointer, size_t sizeInBytes)
{
systemPlatformAllocationInfos.CommittedBytes -= sizeInBytes;
mprotect(pointer, sizeInBytes, PROT_NONE);
if (mprotect(pointer, sizeInBytes, PROT_NONE) != 0)
{
return false;
}

SystemAtomicSubstract(systemPlatformAllocationInfos.CommittedBytes, sizeInBytes);
return true;
}

void SystemPlatformClearMemory(void* pointer, size_t sizeInBytes)
Expand Down Expand Up @@ -144,7 +168,7 @@ void SystemPlatformFileWriteBytes(ReadOnlySpan<char> path, ReadOnlySpan<uint8_t>

if (write(fileHandle, data.Pointer, data.Length) < 0)
{
SystemLogErrorMessage(ElemLogMessageCategory_Application, "Error writing to file %s.", path.Pointer);
SystemLogErrorMessage(ElemLogMessageCategory_Application, "Error writing file %s.", path.Pointer);
}

close(fileHandle);
Expand Down
Loading
Loading