Skip to content

fix(libs): keep thread_local objects with destructors out of module teardown on Windows - #4029

Merged
oneandonlydean merged 7 commits into
boykopovar:mainfrom
AlxcBTW:fix/thread-local-teardown-2
Oct 12, 2026
Merged

oneandonlydean merged 7 commits into
boykopovar:mainfrom
AlxcBTW:fix/thread-local-teardown-2

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

What

Fixes #2980 and the rare 0xc0000374 exit of #3171. On Windows (MinGW, emulated TLS) a thread_local with a destructor in a module DLL is destroyed after its storage is freed: when a thread ends, winpthread runs libgcc's emutls key destructor (emutls_destroy frees the thread's thread_local objects), and only then does the loader's DLL_THREAD_DETACH run the module's tls_atexit list, so the destructors run on freed memory. In libSceAgcDriver this corrupts the heap when Driver::stop joins the queue worker.

  • fix(agc): the driver's dispatch-ahead map, pending waits, draw-snapshot compare vectors and image decode memo move to HostThreadLocal. The memo keeps its unique_ptr, now owned by HostThreadLocal, so Linux builds the same thread_local as main.
  • fix(libs): the same for PreciseSleepUs's timer, libkernel's directory path, socket waker and UUID random device, libSceRandom's random device and libScePosixForWebKit's random device and host lookup. Every other thread_local in core/ is trivially destructible or Linux-only.
  • test(libs): prx_thread_local_destructors checks every built module for calls to __cxa_thread_atexit (outside libc's registration of guest destructors) and fails with the registering function.

Confirmed on #3171:

  • @Silverash-i8 (page heap run, Arrow Lake iGPU): 4 of 4 runs on main fault in ~vector<PendingWait> via tls_callback/run_dtor_list; 6 of 6 runs on the branch end without a fault, and 20 runs without page heap give no 0xc0000374.
  • @kr4y4 (check of 20dfb170, RTX 4070 Laptop): agc_driver_dword_pattern_fill, agc_driver_draw_cache_reuse and agc_driver_prepared_shaders --deferred stop with c0000374 every time under gdb on main and are clean on the branch; the 8-way --deferred run goes from 2 of 64 failures to 0 of 64.

Tested

Windows 11 (26200), WinLibs GCC 15.2.0, Release, rebased onto main a11c8f7.

  • Before the rebase (RTX 5070 Laptop, NVIDIA 616.92, on main 0f863c1): agc_driver_draw_cache_reuse under cdb (debug heap): before 127 of 127 runs stopped with heap corruption at the worker's exit (also with APS5_NO_PIPELINE_LTO=1 and APS5_NO_GPL=1), after 38 of 38 clean. Normal runs with a cold NVIDIA shader cache: before 2 of 143 exited 0xc0000374, after 98 of 98 passed. prx_thread_local_destructors fails with main's libSceRandom (it reports sceRandomGetRandomNumber) and passes on the branch for all 122 modules.
  • Non-GPU suite (Lenovo node, ctest -E "^agc_driver|^video_out|^guest_video"): 528/531 pass, including prx_thread_local_destructors and host_thread_local. The three failures, guest_kernel_sys, guest_filesystem (access denied on a created file) and windows_exceptions, fail the same way (0xc0000409) on unrelated trees there; windows_exceptions also fails on main (CI).
  • GPU suites on NVIDIA (RTX 5070 Laptop, AMD iGPU hidden): agc_driver_graphics, agc_driver_draw_cache_reuse and agc_driver_draw_cache_reuse_off: 3/3 pass.
  • Conventions: tools/check_conventions.py --base origin/main passes.

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
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

AlxcBTW and others added 4 commits October 11, 2026 21:09
…ardown

With MinGW's emulated TLS, a thread_local with a destructor in a DLL is
destroyed after its storage is gone: when a std::thread ends, winpthread
runs libgcc's emutls key destructor, which frees the thread's thread_local
storage, and only then does the loader's DLL_THREAD_DETACH run the DLL's
tls_atexit list, so the destructors run on freed memory. The queue worker
touches four of them in libSceAgcDriver (the dispatch-ahead map, the
pending waits, the draw-snapshot compare vectors and the image decode
memo), and Driver::stop's join of the worker then corrupts the heap.
Under cdb's checking heap agc_driver_draw_cache_reuse stopped at the
worker's exit with heap corruption in all 127 runs, with graphics
pipeline libraries, with APS5_NO_PIPELINE_LTO=1 and with APS5_NO_GPL=1.
Without it the damage shows intermittently, as exit 0xc0000374 (2 of 143
runs with a cold NVIDIA shader cache) or as a fault in whatever allocates
next, such as NVIDIA's compiler on the optimized-link thread (#2980).

These objects now live in HostThreadLocal, fiber-local storage that owns
them, as the recorder's buffers do since e424b6b.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eardown

The teardown order behind the driver's heap corruption holds in every
module: with MinGW's emulated TLS a thread's thread_local storage is freed
before the module's DLL_THREAD_DETACH runs its thread_local destructors,
so they run on freed objects. PreciseSleepUs's timer (used, among others,
by the video-out vblank thread) then closes a stale handle; libkernel's
directory path, socket waker and UUID random device, libSceRandom's random
device and libScePosixForWebKit's random device and host lookup free or
close stale objects. They move to HostThreadLocal. The other thread_locals
in the modules are trivially destructible or only built for Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prx_thread_local_destructors lists the symbols of every built module and,
where MinGW's thread_local destructor support is linked in, disassembles
the module for calls to __cxa_thread_atexit outside libc's registration of
guest destructors. A module that keeps a thread_local with a destructor
fails it with the function that registers one: with main's libSceRandom
it reports sceRandomGetRandomNumber, and with this branch all 122 modules
pass, libc being the only one that links the support.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The image decode memo went into HostThreadLocal as the whole array. On
Linux, where HostThreadLocal is a plain thread_local, that put 1024 memo
entries into every thread's TLS block instead of one pointer. It keeps
its unique_ptr as before, now owned by HostThreadLocal, so Linux builds
the same thread_local as main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Amoenus

