mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:30:53 +01:00
[PR #1875] runtime: fix title_page_watch mark clipping, split-tail ask, UINTPTR_MAX bounds, and ReadFileScatter pins (RT-TITLE-PAGE-WATCH-RANGE-AND-PINS) #1887
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1887
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1875
Author: @ambroseautomation
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-title-page-watch-range-and-pins📝 Commits (1)
e9ca38bRT-TITLE-PAGE-WATCH-RANGE-AND-PINS: fix mark clipping, split-tail ask, UINTPTR_MAX bounds, and ReadFileScatter pins📊 Changes
3 files changed (+214 additions, -27 deletions)
View changed files
📝
runtime/src/title_page_watch.h(+77 -27)📝
runtime/test/kernel_writes_test.cpp(+63 -0)📝
runtime/test/title_write_watch_test.cpp(+74 -0)📄 Description
Coordination item:
RT-TITLE-PAGE-WATCH-RANGE-AND-PINS(claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164267570).Problem
Five range-clipping, boundary, and pin-lifetime bugs in
runtime/src/title_page_watch.h:title_write_watch::mark(from, to)dropped marks or over-marked past reservation boundaries (title_page_watch.h:579-591):!contains(from): a range starting before a write-watched reservation and overlapping its interior was silently dropped.s.written—and if(to - from) / kPage > kKeep, raiseds.floor = now, forcing every unrelated shadow in the process to re-copy all of its memory.(to + kPage - 1) & ~(kPage - 1)wrapped to0nearUINTPTR_MAX.title_write_watch::ask()checked onlyborn(from)(title_page_watch.h:660):[from, to)spanned into a newly added/replaced write-watched reservation whose tail was added after the reader's last asking while the reservation atfrompredated it,born(from)returned the oldborn <= sinceandask()missed the newly zeroed pages in the tail.UINTPTR_MAX(title_page_watch.h:213,518,773,811,833,875):title_page_aliases::for_each_in()loopedva += kPageSizewithout stopping before wraparound whenend > UINTPTR_MAX - (kPageSize - 1).title_write_watch::add()could wrapendbelowbasewhenbase + sizeexceededUINTPTR_MAX, breaking map order invariants.kernel_writes::begin_write(),hold(),reopen(), andwrite()computedbegin + byteswithout saturation (wrappingendbelowbeginnearUINTPTR_MAX).kernel_writes::read_file_scatter()pin leak on synchronous completion &DWORDpage-count overflow (title_page_watch.h:927,936):bool(ok) || error == ERROR_IO_PENDINGtoend_write()instead of!ok && error == ERROR_IO_PENDING(asread_file()already does): ifReadFileScattercompletes synchronously (ok == TRUE), pins were kept withreturned = trueinstead of released immediately, so reusing theOVERLAPPEDfor another pending request kept the completed scatter buffers pinned.(bytes + info.dwPageSize - 1) / info.dwPageSizeused 32-bitDWORDaddition, overflowing for largebytes..returnedinitializer inkernel_writes::hold()(title_page_watch.h:811):-Wmissing-field-initializersunderclang-cl /W4.Changes
runtime/src/title_page_watch.h:title_write_watch::mark(from, to)to round with overflow saturation and clip directly against overlapping reservations ins.regionsunders.journal -> s.mutexlock order (matchingask()'s lock order, zero process-heap allocations), raisings.flooronly when total overlapping watched pages exceedkKeep.title_write_watch::born_covering(from, to)and used it inask()so a run is only treated as covered by an old reservation when a single reservation covers the entire[from, to).title_write_watch::add(),title_page_aliases::for_each_in(), andkernel_writes::{begin_write, hold, reopen, write}overflow-safe nearUINTPTR_MAX.kernel_writes::read_file_scatter()to use 64-bit page count arithmetic and release pins on synchronous completion (!ok && error == ERROR_IO_PENDING), and explicitly initialized.returned = falseinkernel_writes::hold().runtime/test/title_write_watch_test.cpp&runtime/test/kernel_writes_test.cpp:mark()leading-margin clipping, trailing-margin clipping without spuriouss.floorbumps, multi-reservation spans,ask()detecting split/new-tail reservations,UINTPTR_MAXsaturation/termination inadd()/mark()/title_page_aliases::for_each_in()/hold(), andkernel_writes::read_file_scatter().Verification
main5e95fa2f4):title_write_watch_test: FAILED (3 failures: leading-marginmark(), trailing-marginmark(), and split-tailask())kernel_writes_test: FAILED (1 failure:hold()wrappedendnearUINTPTR_MAX)main77baf9062, MSVC 14.51.36231/W4 /WX /permissive- /std:c++20 /O2 /MDand LLVMclang-cl /W4 /WX):title_write_watch_test.exe— OK (26 checks, 0 failures)kernel_writes_test.exe— 34 checks, 0 failurestitle_memory_map_test.exe— 14 checks, 0 failuresxmem_test.exe— OK (480 checks)clang-cl /W4 /WXontitle_write_watch_test.cppandkernel_writes_test.cpp— exit 0, 0 warningspython -I scripts/check_no_game_data.py runtime/src/title_page_watch.h runtime/test/title_write_watch_test.cpp runtime/test/kernel_writes_test.cpp— clean (exit 0)Hardware / Environment
clang-clAI-assisted: yes
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.