Commit Graph
885 Commits
Author SHA1 Message Date
Adrià e2e3d71ac2 Merge pull request #6072 from notaxeltv/feat/libc-logic-error-doraise-ppsa34015
feat(libc): raise logic_error::_Doraise and _Xruntime_error
2026-10-17 06:53:23 +02:00
Adrià 7c3bfa8632 Merge pull request #5962 from nikowolf123/feat/libc-crash-register-text
feat(libc): print the text that registers point at in Windows crash reports
2026-10-17 06:51:43 +02:00
Santhosh Kumar eb26fb97f8 fix(libkernel): filter sandbox TLS roots and preserve path overrides 2026-10-17 02:25:41 +00:00
screammandClaude Fable 5.1 9f4a8d6ec5 feat(libkernel): serve the console CA list from the host trust store
Titles that bundle OpenSSL load the console's CA file from the sandbox
directory and fail every HTTPS request without it. ProsperoRadio
(PPSA99001, libcurl 8.18.0 + OpenSSL 3.5.2) on main + #4796 + #4525:

  [ProsperoRadio][http] https://all.api.radio-browser.info/json/servers: Problem with the SSL CA cert (path? access rights?) (error adding trust anchors from file: /gkbHtXc3Wq/common/cert/CA_LIST.cer)

