Skip to content

feat(libkernel): implement getrlimit for RLIMIT_DATA - #1675

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Recapi:feat/libkernel-getrlimit
Oct 9, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Recapi:feat/libkernel-getrlimit

Conversation

@Recapi

@Recapi Recapi commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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 f145139, 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

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

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

Recapi commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor

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 b7218b3 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

@popcoder565 popcoder565 mentioned this pull request Oct 9, 2026
9 tasks done
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 merged commit 6642559 into boykopovar:main Oct 9, 2026
6 of 7 checks passed
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Progress report (f145139 → 851f3b7)

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

✅ 1 implemented
Library Name
libkernel getrlimit_nid_postfix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants