Skip to content

Upstream sync 10A: relinker, libkernel, libc, unwrap - #493

Merged
RINNECODER merged 23 commits into
mainfrom
sync10/core
Oct 14, 2026
Merged

RINNECODER merged 23 commits into
mainfrom
sync10/core

Conversation

@RINNECODER

Copy link
Copy Markdown
Owner

Upstream sync 10A: relinker, libkernel, libc, tools/unwrap (range d8888df9b..upstream/main, scopes relinker, libkernel, libkernel_sys, libc, kernel, libs, cli, unwrap, host, build). Each commit is git cherry-pick -x of one upstream commit; upstream's docs/dev/debt/*.md hunks were moved into docs/dev/TechnicalDebt.md, and commit messages and ported debt lines that named titles or title IDs were reworded.

Ported (21 upstream commits + 2 fork commits)

Adaptations

Skipped

  • build(macos): configure the full build for x86-64 under Rosetta: forces CMAKE_OSX_ARCHITECTURES=x86_64 and a configure error otherwise; our CI builds the Metal utilities and shader bridge as arm64, so it would break them.
  • fix(libkernel): find main-program symbols when the executable is not position independent: uses glibc link_map, dlinfo and dladdr1; it does not compile on macOS (tried, DynamicLoader.cpp failed).
  • Windows-only: unwind-table cache commits (5339c08, cf8c63b, 61ed25d, 434e0b9, 05bf752, 19c55dc), indirect crash dumps (139bc7b, 6d33b36), pipe select (f288daf), WindowsMappings (8cc2040, 2af88da, b14d844).
  • Linux-only: --linux-fixed-base (75cfcec) and its follow-up (3d101e8); case-insensitive relinked module lookup (f0c3a5c; macOS hosts already ignore case).
  • Not in range / not in scope: executable-module host-needed fix (fix(relinker): share guest modules between executables that need different system libraries boykopovar/AnyPS5#5443) is not in the range; the libSceNet disconnect_datagram EAFNOSUPPORT follow-up is outside these scopes. CI-only, Tracy, web UI and Vulkan commits skipped as instructed; other-slice commits (agc, shader, recompiler, libSce*) belong to other PRs.

Evidence

  • x86_64 build (-DANYPS5_ROSETTA_LIBS=ON): rosetta_libs rosetta_engine rosetta_launcher_tests direct_memory_darwin_tests built clean.
  • Relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON): ctest 131/131 passed, including unwrap_self and windows_import_modules.
  • Game smoke on the Rosetta build, 130 s limit: first movie <= 34 s, main menu <= 59 s, leader select <= 71 s, map generation start <= 89 s, no fault, no uncaught exception. Not compared against a separate main run in this PR.
  • Not run here: the upstream native libkernel/libc test executables (guest_memory_tests fixed-anonymous, guest_page_table_stats_tests, host_cpu_tests), because this fork's x86_64 build does not build them.
  • No performance claims are made; the streaming change was not benchmarked.

🤖 Generated with Claude Code

omurc4 and others added 23 commits October 14, 2026 08:38
… load with error 126

A relinked executable that cannot load a library reports
"GetLastError: 126 - The specified module could not be found.", which also
covers a library whose dependent DLLs are missing. On Windows a self-built
libs/ directory needs libgcc_s_seh-1.dll, libstdc++-6.dll and
libwinpthread-1.dll next to it. For error 126 the stub now adds a line naming
them.

Refs boykopovar#4482

(cherry picked from commit 1915039)
…erent system libraries

On Linux and macOS every guest module listed the converting executable's
own DT_NEEDED system libraries, so its bytes could depend on which
executable converted it. --executable then failed with "Guest modules
convert differently" when the executables need different system
libraries that the modules do not, or the same ones in another order.
It is the error a title reports on Linux (boykopovar#5268)
for its launcher and main executable. Guest modules now list
only the system libraries the guest modules themselves need, with the
libSceLibcInternal.prx to libc.prx rule. The executable's own DT_NEEDED
is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 6adf63c)
Add the missing wide secure formatting exports required by a title
whose load failed with `undefined symbol: Im55VJ-Bekc`:
swprintf_s and its va_list counterpart follow C11 Annex K.3.9.1.4
(the complete output, including the terminator, must fit), while
vsnwprintf_s is the va_list counterpart of snwprintf_s (K.3.9.1.3,
truncation with full length). The export names produce NIDs
Im55VJ-Bekc, oDoV9tyHTbA and 8SKVXgeK1wY respectively. Document
the new functions in docs/dev/debt/libc.md.

(cherry picked from commit a0bd257)
The relinker reads a plain ELF executable and skips SELF containers with a
warning, so an eboot.bin or a *.prx taken from a title cannot be relinked
before it is unwrapped, and the repository has no tool for that.

The inner ELF program headers of a container carry stale offsets: a SELF
inserts its own metadata blocks between the segments, so the data sits at the
offsets of the SELF segment-record table at file offset 0x40. The segments are
also packed without honouring p_align, while ELF requires p_offset % p_align
== p_vaddr % p_align, which the relinker enforces on guest modules. The tool
places the segments from the records, falls back to the vaddr to file mapping
of the containing PT_LOAD for segments the table does not cover, copies every
region to an offset satisfying the alignment, and refuses a container whose
load segments all look encrypted.

(cherry picked from commit 2a01e9e)
(cherry picked from commit 6beefcc)
Map fixed private anonymous ranges through the existing guest arena. Preserve occupied ranges for MAP_EXCL and use FreeBSD 11.4 errors.

Cover replacement, exclusivity, range validation, rounding, and memory access.

