feat(libkernel): implement getresuid and getresgid #8894

Closed
slopgobblercobbler wants to merge 0 commits from upstream-pr/8894 into main
slopgobblercobbler commented 2026-10-21 04:58:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-21T04:58:04Z.


What

Implement getresuid_nid_postfix and getresgid_nid_postfix (FreeBSD syscalls 360 and 361) in core/libs/prx/libkernel/System/src/Process.cpp, test them in GuestCredentials.cpp, and update docs/dev/debt/libkernel.md.

Why

FreeBSD 11.4 provides getresuid and getresgid (sys/kern/kern_prot.c) to retrieve the real, effective, and saved user and group IDs of the process.
AnyPS5 models a guest environment running as root with real, effective, and saved IDs set to 0.

  • getresuid and getresgid accept nullable output pointers for real, effective, and saved IDs.
  • For each non-null output pointer, 0 is stored.
  • Null pointers are ignored as in FreeBSD's sys_getresuid and sys_getresgid.
  • Returns 0 with errno left untouched on success.

Tested

Windows 11 x64:

  • Extended core/libs/tests/GuestCredentials.cpp with unit test coverage:
    • Valid non-null pointers returning 0 and populating 0 for all three IDs.
    • Verification that errno is untouched on success.
    • Combinations of null and non-null pointers ensuring non-null targets receive 0 and null pointers are safely ignored.
    • All-null pointer invocation returning 0.
    • Local unit test compilation and execution passing with exit code 0.
  • Passed python tools/check_conventions.py --base upstream/main --head HEAD.
  • Passed python tools/check_main_sync.py: HEAD is 1 ahead and 0 behind upstream/main, clean merge.

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:4946625826 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8894). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-21T04:58:04Z. --- ### What Implement `getresuid_nid_postfix` and `getresgid_nid_postfix` (FreeBSD syscalls 360 and 361) in `core/libs/prx/libkernel/System/src/Process.cpp`, test them in `GuestCredentials.cpp`, and update `docs/dev/debt/libkernel.md`. ### Why FreeBSD 11.4 provides `getresuid` and `getresgid` (`sys/kern/kern_prot.c`) to retrieve the real, effective, and saved user and group IDs of the process. AnyPS5 models a guest environment running as root with real, effective, and saved IDs set to 0. - `getresuid` and `getresgid` accept nullable output pointers for real, effective, and saved IDs. - For each non-null output pointer, 0 is stored. - Null pointers are ignored as in FreeBSD's `sys_getresuid` and `sys_getresgid`. - Returns 0 with `errno` left untouched on success. ### Tested Windows 11 x64: - Extended `core/libs/tests/GuestCredentials.cpp` with unit test coverage: - Valid non-null pointers returning 0 and populating 0 for all three IDs. - Verification that `errno` is untouched on success. - Combinations of null and non-null pointers ensuring non-null targets receive 0 and null pointers are safely ignored. - All-null pointer invocation returning 0. - Local unit test compilation and execution passing with exit code 0. - Passed `python tools/check_conventions.py --base upstream/main --head HEAD`. - Passed `python tools/check_main_sync.py`: HEAD is 1 ahead and 0 behind upstream/main, clean merge. ### 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
github-actions[bot] commented 2026-10-21 04:58:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T04:58:46Z.


Progress report (e072e88 → 21154fc)

📈 System libraries: 42.11% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel getresgid_nid_postfix
libkernel getresuid_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308425180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8894#issuecomment-6308425180). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T04:58:46Z. --- <!-- progress-report --> ### Progress report (e072e88 → 21154fc) 📈 **System libraries**: 42.11% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel | `getresgid_nid_postfix` | | libkernel | `getresuid_nid_postfix` | </details>
MarcZX10 commented 2026-10-21 05:02:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:02:18Z.

Review: APPROVED


