feat(libc): export the error_category members and std::future_error #11241

Merged
edubox merged 2 commits from upstream-pr/11241 into main 2026-10-26 22:04:50 +00:00
edubox commented 2026-10-25 22:28:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-10-25T22:28:40Z.


What

Export the std::error_category base members that titles import: the 16-byte _ZTISt14error_category class type info, ~error_category, default_error_condition(int) and both equivalent overloads. They call the same code the generic and system category vtables already use, so a title's error_code maps and compares as the console's libc does. The console keeps the value in the second dword; the test pins nonzero reserved padding in both overloads.

Implement std::future_category and std::future_error from the same libc.prx. _Future_error_category derives from _Generic_error_category, is named future, and its messages for 1..4 are broken promise, future already retrieved, promise already satisfied and no state; other values fall back to the generic table, while future_error::what() returns a null pointer for them as the console helper does. future_error is 0x40 bytes (vtable, GuestLocale::String at 0x8, 16-byte error_code at 0x30), its vtable is 0x30 bytes with a _Doraise slot, and _Throw_future_error allocates that size and throws with the console type info. _Rethrow_future_exception delegates to rethrow_exception.

Evidence: disassembled the libc.prx bundled in PPSA02530's sce_module. The base members are at 0x161a0, 0x161c0, 0x161e0 and 0x16210; the type infos and vtables at 0x18c818, 0x18f470, 0x18f488, 0x18f4b8 and 0x18f500; the future category and future_error at 0xb7540, 0xb7590, 0xb7680, 0xb7390, 0xb74a0, 0xb7760, 0xb7850 and 0xb7860. The debt entry records the differences (the static future category's deleting destructor throws instead of freeing it, and the string destructor frees the block directly).

Tested

  • ctest -R '^(guest_generic_category|guest_future_category|guest_ampr_cpp_error)$' (Linux, CachyOS, GCC 16.2.1): 3/3 pass. The new guest_future_category pins the base type info name and size, nonzero padding in both equivalent overloads, default_error_condition, the future category name/messages/fallback, the future_error size/offsets/vtable, the thrown type and what() for 1..4 (and null outside), and the destructor.
  • nm -D -S on the patched libc.prx: the new NIDs are exported with the console sizes (cbvW20xPgyc 0x10, 3aZN32UTqqk 0x18, DCY9coLQcVI 0x18, 6-LMlTS1nno 0x30, YHfG3-K23CY 0x48).
  • python3 tools/check_conventions.py --base origin/main: pass.
  • python3 tools/pr_overlap.py --branch feat/libc-future-category --jobs 32: no overlapping exports. The PRs whose shared files could not be compared touch only CMakeLists.txt, Api.hpp or the debt file, not StandardExceptions.cpp.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none (removes 11 of the libc imports PPSA05510 needs; further imports remain)
  • GPUs tested: n/a (libc categories and exception layout only)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009356071 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11241). Originally posted by [edubox](https://github.com/edubox) on 2026-10-25T22:28:40Z. --- ### What Export the `std::error_category` base members that titles import: the 16-byte `_ZTISt14error_category` class type info, `~error_category`, `default_error_condition(int)` and both `equivalent` overloads. They call the same code the generic and system category vtables already use, so a title's `error_code` maps and compares as the console's libc does. The console keeps the value in the second dword; the test pins nonzero `reserved` padding in both overloads. Implement `std::future_category` and `std::future_error` from the same `libc.prx`. `_Future_error_category` derives from `_Generic_error_category`, is named `future`, and its messages for 1..4 are `broken promise`, `future already retrieved`, `promise already satisfied` and `no state`; other values fall back to the generic table, while `future_error::what()` returns a null pointer for them as the console helper does. `future_error` is 0x40 bytes (vtable, `GuestLocale::String` at 0x8, 16-byte `error_code` at 0x30), its vtable is 0x30 bytes with a `_Doraise` slot, and `_Throw_future_error` allocates that size and throws with the console type info. `_Rethrow_future_exception` delegates to `rethrow_exception`. Evidence: disassembled the `libc.prx` bundled in PPSA02530's `sce_module`. The base members are at `0x161a0`, `0x161c0`, `0x161e0` and `0x16210`; the type infos and vtables at `0x18c818`, `0x18f470`, `0x18f488`, `0x18f4b8` and `0x18f500`; the future category and `future_error` at `0xb7540`, `0xb7590`, `0xb7680`, `0xb7390`, `0xb74a0`, `0xb7760`, `0xb7850` and `0xb7860`. The debt entry records the differences (the static future category's deleting destructor throws instead of freeing it, and the string destructor frees the block directly). ### Tested - `ctest -R '^(guest_generic_category|guest_future_category|guest_ampr_cpp_error)$'` (Linux, CachyOS, GCC 16.2.1): 3/3 pass. The new `guest_future_category` pins the base type info name and size, nonzero padding in both `equivalent` overloads, `default_error_condition`, the future category name/messages/fallback, the `future_error` size/offsets/vtable, the thrown type and `what()` for 1..4 (and null outside), and the destructor. - `nm -D -S` on the patched `libc.prx`: the new NIDs are exported with the console sizes (`cbvW20xPgyc` 0x10, `3aZN32UTqqk` 0x18, `DCY9coLQcVI` 0x18, `6-LMlTS1nno` 0x30, `YHfG3-K23CY` 0x48). - `python3 tools/check_conventions.py --base origin/main`: pass. - `python3 tools/pr_overlap.py --branch feat/libc-future-category --jobs 32`: no overlapping exports. The PRs whose shared files could not be compared touch only `CMakeLists.txt`, `Api.hpp` or the debt file, not `StandardExceptions.cpp`. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none (removes 11 of the libc imports PPSA05510 needs; further imports remain) - [x] GPUs tested: n/a (libc categories and exception layout only) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 22:34:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:34:53Z.

Review: APPROVED


I reviewed the complete diff and the new guest test. The class-type-info record, base error_category vtable slots, future-category inheritance, and 0x40-byte future_error object layout are internally consistent with the ABI layouts claimed in the PR. The implementation keeps category comparison on the existing generic/system helpers, handles inline versus allocated GuestLocale strings, and copies heap-backed messages before throwing. The regression covers nonzero reserved fields, category identity, all four future messages, generic fallback, thrown type/what(), and the future_error destructor.

git diff --check and python3 tools/check_conventions.py --base upstream/main --head refs/remotes/upstream/pr/11241 pass. The author reports the three focused Linux guest tests passing 3/3; I did not rerun the libc product test locally because the available build-review configuration is relinker-only. Hosted eligibility, intake, labels, report, Ubuntu register-context and ASan pass; Windows/macOS relinker and macOS register-context jobs are still pending, while product builds are skipped by policy. No concrete defect found in this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645699219 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11241#pullrequestreview-5645699219). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:34:53Z. **Review:** APPROVED --- I reviewed the complete diff and the new guest test. The class-type-info record, base error_category vtable slots, future-category inheritance, and 0x40-byte future_error object layout are internally consistent with the ABI layouts claimed in the PR. The implementation keeps category comparison on the existing generic/system helpers, handles inline versus allocated GuestLocale strings, and copies heap-backed messages before throwing. The regression covers nonzero reserved fields, category identity, all four future messages, generic fallback, thrown type/what(), and the future_error destructor. `git diff --check` and `python3 tools/check_conventions.py --base upstream/main --head refs/remotes/upstream/pr/11241` pass. The author reports the three focused Linux guest tests passing 3/3; I did not rerun the libc product test locally because the available `build-review` configuration is relinker-only. Hosted eligibility, intake, labels, report, Ubuntu register-context and ASan pass; Windows/macOS relinker and macOS register-context jobs are still pending, while product builds are skipped by policy. No concrete defect found in this review.
thepoppfish commented 2026-10-25 23:12:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T23:12:22Z.

Review: CHANGES_REQUESTED


Found one allocation-failure cleanup issue at exact head e859215335e34c1fd566130ab0c36223864ec064.

future_error's _Doraise vtable entry first allocates an exception block with __cxa_allocate_exception_nid_postfix, then CopyFutureError allocates again through guest operator new when the source message is heap-backed (capacity > 15). If that second allocation fails, std::bad_alloc escapes before __cxa_throw_nid_postfix receives ownership. The first block is never released. This affects the heap-backed-message copy path, not every _Throw_future_error call (that helper creates an empty inline message).

I reproduced this on native Windows with the complete production Runtime.cpp, StandardExceptions.cpp, StdioExtras.cpp and ApplicationHeap.cpp. The registered guest allocator returns null at the copy allocation, so the real application-heap/new code produces the failure. Runtime malloc/free calls are redirected to observing wrappers that use normal host malloc/free. The actual exception allocation/free bodies are retained. A capture adapter replaces the final throw handoff for successful-copy controls; the failing-copy cases never reach that adapter. This is allocation-ownership validation, not full guest unwinding/RTTI-catch validation.

Results with GCC 16.2.0-6 UCRT, C++20, -O1 -g -fno-inline -flto, static C++ runtime:

Variant Matrix cases Checks Failed checks / unreclaimed-block cases
Published head 80 3310 25 / 25
Cleanup patch 80 3310 0 / 0

The matrix crosses message lengths 0, 1, 15, 16, 24, 31, 47 and 95, codes 1..4/99, and normal/failing guest allocation. Each of the 25 failing heap-copy cases at the head has one exception allocation and zero frees before the probe manually cleans it up. With the patch, the original bad_alloc propagates and the block is freed exactly once. All successful copies retain vtable/code fields and separate heap storage; all source-object bytes and message bytes stay intact, and source destruction still frees the original allocation. The head log's final live count is zero because the probe cleans up after recording each leak, not because the head frees it.

Reviewable repair: ee91bab13f84, branch codex/review-future-error-copy-cleanup. The commit changes one production file, 6 insertions/1 deletion. Its parent is a clean local merge of this PR with current-main snapshot 49d1f9b07ec7f6f989ace1c504bbe9dd6748dcbb; all 133 libc files were identical to this PR before applying the patch. The committed candidate's actual source was then rebuilt and passed the full 80-case fixture (CTest 1/1, 0 skipped, 0.12 s). Conventions against that pinned origin/main and whitespace checks pass; the candidate checkout is clean. This is a support commit for cherry-picking, not another PR or an imposed merge order.

Please free only the raw exception allocation if copying throws, then rethrow. Calling the future-error destructor on that partially copied object would risk freeing the source's aliased string pointer.

--- a/core/libs/prx/libc/src/exception/StandardExceptions.cpp
+++ b/core/libs/prx/libc/src/exception/StandardExceptions.cpp
@@ -718,7 +718,12 @@
 }
 [[noreturn]] static void APS5_VABI RaiseFutureError_nid_no_patch(const LibcException::FutureErrorObject* self) {
     auto* object = static_cast<LibcException::FutureErrorObject*>(__cxa_allocate_exception_nid_postfix(sizeof(LibcException::FutureErrorObject)));
-    CopyFutureError(object, self);
+    try {
+        CopyFutureError(object, self);
+    } catch (...) {
+        __cxa_free_exception_nid_postfix(object);
+        throw;
+    }
     __cxa_throw_nid_postfix(object, reinterpret_cast<std::type_info*>(&_ZTISt12future_error_nid_postfix),
         reinterpret_cast<decltype(LibcException::Header::destructor)>(DestroyFutureError_nid_no_patch));
 }

