Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_error The buffer resize and the final assign caught only std::bad_alloc. A std::length_error now returns 12 as well, so neither exception leaves a C API through the callers that translate 12. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nreadable page Every source the test used was readable well past its terminator, so reading a whole host page from an unaligned start still passed. Put a string at the end of a readable page with an inaccessible page after it, and check the unbounded and exact caps, and the not-terminated cases that stop at or reach the inaccessible page. From Helldiverr's Windows probe on boykopovar#20678. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
|
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.
|
What
CopyGuestString_nid_no_patchresized its buffer to the wholemaximumbefore reading the first byte. So the cost of a call grew with the cap rather than the string. A cap that couldn't be allocated also returned 12 (ENOMEM) even when the string was a few bytes long, so a caller had to pick a cap it could afford to allocate on every call.The buffer now grows one page chunk at a time, by exactly the bytes about to be copied. The loop, the page-sized reads, the terminator search, the copied text and the return codes for every cap that could be allocated before (0, 14 for unreadable memory, 63 for no terminator within the cap) are unchanged. A short string with a large cap now costs one small allocation, and a cap like
SIZE_MAX / 2works, reading only up to the terminator the waystrlenwould.There were no direct tests, so this adds
GuestCopyGuestString.cpp, registered through atests/cmakefragment gated onBUILD_TESTINGthe waylibc_runtime_assertion_tests.cmakeis.Tested
11-21,
1ed2a4caa8(rebased onmain19729fa854): the buffer resize and the final assign inCopyGuestString_nid_no_patchalso return 12 when they throwstd::length_error, not onlystd::bad_alloc, so neither exception leaves a C API through callers that translate 12 (MarcZX10's point on #23418, which carries this helper). In practice it can't be thrown: the buffer grows a page at a time and the copy stops at the first unreadable page. Linux, GCC 15.2, Ninja Release:guest_copy_guest_stringpasses in each of 3 runs. Windows 11 VM (GeForce GT 1030, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release): it passes in each of 3 runs.Linux (Ubuntu 26.04.1), GCC 15.2, Release.
guest_copy_guest_string:0x10) sources return 14 and leave the output untouched;"guest"return 63, and caps of 6 and 16 copy it;""with cap 1 copies an empty string;SIZE_MAX / 2, both"guest"and the long string copy.main'sGeneral.cpp, every case before theSIZE_MAX / 2cap passes, and that cap fails (it returns 12).CopyGuestStringstill pass: the 109 matching path, kernel_sys, event-flag, equeue, file, socket and user-service tests (oneNot Runwas an unbuilt target, built and passed afterwards);guest_system_exit*,guest_np_manager,guest_resolverandguest_sce_v2_exceptions.git merge-treeagainst the open PRs that touchGeneral.cpp(perf(agc): keep shaders off host imports on NVIDIA's Windows driver and cut per-draw CPU boykopovar/AnyPS5#20315, feat(libs): mirror libkernel exports through libkernel_web boykopovar/AnyPS5#18112, feat(run-report): recover the report of a run that ended without writing one boykopovar/AnyPS5#15973, perf(libkernel): resolve an APR path's directory once and find the file in its listing boykopovar/AnyPS5#11446, fix(libc): follow a Windows symbolic link before .. in a guest path boykopovar/AnyPS5#9371): no new conflicts.tools/check_conventions.pypasses on the branch and this body.a831dfc189merged intomain, WinLibs GCC 15.2.0 full build: Windows Server 2025, 6500 of 6500 tests pass in both runs; Windows Server 2022, 2 of 6500 fail in both runs, and the same 2 fail onmainthere.11-24,
c90b8d8aa6: guard-page cases from Helldiverr's run. Helldiverr's Windows run (Ryzen 9 9950X3D, Windows 11 Pro 26300, WinLibs GCC 15.2, this head's parent1ed2a4caa8merged ontomainfa86dfcd3b):guest_copy_guest_stringpasses in 3 of 3 runs,main'sGeneral.cppfails it, and 4 of 5 mutations are caught. The survivor: removing the page alignment still passed, because every test source was readable well past its terminator.c90b8d8aa6adds cases with a string at the end of a readable page that has an inaccessible page after it: the unbounded and exact caps copy it, and the not-terminated text returns 63 at a cap that ends at the inaccessible page and 14 at one that reaches it.Linux (Ubuntu 26.04.1, GCC 15.2, Release), the head merged onto
mainadacf0bd83:guest_copy_guest_stringpasses in 3 of 3 runs, and without the page alignment it aborts.Windows 11 VM (WinLibs GCC 16.2.0, Release), the same merge: passes in 3 of 3 runs.
Not verified on Windows: in Helldiverr's run, a
bad_allocforced insidelibc.prx(by the negative control and one mutation) stopped the process as an undeliverable exception, so the 12 returns are measured on Linux only.Helldiverr's Windows re-check at
c90b8d8aa6, merged ontomain95702cd8d8:guest_copy_guest_stringpasses in 3 of 3 runs, and without the page alignment it fails at the first guard-page case.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit