Commit Graph

10 Commits

Author SHA1 Message Date
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
Hussein Kadhim 44f00e2be8 fix(libc): format %p as FreeBSD does on Windows
The Windows formatter passed %p to the host CRT, which prints 16
zero-padded digits without a prefix. FreeBSD prints 0x followed by the
lowercase hex digits (0x0 for a null pointer), as if by %#lx.
2026-10-11 10:43:41 +02:00
MarcZX100 4d537755e9 test(libc): cover vsscanf_s capacity limits 2026-10-10 23:52:11 +02:00
pushkarreddyy e251de849d feat(libc): implement vsnprintf_s and vsscanf_s
(cherry picked from commit 4ca866ea3b989da6947ad110f4d6c7f4efbe27c8)
2026-10-10 23:52:11 +02:00
gdr-98 21d21da385 fix(libc): format guest wide printf arguments on Linux 2026-10-08 21:15:04 +02:00
Raj 4c60962cd0 test(libc): put sprintf, sscanf and libc_printf arguments on the stack
guest_formatting called sprintf with four variadic arguments and
libc_printf with one, all in registers, and did not call sscanf, so only
snprintf had a check that fails with the old Linux register rebuild. sprintf
now formats six integers, sscanf converts eight fields and libc_printf prints
seven integers; on the old code the first gives "1 2 3 4 0 0" and the other
two crash.

Checks suggested by nauroth in #1435.
2026-10-08 12:30:40 +05:30
Raj 18113907c8 test(libc): run guest_formatting on Linux
guest_formatting_tests was built on Linux but registered with ctest on
Windows only, so the Linux printf and scanf exports had no coverage: on main
the test fails there at its first vsnprintf check and then crashes in
snprintf with eight integers.

It is registered on every platform now. The %ls checks stay Windows-only,
as glibc reads %ls as 32-bit wchar_t; that gap is recorded in TechnicalDebt.
2026-10-08 11:46:56 +05:30
Ethan Barr 62de7ab8ac fix(libc): keep wide printf precision on UTF-8 boundaries 2026-10-06 14:28:56 -07:00
STL1te c206f7049a feat(kernel, libc): memory, files and threads for retail title boot
libkernel:
- direct memory keeps its contents per physical page across unmap and
  remap; a page mapped at two live addresses at once throws
- sceKernelDirectMemoryQuery answers from tracked allocations
- SCE protections read back as set, GPU and AMPR bits included
- APR prefix path resolve, file size and stat by id, positional reads,
  fsync/pread/pwrite; directories open as descriptors on Windows
- sceKernelCheckReachability, getpeername, shutdown
- Dinkumware C11 threads (_Mtx_*, _Cnd_*, _Thrd_*) in the title libc
  layout; any pthread stack size, rounded at thread creation

libc:
- unaddressed guest mappings go to the system-managed area from
  0x2_0000_0000, leaving the application area to fixed mappings
- the process starts in /app0
- guest sscanf on Windows; a null %s prints as (null) as on FreeBSD
- localeconv, _FNan, _FDtest, _FExp, __udivti3, wcsncpy_s, aligned
  operator new, _Throw_Cpp_error

Tests: direct memory following physical pages, guest formatting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:22:13 +03:00
boykopovar ea3f7b5ae0 fix(windows): va_list sysv abi parse for fomatting functions 2026-09-11 07:49:14 +03:00