3 Commits
Author SHA1 Message Date
Thomas MartinandClaude Opus 5.5 fd67f9e899 libmpeg: callbacks on the caller's thread (MpegOptions::callbacksOnCaller)
Sony's libmpeg calls the stream callbacks inside sceMpegDemuxPss / sceMpegDemuxPssRing and Nodata inside
sceMpegGetPicture, on the caller's thread. The native library queued them for whichever thread ran next, which
deadlocks Steambot Chronicles' player (Sony's sample): its video callback waits on the IPU input ring's lock held by
the thread it was stacked on. With the option on (off by default), each callback is a handler bound to the calling
thread and the call is made again after it: the demux going on from where it was, GetPicture calling Nodata again
until a picture is there.

- Kernel::queue(handler, thread): a handler that runs only on that thread; handlerQueuedFor(thread) for the
  dispatcher's checks; the bindings saved in an optional section (older states load with none).
- Libraries::queueHandlerOn and restartCall: the free host stops the thread at the call's own address.
- MpegState::demuxResuming / demuxBytes, saved as an optional tail of the mpeg section.
- Tests: thread-bound handlers (handler_stacks), the demux and Nodata loop (mpeg_callbacks).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-29 13:39:05 +01:00
Thomas MartinandClaude Opus 5.5 c4de93f1d3 Owned handler stacks: a SetupThread of size 0 declares the stack below its top
Twisted Metal: Black's crt0 calls SetupThread(0x8ff800, 0): the address is
the stack pointer and the stack grows below it, undeclared. The owned
handler stacks (PR #75) need bounds, so every native callback threw
"native handler requires a declared thread stack". The kernel now takes
kUndeclaredStackBytes (1 MB) below such a top as the thread's stack. The
call's result is unchanged; a top too low keeps the declaration as given.

The handler-stack test covers the declaration, a callback below the live
SP, and one below a parked SP while the guest uses SP as data (TMB's
hierTraverseAsm, parked by the port).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-10 13:28:49 +01:00
Thomas Martin 666aecb71a Use owned thread stacks for native EE callbacks 2026-11-08 13:23:27 +01:00