fix(libSceFiber): run a fiber on its own context when the context is large #6003
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6003"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-14T18:52:31Z.
What
Since #4265 every fiber runs on an mmap'd host stack (its context size plus 1 MiB), so that host calls made from a fiber cannot overrun the small contexts PPSA01341 packs next to each other. A title that derives state from the stack pointer then reads the wrong memory:
and rsp, ~0xffffffor the 512 KiB ones). On a host stack the mask lands outside the context, the job system loses track of a GameInit job, and the main thread waits forever (while (job->counter) usleep(1)) right after loadingbig4r/actor76.txt.A fiber now gets a host stack only when its context is smaller than 64 KiB; a larger context is the stack again, as on the console.
StackTop,FiberBoundsandSizedWindowalready handle a fiber without a host stack, sosceFiberGetInfo(#5348) keeps reporting the context the fiber runs on.The limit sits between the 16 KiB contexts PPSA01341 needs protected and the 64 KiB ones PPSA05684 needs as its stack; it is chosen between these two titles, not measured, and recorded in
docs/dev/debt/libSceFiber.md. A title with small contexts that also derives state from the stack pointer, or one whose host calls overrun what is left of a large context, is not covered.Tested
main2b7e3ce69: full ctest 1182 of 1182,tools/check_conventions.py --base origin/mainpasses.fiber(RunOnLargeContext): a fiber with a 512 KiB context runs with its stack pointer inside its context. WithExport.cppfrommainit fails witha fiber with a 512 KiB context runs on its context.RunHostCallOnSmallContext(the PPSA01341 case from #4265) andagc_driver_gpu_map_on_fiberstill pass.mainplus #757/#758, which it needs to draw): without this change it hangs in GameInit; with it (and the other local patches that stack carries), it reaches the main menu. With a 256 KiB limit it faulted later in a 64 KiB fiber, which is why the limit is 64 KiB.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AllocateHostStackin the same file, no overlap in lines)main)Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-15T02:09:43Z.
I ran this PR's test on Linux.
Setup: this PR's diff applied to main at
8cd937e29(the PR's base is 282 commits behind it), default CMake build (CMAKE_BUILD_TYPE empty, unoptimized), clean environment.ctest -R '^fiber$', 3 runs each. The test did not open a GPU device, so this is a CPU-only run.So the new test catches the old behaviour here. I did not check Windows, macOS or a real GPU.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:13:06Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/tests/Fiber.cppcore/libs/prx/libSceFiber/Export.cppcore/libs/prx/libSceFiber/Export.cppImported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-16T11:45:23Z.
Thanks for running it, Dextroid17.
Still needed on current
main: Uncharted: Legacy of Thieves Collection (PPSA05684, #4001) built from unchangedmainat5d9dcc42dstalls during startup (its log stops and its fiber worker threads spin at 100% CPU), and it boots with this PR layered on the same commit. Linux, RTX 4070 Ti SUPER, driver 615.78.08.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T20:50:04Z.
Checked on Linux: build + ctest in scope 34/34 green;
fiberfails withExport.cppreverted tomainand passes with the PR. The 64 KiB limit is recorded as unmeasured indocs/dev/debt/libSceFiber.md. Merging once the Windows build is green.