Reviewed the implementations and focused tests. They match the documented guest-root model: independently write zero to each non-null output, accept null outputs, return success, and leave errno untouched. The tests cover those cases.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5595163657 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8894#pullrequestreview-5595163657). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T05:02:18Z. **Review:** APPROVED --- Reviewed the implementations and focused tests. They match the documented guest-root model: independently write zero to each non-null output, accept null outputs, return success, and leave errno untouched. The tests cover those cases.
MarcZX10 commented 2026-10-21 05:36:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T05:36:36Z.


One additional edge case may be missing: invalid non-null output pointers. FreeBSD 11.4 documents EFAULT for an invalid address passed to getresuid/getresgid (https://man.freebsd.org/cgi/man.cgi?query=getresgid&sektion=2&manpath=FreeBSD+11.4-RELEASE+and+Ports), and sys_getresuid/sys_getresgid use copyout for each non-null pointer. These direct stores would fault the host on an unmapped pointer instead of returning -1 with errno 14. I confirmed the analogous native Linux syscall behavior with getresuid((uid_t*)1, NULL, NULL): -1/EFAULT. The null-output cases in the new tests are useful and should remain; could you add a guarded/inaccessible non-null output case and map the failure to guest EFAULT?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308906444 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8894#issuecomment-6308906444). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T05:36:36Z. --- One additional edge case may be missing: invalid non-null output pointers. FreeBSD 11.4 documents EFAULT for an invalid address passed to getresuid/getresgid (https://man.freebsd.org/cgi/man.cgi?query=getresgid&sektion=2&manpath=FreeBSD+11.4-RELEASE+and+Ports), and sys_getresuid/sys_getresgid use copyout for each non-null pointer. These direct stores would fault the host on an unmapped pointer instead of returning -1 with errno 14. I confirmed the analogous native Linux syscall behavior with getresuid((uid_t*)1, NULL, NULL): -1/EFAULT. The null-output cases in the new tests are useful and should remain; could you add a guarded/inaccessible non-null output case and map the failure to guest EFAULT?
MarcZX10 commented 2026-10-21 06:33:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T06:33:05Z.


I prepared a two-commit follow-up on my fork: 85f030a59f validates each non-null output range and uses safe OS copyout to return guest EFAULT instead of faulting the host; 21154fc9ab adds invalid-pointer regression cases for both functions. Branch: codex/8894-getresuid-efault.

Checks on the branch: conventions pass, git diff --check passes, and Process.cpp passes Linux c++ -std=c++20 -fsyntax-only. I could not run guest_credentials: CMake configuration stops because this workspace has an empty SDL2 submodule and lacks XRandR development support. The commits are available if you want to cherry-pick them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309682085 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8894#issuecomment-6309682085). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T06:33:05Z. --- I prepared a two-commit follow-up on my fork: [85f030a59f](https://github.com/MarcZX10/AnyPS5/commit/85f030a59f) validates each non-null output range and uses safe OS copyout to return guest `EFAULT` instead of faulting the host; [21154fc9ab](https://github.com/MarcZX10/AnyPS5/commit/21154fc9ab) adds invalid-pointer regression cases for both functions. Branch: [`codex/8894-getresuid-efault`](https://github.com/MarcZX10/AnyPS5/tree/codex/8894-getresuid-efault). Checks on the branch: conventions pass, `git diff --check` passes, and `Process.cpp` passes Linux `c++ -std=c++20 -fsyntax-only`. I could not run `guest_credentials`: CMake configuration stops because this workspace has an empty SDL2 submodule and lacks XRandR development support. The commits are available if you want to cherry-pick them.
slopgobblercobbler commented 2026-10-21 14:10:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-10-21T14:10:58Z.


Thank you @MarcZX10 for the thorough review, approval, and for providing the guest pointer validation helper commits! We have integrated commits 85f030a59 and 21154fc9a covering guest \EFAULT\ handling and test verification into the branch and confirmed all local unit tests and repository conventions pass cleanly.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6318182776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8894#issuecomment-6318182776). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-10-21T14:10:58Z. --- Thank you @MarcZX10 for the thorough review, approval, and for providing the guest pointer validation helper commits! We have integrated commits 85f030a59 and 21154fc9a covering guest \EFAULT\ handling and test verification into the branch and confirmed all local unit tests and repository conventions pass cleanly.

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