I did not run the full libc/product build, the committed three guest-category tests, Linux/macOS, console/title execution, or a canonical PR-overlap scan. The successful-control adapter does not establish the guest unwinder or catch ABI. AI-assisted implementation and replay: Codex.

Complete fault-injection replay (four production sources, five fixture files)

Check out the exact PR head and support commit separately. Save the five files below in another directory, set REPO to the PR-head checkout and FIXED_SOURCE to the support checkout's core/libs/prx/libc/src/exception/StandardExceptions.cpp, and build with GCC/MinGW on Windows:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DREPO="C:/path/to/head-checkout" -DFIXED_SOURCE="C:/path/to/support-checkout/core/libs/prx/libc/src/exception/StandardExceptions.cpp"
cmake --build build -j 3
ctest --test-dir build -V

Run build/head_probe.exe for the negative control: exit 1 with 25 failed checks/leak cases. build/fixed_probe.exe exits 0 with 0 failures/leaks. CTest registers only the fixed version. Production.cpp keeps Runtime before StandardExceptions as in the library's exception/Exports.cpp; it replaces only the allocator observation and final throw boundary, while omitting the full product's exception-export aliases. The typed vtable accessors avoid declaring the vtable with a conflicting type. Uncalled default-heap paths fail loudly if reached. The objcopy step follows the project's Windows unwind-section handling for exceptions crossing the guest ABI.

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(FutureCopyReview LANGUAGES CXX)
get_filename_component(DEFAULT_REPO "${CMAKE_CURRENT_LIST_DIR}/../review-11241" ABSOLUTE)
set(REPO "${DEFAULT_REPO}" CACHE PATH "Exact reviewed checkout")
set(SRC "${REPO}/core/libs/prx/libc/src")
set(FIXED_SOURCE "${CMAKE_CURRENT_LIST_DIR}/FixedStandardExceptions.cpp" CACHE FILEPATH "Candidate production source")
enable_testing()
add_library(common OBJECT "${SRC}/StdioExtras.cpp" "${SRC}/ApplicationHeap.cpp" Support.cpp)
foreach(target IN ITEMS common)
    target_compile_features(${target} PRIVATE cxx_std_20)
    target_include_directories(${target} PRIVATE "${REPO}/core/libs")
    target_compile_options(${target} PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections)
