Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/runtime_imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
25 changes: 4 additions & 21 deletions runtime/shims/xgameruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <XAsync.h>
#include <XAsyncProvider.h>
#include <XTaskQueue.h>
#include "../../third_party/xtaskqueue/Source/Task/XAsyncProviderPriv.h"
#include "../../third_party/xtaskqueue/Source/Task/XTaskQueuePriv.h"

#include "file_system.h"
#include "shims.h"
Expand Down Expand Up @@ -165,25 +167,6 @@ ULONG STDMETHODCALLTYPE object_release(void* self) {
return static_cast<ULONG>(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 <int Slot> uint64_t STDMETHODCALLTYPE private_slot(void*) {
static std::atomic<bool> 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<bool> 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;
Expand All @@ -203,7 +186,7 @@ const void* const kThreadingVtable[] = {
XM(XAsyncCancel), // 5
XM(XAsyncRun), // 6
XM(XAsyncBegin), // 7
reinterpret_cast<const void*>(&begin_alloc_not_provided), // 8 XAsyncBeginAlloc (private, not called by the package)
XM(XAsyncBeginAlloc), // 8
XM(XAsyncSchedule), // 9
XM(XAsyncComplete), // 10
XM(XAsyncGetResult), // 11
Expand All @@ -223,7 +206,7 @@ const void* const kThreadingVtable[] = {
XM(XTaskQueueGetCurrentProcessTaskQueue), // 25
XM(XTaskQueueSetCurrentProcessTaskQueue), // 26
reinterpret_cast<const void*>(&thread_set_time_sensitive), // 27
reinterpret_cast<const void*>(&private_slot<28>), // 28 XTaskQueueIsEmpty (private; no arguments)
XM(XTaskQueueIsEmpty), // 28
reinterpret_cast<const void*>(&thread_assert_not_time_sensitive), // 29
reinterpret_cast<const void*>(&thread_is_time_sensitive), // 30
};
Expand Down
34 changes: 29 additions & 5 deletions runtime/test/xgameruntime_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ void check_run_time_load() {
check(reinterpret_cast<Create>(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<IsEmpty>(slot(t, 28))(t, queue, XTaskQueuePort::Work),
"slot 28 reports an idle work port empty");
static std::atomic<int> s_ran{0};
using Submit = HRESULT(STDMETHODCALLTYPE*)(void*, XTaskQueueHandle, XTaskQueuePort, void*,
XTaskQueueCallback*);
Expand All @@ -373,6 +376,10 @@ void check_run_time_load() {
};
check(reinterpret_cast<Submit>(slot(t, 18))(t, queue, XTaskQueuePort::Work, &s_ran, cb) == S_OK,
"slot 18 is XTaskQueueSubmitCallback");
check(!reinterpret_cast<IsEmpty>(slot(t, 28))(t, queue, XTaskQueuePort::Work),
"slot 28 reports queued work nonempty");
check(reinterpret_cast<IsEmpty>(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<Dispatch>(slot(t, 16))(t, queue, XTaskQueuePort::Work, 0) && s_ran.load() == 1,
"slot 16 is XTaskQueueDispatch: the callback ran on the work port");
Expand All @@ -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<int> 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<uint8_t*>(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<BeginAlloc>(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<BeginAlloc>(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<Status>(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**);
Expand Down
Loading