Amoenus commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Independent Windows validation of the three production commits 3408e4856, 1385c40a3, 28e73c2b3 from head 28e73c2b3ca46ba9a25bae97e6a1490aed974477, applied with author credit to a diagnostic integration based on main a672688e (local head 274d3f9b2). One adjacent include conflict in ShaderResources.cpp was resolved by retaining both includes. The PR's CMake test registration was not imported; its original ThreadLocalDestructors.cmake was run externally.

Environment: Windows 11 / RTX 5080, MinGW GCC 15.2 UCRT POSIX SEH r7, Release, BUILD_TESTING=ON; native Vulkan required, shader cache off.

Before: the exact same original production module hashes, with a separate test-fixture correction described on #2261, produced 0xC0000374 in prepared-shader debug mode in a parallel repeated run and deferred-undecodable mode in a sequential repeated run. Earlier pre-fixture runs also failed in deferred mode. The preserved original patched AGC module fails this PR's scanner, reporting destructor registrations in resolvedAhead, pendingWaits, draw-snapshot scratch and image decoding. This is a structural fault control, not a debugger trace of our crashes.

After:

  • Full build, libs, registration and convention checks pass. Original scanner: 122 modules register no thread_local destructors on the built unpatched modules.
  • Nine prepared-shader groups ×5; seven thread-local/directory/network groups ×5; thirteen native multisample groups ×5; full recorder ×5: all pass without skips.
  • The three previously failing prepared-shader modes, agc_driver_draw_cache_reuse, and agc_driver_dword_pattern_fill: 100/100 runs pass, --repeat until-fail:20 --parallel 4 --timeout 30, no skips.
  • Full suite: 863 pass, 0 fail, 5 explicit skips of 868 tests; maximum duration 15.50 s (cache off). This is a finite campaign, not proof that every rare heap failure is gone.

