feat(libkernel): implement getlogin #9171

Merged
DavidSamir merged 1 commit from upstream-pr/9171 into main 2026-10-25 16:54:16 +00:00
DavidSamir commented 2026-10-21 14:11:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T14:11:02Z.


What

getlogin was a discovery stub in libkernel_sys that threw NotImplemented. It is now implemented in libkernel, in libkernel/System/src/Login.cpp beside getlogin_r, and the libkernel_sys stub is removed. It follows FreeBSD 11 lib/libc/gen/getlogin.c: a static MAXLOGNAME (33-byte) buffer filled by libkernel's getlogin_r. On an error it sets errno to getlogin_r's error and returns NULL, and an empty name also returns NULL.

Moved to libkernel so libkernel imports reach it on Windows. The PS5 3.20 export lists have getlogin in libkernel as well as libkernel_sys, and on Windows a libkernel import never searches libkernel_sys (WindowsEntryStubBuilder.cpp:175). With the libkernel export and no libkernel_sys stub, both imports reach it, and the duplicate-export rule holds.

futimesat dropped: #9161 implements it. The last commit takes it back out of this PR and restores its stub, so the PR's total change is getlogin only.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is a CPU-side export, so no GPU is involved.

  • New guest_kernel_sys_login (core/libs/tests/GuestKernelSysLogin.cpp): getlogin against getlogin_r, including the error and empty-name cases and the same static buffer on a second call.
  • With main's Export.Discovery.cpp the test aborts with getlogin_nid_postfix not implemented. On this branch it passes. guest_kernel_sys still passes, and tools/check_conventions.py passes, including the duplicate-export rule.
  • Link control: with getlogin renamed in Login.cpp, the test fails to link (undefined reference to getlogin_nid_postfix), so it reaches libkernel's export, which is the only one.
  • Overlap: tools/pr_overlap.py crashes on this machine's partial clone, so I ran git merge-tree against every open PR that touches Login.cpp or Export.Discovery.cpp. It merges cleanly with all of them.

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:4952998055 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9171). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-21T14:11:02Z. --- ### What `getlogin` was a discovery stub in `libkernel_sys` that threw `NotImplemented`. It is now implemented in libkernel, in `libkernel/System/src/Login.cpp` beside `getlogin_r`, and the libkernel_sys stub is removed. It follows FreeBSD 11 `lib/libc/gen/getlogin.c`: a static `MAXLOGNAME` (33-byte) buffer filled by libkernel's `getlogin_r`. On an error it sets `errno` to `getlogin_r`'s error and returns NULL, and an empty name also returns NULL. **Moved to libkernel so libkernel imports reach it on Windows.** The PS5 3.20 export lists have `getlogin` in libkernel as well as libkernel_sys, and on Windows a libkernel import never searches libkernel_sys (`WindowsEntryStubBuilder.cpp:175`). With the libkernel export and no libkernel_sys stub, both imports reach it, and the duplicate-export rule holds. futimesat dropped: #9161 implements it. The last commit takes it back out of this PR and restores its stub, so the PR's total change is `getlogin` only. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is a CPU-side export, so no GPU is involved. - New `guest_kernel_sys_login` (`core/libs/tests/GuestKernelSysLogin.cpp`): `getlogin` against `getlogin_r`, including the error and empty-name cases and the same static buffer on a second call. - With `main`'s `Export.Discovery.cpp` the test aborts with `getlogin_nid_postfix not implemented`. On this branch it passes. `guest_kernel_sys` still passes, and `tools/check_conventions.py` passes, including the duplicate-export rule. - Link control: with `getlogin` renamed in `Login.cpp`, the test fails to link (`undefined reference to getlogin_nid_postfix`), so it reaches libkernel's export, which is the only one. - Overlap: `tools/pr_overlap.py` crashes on this machine's partial clone, so I ran `git merge-tree` against every open PR that touches `Login.cpp` or `Export.Discovery.cpp`. It merges cleanly with all of them. ### 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
xXPBSXx commented 2026-10-21 19:18:20 +00:00 (Migrated from github.com)

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


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main is clean. I built only guest_kernel_sys_login_tests; ctest -N -R guest_kernel_sys_login lists exactly one test.

