feat(posix): implement mkstemp and isatty #1613

Merged
NumberGuan merged 2 commits from upstream-pr/1613 into main 2026-10-09 21:37:02 +00:00
NumberGuan commented 2026-10-08 14:46:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NumberGuan on 2026-10-08T14:46:23Z.


What

Implement mkstemp and isatty in libScePosixForWebKit for the homebrew imports reported in #1578.

mkstemp uses the guest path resolver and existing open implementation, creates files exclusively with read/write access and mode 0600, and handles collisions without truncating existing files. Its trailing-X and fixed-name behavior follows FreeBSD 9.

isatty distinguishes terminals, non-terminal files/pipes/sockets (ENOTTY), and invalid descriptors (EBADF), following FreeBSD's terminal check. Windows checks console handles and handles invalid CRT descriptors without aborting.

The socket check calls GuestSocketIsOpen_nid_no_patch, a C host helper whose export survives NID patching. This fixes the patched module load failure (Windows error 127) reported in the review. Internal socket callers keep using the existing registry implementation.

Refs #1578. No dependency on another PR. Console verification and existing Windows file-permission limits are recorded in TechnicalDebt.

Tested

Windows x64, Release, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX:

  • Eight focused tests passed: POSIX filesystem, filesystem, resolver, strings, UDP, TCP, poll and memory.
  • Full project and patched-library builds passed.
  • All 115 patched .prx libraries loaded with zero failures using the standalone loader from #1828; the loader is statically linked and starts without unpatched guest libraries loaded.
  • Registration/conventions checks and git diff --check passed. git range-diff confirms the original feature commit is unchanged after rebasing.
  • CI on 31b26d7d: Windows and Linux builds and CTest passed, with 489 registered tests / 203 skipped on Windows and 498 / 25 skipped on Linux; zero failures. Conventions passed.
  • The regression covers aliases, binary file I/O, unique names, collisions without content loss, fixed names, missing parents, invalid templates, files, pipes, sockets, closed/invalid descriptors and Windows NUL. Terminal tests run when a console or pseudo-terminal is available.
  • No homebrew/title execution or PS5 hardware verification.

