feat(libkernel_sys): implement sceKernelMlockall #10657

Open
joucknuck-br wants to merge 4 commits from upstream-pr/10657 into main
joucknuck-br commented 2026-10-24 15:28:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by joucknuck-br on 2026-10-24T15:28:29Z.


What

Implement sceKernelMlockall(int flags) in libkernel_sys by forwarding to libkernel's mlockall_nid_postfix and mapping a non-zero POSIX result to 0x80020000 | errno, returning SCE_KERNEL_ERROR_EINVAL for zero or unknown flags and throwing for MCL_CURRENT and MCL_FUTURE.

Tested

Linux (WSL2 Ubuntu 24.04), guest_kernel_sys_barrier_tests via ctest --test-dir build -R guest_kernel_sys_barrier -V:

  • sceKernelMlockall(0) returns SCE_KERNEL_ERROR_EINVAL
  • sceKernelMlockall(0x4) and sceKernelMlockall(-4) return SCE_KERNEL_ERROR_EINVAL
  • sceKernelMlockall(MCL_CURRENT), sceKernelMlockall(MCL_FUTURE), and sceKernelMlockall(MCL_CURRENT | MCL_FUTURE) throw std::runtime_error

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:4996677279 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10657). Originally posted by [joucknuck-br](https://github.com/joucknuck-br) on 2026-10-24T15:28:29Z. --- ### What Implement `sceKernelMlockall(int flags)` in `libkernel_sys` by forwarding to `libkernel`'s `mlockall_nid_postfix` and mapping a non-zero POSIX result to `0x80020000 | errno`, returning `SCE_KERNEL_ERROR_EINVAL` for zero or unknown flags and throwing for `MCL_CURRENT` and `MCL_FUTURE`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux (WSL2 Ubuntu 24.04), `guest_kernel_sys_barrier_tests` via `ctest --test-dir build -R guest_kernel_sys_barrier -V`: - `sceKernelMlockall(0)` returns `SCE_KERNEL_ERROR_EINVAL` - `sceKernelMlockall(0x4)` and `sceKernelMlockall(-4)` return `SCE_KERNEL_ERROR_EINVAL` - `sceKernelMlockall(MCL_CURRENT)`, `sceKernelMlockall(MCL_FUTURE)`, and `sceKernelMlockall(MCL_CURRENT | MCL_FUTURE)` throw `std::runtime_error` ### 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<!-- #PR, or none --> - [x] Fixes: none<!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none<!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a<!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes<!-- yes / no -->
MarcZX10 commented 2026-10-24 15:29:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:29:59Z.

Review: CHANGES_REQUESTED


The changed export forwards the flag argument to the existing libkernel bridge, which is a useful step, and the focused tests cover invalid flags. However, the only valid flags (MCL_CURRENT, MCL_FUTURE, and their combination) all throw in mlockall_nid_postfix; this PR therefore does not implement the advertised operation for any supported request. The repository rule says an export that cannot be implemented must throw and record the gap. Please either implement at least a meaningful supported behavior, or keep the export explicitly unsupported and describe this as a follow-up investigation rather than an implementation. If the throws remain intentional, update the debt entry to identify the still-unimplemented behavior and its limitation instead of describing only the forwarding. The PR also changes the discovered function signature from no arguments to int flags; please add the source/ABI evidence for that signature and a test that exercises the successful return path if one is supportable. The local test report is author-reported; hosted product jobs did not run. I did not run the focused test locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638788442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10657#pullrequestreview-5638788442). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T15:29:59Z. **Review:** CHANGES_REQUESTED --- The changed export forwards the flag argument to the existing libkernel bridge, which is a useful step, and the focused tests cover invalid flags. However, the only valid flags (`MCL_CURRENT`, `MCL_FUTURE`, and their combination) all throw in `mlockall_nid_postfix`; this PR therefore does not implement the advertised operation for any supported request. The repository rule says an export that cannot be implemented must throw and record the gap. Please either implement at least a meaningful supported behavior, or keep the export explicitly unsupported and describe this as a follow-up investigation rather than an implementation. If the throws remain intentional, update the debt entry to identify the still-unimplemented behavior and its limitation instead of describing only the forwarding. The PR also changes the discovered function signature from no arguments to `int flags`; please add the source/ABI evidence for that signature and a test that exercises the successful return path if one is supportable. The local test report is author-reported; hosted product jobs did not run. I did not run the focused test locally.
MarcZX10 commented 2026-10-24 15:45:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:45:11Z.

Review: APPROVED


Re-reviewed exact head 3e24f90def5d3b27ff06f72f32e70756cddd0daa. The change now clearly leaves valid memory-lock requests unsupported: invalid flags return mapped EINVAL, while MCL_CURRENT/MCL_FUTURE continue to throw through the existing bridge, and the debt entry states this limitation. I verified the int flags signature in Orbital’s type database and the flag validation/error mapping against the pinned fpPS4 ps4_map_mm.pas reference. The focused Linux test results in the PR description are author-reported; this PR’s hosted product test jobs did not run, and I did not independently run them. The conventions and labels checks pass. I found no remaining blocking issue for this explicitly partial implementation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638831756 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10657#pullrequestreview-5638831756). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T15:45:11Z. **Review:** APPROVED --- Re-reviewed exact head `3e24f90def5d3b27ff06f72f32e70756cddd0daa`. The change now clearly leaves valid memory-lock requests unsupported: invalid flags return mapped `EINVAL`, while `MCL_CURRENT`/`MCL_FUTURE` continue to throw through the existing bridge, and the debt entry states this limitation. I verified the `int flags` signature in Orbital’s type database and the flag validation/error mapping against the pinned fpPS4 `ps4_map_mm.pas` reference. The focused Linux test results in the PR description are author-reported; this PR’s hosted product test jobs did not run, and I did not independently run them. The conventions and labels checks pass. I found no remaining blocking issue for this explicitly partial implementation.
MarcZX10 commented 2026-11-18 15:48:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T15:48:32Z.

Review: APPROVED


Reviewed — looks good

Nothing in the reviewed changes blocks merging; the forwarding implementation matches the existing libkernel behavior and the test covers invalid flags.

What I ran

Reviewed head 9aa0b5645eb2926c2c3b45fea1932b408aac2196. No commands or tests were run. Read the four changed files listed as reviewed in manifest.json; no changed files were excluded.

Results

Check Result Note
Diff and changed files passed Four changed files reviewed
Tests not run No local test execution

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports running guest_kernel_sys_barrier_tests under WSL2 Ubuntu 24.04; this review did not independently run that test. Console behavior is not measured, as noted in the debt entry.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5960027860 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10657#pullrequestreview-5960027860). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T15:48:32Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the reviewed changes blocks merging; the forwarding implementation matches the existing libkernel behavior and the test covers invalid flags. ## What I ran Reviewed head `9aa0b5645eb2926c2c3b45fea1932b408aac2196`. No commands or tests were run. Read the four changed files listed as reviewed in `manifest.json`; no changed files were excluded. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | Four changed files reviewed | | Tests | not run | No local test execution | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports running `guest_kernel_sys_barrier_tests` under WSL2 Ubuntu 24.04; this review did not independently run that test. Console behavior is not measured, as noted in the debt entry. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 17:17:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:17:21Z.

Review: COMMENTED


Please reconcile this wrapper with the mlockall_nid_postfix implementation on current main. The implementation at the PR head validates the flags, but the merge result against de4730493a calls the newer helper that returns GuestNotPermitted for every value. The wrapper therefore maps sceKernelMlockall(0) to EPERM even though the added assertion expects EINVAL. The supported-flag path also returns EPERM, while the PR description says it throws.

I reproduced a guest_kernel_sys_barrier abort after integrating 9aa0b5645e into a Linux release build. I then checked the helper in the merge result against current main and confirmed the error-mapping discrepancy in source.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6174773918 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10657#pullrequestreview-6174773918). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T17:17:21Z. **Review:** COMMENTED --- Please reconcile this wrapper with the `mlockall_nid_postfix` implementation on current `main`. The implementation at the PR head validates the flags, but the merge result against `de4730493a` calls the newer helper that returns `GuestNotPermitted` for every value. The wrapper therefore maps `sceKernelMlockall(0)` to `EPERM` even though the added assertion expects `EINVAL`. The supported-flag path also returns `EPERM`, while the PR description says it throws. I reproduced a `guest_kernel_sys_barrier` abort after integrating `9aa0b5645e` into a Linux release build. I then checked the helper in the merge result against current `main` and confirmed the error-mapping discrepancy in source. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/10657:upstream-pr/10657'
git switch 'upstream-pr/10657'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/10657'
git switch 'upstream-pr/10657'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/10657'
git switch 'upstream-pr/10657'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/10657'
git switch 'main'
git merge --squash 'upstream-pr/10657'
git switch 'main'
git merge --ff-only 'upstream-pr/10657'
git switch 'main'
git merge 'upstream-pr/10657'
git push origin 'main'
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!10657
No description provided.