feat(libkernel): export setrlimit #3980

Merged
MarcZX10 merged 3 commits from upstream-pr/3980 into main 2026-10-12 20:57:08 +00:00
MarcZX10 commented 2026-10-11 20:28:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T20:28:36Z.


What

Implements the unclaimed setrlimit export from #3558. The call validates a null limit before the resource number, maps negative values to RLIM_INFINITY, and clamps a soft limit that exceeds the hard limit, following FreeBSD 11. It returns success when the normalized request matches what getrlimit reports. A change throws because the emulator does not store guest limit state; resources that getrlimit cannot report remain unsupported.

This PR contains only setrlimit. The credential setters and the separate getrlimit work are tracked by their own changes.

Tested

  • Linux x86-64, GCC 12.2.0, Release: built guest_setrlimit_tests; CTest guest_setrlimit passed 1/1.
  • Locally: tools/check_conventions.py --base upstream/main and git diff --check passed.
  • Windows and console hardware were not tested locally.

Checklist

  • Based on current main
  • One topic per PR
  • Unsupported changes throw explicitly
  • No new third-party code
  • AI-assisted: yes

Depends on: none

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4822108717 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3980). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T20:28:36Z. --- ### What Implements the unclaimed `setrlimit` export from #3558. The call validates a null limit before the resource number, maps negative values to `RLIM_INFINITY`, and clamps a soft limit that exceeds the hard limit, following FreeBSD 11. It returns success when the normalized request matches what `getrlimit` reports. A change throws because the emulator does not store guest limit state; resources that `getrlimit` cannot report remain unsupported. This PR contains only `setrlimit`. The credential setters and the separate `getrlimit` work are tracked by their own changes. ### Tested - Linux x86-64, GCC 12.2.0, Release: built `guest_setrlimit_tests`; CTest `guest_setrlimit` passed 1/1. - Locally: `tools/check_conventions.py --base upstream/main` and `git diff --check` passed. - Windows and console hardware were not tested locally. ### Checklist - [x] Based on current `main` - [x] One topic per PR - [x] Unsupported changes throw explicitly - [x] No new third-party code - [x] AI-assisted: yes Depends on: none
github-actions[bot] commented 2026-10-11 20:28:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T20:28:57Z.


Progress report (529f7bf → f89c7fb)

➖ System libraries: 87.37% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel setrlimit_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113406990 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3980#issuecomment-6113406990). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T20:28:57Z. --- <!-- progress-report --> ### Progress report (529f7bf → f89c7fb) ➖ **System libraries**: 87.37% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `setrlimit_nid_postfix` | </details>
babyhuey commented 2026-10-11 22:46:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T22:46:18Z.


