feat(libkernel): implement getrlimit for RLIMIT_DATA #1675

Merged
Recapi merged 1 commit from upstream-pr/1675 into main 2026-10-09 22:00:57 +00:00
Recapi commented 2026-10-08 16:13:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-08T16:13:42Z.


What

getrlimit in libkernel for RLIMIT_DATA (2), the only resource the importing titles read.

  • The limit is the host process's, which is the emulated process: on Linux the host getrlimit(RLIMIT_DATA), with RLIM_INFINITY reported as the FreeBSD RLIM_INFINITY (INT64_MAX); on Windows the job object's process memory limit, or RLIM_INFINITY when the process has none.
  • Errors follow FreeBSD kern_getrlimit: a resource outside 0..14 returns -1 with EINVAL, checked before the output pointer; a null pointer returns -1 with EFAULT.
  • Every other resource throws until a title reaches it.

Caller: PPSA99005 (blackbearreloaded/ps5-opengl v1.0.1) imports getrlimit (#1578; 19 of the 34 catalog titles in the audit there). In its SDK (ps5-opengl-sdk 1.0.1) the only references are in Mesa, libmesa_util.a os_misc.c.o and libpsbc.ps5.a os_misc.ps5.o: os_get_available_system_memory (src/util/os_misc.c, FreeBSD branch) calls getrlimit(RLIMIT_DATA) after sysctl(CTL_HW, HW_USERMEM). Values on hardware were not measured.

Log

PPSA99005 (blackbearreloaded/ps5-opengl showcase v1.0.1), relinked on Linux (Ubuntu, GCC 15.2.0, main f1451396, bundled libc.prx kept) and run in a bwrap sandbox. On main it stops on mkstemp, as in #1578:

./app.elf: symbol lookup error: ./app.elf: undefined symbol: uEtgPWgPxOk

With the open PRs for its earlier absent imports merged locally (#1978, #1869, #1656, #1729, #1613, #1714, #1482, #1650, #1872, #1641, #1685, #1859; no conflicts), the stops are:

Merged on top Stop
the 12 PRs above Wh7HbV7JFqc (getrlimit, #1675)
+ #1675 JZKw5+Wrnaw (pthread_sigmask, no PR yet)
+ #1675, a local throwaway pthread_sigmask export nnoxZUHK+SA (pthread_getcpuclockid, #1676)
+ #1675, #1676, the throwaway export, #1529 no absent import; Mesa starts its threads and the title then aborts in the AGC driver (#2026)

Each stop is the loader's line, e.g. ./app.elf: symbol lookup error: ./app.elf: undefined symbol: Wh7HbV7JFqc. The throwaway pthread_sigmask only exports the NID and throws when called; it was not called before the abort.

Tested

Ubuntu, Linux 7.0, GCC 15.2.0, full build with BUILD_TESTING=ON. New test guest_getrlimit: matches the host getrlimit(RLIMIT_DATA), reports a lowered setrlimit soft limit, EINVAL/EFAULT order, throws for RLIMIT_NOFILE and RLIMIT_AS. Patched libkernel.prx exports Wh7HbV7JFqc.
The project's Build workflow on the fork (Linux, Windows MinGW, relinker on Ubuntu/Windows/macOS) passes; the run is linked in a comment below. Run with PPSA99005 as above.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4789652493 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1675). Originally posted by [Recapi](https://github.com/Recapi) on 2026-10-08T16:13:42Z. --- ### What `getrlimit` in libkernel for `RLIMIT_DATA` (2), the only resource the importing titles read. - The limit is the host process's, which is the emulated process: on Linux the host `getrlimit(RLIMIT_DATA)`, with `RLIM_INFINITY` reported as the FreeBSD `RLIM_INFINITY` (`INT64_MAX`); on Windows the job object's process memory limit, or `RLIM_INFINITY` when the process has none. - Errors follow FreeBSD `kern_getrlimit`: a resource outside 0..14 returns -1 with `EINVAL`, checked before the output pointer; a null pointer returns -1 with `EFAULT`. - Every other resource throws until a title reaches it. Caller: PPSA99005 ([blackbearreloaded/ps5-opengl](https://github.com/blackbearreloaded/ps5-opengl) v1.0.1) imports `getrlimit` (#1578; 19 of the 34 catalog titles in the audit there). In its SDK (ps5-opengl-sdk 1.0.1) the only references are in Mesa, `libmesa_util.a` `os_misc.c.o` and `libpsbc.ps5.a` `os_misc.ps5.o`: `os_get_available_system_memory` (`src/util/os_misc.c`, FreeBSD branch) calls `getrlimit(RLIMIT_DATA)` after `sysctl(CTL_HW, HW_USERMEM)`. Values on hardware were not measured. ### Log PPSA99005 ([blackbearreloaded/ps5-opengl](https://github.com/blackbearreloaded/ps5-opengl) showcase v1.0.1), relinked on Linux (Ubuntu, GCC 15.2.0, `main` f1451396, bundled `libc.prx` kept) and run in a `bwrap` sandbox. On `main` it stops on `mkstemp`, as in #1578: ``` ./app.elf: symbol lookup error: ./app.elf: undefined symbol: uEtgPWgPxOk ``` With the open PRs for its earlier absent imports merged locally (#1978, #1869, #1656, #1729, #1613, #1714, #1482, #1650, #1872, #1641, #1685, #1859; no conflicts), the stops are: | Merged on top | Stop | |---|---| | the 12 PRs above | `Wh7HbV7JFqc` (`getrlimit`, #1675) | | + #1675 | `JZKw5+Wrnaw` (`pthread_sigmask`, no PR yet) | | + #1675, a local throwaway `pthread_sigmask` export | `nnoxZUHK+SA` (`pthread_getcpuclockid`, #1676) | | + #1675, #1676, the throwaway export, #1529 | no absent import; Mesa starts its threads and the title then aborts in the AGC driver (#2026) | Each stop is the loader's line, e.g. `./app.elf: symbol lookup error: ./app.elf: undefined symbol: Wh7HbV7JFqc`. The throwaway `pthread_sigmask` only exports the NID and throws when called; it was not called before the abort. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. --> Ubuntu, Linux 7.0, GCC 15.2.0, full build with `BUILD_TESTING=ON`. New test `guest_getrlimit`: matches the host `getrlimit(RLIMIT_DATA)`, reports a lowered `setrlimit` soft limit, `EINVAL`/`EFAULT` order, throws for `RLIMIT_NOFILE` and `RLIMIT_AS`. Patched `libkernel.prx` exports `Wh7HbV7JFqc`. The project's Build workflow on the fork (Linux, Windows MinGW, relinker on Ubuntu/Windows/macOS) passes; the run is linked in a comment below. Run with PPSA99005 as above. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-08 17:08:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T17:08:39Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1727 __error_nid_postfix
#1729 __error_nid_postfix
#1738 __error_nid_postfix
#1772 __error_nid_postfix
#1841 __error_nid_postfix
#1860 __error_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065085159 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1675#issuecomment-6065085159). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T17:08:39Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1727 | | `__error_nid_postfix` | | | #1729 | | `__error_nid_postfix` | | | #1738 | | `__error_nid_postfix` | | | #1772 | | `__error_nid_postfix` | | | #1841 | | `__error_nid_postfix` | | | #1860 | | `__error_nid_postfix` | |
Recapi commented 2026-10-08 17:25:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-08T17:25:27Z.


CI is waiting for first-time contributor approval here, so I ran the project's Build workflow (build.yml, workflow_dispatch) on the fork for this head (851f3b7a): https://github.com/Recapi/AnyPS5/actions/runs/37876692013

  • linux: 467/467, guest_getrlimit passed
  • windows (MinGW): 458/458, guest_getrlimit passed
  • relinker on ubuntu, windows and macos: passed

Overlap: no textual conflict with the open PRs that change these files (git merge-tree against each; #1128, the clang-format of the tree, already conflicts with main). The test registration now follows guest_kernel_errors, clear of #1908's and #1477's insertions. The __error_nid_postfix rows are the declaration used to set errno, not an export.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065372695 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1675#issuecomment-6065372695). Originally posted by [Recapi](https://github.com/Recapi) on 2026-10-08T17:25:27Z. --- CI is waiting for first-time contributor approval here, so I ran the project's Build workflow (`build.yml`, `workflow_dispatch`) on the fork for this head (`851f3b7a`): https://github.com/Recapi/AnyPS5/actions/runs/37876692013 - linux: 467/467, `guest_getrlimit` passed - windows (MinGW): 458/458, `guest_getrlimit` passed - relinker on ubuntu, windows and macos: passed Overlap: no textual conflict with the open PRs that change these files (`git merge-tree` against each; #1128, the clang-format of the tree, already conflicts with `main`). The test registration now follows `guest_kernel_errors`, clear of #1908's and #1477's insertions. The `__error_nid_postfix` rows are the declaration used to set `errno`, not an export.
popcoder565 commented 2026-10-09 10:04:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T10:04:01Z.


First Windows run, since the description says it wasn't tested on Windows.

Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Merged onto main b7218b3c together with nine other small libc/libkernel PRs: #1975, #1976, #1977, #1859, #1685, #1676, #1641, #1656, #1807.

  • guest_getrlimit passes (on Windows it takes the test's _WIN32 branch, GuestLimit(GUEST_RLIMIT_DATA)).
  • Full ctest: 510/510 (one GPU test skipped for a device limit).

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078729957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1675#issuecomment-6078729957). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T10:04:01Z. --- First Windows run, since the description says it wasn't tested on Windows. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Merged onto `main` b7218b3c together with nine other small libc/libkernel PRs: #1975, #1976, #1977, #1859, #1685, #1676, #1641, #1656, #1807. - `guest_getrlimit` passes (on Windows it takes the test's `_WIN32` branch, `GuestLimit(GUEST_RLIMIT_DATA)`). - Full ctest: 510/510 (one GPU test skipped for a device limit). _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-09 22:00:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:00:54Z.


Checked on Linux (merged onto current main): full build + ctest 524/524, guest_getrlimit passes and fails to link without the change. Error order (EINVAL for a resource outside 0..14 before the pointer, then EFAULT) matches FreeBSD kern_getrlimit, and reporting no limit by default agrees with SharpProspero's getrlimit. Windows run by @popcoder565 passes too. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089974653 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1675#issuecomment-6089974653). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T22:00:54Z. --- Checked on Linux (merged onto current `main`): full build + ctest 524/524, `guest_getrlimit` passes and fails to link without the change. Error order (`EINVAL` for a resource outside 0..14 before the pointer, then `EFAULT`) matches FreeBSD `kern_getrlimit`, and reporting no limit by default agrees with SharpProspero's `getrlimit`. Windows run by @popcoder565 passes too. Merging.
github-actions[bot] commented 2026-10-09 22:01:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:01:17Z.


Progress report (f145139 → 851f3b7)

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

✅ 1 implemented
Library Name
libkernel getrlimit_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089979604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1675#issuecomment-6089979604). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T22:01:17Z. --- <!-- progress-report --> ### Progress report (f145139 → 851f3b7) ➖ **System libraries**: 84.76% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `getrlimit_nid_postfix` | </details>
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!1675
No description provided.