Skip to content

fix(libc): return flush failures from fflush instead of throwing - #4904

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
EagleBearerYS:fix/libc-fflush-errors
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
EagleBearerYS:fix/libc-fflush-errors

Conversation

@EagleBearerYS

@EagleBearerYS EagleBearerYS commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

fflush (libc/src/FileAndHeap.cpp) throws when the host flush fails, so an ordinary write error such as a full disk ends the title:

terminate called after throwing an instance of 'std::runtime_error'
  what():  fflush: flush failed

On a write error, C17 7.21.5.2 asks fflush to set the stream's error indicator and return EOF. FreeBSD's __sflush does exactly that (fflush.c L126-L137).

fflush was the one stream call left:

fflush now returns the host's result and syncs the guest stream's error flag, as those functions do. A stream that was already closed still throws, as the existing test expects. No title is claimed.

Tested

Windows 11 (10.0.26300), WinLibs MinGW-w64 GCC 15.2.0 r7 (UCRT), Release, -DBUILD_TESTING=ON, on main at c13dc7e:

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
  • Unblocks: none
  • AI-assisted: yes

fflush threw when the host flush failed, which ends the title on an
ordinary write error such as a full disk. FreeBSD's __sflush sets the
stream's error flag and returns EOF, as C17 7.21.5.2 asks. fflush now
returns the host result and keeps the guest stream's error flag in sync,
as fwrite, fputs and fclose already do since boykopovar#4380 and boykopovar#3926.
@github-actions github-actions Bot added the libc label Oct 13, 2026
@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows test: head 3d550b3de merged onto current main ea2bbefb2 (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter file_streams: file_streams passed (1 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

@babyhuey

Copy link
Copy Markdown
Contributor

Title evidence from Windows (Windows 11, RTX 3080, WinLibs GCC 15.2, Release): XPSemu (PPSA97358), on main 18c438b with #5061 and #5187 merged, relinked with --windows-fixed-base 0x400000. Its Mesa shader cache write fails with EACCES under the whole-file Windows flock (#4958), and main throws fflush: flush failed (exit 0xC0000409). With this PR (3d550b3, clean merge, without #4958) there's no throw. fflush returns the failure and Mesa carries on, so the title reaches xemu's GPU probe. Mesa treats each failed part as bad, though, and moves on through part0 to part49 with nothing stored, so #4958 is what makes the cache work.

@oneandonlydean oneandonlydean self-assigned this Oct 14, 2026
@oneandonlydean
oneandonlydean merged commit 7e68acb into boykopovar:main Oct 14, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants