feat(libkernel): implement dup2 #1870
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1870"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T22:27:46Z.
What
dup2was not exported. ccleste (PPSA59322) calls it to move its standard error onto a pipe that it forwards to the kernel log.Two commits:
dup2. Guest file descriptors are host CRT descriptors, sodup2duplicates through the host (_dup2on Windows,dup2elsewhere).EBADF. Duplicating a descriptor onto itself returns it.sceKernelDebugOutTextkeeps the host's standard error. Because guest descriptors are host descriptors, a guest that moves descriptor 2 also moves the streamsceKernelDebugOutTextwrites to. ccleste forwards its standard error into the kernel log, so it read its own debug output back and logged it again without end. Before the guest's firstdup2onto descriptor 2, the host's standard error is duplicated and kept, andsceKernelDebugOutTextwrites there from then on.Tests (
guest_filesystem):EBADFcases are covered.sceKernelDebugOutTextoutput reaches the captured host stream, and a guestwrite(2, ...)reaches the pipe.Not covered: on Windows, the CRT's
_dup2onto descriptor 2 also changes the process'sSTD_ERROR_HANDLE, so AnyPS5's own crash reports written through that handle end up in the guest's pipe too. Restoring the Win32 handle would be a separate change.Tested
Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release.
mainwith this PR and four other small libc/libkernel PRs of mine merged together (atol, getprogname, dup2, ctime/rewind, pthread_set_name_np). It was run from the generatedCTestTestfile.cmakecommands because antivirus blocksctest.exeon this machine.tools/check_conventions.py --base origin/mainpasses on this branch alone.Not tested on Linux or macOS.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T22:32:24Z.
Progress report (
ce64d8e→bf51014)➖ System libraries: 84.76% (+0.0%, +1 implemented functions)
✅ 1 implemented
dup2_nid_postfixImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T09:04:08Z.
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.
main)core/libs/tests/GuestFilesystem.cppL29core/libs/tests/GuestFilesystem.cppL29Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:30:21Z.
Closing: ccleste (PPSA59322) stops at
shm_openon main before it callsdup2. Reopen whendup2is its next stop on main, with the log line.Imported from boykopovar/AnyPS5. Originally posted by Recapi on 2026-10-09T13:50:59Z.
@TheAggie
dup2is now a title's next stop onmain: Prospero Win (PPSA99995, catalog record 0.1.1, sha256 checked) stops at it onmaind70b8998, with nothing else merged:Linux (Ubuntu, GCC 15.2.0),
eboot.binunwrapped from its SELF container, relinked withrelinker --registry, run in abwrapsandbox.tools/import_audit.pylists 9 absent imports for it; besidesdup2they aredup,seteuid,sigemptyset,getdents,sigaction,geteuid,sceKernelGetModuleInfoandsceSysmoduleGetModuleHandleInternal, so it should stop at the others afterwards.That meets the reopen condition in the comment above, if you want to pick it back up. No open PR implements
dup2(checked against the 555 open PRs).Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T16:01:27Z.
Windows confirmation of the above, in case it helps reopening: Windows 11 Pro 25H2 (10.0.26200.9457), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, Prospero Win PPSA99995 (catalog record 0.1.1, sha256 checked),
eboot.binunwrapped from its SELF and relinked with--windows.maind70b8998, nothing else merged:FAIL: unresolved ELF import wdUufa9g-D8 from libkernel.prx(dup2), the first stop.main+ this branch (bf510143, both commits cherry-pick cleanly): the title gets pastdup2and stops at the next absent import,+F7C-hdk7+E(sigemptyset, #1641).guest_filesystempasses, and the full ctest is 510/510.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-10T04:49:14Z.
Thanks @Recapi and @rmz-24 for the Prospero Win runs. Since this was closed, #2478 by @itsbo5 implements both
dupanddup2(with guest sockets) and has a Windows check from @babyhuey, so it covers more than this PR. I'll leave this one closed in favour of #2478.AI-assisted (Claude Code).
Pull request closed