Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions core/libs/prx/libSceLibcInternal/ExceptionDestructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ void APS5_VABI sceLibcInternalUnderflowErrorBaseDestructor_nid_no_patch(void* se
}
APS5_EXPORT("xiqd+QkuYXc", sceLibcInternalUnderflowErrorBaseDestructor_nid_no_patch);

void APS5_VABI sceLibcInternalFutureErrorDeletingDestructor_nid_no_patch(void* self) {
_ZNSt12future_errorD1Ev_nid_postfix(static_cast<LibcException::FutureErrorObject*>(self));
_ZdlPv_nid_postfix(self);
}
APS5_EXPORT("rNYLEsL7M0k", sceLibcInternalFutureErrorDeletingDestructor_nid_no_patch);

void APS5_VABI sceLibcInternalOverflowErrorDeletingDestructor_nid_no_patch(void* self) {
_ZNSt14overflow_errorD1Ev_nid_postfix(static_cast<LibcException::ExceptionObject*>(self));
_ZdlPv_nid_postfix(self);
}
APS5_EXPORT("y1dYQsc67ys", sceLibcInternalOverflowErrorDeletingDestructor_nid_no_patch);

void APS5_VABI sceLibcInternalUnderflowErrorDeletingDestructor_nid_no_patch(void* self) {
_ZNSt15underflow_errorD1Ev_nid_postfix(static_cast<LibcException::ExceptionObject*>(self));
_ZdlPv_nid_postfix(self);
}
APS5_EXPORT("iHILAmwYRGY", sceLibcInternalUnderflowErrorDeletingDestructor_nid_no_patch);

void APS5_VABI sceLibcInternalFutureErrorCategoryDeletingDestructor_nid_no_patch(void* self) {
_ZNSt14error_categoryD2Ev_nid_postfix(static_cast<LibcException::CategoryObject*>(self));
_ZdlPv_nid_postfix(self);
Expand Down
5 changes: 0 additions & 5 deletions core/libs/prx/libSceLibcInternal/InventoryExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ int APS5_VABI libSceLibcInternalInventory_016_nid_no_patch() {
}
APS5_EXPORT("uVOxy7dQTFc", libSceLibcInternalInventory_016_nid_no_patch);

int APS5_VABI libSceLibcInternalInventory_017_nid_no_patch() {
NotImplemented_nid_no_patch(__func__);
}
APS5_EXPORT("rNYLEsL7M0k", libSceLibcInternalInventory_017_nid_no_patch);

void APS5_VABI libSceLibcInternalInventory_019_nid_no_patch(LibcException::SystemErrorObject* self, LibcException::ErrorCode code, const char* message) {
LibcExceptionConstructSystemError_nid_no_patch(self, code, message);
}
Expand Down
12 changes: 0 additions & 12 deletions core/libs/prx/libSceLibcInternal/InventoryExports6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,12 @@ void APS5_VABI sceLibcInternalUnknown6_041_to7GggwECZU_nid_no_patch(void* self)
}
APS5_EXPORT("to7GggwECZU", sceLibcInternalUnknown6_041_to7GggwECZU_nid_no_patch);

int APS5_VABI sceLibcInternalUnknown6_043_iHILAmwYRGY_nid_no_patch() {
NotImplemented_nid_no_patch(__func__);
return 0;
}
APS5_EXPORT("iHILAmwYRGY", sceLibcInternalUnknown6_043_iHILAmwYRGY_nid_no_patch);

int APS5_VABI sceLibcInternalUnknown6_044_raRgiuQfvWk_nid_no_patch() {
NotImplemented_nid_no_patch(__func__);
return 0;
}
APS5_EXPORT("raRgiuQfvWk", sceLibcInternalUnknown6_044_raRgiuQfvWk_nid_no_patch);

int APS5_VABI sceLibcInternalUnknown6_045_y1dYQsc67ys_nid_no_patch() {
NotImplemented_nid_no_patch(__func__);
return 0;
}
APS5_EXPORT("y1dYQsc67ys", sceLibcInternalUnknown6_045_y1dYQsc67ys_nid_no_patch);