endforeach()
foreach(variant IN ITEMS head fixed)
    if(variant STREQUAL head)
        set(standard "${SRC}/exception/StandardExceptions.cpp")
    else()
        set(standard "${FIXED_SOURCE}")
    endif()
    add_executable(${variant}_probe Probe.cpp Production.cpp $<TARGET_OBJECTS:common>)
    target_compile_definitions(${variant}_probe PRIVATE RUNTIME_SOURCE="${SRC}/exception/Runtime.cpp" STANDARD_SOURCE="${standard}")
    target_compile_features(${variant}_probe PRIVATE cxx_std_20)
    target_include_directories(${variant}_probe PRIVATE "${REPO}/core/libs")
    target_compile_options(${variant}_probe PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections)
    target_link_options(${variant}_probe PRIVATE -O1 -flto -static-libstdc++ -static-libgcc -Wl,--gc-sections)
    add_custom_command(TARGET ${variant}_probe POST_BUILD COMMAND "${CMAKE_OBJCOPY}" --rename-section .eh_frame=.ehfram --rename-section .eh_fram=.ehfram "$<TARGET_FILE:${variant}_probe>" VERBATIM)
endforeach()
add_test(NAME fixed_future_copy_ownership COMMAND fixed_probe)
set_tests_properties(fixed_future_copy_ownership PROPERTIES TIMEOUT 8)

Support.hpp

#include "prx/libc/include/Api.hpp"
#include "prx/libc/include/exceptions/Runtime.hpp"
#include <cstddef>
#include <typeinfo>

struct CapturedThrow {
    void* object;
    std::type_info* type;
    void (*destructor)(void*);
};
using FutureRaise = void (APS5_VABI *)(const LibcException::FutureErrorObject*);
FutureRaise FutureRaiseSlot();
const void* FutureVtableAddress();
extern "C" void* ReviewExceptionMalloc(std::size_t size);
extern "C" void ReviewExceptionFree(void* pointer);
void ResetObservation();
std::size_t ExceptionLive();
std::size_t ExceptionAllocations();
std::size_t ExceptionFrees();
void CleanupLeaks();
void ArmGuestFailure(bool armed);
std::size_t GuestLive();
std::size_t GuestCalls();
void* APS5_VABI GuestAllocate(std::size_t size);
void APS5_VABI GuestFree(void* pointer);
void* APS5_VABI GuestCalloc(std::size_t count, std::size_t size);
void* APS5_VABI GuestReallocate(void*, std::size_t);
void* APS5_VABI GuestAlign(std::size_t, std::size_t);
void* APS5_VABI GuestRealign(void*, std::size_t, std::size_t);
int APS5_VABI GuestPosixAlign(void**, std::size_t, std::size_t);

Production.cpp

#include "Support.hpp"
#include <algorithm>
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <limits>
#include <windows.h>

namespace std {
using ::ReviewExceptionMalloc;
using ::ReviewExceptionFree;
}

#define malloc ReviewExceptionMalloc
#define free ReviewExceptionFree
#define __cxa_throw_nid_postfix UnusedActualThrow
#include RUNTIME_SOURCE
#undef __cxa_throw_nid_postfix
#undef free
#undef malloc
#include STANDARD_SOURCE

FutureRaise FutureRaiseSlot() { return _ZTVSt12future_error_nid_postfix.doraise; }
const void* FutureVtableAddress() { return &_ZTVSt12future_error_nid_postfix.destroy; }

Support.cpp

#include "Support.hpp"
#include "prx/libc/include/ApplicationHeap.hpp"
#include "prx/libc/include/GuestHeap.hpp"
#include <array>
#include <cerrno>
#include <cstdlib>
#include <new>
#include <stdexcept>

namespace {
std::array<void*, 64> exceptionBlocks{};
std::array<void*, 64> guestBlocks{};
std::size_t allocated = 0, freed = 0, guestCalls = 0;
bool failGuest = false;
void Track(std::array<void*, 64>& blocks, void* pointer) {
    for (auto& slot : blocks) if (!slot) { slot = pointer; return; }
    std::abort();
}
bool Untrack(std::array<void*, 64>& blocks, void* pointer) {
    for (auto& slot : blocks) if (slot == pointer) { slot = nullptr; return true; }
    return false;
}
std::size_t Live(const std::array<void*, 64>& blocks) {
    std::size_t count = 0;
    for (const auto pointer : blocks) count += pointer != nullptr;
    return count;
}
}

extern "C" void* ReviewExceptionMalloc(std::size_t size) {
    void* pointer = std::malloc(size);
    if (pointer) { Track(exceptionBlocks, pointer); ++allocated; }
    return pointer;
}
extern "C" void ReviewExceptionFree(void* pointer) {
    if (pointer && Untrack(exceptionBlocks, pointer)) ++freed;
    std::free(pointer);
}
void ResetObservation() {
    if (ExceptionLive()) std::abort();
    allocated = freed = guestCalls = 0;
}
std::size_t ExceptionLive() { return Live(exceptionBlocks); }
std::size_t ExceptionAllocations() { return allocated; }
std::size_t ExceptionFrees() { return freed; }
void CleanupLeaks() {
    for (auto& pointer : exceptionBlocks) {
        if (!pointer) continue;
        auto* allocation = static_cast<LibcException::Allocation*>(pointer);
        __cxa_free_exception_nid_postfix(&allocation->header + 1);
    }
}
void ArmGuestFailure(bool armed) { failGuest = armed; }
std::size_t GuestLive() { return Live(guestBlocks); }
std::size_t GuestCalls() { return guestCalls; }
void* APS5_VABI GuestAllocate(std::size_t size) {
    ++guestCalls;
    if (failGuest) return nullptr;
    void* pointer = std::malloc(size);
    if (pointer) Track(guestBlocks, pointer);
    return pointer;
}
void APS5_VABI GuestFree(void* pointer) {
    if (!pointer) return;
    if (!Untrack(guestBlocks, pointer)) std::abort();
    std::free(pointer);
}
void* APS5_VABI GuestCalloc(std::size_t, std::size_t) { throw std::runtime_error("unexpected calloc"); }
void* APS5_VABI GuestReallocate(void*, std::size_t) { throw std::runtime_error("unexpected realloc"); }
void* APS5_VABI GuestAlign(std::size_t, std::size_t) { throw std::runtime_error("unexpected align"); }
void* APS5_VABI GuestRealign(void*, std::size_t, std::size_t) { throw std::runtime_error("unexpected realign"); }
int APS5_VABI GuestPosixAlign(void**, std::size_t, std::size_t) { throw std::runtime_error("unexpected posix align"); }

