libkernel: truncate is an absent import of PS5MC, XPSemu and Porpoise; fix branch ready #3181

Closed
opened 2026-10-11 00:30:45 +00:00 by Mouad-Scriptz-0 · 5 comments
Mouad-Scriptz-0 commented 2026-10-11 00:30:45 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-11T00:30:45Z.


libkernel does not export the POSIX truncate (ayrtszI7GBg, named with tools/nid_names.py against aerolib). sceKernelTruncate (WlyEA-sLDf0) is on main, the POSIX alias is not. An import audit of the homebrew catalog on main 942a174e (Linux) lists it as an absent import of three titles, each a real GOT relocation with resolved call sites:

Title Catalog release truncate call sites Absent imports on main
PPSA99420 PS5MC 1.2 PS5MC-1.2-kodi22-PPSA99420.zip 1 (0x3C972CB) 55
PPSA97358 XPSemu Alpha-2.1 PPSA97358.zip 2 (0xB6E945, 0xB6E955) 59
PPSA99764 Porpoise 2.7 Porpoise-2.7.zip 2 (0x807B5, 0x807C5) 25

With the branch below, each title's absent count drops by exactly one and truncate moves to implemented; nothing else changes. It is also the next stop that @Amoenus reports for PPSA99902 once pathconf resolves. Prospero Win (PPSA99995) references the NID from its bundled ntdll.prx and wineserver.prx; OliSe Player, ProsperoAI, ProsperoEden and PS5SX2 reference it too but the relinker refuses them (#2136), so they are not counted above.

Fix branch ready: Mouad-Scriptz-0:feat/libkernel-truncate (91bc3930, one commit on main 942a174e). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. No open PR adds truncate (tools/pr_overlap.py --branch reports no overlap).

  • truncate_nid_postfix(path, length) in File/src/Stdio.cpp validates the path like the other POSIX wrappers there (EFAULT for null, ENOENT for empty) and resolves through sceKernelTruncate_nid_postfix.
  • sceKernelTruncate now returns EISDIR for a directory and the host errno for other failures, as FreeBSD 11 kern_truncate (sys/kern/vfs_syscalls.c) does: EINVAL for a negative length, EISDIR for VDIR, then the vnode error (EACCES for an unwritable file). Before, every failure after the existence check was EIO. The ENOENT check for a missing path is unchanged.
  • New NativeTruncate helpers: ::truncate on POSIX; _wopen(_O_WRONLY | _O_BINARY) + _chsize_s + _close on Windows, where _chsize_s already backs ftruncate.
  • New guest_truncate test (registered in libkernel/CMakeLists.txt): shrink to 6 keeps 012345, grow to 9 zero-fills, truncate to 0, -1 → EINVAL without touching the file, missing path → ENOENT, "" → ENOENT, nullptr → EFAULT, a directory → EISDIR for both truncate and sceKernelTruncate (0x80020015), a read-only file → EACCES for both and the contents stay intact.

