Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7e1a34d
feat(libc): implement libc++ streambuf defaults
mihai1859 Nov 23, 2026
a272dbf
feat(libc): implement libc++ base streambuf seek defaults
mihai1859 Dec 1, 2026
76cc6ac
feat(libc): implement libc++ base streambuf transfers
mihai1859 Dec 2, 2026
be8fce5
fix(libc): preserve streambuf characters and partial transfers
mihai1859 Dec 2, 2026
13634ac
fix(libc): prepare buffered stream reads before validation
mihai1859 Dec 3, 2026
4cf582c
feat(libc): expose libc++ base streambuf locale hook and RTTI
mihai1859 Dec 2, 2026
cb78535
feat(libc): implement the libc++ streambuf base destructor
cmsierrave-coder Dec 3, 2026
d4135fa
test(libc): exercise the streambuf destructor through its vtable
cmsierrave-coder Dec 3, 2026
c7b4430
feat(libc): implement libc++ ios_base::failure and iostream_category
kiansaeidnia Nov 26, 2026
888c872
refactor(libc): share the libc++ ios_base layout
LeandroLP23 Dec 3, 2026
cd2c142
feat(libc): implement libc++ basic_ostream<char> core members
LeandroLP23 Dec 3, 2026
d8c3628
test(libc): build the ostream fixtures in place and describe null str…
LeandroLP23 Dec 3, 2026
6d0f8e1
feat(libc): expose libc++ input stream type information
mihai1859 Dec 3, 2026
bc6314e
feat(libc): expose narrow libc++ stream vtables
JJenkx Dec 5, 2026
cc91cc6
docs(libc): record the ios_base destructor vtable transition
JJenkx Dec 5, 2026
2016b6a
fix(libc): address narrow stream vtable review
JJenkx Dec 5, 2026
a404051
chore(libc): integrate narrow ostream dependencies
cmsierrave-coder Dec 6, 2026
1d14b66
chore(libc): integrate narrow streambuf lifecycle dependencies
cmsierrave-coder Dec 6, 2026
e530cbb
feat(libc): export narrow libc++ std::__1::cout and std::__1::cerr
cmsierrave-coder Dec 6, 2026
5dfa540
chore(libc): integrate current upstream ios_base field access
cmsierrave-coder Dec 6, 2026
face93f
test(libc): allow classic locale ids initialized by standard streams
cmsierrave-coder Dec 6, 2026
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
3 changes: 3 additions & 0 deletions core/libs/prx/libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ target_sources(libc PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxStringbuf.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxToStringFloat.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxStringbufSet.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxStreambufTransfer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxStreambufLifecycle.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/VectorAlgorithms.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Math.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MathGamma.cpp
Expand Down Expand Up @@ -280,6 +282,7 @@ target_sources(libc PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/AtomicWait.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxMutex.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxIosInit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxOstream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Rename.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Errors.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Syslog.cpp
Expand Down
11 changes: 11 additions & 0 deletions core/libs/prx/libc/include/Api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ struct SharedWeakCountRtti {

struct ExceptionObject { const void* vtable; const char* message; };

struct ClassTypeRecord { const void* vtable; const char* name; };

struct TypeRecord { const void* const* vtable; const char* name; const TypeRecord* base; };

struct BaseTypeRecord { const TypeRecord* type; std::int64_t offsetFlags; };
Expand Down Expand Up @@ -1934,6 +1936,13 @@ void APS5_VABI _ZNSt3__112system_errorC1ENS_10error_codeERKNS_12basic_stringIcNS
void APS5_VABI _ZNSt3__112system_errorD1Ev_nid_postfix(LibcException::LibcxxSystemErrorObject* self) noexcept;
void APS5_VABI _ZNSt3__112system_errorD2Ev_nid_postfix(LibcException::LibcxxSystemErrorObject* self) noexcept;
[[noreturn]] void APS5_VABI _ZNSt3__120__throw_system_errorEiPKc_nid_postfix(int value, const char* what);
const LibcException::CategoryObject* APS5_VABI _ZNSt3__117iostream_categoryEv_nid_postfix() noexcept;
extern const LibcException::TypeRecord _ZTINSt3__18ios_base7failureE_nid_postfix;
extern const LibcException::ExceptionVtable _ZTVNSt3__18ios_base7failureE_nid_postfix;
void APS5_VABI _ZNSt3__18ios_base7failureC1EPKcRKNS_10error_codeE_nid_postfix(LibcException::LibcxxSystemErrorObject* self, const char* what, const LibcException::LibcxxErrorCode* code);
void APS5_VABI _ZNSt3__18ios_base7failureC1ERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERKNS_10error_codeE_nid_postfix(LibcException::LibcxxSystemErrorObject* self, const void* what, const LibcException::LibcxxErrorCode* code);
void APS5_VABI _ZNSt3__18ios_base7failureD1Ev_nid_postfix(LibcException::LibcxxSystemErrorObject* self) noexcept;
void APS5_VABI _ZNSt3__18ios_base7failureD2Ev_nid_postfix(LibcException::LibcxxSystemErrorObject* self) noexcept;
void APS5_VABI _ZNSt11range_errorD1Ev_nid_postfix(LibcException::ExceptionObject* self);
void APS5_VABI _ZNSt11range_errorD2Ev_nid_postfix(LibcException::ExceptionObject* self);
void APS5_VABI _ZNSt11range_errorD0Ev_nid_postfix(LibcException::ExceptionObject* self);
Expand Down Expand Up @@ -2164,6 +2173,8 @@ extern const LibcException::MultipleTypeRecord<2> _ZTINSt3__17codecvtIcc11__mbst
void APS5_VABI _ZNSt3__16locale5facetD2Ev_nid_postfix(GuestLocale::LibcxxFacet* self);
void APS5_VABI _ZNSt3__16locale5facet16__on_zero_sharedEv_nid_postfix(GuestLocale::LibcxxFacet* self);
extern const LibcException::TypeRecord _ZTINSt3__16locale5facetE_nid_postfix;
void APS5_VABI _ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5imbueERKNS_6localeE_nid_postfix(void* self, const void* locale);
extern const LibcException::ClassTypeRecord _ZTINSt3__115basic_streambufIcNS_11char_traitsIcEEEE_nid_postfix;
std::int64_t APS5_VABI _ZNSt3__16locale2id5__getEv_nid_postfix(GuestLocale::LibcxxLocaleId* self);
extern GuestLocale::LibcxxLocaleId _ZNSt3__15ctypeIcE2idE_nid_postfix;
extern GuestLocale::LibcxxLocaleId _ZNSt3__17codecvtIcc11__mbstate_tE2idE_nid_postfix;
Expand Down
32 changes: 32 additions & 0 deletions core/libs/prx/libc/include/GuestLocale.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,38 @@ struct LibcxxLocale {

static_assert(sizeof(LibcxxLocale) == 0x8);

using LibcxxIosCallback = void (APS5_VABI*)(int event, void* stream, int index);

struct LibcxxIosBase {
const void* vtable;
std::uint32_t flags;
std::int64_t precision;
std::int64_t width;
std::uint32_t state;
std::uint32_t exceptions;
void* buffer;
LibcxxLocale locale;
const LibcxxIosCallback* callbacks;
const int* callbackIndexes;
std::uint64_t callbackCount;
std::uint64_t callbackCapacity;
void* integers;
std::uint64_t integerCount;
std::uint64_t integerCapacity;
void* pointers;
std::uint64_t pointerCount;
std::uint64_t pointerCapacity;
};

static_assert(offsetof(LibcxxIosBase, precision) == 0x10);
static_assert(offsetof(LibcxxIosBase, state) == 0x20);
static_assert(offsetof(LibcxxIosBase, buffer) == 0x28);
static_assert(offsetof(LibcxxIosBase, locale) == 0x30);
static_assert(offsetof(LibcxxIosBase, callbackCount) == 0x48);
static_assert(offsetof(LibcxxIosBase, integers) == 0x58);
static_assert(offsetof(LibcxxIosBase, pointers) == 0x70);
static_assert(sizeof(LibcxxIosBase) == 0x88);

struct CtypeFacet {
Facet base;
const std::int16_t* classification;
Expand Down
8 changes: 8 additions & 0 deletions core/libs/prx/libc/include/HostStandardStreams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
#include <stdio.h>
#endif

#ifdef __cplusplus
struct LibcxxStandardOstream;
extern "C" {
extern LibcxxStandardOstream _ZNSt3__14coutE_nid_postfix;
extern LibcxxStandardOstream _ZNSt3__14cerrE_nid_postfix;
}
#endif

#ifdef _WIN32
#undef stdout
#undef stderr
Expand Down
9 changes: 9 additions & 0 deletions core/libs/prx/libc/include/LibcxxIosInit.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#pragma once

#include "general/VabiMacros.hpp"
#include <cstdint>

extern "C" {

void APS5_VABI _ZNSt3__18ios_base4initEPv_nid_postfix(void* self, void* buffer);
void* APS5_VABI _ZNKSt3__18ios_base6getlocEv_nid_postfix(void* result, const void* self);
void* APS5_VABI _ZNSt3__18ios_base5imbueERKNS_6localeE_nid_postfix(void* result, void* self, const void* locale);
void APS5_VABI _ZNSt3__19basic_iosIcNS_11char_traitsIcEEED2Ev_nid_postfix(void* self);
void APS5_VABI _ZNSt3__18ios_base5clearEj_nid_postfix(void* self, std::uint32_t state);
void APS5_VABI _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryC1ERS3__nid_postfix(void* self, void* stream);
void APS5_VABI _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryD1Ev_nid_postfix(void* self);
void* APS5_VABI _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE3putEc_nid_postfix(void* self, char value);
void* APS5_VABI _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5writeEPKcl_nid_postfix(void* self, const char* data, std::int64_t count);
void* APS5_VABI _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5flushEv_nid_postfix(void* self);
void APS5_VABI _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEED1Ev_nid_postfix(void* self);
void APS5_VABI _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEED2Ev_nid_postfix(void* self, const void* const* vtt);

}
62 changes: 62 additions & 0 deletions core/libs/prx/libc/include/LibcxxStreamVtables.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

#include "general/VabiMacros.hpp"
#include <array>
#include <cstddef>

namespace LibcException {
struct TypeRecord;
template<std::size_t Count>
struct MultipleTypeRecord;
}

namespace GuestLocale {

using StreamDestructor = void (APS5_VABI*)(void*);

struct StreamDestructors {
StreamDestructor complete;
StreamDestructor deleting;
};

struct SimpleStreamVtable {
std::ptrdiff_t offsetToTop;
const void* type;
StreamDestructors destructors;
};

struct VirtualIosStreamVtable {
std::ptrdiff_t iosOffset;
SimpleStreamVtable primary;
std::ptrdiff_t iosVcallOffset;
SimpleStreamVtable secondary;
};

static_assert(offsetof(SimpleStreamVtable, destructors) == 0x10);
static_assert(sizeof(SimpleStreamVtable) == 0x20);
static_assert(offsetof(VirtualIosStreamVtable, primary) == 0x08);
static_assert(offsetof(VirtualIosStreamVtable, iosVcallOffset) == 0x28);
static_assert(offsetof(VirtualIosStreamVtable, secondary) == 0x30);
static_assert(sizeof(VirtualIosStreamVtable) == 0x50);

}

extern "C" {

extern const GuestLocale::SimpleStreamVtable _ZTVNSt3__18ios_baseE_nid_postfix;
extern const GuestLocale::SimpleStreamVtable _ZTVNSt3__19basic_iosIcNS_11char_traitsIcEEEE_nid_postfix;
extern const GuestLocale::VirtualIosStreamVtable _ZTVNSt3__113basic_ostreamIcNS_11char_traitsIcEEEE_nid_postfix;
extern const std::array<const void*, 2> _ZTTNSt3__113basic_ostreamIcNS_11char_traitsIcEEEE_nid_postfix;
extern const LibcException::TypeRecord _ZTINSt3__19basic_iosIcNS_11char_traitsIcEEEE_nid_postfix;
extern const LibcException::MultipleTypeRecord<1> _ZTINSt3__113basic_ostreamIcNS_11char_traitsIcEEEE_nid_postfix;

void APS5_VABI _ZNSt3__18ios_baseD0Ev_nid_postfix(void* self);
void APS5_VABI _ZNSt3__18ios_baseD1Ev_nid_postfix(void* self);
void APS5_VABI _ZNSt3__18ios_baseD2Ev_nid_postfix(void* self);
void APS5_VABI _ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev_nid_postfix(void* self);
void APS5_VABI _ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev_nid_postfix(void* self);
void APS5_VABI _ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEED0Ev_nid_postfix(void* self);
void APS5_VABI _ZTv0_n24_NSt3__113basic_ostreamIcNS_11char_traitsIcEEED0Ev_nid_postfix(void* self);
void APS5_VABI _ZTv0_n24_NSt3__113basic_ostreamIcNS_11char_traitsIcEEED1Ev_nid_postfix(void* self);

}
59 changes: 59 additions & 0 deletions core/libs/prx/libc/include/LibcxxStreambufTransfer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

#include "general/VabiMacros.hpp"
#include "prx/libc/include/GuestLocale.hpp"
#include "prx/libc/include/LibcxxStreamPosition.hpp"
#include <cstddef>
#include <cstdint>

struct LibcxxStreambuf;

struct LibcxxStreambufVtable {
void (APS5_VABI* destroy)(LibcxxStreambuf*);
void (APS5_VABI* deleteObject)(LibcxxStreambuf*);
void (APS5_VABI* imbue)(void*, const void*);
void* (APS5_VABI* setbuf)(void*, char*, std::int64_t);
LibcxxStreamPosition (APS5_VABI* seekoff)(void*, std::int64_t, std::int32_t, std::uint32_t);
LibcxxStreamPosition (APS5_VABI* seekpos)(void*, LibcxxStreamPosition, std::uint32_t);
int (APS5_VABI* sync)(void*);
std::int64_t (APS5_VABI* showmanyc)(void*);
std::int64_t (APS5_VABI* xsgetn)(LibcxxStreambuf*, char*, std::int64_t);
int (APS5_VABI* underflow)(void*);
int (APS5_VABI* uflow)(LibcxxStreambuf*);
int (APS5_VABI* pbackfail)(void*, int);
std::int64_t (APS5_VABI* xsputn)(LibcxxStreambuf*, const char*, std::int64_t);
int (APS5_VABI* overflow)(void*, int);
};

struct LibcxxStreambuf {
const LibcxxStreambufVtable* vtable;
GuestLocale::LibcxxLocale locale;
char* getStart;
char* getCurrent;
char* getEnd;
char* putStart;
char* putCurrent;
char* putEnd;
};

static_assert(sizeof(LibcxxStreambuf) == 64);
static_assert(offsetof(LibcxxStreambuf, vtable) == 0x00);
static_assert(offsetof(LibcxxStreambuf, locale) == 0x08);
static_assert(offsetof(LibcxxStreambuf, getStart) == 0x10);
static_assert(offsetof(LibcxxStreambuf, getCurrent) == 0x18);
static_assert(offsetof(LibcxxStreambuf, getEnd) == 0x20);
static_assert(offsetof(LibcxxStreambuf, putStart) == 0x28);
static_assert(offsetof(LibcxxStreambuf, putCurrent) == 0x30);
static_assert(offsetof(LibcxxStreambuf, putEnd) == 0x38);
static_assert(offsetof(LibcxxStreambufVtable, underflow) == 0x48);
static_assert(offsetof(LibcxxStreambufVtable, uflow) == 0x50);
static_assert(offsetof(LibcxxStreambufVtable, overflow) == 0x68);

extern "C" {

void APS5_VABI _ZNSt3__115basic_streambufIcNS_11char_traitsIcEEED2Ev_nid_postfix(LibcxxStreambuf* self);
int APS5_VABI _ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5uflowEv_nid_postfix(LibcxxStreambuf* self);
std::int64_t APS5_VABI _ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE6xsgetnEPcl_nid_postfix(LibcxxStreambuf* self, char* destination, std::int64_t count);
std::int64_t APS5_VABI _ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE6xsputnEPKcl_nid_postfix(LibcxxStreambuf* self, const char* source, std::int64_t count);

}
3 changes: 3 additions & 0 deletions core/libs/prx/libc/libc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
#include "prx/libc/include/LibcxxStringSearch.hpp"
#include "prx/libc/include/LibcxxStreamPosition.hpp"
#include "prx/libc/include/LibcxxStringbufSet.hpp"
#include "prx/libc/include/LibcxxStreamPosition.hpp"
#include "prx/libc/include/WindowsFormatting.hpp"
#include "prx/libc/include/LibcxxIosInit.hpp"
#include "prx/libc/include/LibcxxStreamVtables.hpp"
#include "prx/libc/include/LibcxxStreambufTransfer.hpp"
60 changes: 28 additions & 32 deletions core/libs/prx/libc/src/LibcxxIosInit.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "prx/libc/include/LibcxxIosInit.hpp"
#include "prx/libc/include/LibcxxStreamVtables.hpp"
#include "prx/libc/include/Api.hpp"
#include "prx/libc/include/GuestLocale.hpp"
#include "prx/libc/include/GuestPtr.hpp"
Expand All @@ -18,37 +19,8 @@ constexpr std::uint32_t SkipWhitespace = 0x1000;
constexpr int EraseEvent = 0;
constexpr int ImbueEvent = 1;

using Callback = void (APS5_VABI*)(int event, void* stream, int index);

struct IosBase {
const void* vtable;
std::uint32_t flags;
std::int64_t precision;
std::int64_t width;
std::uint32_t state;
std::uint32_t exceptions;
void* buffer;
LibcxxLocale locale;
const Callback* callbacks;
const int* callbackIndexes;
std::uint64_t callbackCount;
std::uint64_t callbackCapacity;
void* integers;
std::uint64_t integerCount;
std::uint64_t integerCapacity;
void* pointers;
std::uint64_t pointerCount;
std::uint64_t pointerCapacity;
};

static_assert(offsetof(IosBase, precision) == 0x10);
static_assert(offsetof(IosBase, state) == 0x20);
static_assert(offsetof(IosBase, buffer) == 0x28);
static_assert(offsetof(IosBase, locale) == 0x30);
static_assert(offsetof(IosBase, callbackCount) == 0x48);
static_assert(offsetof(IosBase, integers) == 0x58);
static_assert(offsetof(IosBase, pointers) == 0x70);
static_assert(sizeof(IosBase) == 0x88);
using Callback = GuestLocale::LibcxxIosCallback;
using IosBase = GuestLocale::LibcxxIosBase;

[[noreturn]] void Inaccessible() {
throw std::invalid_argument("libc++ ios_base: inaccessible guest object");
Expand Down Expand Up @@ -153,8 +125,10 @@ void* APS5_VABI _ZNSt3__18ios_base5imbueERKNS_6localeE_nid_postfix(void* result,
return result;
}

void APS5_VABI _ZNSt3__19basic_iosIcNS_11char_traitsIcEEED2Ev_nid_postfix(void* self) {
void APS5_VABI _ZNSt3__18ios_baseD2Ev_nid_postfix(void* self) {
if (Read(Member(self, &IosBase::locale)).imp == nullptr) return;
const void* const addressPoint = &_ZTVNSt3__18ios_baseE_nid_postfix.destructors;
Write(Member(self, &IosBase::vtable), addressPoint);
Notify(self, EraseEvent);
auto base = Read(static_cast<const IosBase*>(self));
_ZNSt3__16localeD1Ev_nid_postfix(&base.locale);
Expand All @@ -164,4 +138,26 @@ void APS5_VABI _ZNSt3__19basic_iosIcNS_11char_traitsIcEEED2Ev_nid_postfix(void*
free_nid_postfix(base.pointers);
}

void APS5_VABI _ZNSt3__18ios_baseD1Ev_nid_postfix(void* self) {
_ZNSt3__18ios_baseD2Ev_nid_postfix(self);
}

void APS5_VABI _ZNSt3__18ios_baseD0Ev_nid_postfix(void* self) {
_ZNSt3__18ios_baseD2Ev_nid_postfix(self);
_ZdlPv_nid_postfix(self);
}

void APS5_VABI _ZNSt3__19basic_iosIcNS_11char_traitsIcEEED2Ev_nid_postfix(void* self) {
_ZNSt3__18ios_baseD2Ev_nid_postfix(self);
}

void APS5_VABI _ZNSt3__19basic_iosIcNS_11char_traitsIcEEED1Ev_nid_postfix(void* self) {
_ZNSt3__18ios_baseD2Ev_nid_postfix(self);
}

void APS5_VABI _ZNSt3__19basic_iosIcNS_11char_traitsIcEEED0Ev_nid_postfix(void* self) {
_ZNSt3__18ios_baseD2Ev_nid_postfix(self);
_ZdlPv_nid_postfix(self);
}

}
2 changes: 2 additions & 0 deletions core/libs/prx/libc/src/LibcxxLocaleFacet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const LibcException::TypeRecord SharedCountType {

extern "C" {

void APS5_VABI _ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5imbueERKNS_6localeE_nid_postfix(void*, const void*) {}

void APS5_VABI _ZNSt3__16locale5facetD2Ev_nid_postfix(GuestLocale::LibcxxFacet* self) {
if (self == nullptr) APS5_INVALID_ARG_EX;
}
Expand Down
Loading