Repository navigation
fix(libc): fail stream calls on a stream that a failed freopen closed - #5632
Conversation
d862be2 to
292752f
Compare
|
#5605 is merged, so PS5LM Plus (PPSA99581) now stops at this PR's fix on
These are the same stops described above for |
|
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.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
The Linux part with a display, since the run above stopped at the headless
|
|
Checked on the PR merged onto main: Conventions was red on the |
What
A
freopenthat fails closes the stream, on FreeBSD as on the host. Later calls on that stream fail withEBADFon FreeBSD: a write returnsEOFandfflushreturnsEOF. In AnyPS5 every libc call on such aFileStreamreachedGetHandle()and threwFileStream: closed stream. On Windows,printf'sPrintWindowswrote to the closed hoststdoutand threwFormatted output write failed.FileStream::IsOpen()reports whether the host handle is still there.errnoto 9 (EBADF) and return their failure value instead of throwing:fputs,fputc,putc_unlocked,fwrite(0),vfprintf/fprintf, and thestdoutwritersprintf,libc_printf,vprintfandputs;fread(0),fgetc,getc_unlocked,ungetc,fgets(null),fscanf;fseeko,ftello,fflush,fileno,setvbuf,fclose.SyncStatus,SyncUnlockedStatusandClearErrordo nothing on a closed stream, sofeof,ferrorandclearerrno longer throw.Close()has already cleared its flags.fcloseon a closed dynamic stream still frees it.flockfile,funlockfile,ftrylockfile) still throw on a closed stream, asCheckTryLockexpects.FileStreams.cppexpectedfflushon a closed stream to throw. It now expects-1witherrno9, as FreeBSD'sfflushreturns for a stream that is neither reading nor writing.The wide writers (
fputwc,fputws) already catch the throw and return -1.Tested
On the PR head 292752f (rebased onto
main58d98de after #4904 and #4728; the test file merge keeps both sides), Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release:guest_standard_streams,guest_standard_streams_closed_stdout(new: it reopens the gueststdoutto a missing directory and checksprintf,vprintf,putsandfputs) andfile_streamseach pass 5/5 (--repeat until-fail:5) on both. The new closed-stream checks fail onmain. The Windows run of--closed-stdoutshows no UCRT invalid-parameter report.PS5LM Plus (PPSA99581, catalog release 0.8.3), with #5605 merged (its stop on
mainis the absentsceKernelGetSocPowerConsumption). At start-up it callsfreopen("/data/PS5LM/app.log", "w", stdout)andfreopen(..., "a", stderr)./data/PS5LMdoesn't exist, so both fail and it goes on printing.fputsthrowsFileStream: closed stream; on WindowsprintfthrowsFormatted output write failed, thenfprintfandfflushthrow too as each is reached.no models; copy a .gguf to /data/PS5LM/models. On Linux it gets to the headlessDisplayWindowthrow.A separate problem remains, not changed here: on Windows the failed
freopenalso closes the host process's nativestdout. The libraries' own logging then trips the UCRT invalid-parameter handler on every line (about 740 reports in 60 s for PS5LM Plus), which slows it to about one frame. That needs the standard streams handled so a failed guestfreopendoesn't close the host's, and is left for a follow-up.The
fflushchange touches the same function as #4904 (which returns flush failures instead of throwing), in a different place.check_conventions.pypasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)main63fb0cd: it now stops atFileStream: closed stream0.5 s in on Linux and atFormatted output write failed(exit0xC0000409) about 1 s in on Windows.