feat(libc): export std::overflow_error type info, vtable and destructor

This commit is contained in:
Hannah Lyons 2026-10-12 05:20:17 -04:00
parent 9aa5fd2900
commit d316fcd8d5
3 changed files with 51 additions and 0 deletions

View File

@ -452,6 +452,15 @@ if(BUILD_TESTING)
set_tests_properties(guest_wcsrtombs_s PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
add_test_executable(guest_overflow_error_tests ${LIBS_INCLUDE_DIR}/tests/GuestOverflowError.cpp)
target_include_directories(guest_overflow_error_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_overflow_error_tests PRIVATE libc)
configure_windows_unwind(guest_overflow_error_tests)
add_test(NAME guest_overflow_error COMMAND guest_overflow_error_tests)
if(WIN32)
set_tests_properties(guest_overflow_error PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
if(UNIX)
add_test_executable(exception_runtime_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionRuntime.cpp)
target_include_directories(exception_runtime_tests PRIVATE ${LIBS_INCLUDE_DIR})

View File

@ -291,6 +291,10 @@ void APS5_VABI _ZNSt11range_errorD1Ev_nid_postfix(LibcException::ExceptionObject
void APS5_VABI _ZNSt11range_errorD2Ev_nid_postfix(LibcException::ExceptionObject* self) { LibcException::DestroyMessage(self); }
void APS5_VABI _ZNSt11range_errorD0Ev_nid_postfix(LibcException::ExceptionObject* self) { LibcException::DeleteMessage(self); }
LibcException::TypeRecord _ZTISt14overflow_error_nid_postfix {LibcException::SingleTypeVtable + 2, "St14overflow_error", &_ZTISt13runtime_error_nid_postfix};
LibcException::ExceptionVtable _ZTVSt14overflow_error_nid_postfix {0, &_ZTISt14overflow_error_nid_postfix, LibcException::GuestDestroyMessage_nid_no_patch, LibcException::GuestDeleteMessage_nid_no_patch, LibcException::GuestMessageWhat_nid_no_patch};
void APS5_VABI _ZNSt14overflow_errorD1Ev_nid_postfix(LibcException::ExceptionObject* self) { LibcException::DestroyMessage(self); }
LibcException::TypeRecord _ZTINSt8ios_base7failureE_nid_postfix {LibcException::SingleTypeVtable + 2, "NSt8ios_base7failureE", &_ZTISt12system_error_nid_postfix};
LibcException::ExceptionVtable _ZTVNSt8ios_base7failureE_nid_postfix {0, &_ZTINSt8ios_base7failureE_nid_postfix, LibcException::GuestDestroyMessage_nid_no_patch, LibcException::GuestDeleteMessage_nid_no_patch, LibcException::GuestMessageWhat_nid_no_patch};
void APS5_VABI _ZNSt8ios_base7failureD1Ev_nid_postfix(LibcException::ExceptionObject* self) { LibcException::DestroyMessage(self); }

View File

@ -0,0 +1,38 @@
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstddef>
#include <cstdlib>
#include <cstring>
struct TypeRecord { const void* const* vtable; const char* name; const TypeRecord* base; };
struct Object { const void* vtable; const char* message; };
struct Vtable { std::ptrdiff_t offset; const TypeRecord* type; const void* destroy; const void* deleteObject; const void* what; };
extern "C" {
extern const TypeRecord _ZTISt13runtime_error_nid_postfix;
extern const TypeRecord _ZTISt14overflow_error_nid_postfix;
extern const Vtable _ZTVSt13runtime_error_nid_postfix;
extern const Vtable _ZTVSt14overflow_error_nid_postfix;
void APS5_VABI _ZNSt13runtime_errorC1EPKc_nid_postfix(Object*, const char*);
void APS5_VABI _ZNSt14overflow_errorD1Ev_nid_postfix(Object*);
}
static void Require(bool value) { if (!value) std::abort(); }
int main() {
const auto& type = _ZTISt14overflow_error_nid_postfix;
const auto& runtimeType = _ZTISt13runtime_error_nid_postfix;
Require(std::strcmp(type.name, "St14overflow_error") == 0);
Require(type.base == &runtimeType && type.vtable == runtimeType.vtable);
const auto& table = _ZTVSt14overflow_error_nid_postfix;
const auto& runtimeTable = _ZTVSt13runtime_error_nid_postfix;
Require(table.offset == 0 && table.type == &type);
Require(table.destroy == runtimeTable.destroy && table.deleteObject == runtimeTable.deleteObject && table.what == runtimeTable.what);
Object object{};
_ZNSt13runtime_errorC1EPKc_nid_postfix(&object, "value too large");
Require(object.message != nullptr && std::strcmp(object.message, "value too large") == 0);
_ZNSt14overflow_errorD1Ev_nid_postfix(&object);
Require(object.message == nullptr);
_ZNSt14overflow_errorD1Ev_nid_postfix(&object);
Require(object.message == nullptr);
return 0;
}