The integration includes experimental multisample support and the exact #4021 Windows select correction. These results do not validate the unchanged whole PR head or Linux execution, and do not independently establish the faulting teardown stack. Four PPSA99902 startup controls (before / after twice / restored before) still stop at the intentional native depth fast-clear guard, without timeouts; no additional title startup or frames claimed. Original dump/module, converted guest libc and exact 123-file runtime baseline restored and hash verified. No push or new PR.

@AlxcBTW

AlxcBTW commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

@Amoenus thank you, that's a thorough campaign. The before/after on the three prepared-shader modes (failing → 100/100) and the scanner catching resolvedAhead, pendingWaits, the draw-snapshot scratch and image decoding on the unpatched module are exactly the evidence this PR needed. Noted on scope too: Windows only, three production commits on your integration, and no claim about the teardown stack itself.

AI-assisted: yes (Claude Code)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Conflicts with main in ShaderResources.cpp and Udp.cpp; please rebase.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlxcBTW

AlxcBTW commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean done: I merged current main (bab7b32) into the branch as b6a860f rather than force-pushing. The conflicts were include lists only:

  • ShaderResources.cpp: kept both HostThreadLocal.hpp and main's MultisampleTarget.hpp;
  • Udp.cpp: kept both HostThreadLocal.hpp and main's SocketError.hpp.

The imageMemo and ThreadWaker changes are unchanged. The only new thread_local on main is a plain int in tests/shared_memory/Support.cpp, which has no destructor.