SwanStation (PPSA98510) stops on the same file (#5001).

The guest path resolver now accepts exact-path providers, and libkernel
registers one for /<sceKernelGetFsSandboxRandomWord()>/common/cert/CA_LIST.cer.
On first use it writes a PEM bundle once per process to
cert_cache/CA_LIST.cer in the run directory, read-only: on Windows the
current user's ROOT and CA system stores, elsewhere SSL_CERT_FILE or the
first distro bundle that exists. Without a certificate the path keeps
resolving under the guest root and does not exist, as before. Every other
path under the sandbox word is unchanged. The console file's format and
the rest of its common/cert directory are unverified and recorded in
docs/dev/debt/libkernel.md.

With this change, #4796, #4525 and #5025 on Windows 11, 60 s each:

  [ProsperoRadio][http] 11846160 bytes in 1458 ms: 1161 passes, 803 waits (679 woken) for 1428 ms
  [ProsperoRadio][catalog] page offset=0 bytes=11846160 objects=10000 accepted=9549 total=9549
  ...
  [ProsperoRadio][catalog] page offset=60000 bytes=1712035 objects=1494 accepted=1436 total=59371

  [SwanStationPS5] update: latest 1.2.5, this 1.1.3, available
  [SwanStationPS5] gamedb: index written

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-17 02:24:02 +00:00
Adrià 1cdaed073d Merge pull request #6016 from akkadbakkad89/feat/missing-lib-exports
feat(libc): export the fmin and fmax family
2026-10-17 04:14:54 +02:00
Adrià f3263dfbf3 Merge pull request #5949 from Ondra97/codex/fix-fiopen-exclusive-create
fix(libc): create noreplace streams exclusively
2026-10-17 02:30:12 +02:00
Adrià 29a546d378 Merge pull request #5978 from MarcZX100/codex/libc-explicit-exit-finalizers-5931
fix(libc): run guest finalizers before driver shutdown
2026-10-17 01:07:47 +02:00
NikoandClaude Opus 5.5 b263cbbb1b feat(libc): print the text that registers point at in Windows crash reports
Unreal titles end in their own libc fatal path with the UTF-16
LowLevelFatalError message in a register, and the crash report shows
only the first 64 bytes of it as hex words, so the message is lost
(#4238: Demon Slayer PPSA03490, Stray PPSA02100).

For every general register that points at readable memory starting
with at least four printable ASCII characters, as UTF-16LE or as single
bytes, the report now prints the text up to a NUL, the first other
character, 512 characters or the end of readable memory (each page is
checked with VirtualQuery before it is read).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 23:33:43 +02:00
Adrià 5b70a50680 Merge pull request #5955 from fma-rc/fix/libkernel-linux-guest-module-protect
fix(libkernel): register a relinked guest module's image when Linux protects its pages
2026-10-16 23:29:46 +02:00
MarcZX100 db3b406dd2 fix(libc): run guest finalizers before driver shutdown 2026-10-16 21:53:02 +02:00
Adrià 1b1f8483ca Merge pull request #5849 from wachi35676/fix/nid-elf-duplicate-exports
fix(nid): reject ELF exports that patch to different symbols under one name
2026-10-16 21:24:01 +02:00
Adrià d96e0e554c Merge pull request #5772 from DavidSamir/fix/libc-empty-guest-environment
fix(libc): start the guest environment empty instead of copying the host's
2026-10-16 21:23:35 +02:00
Alexej Szpevák b71434d9b7 feat(libc): read app0.zar beside app0 and refuse archive-only paths elsewhere
A ZArchive named app0.zar beside app0/ is a read-only layer under it. libc opens it at the first path resolution, looks paths missing from app0/ up case-insensitively, reads files across compressed blocks and keeps the archived descriptor table with shared positions.

Resolving an archive-only path through a call that does not read the archive throws instead of failing with ENOENT, as do opendir of a directory present in both places, fdopen of an archived descriptor and chdir into the archive. A path through .. in an archive-only directory resolves.
2026-10-16 20:03:26 +02:00
Adrià a4782fe11d Merge pull request #4855 from fdfawef324/feat/agc-submission-ring
feat(agc): keep the last submissions per queue and dump them on a stall or crash
2026-10-16 12:32:48 +02:00
Adrià 332b0b1b79 Merge pull request #6371 from AlxcBTW/perf/worker-logging
perf(agc): format and write steady-state log lines off the queue worker
2026-10-16 11:44:23 +02:00
Ondra97 3f95553e80 fix(libc): ignore noreplace for read-only streams 2026-10-16 11:35:14 +02:00
Ondra97 a70531c8fb Merge remote-tracking branch 'origin/main' into codex/fix-fiopen-exclusive-create 2026-10-16 11:22:10 +02:00
fdfawef324andClaude Opus 5.5 13b171cab5 feat(agc): keep the last submissions per queue and dump them on a stall or crash
A GPU hang or a crash in a title leaves no record of what the queues
were last given: APS5_TRACE_GPU prints every submission (too much to
leave on), and the WAIT_REG_MEM timeout message shows only the packet
before the wait on the waiting queue.

Each queue now keeps a ring of its last 16 submissions
(APS5_PM4_RING=<n>, 0 to 4096, 0 disables): the TraceMs time in tenths
of a millisecond, serial, size, guest address and a copy of the first
512 dwords after indirect buffers are inlined, recorded under the
driver lock next to the serial, REWIND tails included. The ring of a
queue and the failure report registration are set up at the top of
Submit, before any output is reserved, so recording under the lock
does not allocate. Disabled, Submit only tests a static flag; enabled,
it costs one bounded copy per submission.

DumpSubmissionRings decodes the kept dwords with Pm4::PacketWords and
the new Pm4::KnownName, which returns the decoder's names as views of
static strings (empty for an unknown opcode, printed as UNKNOWN_0x%02x);
Pm4::Name now builds its std::string from it. Every line is formatted
with integer and string conversions only into a 512-byte stack buffer
and written with one WriteFile / write(2) on the stderr handle, so the
dump does not allocate from the C runtime heap, lines from other
threads do not interleave and the CRT stream lock is not taken (the
rule of #3871). The header gives the number of queues and the ring
size, and each queue line the submissions recorded and kept.

libc gets a small registry of failure reports
(LibcRegisterFailureReport_nid_no_patch, Unregister, Run); Run runs
the registered reports the first time it is called and returns at once
after that. The Windows crash report runs it after the thread dump of
an unhandled exception, after SIGABRT (which also covers the
APS5_HANG_DUMP_SECS timed dump, since it aborts) and after an invalid
CRT parameter, so an abort after a reported exception does not print
the rings twice. The driver registers its dump at the first submission
and unregisters at static destruction; the dump there waits a bounded
time for each ring lock. What the crash-path dump cannot do (a ring
held by the crashed thread, rings corrupted by the crash, Linux) is
recorded in technical debt.

APS5_STALL_WATCHDOG_SECS=<n> (0 to 86400, 0 disables) makes a waiter
that has not progressed for n seconds dump the rings once per wait: a
WAIT_REG_MEM (progress as for APS5_GPU_WAIT_TIMEOUT_MS: another packet
runs or completes), a REWIND waiting for the title, and a compute
submission held behind queue 0. The last one prints under the driver
lock, so submissions and the other queues wait for it (USAGE.md says
so). Both variables are read at the top of Submit, so an invalid value
of either throws at the first submission and never later inside a GPU
worker. The order wait behind queue 0 releases its order hold on scope
exit, so a throwing dump cannot leave it counted.

No packet semantics change; packet sizes and names are those of the
existing decoder (PM4 type-3 header layout as in Mesa
src/amd/common/sid.h). The queue bound of Submit and of the rings is
one constant, SubmissionQueueEnd.

Tests: agc_driver_pm4_tests gets ten modes, each its own ctest:
agc_driver_pm4_ring (APS5_PM4_RING=4, six submissions on queue 0 and
two on 0x20: the dump holds #3..#6 and #1..#2 in order, nothing
older), agc_driver_pm4_ring_empty (one line), _ring_disabled (one
line), _ring_invalid and agc_driver_pm4_stall_watchdog_invalid
(APS5_STALL_WATCHDOG_SECS=1x: the submission throws and is not
executed), _ring_report (LibcRunFailureReports_nid_no_patch dumps the
rings), _ring_report_heap (Windows: with ucrtbase.dll's HeapAlloc and
HeapReAlloc imports counting calls from the reporting thread, the
failure report of a submission holding INDEX_BUFFER_SIZE names it and
allocates nothing, while Pm4::Name of the same header is seen
allocating), and with APS5_STALL_WATCHDOG_SECS=1 a WAIT_REG_MEM
(agc_driver_pm4_stall_watchdog), a REWIND (_stall_watchdog_rewind) and
a compute submission held behind a queue 0 rendering wait
(_stall_watchdog_order), each held for about 2.5 s, dump once and
complete when released. The PM4 catalog test checks KnownName against
every opcode and custom name. windows_backtrace_failure_report checks
that abort() runs the registered reports once and not an unregistered
one; windows_backtrace_failure_report_once that abort() does not run
them again after an earlier run. With the dump decoding through
Pm4::Name, agc_driver_pm4_ring_report_heap fails with "the failure
report allocated from the C runtime heap"; with Run resetting its
flag, windows_backtrace_failure_report_once prints the report twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 11:18:26 +02:00
Adrià b8aca1eeea Merge pull request #5843 from Ondra97/codex/fix-window-close-exit
fix(libc): skip guest exit handlers on host window close
2026-10-15 23:00:41 +02:00
Adrià 7663bc63bb Merge pull request #5092 from MrMha/fix/scripting-heap-694
feat(libc): provide the runtime scripting allocator hooks
2026-10-15 22:58:23 +02:00
Muhammad Wasif Ali WasifandClaude Opus 5.5 7d9a308044 fix(nid): reject ELF exports that patch to different symbols under one name
Two defined ELF exports that are renamed to the same name, such as foo
and foo_nid_disambig1, were both written as one name and the patcher
exited 0, leaving a lookup that can reach only one of them. The PE and
Mach-O back ends already reject this.

The ELF patcher now remembers the address (st_value and st_shndx) of
each patched export name and throws "duplicate patched export name"
only when the name comes from a symbol at a different address. Aliases
of one address are kept: the Linux libc defines __cxa_throw and
__cxa_throw_nid_no_patch_cut as aliases of __cxa_throw_nid_postfix, so
both become __cxa_throw, and any lookup of that name resolves to the
same code.

The Linux libc also exported __gxx_personality_v0 twice at different
addresses: the forwarding function in Personality.cpp and the
__gxx_personality_v0_nid_no_patch_cut alias of the guest personality.
Drop that alias, so the name keeps only the forwarding function, as
in the PE build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 00:08:27 +05:00
AlxcBTW b82d688ed8 fix(agc): flush the log queue, bounded, where the process ends without exit handlers
Lines queued behind the logger were lost when the process ended through
abort(), std::terminate, the Windows crash report or a guest _Exit,
because only driver failure, Driver::stop and a normal exit flushed the
queue.

libc keeps one end flush (LibcSetEndFlush_nid_no_patch) and runs it from
those paths. Its first registration chains a SIGABRT handler in front of
the previous one, so every abort() and std::terminate in the process is
covered, on Linux as well; with the default disposition the handler
restores it and raises again, so raise(SIGABRT) still ends the process.
Guest abort() and _Exit, and ReportCrash for the first fatal exception,
run the flush directly. AsyncLog registers a bounded flush (FlushFor, 2 s)
that polls two counters and takes no lock, so a dying process cannot hang
on a blocked stream or on the queue lock; after its first timeout it
returns at once. Flush counts queued and finished entries instead of
watching the queue and the writer flag, so it waits for the lines queued
before the call and not for a moment in which no thread is logging.

agc_async_log_fatal runs the test executable as a child that queues lines
behind a held stream and ends in abort(), std::terminate(), raise(SIGABRT)
(POSIX) or an access violation (Windows), and once more with the stream
never released. The lines of the first four must arrive in order, the last
child must end after the bound, and every child has a watchdog.
agc_async_log gains the bounded flush case.
2026-10-15 20:42:16 +02:00
AlxcBTW ad85ed13ac perf(agc): format and write steady-state log lines off the queue worker
Texture creation logged one stdout line per texture and per mip through
WriteLogLine, which formatted with the mingw printf and flushed every
line on the queue worker (about 786k lines in a 25 minute cave run).

AsyncLog keeps a bounded queue and a logger thread. AGC_LOG_DEFERRED
captures numeric arguments on the caller and formats them on the logger
thread; WriteLogLine hands finished lines to a per-module sink in
libc/LogMacros.hpp that AgcDriver installs, so all AgcDriver stdout
lines keep their order and are written one flush per batch. A full queue
blocks the caller, so no line is dropped. Flush runs on driver failure,
shutdown and at exit. APS5_LOG_SYNC=1 restores the synchronous path.

Identical "deferred write-back failed" notes are printed three times per
10 s and then counted into one "repeated N more times" line. A
"[log] 10 s" line reports lines, bytes, caller time and logger time
(APS5_LOG_STATS=0 hides it).
2026-10-15 20:42:16 +02:00
Adrià e6134fd0d9 Merge pull request #5827 from hamb3r/perf/precise-wait-spin-tail
perf(libc): add sub-tick spin tail to PreciseSleepUs and PreciseSleepUntil
2026-10-15 20:34:20 +02:00
Adrià ec1193dc39 Merge pull request #5775 from wachi35676/fix/libc-lgamma-tiny-arguments
fix(libc): keep lgamma finite for subnormal arguments on Windows
2026-10-15 18:36:22 +02:00
Adrià da85abc480 Merge pull request #5774 from wachi35676/fix/libc-printf-unsigned-sign-flags
fix(libc): ignore the space and + flags for unsigned printf conversions
2026-10-15 18:36:17 +02:00
Adrià 0c4816f611 Merge pull request #5753 from Tiberon-Kuiper/fix/macos-empty-write-watch-ranges
fix(libc): ignore empty macOS write-watch ranges
2026-10-15 17:39:52 +02:00
Adrià d67b79a7e4 Merge pull request #5709 from fogydes/fix/libc-formatting-allocation-and-bounds
fix(libc): check allocation result in vasprintf and guard null pointer in strndup
2026-10-15 17:04:33 +02:00
Adrià f5a55a11d0 Merge pull request #5662 from Roojool/contrib/g15-libc-pending
feat(libc): implement collate<wchar_t>::_Getcat
2026-10-15 17:03:49 +02:00
Adrià 21ca964f3f Merge pull request #5632 from babyhuey/fix/libc-closed-stream-writes
fix(libc): fail stream calls on a stream that a failed freopen closed
2026-10-15 17:03:43 +02:00
Adrià 08290338aa Merge pull request #5599 from JJenkx/feat/libc-isfinitel
feat(libc): implement x87 long-double finite classification
2026-10-15 17:03:18 +02:00
Adrià 120615bc73 Merge pull request #4927 from QRMOE/fix-libc-getcwd-allocated-size
fix(libc): ignore getcwd size when allocating a buffer
2026-10-15 16:59:41 +02:00
Adrià 0dab493f5b Merge pull request #5816 from Nawasfadili/feat/libc-wide-and-unlocked-stream-io
feat(libc): implement wide and unlocked stream I/O
2026-10-15 15:58:44 +02:00
MrMha aea1dd601a feat(libc): provide the runtime scripting allocator hooks
Use the registered application allocator and the source-backed alignment/size signature. Add callback ownership and failure checks; record unmeasured console behavior.
2026-10-15 17:21:14 +04:00
fogydes ceb963c6dd fix(libc): check allocation result in vasprintf and guard null pointer in strndup 2026-10-15 14:43:04 +02:00
Rujul Talekar 3dffc8ca9e fix(libc): give collate<wchar_t> its own 16-bit vtable 2026-10-15 11:07:58 +05:30
Dean Galvin eac8bfcfc0 fix(libc): list the directory once for a missing path that may be a relinked module
A read-only open, stat or reachability check of a missing path listed its
directory twice: once for a case-insensitive match of the name and again for
a case-insensitive match of the relinked <name>.guest.prx (#5434). Both
names are now matched in the same listing. Precedence and the ambiguous-name
errors are unchanged.
2026-10-15 13:59:12 +13:00
Dean 2bae94b978 Merge pull request #4774 from hamb3r/feat/relinker-windows-startup-barrier
feat(libc): lazily initialize application heap on first access
2026-10-15 10:57:18 +13:00
Dean 95945006ec Merge pull request #4629 from mugurc/fix/libcxx-portability
fix(libs): build with libc++
2026-10-15 10:46:05 +13:00
notaxeltvandCursor 70c080458a feat(libc): raise logic_error::_Doraise and _Xruntime_error
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-14 23:21:34 +02:00
Ondra97 eb8146b734 fix(libc): skip guest exit handlers when closing the host window 2026-10-14 23:14:16 +02:00
hamb3r ea690728c3 perf(libc): limit Windows PreciseSleepUs spin tail to pacing sleeps 2026-10-14 23:26:08 +03:00
hamb3r cee2006d18 feat(libc): lazily initialize application heap on first access 2026-10-14 23:14:30 +03:00
David-cmrg 2dd7f2b0e3 fix(libSceSystemService): end LoadExec exit without running guest exit handlers 2026-10-14 21:41:22 +02:00
akkadbakkad89 bf4945eabd feat(libc): export the fmin and fmax family
Adds fmin, fminf, fminl, fmax, fmaxf and fmaxl, the remaining
missing members of the C99 minimum/maximum family, with the NaN
propagation and signed-zero handling guest_fminf pins down (host
std::fmin does not guarantee the sign of a zero result). The
previous libSceLibcInternal copy of fminf is removed so the export
stays single-owner. PPSA28319 imports fmaxf from libc.prx; the
other five names were exported by nothing.
2026-10-14 19:25:39 +00:00
Adrià 9811e9d4b7 Merge pull request #5218 from YossiYad/fix/guest-arena-mapping-hint
fix(libkernel): fall back below a mapping hint with no room above it
2026-10-14 21:05:23 +02:00
Adrià 066442c961 Merge pull request #5143 from xXPBSXx/fix/mprotect-unmapped-einval-v2
fix(libkernel): fail sceKernelMprotect over an unmapped range with EINVAL instead of aborting
2026-10-14 21:05:05 +02:00
Adrià 587b63d2a3 Merge pull request #5073 from krishalivaibhav/codex/memory-service-lifetime
fix(memory): preserve process-owned services during exit
2026-10-14 20:33:53 +02:00
Adrià dc89131a1c Merge pull request #3864 from CnRJay/perf/libc-collect-view-walk
perf(libc): remember clean pages once per run in Windows write collects
2026-10-14 20:30:23 +02:00
Adrià f7628decf2 Merge pull request #4994 from krishalivaibhav/codex/path-service-lifetime
fix(libc): preserve path services through process exit
2026-10-14 19:52:39 +02:00