Skip to content

feat(libc): expose libc++ input stream type information - #28798

Open
mihai1859 wants to merge 1 commit into
boykopovar:mainfrom
mihai1859:codex/azahar-libcxx-input-stream-rtti
Open

mihai1859 wants to merge 1 commit into
boykopovar:mainfrom
mihai1859:codex/azahar-libcxx-input-stream-rtti

Conversation

@mihai1859

@mihai1859 mihai1859 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What

Expose the narrow libc++ type records for ios_base, basic_ios<char>, and basic_istream<char>. The records model the root class, the single public base of basic_ios, and the public virtual base of basic_istream using the existing Itanium RTTI runtime. The virtual-base offset comes from the PS5 SDK type record.

Tested

  • Windows 11 x64 with MinGW GCC 16.2.0. guest_dynamic_cast and guest_standard_exception_type_records passed. The new cases check all three record names, the two base relationships, and downcasts from both base types.

  • Compared the record sizes, base references, and virtual-base flags against ios.instantiations.cpp.o and ios.cpp.o in the pinned SDK. PS5 Payload SDK v0.42

  • The Windows libc.prx exports all three records. An isolated Azahar startup with the same test stack resolved the basic_istream<char> import, dropping the count from 140 to 139. RetroArch tracker

  • The final branch head passed the same tests on a combined Windows build based on main 2bf6ec6. Startup resolved the same input-stream type record. The rest of the 140 to 132 change came from #28728 and the separate file-buffer close patch.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Summary by CodeRabbit

  • New Features
    • Added runtime type information support for libc++ input streams, enabling type checks and casts between input streams and their base stream types.
    • Improved compatibility with applications that rely on C++ runtime type information for these stream classes.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: libc++ Input-Stream RTTI

Layer / File(s) Summary
Stream RTTI records
core/libs/prx/libc/src/exception/TypeInfo.cpp, docs/dev/debt/changes/feat-libc-input-stream-rtti.md
Adds RTTI records for ios_base, basic_ios, and basic_istream. The documentation identifies the PS5 Payload SDK v0.42 inheritance and virtual-base offset, and notes that retail firmware layouts and the provider are unverified.
Dynamic-cast validation
core/libs/tests/GuestDynamicCast.cpp
Adds RTTI declarations and checks type names, vtable identities, base metadata, and casts from a synthetic stream object to basic_ios and ios_base. The check runs before the existing dynamic-cast tests.

Suggested labels: libc, docs

Suggested reviewers: marczx10, boykopovar

Change: Feature

Merge Risk: Minimal · up to c50ba

This change adds type information for libc++ input streams so dynamic casts between them can work. No concrete merge-blocking risk was identified; the documentation notes that retail firmware layouts are not yet verified.

Security architecture risk: Minimal · up to c50ba

libc now supplies type information for three input-stream classes without adding a privileged operation or changing how casts are performed. The records target the PS5 Payload SDK v0.42 layout; compatibility with retail firmware remains unverified.

Security review details

Security Blast Radius

  • inferred — The new exposure is to guest code that binds to the three libc RTTI symbols. This adds data that callers can reference, not a new callable operation or a change in caller permissions.

Dependencies

  • inferred — Consumers need object vtables compatible with the SDK-derived records. No competing in-repository definition was found; whether external modules or retail firmware supply the same records, and which provider would win, remains unknown.

Data and control flow

  • observed — The existing cast routine reads the complete-object offset and dynamic type from the caller's vtable, walks the encoded base relationships, and checks the source subobject and public inheritance path before returning a matching pointer or null.

Resilience and Maintainability Implications

  • observed — The regression test checks that casts from both base types recover the complete stream object for a matching synthetic vtable layout. It does not establish that binding to the records is sufficient for correct casts with retail vtables or objects from another provider.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 040ebf95-8157-42dc-8925-d316940dd803
Commits

Reviewing files that changed from the base of the PR and between 6c7582c and c50badf.