extern "C" [[noreturn]] void APS5_VABI __cxa_throw_nid_postfix(void* object, std::type_info* type, void (*destructor)(void*)) {
    throw CapturedThrow{object, type, destructor};
}
extern "C" int* APS5_VABI __error_nid_postfix() { return &errno; }
extern "C" const void* ApplicationProcessParameters_nid_no_patch() { throw std::runtime_error("unexpected process parameters"); }
extern "C" bool ApplicationGuestHeapApi_nid_no_patch(void**) { throw std::runtime_error("unexpected default heap API"); }
extern "C" [[noreturn]] void NotImplemented_nid_no_patch(const char* name) { throw std::runtime_error(name); }
namespace GuestHeap {
extern "C" std::size_t GuestHeapUsableSize_nid_postfix(const void*) { throw std::runtime_error("unexpected default heap size"); }
extern "C" void* GuestHeapAllocate_nid_postfix(std::size_t) { throw std::runtime_error("unexpected default heap allocate"); }
extern "C" void GuestHeapFree_nid_postfix(void*) { throw std::runtime_error("unexpected default heap free"); }
extern "C" void* GuestHeapReallocate_nid_postfix(void*, std::size_t) { throw std::runtime_error("unexpected default heap realloc"); }
extern "C" void* GuestHeapAlign_nid_postfix(std::size_t, std::size_t) { throw std::runtime_error("unexpected default heap align"); }
extern "C" void* GuestHeapRealign_nid_postfix(void*, std::size_t, std::size_t) { throw std::runtime_error("unexpected default heap realign"); }
extern "C" int GuestHeapStatsFast_nid_postfix(void*) { throw std::runtime_error("unexpected default heap statistics"); }
}

Probe.cpp

#include "Support.hpp"
#include "prx/libc/include/ApplicationHeap.hpp"
#include <array>
#include <bit>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <new>
#include <windows.h>

using Destroy = void (APS5_VABI *)(void*);
std::size_t checks = 0, failures = 0, leakCases = 0, cases = 0;
void Check(bool ok, const char* label) {
    ++checks;
    if (ok) return;
    ++failures;
    if (failures <= 5) std::fprintf(stderr, "FAIL: %s\n", label);
}