PR head tested: 312fccbf0b64f7cd61a1793756852805203862fd.

Results (3 runs each):

  • PR head: guest_kernel_sys_login passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/libs/prx/libkernel_sys/Export.Discovery.cpp with the version from the PR's merge base (663de1ab21), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.

Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324475226 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9171#issuecomment-6324475226). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T19:18:20Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` is clean. I built only `guest_kernel_sys_login_tests`; `ctest -N -R guest_kernel_sys_login` lists exactly one test. **PR head tested:** `312fccbf0b64f7cd61a1793756852805203862fd`. **Results (3 runs each):** - PR head: `guest_kernel_sys_login` passes 3/3. - Baseline: I kept the PR's test and replaced only `core/libs/prx/libkernel_sys/Export.Discovery.cpp` with the version from the PR's merge base (`663de1ab21`), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards. **Not run:** other platforms, the other tests in the same family, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
DavidSamir commented 2026-10-22 02:06:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T02:06:15Z.


Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head 4051c0af7 merged onto main 8c26eac3c.

  • guest_kernel_sys_login passes 3/3.
  • Link control: with getlogin renamed in Login.cpp, the test fails to link: undefined reference to getlogin_nid_postfix, as listed.

Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330941792 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9171#issuecomment-6330941792). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T02:06:15Z. --- Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head `4051c0af7` merged onto `main` `8c26eac3c`. - `guest_kernel_sys_login` passes 3/3. - Link control: with `getlogin` renamed in `Login.cpp`, the test fails to link: `undefined reference to getlogin_nid_postfix`, as listed. Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.
MarcZX10 commented 2026-10-22 08:30:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:30:12Z.

Review: DISMISSED


Review

Moving getlogin to libkernel is a sensible way to serve both import paths, and the dedicated link test is useful. I found one error-path mismatch and test-coverage gaps to resolve before approval.

Host lookup failures

The new wrapper sets guest errno only when getlogin_r_nid_postfix returns a nonzero code. In the same file, however, ReadLogin throws std::system_error when the host lookup/conversion fails and std::runtime_error when no account name is available. Those cases do not return through this wrapper’s NULL plus guest-errno path.

Please make the host lookup failures return or translate to an error code that getlogin can expose, or document why exceptions are the intended guest-visible behavior. Add a deterministic test for the selected behavior.

Test report

GuestKernelSysLogin.cpp conditionally checks the error and empty-name branches based on the host account result; it does not force either case. In particular, a normal non-empty Windows username takes only the success path, and the host lookup code throws rather than producing an empty name. Please make those cases deterministic or revise the Tested description to state which path actually ran.

Current base and overlap scan

This head is 608 commits behind current main (merge base 663de1ab21). Please rebase/update and rerun the focused test.

The current overlap report flags both core/libs/prx/libkernel_sys/Export.Discovery.cpp and core/libs/CMakeLists.txt. The manual scan in the PR description covered Login.cpp and Export.Discovery.cpp, but not the CMake test registration, and predates newer open PRs. Please rerun the overlap check against current main for all changed files and update the PR notes with any order/dependency that is actually needed. I did not find a duplicate getlogin implementation in the listed kernel PRs.

Checks

  • git diff --check against current main: passed.
  • tools/check_conventions.py against current main: passed.
  • Hosted conventions, eligibility, labels, and report jobs passed; Linux, Windows, register-context, relinker, ASan relinker, and write-watch jobs were skipped.
  • I did not build or run this locally in this session. The Windows test and link-control results are author-reported on the older base.

