fix(libkernel): raise the Windows stdio stream limit to RLIMIT_NOFILE #7813

Merged
whamre merged 2 commits from upstream-pr/7813 into main 2026-10-19 10:52:59 +00:00
whamre commented 2026-10-19 08:33:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by whamre on 2026-10-19T08:33:25Z.


Requested by Werner

What

On Windows the C runtime allows 512 stdio streams unless _setmaxstdio raises it, and nothing in AnyPS5 does. Guest fopen/fdopen streams are stdio streams (_wfdopen in libc FileAndHeap.cpp), and so is the std::ifstream that APR opens for every read (Apr.cpp). Once about 509 streams are open, every further one fails with EMFILE, so APR reads throw APR: cannot open <path>, while getrlimit(RLIMIT_NOFILE) tells the title 8192. This is the error Soul Hackers 2 (PPSA03743) stops on intermittently in #6602, at different points depending on how many files are open.

libkernel now raises the stream limit to 8192 when it loads, the Windows counterpart of the Linux build raising RLIMIT_NOFILE to its hard limit, and the getrlimit entry in the libkernel debt file says so. guest_getrlimit opens 1024 guest streams on Windows, and guest_apr_read reads through APR while 600 guest streams are open.

Tested

Windows 11 (build 26300), WinLibs GCC 16.2.0 UCRT, full library build on current main: guest_getrlimit, file_streams, guest_filesystem, guest_posix_filesystem, guest_standard_streams (3), guest_apr_read (host, direct, eof, errors, fault, streams) and guest_ampr (markers, threads, cpp_error) pass. Without the OpenFileLimit.cpp change, guest_getrlimit aborts after 509 streams and the APR case fails with APR: cannot open ...\apr_read_generated.bin. Not tested with Soul Hackers 2 itself (no copy); Linux and macOS are unchanged.

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: PPSA03743 #6602
  • GPUs tested: n/a
  • AI-assisted: yes, generated with Claude Code

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4918128271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7813). Originally posted by [whamre](https://github.com/whamre) on 2026-10-19T08:33:25Z. --- <!-- claude-projects-attribution: {"github_login":"whamre"} --> _Requested by **Werner**_ ### What On Windows the C runtime allows 512 stdio streams unless `_setmaxstdio` raises it, and nothing in AnyPS5 does. Guest `fopen`/`fdopen` streams are stdio streams (`_wfdopen` in libc `FileAndHeap.cpp`), and so is the `std::ifstream` that APR opens for every read (`Apr.cpp`). Once about 509 streams are open, every further one fails with `EMFILE`, so APR reads throw `APR: cannot open <path>`, while `getrlimit(RLIMIT_NOFILE)` tells the title 8192. This is the error Soul Hackers 2 (PPSA03743) stops on intermittently in #6602, at different points depending on how many files are open. libkernel now raises the stream limit to 8192 when it loads, the Windows counterpart of the Linux build raising `RLIMIT_NOFILE` to its hard limit, and the `getrlimit` entry in the libkernel debt file says so. `guest_getrlimit` opens 1024 guest streams on Windows, and `guest_apr_read` reads through APR while 600 guest streams are open. ### Tested Windows 11 (build 26300), WinLibs GCC 16.2.0 UCRT, full library build on current `main`: `guest_getrlimit`, `file_streams`, `guest_filesystem`, `guest_posix_filesystem`, `guest_standard_streams` (3), `guest_apr_read` (host, direct, eof, errors, fault, streams) and `guest_ampr` (markers, threads, cpp_error) pass. Without the `OpenFileLimit.cpp` change, `guest_getrlimit` aborts after 509 streams and the APR case fails with `APR: cannot open ...\apr_read_generated.bin`. Not tested with Soul Hackers 2 itself (no copy); Linux and macOS are unchanged. ### 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: PPSA03743 #6602 - [x] GPUs tested: n/a - [x] AI-assisted: yes, generated with Claude Code 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-19 08:41:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T08:41:33Z.


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
PR 6836 core/libs/tests/GuestGetrlimit.cpp L72
docs/dev/debt/libkernel.md L167
PR 7543 docs/dev/debt/libkernel.md L167-168

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
core/libs/tests/GuestGetrlimit.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6226 core/libs/prx/libkernel/CMakeLists.txt
PR 6446 docs/dev/debt/libkernel.md
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6908 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6942 core/libs/prx/libkernel/CMakeLists.txt
PR 6977 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7039 core/libs/tests/GuestGetrlimit.cpp
docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7075 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7129 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7192 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/OpenFileLimit.cpp
PR 7299 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7332 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/OpenFileLimit.cpp
core/libs/tests/GuestGetrlimit.cpp
docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6263232454 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7813#issuecomment-6263232454). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T08:41:33Z. --- <!-- 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 | |---|---|---|---| | [PR 6836](https://www.github.com/boykopovar/AnyPS5/pull/6836) | `core/libs/tests/GuestGetrlimit.cpp` [L72](https://github.com/boykopovar/AnyPS5/blob/b7a75819f3efad870a3372eb0e2aba1d0e956657/core/libs/tests/GuestGetrlimit.cpp#L72)<br>`docs/dev/debt/libkernel.md` [L167](https://github.com/boykopovar/AnyPS5/blob/b7a75819f3efad870a3372eb0e2aba1d0e956657/docs/dev/debt/libkernel.md#L167) | | | | [PR 7543](https://www.github.com/boykopovar/AnyPS5/pull/7543) | `docs/dev/debt/libkernel.md` [L167-168](https://github.com/boykopovar/AnyPS5/blob/b7a75819f3efad870a3372eb0e2aba1d0e956657/docs/dev/debt/libkernel.md#L167-L168) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/tests/GuestGetrlimit.cpp` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6446](https://www.github.com/boykopovar/AnyPS5/pull/6446) | `docs/dev/debt/libkernel.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6519](https://www.github.com/boykopovar/AnyPS5/pull/6519) | `docs/dev/debt/libkernel.md` | | [PR 6908](https://www.github.com/boykopovar/AnyPS5/pull/6908) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6942](https://www.github.com/boykopovar/AnyPS5/pull/6942) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 7039](https://www.github.com/boykopovar/AnyPS5/pull/7039) | `core/libs/tests/GuestGetrlimit.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7049](https://www.github.com/boykopovar/AnyPS5/pull/7049) | `docs/dev/debt/libkernel.md` | | [PR 7075](https://www.github.com/boykopovar/AnyPS5/pull/7075) | `docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `docs/dev/debt/libkernel.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `docs/dev/debt/libkernel.md` | | [PR 7129](https://www.github.com/boykopovar/AnyPS5/pull/7129) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `docs/dev/debt/libkernel.md` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/OpenFileLimit.cpp` | | [PR 7299](https://www.github.com/boykopovar/AnyPS5/pull/7299) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/OpenFileLimit.cpp`<br>`core/libs/tests/GuestGetrlimit.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `docs/dev/debt/libkernel.md` |
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!7813
No description provided.