Repository navigation
FFI: use extern "system-unwind" across guest-reentry boundaries (#106) - #197
JGonzalezRodriguez wants to merge 3 commits into
Conversation
|
One unwind path still leaves XAsync pending indefinitely. In I built PR head The head tests establish Rust panic propagation and cleanup through the exercised call paths. Foreign C++ exceptions and SEH from a title still need their own verification. In particular, casting |
…gthen tests Address adversarial review findings on PR xcl-dev#197: - xasync: make BeginCleanup only remove Phase::Pending blocks (preserving synchronously completed payloads), guard XAsyncComplete OP_CLEANUP unwinds with CompleteCleanup (writes FLAG_DONE, removes ACTIVE, marks Consumed, wakes waiters), guard XAsyncGetResult OP_GET_RESULT/OP_CLEANUP unwinds with ConsumeCleanup (without re-entering guest OP_CLEANUP in Drop), guard XAsyncRun's XAsyncSchedule with BeginCleanup, and track Payload ownership via Arc<Payload> + AtomicBool + PayloadGuard to prevent both leaks and double-free. - taskqueue: drain both PORT_WORK and PORT_COMPLETION into a single Remaining(VecDeque) and notify both ports' condvars before running any canceled callbacks in XTaskQueueTerminate (using O(1) pop_front). - d3d12x/real: revert all 3 lines completely. - kernelx test: separate throwing_title_alloc/throwing_title_free fallback returning null/no-op so concurrent D3D12 tests are undisturbed. - gameinput test: assert CallbackGuard state directly + from a second thread, verify ReadingGuard released the Reading ref via extra AddRef, and guard unregister via RAII Drop declared after ctx. - loader/eh tests: drop flaky global LOAD_LOCK.try_lock() check and serialize TITLE_FILTER mutation with a local test mutex. - tests: add regression tests for BeginCleanup sync-completed payloads, Payload ownership on unwind, XAsyncComplete/XAsyncGetResult/XAsyncRun unwinds, and XTaskQueueTerminate PORT_WORK unwind draining/waking PORT_COMPLETION.
|
Thanks @Kalmarv for testing on native Windows 11 and for the detailed code review! Both points are addressed in the latest commits (
AI-assisted. |
…gthen tests Address adversarial review findings on PR xcl-dev#197: - xasync: make BeginCleanup only remove Phase::Pending blocks (preserving synchronously completed payloads), guard XAsyncComplete OP_CLEANUP unwinds with CompleteCleanup (writes FLAG_DONE, removes ACTIVE, marks Consumed, wakes waiters), guard XAsyncGetResult OP_GET_RESULT/OP_CLEANUP unwinds with ConsumeCleanup (without re-entering guest OP_CLEANUP in Drop), guard XAsyncRun's XAsyncSchedule with BeginCleanup, and track Payload ownership via Arc<Payload> + AtomicBool + PayloadGuard to prevent both leaks and double-free. - taskqueue: drain both PORT_WORK and PORT_COMPLETION into a single Remaining(VecDeque) and notify both ports' condvars before running any canceled callbacks in XTaskQueueTerminate (using O(1) pop_front). - d3d12x/real: revert all 3 lines completely. - kernelx test: separate throwing_title_alloc/throwing_title_free fallback returning null/no-op so concurrent D3D12 tests are undisturbed. - gameinput test: assert CallbackGuard state directly + from a second thread, verify ReadingGuard released the Reading ref via extra AddRef, and guard unregister via RAII Drop declared after ctx. - loader/eh tests: drop flaky global LOAD_LOCK.try_lock() check and serialize TITLE_FILTER mutation with a local test mutex. - tests: add regression tests for BeginCleanup sync-completed payloads, Payload ownership on unwind, XAsyncComplete/XAsyncGetResult/XAsyncRun unwinds, and XTaskQueueTerminate PORT_WORK unwind draining/waking PORT_COMPLETION.
1712e46 to
2ba3fba
Compare
…ies (xcl-dev#106) Switch guest callback function pointer types and re-entrant HLE entrypoints/ trampolines/hooks from plain `extern "system"` (nounwind in Rust 1.71+) to `extern "system-unwind"` so guest C++ / SEH exceptions unwind cleanly through XCL's Rust frames while running Drop guards instead of aborting via `panic_cannot_unwind` or skipping cleanups: - kernelx: XMemAllocFn/XMemFreeFn, XMemAlloc, XMemFree, LoadLibrary*, LoadPackagedLibrary, GetProcAddress - d3d12x/real: dev_create_descriptor_heap_x, heap_release, dev_create_committed_resource_layout_x (transitive title allocation hooks) - user: console_wndproc, CreateWindowExA/create_window_ex_w, and CallWindowProcW/SetWindowPos/CreateWindowExW imports - loader & main: TlsCallback, DllMain, ExeEntry, main_thread, xcl_tls_callback - eh: unhandled_filter and TITLE_FILTER invocation - vfs_hooks: MoveFileWithProgressA/W, CopyFileExW, CopyFile2 hooks & orig types - gameinput: ReadingCallback, DeviceCallback, register_device_callback, plus RAII ReadingGuard/EntryCleanup guards - xaudio2: VoiceCallbackVtbl and decoded_cb_* trampolines - xgameruntime: taskqueue callbacks/entrypoints (with InflightGuard, CancelInflight, RunningGuard, and Remaining guards), xasync provider/work/ completion callbacks & entrypoints (with BeginCleanup and NotifyGuard), COM vtable SHIMS/FORWARDS/call_target, XErrorReport, XPackageEnumeratePackages, XGameSave enumerators/async entrypoints, XUser/XNetworking async entrypoints Add 10 unit regression tests exercising unwinding and Drop-guard cleanup across each boundary (verified on x86_64-pc-windows-msvc under Proton Experimental).
…gthen tests Address adversarial review findings on PR xcl-dev#197: - xasync: make BeginCleanup only remove Phase::Pending blocks (preserving synchronously completed payloads), guard XAsyncComplete OP_CLEANUP unwinds with CompleteCleanup (writes FLAG_DONE, removes ACTIVE, marks Consumed, wakes waiters), guard XAsyncGetResult OP_GET_RESULT/OP_CLEANUP unwinds with ConsumeCleanup (without re-entering guest OP_CLEANUP in Drop), guard XAsyncRun's XAsyncSchedule with BeginCleanup, and track Payload ownership via Arc<Payload> + AtomicBool + PayloadGuard to prevent both leaks and double-free. - taskqueue: drain both PORT_WORK and PORT_COMPLETION into a single Remaining(VecDeque) and notify both ports' condvars before running any canceled callbacks in XTaskQueueTerminate (using O(1) pop_front). - d3d12x/real: revert all 3 lines completely. - kernelx test: separate throwing_title_alloc/throwing_title_free fallback returning null/no-op so concurrent D3D12 tests are undisturbed. - gameinput test: assert CallbackGuard state directly + from a second thread, verify ReadingGuard released the Reading ref via extra AddRef, and guard unregister via RAII Drop declared after ctx. - loader/eh tests: drop flaky global LOAD_LOCK.try_lock() check and serialize TITLE_FILTER mutation with a local test mutex. - tests: add regression tests for BeginCleanup sync-completed payloads, Payload ownership on unwind, XAsyncComplete/XAsyncGetResult/XAsyncRun unwinds, and XTaskQueueTerminate PORT_WORK unwind draining/waking PORT_COMPLETION.
…plain extern "system" - xasync: replace PayloadGuard with State::_owned_payload (Option<Arc<Payload>>) and Payload::owned_by_pc so XCL-managed payloads stay alive across concurrent workers/unwinds until every Arc<State> drops (clearing work/result buffers in OP_CLEANUP), while PC-runtime-delegated payloads (PC_ASYNC != 0) are only reclaimed on synchronous hr < 0 or OP_CLEANUP (eliminating both PC-runtime and concurrent-worker UAF paths). - taskqueue: revert waiter_fired back to plain extern "system" and remove the RegisterWaitForSingleObject callback transmute (OS thread-pool callback).
2ba3fba to
a82fbfb
Compare
|
Native Windows Tested
A hang that is not this PR's My first Not tested
AI use
|
|
Closing as a stale, conflicting ~1,300-line PR failing the |
Part of #106. Converts guest-callback function pointer types and re-entrant HLE entrypoints/trampolines/hooks to
extern "system-unwind"across 14 files and adds RAII cleanup guards so guest exceptions unwinding through Rust frames do not abort or leave locks/state wedged.What is in it
hle/kernelx.rs:XMemAllocFn/XMemFreeFn,XMemAlloc,XMemFree,LoadLibrary*,LoadPackagedLibrary,GetProcAddress. (hle/d3d12x/real.rsintentionally left untouched.)hle/user.rs:console_wndproc,CreateWindowExA/create_window_ex_w, andCallWindowProcW/SetWindowPos/CreateWindowExWimports.loader.rs&main.rs:TlsCallback,DllMain,ExeEntry,main_thread,xcl_tls_callback.eh.rs:unhandled_filterandTITLE_FILTERinvocation (VEH/terminate/gs_failure handlers stayextern "system"/"C").vfs_hooks.rs:MoveFileWithProgressA/W,CopyFileExW,CopyFile2hooks & orig types soGuard::dropresetsIN_HOOKon progress-callback unwind.hle/gameinput.rs:ReadingCallback,DeviceCallback,register_device_callback, plus RAIIReadingGuard/EntryCleanup.hle/xaudio2.rs:VoiceCallbackVtbl(all 7 methods) anddecoded_cb_*trampolines.hle/xgameruntime/:taskqueue.rs(callbacks/entrypoints +InflightGuard,CancelInflight,RunningGuard, dual-portRemaining;waiter_firedstays plainextern "system"forRegisterWaitForSingleObject),xasync.rs(callbacks/entrypoints +BeginCleanup,CompleteCleanup,ConsumeCleanup,NotifyGuard,State._owned_payload),api.rs,gamesave.rs,mod.rs,networking.rs.Tested
610.57.4,rustc 1.98.1x86_64-pc-windows-msvcviaclang-cl 23.1.1+lld-link+xwinSDK10.0.26100, Proton Experimental + local relaxedvkd3d-proton):cargo build --release --workspace --target x86_64-pc-windows-msvc: 0 errors, 0 warnings.cargo test --no-run --package xcl --lib --target x86_64-pc-windows-msvc: 0 errors, 0 warnings.unwind): 13 passed, 0 failed acrosseh,hle::gameinput,hle::kernelx,hle::user(throughuser32!CallWindowProcW),hle::xaudio2,hle::xgameruntime::{api,taskqueue,xasync}, andloader.hle::kernelx:: hle::gameinput:: hle::user:: loader:: hle::xgameruntime:: eh:: hle::xaudio2:: vfs_hooks::): 139 passed, 1 failed (pre-existing Wine/FAudio-onlyxma2_source_voice_decodes_and_manages_lifetime).xcl_testtitle.exe: 47/50 passed (all CPU/TLS/exceptions/XGameRuntime/D3D12.X checks pass; 3 known Wine/FAudio diffs).202bf56):@Kalmarvbuilt and passed all 10 initial unwind tests on Windows 11 Pro 26200, x64 MSVC,rustc 1.99.0(and flaggedXAsyncComplete/XAsyncGetResult/waiter_fired, all addressed ina82fbfb).Regression run
scripts/smoke.ps1run by a tester with a retail title.Not tested
scripts/smoke.ps1regression run; full native Windowsscripts/test.ps1on heada82fbfb.AI use