feat(libkernel): open /dev/random and /dev/urandom for reading #1777

Merged
MathiasDevelopes merged 2 commits from upstream-pr/1777 into main 2026-10-10 07:27:46 +00:00
MathiasDevelopes commented 2026-10-08 18:58:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-08T18:58:35Z.


What

/dev/random and /dev/urandom resolved to files under the guest root that do not exist, so open failed. Titles that read entropy from them then read from the failed descriptor: Planet Coaster (PPSA01736) aborts in sceKernelRead with fd=-1, errno=9.

Opening either path for reading now returns a descriptor backed by the host's null device. read, pread, readv and preadv on it fill the buffer from std::random_device, the source sceRandomGetRandomNumber already uses. As on FreeBSD, both devices behave the same and positioned reads ignore the offset. Opening them for writing (adding entropy) throws. Closing a descriptor, through close or sceKernelClose, forgets it.

Tested

Windows 11, MinGW-w64 15.2.0. guest_filesystem opens both paths and checks read. guest_file_vector checks readv, preadv and pread on /dev/urandom. The full ctest suite passes (476/476), and tools/check_conventions.py --base origin/main passes. With this change, Planet Coaster (PPSA01736) no longer aborts reading /dev/urandom at startup. Linux: built and run only through the shared code; the Linux-only pread, readv and preadv branches are not run on Linux.

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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4791465405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1777). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-08T18:58:35Z. --- ### What `/dev/random` and `/dev/urandom` resolved to files under the guest root that do not exist, so `open` failed. Titles that read entropy from them then read from the failed descriptor: Planet Coaster (PPSA01736) aborts in `sceKernelRead` with `fd=-1, errno=9`. Opening either path for reading now returns a descriptor backed by the host's null device. `read`, `pread`, `readv` and `preadv` on it fill the buffer from `std::random_device`, the source `sceRandomGetRandomNumber` already uses. As on FreeBSD, both devices behave the same and positioned reads ignore the offset. Opening them for writing (adding entropy) throws. Closing a descriptor, through `close` or `sceKernelClose`, forgets it. ### Tested Windows 11, MinGW-w64 15.2.0. `guest_filesystem` opens both paths and checks `read`. `guest_file_vector` checks `readv`, `preadv` and `pread` on `/dev/urandom`. The full ctest suite passes (476/476), and `tools/check_conventions.py --base origin/main` passes. With this change, Planet Coaster (PPSA01736) no longer aborts reading `/dev/urandom` at startup. Linux: built and run only through the shared code; the Linux-only `pread`, `readv` and `preadv` branches are not run on Linux. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-08 18:58:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-08T18:58:40Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5461494201 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1777#pullrequestreview-5461494201). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-08T18:58:40Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
oneandonlydean commented 2026-10-10 03:18:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:18:56Z.


This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093232159 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1777#issuecomment-6093232159). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T03:18:56Z. --- This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.
adriadam10 commented 2026-10-10 07:19:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:19:09Z.


Rebased onto current main (conflicts were only include/source-list adjacency); build and the affected tests pass on Linux (400/400).

Also added one commit: a "Functional" line in docs/dev/TechnicalDebt.md for the unverified choices (both devices identical, never block, positioned reads ignore the offset, only the exact paths recognised, duped descriptors read as empty, write-open throws).

Merging once CI is green on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095052431 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1777#issuecomment-6095052431). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:19:09Z. --- Rebased onto current main (conflicts were only include/source-list adjacency); build and the affected tests pass on Linux (400/400). Also added one commit: a "Functional" line in `docs/dev/TechnicalDebt.md` for the unverified choices (both devices identical, never block, positioned reads ignore the offset, only the exact paths recognised, `dup`ed descriptors read as empty, write-open throws). Merging once CI is green on the new head.
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!1777
No description provided.