From c3aa9bdf81c584411922271b58a6db7e8786de37 Mon Sep 17 00:00:00 2001 From: Longno242 Date: Tue, 24 Nov 2026 13:13:57 +0000 Subject: [PATCH] XGameRuntime: XAsyncGetResult writes 0 into *used while pending libHttpClient stores *bufferUsed before returning E_PENDING (and on failure HRESULTs). Leaving the out-parameter untouched kept a caller's sentinel. Same class as GetResultSize (#1201). Assisted-by: Cursor Auto (Composer) Co-authored-by: Cursor --- crates/xcl/src/hle/xgameruntime/xasync.rs | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/xcl/src/hle/xgameruntime/xasync.rs b/crates/xcl/src/hle/xgameruntime/xasync.rs index d358dc59c9..86e252e8cb 100644 --- a/crates/xcl/src/hle/xgameruntime/xasync.rs +++ b/crates/xcl/src/hle/xgameruntime/xasync.rs @@ -383,10 +383,14 @@ pub unsafe extern "system" fn XAsyncGetResult( let f: unsafe extern "system" fn(usize, *mut XAsyncBlock, *const c_void, usize, *mut c_void, *mut usize) -> HRESULT = std::mem::transmute(f); return f(o, b, identity, size, buffer, used); } + // libHttpClient writes `*bufferUsed` (0) before returning E_PENDING / failure HRESULTs. match lookup(b) { Lookup::Invalid => E_INVALIDARG, Lookup::Finished(h) => { if h.status < 0 { + if !used.is_null() { + *used = 0; + } return h.status; } if h.flags & FLAG_CONSUMED != 0 { @@ -401,12 +405,18 @@ pub unsafe extern "system" fn XAsyncGetResult( let (status, need) = { let mut g = s.inner.lock().unwrap(); if !g.is_done() { + if !used.is_null() { + *used = 0; + } return E_PENDING; } if !identity.is_null() && s.identity != 0 && identity as usize != s.identity { return E_INVALIDARG; } if g.status < 0 { + if !used.is_null() { + *used = 0; + } return g.status; } if g.result_size > 0 { @@ -761,6 +771,25 @@ mod tests { } } + /// libHttpClient stores 0 into `*bufferUsed` before returning E_PENDING. + #[test] + fn get_result_writes_zero_used_while_pending() { + let _g = crate::hle::xgameruntime::xasync::ASYNC_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + unsafe { + let mut b: XAsyncBlock = std::mem::zeroed(); + assert_eq!(XAsyncBegin(&mut b, std::ptr::null_mut(), std::ptr::null(), std::ptr::null(), begins_without_work as usize), S_OK); + let mut used = 0xDEADusize; + let mut buf = [0u8; 4]; + assert_eq!( + XAsyncGetResult(&mut b, std::ptr::null(), buf.len(), buf.as_mut_ptr() as _, &mut used), + E_PENDING + ); + assert_eq!(used, 0, "pending GetResult must write *used = 0"); + XAsyncComplete(&mut b, S_OK, 0); + assert_eq!(XAsyncGetStatus(&mut b, true), S_OK); + } + } + /// A terminated queue takes no new async work: the call fails with E_ABORT through the /// block, and the work never runs. #[test]