fix(libc): write each log line in one call #3871
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3871"
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 fdfawef324 on 2026-10-11T18:19:29Z.
What
Demon's Souls (PPSA01342 v1.005, Windows) stops on a black screen on
maina11c8f7f: the window showsDemon's Souls | FPS: 0.00 (2)for good, every BPE job worker spins in its scheduler and nothing is reported. This is the black screen #3710 describes after its Acm change; on this machine (RTX 3060) it happens on plainmain. The last stderr lines before it are the shader preparation pool's failures:Thread stacks sampled with gdb while it is stuck (three samples, all the same):
mingw's
fprintf(libstdc++ turns on__USE_MINGW_ANSI_STDIO) writes an unbuffered stream throughfputc, so every character is aWriteFile, and it holds the stream's lock for the whole line. AnAPS5_LOG_ERRline carrying a RecompileRequest is tens of thousands of writes; while the game runs, stderr grew by about 500 bytes a second. Every other thread that writes to stderr waits behind it, and the job worker waiting insceSaveDataDirNameSearch's trace keepsGameCoreLoopfrom ever finishing a frame. With stderr sent toNULthe game passes the black screen within 30 s.Driver::reportSkipgot the same treatment in8cf2f6580(GTA V at 0.1 fps). This does it for theAPS5_LOG_*macros:WriteLogLineformats the line into memory (onevsnprintf, a second one only for lines over 1 KiB) and writes it with onefwriteand the existingfflush. The format string is still checked at compile time (gnu::format, with mingw's__MINGW_PRINTF_FORMATso%zuand%llustay valid there). The UCRT writes an unbuffered stream'sfwriteas one even-length block and the last byte, so a line takes at most two writes on Windows and one on Linux.With this change Demon's Souls renders and stops at its next error, a separate topic:
Tested
ANYPS5_ENABLE_SPIRV_TOOLS=OFF, RTX 3060.log_macrostest: logs a short line, a 20000-character line and a line without arguments to an unbuffered stream whose writes keep their boundaries (a message-mode named pipe on Windows, aSOCK_SEQPACKETsocket pair on Linux) and checks the text and the number of writes. Onmainit fails witha short line took more than two writes; with this change it passes. Linux not run (no Linux machine here).ctest -j10: the same 4 tests fail with and without this change on this machine (guest_kernel_sysneeds symlink privileges,guest_filesystemgets Access Denied on its probe file,windows_exceptions,agc_driver_emulated_color_compareneeds sRGB sampling the device lacks).main; with this change it renders and reaches the error above.python tools/check_conventions.py --base mainpasses.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 adriadam10 on 2026-10-11T22:12:32Z.
Checked on Linux: PR merged onto current main builds,
log_macrospasses and fails withLogMacros.hppreverted, so the test pins the change (short line, 20000-character line and a line without arguments each stay within two writes, text compared exactly). Return value of the macros is unchanged (fflush), format checking is kept viagnu::format. Windows/mingw behaviour relies on your run. Merging once CI is green.