feat(libc): implement std::_Throw_C_error #7648

Merged
Islam-ElShahaby merged 3 commits from upstream-pr/7648 into main 2026-11-04 17:33:56 +00:00
Islam-ElShahaby commented 2026-10-18 19:32:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Islam-ElShahaby on 2026-10-18T19:32:20Z.


What

Implements std::_Throw_C_error(int) using the PRAGMATA (PPSA02530) bundled libc.prx disassembly reported by Ondra97 in https://github.com/boykopovar/AnyPS5/pull/7648#issuecomment-6269342411. Inputs 1/2 throw guest std::system_error with generic error 35, input 3 maps to 16, input 4 to 22, and input 5 to 1 (operation_not_permitted). Other inputs return normally. The guest ABI fixture checks the exception type, category, payload, and return cases.

Rebased onto origin/main at fa515def85, preserving Adrià Franch's correction and contributor credits. RequireThrd now delegates from its upstream location in libc/src/Threads.cpp. Other SDK versions have not been inspected.

Tested

Linux x86_64, GCC 13.3.0, Release: guest_ampr_cpp_error, guest_ampr_threads, and patched_libraries passed (3/3). Conventions and whitespace checks passed. Full Linux Release build passed before the latest base update; all three affected targets were rebuilt and their tests passed again after rebasing onto fa515def85.

