From d536252843ee1f25a1f25547aad7bb7d814074b1 Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 29 Nov 2026 19:49:36 +0000 Subject: [PATCH 1/5] Initial commit with task details Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: https://github.com/linksplatform/Memory/issues/92 --- .gitkeep | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitkeep diff --git a/.gitkeep b/.gitkeep new file mode 100644 index 0000000..fc05b66 --- /dev/null +++ b/.gitkeep @@ -0,0 +1 @@ +# .gitkeep file auto-generated at 2026-11-29T19:49:36.520Z for PR creation at branch issue-92-c5422c79f44a for issue https://github.com/linksplatform/Memory/issues/92 \ No newline at end of file From 996fe2631871fb456c8cb041a55be998027bbc78 Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 29 Nov 2026 19:57:15 +0000 Subject: [PATCH 2/5] Free C++ heap memory with the matching allocator Initialize the default reservation directly from the system page size so the existing growth test can run with Clang sanitizers. --- cpp/Platform.Memory/HeapResizableDirectMemory.h | 4 ++-- cpp/Platform.Memory/Platform.Memory.h | 1 + cpp/Platform.Memory/ResizableDirectMemoryBase.h | 6 ++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/cpp/Platform.Memory/HeapResizableDirectMemory.h b/cpp/Platform.Memory/HeapResizableDirectMemory.h index 96d28ff..abd0f34 100644 --- a/cpp/Platform.Memory/HeapResizableDirectMemory.h +++ b/cpp/Platform.Memory/HeapResizableDirectMemory.h @@ -62,7 +62,7 @@ public: ~HeapResizableDirectMemory() final { - delete static_cast(Pointer()); + std::free(Pointer()); } }; -} \ No newline at end of file +} diff --git a/cpp/Platform.Memory/Platform.Memory.h b/cpp/Platform.Memory/Platform.Memory.h index f91f188..d2610f7 100644 --- a/cpp/Platform.Memory/Platform.Memory.h +++ b/cpp/Platform.Memory/Platform.Memory.h @@ -6,6 +6,7 @@ #include #include #endif +#include #include #include #include diff --git a/cpp/Platform.Memory/ResizableDirectMemoryBase.h b/cpp/Platform.Memory/ResizableDirectMemoryBase.h index d2ddbec..8211e1b 100644 --- a/cpp/Platform.Memory/ResizableDirectMemoryBase.h +++ b/cpp/Platform.Memory/ResizableDirectMemoryBase.h @@ -2,7 +2,7 @@ { namespace Internal { - std::size_t page_size() noexcept + inline std::size_t page_size() noexcept { std::size_t page_size; #if defined(WIN32) @@ -16,8 +16,6 @@ #endif return page_size; } - - auto PageSize = page_size(); } class ResizableDirectMemoryBase : public IResizableDirectMemory @@ -25,7 +23,7 @@ protected: using IResizableDirectMemory::pointer_t; protected: using IResizableDirectMemory::capacity_t; - public: inline static const std::size_t MinimumCapacity = Internal::PageSize; + public: inline static const std::size_t MinimumCapacity = Internal::page_size(); private: pointer_t _pointer = nullptr; private: capacity_t _reservedCapacity = 0; From f22fc6d2c5088385f2e0e37c84ba954fa70538c6 Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 29 Nov 2026 19:57:15 +0000 Subject: [PATCH 3/5] Run the C++ heap regression under ASan and UBSan --- .github/workflows/cpp-sanitizers.yml | 38 +++++++++++++++++++ .github/workflows/cpp-test.yml | 28 +++++++------- cpp/CMakeLists.txt | 2 + .../HeapResizableDirectMemoryTests.cpp | 9 +++++ 4 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/cpp-sanitizers.yml diff --git a/.github/workflows/cpp-sanitizers.yml b/.github/workflows/cpp-sanitizers.yml new file mode 100644 index 0000000..c0f6b94 --- /dev/null +++ b/.github/workflows/cpp-sanitizers.yml @@ -0,0 +1,38 @@ +name: C++ sanitizers + +on: + workflow_call: + +permissions: + contents: read + +jobs: + sanitizers: + runs-on: ubuntu-latest + timeout-minutes: 15 + defaults: + run: + working-directory: cpp + env: + CC: clang + CXX: clang++ + steps: + - uses: actions/checkout@v4 + - name: Install C++ dependencies + run: | + pipx install conan + conan profile detect + sed -i 's/^compiler.cppstd=.*/compiler.cppstd=20/' "$(conan profile path default)" + bash ./install-local-conan-dependencies.sh + - name: Build tests with ASan and UBSan + run: | + cmake -S . -B build-sanitizers -DCMAKE_TOOLCHAIN_FILE="$PWD/conan_toolchain.cmake" \ + -DCMAKE_BUILD_TYPE=Release -DLINKS_PLATFORM_TESTS=ON \ + -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \ + -DCMAKE_CXX_FLAGS_RELEASE="-O0 -gline-tables-only" + cmake --build build-sanitizers --target Platform.Memory.Tests --parallel 1 + - name: Run sanitizer tests + env: + ASAN_OPTIONS: alloc_dealloc_mismatch=1:detect_leaks=1 + UBSAN_OPTIONS: halt_on_error=1:print_stacktrace=1 + run: ctest --test-dir build-sanitizers --output-on-failure --no-tests=error diff --git a/.github/workflows/cpp-test.yml b/.github/workflows/cpp-test.yml index fc4d56b..3982919 100644 --- a/.github/workflows/cpp-test.yml +++ b/.github/workflows/cpp-test.yml @@ -2,24 +2,22 @@ name: Test cpp on: push: - branches: - - 'main' + branches: [main] paths: - - 'cpp/**.h' - - 'cpp/**.cpp' - - 'cpp/CMakeLists.txt' - - 'cpp/conanfile.txt' + - 'cpp/**' + - '.github/workflows/cpp-test.yml' + - '.github/workflows/cpp-sanitizers.yml' pull_request: - types: - - edited - branches: - - 'main' + types: [opened, edited, synchronize, reopened] + branches: [main] paths: - - 'cpp/**.h' - - 'cpp/**.cpp' - - 'cpp/CMakeLists.txt' - - 'cpp/conanfile.txt' - + - 'cpp/**' + - '.github/workflows/cpp-test.yml' + - '.github/workflows/cpp-sanitizers.yml' + - '.github/workflows/deploy-cpp.yml' + jobs: main: uses: linksplatform/Workflows/.github/workflows/cpp-test.yml@main + sanitizers: + uses: ./.github/workflows/cpp-sanitizers.yml diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 956a0a5..9f0a8ef 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -16,11 +16,13 @@ target_link_libraries(${PROJECT_NAME}.Library INTERFACE Platform.Collections::Pl target_link_libraries(${PROJECT_NAME}.Library INTERFACE mio::mio) if(${LINKS_PLATFORM_TESTS}) + enable_testing() add_executable(${PROJECT_NAME}.Tests ${PROJECT_NAME}.Tests/AllTests.cpp) set_target_properties(${PROJECT_NAME}.Tests PROPERTIES CXX_STANDARD 20) target_link_libraries(${PROJECT_NAME}.Tests PRIVATE GTest::gtest) target_link_libraries(${PROJECT_NAME}.Tests PRIVATE GTest::gtest_main) target_link_libraries(${PROJECT_NAME}.Tests PRIVATE ${PROJECT_NAME}.Library) + add_test(NAME ${PROJECT_NAME}.Tests COMMAND ${PROJECT_NAME}.Tests) add_executable(MappedFileFixture ../examples/mapped-file-interop/fixture.cpp) set_target_properties(MappedFileFixture PROPERTIES CXX_STANDARD 20) diff --git a/cpp/Platform.Memory.Tests/HeapResizableDirectMemoryTests.cpp b/cpp/Platform.Memory.Tests/HeapResizableDirectMemoryTests.cpp index 2b34ca8..9aa02e0 100644 --- a/cpp/Platform.Memory.Tests/HeapResizableDirectMemoryTests.cpp +++ b/cpp/Platform.Memory.Tests/HeapResizableDirectMemoryTests.cpp @@ -12,9 +12,18 @@ return *((std::byte*)pointer1 + heapMemory.ReservedCapacity() - 1); } + TEST(HeapResizableDirectMemory, DestroysAllocatedMemory) + { + HeapResizableDirectMemory heapMemory{4096}; + heapMemory.UsedCapacity(1); + *static_cast(heapMemory.Pointer()) = std::byte{42}; + } + TEST(HeapResizableDirectMemory, CorrectMemoryReallocation) { auto heapMemory = HeapResizableDirectMemory(); + ASSERT_GT(heapMemory.ReservedCapacity(), 0u); + ASSERT_NE(heapMemory.Pointer(), nullptr); auto value1 = GetLastByte(heapMemory); heapMemory.ReservedCapacity(heapMemory.ReservedCapacity() * 2); auto value2 = GetLastByteByCopy(heapMemory); From b4964cff1531775b1d23a204e0e3ca206d8bdbb3 Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 29 Nov 2026 19:57:15 +0000 Subject: [PATCH 4/5] Prepare the C++ 0.1.1 release --- .github/workflows/deploy-cpp.yml | 7 ++++++- cpp/Platform.Memory/Platform.Memory.TemplateLibrary.nuspec | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-cpp.yml b/.github/workflows/deploy-cpp.yml index 9304934..e6960f4 100644 --- a/.github/workflows/deploy-cpp.yml +++ b/.github/workflows/deploy-cpp.yml @@ -8,9 +8,14 @@ on: workflow_dispatch: jobs: + sanitizers: + uses: ./.github/workflows/cpp-sanitizers.yml main: + needs: sanitizers + permissions: + contents: write uses: linksplatform/Workflows/.github/workflows/deploy-cpp.yml@main with: - recipe_folder: "platform.delegates" + recipe_folder: "platform.memory" secrets: NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }} diff --git a/cpp/Platform.Memory/Platform.Memory.TemplateLibrary.nuspec b/cpp/Platform.Memory/Platform.Memory.TemplateLibrary.nuspec index 4a061fc..841b5af 100644 --- a/cpp/Platform.Memory/Platform.Memory.TemplateLibrary.nuspec +++ b/cpp/Platform.Memory/Platform.Memory.TemplateLibrary.nuspec @@ -5,8 +5,8 @@ LinksPlatform's Platform.Memory Template Library LinksPlatform's Platform.Memory is a Template Library what contains crossplatform class API for memory mapping. LinksPlatform's Platform.Memory is a Template Library what contains crossplatform class API for memory mapping. Use Platform.Memory.h file to include the library. - Initial realise - 0.1.0 + Free heap memory with the allocator that reserved it. + 0.1.1 konard konard konard From 883ef478f67ce777de3f73b3475b7b7f7c16c840 Mon Sep 17 00:00:00 2001 From: konard Date: Sun, 29 Nov 2026 19:59:44 +0000 Subject: [PATCH 5/5] Remove the pull request placeholder --- .gitkeep | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .gitkeep diff --git a/.gitkeep b/.gitkeep deleted file mode 100644 index fc05b66..0000000 --- a/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -# .gitkeep file auto-generated at 2026-11-29T19:49:36.520Z for PR creation at branch issue-92-c5422c79f44a for issue https://github.com/linksplatform/Memory/issues/92 \ No newline at end of file