The move to libkernel and the static-buffer success path look reasonable; the failure behavior and current-base validation need follow-up.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5611347640 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9171#pullrequestreview-5611347640). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T08:30:12Z. **Review:** DISMISSED --- ## Review Moving `getlogin` to libkernel is a sensible way to serve both import paths, and the dedicated link test is useful. I found one error-path mismatch and test-coverage gaps to resolve before approval. ### Host lookup failures The new wrapper sets guest `errno` only when `getlogin_r_nid_postfix` returns a nonzero code. In the same file, however, `ReadLogin` throws `std::system_error` when the host lookup/conversion fails and `std::runtime_error` when no account name is available. Those cases do not return through this wrapper’s `NULL` plus guest-`errno` path. Please make the host lookup failures return or translate to an error code that `getlogin` can expose, or document why exceptions are the intended guest-visible behavior. Add a deterministic test for the selected behavior. ### Test report `GuestKernelSysLogin.cpp` conditionally checks the error and empty-name branches based on the host account result; it does not force either case. In particular, a normal non-empty Windows username takes only the success path, and the host lookup code throws rather than producing an empty name. Please make those cases deterministic or revise the Tested description to state which path actually ran. ### Current base and overlap scan This head is 608 commits behind current `main` (merge base `663de1ab21`). Please rebase/update and rerun the focused test. The current overlap report flags both `core/libs/prx/libkernel_sys/Export.Discovery.cpp` and `core/libs/CMakeLists.txt`. The manual scan in the PR description covered `Login.cpp` and `Export.Discovery.cpp`, but not the CMake test registration, and predates newer open PRs. Please rerun the overlap check against current `main` for all changed files and update the PR notes with any order/dependency that is actually needed. I did not find a duplicate `getlogin` implementation in the listed kernel PRs. ### Checks - `git diff --check` against current `main`: passed. - `tools/check_conventions.py` against current `main`: passed. - Hosted conventions, eligibility, labels, and report jobs passed; Linux, Windows, register-context, relinker, ASan relinker, and write-watch jobs were skipped. - I did not build or run this locally in this session. The Windows test and link-control results are author-reported on the older base. The move to libkernel and the static-buffer success path look reasonable; the failure behavior and current-base validation need follow-up.
DavidSamir commented 2026-10-22 09:50:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T09:50:26Z.


