feat(libScePosixForWebKit): implement mkostemp #14431

Merged
AlexWhitehouse merged 2 commits from upstream-pr/14431 into main 2026-11-07 16:26:50 +00:00
AlexWhitehouse commented 2026-11-01 12:56:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-01T12:56:41Z.


What

Implements mkostemp (NID QP8dYkB8zCU) in libScePosixForWebKit, following FreeBSD 11.4 mktemp.c. Upstream WebKit's PlayStation port compiles FileSystemPOSIX.cpp, whose openTemporaryFile calls mkostemp(..., O_CLOEXEC).

  • Flag bits outside O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC | O_CLOEXEC return EINVAL before the template is read. A null template then throws, where upstream dereferences it.
  • O_APPEND, O_SYNC and O_CLOEXEC pass through guest open. O_CLOEXEC also clears native inheritance after creation, with fcntl(F_SETFD) on POSIX and SetHandleInformation on Windows, so libkernel's Open.cpp is not touched.
  • O_SHLOCK and O_EXLOCK take a guest flock after creation, and exclusive wins, as in FreeBSD's open-time locking. A lock failure closes the descriptor, keeps the error and leaves the created file, as FreeBSD does.
  • O_DIRECT throws through NotImplemented_nid_no_patch: FreeBSD's cache-bypass semantics have no proven host equivalent. This is recorded in the debt file, and it is why the title doesn't claim full flag support.
  • mkstemp and mkostemp now share one temporary-file loop in the new TemporaryFile.cpp, which starts with mktemp.c's notice (lines 1-29, byte for byte). mkstemp's loop moved out of Filesystem.cpp, and like FreeBSD's _gettemp it now also stats the template's parent directory before the first open, failing with that error or ENOTDIR.

Tested

  • Ubuntu 26.04 x86-64, GCC 15.2, full build.
  • tests/GuestPosixFilesystem.cpp (ctest guest_posix_filesystem) now covers mkostemp:
    • each accepted flag and combinations of them;
    • mode 0600;
    • F_GETFD showing FD_CLOEXEC only when requested, both in the guest and natively;
    • append position after a seek;
    • shared and exclusive locks checked through a second descriptor;
    • invalid flags returning EINVAL with the template untouched, including with a null template;
    • collision cycling, fixed names, a missing directory, an empty template and too long a template.
  • On main the test fails with mkostemp_nid_postfix not implemented.
  • Mutation checks:
    • swapping the shared and exclusive selection fails at line 82;
    • dropping guest close-on-exec fails at line 53;
    • dropping native close-on-exec fails at line 61;
    • the restored code passes.
  • ctest --test-dir build-full -R posix: 25/25 passed. The wider posix|public_headers run: 90/90 passed.
  • On head 6746951f0f, after the O_DIRECT test checks were dropped at review: guest_posix_filesystem, public_headers and public_headers_compile_0 to _63 passed, 66/66.
  • python3 tools/check_conventions.py --base origin/main: all conventions checks passed.
  • python3 tools/pr_overlap.py --branch feat/libsceposixforwebkit-mkostemp: no PR shares these exports. #14157 (gethostbyname_r) edits the neighbouring line of docs/dev/debt/libScePosixForWebKit.md, and the tool could not compare #14212, a debt-text cleanup that conflicts with main. Both are text conflicts only; whichever merges second rebases.
  • Windows 11 Pro 26H2 (build 26300.9711), WinLibs GCC 15.2.0 (DWARF exceptions), CMake 4.3.1, Ninja 1.13.2, Release build of libs and guest_posix_filesystem_tests at 6746951f0f: ctest -R posix 24/24 passed (guest_posix_spawn_flags is Linux-only). Changing SetHandleInformation's third argument in TemporaryFile.cpp from 0 to HANDLE_FLAG_INHERIT makes guest_posix_filesystem fail at line 59; the restored code passes.
  • Not run on macOS or a console.

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: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5107544548 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14431). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-01T12:56:41Z. --- ### What Implements `mkostemp` (NID `QP8dYkB8zCU`) in libScePosixForWebKit, following FreeBSD 11.4 [`mktemp.c`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libc/stdio/mktemp.c). Upstream WebKit's PlayStation port compiles [`FileSystemPOSIX.cpp`](https://github.com/WebKit/WebKit/blob/main/Source/WTF/wtf/posix/FileSystemPOSIX.cpp#L177-L191), whose `openTemporaryFile` calls `mkostemp(..., O_CLOEXEC)`. - Flag bits outside `O_APPEND | O_DIRECT | O_SHLOCK | O_EXLOCK | O_SYNC | O_CLOEXEC` return `EINVAL` before the template is read. A null template then throws, where upstream dereferences it. - `O_APPEND`, `O_SYNC` and `O_CLOEXEC` pass through guest open. `O_CLOEXEC` also clears native inheritance after creation, with `fcntl(F_SETFD)` on POSIX and `SetHandleInformation` on Windows, so libkernel's `Open.cpp` is not touched. - `O_SHLOCK` and `O_EXLOCK` take a guest `flock` after creation, and exclusive wins, as in FreeBSD's [open-time locking](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/vfs_vnops.c). A lock failure closes the descriptor, keeps the error and leaves the created file, as FreeBSD does. - `O_DIRECT` throws through `NotImplemented_nid_no_patch`: FreeBSD's cache-bypass semantics have no proven host equivalent. This is recorded in the debt file, and it is why the title doesn't claim full flag support. - `mkstemp` and `mkostemp` now share one temporary-file loop in the new `TemporaryFile.cpp`, which starts with `mktemp.c`'s notice (lines 1-29, byte for byte). `mkstemp`'s loop moved out of `Filesystem.cpp`, and like FreeBSD's `_gettemp` it now also stats the template's parent directory before the first open, failing with that error or ENOTDIR. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Ubuntu 26.04 x86-64, GCC 15.2, full build. - `tests/GuestPosixFilesystem.cpp` (ctest `guest_posix_filesystem`) now covers `mkostemp`: - each accepted flag and combinations of them; - mode 0600; - `F_GETFD` showing `FD_CLOEXEC` only when requested, both in the guest and natively; - append position after a seek; - shared and exclusive locks checked through a second descriptor; - invalid flags returning `EINVAL` with the template untouched, including with a null template; - collision cycling, fixed names, a missing directory, an empty template and too long a template. - On `main` the test fails with `mkostemp_nid_postfix not implemented`. - Mutation checks: - swapping the shared and exclusive selection fails at line 82; - dropping guest close-on-exec fails at line 53; - dropping native close-on-exec fails at line 61; - the restored code passes. - `ctest --test-dir build-full -R posix`: 25/25 passed. The wider `posix|public_headers` run: 90/90 passed. - On head 6746951f0f, after the `O_DIRECT` test checks were dropped at review: `guest_posix_filesystem`, `public_headers` and `public_headers_compile_0` to `_63` passed, 66/66. - `python3 tools/check_conventions.py --base origin/main`: all conventions checks passed. - `python3 tools/pr_overlap.py --branch feat/libsceposixforwebkit-mkostemp`: no PR shares these exports. #14157 (`gethostbyname_r`) edits the neighbouring line of `docs/dev/debt/libScePosixForWebKit.md`, and the tool could not compare #14212, a debt-text cleanup that conflicts with `main`. Both are text conflicts only; whichever merges second rebases. - Windows 11 Pro 26H2 (build 26300.9711), WinLibs GCC 15.2.0 (DWARF exceptions), CMake 4.3.1, Ninja 1.13.2, Release build of `libs` and `guest_posix_filesystem_tests` at 6746951f0f: `ctest -R posix` 24/24 passed (`guest_posix_spawn_flags` is Linux-only). Changing `SetHandleInformation`'s third argument in `TemporaryFile.cpp` from `0` to `HANDLE_FLAG_INHERIT` makes `guest_posix_filesystem` fail at line 59; the restored code passes. - Not run on macOS or a console. ### 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: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-01 13:51:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T13:51:39Z.

Review: COMMENTED


Reviewed — no blocking findings

mkostemp is implemented with the flag bits it accepts, the errors it returns for unsupported ones, and the close-on-exec and lock handling I traced through the code, and the helpers it calls exist at head; the one open point is whether BSD-derived code with its licence header is acceptable here, which is a maintainer call.

What I ran

  • Exact head 6746951f0fc666a60a1301df2339820b943c3513, base ab6f5d32ed5bc9a2e5393bb1ab9b4459b5857bfb (the PR base, which is the current main).
  • Environment: Linux, /usr/bin/python3 3.11.2, no build.
  • Precheck: python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14431 --output-dir /dev/shm/reviewer-run/precheck/14431
  • Helper names used by the new code checked with git grep at head: flock_nid_postfix, stat_nid_postfix and FileStat (libkernel include/Api.hpp), open_nid_postfix and close_nid_postfix (libc include/Api.hpp).
  • Test-quality helper on core/libs/tests/GuestPosixFilesystem.cpp from a head extract: one registration heuristic; the test is already a registered target.
  • Source read at head: TemporaryFile.cpp in full, the removals in Filesystem.cpp and Export.cpp, and the test diff.
  • Repository rules read: CONTRIBUTING.md line 17 (third-party code as a submodule) and docs/dev/CONVENTIONS.md; the conventions check passed at head.

Results