Windows build (WinLibs GCC 15.2, Release, with #4021's Socket.cpp guard applied locally, since main doesn't compile on MinGW without it):

If you'd rather have it rebased to a linear history, say so and I'll do that instead.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@winstrex

Copy link
Copy Markdown
Contributor

Hi @AlxcBTW, a heads-up about an overlap: #4200 takes guest entropy from the host OS (getentropy, rand_s on Windows) instead of std::random_device, so it removes the thread_local std::random_device in arc4random_buf, sceRandomGetRandomNumber and sceKernelUuidCreate. If it merges first, those three hunks here are no longer needed; if this PR merges first, I'll resolve the conflict on my side. The rest of your change doesn't overlap with mine.

@AlxcBTW

AlxcBTW commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

@winstrex thanks for the heads-up, agreed. If #4200 merges first, I'll drop the three random_device hunks here (arc4random_buf, sceRandomGetRandomNumber, sceKernelUuidCreate). Taking entropy from the host OS removes those thread_locals altogether, which is the better fix for them. This PR's scanner (ThreadLocalDestructors.cmake) passes either way, since it only fails on a remaining thread_local with a destructor.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Merged current main into this branch (28fea1c) so it can build again: the Windows heap corruption at worker exit this fixes (agc_driver_flip_compute, exit code 0xc0000374) is turning unrelated full builds red, three so far today. The only conflicts were the three random_device hunks (arc4random_buf, sceRandomGetRandomNumber, sceKernelUuidCreate); I took main's side there, as agreed above with #4200 in. Full build started on this head.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Merged main in again (15f345c): #3661 landed and changed Driver::resolvedAhead in DispatchAhead.cpp to a ThreadOwned pointer, which has no destructor to run at teardown, so I took main's version of that function there. The rest is unchanged. New full build started.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@oneandonlydean
oneandonlydean merged commit b42ef24 into boykopovar:main Oct 12, 2026
14 checks passed
@Scramblrrrr

Copy link
Copy Markdown
Contributor

Windows integration cross-test: your production changes applied cleanly to our older retail 007 stack (3408e48 + 28e73c2 + 1385c40, original author retained).

The upstream binary inspection also caught two extra destructor-bearing containers in our local performance patches, outside this PR: the stale vector in ShaderResources::MovedReadOnlyBuffers and ColumnMemos in ResourceMaterializer. Local adaptation d7a0d01 moves them to the same HostThreadLocal pattern. Our intermediate 903d503 graphics binary fails the inspector; rebuilt d29fd5f passes it. Inspection was scoped to libSceAgcDriver, not all runtime modules.

14 selected native Vulkan tests passed on RTX 5070 Ti in 9.04 s with no skips, including draw-cache reuse GPL on/off, recorder alias lifetime/memory, upload lifetime/failure, idle write-back, graphics, BDA and clip/cull fixtures. A guarded 007 run is underway; no claim of reproducing or resolving all title teardown faults. Public integration: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-thread-lifetime-cross-test . AI-assisted: Codex.

@AlxcBTW
AlxcBTW deleted the fix/thread-local-teardown-2 branch October 12, 2026 18:56
YossiYad pushed a commit to YossiYad/AnyPS5 that referenced this pull request Oct 13, 2026
…structible

The per-thread servent storage held std::string and std::vector
members, so getservbyname_nid_postfix registered a thread_local
destructor through __cxa_thread_atexit. On Windows that destructor runs
after emulated TLS freed the object, and prx_thread_local_destructors
(boykopovar#4029) rejects libScePosixForWebKit.prx for it.

The result now lives in a thread_local struct of fixed-size char arrays
and an alias pointer array, sized for the longest name (submission),
alias (www-http), protocol (sctp) and alias count in the embedded table;
static_asserts check the sizes against the table and that the struct is
trivially destructible. The guest servent layout and the per-thread
result FreeBSD's getservent.c keeps in its NSS TLS state are unchanged.
Nothing is allocated, so the ENOMEM path is gone.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
RINNECODER added a commit to RINNECODER/AnyPS5 that referenced this pull request Oct 14, 2026
… nid and others) (#489)

* fix(nid): validate ELF table layouts before patching

(cherry picked from commit abe8fb8)

* test(nid): avoid competing hash test registration

(cherry picked from commit 617e7ac)

* fix(avplayer): resume the presentation clock when the source restarts after a pause

Clock::Reset left the paused flag set by Clock::Pause, so a Start issued
from the paused state (stop and restart of the source) kept the clock
frozen at the start position. Only the frame at that position was
delivered; later frames were held back by the default A/V sync.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit a671dc4)

* fix(libSceNet): accept MSG_DONTWAIT in the send and receive calls

sceNetSend, sceNetSendto, sceNetRecv, sceNetRecvfrom, sceNetRecvmsg and
sceNetSendmsg failed with EOPNOTSUPP for any flag other than MSG_PEEK on
a receive, so a game polling a socket with MSG_DONTWAIT got an error on
every call instead of its data or EWOULDBLOCK.

FreeBSD 11.4 defines the flag in sys/sys/socket.h:

	#define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */

and soreceive_generic() (sys/kern/uipc_socket.c) treats it like a
non-blocking socket for that one call:

		if ((so->so_state & SS_NBIO) ||
		    (flags & (MSG_DONTWAIT|MSG_NBIO))) {
			SOCKBUF_UNLOCK(&so->so_rcv);
			error = EWOULDBLOCK;
			goto release;

shadPS4's sceNet uses the same value (ORBIS_NET_MSG_DONTWAIT 0x80).

On Linux and macOS the flag now maps to the host's MSG_DONTWAIT, alone
or with MSG_PEEK on a receive. Winsock has no per-call non-blocking
flag, so Windows keeps failing with EOPNOTSUPP for it; TechnicalDebt
records that. Other flags still fail with EOPNOTSUPP.

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

* fix(audioout): serialize shared SDL audio initialization

(cherry picked from commit c35572e)

* test(audioout): detect overlapping backend initialization

(cherry picked from commit 5031432)

* feat(net): implement memory-pool netstat diagnostic

(cherry picked from commit 565fafa)

* fix(libSceVideoOut): return RESOURCE_BUSY when a bus is opened twice

(cherry picked from commit c15e9f2)

* fix(savedata): leave the mount result untouched when sceSaveDataMount3 fails

A title checks for its save with a CREATE2 mount it never
unmounts, then saves with a second mount of the same directory. That
mount returns BUSY, and the title keeps using the first mount point for
sceSaveDataPrepare, its save file and sceSaveDataUmount2.
sceSaveDataMount3 cleared the result before its checks, so the save was
written to "/save" in the game folder instead of the save directory, and
the first mount was never released. The result is now written only when
the mount succeeds, as shadPS4 does.

(cherry picked from commit 4ccf888)

* fix(libSceNet): report SO_ERROR from sceNetGetsockopt

(cherry picked from commit 0daf1d5)

* fix(savedata): report a save's size as the mount that created it gave

Every native save reported SAVE_DATA_BLOCKS_MAX blocks, all of them free,
in the sceSaveDataDirNameSearch infos and in sceSaveDataGetMountInfo,
whatever the title created it with and whatever its files held. A save's
size is now the blocks of the sceSaveDataMount3 call that created it,
kept beside the save; a save without a kept size takes that of its next
mount that names one, and otherwise keeps SAVE_DATA_BLOCKS_MAX. Free
blocks are what the save's files leave of it, each file rounded up to
32 KiB blocks, and the blocks and free-blocks sort keys use both.

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

* fix(savedata): return no saves for a search with another title's ID

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

* feat(libScePosixForWebKit): implement getservbyname

Implement getservbyname (H1bArJPagV0) in libScePosixForWebKit. A title imports it from this library only (registry index 408,
call site 0x1042124); once fnmatch (boykopovar#3545) is in, its predicted load
stop is:

    FAIL: unresolved ELF import H1bArJPagV0 from libScePosixForWebKit.prx

The ps5-payload-dev SDK stubs (f5d40f02, sce_stubs/) declare
getservbyname in libScePosixForWebKit.c and not in libkernel.c or
libSceLibcInternal.c. The call site is the service-name branch of a
getaddrinfo inside the title: a non-numeric service is looked up with
protocol "tcp", "udp" or "sctp" and the port is read big-endian at
offset 16 of the result, which fixes the servent layout used here
(name, aliases, 32-bit port, protocol at 0, 8, 16, 24).

The guest has no /etc/services and the console's file is unknown, so the
function searches 37 lines of FreeBSD 11.4 etc/services (8c639945):
ftp-data, ftp, ssh, telnet, smtp, domain, tftp, http, pop3, ntp, imap,
https, rtsp, submission, imaps and pop3s with their aliases and
protocols, in file order. None of their names or aliases appears on an
earlier line of the full file, so these lookups answer as the full file
would. The search follows files_servent in lib/libc/net/getservent.c
(8c639945): exact, case-sensitive match on the name or an alias, a null
protocol takes the first match, the port in network byte order, the
result in per-thread storage like getserv's NSS TLS state. Any other
name returns null without touching errno, as for a name the file lacks.
The repository's getaddrinfo still resolves service names through the
host, so there was no table to share; this is recorded in
TechnicalDebt.md.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 15bbc19)

* fix(libScePosixForWebKit): keep the getservbyname result trivially destructible

The per-thread servent storage held std::string and std::vector
members, so getservbyname_nid_postfix registered a thread_local
destructor through __cxa_thread_atexit. On Windows that destructor runs
after emulated TLS freed the object, and prx_thread_local_destructors
(boykopovar#4029) rejects libScePosixForWebKit.prx for it.

The result now lives in a thread_local struct of fixed-size char arrays
and an alias pointer array, sized for the longest name (submission),
alias (www-http), protocol (sctp) and alias count in the embedded table;
static_asserts check the sizes against the table and that the struct is
trivially destructible. The guest servent layout and the per-thread
result FreeBSD's getservent.c keeps in its NSS TLS state are unchanged.
Nothing is allocated, so the ENOMEM path is gone.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 8b9529b)

* test(libSceConvertKeycode): cover sceConvertKeycodeGetImeKeyboardType

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

* feat(ces): implement sceCesUcsProfileInitSJis1997Cp932

(cherry picked from commit e5f0938)

* refactor(savedata): clear the mount result once the mount point is made

boykopovar#5173 changes the create condition right after the last error check, and boykopovar#3950 removes the comment after the create block, so clearing the result in either place made the pull requests conflict. The result is still cleared only after every error return and before anything is written to it.

(cherry picked from commit 6a46563)

* fix(libSceKeyboard): report one key slot when no key is held

A keyboard record on the console never counts fewer than one key: with
nothing held, and with no keyboard connected, the count is 1 and that
slot holds code 0. SharpProspero's keyboard reader, PS5_Quake3e's notes
on records read from a console and the PS5 input research notes all say
so. AnyPS5 reported a count of 0. The count is now at least 1; the key
slots themselves are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 8ea8ea3)

* fix(libSceNpAuth): report an async request as running on its first poll

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

* feat(libSceConvertKeycode): implement sceConvertKeycodeGetCharacter for the US layout

The signature is inferred from a title call: a 16-bit keycode, a second
argument the title passes as 0, the type from
sceConvertKeycodeGetImeKeyboardType and a UTF-16 output. The keycode is a
USB HID keyboard usage and the unshifted US character is returned; a
keycode without a character returns 0. A second argument or keyboard type
other than 0 throws.

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

* feat(libSceNet): implement sceNetResolverStartNtoa6

Resolve a host name to its first IPv6 address through the host resolver
(getaddrinfo with AF_INET6) and write the 16-byte address. The lookup
shares the IPv4 path's resolver bookkeeping (abort preservation, error
state); a name without an IPv6 address fails with RESOLVER_ENODNS like a
failed lookup. Nonzero flags throw.