Earlier Windows checks were reported by LeandroLP23 and Ondra97 in the PR discussion; these precede this rebase. No title or console run was performed for this rebase. The repository overlap checker was run against 1,263 open PRs using public GitHub API reads in place of GitHub CLI. Its only same-export match was this PR itself. The shared-file warnings were manually reviewed; no other PR implements _Throw_C_error. PR #6044 reorganizes the test files and may require a future rebase.

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
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4912157038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7648). Originally posted by [Islam-ElShahaby](https://github.com/Islam-ElShahaby) on 2026-10-18T19:32:20Z. --- ### What Implements `std::_Throw_C_error(int)` using the PRAGMATA (PPSA02530) bundled `libc.prx` disassembly reported by Ondra97 in https://github.com/boykopovar/AnyPS5/pull/7648#issuecomment-6269342411. Inputs 1/2 throw guest `std::system_error` with generic error 35, input 3 maps to 16, input 4 to 22, and input 5 to 1 (`operation_not_permitted`). Other inputs return normally. The guest ABI fixture checks the exception type, category, payload, and return cases. Rebased onto `origin/main` at `fa515def85`, preserving Adrià Franch's correction and contributor credits. `RequireThrd` now delegates from its upstream location in `libc/src/Threads.cpp`. Other SDK versions have not been inspected. ### Tested Linux x86_64, GCC 13.3.0, Release: `guest_ampr_cpp_error`, `guest_ampr_threads`, and `patched_libraries` passed (3/3). Conventions and whitespace checks passed. Full Linux Release build passed before the latest base update; all three affected targets were rebuilt and their tests passed again after rebasing onto `fa515def85`. Earlier Windows checks were reported by LeandroLP23 and Ondra97 in the PR discussion; these precede this rebase. No title or console run was performed for this rebase. The repository overlap checker was run against 1,263 open PRs using public GitHub API reads in place of GitHub CLI. Its only same-export match was this PR itself. The shared-file warnings were manually reviewed; no other PR implements `_Throw_C_error`. PR #6044 reorganizes the test files and may require a future rebase. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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 - [x] GPUs tested: n/a - [x] AI-assisted: yes
LeandroLP23 commented 2026-10-18 20:52:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T20:52:13Z.


Windows run, since the description covers Linux only. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. Build: main e8ad642fe with #7651, #7650, #7647, #7655 and #7648 merged together (each merge clean, built once).

guest_ampr_cpp_error, guest_ampr_threads and patched_libraries pass 3 runs of 3.

AI-assisted

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6255006002 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7648#issuecomment-6255006002). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-18T20:52:13Z. --- Windows run, since the description covers Linux only. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`. Build: `main` `e8ad642fe` with #7651, #7650, #7647, #7655 and #7648 merged together (each merge clean, built once). `guest_ampr_cpp_error`, `guest_ampr_threads` and `patched_libraries` pass 3 runs of 3. AI-assisted
Ondra97 commented 2026-10-19 14:14:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-19T14:14:58Z.


I compared this exact head (16ee65bed011d4f21bc798ddfe5a0b49014fcae4) with std::_Throw_C_error in the libc.prx bundled with PRAGMATA (PPSA02530). Its NID is bRujIheWlB0; original virtual address 0x15f20, ELF symbol size 256 bytes. The original SELF SHA-256 is 03f2202ca1cbd497e136bc47a91e65677b0e8d7e4ae0fe3dea67b0e8f7b609cf. I checked that all 256 function bytes match the existing converted PE used for disassembly.

This PS5 version differs from the VC12 contract in two places:

  • Input 5 throws guest std::system_error with generic_category, error value 1, and the prefix operation not permitted.
  • Values outside 1..5 return. The function starts with dec edi; cmp edi, 4; jbe dispatch, followed by the register restores and ret for the other values. This also means its [[noreturn]] declarations should be removed.

The jump-table mapping is 1/2 -> 35, 3 -> 16, 4 -> 22, 5 -> 1. The type passed to __cxa_throw is _ZTISt12system_error; the category getter is _ZSt16generic_categoryv.

I prepared a small follow-up patch against your head. It reuses ThrowCppError_nid_no_patch(4) for input 5 and updates the existing guest ABI fixture to check the system_error payload/category and normal returns for INT_MIN, -1, 0, 6 and INT_MAX. The same regression test fails against the original PR implementation and passes with the fix. This is based on the bundled PS5 binary; I have not established behavior for other SDK versions.

Local verification: Windows 11 10.0.26300, Ryzen 9 7900X, 32 GB RAM, MinGW-w64 GCC 15.2.0, Release. Full native build passed. patched_libraries, guest_ampr_markers, guest_amm_placement, guest_ampr_threads, guest_ampr_cpp_error and guest_unwind_module_info: 6/6 passed, no failures or skips. The regression-only fixture fails against your original production code at INT_MIN; the identical fixture passes with this patch. The relevant library hashes remain unchanged after committing, and the final post-commit library-loading check passed again. Conventions and whitespace checks passed. Linux and a game run were not tested.

AI-assisted: yes.

Follow-up patch against 16ee65bed011d4f21bc798ddfe5a0b49014fcae4
diff --git a/core/libs/prx/libSceAmpr/Export.cpp b/core/libs/prx/libSceAmpr/Export.cpp
index 3ec4e8ebbc720a72f469ce06024dbbe61a5986f7..db174400346e9c67de8ffe7c7c7d2b957bddd49f 100644
--- a/core/libs/prx/libSceAmpr/Export.cpp
+++ b/core/libs/prx/libSceAmpr/Export.cpp
@@ -272,7 +272,7 @@ int APS5_VABI wcsrtombs_s_nid_postfix(std::size_t* result, char* destination, st
 int APS5_VABI _Cnd_init_nid_postfix(void** handle);
 int SignalCondition_nid_no_patch(void** handle);
 [[noreturn]] void ThrowCppError_nid_no_patch(int code);
-[[noreturn]] void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code);
+void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code);
 }
 
 static void RequireThrd(int result) {
diff --git a/core/libs/prx/libc/src/RuntimeSupport.cpp b/core/libs/prx/libc/src/RuntimeSupport.cpp
index eb5c97088393337d3a90790e3073df4c460d36a5..bdfd9a282cdf7c605afb7378a6fc931d8cdf5f97 100644
--- a/core/libs/prx/libc/src/RuntimeSupport.cpp
+++ b/core/libs/prx/libc/src/RuntimeSupport.cpp
@@ -132,14 +132,16 @@ static constexpr int ThrdNomem = 1;
 static constexpr int ThrdTimedout = 2;
 static constexpr int ThrdBusy = 3;
 static constexpr int ThrdError = 4;
+static constexpr int ThrdPermission = 5;
 
 static constexpr int CppDeviceOrResourceBusy = 0;
 static constexpr int CppInvalidArgument = 1;
+static constexpr int CppOperationNotPermitted = 4;
 static constexpr int CppResourceUnavailableTryAgain = 6;
 
 [[noreturn]] void ThrowCppError_nid_no_patch(int code);
 
-[[noreturn]] void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code) {
+void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code) {
     switch (code) {
     case ThrdNomem:
     case ThrdTimedout:
@@ -148,8 +150,10 @@ static constexpr int CppResourceUnavailableTryAgain = 6;
         ThrowCppError_nid_no_patch(CppDeviceOrResourceBusy);
     case ThrdError:
         ThrowCppError_nid_no_patch(CppInvalidArgument);
+    case ThrdPermission:
+        ThrowCppError_nid_no_patch(CppOperationNotPermitted);
     default:
-        throw std::out_of_range("_Throw_C_error: " + std::to_string(code) + " is not a _Thrd_t error code");
+        return;
     }
 }
 