Precheck report, checks table, unedited (/dev/shm/reviewer-run/precheck/14431/report.md):

Check Status Command / reason
build_and_compile not_applicable The precheck deliberately does not configure, build, or compile AnyPS5.
diff_check passed git diff --check ab6f5d32ed5bc9a2e5393bb1ab9b4459b5857bfb...6746951f0fc666a60a1301df2339820b943c3513
conventions_and_pr_template passed /usr/bin/python3 tools/check_conventions.py --base ab6f5d32ed5bc9a2e5393bb1ab9b4459b5857bfb --head 6746951f0fc666a60a1301df2339820b943c3513 --title feat(libScePosixForWebKit): implement mkostemp --body /dev/shm/reviewer-run/precheck/14431/pr-body.md
changed_export_abi_audit failed /usr/bin/python3 tools/pr_abi_audit.py --base ab6f5d32ed5bc9a2e5393bb1ab9b4459b5857bfb --head 6746951f0fc666a60a1301df2339820b943c3513 --json
python_syntax not_applicable No changed Python implementation files.
related_python_unit_tests not_applicable No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.
python_test_registration not_applicable No changed test_*.py files.
live_dependency_and_mergeability_check passed /usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 14431 --repo boykopovar/AnyPS5 --output-dir /dev/shm/reviewer-run/precheck/14431/stack
build_dependent_cpp_tests not_applicable Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.
test_quality_heuristics failed /usr/bin/python3 /dev/shm/reviewer-run/precheck/14431/head-6746951f0fc6-896fc439/tools/pr_test_quality.py --root /dev/shm/reviewer-run/precheck/14431/head-6746951f0fc6-896fc439 --json core/libs/prx/libScePosixForWebKit/CMakeLists.txt core/libs/prx/libScePosixForWebKit/Export.cpp core/libs/prx/libScePosixForWebKit/Filesystem.cpp core/libs/prx/libScePosixForWebKit/TemporaryFile.cpp core/libs/prx/libScePosixForWebKit/include/Api.hpp core/libs/tests/GuestPosixFilesystem.cpp docs/dev/debt/libScePosixForWebKit.md
negative_controls not_applicable No changed Python test module in tools/ can be run as a no-build base-source control.

Negative control

Not run. The PR's test runs many flag combinations; the precheck does not run C++ tests.

Findings

Blocking: none.

Non-blocking:

  • TemporaryFile.cpp begins with the FreeBSD 11.4 licence block (the BSD-3-Clause copyright notice from mktemp.c). The conventions check passes, and the repository already has the same block in libc sources (core/libs/prx/libc/src/FileAndHeap.cpp and core/libs/prx/libc/src/Math.cpp), so this is not a new rule violation. CONTRIBUTING.md says third-party code is a submodule, and the code here is derived from FreeBSD, so the maintainers should decide whether copied BSD code belongs in the tree this way.
  • CloseOnExec (0x100000) reaches the guest open as a flag. That matches FreeBSD's O_CLOEXEC value, and the PR says so; it is the intended behaviour.
  • The test checks errno 35 for a lock conflict. That is FreeBSD's EWOULDBLOCK; the guest mapping is what the test relies on, and I did not check it against the libkernel error table.

Sources