Tested on Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release, full build with BUILD_TESTING=ON):

  • guest_truncate and guest_filesystem pass 3/3 (--repeat until-fail:3).
  • Full ctest -j6 --timeout 120: 744/752. The 8 that fail are agc_driver_* (f64_fma_subnormals, vop1_float_unary, vopc_compare, prepared_shaders, prepared_shaders_indirect, prepared_shaders_uncached, prepared_shaders_debug, and flat_apertures by timeout under -j6): on a clean main 942a174e build with the same Intel Arc (Meteor Lake) iGPU the seven fail the same way and flat_apertures passes alone in 25 s, so they are unrelated to this branch.
  • tools/check_conventions.py --base origin/main, tools/check_test_registration.py build and git diff --check pass.
  • Method for the table: release ZIPs checked against the catalog sha256, eboot.bin and sce_module/libc.prx unwrapped from their SELF containers, relinker --registry, then tools/import_audit.py against .prx files built from main and from the branch. The titles were not run. Not tested on Windows.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5796609405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3181). Originally posted by [Mouad-Scriptz-0](https://github.com/Mouad-Scriptz-0) on 2026-10-11T00:30:45Z. --- libkernel does not export the POSIX `truncate` (`ayrtszI7GBg`, named with `tools/nid_names.py` against aerolib). `sceKernelTruncate` (`WlyEA-sLDf0`) is on `main`, the POSIX alias is not. An import audit of the homebrew catalog on `main` 942a174e (Linux) lists it as an absent import of three titles, each a real GOT relocation with resolved call sites: | Title | Catalog release | `truncate` call sites | Absent imports on `main` | |---|---|---|---| | PPSA99420 PS5MC 1.2 | `PS5MC-1.2-kodi22-PPSA99420.zip` | 1 (`0x3C972CB`) | 55 | | PPSA97358 XPSemu Alpha-2.1 | `PPSA97358.zip` | 2 (`0xB6E945`, `0xB6E955`) | 59 | | PPSA99764 Porpoise 2.7 | `Porpoise-2.7.zip` | 2 (`0x807B5`, `0x807C5`) | 25 | With the branch below, each title's absent count drops by exactly one and `truncate` moves to `implemented`; nothing else changes. It is also the next stop that @Amoenus [reports for PPSA99902](https://github.com/boykopovar/AnyPS5/issues/1578#issuecomment-6103542716) once `pathconf` resolves. Prospero Win (PPSA99995) references the NID from its bundled `ntdll.prx` and `wineserver.prx`; OliSe Player, ProsperoAI, ProsperoEden and PS5SX2 reference it too but the relinker refuses them (#2136), so they are not counted above. **Fix branch ready:** [`Mouad-Scriptz-0:feat/libkernel-truncate`](https://github.com/Mouad-Scriptz-0/AnyPS5/tree/feat/libkernel-truncate) (`91bc3930`, one commit on `main` 942a174e). I cannot open it as a PR because of the intake check; anyone eligible is welcome to carry it, keeping the commit as is. No open PR adds `truncate` (`tools/pr_overlap.py --branch` reports no overlap). - `truncate_nid_postfix(path, length)` in `File/src/Stdio.cpp` validates the path like the other POSIX wrappers there (`EFAULT` for null, `ENOENT` for empty) and resolves through `sceKernelTruncate_nid_postfix`. - `sceKernelTruncate` now returns `EISDIR` for a directory and the host errno for other failures, as FreeBSD 11 `kern_truncate` (`sys/kern/vfs_syscalls.c`) does: `EINVAL` for a negative length, `EISDIR` for `VDIR`, then the vnode error (`EACCES` for an unwritable file). Before, every failure after the existence check was `EIO`. The `ENOENT` check for a missing path is unchanged. - New `NativeTruncate` helpers: `::truncate` on POSIX; `_wopen(_O_WRONLY | _O_BINARY)` + `_chsize_s` + `_close` on Windows, where `_chsize_s` already backs `ftruncate`. - New `guest_truncate` test (registered in `libkernel/CMakeLists.txt`): shrink to 6 keeps `012345`, grow to 9 zero-fills, truncate to 0, `-1` → `EINVAL` without touching the file, missing path → `ENOENT`, `""` → `ENOENT`, `nullptr` → `EFAULT`, a directory → `EISDIR` for both `truncate` and `sceKernelTruncate` (`0x80020015`), a read-only file → `EACCES` for both and the contents stay intact. **Tested** on Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release, full build with `BUILD_TESTING=ON`): - `guest_truncate` and `guest_filesystem` pass 3/3 (`--repeat until-fail:3`). - Full `ctest -j6 --timeout 120`: 744/752. The 8 that fail are `agc_driver_*` (`f64_fma_subnormals`, `vop1_float_unary`, `vopc_compare`, `prepared_shaders`, `prepared_shaders_indirect`, `prepared_shaders_uncached`, `prepared_shaders_debug`, and `flat_apertures` by timeout under `-j6`): on a clean `main` 942a174e build with the same Intel Arc (Meteor Lake) iGPU the seven fail the same way and `flat_apertures` passes alone in 25 s, so they are unrelated to this branch. - `tools/check_conventions.py --base origin/main`, `tools/check_test_registration.py build` and `git diff --check` pass. - Method for the table: release ZIPs checked against the catalog sha256, `eboot.bin` and `sce_module/libc.prx` unwrapped from their SELF containers, `relinker --registry`, then `tools/import_audit.py` against `.prx` files built from `main` and from the branch. The titles were not run. Not tested on Windows. AI-assisted: yes (Claude Code).
Silverash-i8 commented 2026-10-11 01:18:42 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:18:42Z.


Windows run, since the issue says it wasn't tested there: Windows 11, WinLibs GCC 15.2.0 r7, Release, feat/libkernel-truncate (91bc3930) merged onto main 06da1176 together with #3116, #3117 and #3169.

  • guest_truncate passes, including the Windows-only part: the read-only file (SetFileAttributesW(FILE_ATTRIBUTE_READONLY)) gives EACCES and the locked file keeps its contents. So the _wopen + _chsize_s path works here.
  • All 421 non-GPU tests (ctest -E "^agc_") pass with the four branches merged.

AI-assisted (Claude Code); I ran this on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104126728 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3181#issuecomment-6104126728). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T01:18:42Z. --- Windows run, since the issue says it wasn't tested there: Windows 11, WinLibs GCC 15.2.0 r7, Release, `feat/libkernel-truncate` (`91bc3930`) merged onto `main` 06da1176 together with #3116, #3117 and #3169. - `guest_truncate` passes, including the Windows-only part: the read-only file (`SetFileAttributesW(FILE_ATTRIBUTE_READONLY)`) gives EACCES and the locked file keeps its contents. So the `_wopen` + `_chsize_s` path works here. - All 421 non-GPU tests (`ctest -E "^agc_"`) pass with the four branches merged. AI-assisted (Claude Code); I ran this on my machine.
danzaio commented 2026-10-11 01:30:05 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by danzaio on 2026-10-11T01:30:05Z.


Windows validation for this branch, which was Fedora-only so far.

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, BUILD_TESTING=ON, branch 91bc3930: guest_truncate passes 1/1. I did not run guest_filesystem here (this machine lacks Developer Mode, so its symlink setup aborts before any assertion).

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104207834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3181#issuecomment-6104207834). Originally posted by [danzaio](https://github.com/danzaio) on 2026-10-11T01:30:05Z. --- Windows validation for this branch, which was Fedora-only so far. Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, BUILD_TESTING=ON, branch 91bc3930: guest_truncate passes 1/1. I did not run guest_filesystem here (this machine lacks Developer Mode, so its symlink setup aborts before any assertion). AI-assisted: yes.
blawesom commented 2026-10-11 10:27:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T10:27:49Z.


Independent verification on Linux — a second distribution and GPU to complement the report's Fedora 44 / Intel Arc run: CachyOS, kernel 7.2.9, AMD RX 9070 XT (RADV), GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON.

  • Rebased 91bc3930 onto current main (the branch sat on 942a174e, several hundred commits behind): applies cleanly, no conflicts.
  • tools/check_conventions.py and git diff --check pass.
  • guest_truncate and guest_filesystem pass.
  • Full suite (ctest -j8 -E "^agc_driver_|^video_out_flip"): 521/521 passed.

The rebased branch is available at blawesom:verify/3181 for anyone carrying — the commit is otherwise unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108072539 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3181#issuecomment-6108072539). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-11T10:27:49Z. --- Independent verification on **Linux** — a second distribution and GPU to complement the report's Fedora 44 / Intel Arc run: CachyOS, kernel 7.2.9, AMD RX 9070 XT (RADV), GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`. - Rebased `91bc3930` onto current `main` (the branch sat on `942a174e`, several hundred commits behind): applies cleanly, no conflicts. - `tools/check_conventions.py` and `git diff --check` pass. - `guest_truncate` and `guest_filesystem` pass. - Full suite (`ctest -j8 -E "^agc_driver_|^video_out_flip"`): **521/521 passed**. The rebased branch is available at [`blawesom:verify/3181`](https://github.com/blawesom/AnyPS5/tree/verify/3181) for anyone carrying — the commit is otherwise unchanged.
MarcZX10 commented 2026-10-16 04:25:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T04:25:02Z.


The author of the ready truncate branch is Mouad-Scriptz-0, and the commit preserves their authored change. Do you want me to carry the verified commit into an upstream PR, or would you rather open it yourself? I will wait for your preference.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208049180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3181#issuecomment-6208049180). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T04:25:02Z. --- The author of the ready `truncate` branch is Mouad-Scriptz-0, and the commit preserves their authored change. Do you want me to carry the verified commit into an upstream PR, or would you rather open it yourself? I will wait for your preference.
MarcZX10 commented 2026-10-16 04:28:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T04:28:46Z.


I independently carried the published blawesom:verify/3181 commit onto current main 5d9dcc42d in a temporary worktree, preserving the original author (the commit already includes blawesom as committer/coauthor context). Linux GCC 12.2 Release: guest_truncate_tests builds; guest_truncate passes when run as an unprivileged user from a writable temporary directory. The first root run aborted at the read-only-file assertion because root can truncate through POSIX mode bits; that is an environment limitation, not a failure under the intended permission model. check_conventions.py --base upstream/main and git diff --check pass. This focused configure reports 638 registered executables, 0 built, so I did not run the full suite. I checked the original commit and current-main diff; the implementation remains confined to Stdio.cpp, its test registration, and the new guest test. Are you happy for me to open this commit as a PR now, or do you plan to do so yourself?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6208091855 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3181#issuecomment-6208091855). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T04:28:46Z. --- I independently carried the published `blawesom:verify/3181` commit onto current main `5d9dcc42d` in a temporary worktree, preserving the original author (the commit already includes blawesom as committer/coauthor context). Linux GCC 12.2 Release: `guest_truncate_tests` builds; `guest_truncate` passes when run as an unprivileged user from a writable temporary directory. The first root run aborted at the read-only-file assertion because root can truncate through POSIX mode bits; that is an environment limitation, not a failure under the intended permission model. `check_conventions.py --base upstream/main` and `git diff --check` pass. This focused configure reports 638 registered executables, 0 built, so I did not run the full suite. I checked the original commit and current-main diff; the implementation remains confined to Stdio.cpp, its test registration, and the new guest test. Are you happy for me to open this commit as a PR now, or do you plan to do so yourself?
Sign in to join this conversation.
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#3181
No description provided.