int APS5_VABI sceLibcInternalUnknown6_046_6b3KIjPD33k_nid_no_patch() {
NotImplemented_nid_no_patch(__func__);
return 0;
Expand Down
3 changes: 3 additions & 0 deletions core/libs/prx/libSceLibcInternal/include/Api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ const std::error_category* APS5_VABI sceLibcInternalIostreamCategory_nid_no_patc
void APS5_VABI sceLibcInternalFutureErrorBaseDestructor_nid_no_patch(void* self);
void APS5_VABI sceLibcInternalOverflowErrorBaseDestructor_nid_no_patch(void* self);
void APS5_VABI sceLibcInternalUnderflowErrorBaseDestructor_nid_no_patch(void* self);
void APS5_VABI sceLibcInternalFutureErrorDeletingDestructor_nid_no_patch(void* self);
void APS5_VABI sceLibcInternalOverflowErrorDeletingDestructor_nid_no_patch(void* self);
void APS5_VABI sceLibcInternalUnderflowErrorDeletingDestructor_nid_no_patch(void* self);
void APS5_VABI sceLibcInternalFutureErrorCategoryDeletingDestructor_nid_no_patch(void* self);
void APS5_VABI sceLibcInternalSystemErrorCategoryDeletingDestructor_nid_no_patch(void* self);
void APS5_VABI sceLibcInternalSystemErrorCategoryDestructor_nid_no_patch(void* self);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ int APS5_VABI libSceLibcInternalInventory_013_nid_no_patch();
int APS5_VABI libSceLibcInternalInventory_014_nid_no_patch();
int APS5_VABI libSceLibcInternalInventory_015_nid_no_patch();
int APS5_VABI libSceLibcInternalInventory_016_nid_no_patch();
int APS5_VABI libSceLibcInternalInventory_017_nid_no_patch();
void APS5_VABI libSceLibcInternalInventory_019_nid_no_patch(LibcException::SystemErrorObject* self, LibcException::ErrorCode code, const char* message);
void APS5_VABI libSceLibcInternalInventory_021_nid_no_patch(void* self);
void APS5_VABI libSceLibcInternalInventory_022_nid_no_patch(void* self);
Expand Down
28 changes: 27 additions & 1 deletion core/libs/tests/GuestLibcInternalExceptionDestructors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <new>

namespace {

unsigned releases = 0;
void* lastReleased = nullptr;
std::array<void*, 4> released{};

void Require(bool condition, const char* message) {
if (condition) return;
Expand All @@ -23,6 +25,7 @@ void Require(bool condition, const char* message) {

void* APS5_VABI TestAllocate(std::size_t size) { return std::malloc(size); }
void APS5_VABI TestFree(void* pointer) {
if (releases < released.size()) released[releases] = pointer;
++releases;
lastReleased = pointer;
std::free(pointer);
Expand Down Expand Up @@ -77,6 +80,26 @@ void CheckFutureError() {
Require(std::memcmp(&expected, &actual, sizeof(expected)) == 0, "D2 leaves the object as D1 does");
}

void CheckMessageDeletingDestructor(Destructor destructor, const char* text) {
auto* object = static_cast<LibcException::ExceptionObject*>(_Znwm_nid_postfix(sizeof(LibcException::ExceptionObject)));
_ZNSt13runtime_errorC1EPKc_nid_postfix(object, text);
releases = 0;
destructor(object);
Require(releases == 1 && released[0] == object, "the deleting destructor frees the object through operator delete");
}

void CheckFutureErrorDeletingDestructor() {
auto* object = new (_Znwm_nid_postfix(sizeof(LibcException::FutureErrorObject))) LibcException::FutureErrorObject{};
object->message.capacity = 24;
object->message.size = 24;
object->message.pointer = static_cast<char*>(_Znwm_nid_postfix(25));
std::memcpy(object->message.pointer, "future already retrieved", 25);
char* storage = object->message.pointer;
releases = 0;
sceLibcInternalFutureErrorDeletingDestructor_nid_no_patch(object);
Require(releases == 2 && released[0] == storage && released[1] == object, "the message and then the object are freed");
}

}

GuestLocale::String* APS5_VABI TestCategoryMessage(GuestLocale::String* result, const LibcException::CategoryObject*, int) {
Expand Down Expand Up @@ -121,7 +144,10 @@ int main() {
CheckMessageDestructor(&sceLibcInternalOverflowErrorBaseDestructor_nid_no_patch, "value too large");
CheckMessageDestructor(&sceLibcInternalUnderflowErrorBaseDestructor_nid_no_patch, "value too small");
CheckFutureError();
CheckMessageDeletingDestructor(&sceLibcInternalOverflowErrorDeletingDestructor_nid_no_patch, "value too large");
CheckMessageDeletingDestructor(&sceLibcInternalUnderflowErrorDeletingDestructor_nid_no_patch, "value too small");
CheckFutureErrorDeletingDestructor();

std::puts("libc internal exception base-object destructor checks passed");
std::puts("libc internal exception destructor checks passed");
return 0;
}
3 changes: 1 addition & 2 deletions docs/dev/debt/libSceLibcInternal.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ The five `std::ctype<wchar_t>` operations `do_is` (NIDs `rh7L-TliPoc`, `D0lUMKU+
- [std::_Get_future_error_what](../../../core/libs/prx/libSceLibcInternal/ConstantMembers.cpp) (libSceLibcInternal, NID `cPNeOAYgB0A`) was not compared with the console's `libSceLibcInternal.sprx` and no title was seen calling it. It returns the strings `libc.prx` gives `future_error::what()` in [StandardExceptions.cpp](../../../core/libs/prx/libc/src/exception/StandardExceptions.cpp) for 1 to 4 and null for every other value; the `const char*(int)` prototype is the demangled name's with the return type of Dinkumware `<future>`
- [std::_Future_error_map](../../../core/libs/prx/libSceLibcInternal/ConstantMembers.cpp) (libSceLibcInternal, NID `0r8rbw2SFqk`) was not compared with the console's `libSceLibcInternal.sprx` and no title was seen calling it. It is the Microsoft STL's [_Future_error_map](https://github.com/microsoft/STL/blob/54d74d7a58e828857a73f979eccc2ba1c02e256d/stl/inc/future#L97-L114): the four `future_errc` names for 1 to 4 and null for every other value, the same pointers `std::_Get_future_error_what` returns here
- [_ZNSt12future_errorD2Ev, _ZNSt14overflow_errorD2Ev and _ZNSt15underflow_errorD2Ev](../../../core/libs/prx/libSceLibcInternal/ExceptionDestructors.cpp) (libSceLibcInternal, NIDs `XFh0C66aEms`, `OypvNf3Uq3c` and `xiqd+QkuYXc`) are the base-object destructors of classes without virtual bases, which the [Itanium C++ ABI](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#definitions) makes do the same work as the complete-object `D1` destructors, so they run the `libc` exports of those `D1` names. The console's `libSceLibcInternal.sprx` was not read and no title was seen calling them, so whether it frees the message from the same heap as `libc.prx` is unverified
- [_ZNSt12future_errorD0Ev, _ZNSt14overflow_errorD0Ev, _ZNSt15underflow_errorD0Ev](../../../core/libs/prx/libSceLibcInternal/ExceptionDestructors.cpp) (libSceLibcInternal, NIDs `rNYLEsL7M0k`, `y1dYQsc67ys`, `iHILAmwYRGY`) are the deleting destructors: the [Itanium C++ ABI](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#definitions) defines them as the complete-object destructor followed by the class's `operator delete`, so each runs the `libc` `D1` export of its class and then `operator delete` (`_ZdlPv`, the application heap); none of these classes declares its own `operator delete`. libc's own `D0` exports of the other exception classes free with `std::free`; this entry does not change them. The console's `libSceLibcInternal.sprx` was not read and no title was seen calling them
- [_ZNSt22_Future_error_categoryD0Ev, _ZNSt22_System_error_categoryD0Ev, _ZNSt22_System_error_categoryD1Ev and _ZNSt23_Generic_error_categoryD1Ev](../../../core/libs/prx/libSceLibcInternal/ExceptionDestructors.cpp) (libSceLibcInternal, NIDs `WDKzMM-uuLE`, `Dc4ZMWmPMl8`, `hVQgfGhJz3U` and `MAalgQhejPc`): the console's `libSceLibcInternal.sprx` was not read and no title was seen calling them. The [system_error](https://github.com/microsoft/STL/blob/54d74d7a58e828857a73f979eccc2ba1c02e256d/stl/inc/system_error#L91) gives `error_category` a defaulted virtual destructor and the derived categories none, so `D1` runs the `libc` export `_ZNSt14error_categoryD2Ev`, which frees nothing, and `D0` runs it and then `_ZdlPv`, as the [Itanium C++ ABI](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#definitions) deleting destructor does. The category objects `libc` returns are static, so their own vtable delete slots still throw, and an exported `D0` on one of them is undefined
- [_ZNSt22_Future_error_categoryD1Ev and _ZNSt23_Generic_error_categoryD0Ev](../../../core/libs/prx/libSceLibcInternal/ExceptionDestructors.cpp) (libSceLibcInternal, NIDs `xsXQD5ybREw` and `YBrp9BlADaA`) follow the entry above: `_Future_error_category` derives from `_Generic_error_category`, which derives from `error_category`, and neither adds a member, so `D1` runs the `libc` export `_ZNSt14error_categoryD2Ev` and `D0` runs it and then `_ZdlPv`. The console's `libSceLibcInternal.sprx` was not read and no title was seen calling them. The `libc` category objects are static, so an exported `D0` on one of them is undefined
- [_ZNSt18bad_variant_accessD1Ev and _ZNSt18bad_variant_accessD0Ev](../../../core/libs/prx/libSceLibcInternal/ExceptionDestructors.cpp) (libSceLibcInternal, NIDs `U3b5A2LEiTc` and `8DNJW5tX-A8`): [LLVM libc++](https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/libcxx/include/variant#L270-L273) derives `bad_variant_access` from `exception` with no member and only a `what()` override, so `D1` runs the `libc` export `_ZNSt9exceptionD2Ev`, which frees nothing, and `D0` runs it and then `_ZdlPv`, as the [Itanium C++ ABI](https://itanium-cxx-abi.github.io/cxx-abi/abi.html#definitions) deleting destructor does. `libc`'s own `_ZNSt9exceptionD0Ev` and the delete slot of `_ZTVSt18bad_variant_access` free with the host `free`, while guest `operator new` allocates from the application heap, so `D0` is not forwarded to them. The console's `libSceLibcInternal.sprx` was not read and no title was seen calling them
Expand Down Expand Up @@ -566,9 +567,7 @@ The five `std::ctype<wchar_t>` operations `do_is` (NIDs `rh7L-TliPoc`, `D0lUMKU+
- [malloc_get_malloc_state](../../../core/libs/prx/libSceLibcInternal/InventoryExports6.cpp) (libSceLibcInternal, NID `Nmezc1Lh7TQ`) - listed in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c); signature and behavior are unverified, so this parameterless declaration is for import resolution only and throws through `NotImplemented_nid_no_patch`
- [_ZNSt8time_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEEC1Em](../../../core/libs/prx/libSceLibcInternal/InventoryExports6.cpp) (libSceLibcInternal, NID `X3DrtC2AZCI`) - listed in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c); signature and behavior are unverified, so this parameterless declaration is for import resolution only and throws through `NotImplemented_nid_no_patch`
- [_ZNSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEEC1EPKcm](../../../core/libs/prx/libSceLibcInternal/InventoryExports6.cpp) (libSceLibcInternal, NID `9pPbNXw5N9E`) - listed in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c); signature and behavior are unverified, so this parameterless declaration is for import resolution only and throws through `NotImplemented_nid_no_patch`
- [_ZNSt15underflow_errorD0Ev](../../../core/libs/prx/libSceLibcInternal/InventoryExports6.cpp) (libSceLibcInternal, NID `iHILAmwYRGY`) - listed in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c); signature and behavior are unverified, so this parameterless declaration is for import resolution only and throws through `NotImplemented_nid_no_patch`
- [sceLibcMspaceGetAddressRanges](../../../core/libs/prx/libSceLibcInternal/InventoryExports6.cpp) (libSceLibcInternal, NID `raRgiuQfvWk`) - listed in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c); signature and behavior are unverified, so this parameterless declaration is for import resolution only and throws through `NotImplemented_nid_no_patch`
- [_ZNSt14overflow_errorD0Ev](../../../core/libs/prx/libSceLibcInternal/InventoryExports6.cpp) (libSceLibcInternal, NID `y1dYQsc67ys`) - listed in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c); signature and behavior are unverified, so this parameterless declaration is for import resolution only and throws through `NotImplemented_nid_no_patch`
- [_ZNSt6locale7_LocimpC1Eb](../../../core/libs/prx/libSceLibcInternal/InventoryExports6.cpp) (libSceLibcInternal, NID `6b3KIjPD33k`) - listed in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c); signature and behavior are unverified, so this parameterless declaration is for import resolution only and throws through `NotImplemented_nid_no_patch`
- [malloc_report_memory_blocks](../../../core/libs/prx/libSceLibcInternal/InventoryExports6.cpp) (libSceLibcInternal, NID `0F08WOP8G3s`) - listed in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c); signature and behavior are unverified, so this parameterless declaration is for import resolution only and throws through `NotImplemented_nid_no_patch`
- [_ZNSt8numpunctIwE5_InitERKSt8_Locinfob](../../../core/libs/prx/libSceLibcInternal/InventoryExports6.cpp) (libSceLibcInternal, NID `uiRALKOdAZk`) - listed in the [PS5 3.20 export inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c); signature and behavior are unverified, so this parameterless declaration is for import resolution only and throws through `NotImplemented_nid_no_patch`
Expand Down
Loading