int main() {
    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
    const std::array<void*, 10> api {
        reinterpret_cast<void*>(GuestAllocate), reinterpret_cast<void*>(GuestFree), reinterpret_cast<void*>(GuestCalloc),
        reinterpret_cast<void*>(GuestReallocate), reinterpret_cast<void*>(GuestAlign), reinterpret_cast<void*>(GuestRealign),
        reinterpret_cast<void*>(GuestPosixAlign), nullptr, nullptr, nullptr
    };
    ApplicationHeapRegister_nid_no_patch(api.data());
    const FutureRaise raise = FutureRaiseSlot();
    for (std::size_t length : {0u, 1u, 15u, 16u, 24u, 31u, 47u, 95u}) {
        for (int code : {1, 2, 3, 4, 99}) {
            for (bool fail : {false, true}) {
                ++cases;
                ArmGuestFailure(false);
                LibcException::FutureErrorObject source{};
                source.vtable = FutureVtableAddress();
                source.message.capacity = length | std::size_t{15};
                source.message.size = length;
                char* text = source.message.buffer;
                if (length > 15) source.message.pointer = text = static_cast<char*>(_Znwm_nid_postfix(source.message.capacity + 1));
                std::memset(text, 'x', length);
                text[length] = 0;
                source.code = {0x12345678, code, _ZSt15future_categoryv_nid_postfix()};
                const auto sourceBefore = source;
                const std::size_t guestBefore = GuestLive();
                ResetObservation();
                ArmGuestFailure(fail);
                bool caughtAllocationFailure = false, captured = false;
                try { raise(&source); Check(false, "Doraise returned"); }
                catch (const std::bad_alloc&) { caughtAllocationFailure = true; }
                catch (const CapturedThrow& thrown) {
                    captured = true;
                    auto* copy = static_cast<LibcException::FutureErrorObject*>(thrown.object);
                    Check(copy != &source && copy->vtable == source.vtable, "copied object/vtable");
                    Check(copy->code.reserved == source.code.reserved && copy->code.value == source.code.value && copy->code.category == source.code.category, "all error-code fields copied");
                    Check(copy->message.capacity == source.message.capacity && copy->message.size == length, "message metadata copied");
                    const char* copiedText = length > 15 ? copy->message.pointer : copy->message.buffer;
                    Check(std::memcmp(copiedText, text, length + 1) == 0, "message payload copied");
                    if (length > 15) Check(copy->message.pointer != source.message.pointer, "heap storage deep copied");
                    Check(std::strcmp(thrown.type->name(), "St12future_error") == 0, "throw type retained");
                    reinterpret_cast<Destroy>(thrown.destructor)(copy);
                    __cxa_free_exception_nid_postfix(copy);
                }
                ArmGuestFailure(false);
                Check(caughtAllocationFailure == (fail && length > 15), "allocation failure propagated only when deep-copy allocation needed");
                Check(captured == !(fail && length > 15), "success reaches throw ownership boundary");
                Check(GuestCalls() == (length > 15 ? 1u : 0u), "guest allocation call count");
                Check(ExceptionAllocations() == 1, "actual runtime allocated one exception block");
                if (ExceptionLive()) ++leakCases;
                Check(ExceptionLive() == 0 && ExceptionFrees() == 1, "exception allocation reclaimed");
                Check(GuestLive() == guestBefore, "no source message double free or clone leak");
                Check(std::memcmp(&source, &sourceBefore, sizeof(source)) == 0, "source object bytes intact");
                Check(text[length] == 0, "source terminator intact");
                for (std::size_t i = 0; i < length; ++i) Check(text[i] == 'x', "source payload intact");
                CleanupLeaks();
                _ZNSt12future_errorD1Ev_nid_postfix(&source);
                Check(GuestLive() == 0, "source destruction frees original heap string");
            }
        }
    }
    std::printf("{\"cases\":%zu,\"checks\":%zu,\"failures\":%zu,\"leak_cases\":%zu,\"final_exception_live\":%zu,\"final_guest_live\":%zu}\n", cases, checks, failures, leakCases, ExceptionLive(), GuestLive());
    return failures ? 1 : 0;
}
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645825587 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11241#pullrequestreview-5645825587). Originally posted by [thepoppfish](https://github.com/thepoppfish) on 2026-10-25T23:12:22Z. **Review:** CHANGES_REQUESTED --- Found one allocation-failure cleanup issue at exact head `e859215335e34c1fd566130ab0c36223864ec064`. `future_error`'s `_Doraise` vtable entry first allocates an exception block with `__cxa_allocate_exception_nid_postfix`, then `CopyFutureError` allocates again through guest `operator new` when the source message is heap-backed (`capacity > 15`). If that second allocation fails, `std::bad_alloc` escapes before `__cxa_throw_nid_postfix` receives ownership. The first block is never released. This affects the heap-backed-message copy path, not every `_Throw_future_error` call (that helper creates an empty inline message). I reproduced this on native Windows with the **complete production** `Runtime.cpp`, `StandardExceptions.cpp`, `StdioExtras.cpp` and `ApplicationHeap.cpp`. The registered guest allocator returns null at the copy allocation, so the real application-heap/new code produces the failure. Runtime malloc/free calls are redirected to observing wrappers that use normal host malloc/free. The actual exception allocation/free bodies are retained. A capture adapter replaces the final throw handoff for successful-copy controls; the failing-copy cases never reach that adapter. This is allocation-ownership validation, not full guest unwinding/RTTI-catch validation. Results with GCC **16.2.0-6 UCRT**, C++20, `-O1 -g -fno-inline -flto`, static C++ runtime: | Variant | Matrix cases | Checks | Failed checks / unreclaimed-block cases | | --- | ---: | ---: | ---: | | Published head | 80 | 3310 | 25 / 25 | | Cleanup patch | 80 | 3310 | 0 / 0 | The matrix crosses message lengths 0, 1, 15, 16, 24, 31, 47 and 95, codes 1..4/99, and normal/failing guest allocation. Each of the 25 failing heap-copy cases at the head has one exception allocation and zero frees before the probe manually cleans it up. With the patch, the original `bad_alloc` propagates and the block is freed exactly once. All successful copies retain vtable/code fields and separate heap storage; all source-object bytes and message bytes stay intact, and source destruction still frees the original allocation. The head log's final live count is zero **because the probe cleans up after recording each leak**, not because the head frees it. Reviewable repair: [ee91bab13f84](https://github.com/thepoppfish/AnyPS5/commit/ee91bab13f84d64f8f31d4845ac5a17c7cb9e478), branch [`codex/review-future-error-copy-cleanup`](https://github.com/thepoppfish/AnyPS5/tree/codex/review-future-error-copy-cleanup). The commit changes one production file, 6 insertions/1 deletion. Its parent is a clean local merge of this PR with current-main snapshot `49d1f9b07ec7f6f989ace1c504bbe9dd6748dcbb`; all 133 libc files were identical to this PR before applying the patch. The committed candidate's actual source was then rebuilt and passed the full 80-case fixture (CTest 1/1, 0 skipped, 0.12 s). Conventions against that pinned `origin/main` and whitespace checks pass; the candidate checkout is clean. This is a support commit for cherry-picking, not another PR or an imposed merge order. Please free only the raw exception allocation if copying throws, then rethrow. Calling the future-error destructor on that partially copied object would risk freeing the source's aliased string pointer. ```diff --- a/core/libs/prx/libc/src/exception/StandardExceptions.cpp +++ b/core/libs/prx/libc/src/exception/StandardExceptions.cpp @@ -718,7 +718,12 @@ } [[noreturn]] static void APS5_VABI RaiseFutureError_nid_no_patch(const LibcException::FutureErrorObject* self) { auto* object = static_cast<LibcException::FutureErrorObject*>(__cxa_allocate_exception_nid_postfix(sizeof(LibcException::FutureErrorObject))); - CopyFutureError(object, self); + try { + CopyFutureError(object, self); + } catch (...) { + __cxa_free_exception_nid_postfix(object); + throw; + } __cxa_throw_nid_postfix(object, reinterpret_cast<std::type_info*>(&_ZTISt12future_error_nid_postfix), reinterpret_cast<decltype(LibcException::Header::destructor)>(DestroyFutureError_nid_no_patch)); } ``` I did not run the full libc/product build, the committed three guest-category tests, Linux/macOS, console/title execution, or a canonical PR-overlap scan. The successful-control adapter does not establish the guest unwinder or catch ABI. AI-assisted implementation and replay: Codex. <details> <summary>Complete fault-injection replay (four production sources, five fixture files)</summary> Check out the exact PR head and support commit separately. Save the five files below in another directory, set `REPO` to the PR-head checkout and `FIXED_SOURCE` to the support checkout's `core/libs/prx/libc/src/exception/StandardExceptions.cpp`, and build with GCC/MinGW on Windows: ```powershell cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DREPO="C:/path/to/head-checkout" -DFIXED_SOURCE="C:/path/to/support-checkout/core/libs/prx/libc/src/exception/StandardExceptions.cpp" cmake --build build -j 3 ctest --test-dir build -V ``` Run `build/head_probe.exe` for the negative control: exit 1 with 25 failed checks/leak cases. `build/fixed_probe.exe` exits 0 with 0 failures/leaks. CTest registers only the fixed version. `Production.cpp` keeps Runtime before StandardExceptions as in the library's `exception/Exports.cpp`; it replaces only the allocator observation and final throw boundary, while omitting the full product's exception-export aliases. The typed vtable accessors avoid declaring the vtable with a conflicting type. Uncalled default-heap paths fail loudly if reached. The objcopy step follows the project's Windows unwind-section handling for exceptions crossing the guest ABI. **CMakeLists.txt** ```cmake cmake_minimum_required(VERSION 3.20) project(FutureCopyReview LANGUAGES CXX) get_filename_component(DEFAULT_REPO "${CMAKE_CURRENT_LIST_DIR}/../review-11241" ABSOLUTE) set(REPO "${DEFAULT_REPO}" CACHE PATH "Exact reviewed checkout") set(SRC "${REPO}/core/libs/prx/libc/src") set(FIXED_SOURCE "${CMAKE_CURRENT_LIST_DIR}/FixedStandardExceptions.cpp" CACHE FILEPATH "Candidate production source") enable_testing() add_library(common OBJECT "${SRC}/StdioExtras.cpp" "${SRC}/ApplicationHeap.cpp" Support.cpp) foreach(target IN ITEMS common) target_compile_features(${target} PRIVATE cxx_std_20) target_include_directories(${target} PRIVATE "${REPO}/core/libs") target_compile_options(${target} PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections) endforeach() foreach(variant IN ITEMS head fixed) if(variant STREQUAL head) set(standard "${SRC}/exception/StandardExceptions.cpp") else() set(standard "${FIXED_SOURCE}") endif() add_executable(${variant}_probe Probe.cpp Production.cpp $<TARGET_OBJECTS:common>) target_compile_definitions(${variant}_probe PRIVATE RUNTIME_SOURCE="${SRC}/exception/Runtime.cpp" STANDARD_SOURCE="${standard}") target_compile_features(${variant}_probe PRIVATE cxx_std_20) target_include_directories(${variant}_probe PRIVATE "${REPO}/core/libs") target_compile_options(${variant}_probe PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections) target_link_options(${variant}_probe PRIVATE -O1 -flto -static-libstdc++ -static-libgcc -Wl,--gc-sections) add_custom_command(TARGET ${variant}_probe POST_BUILD COMMAND "${CMAKE_OBJCOPY}" --rename-section .eh_frame=.ehfram --rename-section .eh_fram=.ehfram "$<TARGET_FILE:${variant}_probe>" VERBATIM) endforeach() add_test(NAME fixed_future_copy_ownership COMMAND fixed_probe) set_tests_properties(fixed_future_copy_ownership PROPERTIES TIMEOUT 8) ``` **Support.hpp** ```cpp #include "prx/libc/include/Api.hpp" #include "prx/libc/include/exceptions/Runtime.hpp" #include <cstddef> #include <typeinfo> struct CapturedThrow { void* object; std::type_info* type; void (*destructor)(void*); }; using FutureRaise = void (APS5_VABI *)(const LibcException::FutureErrorObject*); FutureRaise FutureRaiseSlot(); const void* FutureVtableAddress(); extern "C" void* ReviewExceptionMalloc(std::size_t size); extern "C" void ReviewExceptionFree(void* pointer); void ResetObservation(); std::size_t ExceptionLive(); std::size_t ExceptionAllocations(); std::size_t ExceptionFrees(); void CleanupLeaks(); void ArmGuestFailure(bool armed); std::size_t GuestLive(); std::size_t GuestCalls(); void* APS5_VABI GuestAllocate(std::size_t size); void APS5_VABI GuestFree(void* pointer); void* APS5_VABI GuestCalloc(std::size_t count, std::size_t size); void* APS5_VABI GuestReallocate(void*, std::size_t); void* APS5_VABI GuestAlign(std::size_t, std::size_t); void* APS5_VABI GuestRealign(void*, std::size_t, std::size_t); int APS5_VABI GuestPosixAlign(void**, std::size_t, std::size_t); ``` **Production.cpp** ```cpp #include "Support.hpp" #include <algorithm> #include <cstdarg> #include <cstdio> #include <cstring> #include <limits> #include <windows.h> namespace std { using ::ReviewExceptionMalloc; using ::ReviewExceptionFree; } #define malloc ReviewExceptionMalloc #define free ReviewExceptionFree #define __cxa_throw_nid_postfix UnusedActualThrow #include RUNTIME_SOURCE #undef __cxa_throw_nid_postfix #undef free #undef malloc #include STANDARD_SOURCE FutureRaise FutureRaiseSlot() { return _ZTVSt12future_error_nid_postfix.doraise; } const void* FutureVtableAddress() { return &_ZTVSt12future_error_nid_postfix.destroy; } ``` **Support.cpp** ```cpp #include "Support.hpp" #include "prx/libc/include/ApplicationHeap.hpp" #include "prx/libc/include/GuestHeap.hpp" #include <array> #include <cerrno> #include <cstdlib> #include <new> #include <stdexcept> namespace { std::array<void*, 64> exceptionBlocks{}; std::array<void*, 64> guestBlocks{}; std::size_t allocated = 0, freed = 0, guestCalls = 0; bool failGuest = false; void Track(std::array<void*, 64>& blocks, void* pointer) { for (auto& slot : blocks) if (!slot) { slot = pointer; return; } std::abort(); } bool Untrack(std::array<void*, 64>& blocks, void* pointer) { for (auto& slot : blocks) if (slot == pointer) { slot = nullptr; return true; } return false; } std::size_t Live(const std::array<void*, 64>& blocks) { std::size_t count = 0; for (const auto pointer : blocks) count += pointer != nullptr; return count; } } extern "C" void* ReviewExceptionMalloc(std::size_t size) { void* pointer = std::malloc(size); if (pointer) { Track(exceptionBlocks, pointer); ++allocated; } return pointer; } extern "C" void ReviewExceptionFree(void* pointer) { if (pointer && Untrack(exceptionBlocks, pointer)) ++freed; std::free(pointer); } void ResetObservation() { if (ExceptionLive()) std::abort(); allocated = freed = guestCalls = 0; } std::size_t ExceptionLive() { return Live(exceptionBlocks); } std::size_t ExceptionAllocations() { return allocated; } std::size_t ExceptionFrees() { return freed; } void CleanupLeaks() { for (auto& pointer : exceptionBlocks) { if (!pointer) continue; auto* allocation = static_cast<LibcException::Allocation*>(pointer); __cxa_free_exception_nid_postfix(&allocation->header + 1); } } void ArmGuestFailure(bool armed) { failGuest = armed; } std::size_t GuestLive() { return Live(guestBlocks); } std::size_t GuestCalls() { return guestCalls; } void* APS5_VABI GuestAllocate(std::size_t size) { ++guestCalls; if (failGuest) return nullptr; void* pointer = std::malloc(size); if (pointer) Track(guestBlocks, pointer); return pointer; } void APS5_VABI GuestFree(void* pointer) { if (!pointer) return; if (!Untrack(guestBlocks, pointer)) std::abort(); std::free(pointer); } void* APS5_VABI GuestCalloc(std::size_t, std::size_t) { throw std::runtime_error("unexpected calloc"); } void* APS5_VABI GuestReallocate(void*, std::size_t) { throw std::runtime_error("unexpected realloc"); } void* APS5_VABI GuestAlign(std::size_t, std::size_t) { throw std::runtime_error("unexpected align"); } void* APS5_VABI GuestRealign(void*, std::size_t, std::size_t) { throw std::runtime_error("unexpected realign"); } int APS5_VABI GuestPosixAlign(void**, std::size_t, std::size_t) { throw std::runtime_error("unexpected posix align"); } extern "C" [[noreturn]] void APS5_VABI __cxa_throw_nid_postfix(void* object, std::type_info* type, void (*destructor)(void*)) { throw CapturedThrow{object, type, destructor}; } extern "C" int* APS5_VABI __error_nid_postfix() { return &errno; } extern "C" const void* ApplicationProcessParameters_nid_no_patch() { throw std::runtime_error("unexpected process parameters"); } extern "C" bool ApplicationGuestHeapApi_nid_no_patch(void**) { throw std::runtime_error("unexpected default heap API"); } extern "C" [[noreturn]] void NotImplemented_nid_no_patch(const char* name) { throw std::runtime_error(name); } namespace GuestHeap { extern "C" std::size_t GuestHeapUsableSize_nid_postfix(const void*) { throw std::runtime_error("unexpected default heap size"); } extern "C" void* GuestHeapAllocate_nid_postfix(std::size_t) { throw std::runtime_error("unexpected default heap allocate"); } extern "C" void GuestHeapFree_nid_postfix(void*) { throw std::runtime_error("unexpected default heap free"); } extern "C" void* GuestHeapReallocate_nid_postfix(void*, std::size_t) { throw std::runtime_error("unexpected default heap realloc"); } extern "C" void* GuestHeapAlign_nid_postfix(std::size_t, std::size_t) { throw std::runtime_error("unexpected default heap align"); } extern "C" void* GuestHeapRealign_nid_postfix(void*, std::size_t, std::size_t) { throw std::runtime_error("unexpected default heap realign"); } extern "C" int GuestHeapStatsFast_nid_postfix(void*) { throw std::runtime_error("unexpected default heap statistics"); } } ``` **Probe.cpp** ```cpp #include "Support.hpp" #include "prx/libc/include/ApplicationHeap.hpp" #include <array> #include <bit> #include <cstdio> #include <cstdlib> #include <cstring> #include <new> #include <windows.h> using Destroy = void (APS5_VABI *)(void*); std::size_t checks = 0, failures = 0, leakCases = 0, cases = 0; void Check(bool ok, const char* label) { ++checks; if (ok) return; ++failures; if (failures <= 5) std::fprintf(stderr, "FAIL: %s\n", label); } int main() { SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); const std::array<void*, 10> api { reinterpret_cast<void*>(GuestAllocate), reinterpret_cast<void*>(GuestFree), reinterpret_cast<void*>(GuestCalloc), reinterpret_cast<void*>(GuestReallocate), reinterpret_cast<void*>(GuestAlign), reinterpret_cast<void*>(GuestRealign), reinterpret_cast<void*>(GuestPosixAlign), nullptr, nullptr, nullptr }; ApplicationHeapRegister_nid_no_patch(api.data()); const FutureRaise raise = FutureRaiseSlot(); for (std::size_t length : {0u, 1u, 15u, 16u, 24u, 31u, 47u, 95u}) { for (int code : {1, 2, 3, 4, 99}) { for (bool fail : {false, true}) { ++cases; ArmGuestFailure(false); LibcException::FutureErrorObject source{}; source.vtable = FutureVtableAddress(); source.message.capacity = length | std::size_t{15}; source.message.size = length; char* text = source.message.buffer; if (length > 15) source.message.pointer = text = static_cast<char*>(_Znwm_nid_postfix(source.message.capacity + 1)); std::memset(text, 'x', length); text[length] = 0; source.code = {0x12345678, code, _ZSt15future_categoryv_nid_postfix()}; const auto sourceBefore = source; const std::size_t guestBefore = GuestLive(); ResetObservation(); ArmGuestFailure(fail); bool caughtAllocationFailure = false, captured = false; try { raise(&source); Check(false, "Doraise returned"); } catch (const std::bad_alloc&) { caughtAllocationFailure = true; } catch (const CapturedThrow& thrown) { captured = true; auto* copy = static_cast<LibcException::FutureErrorObject*>(thrown.object); Check(copy != &source && copy->vtable == source.vtable, "copied object/vtable"); Check(copy->code.reserved == source.code.reserved && copy->code.value == source.code.value && copy->code.category == source.code.category, "all error-code fields copied"); Check(copy->message.capacity == source.message.capacity && copy->message.size == length, "message metadata copied"); const char* copiedText = length > 15 ? copy->message.pointer : copy->message.buffer; Check(std::memcmp(copiedText, text, length + 1) == 0, "message payload copied"); if (length > 15) Check(copy->message.pointer != source.message.pointer, "heap storage deep copied"); Check(std::strcmp(thrown.type->name(), "St12future_error") == 0, "throw type retained"); reinterpret_cast<Destroy>(thrown.destructor)(copy); __cxa_free_exception_nid_postfix(copy); } ArmGuestFailure(false); Check(caughtAllocationFailure == (fail && length > 15), "allocation failure propagated only when deep-copy allocation needed"); Check(captured == !(fail && length > 15), "success reaches throw ownership boundary"); Check(GuestCalls() == (length > 15 ? 1u : 0u), "guest allocation call count"); Check(ExceptionAllocations() == 1, "actual runtime allocated one exception block"); if (ExceptionLive()) ++leakCases; Check(ExceptionLive() == 0 && ExceptionFrees() == 1, "exception allocation reclaimed"); Check(GuestLive() == guestBefore, "no source message double free or clone leak"); Check(std::memcmp(&source, &sourceBefore, sizeof(source)) == 0, "source object bytes intact"); Check(text[length] == 0, "source terminator intact"); for (std::size_t i = 0; i < length; ++i) Check(text[i] == 'x', "source payload intact"); CleanupLeaks(); _ZNSt12future_errorD1Ev_nid_postfix(&source); Check(GuestLive() == 0, "source destruction frees original heap string"); } } } std::printf("{\"cases\":%zu,\"checks\":%zu,\"failures\":%zu,\"leak_cases\":%zu,\"final_exception_live\":%zu,\"final_guest_live\":%zu}\n", cases, checks, failures, leakCases, ExceptionLive(), GuestLive()); return failures ? 1 : 0; } ``` </details>
thepoppfish commented 2026-10-26 01:12:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-26T01:12:28Z.