(cherry picked from commit 6215101)
A title imports setpriority and stops at start-up once getpriority is implemented. Accept PRIO_PROCESS, PRIO_PGRP and PRIO_USER for the guest's own process and fail with ESRCH for any other id and EINVAL for any other which, leaving errno unchanged on success like FreeBSD's libc; the value is not applied, since the guest nice is not the host's scheduling class.

(cherry picked from commit afc04c7)
Charge each recorded protection ranges 2 MiB granules to the gpu
pool when the range has GPU-access protection bits and to the cpu
pool otherwise, so the available counts reflect committed usage
instead of staying at the 2048-entry budget. Follows KytyPS5s
counting model.

(cherry picked from commit 975ed12)
Partial port: the streamed instruction scans (VisitCodeSection in the
instruction scanner, the syscall scanner and the call-site resolver) are
kept. The executable-buffer reuse and scan progress reporting are not,
because this fork's relinker pipeline has no progress reporting and a
different conversion entry point.

(cherry picked from commit 94ae3f1)
A title queries RLIMIT_NOFILE at start-up in QEMU's
os_setup_limits and stopped on the unsupported resource. It reports the
descriptor count after which AnyPS5 fails with EMFILE: the C runtime's
8192 low-level descriptors on Windows and the host limit on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1aaec97)
…ensions

Titles run natively, so a host CPU without an extension that compiled Zen 2 code uses faults with an illegal instruction deep inside a title (boykopovar#3719: SHLX, BMI2). libkernel now reads CPUID and XCR0 when it loads on Linux and Windows, logs the host CPU's extensions and throws, naming the CPU and the missing extensions, before any title code runs.

(cherry picked from commit 83a268a)
…5 serves

Map hw.model, hw.ncpu, hw.physmem, hw.realmem, kern.arandom and
kern.proc.pathname to their FreeBSD MIBs with the size handling of
FreeBSD's libc wrapper over name2oid, fail with ENOENT and ENAMETOOLONG
as name2oid does, and throw for null pointers, which FreeBSD's wrapper
dereferences, and for names sysctl does not serve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit cc3d25d)
…Windows

The Windows startup stub stopped at the first import it could not
resolve, so a title missing several functions showed one
"FAIL: unresolved ELF import" line per run and needed a run per
missing function to list them all.

The stub now counts unresolved imports, writes the FAIL line of each
and goes on with the next import. After the last import it fails once,
with the searched library list and the last Windows error as before,
and exits with STATUS_ENTRYPOINT_NOT_FOUND. Weak imports, lazy binding
and a startup where every import resolves are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4ae26f8)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 74b93ad)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 34cf0e2)
…r#5495 changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f49c542)
… debt lines

Upstream keeps these in docs/dev/debt/*.md; this fork keeps them in
docs/dev/TechnicalDebt.md. The Host CPU check does not run on macOS hosts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RINNECODER RINNECODER added the upstream-sync Upstream boykopovar/AnyPS5 intake label Oct 14, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T14:10:07.947760Z ed06a35 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 14, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e3645f54-018f-4154-b6f3-6c683d198b7f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed06a35c03

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/unwrap_self.py

SELF_MAGIC = 0x1D3D154F
SELF_MAGIC_KERNEL = 0xEEF51454
RECORD_OFFSET = 0x40

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Start reading SELF records at byte 0x20

A SELF's segment table begins immediately after its 32-byte container header; the existing decoders in tools/unself.py and tools/rosetta/launcher/Unself.cpp both read entry i from 32 + i * 32. Starting at 0x40 skips the first entry, which is normally the data record for the first loadable program, so real plaintext SELF files either retain that segment's stale ELF offset and are refused or silently copy unrelated container bytes. Read from 0x20, preferably bounded by the entry count stored in the SELF header.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Real. The record table is now read from 0x20 bounded by the header entry count; fixed in #497

Comment thread tools/unwrap_self.py
Comment on lines +122 to +126
for index, (_, segment, size) in enumerate(records):
if index in used:
continue
if size == header["size"]:
used.add(index)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Map SELF records by their encoded program index

Valid SELF entries encode their target program-header index in bits 20–35 of flags, and entries without flags & 0x800 are digest metadata rather than program data. Matching every record solely by byte size can therefore swap equally sized programs or select a same-sized digest block, producing a corrupt ELF while reporting success. Filter for data records and assign each one to (flags >> 20) & 0xffff, as the repository's other SELF decoders do.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Real. Only data records (flags 0x800) are kept and mapped by program index (flags bits 20-35); fixed in #497

@RINNECODER
RINNECODER merged commit 5ad80f8 into main Oct 14, 2026
6 checks passed
@RINNECODER
RINNECODER deleted the sync10/core branch October 14, 2026 14:27
RINNECODER added a commit that referenced this pull request Oct 14, 2026
…s) (#497)

* Address Codex review findings left on merged #489, #493, #494

NGS2: custom-submixer voices now run their filter chain after mixing; a
drained custom-sampler stream reports the EMPTY state flag like a
sampler. AJM M4AAC: the first non-delay frame is sized from the ADTS
channel configuration and one AAC-LC frame before FFmpeg consumes it.
tools: unwrap_self reads the SELF record table from 0x20 bounded by the
header entry count, keeps only data records and assigns each by its
encoded program index (duplicates refused); check_compile keys compile
commands against the repository root so sibling build trees work.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj

* AJM M4AAC: size the first raw frame by the configured channel count

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

upstream-sync Upstream boykopovar/AnyPS5 intake

Projects

None yet

Development

Successfully merging this pull request may close these issues.