feat(libSceFiber): attach contexts on run and switch, internal option initialize #9072

Merged
rocklouis055 merged 1 commit from upstream-pr/9072 into main 2026-10-24 07:24:41 +00:00
rocklouis055 commented 2026-10-21 11:41:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rocklouis055 on 2026-10-21T11:41:57Z.


What

Implements _sceFiberAttachContextAndRun, _sceFiberAttachContextAndSwitch and _sceFiberInitializeWithInternalOptionImpl, completing libSceFiber.

  • Fibers may be initialized without a context (addr_context null, size_context 0). The attach exports give such a fiber its context when it is first run or switched to; with a null context and size 0 they behave as sceFiberRun and sceFiberSwitch, which now share their implementation. Attaching to a fiber that already has a context, or is not idle, returns SCE_FIBER_ERROR_INVALID; the idle check and the attach happen under the state claim, so concurrent attaches cannot both succeed.
  • Running or switching to a fiber that has no context throws: on the console it runs on its caller's stack, which is not supported.
  • _sceFiberInitializeWithInternalOptionImpl accepts 0x1 (no ulobjmgr, no effect), 0x10 (per-fiber context size check) and 0x100 (start with MXCSR 0x9fc0 and x87 control word 0x037f); other bits throw.
  • Semantics follow shadPS4 and are not measured on a console; recorded in docs/dev/debt/libSceFiber.md.

Overlap: #7149 changes the Windows host stack allocation and the Fiber stacks debt entry, and #6044 moves core/libs/tests/Fiber.cpp; neither implements these functions.

Tested

Linux (Ubuntu 26.04, GCC, Release): ctest -R '^fiber$' passes, with new cases for the attach error codes, attach and run on 64 KiB and 4 KiB contexts, attach and switch, resume after attach, the permission checks, and each internal option flag. Windows not tested.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4950962601 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9072). Originally posted by [rocklouis055](https://github.com/rocklouis055) on 2026-10-21T11:41:57Z. --- ### What Implements `_sceFiberAttachContextAndRun`, `_sceFiberAttachContextAndSwitch` and `_sceFiberInitializeWithInternalOptionImpl`, completing libSceFiber. - Fibers may be initialized without a context (`addr_context` null, `size_context` 0). The attach exports give such a fiber its context when it is first run or switched to; with a null context and size 0 they behave as `sceFiberRun` and `sceFiberSwitch`, which now share their implementation. Attaching to a fiber that already has a context, or is not idle, returns `SCE_FIBER_ERROR_INVALID`; the idle check and the attach happen under the state claim, so concurrent attaches cannot both succeed. - Running or switching to a fiber that has no context throws: on the console it runs on its caller's stack, which is not supported. - `_sceFiberInitializeWithInternalOptionImpl` accepts `0x1` (no ulobjmgr, no effect), `0x10` (per-fiber context size check) and `0x100` (start with MXCSR `0x9fc0` and x87 control word `0x037f`); other bits throw. - Semantics follow shadPS4 and are not measured on a console; recorded in `docs/dev/debt/libSceFiber.md`. Overlap: #7149 changes the Windows host stack allocation and the Fiber stacks debt entry, and #6044 moves `core/libs/tests/Fiber.cpp`; neither implements these functions. ### Tested Linux (Ubuntu 26.04, GCC, Release): `ctest -R '^fiber$'` passes, with new cases for the attach error codes, attach and run on 64 KiB and 4 KiB contexts, attach and switch, resume after attach, the permission checks, and each internal option flag. Windows not tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-21 12:02:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T12:02:41Z.


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.

Pull request Shared files not compared
PR 6044 core/libs/tests/Fiber.cpp
PR 7149 core/libs/prx/libSceFiber/Export.cpp
docs/dev/debt/libSceFiber.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6315416113 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9072#issuecomment-6315416113). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T12:02:41Z. --- <!-- pr-overlap --> 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. | Pull request | Shared files not compared | |---|---| | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/Fiber.cpp` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `core/libs/prx/libSceFiber/Export.cpp`<br>`docs/dev/debt/libSceFiber.md` |
ycbuzi commented 2026-10-21 17:51:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T17:51:06Z.


Windows run of 43d4eebe51 merged onto main 745b394629 (90515ad990, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

Built libSceFiber and fiber_tests with no errors or warnings. ctest --repeat until-fail:2 on fiber: passes on both repeats. Not run: a title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6322738929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9072#issuecomment-6322738929). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-21T17:51:06Z. --- Windows run of 43d4eebe51 merged onto `main` 745b394629 (90515ad990, clean), the platform the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, `BUILD_TESTING=ON`. Built `libSceFiber` and `fiber_tests` with no errors or warnings. `ctest --repeat until-fail:2` on `fiber`: passes on both repeats. Not run: a title.
rocklouis055 commented 2026-10-21 19:47:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rocklouis055 on 2026-10-21T19:47:58Z.


@ycbuzi thanks for the Windows run, that was the platform I couldn't test.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325048097 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9072#issuecomment-6325048097). Originally posted by [rocklouis055](https://github.com/rocklouis055) on 2026-10-21T19:47:58Z. --- @ycbuzi thanks for the Windows run, that was the platform I couldn't test.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9072
No description provided.