Not verified

  • No build, so TemporaryFile.cpp and the guest test were not compiled or run here.
  • The Windows branch (SetHandleInformation, _get_osfhandle) was not compiled.
  • The guest errno mapping for lock conflicts (35) was not checked against the libkernel error table.
  • Hosted: conventions was cancelled twice and re-queued, and eligibility, library-portability and report were queued at review time.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5728376377 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14431#pullrequestreview-5728376377). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T13:51:39Z. **Review:** COMMENTED --- # Reviewed — no blocking findings `mkostemp` is implemented with the flag bits it accepts, the errors it returns for unsupported ones, and the close-on-exec and lock handling I traced through the code, and the helpers it calls exist at head; the one open point is whether BSD-derived code with its licence header is acceptable here, which is a maintainer call. ## What I ran - Exact head `6746951f0fc666a60a1301df2339820b943c3513`, base `ab6f5d32ed5bc9a2e5393bb1ab9b4459b5857bfb` (the PR base, which is the current `main`). - Environment: Linux, `/usr/bin/python3` 3.11.2, no build. - Precheck: `python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14431 --output-dir /dev/shm/reviewer-run/precheck/14431` - Helper names used by the new code checked with `git grep` at head: `flock_nid_postfix`, `stat_nid_postfix` and `FileStat` (libkernel `include/Api.hpp`), `open_nid_postfix` and `close_nid_postfix` (libc `include/Api.hpp`). - Test-quality helper on `core/libs/tests/GuestPosixFilesystem.cpp` from a head extract: one registration heuristic; the test is already a registered target. - Source read at head: `TemporaryFile.cpp` in full, the removals in `Filesystem.cpp` and `Export.cpp`, and the test diff. - Repository rules read: `CONTRIBUTING.md` line 17 (third-party code as a submodule) and `docs/dev/CONVENTIONS.md`; the conventions check passed at head. ## Results Precheck report, checks table, unedited (`/dev/shm/reviewer-run/precheck/14431/report.md`): | Check | Status | Command / reason | |---|---|---| | build_and_compile | not_applicable | `The precheck deliberately does not configure, build, or compile AnyPS5.` | | diff_check | passed | `git diff --check ab6f5d32ed5bc9a2e5393bb1ab9b4459b5857bfb...6746951f0fc666a60a1301df2339820b943c3513` | | conventions_and_pr_template | passed | `/usr/bin/python3 tools/check_conventions.py --base ab6f5d32ed5bc9a2e5393bb1ab9b4459b5857bfb --head 6746951f0fc666a60a1301df2339820b943c3513 --title feat(libScePosixForWebKit): implement mkostemp --body /dev/shm/reviewer-run/precheck/14431/pr-body.md` | | changed_export_abi_audit | failed | `/usr/bin/python3 tools/pr_abi_audit.py --base ab6f5d32ed5bc9a2e5393bb1ab9b4459b5857bfb --head 6746951f0fc666a60a1301df2339820b943c3513 --json` | | python_syntax | not_applicable | `No changed Python implementation files.` | | related_python_unit_tests | not_applicable | `No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.` | | python_test_registration | not_applicable | `No changed test_*.py files.` | | live_dependency_and_mergeability_check | passed | `/usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 14431 --repo boykopovar/AnyPS5 --output-dir /dev/shm/reviewer-run/precheck/14431/stack` | | build_dependent_cpp_tests | not_applicable | `Not run: C++ tests need exact-head binaries, which require a build; the precheck does not build.` | | test_quality_heuristics | failed | `/usr/bin/python3 /dev/shm/reviewer-run/precheck/14431/head-6746951f0fc6-896fc439/tools/pr_test_quality.py --root /dev/shm/reviewer-run/precheck/14431/head-6746951f0fc6-896fc439 --json core/libs/prx/libScePosixForWebKit/CMakeLists.txt core/libs/prx/libScePosixForWebKit/Export.cpp core/libs/prx/libScePosixForWebKit/Filesystem.cpp core/libs/prx/libScePosixForWebKit/TemporaryFile.cpp core/libs/prx/libScePosixForWebKit/include/Api.hpp core/libs/tests/GuestPosixFilesystem.cpp docs/dev/debt/libScePosixForWebKit.md` | | negative_controls | not_applicable | `No changed Python test module in tools/ can be run as a no-build base-source control.` | ## Negative control Not run. The PR's test runs many flag combinations; the precheck does not run C++ tests. ## Findings **Blocking:** none. **Non-blocking:** - `TemporaryFile.cpp` begins with the FreeBSD 11.4 licence block (the BSD-3-Clause copyright notice from `mktemp.c`). The conventions check passes, and the repository already has the same block in libc sources (`core/libs/prx/libc/src/FileAndHeap.cpp` and `core/libs/prx/libc/src/Math.cpp`), so this is not a new rule violation. `CONTRIBUTING.md` says third-party code is a submodule, and the code here is derived from FreeBSD, so the maintainers should decide whether copied BSD code belongs in the tree this way. - `CloseOnExec` (0x100000) reaches the guest `open` as a flag. That matches FreeBSD's `O_CLOEXEC` value, and the PR says so; it is the intended behaviour. - The test checks errno 35 for a lock conflict. That is FreeBSD's `EWOULDBLOCK`; the guest mapping is what the test relies on, and I did not check it against the libkernel error table. ## Sources - `mkostemp` and the flag handling at head: https://github.com/boykopovar/AnyPS5/blob/6746951f0fc666a60a1301df2339820b943c3513/core/libs/prx/libScePosixForWebKit/TemporaryFile.cpp - Repository precedent for the licence block at head: https://github.com/boykopovar/AnyPS5/blob/6746951f0fc666a60a1301df2339820b943c3513/core/libs/prx/libc/src/FileAndHeap.cpp ## Not verified - No build, so `TemporaryFile.cpp` and the guest test were not compiled or run here. - The Windows branch (`SetHandleInformation`, `_get_osfhandle`) was not compiled. - The guest errno mapping for lock conflicts (35) was not checked against the libkernel error table. - Hosted: `conventions` was cancelled twice and re-queued, and `eligibility`, `library-portability` and `report` were queued at review time.
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!14431
No description provided.