Files selected for processing: 3

  • core/libs/prx/libc/src/exception/TypeInfo.cpp
  • core/libs/tests/GuestDynamicCast.cpp
  • docs/dev/debt/changes/feat-libc-input-stream-rtti.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guest_dynamic_cast and guest_standard_exception_type_records passed with c50badfe1e integrated on Linux. The new dynamic-cast rows cover the three exported type records, the public virtual base, and downcasts through both basic_ios<char> and ios_base. The retail firmware layouts remain unverified, as recorded in the debt fragment.

AI-assisted: yes.

@JJenkx

JJenkx commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Linux check at head c50badfe1ed7: all 3 selected tests pass with none skipped (guest_dynamic_cast, guest_fundamental_type_info, guest_libc_internal_type_info_destructors), including guest_dynamic_cast, which this PR extends.

Setup: Linux 7.3.6, Release build of the PR merged onto current main, ctest filter guest_dynamic_cast|type_info|typeinfo.

AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — changes requested

Changes are required before merge: cast the class type-info function pointer to const void* when initializing the new record.

What I ran

Reviewed head c50badfe1ed757261f954f6fe02247c87fb4937d by inspecting the prepared review artifacts and using the pinned repo_read.py reader for source context. No build or tests were run.

sed -n '1,200p' description.md
cat manifest.json diff.patch files.json
python3 repo_read.py search 'MultipleTypeRecord'
python3 repo_read.py cat core/libs/prx/libc/include/Api.hpp 90 125
python3 repo_read.py cat core/libs/prx/libc/src/exception/TypeInfo.cpp 1 98
python3 repo_read.py cat core/libs/prx/libc/src/exception/Runtime.cpp 250 420

Read the full prepared text for core/libs/prx/libc/src/exception/TypeInfo.cpp, core/libs/tests/GuestDynamicCast.cpp, and docs/dev/debt/changes/feat-libc-input-stream-rtti.md. files.json lists all three as reviewed and none as excluded.

Results

Check Result Note
Diff and source review failed Found a compile-time type mismatch
Build and tests not run No compilation or execution performed

Negative control

Not run; no test was executed or modified.

Findings

Blocking

  • core/libs/prx/libc/src/exception/TypeInfo.cpp:291 initializes FundamentalTypeRecord::vtable, which is const void*, directly from the destroy function pointer. This function pointer does not implicitly convert to an object pointer in this initializer, so the changed translation unit will fail to compile. The neighboring fundamental type records use an explicit reinterpret_cast<const void*> for the same conversion. Apply that cast here as well.

Non-blocking

None.

Sources

Not verified

  • The build and tests reported in the PR description were not independently run.
  • The SDK comparison and Azahar startup report were not independently verified.

To get this to a good state

Cast the function pointer in the new initializer to const void*, then rerun the reported build and relevant RTTI tests on the new head.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@mihai1859 I read this at c50badf. An open review on the head asks for a const void* cast on the new ios_base record initializer, saying it will not compile. It does not need one: destroy is a data member that holds a function pointer, so &_ZTV...class_type_info.destroy is the address of an object and converts to const void* implicitly. The explicit casts on the older fundamental records are redundant, not required. Your Windows MinGW run and ligmaSec's Linux run, both on this head, built and passed guest_dynamic_cast, which agrees. No change needed from my side.

@Plyxen Plyxen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Windows 11 with WinLibs GCC 15.2.0 r7 (Release). I applied the diff of c50badfe1e to main 63b98e5bf8, together with #28804 and #28844 (neither touches libc).

  • guest_dynamic_cast and guest_standard_exception_type_records pass with the change. No negative control: the new checks name the new records, so the test does not link without them.
  • I read the three records against the Itanium C++ ABI and libc++'s declarations:
    • ios_base is a root class, so a plain __class_type_info is right.
    • basic_ios<char> has one public non-virtual base at offset 0, so __si_class_type_info is right.
    • basic_istream<char> derives virtual public basic_ios, so __vmi_class_type_info with flags 0, one base, and __offset_flags of (-3 * sizeof(void*)) << 8 | __virtual_mask | __public_mask is right. That is the vtable slot of the virtual-base offset, the one just before offset-to-top and the type pointer, which is where GCC and Clang put the only virtual base.
  • No other file in core/ defines these three symbols.

Not run: Linux, macOS, a title.

AI-assisted: yes (Claude Code)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants