diff --git a/docs/runtime_imports.md b/docs/runtime_imports.md index 0d82077815..2f1c837e4e 100644 --- a/docs/runtime_imports.md +++ b/docs/runtime_imports.md @@ -336,7 +336,7 @@ count and width, the function at that position of xgameruntime-docs' "Layout" li | Class | Slots called | Checked against the documented order | |---|---|---| -| `XThreadingImpl` (`IXThreadingImpl`, 28 methods, slots 3-30) | 3-7 and 9-30 (`libHttpClient.GDK.dll`), 3, 5, 12, 16-18, 22, 29 (`XCurl.dll`) | e.g. 7 `XAsyncBegin` (5 args), 9 `XAsyncSchedule` (pointer, 32-bit), 10 `XAsyncComplete` (pointer, HRESULT, size), 12 `XTaskQueueCreate` (two 32-bit modes, pointer), 16 `XTaskQueueDispatch` (returns a byte), 19 `XTaskQueueSubmitDelayedCallback` (5 args), 22 `XTaskQueueTerminate` (pointer, bool, two pointers), 27 `XThreadSetTimeSensitive` (bool), 30 `XThreadIsTimeSensitive` (returns a byte). Slot 8 (`XAsyncBeginAlloc`, private) is never called; slot 28 (`XTaskQueueIsEmpty`, private) takes no arguments | +| `XThreadingImpl` (`IXThreadingImpl`, 28 methods, slots 3-30) | 3-7 and 9-30 (`libHttpClient.GDK.dll`), 3, 5, 12, 16-18, 22, 29 (`XCurl.dll`) | e.g. 7 `XAsyncBegin` (5 args), 9 `XAsyncSchedule` (pointer, 32-bit), 10 `XAsyncComplete` (pointer, HRESULT, size), 12 `XTaskQueueCreate` (two 32-bit modes, pointer), 16 `XTaskQueueDispatch` (returns a byte), 19 `XTaskQueueSubmitDelayedCallback` (5 args), 22 `XTaskQueueTerminate` (pointer, bool, two pointers), 27 `XThreadSetTimeSensitive` (bool), 30 `XThreadIsTimeSensitive` (returns a byte). Slot 8 (`XAsyncBeginAlloc`, private) is never called; slot 28 (`XTaskQueueIsEmpty`, private) takes a queue and a port | | `XErrorImpl` (`IXErrorImpl`, slots 3-5) | 3 (`XCurl.dll`) | slot 3, the docs' `_unknown_`, takes an HRESULT and a pointer: `XErrorReport(HRESULT, const char*)` | | `XNetworkingImpl` (`IXNetworkingImpl2`, slots 3-20) | 11-17 (`XCurl.dll`), 3-20 (`libHttpClient.GDK.dll`, each in its documented argument shape, e.g. 18-20 (enum, u64 pointer / u64 / pointer)) | the Utf16 `XNetworkingQuerySecurityInformationForUrl*` trio, `XNetworkingVerifyServerCertificate`, `XNetworkingGetConnectivityHint`, `XNetworkingRegister/UnregisterConnectivityHintChanged` (pointer, bool). Served offline, asked for with `IXNetworkingImpl2`'s id | | `XSystemImpl` (`IXSystemImpl5`, slots 3-8 known) | 3-8 (`libHttpClient.GDK.dll`) | 3-5 `XSystemGetConsoleId` / `GetXboxLiveSandboxId` / `GetAppSpecificDeviceId` (size, pointer, pointer each), 6 `XSystemHandleTrack` (two pointers, IXSystemImpl3), 7 `XSystemIsHandleValid` (pointer), 8 `XSystemAllowFullDownloadBandwidth` (bool, IXSystemImpl4); IXSystemImpl2 and 5 add no known method. Served offline | diff --git a/runtime/shims/xgameruntime.cpp b/runtime/shims/xgameruntime.cpp index 2b44229be4..f27ec6ab89 100644 --- a/runtime/shims/xgameruntime.cpp +++ b/runtime/shims/xgameruntime.cpp @@ -33,6 +33,8 @@ #include #include #include +#include "../../third_party/xtaskqueue/Source/Task/XAsyncProviderPriv.h" +#include "../../third_party/xtaskqueue/Source/Task/XTaskQueuePriv.h" #include "file_system.h" #include "shims.h" @@ -165,25 +167,6 @@ ULONG STDMETHODCALLTYPE object_release(void* self) { return static_cast(prev > 1 ? prev - 1 : 1); // the singleton's own reference stays } -// A private slot whose signature isn't public: logged once, answers 0 (S_OK / false / nothing to do). -template uint64_t STDMETHODCALLTYPE private_slot(void*) { - static std::atomic s_logged{false}; - if (!s_logged.exchange(true)) - std::fprintf(stderr, "[rt] xgameruntime: XThreadingImpl private slot %d called; answering 0\n", Slot); - return 0; -} - -// Slot 8, XAsyncBeginAlloc: private (no public page) and never called by the package's DLLs, so its signature here -// is not measured. Refuse it: answering S_OK would tell the caller its async call has begun while no provider ever -// receives XAsyncOp::Begin, so its completion never arrives. -HRESULT STDMETHODCALLTYPE begin_alloc_not_provided(void*) { - static std::atomic s_logged{false}; - if (!s_logged.exchange(true)) - std::fprintf(stderr, "[rt] xgameruntime: XThreadingImpl slot 8 (XAsyncBeginAlloc) called; not provided, " - "returning E_NOTIMPL\n"); - return E_NOTIMPL; -} - // XThreadSetTimeSensitive / XThreadIsTimeSensitive / XThreadAssertNotTimeSensitive. The flag is per thread, as in // the GDK; nothing is enforced offline (a time-sensitive thread may still block). thread_local bool t_time_sensitive = false; @@ -203,7 +186,7 @@ const void* const kThreadingVtable[] = { XM(XAsyncCancel), // 5 XM(XAsyncRun), // 6 XM(XAsyncBegin), // 7 - reinterpret_cast(&begin_alloc_not_provided), // 8 XAsyncBeginAlloc (private, not called by the package) + XM(XAsyncBeginAlloc), // 8 XM(XAsyncSchedule), // 9 XM(XAsyncComplete), // 10 XM(XAsyncGetResult), // 11 @@ -223,7 +206,7 @@ const void* const kThreadingVtable[] = { XM(XTaskQueueGetCurrentProcessTaskQueue), // 25 XM(XTaskQueueSetCurrentProcessTaskQueue), // 26 reinterpret_cast(&thread_set_time_sensitive), // 27 - reinterpret_cast(&private_slot<28>), // 28 XTaskQueueIsEmpty (private; no arguments) + XM(XTaskQueueIsEmpty), // 28 reinterpret_cast(&thread_assert_not_time_sensitive), // 29 reinterpret_cast(&thread_is_time_sensitive), // 30 }; diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp index af67045d42..d42021f86f 100644 --- a/runtime/test/xgameruntime_test.cpp +++ b/runtime/test/xgameruntime_test.cpp @@ -365,6 +365,9 @@ void check_run_time_load() { check(reinterpret_cast(slot(t, 12))(t, XTaskQueueDispatchMode::Manual, XTaskQueueDispatchMode::Manual, &queue) == S_OK && queue, "slot 12 is XTaskQueueCreate"); + using IsEmpty = bool(STDMETHODCALLTYPE*)(void*, XTaskQueueHandle, XTaskQueuePort); + check(reinterpret_cast(slot(t, 28))(t, queue, XTaskQueuePort::Work), + "slot 28 reports an idle work port empty"); static std::atomic s_ran{0}; using Submit = HRESULT(STDMETHODCALLTYPE*)(void*, XTaskQueueHandle, XTaskQueuePort, void*, XTaskQueueCallback*); @@ -373,6 +376,10 @@ void check_run_time_load() { }; check(reinterpret_cast(slot(t, 18))(t, queue, XTaskQueuePort::Work, &s_ran, cb) == S_OK, "slot 18 is XTaskQueueSubmitCallback"); + check(!reinterpret_cast(slot(t, 28))(t, queue, XTaskQueuePort::Work), + "slot 28 reports queued work nonempty"); + check(reinterpret_cast(slot(t, 28))(t, queue, XTaskQueuePort::Completion), + "slot 28 reports completion empty while work is queued"); using Dispatch = bool(STDMETHODCALLTYPE*)(void*, XTaskQueueHandle, XTaskQueuePort, uint32_t); check(reinterpret_cast(slot(t, 16))(t, queue, XTaskQueuePort::Work, 0) && s_ran.load() == 1, "slot 16 is XTaskQueueDispatch: the callback ran on the work port"); @@ -393,17 +400,34 @@ void check_run_time_load() { // Slot 8 (XAsyncBeginAlloc, private, signature not measured) must not report a begun call whose provider // never received XAsyncOp::Begin: either it refuses, or the provider saw Begin exactly once. static std::atomic s_begins{0}; - XAsyncProvider* provider = [](XAsyncOp op, const XAsyncProviderData*) -> HRESULT { - if (op == XAsyncOp::Begin) s_begins.fetch_add(1); + static bool s_context_ok = false; + static const uint8_t* s_parameter = nullptr; + XAsyncProvider* provider = [](XAsyncOp op, const XAsyncProviderData* data) -> HRESULT { + if (op == XAsyncOp::Begin) { + auto* context = static_cast(data->context); + s_context_ok = context && context != s_parameter && + std::memcmp(context, s_parameter, 4) == 0 && context[15] == 0; + if (context) context[15] = 0x7f; + s_begins.fetch_add(1); + XAsyncComplete(data->async, S_OK, 0); + } return S_OK; }; XAsyncBlock alloc_block{}; using BeginAlloc = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, const void*, const char*, XAsyncProvider*, size_t, size_t, void*); + uint8_t parameter[] = {0x12, 0x34, 0x56, 0x78}; + s_parameter = parameter; const HRESULT alloc_hr = - reinterpret_cast(slot(t, 8))(t, &alloc_block, nullptr, "test", provider, 16, 0, nullptr); - check(FAILED(alloc_hr) || s_begins.load() == 1, - "slot 8 (XAsyncBeginAlloc) never reports success for a call whose provider did not begin"); + reinterpret_cast(slot(t, 8))(t, &alloc_block, nullptr, "test", provider, 16, sizeof(parameter), parameter); + check(alloc_hr == S_OK && s_begins.load() == 1, + "slot 8 begins the allocated provider"); + check(s_context_ok, "slot 8 provides a 16-byte context with a copied parameter block"); + if (alloc_hr == S_OK) { + using Status = HRESULT(STDMETHODCALLTYPE*)(void*, XAsyncBlock*, bool); + check(reinterpret_cast(slot(t, 3))(t, &alloc_block, true) == S_OK, + "slot 8 provider completes successfully"); + } void* unk = nullptr; const GUID iunknown = {0, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46}}; using QI = HRESULT(STDMETHODCALLTYPE*)(void*, REFIID, void**);