mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-23 09:49:34 -10:00
RARCH_LOG_V's generic branch - Linux, Windows, Switch and every console - wrote each line as a tag fprintf followed by a body vfprintf, under a comment claiming it was one call. Between those two calls sits a window where a thread switch interleaves one writer's tag into another's message; RetroArch logs from task workers and, under threaded video, from the video thread, so the window is real. The Switch-only mutex around the pair existed to paper over exactly this on a platform whose newlib stdio locking was not trusted. The branch now formats tag and message into one stack buffer and ships it with a single fputs: stdio's per-call lock keeps concurrent lines whole on every platform, which is what the other branches already had (the Xbox/WinRT head formats into one buffer, Apple goes through vasprintf, Android hands the va_list to the OS logger). Lines wider than the 1024-byte stack buffer take an exact-sized heap detour rather than truncating; if that allocation fails, the truncated stack line ships - a shortened message over a dropped one. The libnx mutex remains, shrunk around exactly the one write and its flush, since trusting devkitA64's stdio lock retargeting is a platform verification this change does not make. Two unreachable blocks fall out of the same read of the function: an inner __WINRT__ arm nested inside the head branch's #else (only compiled when __WINRT__ is undefined, so never), and the HAVE_LIBNX mutex lines inside the Apple ASL branch, which referenced a g_verbosity symbol that exists nowhere in the tree - only an impossible platform combination kept them from being a compile error. samples/frontend/log_atomicity links the shipping objects with only main() replaced and hammers RARCH_LOG from concurrent threads: fixed-width payloads from racing writers, plus a lane wider than the stack buffer so the heap detour is raced too. Every line of the resulting file must be a tag followed by one complete payload, at full count. Against the split-write shape the tear reproduced in three of six runs on a single CPU; the lane documents that the red is probabilistic by nature - its standing value is the invariant it hammers on. Verified: thread-read audit 0 findings / 0 allowlisted pairs, the harness green three consecutive runs, a host syntax pass under -DHAVE_LIBNX with stubbed mutex primitives, C89 gate at its pre-existing baseline, five forced atomic backends, the full build scanned clean for implicit-declaration and static-follows warnings, hot-function budgets and the 74-lane compile matrix.
11 lines
172 B
Makefile
11 lines
172 B
Makefile
TARGET := log_atomicity_test
|
|
|
|
all:
|
|
@sh ./build.sh
|
|
|
|
clean:
|
|
rm -f $(TARGET) retroarch_nomain.o retroarch_nomain.d \
|
|
harness_main.o harness_main.d
|
|
|
|
.PHONY: all clean
|