I checked this PR on both OSes with XPSemu (PPSA97358) and PS5MC (PPSA99420), catalog builds. With #3580 merged, both stop at setrlimit on main 5aaf26bd:

  • Linux: undefined symbol: 4X0QwvuCfjc (setrlimit)
  • Windows: FAIL: unresolved ELF import 4X0QwvuCfjc (setrlimit) from libkernel.prx
  • With this PR merged locally (e96cb3a3; the only conflict was a TechnicalDebt line, kept both), setrlimit resolves on both OSes:
    • XPSemu then stops at mlockall (x7g7Ebeo8-U, in your #3650).
    • PS5MC then stops at tcsendbreak (vXE-dIUIZlE, in #3781).
  • On Windows 11 (MinGW GCC 15.2, #4021 stacked) the stop lines are FAIL: unresolved ELF import x7g7Ebeo8-U (mlockall) from libkernel.prx and ... vXE-dIUIZlE (tcsendbreak) from libkernel.prx.
  • guest_setrlimit passes 5/5 (--repeat until-fail:5) on both. No warnings in Process.cpp or GuestSetrlimit.cpp.
  • Clamping rlim_cur to rlim_max matches FreeBSD 11's kern_proc_setrlimit (sys/kern/kern_resource.c, stable/11).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114749643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3980#issuecomment-6114749643). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T22:46:18Z. --- I checked this PR on both OSes with XPSemu (PPSA97358) and PS5MC (PPSA99420), catalog builds. With #3580 merged, both stop at `setrlimit` on `main` 5aaf26bd: - Linux: `undefined symbol: 4X0QwvuCfjc (setrlimit)` - Windows: `FAIL: unresolved ELF import 4X0QwvuCfjc (setrlimit) from libkernel.prx` - With this PR merged locally (e96cb3a3; the only conflict was a TechnicalDebt line, kept both), `setrlimit` resolves on both OSes: - XPSemu then stops at `mlockall` (`x7g7Ebeo8-U`, in your #3650). - PS5MC then stops at `tcsendbreak` (`vXE-dIUIZlE`, in #3781). - On Windows 11 (MinGW GCC 15.2, #4021 stacked) the stop lines are `FAIL: unresolved ELF import x7g7Ebeo8-U (mlockall) from libkernel.prx` and `... vXE-dIUIZlE (tcsendbreak) from libkernel.prx`. - `guest_setrlimit` passes 5/5 (`--repeat until-fail:5`) on both. No warnings in `Process.cpp` or `GuestSetrlimit.cpp`. - Clamping `rlim_cur` to `rlim_max` matches FreeBSD 11's `kern_proc_setrlimit` (`sys/kern/kern_resource.c`, stable/11).
oneandonlydean commented 2026-10-12 08:24:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T08:24:46Z.


Conflicts with main in core/libs/prx/libkernel/System/src/Process.cpp and docs/dev/TechnicalDebt.md; please rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120528993 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3980#issuecomment-6120528993). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T08:24:46Z. --- Conflicts with main in `core/libs/prx/libkernel/System/src/Process.cpp` and `docs/dev/TechnicalDebt.md`; please rebase.
Nixitov commented 2026-10-12 16:43:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nixitov on 2026-10-12T16:43:56Z.


Build verification on Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release fails on this branch:

core/libs/prx/libkernel/System/src/Process.cpp:322:5: error: 'getrlimit_nid_postfix' was not declared in this scope; did you mean 'setrlimit_nid_postfix'?

setrlimit_nid_postfix calls getrlimit_nid_postfix at line 322, but that function is only defined at line 489 of the same file, with no declaration in scope before the call (no header declares it on this branch either).

A forward declaration before the call fixes it, e.g. in Process.cpp:

extern "C" int APS5_VABI getrlimit_nid_postfix(int resource, GuestResourceLimit* limit);

I could not run the setrlimit titles (PPSA50011, PPSA97358, PPSA99420) against this branch because the library does not build, so the "gets past 4X0QwvuCfjc" evidence is still untested. Happy to re-run once it compiles.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6128583989 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3980#issuecomment-6128583989). Originally posted by [Nixitov](https://github.com/Nixitov) on 2026-10-12T16:43:56Z. --- Build verification on **Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release** fails on this branch: ``` core/libs/prx/libkernel/System/src/Process.cpp:322:5: error: 'getrlimit_nid_postfix' was not declared in this scope; did you mean 'setrlimit_nid_postfix'? ``` `setrlimit_nid_postfix` calls `getrlimit_nid_postfix` at line 322, but that function is only *defined* at line 489 of the same file, with no declaration in scope before the call (no header declares it on this branch either). A forward declaration before the call fixes it, e.g. in `Process.cpp`: ```cpp extern "C" int APS5_VABI getrlimit_nid_postfix(int resource, GuestResourceLimit* limit); ``` I could not run the `setrlimit` titles (PPSA50011, PPSA97358, PPSA99420) against this branch because the library does not build, so the "gets past `4X0QwvuCfjc`" evidence is still untested. Happy to re-run once it compiles. AI-assisted: yes
MarcZX10 commented 2026-10-12 19:43:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:43:37Z.


Thanks for catching this. I confirmed the current head calls getrlimit_nid_postfix before its definition and has no earlier declaration, so the Windows compile failure is valid. We will update the head before asking you to rerun the build or title checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131395681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3980#issuecomment-6131395681). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:43:37Z. --- Thanks for catching this. I confirmed the current head calls `getrlimit_nid_postfix` before its definition and has no earlier declaration, so the Windows compile failure is valid. We will update the head before asking you to rerun the build or title checks.
MarcZX10 commented 2026-10-12 19:49:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T19:49:25Z.


Fixed in commit 2db6f669 with a forward declaration before setrlimit_nid_postfix. On Linux, the guest_setrlimit_tests target builds and ctest -R '^guest_setrlimit$' passes 1/1; git diff --check and tools/check_conventions.py --base origin/main pass. This environment has no MinGW cross-compiler, so I could not reproduce the Windows build locally. @Nixitov, could you confirm the current head builds on Windows and rerun the title checks now that the compile error is fixed?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131484130 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3980#issuecomment-6131484130). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T19:49:25Z. --- Fixed in commit `2db6f669` with a forward declaration before `setrlimit_nid_postfix`. On Linux, the `guest_setrlimit_tests` target builds and `ctest -R '^guest_setrlimit$'` passes 1/1; `git diff --check` and `tools/check_conventions.py --base origin/main` pass. This environment has no MinGW cross-compiler, so I could not reproduce the Windows build locally. @Nixitov, could you confirm the current head builds on Windows and rerun the title checks now that the compile error is fixed?
MarcZX10 commented 2026-10-12 20:02:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T20:02:27Z.


Additional validation: I installed Debian MinGW-w64 GCC 12 and cross-compiled the affected Process.cpp as a Windows target (x86_64-w64-mingw32-g++ -std=gnu++20 -fno-asynchronous-unwind-tables, project include paths). The translation unit compiles successfully with the declaration on this head. This is not the repository-supported WinLibs GCC 15.2 toolchain and does not replace a native Windows run; @Nixitov, please still confirm on your supported build and retry the title checks when available.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6131679786 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3980#issuecomment-6131679786). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T20:02:27Z. --- Additional validation: I installed Debian MinGW-w64 GCC 12 and cross-compiled the affected `Process.cpp` as a Windows target (`x86_64-w64-mingw32-g++ -std=gnu++20 -fno-asynchronous-unwind-tables`, project include paths). The translation unit compiles successfully with the declaration on this head. This is not the repository-supported WinLibs GCC 15.2 toolchain and does not replace a native Windows run; @Nixitov, please still confirm on your supported build and retry the title checks when available.
adriadam10 commented 2026-10-12 20:52:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:52:50Z.


Checked against FreeBSD 11 kern_setrlimit (null limit before resource, negative → infinity, soft clamped to hard), built libkernel and ran guest_setrlimit and guest_getrlimit on Linux (pass). The Windows forward-declaration fix is already on the head.

Added in our own commit: moved the TechnicalDebt line next to the getrlimit one, so it no longer sits at the end of the section where #4651 and #4740 also append.

Not verified here: a native Windows build (@Nixitov's MinGW GCC 15.2 run) and behaviour on the console. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132416740 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3980#issuecomment-6132416740). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-12T20:52:50Z. --- Checked against FreeBSD 11 `kern_setrlimit` (null limit before resource, negative → infinity, soft clamped to hard), built libkernel and ran `guest_setrlimit` and `guest_getrlimit` on Linux (pass). The Windows forward-declaration fix is already on the head. Added in our own commit: moved the TechnicalDebt line next to the `getrlimit` one, so it no longer sits at the end of the section where #4651 and #4740 also append. Not verified here: a native Windows build (@Nixitov's MinGW GCC 15.2 run) and behaviour on the console. Merging once CI is green.
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!3980
No description provided.