feat(libc): cross pltaform build

This commit is contained in:
boykopovar
2026-09-08 09:08:00 +03:00
parent fba8da58a2
commit fca5dc8782
7 changed files with 54 additions and 9 deletions
@@ -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 {};
@@ -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
@@ -1,6 +1,39 @@
#ifndef CORE_LIBS_PRX_LIBC_INCLUDE_ITANIUM_UNWINDABI_HPP
#define CORE_LIBS_PRX_LIBC_INCLUDE_ITANIUM_UNWINDABI_HPP
#include <unwind.h>
#include <cstdint>
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
+3 -2
View File
@@ -1,5 +1,8 @@
#include "prx/libc/include/exceptions/Runtime.hpp"
#include <cstddef>
#ifndef _UNWIND_H
#define _UNWIND_H
#endif
#include <cxxabi.h>
#include <cstdint>
#include <cstdlib>
@@ -12,8 +15,6 @@
#include <locale>
#include <regex>
#include <functional>
#include <unwind.h>
extern "C" {
void* __cxa_demangle_nid_postfix(const char* mangled, char* buf, std::size_t* len, int* status) {
+3
View File
@@ -5,6 +5,7 @@
#include <memory>
#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<FileStream>(handle.get(), true);
handle.release();
std::fprintf(stderr, "fopen success: \"%s\"\n", filename);
return stream.release();
}
+1 -1
View File
@@ -179,8 +179,8 @@ void* __cxa_allocate_exception_nid_postfix(std::size_t size) {
if (size > std::numeric_limits<std::size_t>::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) {
@@ -1,12 +1,10 @@
#if !defined(__linux__) || !defined(__x86_64__)
#error "This file is x86_64 Linux only"
#endif
#include <cstdint>
#include <cstdlib>
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