diff --git a/core/libs/prx/libc/include/exceptions/Runtime.hpp b/core/libs/prx/libc/include/exceptions/Runtime.hpp index 3ae027714..bb50789ba 100644 --- a/core/libs/prx/libc/include/exceptions/Runtime.hpp +++ b/core/libs/prx/libc/include/exceptions/Runtime.hpp @@ -15,6 +15,8 @@ struct Header { Header* next {}; int handlers {}; int selector {}; + std::uint32_t _pad {}; + std::uint32_t _pad2 {}; const unsigned char* action {}; const unsigned char* lsda {}; std::uintptr_t landing {}; diff --git a/core/libs/prx/libc/include/specifics/gcc/SymbolAlias.hpp b/core/libs/prx/libc/include/specifics/gcc/SymbolAlias.hpp index 7341db395..f42eb1802 100644 --- a/core/libs/prx/libc/include/specifics/gcc/SymbolAlias.hpp +++ b/core/libs/prx/libc/include/specifics/gcc/SymbolAlias.hpp @@ -1,11 +1,15 @@ #ifndef CORE_LIBS_PRX_LIBC_INCLUDE_GCC_SYMBOLALIAS_HPP #define CORE_LIBS_PRX_LIBC_INCLUDE_GCC_SYMBOLALIAS_HPP +#if defined(__linux__) #define GCC_LOCAL_ALIAS(alias, target) \ asm(".local " #alias "\n.set " #alias "," #target "\n") - #define GCC_GLOBAL_ALIAS(alias, target) \ asm(".globl " #alias "\n.set " #alias "," #target "\n") +#else +#define GCC_LOCAL_ALIAS(alias, target) +#define GCC_GLOBAL_ALIAS(alias, target) +#endif #define GCC_HIDDEN_FN diff --git a/core/libs/prx/libc/include/specifics/itanium/UnwindAbi.hpp b/core/libs/prx/libc/include/specifics/itanium/UnwindAbi.hpp index afe5b910e..4dc8ad4da 100644 --- a/core/libs/prx/libc/include/specifics/itanium/UnwindAbi.hpp +++ b/core/libs/prx/libc/include/specifics/itanium/UnwindAbi.hpp @@ -1,6 +1,39 @@ #ifndef CORE_LIBS_PRX_LIBC_INCLUDE_ITANIUM_UNWINDABI_HPP #define CORE_LIBS_PRX_LIBC_INCLUDE_ITANIUM_UNWINDABI_HPP -#include +#include + +using _Unwind_Word = std::uintptr_t; +using _Unwind_Ptr = std::uintptr_t; +using _Unwind_Reason_Code = int; +using _Unwind_Action = int; + +static constexpr _Unwind_Reason_Code _URC_NO_REASON = 0; +static constexpr _Unwind_Reason_Code _URC_FOREIGN_EXCEPTION_CAUGHT = 1; +static constexpr _Unwind_Reason_Code _URC_FATAL_PHASE2_ERROR = 2; +static constexpr _Unwind_Reason_Code _URC_FATAL_PHASE1_ERROR = 3; +static constexpr _Unwind_Reason_Code _URC_NORMAL_STOP = 4; +static constexpr _Unwind_Reason_Code _URC_END_OF_STACK = 5; +static constexpr _Unwind_Reason_Code _URC_HANDLER_FOUND = 6; +static constexpr _Unwind_Reason_Code _URC_INSTALL_CONTEXT = 7; +static constexpr _Unwind_Reason_Code _URC_CONTINUE_UNWIND = 8; + +static constexpr _Unwind_Action _UA_SEARCH_PHASE = 1; +static constexpr _Unwind_Action _UA_CLEANUP_PHASE = 2; +static constexpr _Unwind_Action _UA_HANDLER_FRAME = 4; +static constexpr _Unwind_Action _UA_FORCE_UNWIND = 8; +static constexpr _Unwind_Action _UA_END_OF_STACK = 16; + +struct _Unwind_Exception { + std::uint64_t exception_class; + void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Exception*); + std::uintptr_t private_1; + std::uintptr_t private_2; +}; + +struct _Unwind_Context; + +using _Unwind_Trace_Fn = _Unwind_Reason_Code (*)(_Unwind_Context*, void*); +using _Unwind_Stop_Fn = _Unwind_Reason_Code (*)(int, _Unwind_Action, std::uint64_t, _Unwind_Exception*, _Unwind_Context*, void*); #endif diff --git a/core/libs/prx/libc/src/CxxAbiSupport.cpp b/core/libs/prx/libc/src/CxxAbiSupport.cpp index edfa329fa..fa79d60a3 100644 --- a/core/libs/prx/libc/src/CxxAbiSupport.cpp +++ b/core/libs/prx/libc/src/CxxAbiSupport.cpp @@ -1,5 +1,8 @@ #include "prx/libc/include/exceptions/Runtime.hpp" #include +#ifndef _UNWIND_H +#define _UNWIND_H +#endif #include #include #include @@ -12,8 +15,6 @@ #include #include #include -#include - extern "C" { void* __cxa_demangle_nid_postfix(const char* mangled, char* buf, std::size_t* len, int* status) { diff --git a/core/libs/prx/libc/src/FileAndHeap.cpp b/core/libs/prx/libc/src/FileAndHeap.cpp index e2bf1e87a..be89114e7 100644 --- a/core/libs/prx/libc/src/FileAndHeap.cpp +++ b/core/libs/prx/libc/src/FileAndHeap.cpp @@ -5,6 +5,7 @@ #include #include "prx/libc/include/FileStream.hpp" + extern "C" { [[noreturn]] void _ZSt11_Xbad_allocv_nid_postfix(); @@ -21,6 +22,8 @@ FileStream* fopen_nid_postfix(const char* filename, const char* mode) { } auto stream = std::make_unique(handle.get(), true); handle.release(); + + std::fprintf(stderr, "fopen success: \"%s\"\n", filename); return stream.release(); } diff --git a/core/libs/prx/libc/src/exception/Runtime.cpp b/core/libs/prx/libc/src/exception/Runtime.cpp index 4539f6967..7328d4057 100644 --- a/core/libs/prx/libc/src/exception/Runtime.cpp +++ b/core/libs/prx/libc/src/exception/Runtime.cpp @@ -179,8 +179,8 @@ void* __cxa_allocate_exception_nid_postfix(std::size_t size) { if (size > std::numeric_limits::max() - sizeof(Allocation)) Terminate(); void* storage = std::malloc(sizeof(Allocation) + size); if (!storage) Terminate(); - auto* allocation = new (storage) Allocation; static_assert(offsetof(Allocation, header) + sizeof(Header) == sizeof(Allocation)); + auto* allocation = new (storage) Allocation; return &allocation->header + 1; } void __cxa_free_exception_nid_postfix(void* object) { diff --git a/core/libs/prx/libc/src/specifics/x86_64/RegisterContext.cpp b/core/libs/prx/libc/src/specifics/x86_64/RegisterContext.cpp index e67097bad..928b6b0ed 100644 --- a/core/libs/prx/libc/src/specifics/x86_64/RegisterContext.cpp +++ b/core/libs/prx/libc/src/specifics/x86_64/RegisterContext.cpp @@ -1,12 +1,10 @@ -#if !defined(__linux__) || !defined(__x86_64__) -#error "This file is x86_64 Linux only" -#endif - #include +#include extern "C" void LibcCaptureRegisters(std::uintptr_t*); extern "C" [[noreturn]] void LibcRestoreRegisters(const std::uintptr_t*); +#if defined(__linux__) && defined(__x86_64__) asm( ".text\n" ".hidden LibcCaptureRegisters\n" @@ -28,3 +26,7 @@ asm( "movq 104(%r10),%r13\nmovq 112(%r10),%r14\nmovq 120(%r10),%r15\njmp *%r11\n" ".size LibcRestoreRegisters,.-LibcRestoreRegisters\n" ); +#else +void LibcCaptureRegisters(std::uintptr_t*) { std::abort(); } +[[noreturn]] void LibcRestoreRegisters(const std::uintptr_t*) { std::abort(); } +#endif