A title imports it and failed to
load without it (unresolved zl35YNs9jnI from libSceNet.prx).

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

* fix(libSceNet): dissolve a datagram association on connect to AF_UNSPEC

sceNetConnect() on a connected datagram socket rejected an address
whose family is AF_UNSPEC (a null address) with EINVAL before touching
the socket, so the socket stayed connected: sceNetGetpeername() still
reported the old peer and datagrams from any other sender were dropped
by the host.

FreeBSD 11.4 disconnects a connected datagram socket first and only then
looks at the address. sys/kern/uipc_socket.c, soconnectat():

	 * If protocol is connection-based, can only connect once.
	 * Otherwise, if connected, try to disconnect first.  This allows
	 * user to disconnect by connecting to, e.g., a null address.
	 */
	if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) &&
	    ((so->so_proto->pr_flags & PR_CONNREQUIRED) ||
	    (error = sodisconnect(so)))) {

udp_disconnect() (sys/netinet/udp_usrreq.c) clears the peer and keeps
the local port. connect(2): "Datagram sockets may dissolve the
association by connecting to an invalid address, such as a null
address." libkernel's connect gets the same change in boykopovar#4498.

A connected datagram socket given an address whose family byte is 0 is
now disconnected on the host first (AF_UNSPEC on Linux, a zeroed
address of the socket's family on Windows), and the call then fails
with EINVAL as before. Linux also drops an ephemeral local port on that
disconnect, so the port is bound again on the wildcard address, which
is what FreeBSD leaves. A host failure during the disconnect is
returned as the call's error. Stream sockets keep the previous path.

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

* fix(libSceNet): fail the AF_UNSPEC connect with EAFNOSUPPORT as FreeBSD does

Co-Authored-By: Claude <noreply@anthropic.com>
(cherry picked from commit fce9538)

* fix(libSceOpusDec): decode narrowband SILK packets

FFmpeg resamples narrowband SILK (TOC configurations 0-3) from 8 kHz and
holds back 24 samples of the first narrowband packet after the decoder
starts or after a packet of another bandwidth: a 20 ms packet decodes to
936 samples and the next wider packet to 984. sceOpusDecDecode required
exactly the packet's duration and threw, so ProsperoRadio aborted on a
narrowband Opus station.

The decoder now keeps FFmpeg's output in a queue and returns exactly the
packet's duration, as libopus does: the first narrowband packet starts
with 24 samples of silence and the held-back samples follow in the next
calls. The new test decodes three libopus 6 kb/s narrowband packets and
a wideband packet after them; it aborts on main.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
(cherry picked from commit fb41f10)

* fix(http2): allow completion waits without an event queue

(cherry picked from commit 28bcd6b)

* feat(libSceNgs2.native): implement custom sampler rack id 0x4001 (boykopovar#4334)

(cherry picked from commit 855823e)

* feat(libSceNgs2.native): add custom voice filter support and related tests for 0x13 issue case

(cherry picked from commit ef52b16)

* test(libSceNgs2): fix custom filter regression expectations

(cherry picked from commit 852c808)

* fix(ngs2): resolve voice patches to rack handles

(cherry picked from commit 8b0da18)

* docs: drop title IDs from ported test and debt text

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: MiniRML <134226498+MiniRML@users.noreply.github.com>
Co-authored-by: xXPBSXx <20614131+xXPBSXx@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: milescoviello <kitslayer29@gmail.com>
Co-authored-by: PrintOrb <donhou45@gmail.com>
Co-authored-by: krishalivaibhav <krishalivaibhav@gmail.com>
Co-authored-by: babyhuey <7751607+babyhuey@users.noreply.github.com>
Co-authored-by: Yunus Shaikh <75296019+EagleBearerYS@users.noreply.github.com>
Co-authored-by: bubblegg <86165363+bubblegg@users.noreply.github.com>
Co-authored-by: SandstromPL <paritoshlahre@gmail.com>
Co-authored-by: screamm <davidrydgren@gmail.com>
Co-authored-by: melihcan <melihcan.abay@students.fhnw.ch>
Co-authored-by: Kikoarl <7354010+Kikoarl@users.noreply.github.com>
Co-authored-by: Rick <99503318+0xRickx@users.noreply.github.com>
Co-authored-by: Sasha Papo <sasha.papo@gmail.com>
Co-authored-by: codingreapermaps <233954859+codingreapermaps@users.noreply.github.com>
Co-authored-by: ps54all <ps5@4.all>
Co-authored-by: Adrià Franch <adriadam10@gmail.com>
Co-authored-by: eliasbruno124-dev <eliasbruno124@gmail.com>
Co-authored-by: Jnbla6 <badrsha321@gmail.com>
Co-authored-by: MarcZX100 <marczxrr@gmail.com>
TheBlenDed pushed a commit to TheBlenDed/AnyPS5 that referenced this pull request Oct 25, 2026
AlxcBTW's boykopovar#4029 (merged upstream 2026-10-12): with MinGW's emulated TLS a
thread_local with a destructor in a DLL is destroyed after winpthread
freed the thread's TLS storage, so the destructor runs on freed memory.
In libSceAgcDriver the queue worker's pending waits, draw-snapshot
compare vectors and image decode memo (the dispatch-ahead map is the
previous commit) did that at Driver::stop's join: the prepared_shaders
tests exited 0xc0000374 from the prx's tls_callback/run_dtor_list (4 of
12 in one parallel ctest pass, 1 in 21 serially); upstream main at
0a8b1d3 shows it too (exit 127 in 4 of 80 --deferred runs), current
main 0f2683c does not (0 of 160). PreciseSleepUs's timer and
libkernel's directory path and socket waker had the same pattern (guest
threads end in the game). They move to HostThreadLocal, and
prx_thread_local_destructors fails on any module that still registers a
thread_local destructor. ShaderResources.cpp and Udp.cpp merged by hand
(include lines only).
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.

5 participants