diff --git a/core/libs/tests/GuestAmprCppError.cpp b/core/libs/tests/GuestAmprCppError.cpp
index 871f3dae09c30e8aadab1ee14f798649cf834ef4..70202a9c9276e55d72b332a68c9207b0418cc245 100644
--- a/core/libs/tests/GuestAmprCppError.cpp
+++ b/core/libs/tests/GuestAmprCppError.cpp
@@ -7,6 +7,7 @@
 #include <cstdlib>
 #include <cstring>
 #include <iterator>
+#include <limits>
 #include <stdexcept>
 #include <string>
 
@@ -41,7 +42,7 @@ extern const unsigned char _ZTISt11logic_error_nid_postfix[];
 extern const unsigned char _ZTISt13runtime_error_nid_postfix[];
 extern const unsigned char _ZTISt12system_error_nid_postfix[];
 [[noreturn]] void APS5_VABI _ZSt16_Throw_Cpp_errori_nid_postfix(int code);
-[[noreturn]] void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code);
+void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code);
 void APS5_VABI _ZNSt12system_errorC1ERKS__nid_postfix(SystemError* self, const SystemError* source);
 SystemError* APS5_VABI _ZNSt12system_erroraSERKS__nid_postfix(SystemError* self, const SystemError* source);
 void APS5_VABI _ZNSt12system_errorD1Ev_nid_postfix(SystemError* self);
@@ -160,14 +161,13 @@ static void CheckOutOfRange(int code) {
     Require(threw, 3);
 }
 
