Skip to content

feat(posix): implement mkstemp and isatty - #1613

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
NumberGuan:codex/posix-temp-files
Oct 9, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
NumberGuan:codex/posix-temp-files

Conversation

@NumberGuan

@NumberGuan NumberGuan commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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 test(libs): load every patched library with its imports bound #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

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

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

@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
#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

@LeandroLP23

Copy link
Copy Markdown
Contributor

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 4b6ab6b; title relinked with relinker --windows and run with the patched build/core/libs/libs/*.prx.

Tested with AI assistance (Claude Code).

@adriadam10
adriadam10 force-pushed the codex/posix-temp-files branch from 31b26d7 to f9be276 Compare October 9, 2026 21:19
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 9, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

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).

@adriadam10
adriadam10 merged commit e603f3f into boykopovar:main Oct 9, 2026
8 checks passed
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