Repository navigation
Conversation
…o as fputs and fflush do When the host write behind fprintf, fprintf_s, fwprintf and their v and _s forms failed, or fseeko could not flush pending output, the host errno reached the guest as it was: 11 for EAGAIN on Linux, which is EDEADLK in the guest numbering, where fputs, fwrite and fflush report 35. These calls now translate it the same way. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
What
When the host write behind a guest stream fails with
EAGAINon Linux,fputsreports 35 (FreeBSD'sEAGAIN) butfprintfon the same stream reports 11, which a title reads as FreeBSD'sEDEADLK(errno.h:59-60, :92). These writes pass the hosterrnothrough untranslated:vfprintf(fprintf,vfprintf): thestd::fwriteat Formatting.cpp:745 (Windows) and :751, and the hoststd::vfprintfat :757.WriteSecure(fprintf_s,vfprintf_s,printf_s,vprintf_s): Formatting.cpp:1051.wprintf,vfwprintf(fwprintf,vwprintf) andvfwprintf_s(fwprintf_s,wprintf_s,vwprintf_s): FormattingWide.cpp:501, :522, :555.fseeko(andfseek,rewind,fsetpos): FileAndHeap.cpp:1206 maps onlyEOVERFLOW, so a failed flush of pending output before the seek keeps the host number.FreeBSD 11.4 returns
EOFfromvfprintfandvfwprintfwith theerrnothatwrite(2)set in__sflush(vfprintf.c:1043-1044, vfwprintf.c:1101-1102, fflush.c:125-137), and_fseekoflushes a writing stream before it seeks (fseek.c:169-172, :283-286).Each of the formatted writes now follows
fputs,fwriteandfflush: it saveserrnoand zeroes it before the hostfwriteorvfprintf, then setsGuestErrnoFromHost_nid_no_patchof what the host set, or restores the saved value if the host set nothing (one small helper per file). The other stream writes already translate this way:fputs,fputc,fwriteandfflush(boykopovar#14559),dprintf(boykopovar#15912),fputwcandfputws(boykopovar#16913),fclose(boykopovar#25515) and theungetc/ungetwcflush (boykopovar#25593). InfseekotheEOVERFLOWspecial case becomes the general mapping, which still gives 84 forEOVERFLOW. Guest values set in place of a write (EILSEQin the wide catches, the closed-streamEBADF,fseeko's target checks) are not translated. No title is known to hit this; the case for the change is the siblings above. In practice it isEAGAINon a non-blocking pipe or socket stream, orEDQUOT.Side effects: the host
vfprintfpath also maps LinuxEOVERFLOW(75) for output aboveINT_MAXto 84, andfseekomaps a hosterrnothe table does not know toEIO(5), asfputsdoes, wheremainpassed it through. In-tree callers of these functions (libSceLibcInternal's__vfprintf,err/warn, andfseekusers in other libraries) see the translated values too.Neighbours: our boykopovar#25024 changes only
PrintWindowsand says "translating the hosterrnoin the printf family is a separate change"; this is that change for the stream functions, andprintf,vprintfandputsare left for after boykopovar#25024. boykopovar#11332 (conflicting) adds acount < 0return just above the narrowfwritelines, so a textual conflict is likely. boykopovar#24406 (conflicting) addsIsBadDescriptorchecks at the top ofvfprintf,fseekoand other stream functions. boykopovar#22047 adds a closed-stream check at the top offprintf. boykopovar#24377 changes the macOS branch ofWritingStream, whichResolveSeekTargetcalls forSEEK_END.Tested
Linux (WSL2, x86-64), GCC, full build.
file_streamsgains five entries in the pipe writer cases (fprintfwith%s, which takes the hostvfprintf,fprintfwith%.0f, which is guest-formatted,fprintf_s,fwprintf,fwprintf_s): each fails on a full non-blocking pipe witherrno35 and the error flag set, then writes once the pipe is drained. Two new blocks check thatfseeko(SEEK_SET)andrewindwith output pending on a full pipe giveerrno35. The existing recovery step of the writer cases checks that a successful write leaves a preseterrnounchanged.mainwith the new test:file_streamsfails. A probe calling the same functions onmain'slibcprintserrno=11for all seven (fprintf %s,fprintf %.0f,fprintf_s,fwprintf,fwprintf_s,fseeko,rewind).file_streams,guest_formattingandguest_wide_formattingpass, and the probe printserrno=35for all seven. Fullctest: 7,117 of 7,312 pass; the 195 failures are GPU and environment tests that fail the same way onmainon this machine (WSL2: no GPU, so Vulkan falls back to llvmpipe, and the 6.6 kernel lacks asynchronous userfaultfd write protection).wprintfto stdout or the Windowsvfprintfbranch. In CI the new cases run only in the Linux job, on pushes and manual runs (build.ymlline 516). On a pull request the Windows job builds and runs the changedcore/libstests (lines 746, 934-937), where the pipe section offile_streamsis compiled out (#ifndef _WIN32). The macOS jobs build the relinker only (line 354) or their own test projects.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)🤖 Generated with Claude Code
Summary by CodeRabbit