Thanks @MarcZX10. New commits, no force-push:

  • Host lookup failures: throwing is the intended behaviour, and I've kept it. getlogin only forwards getlogin_r, and the getlogin_r entry already on main (docs/dev/debt/libkernel.md) says: "Account lookup or encoding failures, a missing or empty account name, and POSIX account records exceeding the 16 KiB lookup buffer throw; there is no replacement name or retry". That follows the repository rule that behaviour we can't confirm on the console throws instead of returning a guessed code. The console's behaviour without a login session is unknown. So getlogin returns NULL with errno only for the codes getlogin_r returns (ERANGE, EFAULT).

  • Deterministic paths (146c781256): a LoginNameForTest_nid_no_patch seam sets the name getlogin_r reads, so guest_kernel_sys_login now forces each path, whatever the host account is:

    • a short name is returned, and repeated calls return the same buffer;
    • getlogin_r with a buffer one byte short gives ERANGE without writing to it;
    • a 40-byte name gives NULL from getlogin with errno ERANGE (its buffer is 33 bytes);
    • an empty name throws.

    The original host-account check still runs first, and it states which path the host took.

  • Negative control: with getlogin not setting errno, the test fails at line 57, the 40-byte case.

  • Current base (badef62185): merges current main. guest_kernel_sys_login, guest_getlogin, guest_login_dialog and guest_login_service pass on Windows 11 (WinLibs GCC 15.2), and check_conventions.py passes.

  • Overlap, rerun on all changed files: git merge-tree adds no conflict with any PR sharing core/libs/CMakeLists.txt or Export.Discovery.cpp. #5021, #6044, #7201, #7275, #7622, #8285, #8650, #9019, #9040, #9103, #9208, #9212, #9219, #9221, #9224, #9294 and #9382 all have the same conflict hunks as against main. The one new overlap is #9693 (setlogin, opened today), which edits Login.cpp in two places next to mine. I've proposed the order on that PR and will record it here.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337847129 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9171#issuecomment-6337847129). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T09:50:26Z. --- Thanks @MarcZX10. New commits, no force-push: - **Host lookup failures:** throwing is the intended behaviour, and I've kept it. `getlogin` only forwards `getlogin_r`, and the `getlogin_r` entry already on `main` (`docs/dev/debt/libkernel.md`) says: "Account lookup or encoding failures, a missing or empty account name, and POSIX account records exceeding the 16 KiB lookup buffer throw; there is no replacement name or retry". That follows the repository rule that behaviour we can't confirm on the console throws instead of returning a guessed code. The console's behaviour without a login session is unknown. So `getlogin` returns `NULL` with errno only for the codes `getlogin_r` returns (`ERANGE`, `EFAULT`). - **Deterministic paths (`146c781256`):** a `LoginNameForTest_nid_no_patch` seam sets the name `getlogin_r` reads, so `guest_kernel_sys_login` now forces each path, whatever the host account is: - a short name is returned, and repeated calls return the same buffer; - `getlogin_r` with a buffer one byte short gives `ERANGE` without writing to it; - a 40-byte name gives `NULL` from `getlogin` with errno `ERANGE` (its buffer is 33 bytes); - an empty name throws. The original host-account check still runs first, and it states which path the host took. - **Negative control:** with `getlogin` not setting errno, the test fails at line 57, the 40-byte case. - **Current base (`badef62185`):** merges current `main`. `guest_kernel_sys_login`, `guest_getlogin`, `guest_login_dialog` and `guest_login_service` pass on Windows 11 (WinLibs GCC 15.2), and `check_conventions.py` passes. - **Overlap, rerun on all changed files:** `git merge-tree` adds no conflict with any PR sharing `core/libs/CMakeLists.txt` or `Export.Discovery.cpp`. #5021, #6044, #7201, #7275, #7622, #8285, #8650, #9019, #9040, #9103, #9208, #9212, #9219, #9221, #9224, #9294 and #9382 all have the same conflict hunks as against `main`. The one new overlap is #9693 (`setlogin`, opened today), which edits `Login.cpp` in two places next to mine. I've proposed the order on that PR and will record it here. AI-assisted: yes
MarcZX10 commented 2026-10-23 18:41:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T18:41:58Z.

Review: COMMENTED


I reviewed the implementation and its focused test. One documentation follow-up: please extend the existing getlogin_r entry in docs/dev/debt/libkernel.md to cover getlogin too. The implementation follows FreeBSD 11 for the static 33-byte result, return value, and errno, but those getlogin semantics have not been checked against a PS5. The current debt entry documents the host-account behavior and gaps for getlogin_r, not the new API wrapper. This is not a finding about the implementation logic; it keeps the unmeasured behavior visible under the repository technical-debt convention. The current hosted product suites are skipped, so the local focused test report is the runtime evidence available here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5632967925 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9171#pullrequestreview-5632967925). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T18:41:58Z. **Review:** COMMENTED --- I reviewed the implementation and its focused test. One documentation follow-up: please extend the existing `getlogin_r` entry in `docs/dev/debt/libkernel.md` to cover `getlogin` too. The implementation follows FreeBSD 11 for the static 33-byte result, return value, and `errno`, but those `getlogin` semantics have not been checked against a PS5. The current debt entry documents the host-account behavior and gaps for `getlogin_r`, not the new API wrapper. This is not a finding about the implementation logic; it keeps the unmeasured behavior visible under the repository technical-debt convention. The current hosted product suites are skipped, so the local focused test report is the runtime evidence available here.
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!9171
No description provided.