Checklist

  • Based on current main (f1451396); no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No new comments in code
  • No silent stubs or fallbacks added
  • No investigation files, images or new dependencies added
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes, Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4788554056 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1613). Originally posted by [NumberGuan](https://github.com/NumberGuan) on 2026-10-08T14:46:23Z. --- ### What Implement `mkstemp` and `isatty` in `libScePosixForWebKit` for the homebrew imports reported in #1578. `mkstemp` uses the guest path resolver and existing `open` implementation, creates files exclusively with read/write access and mode 0600, and handles collisions without truncating existing files. Its trailing-X and fixed-name behavior follows [FreeBSD 9](https://github.com/freebsd/freebsd-src/blob/stable/9/lib/libc/stdio/mktemp.c). `isatty` distinguishes terminals, non-terminal files/pipes/sockets (`ENOTTY`), and invalid descriptors (`EBADF`), following [FreeBSD's terminal check](https://github.com/freebsd/freebsd-src/blob/stable/9/lib/libc/gen/isatty.c). Windows checks console handles and handles invalid CRT descriptors without aborting. The socket check calls `GuestSocketIsOpen_nid_no_patch`, a C host helper whose export survives NID patching. This fixes the patched module load failure (Windows error 127) reported in the review. Internal socket callers keep using the existing registry implementation. Refs #1578. No dependency on another PR. Console verification and existing Windows file-permission limits are recorded in TechnicalDebt. ### Tested Windows x64, Release, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX: - Eight focused tests passed: POSIX filesystem, filesystem, resolver, strings, UDP, TCP, poll and memory. - Full project and patched-library builds passed. - All 115 patched `.prx` libraries loaded with zero failures using the standalone loader from #1828; the loader is statically linked and starts without unpatched guest libraries loaded. - Registration/conventions checks and `git diff --check` passed. `git range-diff` confirms the original feature commit is unchanged after rebasing. - CI on `31b26d7d`: Windows and Linux builds and CTest passed, with 489 registered tests / 203 skipped on Windows and 498 / 25 skipped on Linux; zero failures. Conventions passed. - The regression covers aliases, binary file I/O, unique names, collisions without content loss, fixed names, missing parents, invalid templates, files, pipes, sockets, closed/invalid descriptors and Windows `NUL`. Terminal tests run when a console or pseudo-terminal is available. - No homebrew/title execution or PS5 hardware verification. ### Checklist - [x] Based on current `main` (`f1451396`); no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No new comments in code - [x] No silent stubs or fallbacks added - [x] No investigation files, images or new dependencies added - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, Codex
github-actions[bot] commented 2026-10-08 14:46:54 +00:00 (Migrated from github.com)

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


Progress report (2e375a5 → f9be276)

📈 System libraries: 85.23% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libScePosixForWebKit isatty_nid_postfix
libScePosixForWebKit mkstemp_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6062448705 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1613#issuecomment-6062448705). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T14:46:54Z. --- <!-- progress-report --> ### Progress report (2e375a5 → f9be276) 📈 **System libraries**: 85.23% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libScePosixForWebKit | `isatty_nid_postfix` | | libScePosixForWebKit | `mkstemp_nid_postfix` | </details>
github-actions[bot] commented 2026-10-08 14:51:06 +00:00 (Migrated from github.com)

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


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
#1605 docs/dev/TechnicalDebt.md L238
#1616 __error_nid_postfix
#1627 __error_nid_postfix
#1641 __error_nid_postfix
#1675 __error_nid_postfix
#1727 __error_nid_postfix
#1729 __error_nid_postfix
#1738 __error_nid_postfix
#1772 __error_nid_postfix
#1823 docs/dev/TechnicalDebt.md L238
#1824 docs/dev/TechnicalDebt.md L238
#1832 core/libs/prx/libkernel/Socket/src/Udp.cpp L182
#1841 __error_nid_postfix
#1860 __error_nid_postfix
#1873 docs/dev/TechnicalDebt.md L238
#1924 docs/dev/TechnicalDebt.md L238
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6062526347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1613#issuecomment-6062526347). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T14:51:06Z. --- <!-- 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 | |---|---|---|---| | #1605 | `docs/dev/TechnicalDebt.md` [L238](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L238) | | | | #1616 | | `__error_nid_postfix` | | | #1627 | | `__error_nid_postfix` | | | #1641 | | `__error_nid_postfix` | | | #1675 | | `__error_nid_postfix` | | | #1727 | | `__error_nid_postfix` | | | #1729 | | `__error_nid_postfix` | | | #1738 | | `__error_nid_postfix` | | | #1772 | | `__error_nid_postfix` | | | #1823 | `docs/dev/TechnicalDebt.md` [L238](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L238) | | | | #1824 | `docs/dev/TechnicalDebt.md` [L238](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L238) | | | | #1832 | `core/libs/prx/libkernel/Socket/src/Udp.cpp` [L182](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/core/libs/prx/libkernel/Socket/src/Udp.cpp#L182) | | | | #1841 | | `__error_nid_postfix` | | | #1860 | | `__error_nid_postfix` | | | #1873 | `docs/dev/TechnicalDebt.md` [L238](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L238) | | | | #1924 | `docs/dev/TechnicalDebt.md` [L238](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L238) | | |
LeandroLP23 commented 2026-10-08 20:16:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T20:16:24Z.


On Windows the patched libScePosixForWebKit.prx from this PR fails to load, so a title that imports it stops before start-up. OpenGL Showcase (PPSA99005) stops at mkstemp on main (FAIL: unresolved ELF import uEtgPWgPxOk from libScePosixForWebKit.prx); with this PR it no longer gets that far and ends with Failed to load module: ...\libs\libScePosixForWebKit.prx / GetLastError: 127 - The specified procedure could not be found.

The cause is the new call to GuestSockets::IsOpen, a C++ export of libkernel. nid_patcher keeps a host export's name only if libc exports it too, it ends in _nid_no_patch, or it starts with SDL_. Every other export is renamed to its hash (core/libs/nid/src/NidResolver.cpp:40-62). So the patched libkernel.prx no longer has _ZN12GuestSockets6IsOpenEi, while the import in libScePosixForWebKit.prx keeps that name. CI doesn't see it because ctest loads the libraries from libs/unpatched.

Tested fix: export a wrapper extern "C" bool GuestSocketIsOpen_nid_no_patch(int descriptor) from libkernel (as KernelSetSocketPoller_nid_no_patch does in Socket/include/SocketPoll.hpp) and call it from Filesystem.cpp. With that, the module loads, PPSA99005 gets past mkstemp and stops at sceVideoOutGetResolutionStatus (#1714), and the 3 POSIX tests pass.

Windows 11, Radeon 860M, MinGW-w64 GCC 15.2.0, Release, main 4b6ab6bb; title relinked with relinker --windows and run with the patched build/core/libs/libs/*.prx.

Tested with AI assistance (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6068253611 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1613#issuecomment-6068253611). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-08T20:16:24Z. --- On Windows the patched `libScePosixForWebKit.prx` from this PR fails to load, so a title that imports it stops before start-up. OpenGL Showcase (PPSA99005) stops at `mkstemp` on `main` (`FAIL: unresolved ELF import uEtgPWgPxOk from libScePosixForWebKit.prx`); with this PR it no longer gets that far and ends with `Failed to load module: ...\libs\libScePosixForWebKit.prx` / `GetLastError: 127 - The specified procedure could not be found.` The cause is the new call to `GuestSockets::IsOpen`, a C++ export of libkernel. `nid_patcher` keeps a host export's name only if libc exports it too, it ends in `_nid_no_patch`, or it starts with `SDL_`. Every other export is renamed to its hash (`core/libs/nid/src/NidResolver.cpp:40-62`). So the patched `libkernel.prx` no longer has `_ZN12GuestSockets6IsOpenEi`, while the import in `libScePosixForWebKit.prx` keeps that name. CI doesn't see it because ctest loads the libraries from `libs/unpatched`. Tested fix: export a wrapper `extern "C" bool GuestSocketIsOpen_nid_no_patch(int descriptor)` from libkernel (as `KernelSetSocketPoller_nid_no_patch` does in `Socket/include/SocketPoll.hpp`) and call it from `Filesystem.cpp`. With that, the module loads, PPSA99005 gets past `mkstemp` and stops at `sceVideoOutGetResolutionStatus` (#1714), and the 3 POSIX tests pass. Windows 11, Radeon 860M, MinGW-w64 GCC 15.2.0, Release, `main` 4b6ab6bb; title relinked with `relinker --windows` and run with the patched `build/core/libs/libs/*.prx`. Tested with AI assistance (Claude Code).
adriadam10 commented 2026-10-09 21:36:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:36:59Z.


Checked the diff, the mkstemp collision/wrap logic (fixed names, all-X suffix, no truncation of existing files), isatty errno mapping against FreeBSD, the TechnicalDebt entry and the _nid_no_patch helper (same pattern as KernelSetSocketPoller_nid_no_patch). guest_posix_filesystem passes locally on Linux; Windows and Linux CI are green on this head. Merging.

Rebased onto current main to resolve the TechnicalDebt conflict with #1823 (both lines kept, no code change).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089668556 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1613#issuecomment-6089668556). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T21:36:59Z. --- Checked the diff, the `mkstemp` collision/wrap logic (fixed names, all-`X` suffix, no truncation of existing files), `isatty` errno mapping against FreeBSD, the TechnicalDebt entry and the `_nid_no_patch` helper (same pattern as `KernelSetSocketPoller_nid_no_patch`). `guest_posix_filesystem` passes locally on Linux; Windows and Linux CI are green on this head. Merging. Rebased onto current `main` to resolve the TechnicalDebt conflict with #1823 (both lines kept, no code change).
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!1613
No description provided.