Repository navigation
fix(libc): read guest wide strings as 16-bit units - #1116
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
|
|
This looks like the same change as #1126: both add |
The guest's wchar_t is 16 bits, but wcslen, wcscmp, wcsncmp, wcscpy, wcsncpy, wcschr, wcsrchr, wcsstr, wcspbrk, wcsspn and the wmem functions forwarded to the host's wchar_t functions, which use 32-bit units on Linux. Implement them on char16_t. The wide conversions that still use the host's wchar_t are listed in TechnicalDebt.
|
Checked the 15 rewrites against the C semantics (unsigned unit comparison, Only issue was a TechnicalDebt.md adjacency conflict with main; I rebased and kept all lines. Merging once CI is green on the rebased head. #1126 is the follow-up and will need a rebase after this lands. |
d482c4a to
cd39c8d
Compare
What
The guest's
wchar_tis 16 bits (UTF-16, seeWindowsFormatting.hpp;FormattingWide.cppand_Mbtowcxalready use 16-bit units). The string functions incore/libs/prx/libc/src/Strings.cpptookwchar_t*and forwarded to the host'sstd::wcs*/std::wmem*, which only matches the guest on Windows. On Linux the host'swchar_tis 32 bits, so these read and wrote guest strings in 4-byte units:wcslenof a guest string returned a wrong length, comparisons were wrong, and the copies could overrun the guest buffer.This implements them on
char16_t:wmemchr,wmemcmp,wmemcpy,wmemmove,wmemset,wcslen,wcscmp,wcsncmp,wcscpy,wcsncpy,wcschr,wcsrchr,wcsstr,wcspbrk,wcsspnComparisons are on unsigned code units and return -1, 0 or 1, as the Windows build returned before, so Windows behaviour does not change.
The wide conversions (
wcstod,wcstof,wcstold,wcstol,wcstoll,wcstoul,wcstoull,wcscoll,wcsxfrm,wcsrtombs) andswprintfhave the same problem on Linux but need a UTF-16 conversion, so they are left for a follow-up and listed in TechnicalDebt.guest_wide_stringscovers every changed function, including code units above 0x7FFF, embedded terminators,wcsncpypadding and truncation, overlappingwmemmoveand writes past the requested count.Tested
15.2.0posix-14.0.0-ucrt-r7), Release,-DBUILD_TESTING=ON, ond5adabaeStrings.cppandGuestWideStrings.cppbuild without warnings, also with-Wall -Wextra.ctest -E 'agc|shader|recompiler|Vulkan|vulkan|video_out': 197/197 passed, includingguest_wide_stringsandguest_wide_formatting. GPU tests not run.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)