fix(libkernel_sys): implement fchown #8531

Closed
PayloadAnim wants to merge 1 commit from upstream-pr/8531 into main
PayloadAnim commented 2026-10-20 15:18:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PayloadAnim on 2026-10-20T15:18:21Z.


What

Implement fchown using the host call on Linux. Guest owner and group ID 0 remain unchanged because the guest runs as root while the host process may not. On Windows, validate the descriptor and return EOPNOTSUPP for ownership changes the host cannot represent. Update the technical debt note with these platform limits.

Tested

Windows: cmake --build build --target libkernel_sys completed successfully. python3 tools/check_conventions.py --base origin/main and rtk git diff --check passed. The overlap script could not run because gh is unavailable; an open PR search found #8457, which also concerns fchown.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4937981257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8531). Originally posted by [PayloadAnim](https://github.com/PayloadAnim) on 2026-10-20T15:18:21Z. --- ### What Implement `fchown` using the host call on Linux. Guest owner and group ID `0` remain unchanged because the guest runs as root while the host process may not. On Windows, validate the descriptor and return `EOPNOTSUPP` for ownership changes the host cannot represent. Update the technical debt note with these platform limits. ### Tested Windows: `cmake --build build --target libkernel_sys` completed successfully. `python3 tools/check_conventions.py --base origin/main` and `rtk git diff --check` passed. The overlap script could not run because `gh` is unavailable; an open PR search found [#8457](https://github.com/boykopovar/AnyPS5/pull/8457), which also concerns `fchown`. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
github-actions[bot] commented 2026-10-20 15:19:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T15:19:15Z.


Progress report (d073fe6 → ed66166)

📈 System libraries: 64.02% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel_sys fchown_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6294335147 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8531#issuecomment-6294335147). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T15:19:15Z. --- <!-- progress-report --> ### Progress report (d073fe6 → ed66166) 📈 **System libraries**: 64.02% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `fchown_nid_postfix` | </details>
github-actions[bot] commented 2026-10-20 15:32:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T15:32:21Z.


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 5021 core/libs/prx/libkernel_sys/Export.cpp
PR 5528 core/libs/prx/libkernel_sys/Export.cpp
PR 6525 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 7201 core/libs/prx/libkernel_sys/Export.cpp
PR 8457 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 8701 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 8723 core/libs/prx/libkernel_sys/Export.cpp
PR 8797 core/libs/prx/libkernel_sys/Export.cpp
PR 8987 docs/dev/debt/libkernel_sys.md
PR 9008 core/libs/prx/libkernel_sys/Export.cpp
PR 9019 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9040 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9095 core/libs/prx/libkernel_sys/Export.cpp
PR 9097 core/libs/prx/libkernel_sys/Export.cpp
PR 9103 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9131 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9141 docs/dev/debt/libkernel_sys.md
PR 9161 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9162 docs/dev/debt/libkernel_sys.md
PR 9195 docs/dev/debt/libkernel_sys.md
PR 9200 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9214 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9294 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9297 docs/dev/debt/libkernel_sys.md
PR 9302 docs/dev/debt/libkernel_sys.md
PR 9322 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9336 core/libs/prx/libkernel_sys/Export.cpp
PR 9355 docs/dev/debt/libkernel_sys.md
PR 9382 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 9389 core/libs/prx/libkernel_sys/Export.cpp
PR 9423 core/libs/prx/libkernel_sys/Export.cpp
PR 9442 core/libs/prx/libkernel_sys/Export.cpp
PR 9537 docs/dev/debt/libkernel_sys.md
PR 9573 docs/dev/debt/libkernel_sys.md
PR 9682 core/libs/prx/libkernel_sys/Export.cpp
PR 9693 core/libs/prx/libkernel_sys/Export.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6294615351 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8531#issuecomment-6294615351). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T15:32:21Z. --- <!-- 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 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 5528](https://www.github.com/boykopovar/AnyPS5/pull/5528) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 6525](https://www.github.com/boykopovar/AnyPS5/pull/6525) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 8457](https://www.github.com/boykopovar/AnyPS5/pull/8457) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 8701](https://www.github.com/boykopovar/AnyPS5/pull/8701) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 8723](https://www.github.com/boykopovar/AnyPS5/pull/8723) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 8797](https://www.github.com/boykopovar/AnyPS5/pull/8797) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 8987](https://www.github.com/boykopovar/AnyPS5/pull/8987) | `docs/dev/debt/libkernel_sys.md` | | [PR 9008](https://www.github.com/boykopovar/AnyPS5/pull/9008) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 9019](https://www.github.com/boykopovar/AnyPS5/pull/9019) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9040](https://www.github.com/boykopovar/AnyPS5/pull/9040) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9095](https://www.github.com/boykopovar/AnyPS5/pull/9095) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 9097](https://www.github.com/boykopovar/AnyPS5/pull/9097) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 9103](https://www.github.com/boykopovar/AnyPS5/pull/9103) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9131](https://www.github.com/boykopovar/AnyPS5/pull/9131) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9141](https://www.github.com/boykopovar/AnyPS5/pull/9141) | `docs/dev/debt/libkernel_sys.md` | | [PR 9161](https://www.github.com/boykopovar/AnyPS5/pull/9161) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9162](https://www.github.com/boykopovar/AnyPS5/pull/9162) | `docs/dev/debt/libkernel_sys.md` | | [PR 9195](https://www.github.com/boykopovar/AnyPS5/pull/9195) | `docs/dev/debt/libkernel_sys.md` | | [PR 9200](https://www.github.com/boykopovar/AnyPS5/pull/9200) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9214](https://www.github.com/boykopovar/AnyPS5/pull/9214) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9294](https://www.github.com/boykopovar/AnyPS5/pull/9294) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9297](https://www.github.com/boykopovar/AnyPS5/pull/9297) | `docs/dev/debt/libkernel_sys.md` | | [PR 9302](https://www.github.com/boykopovar/AnyPS5/pull/9302) | `docs/dev/debt/libkernel_sys.md` | | [PR 9322](https://www.github.com/boykopovar/AnyPS5/pull/9322) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9336](https://www.github.com/boykopovar/AnyPS5/pull/9336) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 9355](https://www.github.com/boykopovar/AnyPS5/pull/9355) | `docs/dev/debt/libkernel_sys.md` | | [PR 9382](https://www.github.com/boykopovar/AnyPS5/pull/9382) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 9389](https://www.github.com/boykopovar/AnyPS5/pull/9389) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 9423](https://www.github.com/boykopovar/AnyPS5/pull/9423) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 9442](https://www.github.com/boykopovar/AnyPS5/pull/9442) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 9537](https://www.github.com/boykopovar/AnyPS5/pull/9537) | `docs/dev/debt/libkernel_sys.md` | | [PR 9573](https://www.github.com/boykopovar/AnyPS5/pull/9573) | `docs/dev/debt/libkernel_sys.md` | | [PR 9682](https://www.github.com/boykopovar/AnyPS5/pull/9682) | `core/libs/prx/libkernel_sys/Export.cpp` | | [PR 9693](https://www.github.com/boykopovar/AnyPS5/pull/9693) | `core/libs/prx/libkernel_sys/Export.cpp` |
oneandonlydean commented 2026-10-20 23:08:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T23:08:53Z.


@xxLnolan Thanks. #8457 changes the same lines and got the same question, so I'll keep it consistent:

  • On Windows, EOPNOTSUPP for another owner isn't what the console would say. The guest runs as root here (getuid returns 0), and FreeBSD lets root change ownership, so the reference answer is success, which we can't honour because ownership isn't modelled. In that case the rule is to keep throwing (as main does) rather than return an invented error.
  • On Linux, handing the guest's uid and gid to the host fchown mixes two ID spaces: the console's IDs mean nothing on the host. As a normal user it fails with a host EPERM, and run as root it would really change the owner of the user's files. It also makes Linux and Windows answer the same call differently.

What I'd keep from this change is checking the descriptor before the owner (EBADF first, as FreeBSD does). If you have a measurement from a PS5 title process showing the actual result for another owner, that would let us implement it properly.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6303818081 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8531#issuecomment-6303818081). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T23:08:53Z. --- @xxLnolan Thanks. #8457 changes the same lines and got the same question, so I'll keep it consistent: - On Windows, `EOPNOTSUPP` for another owner isn't what the console would say. The guest runs as root here (`getuid` returns 0), and FreeBSD lets root change ownership, so the reference answer is success, which we can't honour because ownership isn't modelled. In that case the rule is to keep throwing (as `main` does) rather than return an invented error. - On Linux, handing the guest's uid and gid to the host `fchown` mixes two ID spaces: the console's IDs mean nothing on the host. As a normal user it fails with a host `EPERM`, and run as root it would really change the owner of the user's files. It also makes Linux and Windows answer the same call differently. What I'd keep from this change is checking the descriptor before the owner (`EBADF` first, as FreeBSD does). If you have a measurement from a PS5 title process showing the actual result for another owner, that would let us implement it properly.

Pull request closed

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!8531
No description provided.