Review: APPROVED


Re-reviewed exact head 45ea48c5aa1d3a612822d373944b5ba9817c1737. The allocation-cleanup finding is addressed, and I approve this revision.

The complete StandardExceptions.cpp blob is a04b42a966ad33fa11d78cda7bc21d9f8e93d635, byte-identical to the tested repair in ee91bab13f84. The catch frees only the raw exception allocation and rethrows; it leaves the source-owned message intact.

I rebuilt the unchanged 80-case ownership probe from my original review against both:

  • This exact head: 80 cases / 3,310 checks / 0 failures / 0 leaked exception blocks; isolated CTest 1/1 passes in 0.11s, zero skips.
  • A clean local integration with main 5b85225ef39b9321d8f5c251ecb391b8331e8aea, commit ad3f17baefc1e50667eaf0983eab236674d0fa08 / tree 93150b24d736af1a33eac6c1ca1b4862c4766a3f: the same 80 / 3,310 / 0 / 0, CTest 1/1 in 0.13s, zero skips.

Both are fresh six-step builds on Windows 11 build 26200, GCC 16.2.0-6 UCRT64, CMake 4.3.1 and Ninja 1.13.2. Each uses its own actual headers. Runtime, StandardExceptions, StdioExtras and ApplicationHeap production blobs are identical between the two trees. The five original fixture files match the code published in the original review.

The matrix covers eight message lengths across the inline/heap boundary, five error codes and successful/failing guest allocation. Every raw exception block is freed exactly once, heap copies remain separate from the source, source bytes remain intact, and both exception/guest allocation trackers end at zero. For the 25 heap-copy failures, bad_alloc propagates without reaching the final throw adapter.

Conventions against pinned origin/main and whitespace checks pass on both trees; both builds have no compiler warnings. I also inspected the new committed allocation-failure check in GuestFutureCategory.cpp. These runs use the original real Runtime allocator and guest-new/ApplicationHeap path, with observational malloc/free wrappers and the explicit final-throw capture adapter described previously. They do not run the complete committed guest fixture, full product/unwinder/RTTI catch ABI, Linux/macOS, a title or console. The original negative controls are historical and were not rerun. AI-assisted: yes.

The original inline thread is now outdated but remains unresolved; please resolve it.

Fresh-build replay

Keep the five original fixture files from the linked review in a directory named native-future11241. Save this CMake file in a sibling directory and configure it with -DREPO=<absolute-head-checkout>, then build and run CTest. Repeat with the integration checkout for the second run. The source tree is selected by REPO; no production file is replaced with the old scratch candidate.

cmake_minimum_required(VERSION 3.20)
project(FutureCopyRevisionReview LANGUAGES CXX)
enable_testing()
get_filename_component(DEFAULT_REPO "../review-11241-revision" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
get_filename_component(FIXTURE "../native-future11241" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(REPO "${DEFAULT_REPO}" CACHE PATH "Exact source tree")
set(SRC "${REPO}/core/libs/prx/libc/src")
add_executable(future_copy_probe
    "${FIXTURE}/Probe.cpp" "${FIXTURE}/Production.cpp" "${FIXTURE}/Support.cpp"
    "${SRC}/StdioExtras.cpp" "${SRC}/ApplicationHeap.cpp")
target_compile_features(future_copy_probe PRIVATE cxx_std_20)
target_include_directories(future_copy_probe PRIVATE "${REPO}/core/libs")
target_compile_definitions(future_copy_probe PRIVATE
    RUNTIME_SOURCE="${SRC}/exception/Runtime.cpp"
    STANDARD_SOURCE="${SRC}/exception/StandardExceptions.cpp")
target_compile_options(future_copy_probe PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections)
target_link_options(future_copy_probe PRIVATE -O1 -flto -static-libstdc++ -static-libgcc -Wl,--gc-sections)
add_custom_command(TARGET future_copy_probe POST_BUILD COMMAND "${CMAKE_OBJCOPY}"
    --rename-section .eh_frame=.ehfram --rename-section .eh_fram=.ehfram "$<TARGET_FILE:future_copy_probe>" VERBATIM)
add_test(NAME future_copy_ownership COMMAND future_copy_probe)
set_tests_properties(future_copy_ownership PROPERTIES TIMEOUT 8)
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5646350915 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11241#pullrequestreview-5646350915). Originally posted by [thepoppfish](https://github.com/thepoppfish) on 2026-10-26T01:12:28Z. **Review:** APPROVED --- Re-reviewed exact head `45ea48c5aa1d3a612822d373944b5ba9817c1737`. The allocation-cleanup finding is addressed, and I approve this revision. The complete `StandardExceptions.cpp` blob is `a04b42a966ad33fa11d78cda7bc21d9f8e93d635`, byte-identical to the tested repair in [ee91bab13f84](https://github.com/thepoppfish/AnyPS5/commit/ee91bab13f84d64f8f31d4845ac5a17c7cb9e478). The catch frees only the raw exception allocation and rethrows; it leaves the source-owned message intact. I rebuilt the unchanged 80-case ownership probe from [my original review](https://github.com/boykopovar/AnyPS5/pull/11241#pullrequestreview-5645825587) against both: - This exact head: **80 cases / 3,310 checks / 0 failures / 0 leaked exception blocks**; isolated CTest 1/1 passes in 0.11s, zero skips. - A clean local integration with main `5b85225ef39b9321d8f5c251ecb391b8331e8aea`, commit `ad3f17baefc1e50667eaf0983eab236674d0fa08` / tree `93150b24d736af1a33eac6c1ca1b4862c4766a3f`: the same **80 / 3,310 / 0 / 0**, CTest 1/1 in 0.13s, zero skips. Both are fresh six-step builds on Windows 11 build 26200, GCC 16.2.0-6 UCRT64, CMake 4.3.1 and Ninja 1.13.2. Each uses its own actual headers. Runtime, StandardExceptions, StdioExtras and ApplicationHeap production blobs are identical between the two trees. The five original fixture files match the code published in the original review. The matrix covers eight message lengths across the inline/heap boundary, five error codes and successful/failing guest allocation. Every raw exception block is freed exactly once, heap copies remain separate from the source, source bytes remain intact, and both exception/guest allocation trackers end at zero. For the 25 heap-copy failures, `bad_alloc` propagates without reaching the final throw adapter. Conventions against pinned `origin/main` and whitespace checks pass on both trees; both builds have no compiler warnings. I also inspected the new committed allocation-failure check in `GuestFutureCategory.cpp`. These runs use the original real Runtime allocator and guest-new/ApplicationHeap path, with observational malloc/free wrappers and the explicit final-throw capture adapter described previously. They do not run the complete committed guest fixture, full product/unwinder/RTTI catch ABI, Linux/macOS, a title or console. The original negative controls are historical and were not rerun. AI-assisted: yes. The original inline thread is now outdated but remains unresolved; please resolve it. <details><summary>Fresh-build replay</summary> Keep the five original fixture files from the linked review in a directory named `native-future11241`. Save this CMake file in a sibling directory and configure it with `-DREPO=<absolute-head-checkout>`, then build and run CTest. Repeat with the integration checkout for the second run. The source tree is selected by `REPO`; no production file is replaced with the old scratch candidate. ```cmake cmake_minimum_required(VERSION 3.20) project(FutureCopyRevisionReview LANGUAGES CXX) enable_testing() get_filename_component(DEFAULT_REPO "../review-11241-revision" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}") get_filename_component(FIXTURE "../native-future11241" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}") set(REPO "${DEFAULT_REPO}" CACHE PATH "Exact source tree") set(SRC "${REPO}/core/libs/prx/libc/src") add_executable(future_copy_probe "${FIXTURE}/Probe.cpp" "${FIXTURE}/Production.cpp" "${FIXTURE}/Support.cpp" "${SRC}/StdioExtras.cpp" "${SRC}/ApplicationHeap.cpp") target_compile_features(future_copy_probe PRIVATE cxx_std_20) target_include_directories(future_copy_probe PRIVATE "${REPO}/core/libs") target_compile_definitions(future_copy_probe PRIVATE RUNTIME_SOURCE="${SRC}/exception/Runtime.cpp" STANDARD_SOURCE="${SRC}/exception/StandardExceptions.cpp") target_compile_options(future_copy_probe PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections) target_link_options(future_copy_probe PRIVATE -O1 -flto -static-libstdc++ -static-libgcc -Wl,--gc-sections) add_custom_command(TARGET future_copy_probe POST_BUILD COMMAND "${CMAKE_OBJCOPY}" --rename-section .eh_frame=.ehfram --rename-section .eh_fram=.ehfram "$<TARGET_FILE:future_copy_probe>" VERBATIM) add_test(NAME future_copy_ownership COMMAND future_copy_probe) set_tests_properties(future_copy_ownership PROPERTIES TIMEOUT 8) ``` </details>
MarcZX10 commented 2026-10-26 06:40:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T06:40:03Z.

Review: APPROVED


Re-reviewed exact head 45ea48c5aa1d3a612822d373944b5ba9817c1737. The _Doraise path now frees the raw exception allocation if CopyFutureError throws and rethrows without running the partially initialized object destructor, which could otherwise free the source-owned aliased message. The new guest regression exercises heap-backed source text with guest allocation failure and checks bad_alloc propagation plus source-text integrity. I verified the current-main diff and git diff --check; hosted conventions, relinker matrix, relinker ASan and register-context checks pass. Product Linux/Windows builds are skipped by repository policy. The focused guest tests and ownership probe are reported by the author and an independent reviewer; I did not rerun a local libc product build.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5648244288 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11241#pullrequestreview-5648244288). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T06:40:03Z. **Review:** APPROVED --- Re-reviewed exact head `45ea48c5aa1d3a612822d373944b5ba9817c1737`. The `_Doraise` path now frees the raw exception allocation if `CopyFutureError` throws and rethrows without running the partially initialized object destructor, which could otherwise free the source-owned aliased message. The new guest regression exercises heap-backed source text with guest allocation failure and checks `bad_alloc` propagation plus source-text integrity. I verified the current-main diff and `git diff --check`; hosted conventions, relinker matrix, relinker ASan and register-context checks pass. Product Linux/Windows builds are skipped by repository policy. The focused guest tests and ownership probe are reported by the author and an independent reviewer; I did not rerun a local libc product build.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11241
No description provided.