Commit Graph

19 Commits

Author SHA1 Message Date
David 9c7aa0d61a feat(libc): implement ftrylockfile
Porpoise PPSA99764 stops after pthread_attr_* (#3494) with the
predicted `FAIL: unresolved ELF import h05OHOMZNMw from
libSceLibcInternal.prx` (idx 311, call site 0x8EC37); RetroArch
PPSA99169 imports it at idx 448 (call site 0xA4A27). h05OHOMZNMw is
ftrylockfile by tools/nid_names.py and aerolib.csv (zecoxao/sce_symbols
2883963a); ps5-payload-dev/sdk f5d40f02 declares
`int ftrylockfile(FILE *)` in include/freebsd/stdio.h.

ftrylockfile tries the same host CRT stream lock that flockfile,
funlockfile and every locking host stdio call on the stream take, so
no second lock exists beside the one stdio uses. It returns 0 when the
lock is acquired or already owned by the caller (recursive, released by
as many funlockfile calls) and -1 when another thread holds it, as
FreeBSD 8c639945 lib/libc/stdio/_flock_stub.c:89-104 does. Linux calls
glibc ftrylockfile. UCRT has no try variant of _lock_file, so Windows
calls TryEnterCriticalSection on the CRITICAL_SECTION that _lock_file
enters (__crt_stdio_stream_data::_lock, ucrt/inc/corecrt_internal_stdio.h,
same layout in Windows SDK 10.0.19041, 10.0.22621 and 10.0.26100). A
null or closed stream throws. The UCRT layout dependency is recorded in
TechnicalDebt.

guest_standard_streams covers trylock on an unlocked stream, re-entry
by the owner, failure from another thread while held (also after one of
two unlocks and while another thread holds flockfile), stdio calls
from another thread blocking on the trylock-held lock, release order,
and null and closed streams.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-11 18:42:23 +05:30
Hussein Kadhim 09921dd376 fix(libc): return 0 from scanf when input fails after a suppressed conversion on Windows
C17 7.21.6.2p16 returns EOF only if input fails before the first conversion completes, and a suppressed conversion completes. FreeBSD counts it in nconversions (vfscanf.c, releng/11.4, lines 799-805). The host scanf returned EOF there, so sscanf("12", "%*d%d", &v) reported EOF instead of 0. Each suppressed conversion now records its end with a %n and a result of EOF becomes 0 when one was recorded.
2026-10-11 12:12:48 +02:00
Romans Pokrovskis 228532e9a8 fix(libc): keep unlocked stream status queries lock-free
Use unlocked POSIX EOF/error queries after unlocked byte operations so status synchronization cannot reacquire the stream lock. Keep the verified UCRT status calls on Windows, and cover byte, status, error, and held-lock behavior.

Co-authored-by: MarcZX100 <marczxrr@gmail.com>
2026-10-11 09:18:23 +00:00
MarcZX100 753b856526 feat(libc): implement unlocked character I/O 2026-10-11 09:18:23 +00:00
Adrià Franch e7605c8fd6 feat(libc): implement rewind
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-11 02:54:24 +02:00
Hannah Lyons 92c9296ae3 feat(libc): implement flockfile and funlockfile
(cherry picked from commit d32eaf181aadf79efc4199b22591f1f5f228d00c)
2026-10-10 21:49:58 +00:00
Scott Schuster 8bba489932 fix(libc): parse fopen and freopen modes as FreeBSD does
FreeBSD's __sflags reads the access character, then b, +, x, e and v, and
stops at the first other character without failing, so "rt" opens for
reading. On Windows fopen inserted b after the first character and passed
the rest on, so "rt" became "rbt", the CRT rejected it with EINVAL, and
fopen threw. vkQuake opens history.txt with "rt" at startup. freopen
accepted only a fixed list of modes.

Both now parse the mode like __sflags. An unknown access character, or x
on a read-only stream, returns NULL with EINVAL; x on an existing file
returns NULL with EEXIST; e and v are accepted and ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:48:13 -05:00
LeandroLP23 2e9ab8cc59 fix(libc): give setvbuf a default buffer when the size is 0
FreeBSD's setvbuf takes a zero size with _IOFBF or _IOLBF as "pick the
buffer size". The UCRT rejects sizes below 2 for those modes through
its invalid parameter handler, so the call failed on Windows and a test
process was terminated. A zero size now drops the given buffer and
asks the host for one of BUFSIZ bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 09:58:38 +02:00
Dean a2073010c4
Merge pull request #972 from ebarr24/codex/libc-fscanf-abi
fix(libc): translate Windows fscanf guest arguments
2026-10-07 15:14:30 +13:00
Ethan Barr 73facbc3d1 fix(libc): translate Windows fscanf guest arguments 2026-10-06 13:45:10 -07:00
Ethan Barr 34689f39ca fix(libc): preserve guest stdio bytes on Windows 2026-10-06 13:41:25 -07:00
Nicolas Abosch 7789c0a57b feat(libs): implement homebrew libc and kernel runtime exports 2026-10-05 22:40:16 -03:00
asimplestray 85a0ec2e69 fix(libc): convert sysv va_list for fscanf on Windows 2026-09-29 21:32:30 +00:00
asimplestray 77194e4561 feat(libc): implement fputwc, fputws and fscanf 2026-09-29 21:25:07 +00:00
SamG-Coder f37fffdacd feat(libc): expose guest vsprintf formatting 2026-09-25 07:26:06 +10:00
SamG-Coder dd0debe967 feat(libc): reopen guest streams while preserving identity 2026-09-25 07:05:07 +10:00
SamG-Coder 79edb20f17 fix(libc): preserve 64-bit guest stream offsets 2026-09-25 07:00:45 +10:00
SamG-Coder f49cace1ca feat(libc): implement guest formatted stream output 2026-09-25 06:35:32 +10:00
SamG-Coder e8ecb29170 feat(libc): expose guest standard streams and character IO 2026-09-25 06:30:30 +10:00