-static void CheckCErrorOutOfRange(int code) {
-    bool threw = false;
+static void CheckCErrorReturns(int code) {
     try {
         _ZSt14_Throw_C_errori_nid_postfix(code);
-    } catch (const std::out_of_range& error) {
-        threw = std::string(error.what()).find(std::to_string(code)) != std::string::npos;
+    } catch (...) {
+        std::fprintf(stderr, "guest _Throw_C_error unexpectedly threw for %d\n", code);
+        FixtureFail(6);
     }
-    Require(threw, 6);
 }
 
 int main() {
@@ -185,9 +185,9 @@ int main() {
     CatchCError(_ZTISt12system_error_nid_postfix, 4, 1);
     CatchCError(_ZTISt13runtime_error_nid_postfix, 3, 0);
     CatchCError(_ZTISt9exception_nid_postfix, 4, 1);
-    CheckCErrorOutOfRange(-1);
-    CheckCErrorOutOfRange(0);
-    CheckCErrorOutOfRange(5);
+    const std::array returnCodes {std::numeric_limits<int>::min(), -1, 0, 6, std::numeric_limits<int>::max()};
+    for (const int code : returnCodes) CheckCErrorReturns(code);
+    CatchCError(_ZTISt12system_error_nid_postfix, 5, 4);
     std::puts("guest _Throw_Cpp_error and _Throw_C_error system_error, generic category and range: PASS");
     return 0;
 }
diff --git a/docs/dev/debt/libc.md b/docs/dev/debt/libc.md
index a7dc2937ab10c6def85406ff6ea765e3c545cdb0..088c8e3c07dab6ee68c99d32fe66e4ac7ca5f7a8 100644
--- a/docs/dev/debt/libc.md
+++ b/docs/dev/debt/libc.md
@@ -38,7 +38,7 @@
 - [set_constraint_handler_s](../../../core/libs/prx/libc/src/WideConversion.cpp) (libc, re-exported by libSceAmpr) - the default handler is assumed to abort; each module keeps its own handler state, so a handler set through one library is not seen by the other. `ctime_s` and `asctime_s` follow the Dinkumware 26-byte format with `EINVAL` for a buffer under 26 bytes, a null pointer or an out-of-range weekday/month; `ctime_s` uses the guest time zone of `localtime_s`, and the console's exact checks are not verified
 - [__udivti3](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc, re-exported by libSceAmpr) - the hardware traps on a zero divisor; this throws instead
 - [__umodti3](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc) - the hardware traps on a zero divisor; this throws instead
-- [std::_Throw_C_error](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc) follows Dinkumware's `thread0.cpp` as shipped with [Visual C++ 2013](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/thread0.cpp) and in [microsoft/STL](https://github.com/microsoft/STL/blob/da52dc0fcadbd83690cfd1ed32408d2847439493/stl/src/thread0.cpp), without console verification: maps `_Thrd_nomem` (1) and `_Thrd_timedout` (2) to `_Cpp_error` 6 (`resource_unavailable_try_again`), `_Thrd_busy` (3) to 0 (`device_or_resource_busy`), and `_Thrd_error` (4) to 1 (`invalid_argument`) through `std::_Throw_Cpp_error`, and throws `std::out_of_range` on the host for any other code where VC12 calls `abort()`
+- [std::_Throw_C_error](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc) follows disassembly of PRAGMATA's (PPSA02530) bundled `libc.prx`: maps 1 and 2 to generic error 35 (`resource_unavailable_try_again`), 3 to 16 (`device_or_resource_busy`), 4 to 22 (`invalid_argument`), and 5 to 1 (`operation_not_permitted`), throwing a guest `std::system_error` through the existing C++ error helper. Other values return without throwing. Other SDK versions have not been inspected
 - [__modti3](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc) - the hardware traps on a zero divisor; this throws instead
 
 ### Functional
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6269342411 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7648#issuecomment-6269342411). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-19T14:14:58Z. --- I compared this exact head (`16ee65bed011d4f21bc798ddfe5a0b49014fcae4`) with `std::_Throw_C_error` in the `libc.prx` bundled with PRAGMATA (PPSA02530). Its NID is `bRujIheWlB0`; original virtual address `0x15f20`, ELF symbol size 256 bytes. The original SELF SHA-256 is `03f2202ca1cbd497e136bc47a91e65677b0e8d7e4ae0fe3dea67b0e8f7b609cf`. I checked that all 256 function bytes match the existing converted PE used for disassembly. This PS5 version differs from the VC12 contract in two places: - Input `5` throws guest `std::system_error` with `generic_category`, error value `1`, and the prefix `operation not permitted`. - Values outside `1..5` return. The function starts with `dec edi; cmp edi, 4; jbe dispatch`, followed by the register restores and `ret` for the other values. This also means its `[[noreturn]]` declarations should be removed. The jump-table mapping is `1/2 -> 35`, `3 -> 16`, `4 -> 22`, `5 -> 1`. The type passed to `__cxa_throw` is `_ZTISt12system_error`; the category getter is `_ZSt16generic_categoryv`. I prepared a small follow-up patch against your head. It reuses `ThrowCppError_nid_no_patch(4)` for input 5 and updates the existing guest ABI fixture to check the system_error payload/category and normal returns for INT_MIN, -1, 0, 6 and INT_MAX. The same regression test fails against the original PR implementation and passes with the fix. This is based on the bundled PS5 binary; I have not established behavior for other SDK versions. Local verification: Windows 11 10.0.26300, Ryzen 9 7900X, 32 GB RAM, MinGW-w64 GCC 15.2.0, Release. Full native build passed. `patched_libraries`, `guest_ampr_markers`, `guest_amm_placement`, `guest_ampr_threads`, `guest_ampr_cpp_error` and `guest_unwind_module_info`: 6/6 passed, no failures or skips. The regression-only fixture fails against your original production code at INT_MIN; the identical fixture passes with this patch. The relevant library hashes remain unchanged after committing, and the final post-commit library-loading check passed again. Conventions and whitespace checks passed. Linux and a game run were not tested. AI-assisted: yes. <details> <summary>Follow-up patch against 16ee65bed011d4f21bc798ddfe5a0b49014fcae4</summary> ```diff diff --git a/core/libs/prx/libSceAmpr/Export.cpp b/core/libs/prx/libSceAmpr/Export.cpp index 3ec4e8ebbc720a72f469ce06024dbbe61a5986f7..db174400346e9c67de8ffe7c7c7d2b957bddd49f 100644 --- a/core/libs/prx/libSceAmpr/Export.cpp +++ b/core/libs/prx/libSceAmpr/Export.cpp @@ -272,7 +272,7 @@ int APS5_VABI wcsrtombs_s_nid_postfix(std::size_t* result, char* destination, st int APS5_VABI _Cnd_init_nid_postfix(void** handle); int SignalCondition_nid_no_patch(void** handle); [[noreturn]] void ThrowCppError_nid_no_patch(int code); -[[noreturn]] void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code); +void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code); } static void RequireThrd(int result) { diff --git a/core/libs/prx/libc/src/RuntimeSupport.cpp b/core/libs/prx/libc/src/RuntimeSupport.cpp index eb5c97088393337d3a90790e3073df4c460d36a5..bdfd9a282cdf7c605afb7378a6fc931d8cdf5f97 100644 --- a/core/libs/prx/libc/src/RuntimeSupport.cpp +++ b/core/libs/prx/libc/src/RuntimeSupport.cpp @@ -132,14 +132,16 @@ static constexpr int ThrdNomem = 1; static constexpr int ThrdTimedout = 2; static constexpr int ThrdBusy = 3; static constexpr int ThrdError = 4; +static constexpr int ThrdPermission = 5; static constexpr int CppDeviceOrResourceBusy = 0; static constexpr int CppInvalidArgument = 1; +static constexpr int CppOperationNotPermitted = 4; static constexpr int CppResourceUnavailableTryAgain = 6; [[noreturn]] void ThrowCppError_nid_no_patch(int code); -[[noreturn]] void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code) { +void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code) { switch (code) { case ThrdNomem: case ThrdTimedout: @@ -148,8 +150,10 @@ static constexpr int CppResourceUnavailableTryAgain = 6; ThrowCppError_nid_no_patch(CppDeviceOrResourceBusy); case ThrdError: ThrowCppError_nid_no_patch(CppInvalidArgument); + case ThrdPermission: + ThrowCppError_nid_no_patch(CppOperationNotPermitted); default: - throw std::out_of_range("_Throw_C_error: " + std::to_string(code) + " is not a _Thrd_t error code"); + return; } } diff --git a/core/libs/tests/GuestAmprCppError.cpp b/core/libs/tests/GuestAmprCppError.cpp index 871f3dae09c30e8aadab1ee14f798649cf834ef4..70202a9c9276e55d72b332a68c9207b0418cc245 100644 --- a/core/libs/tests/GuestAmprCppError.cpp +++ b/core/libs/tests/GuestAmprCppError.cpp @@ -7,6 +7,7 @@ #include <cstdlib> #include <cstring> #include <iterator> +#include <limits> #include <stdexcept> #include <string> @@ -41,7 +42,7 @@ extern const unsigned char _ZTISt11logic_error_nid_postfix[]; extern const unsigned char _ZTISt13runtime_error_nid_postfix[]; extern const unsigned char _ZTISt12system_error_nid_postfix[]; [[noreturn]] void APS5_VABI _ZSt16_Throw_Cpp_errori_nid_postfix(int code); -[[noreturn]] void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code); +void APS5_VABI _ZSt14_Throw_C_errori_nid_postfix(int code); void APS5_VABI _ZNSt12system_errorC1ERKS__nid_postfix(SystemError* self, const SystemError* source); SystemError* APS5_VABI _ZNSt12system_erroraSERKS__nid_postfix(SystemError* self, const SystemError* source); void APS5_VABI _ZNSt12system_errorD1Ev_nid_postfix(SystemError* self); @@ -160,14 +161,13 @@ static void CheckOutOfRange(int code) { Require(threw, 3); } -static void CheckCErrorOutOfRange(int code) { - bool threw = false; +static void CheckCErrorReturns(int code) { try { _ZSt14_Throw_C_errori_nid_postfix(code); - } catch (const std::out_of_range& error) { - threw = std::string(error.what()).find(std::to_string(code)) != std::string::npos; + } catch (...) { + std::fprintf(stderr, "guest _Throw_C_error unexpectedly threw for %d\n", code); + FixtureFail(6); } - Require(threw, 6); } int main() { @@ -185,9 +185,9 @@ int main() { CatchCError(_ZTISt12system_error_nid_postfix, 4, 1); CatchCError(_ZTISt13runtime_error_nid_postfix, 3, 0); CatchCError(_ZTISt9exception_nid_postfix, 4, 1); - CheckCErrorOutOfRange(-1); - CheckCErrorOutOfRange(0); - CheckCErrorOutOfRange(5); + const std::array returnCodes {std::numeric_limits<int>::min(), -1, 0, 6, std::numeric_limits<int>::max()}; + for (const int code : returnCodes) CheckCErrorReturns(code); + CatchCError(_ZTISt12system_error_nid_postfix, 5, 4); std::puts("guest _Throw_Cpp_error and _Throw_C_error system_error, generic category and range: PASS"); return 0; } diff --git a/docs/dev/debt/libc.md b/docs/dev/debt/libc.md index a7dc2937ab10c6def85406ff6ea765e3c545cdb0..088c8e3c07dab6ee68c99d32fe66e4ac7ca5f7a8 100644 --- a/docs/dev/debt/libc.md +++ b/docs/dev/debt/libc.md @@ -38,7 +38,7 @@ - [set_constraint_handler_s](../../../core/libs/prx/libc/src/WideConversion.cpp) (libc, re-exported by libSceAmpr) - the default handler is assumed to abort; each module keeps its own handler state, so a handler set through one library is not seen by the other. `ctime_s` and `asctime_s` follow the Dinkumware 26-byte format with `EINVAL` for a buffer under 26 bytes, a null pointer or an out-of-range weekday/month; `ctime_s` uses the guest time zone of `localtime_s`, and the console's exact checks are not verified - [__udivti3](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc, re-exported by libSceAmpr) - the hardware traps on a zero divisor; this throws instead - [__umodti3](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc) - the hardware traps on a zero divisor; this throws instead -- [std::_Throw_C_error](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc) follows Dinkumware's `thread0.cpp` as shipped with [Visual C++ 2013](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/thread0.cpp) and in [microsoft/STL](https://github.com/microsoft/STL/blob/da52dc0fcadbd83690cfd1ed32408d2847439493/stl/src/thread0.cpp), without console verification: maps `_Thrd_nomem` (1) and `_Thrd_timedout` (2) to `_Cpp_error` 6 (`resource_unavailable_try_again`), `_Thrd_busy` (3) to 0 (`device_or_resource_busy`), and `_Thrd_error` (4) to 1 (`invalid_argument`) through `std::_Throw_Cpp_error`, and throws `std::out_of_range` on the host for any other code where VC12 calls `abort()` +- [std::_Throw_C_error](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc) follows disassembly of PRAGMATA's (PPSA02530) bundled `libc.prx`: maps 1 and 2 to generic error 35 (`resource_unavailable_try_again`), 3 to 16 (`device_or_resource_busy`), 4 to 22 (`invalid_argument`), and 5 to 1 (`operation_not_permitted`), throwing a guest `std::system_error` through the existing C++ error helper. Other values return without throwing. Other SDK versions have not been inspected - [__modti3](../../../core/libs/prx/libc/src/RuntimeSupport.cpp) (libc) - the hardware traps on a zero divisor; this throws instead ### Functional ``` </details>
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!7648
No description provided.