mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 12:20:42 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b0e23e10a |
No files matched your search
@@ -10,6 +10,7 @@ Guest execution uses original, purpose-built test programs. Commercial Xbox game
|
||||
remains unsupported.
|
||||
|
||||
### Added
|
||||
- Added a BetterXen-only DirectStorage conformance interface for asynchronous uncompressed file and memory transfers, status arrays, and completion events in `XCRDAPI.dll` (#413).
|
||||
- Added Section 0 (`First-Time Contributor Onboarding`) to `AGENTS.md` (`CLAUDE.md` symlink) giving coding agents a turnkey step-by-step onboarding flow (preflight, `bx-cli doctor`, unclaimed `status: ready` issue discovery, claiming, scoped implementation, local verification including hosts without CrossOver, DCO commit, and PR CI watching).
|
||||
- Overhauled the repository into a clean 6-track parallel hybrid workspace (Milestone M0) designed for 5–8+ concurrent contributors and coding agents: added frozen cross-DLL ABI headers and canonical `.def` export tables (`abi/`), native ARM64 Rust workspace (`launcher/crates/{bx-cli,bx-probe,bx-telemetry}` with `env_clear()` child environment isolation, and `shader-transpiler/crates/dxbc-accc`), CMake + `mingw-w64` superbuild (`shims/`, `scripts/build-shims.sh`) producing 16 standalone x86-64 PE32+ shim DLLs (`bx_runtime_veh.dll` with working `clwb` VEH trap and JSONL logger, `xmem.dll`, `XCRDAPI.dll`, `d3d12_xs.dll`, `xg_xs.dll`, `xgameruntime.dll`, `GameInput.dll`, `AcpHal.dll`, `xapu.dll`, `chad.dll`, and PSM/ntuser forwarders) with strict PE Export Directory verification (exact names, ordinals, forwarders, zero extra exports, zero dynamic MinGW runtime dependencies), auto-discovered synthetic PE32+ conformance tests (`tests/conformance/`), `.github/workflows/hybrid-ci.yml`, `.github/ISSUE_TEMPLATE/track-handoff.yml`, `docs/adr/0006-retire-in-tree-native-workspace.md`, `docs/architecture/parallel-tracks.md`, and `docs/issues/wave-1-backlog.md`. Unified `docs/roadmap.md`, `CONTRIBUTING.md`, `AGENTS.md`, `README.md`, and `.github/CODEOWNERS` (retaining global `* @MacosPorters/maintainers` fallback and full provenance/independent-verification rules). Verified locally on Apple M5 (macOS 27.2.1, CrossOver 26.3, Rosetta 2) with all Rust checks, strict 16-DLL export verification, and live `test_veh_clwb.exe` + `test_shim_exports.exe` smoke tests passing.
|
||||
- Documented the original Windows workload set and Phase 1 hybrid measurement protocol (#353), including receipt-field sources, percentile definitions, negative controls and independent reproduction requirements. The protocol identifies the unmerged runner candidate and its missing raw traces and measurements; it adds no execution or compatibility claim.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
bx_add_shim_dll(xcrdapi XCRDAPI XCRDAPI.def
|
||||
xcrdapi.cpp
|
||||
)
|
||||
target_link_libraries(xcrdapi PRIVATE bx_runtime_veh kernel32)
|
||||
target_link_libraries(xcrdapi PRIVATE bx_runtime_veh kernel32 uuid)
|
||||
@@ -0,0 +1,68 @@
|
||||
#ifndef BETTERXEN_SYNTHETIC_STORAGE_H
|
||||
#define BETTERXEN_SYNTHETIC_STORAGE_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <d3d12.h>
|
||||
#include <unknwn.h>
|
||||
|
||||
// BetterXen-only COM contract for original conformance guests. The Xbox
|
||||
// DirectStorage interface IDs and binary layouts are independent of these types.
|
||||
namespace bx::storage {
|
||||
inline constexpr IID factory_iid{0xaad71506, 0x7beb, 0x49fc, {0x94, 0x1d, 0x46, 0x58, 0x75, 0xed, 0x35, 0x00}};
|
||||
inline constexpr IID file_iid{0x723738ce, 0x6772, 0x47dc, {0x95, 0x47, 0x27, 0x7d, 0x67, 0x22, 0xb0, 0xc7}};
|
||||
inline constexpr IID queue_iid{0xd895469a, 0xd810, 0x4dea, {0xb4, 0x48, 0xf4, 0x42, 0x5e, 0x52, 0x9e, 0x69}};
|
||||
inline constexpr IID status_iid{0xfb214629, 0xa3ae, 0x4a81, {0x9c, 0xe3, 0xe8, 0x42, 0x6b, 0x08, 0x62, 0xd7}};
|
||||
|
||||
struct File : IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE Close() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetFileInformation(BY_HANDLE_FILE_INFORMATION*) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetHandle(HANDLE*) = 0;
|
||||
};
|
||||
|
||||
struct Status : IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE GetResult(UINT index) = 0;
|
||||
};
|
||||
|
||||
// Requests keep source and destination buffers borrowed until completion.
|
||||
// File requests retain a duplicate of the file handle when enqueued.
|
||||
struct Request {
|
||||
File* file;
|
||||
UINT64 file_offset;
|
||||
const void* source;
|
||||
void* destination;
|
||||
DWORD size;
|
||||
UINT compression;
|
||||
};
|
||||
|
||||
struct ErrorRecord {
|
||||
HRESULT first_error;
|
||||
UINT64 failure_count;
|
||||
};
|
||||
|
||||
struct QueueInfo {
|
||||
UINT capacity;
|
||||
UINT available;
|
||||
};
|
||||
|
||||
struct Queue : IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE EnqueueRequest(const Request*) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE EnqueueStatus(Status*, UINT index) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE EnqueueSignal(ID3D12Fence*, UINT64 value) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE EnqueueSetEvent(HANDLE) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE Submit() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE RetrieveErrorRecord(ErrorRecord*) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE Query(QueueInfo*) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE Close() = 0;
|
||||
};
|
||||
|
||||
struct Factory : IUnknown {
|
||||
virtual HRESULT STDMETHODCALLTYPE OpenFile(PCWSTR, REFIID, void**) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateQueue(UINT capacity, REFIID, void**) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateStatusArray(UINT count, REFIID, void**) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE SetStagingBufferSize(UINT size) = 0;
|
||||
};
|
||||
} // namespace bx::storage
|
||||
|
||||
extern "C" HRESULT WINAPI DStorageGetFactory(REFIID, void**);
|
||||
|
||||
#endif
|
||||
+430
-7
@@ -1,13 +1,436 @@
|
||||
#include <windows.h>
|
||||
#include "synthetic_storage.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <new>
|
||||
|
||||
#include "bx_log.h"
|
||||
|
||||
/* Track B (M1-B3): DirectStorage factory & async I/O queue shim. */
|
||||
namespace {
|
||||
using namespace bx::storage;
|
||||
|
||||
extern "C" HRESULT WINAPI DStorageGetFactory(REFIID /*riid*/, void** ppv) {
|
||||
BX_STUB_LOG("XCRDAPI.dll", "DStorageGetFactory");
|
||||
if (ppv) {
|
||||
*ppv = nullptr;
|
||||
HRESULT win32_error() { return HRESULT_FROM_WIN32(GetLastError()); }
|
||||
|
||||
class Lock {
|
||||
public:
|
||||
explicit Lock(SRWLOCK& mutex) : mutex_(mutex) { AcquireSRWLockExclusive(&mutex_); }
|
||||
~Lock() { ReleaseSRWLockExclusive(&mutex_); }
|
||||
|
||||
private:
|
||||
SRWLOCK& mutex_;
|
||||
};
|
||||
|
||||
template<class Interface, const IID& interface_id>
|
||||
class Object : public Interface {
|
||||
public:
|
||||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** result) override {
|
||||
if (!result) return E_POINTER;
|
||||
*result = nullptr;
|
||||
if (!IsEqualIID(riid, interface_id) && !IsEqualIID(riid, IID_IUnknown)) {
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
*result = static_cast<Interface*>(this);
|
||||
AddRef();
|
||||
return S_OK;
|
||||
}
|
||||
return E_NOTIMPL;
|
||||
|
||||
ULONG STDMETHODCALLTYPE AddRef() override { return InterlockedIncrement(&references_); }
|
||||
|
||||
ULONG STDMETHODCALLTYPE Release() override {
|
||||
const ULONG references = InterlockedDecrement(&references_);
|
||||
if (!references) delete this;
|
||||
return references;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~Object() = default;
|
||||
|
||||
private:
|
||||
LONG references_ = 1;
|
||||
};
|
||||
|
||||
template<class Interface>
|
||||
HRESULT publish(Interface* object, REFIID iid, void** result) {
|
||||
const HRESULT status = object->QueryInterface(iid, result);
|
||||
object->Release();
|
||||
return status;
|
||||
}
|
||||
|
||||
HRESULT duplicate_handle(HANDLE handle, HANDLE* copy) {
|
||||
const HANDLE process = GetCurrentProcess();
|
||||
return DuplicateHandle(process, handle, process, copy, 0, FALSE, DUPLICATE_SAME_ACCESS)
|
||||
? S_OK : win32_error();
|
||||
}
|
||||
|
||||
class StorageFile final : public Object<File, file_iid> {
|
||||
public:
|
||||
explicit StorageFile(HANDLE handle) : handle_(handle) {}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE Close() override {
|
||||
Lock lock(mutex_);
|
||||
if (handle_ == INVALID_HANDLE_VALUE) return S_OK;
|
||||
if (!CloseHandle(handle_)) return win32_error();
|
||||
handle_ = INVALID_HANDLE_VALUE;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE GetFileInformation(BY_HANDLE_FILE_INFORMATION* info) override {
|
||||
if (!info) return E_POINTER;
|
||||
Lock lock(mutex_);
|
||||
return GetFileInformationByHandle(handle_, info) ? S_OK : win32_error();
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE GetHandle(HANDLE* copy) override {
|
||||
if (!copy) return E_POINTER;
|
||||
*copy = nullptr;
|
||||
Lock lock(mutex_);
|
||||
if (handle_ == INVALID_HANDLE_VALUE) return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
|
||||
return duplicate_handle(handle_, copy);
|
||||
}
|
||||
|
||||
private:
|
||||
~StorageFile() override { Close(); }
|
||||
|
||||
SRWLOCK mutex_ = SRWLOCK_INIT;
|
||||
HANDLE handle_;
|
||||
};
|
||||
|
||||
class StatusArray final : public Object<Status, status_iid> {
|
||||
public:
|
||||
struct Slot {
|
||||
HRESULT result = E_PENDING;
|
||||
bool busy = false;
|
||||
};
|
||||
|
||||
StatusArray(Slot* slots, UINT count) : slots_(slots), count_(count) {}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE GetResult(UINT index) override {
|
||||
if (index >= count_) return E_INVALIDARG;
|
||||
Lock lock(mutex_);
|
||||
return slots_[index].result;
|
||||
}
|
||||
|
||||
HRESULT begin(UINT index) {
|
||||
if (index >= count_) return E_INVALIDARG;
|
||||
Lock lock(mutex_);
|
||||
if (slots_[index].busy) return HRESULT_FROM_WIN32(ERROR_BUSY);
|
||||
slots_[index] = {E_PENDING, true};
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void complete(UINT index, HRESULT result) {
|
||||
Lock lock(mutex_);
|
||||
slots_[index] = {result, false};
|
||||
}
|
||||
|
||||
private:
|
||||
~StatusArray() override { delete[] slots_; }
|
||||
|
||||
SRWLOCK mutex_ = SRWLOCK_INIT;
|
||||
Slot* slots_;
|
||||
UINT count_;
|
||||
};
|
||||
|
||||
enum class Kind { request, status, signal, event };
|
||||
|
||||
struct Entry {
|
||||
Kind kind;
|
||||
Request request{};
|
||||
HANDLE handle = nullptr;
|
||||
StatusArray* status = nullptr;
|
||||
UINT index = 0;
|
||||
ID3D12Fence* fence = nullptr;
|
||||
UINT64 value = 0;
|
||||
};
|
||||
|
||||
HRESULT read_request(HANDLE file, const Request& request) {
|
||||
if (!request.size) return S_OK;
|
||||
if (!file) {
|
||||
std::memmove(request.destination, request.source, request.size);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
OVERLAPPED operation{};
|
||||
operation.Offset = static_cast<DWORD>(request.file_offset);
|
||||
operation.OffsetHigh = static_cast<DWORD>(request.file_offset >> 32);
|
||||
operation.hEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
|
||||
if (!operation.hEvent) return win32_error();
|
||||
|
||||
DWORD bytes = 0;
|
||||
HRESULT result = S_OK;
|
||||
if (!ReadFile(file, request.destination, request.size, &bytes, &operation)) {
|
||||
const DWORD error = GetLastError();
|
||||
if (error != ERROR_IO_PENDING) {
|
||||
result = HRESULT_FROM_WIN32(error);
|
||||
} else if (!GetOverlappedResult(file, &operation, &bytes, TRUE)) {
|
||||
result = win32_error();
|
||||
}
|
||||
}
|
||||
CloseHandle(operation.hEvent);
|
||||
if (SUCCEEDED(result) && bytes != request.size) return HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
|
||||
return result;
|
||||
}
|
||||
|
||||
class WorkQueue final : public Object<Queue, queue_iid> {
|
||||
public:
|
||||
WorkQueue(Entry* entries, UINT capacity) : entries_(entries), capacity_(capacity) {}
|
||||
|
||||
bool create_work() {
|
||||
work_ = CreateThreadpoolWork(run, this, nullptr);
|
||||
return work_ != nullptr;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE EnqueueRequest(const Request* request) override {
|
||||
constexpr UINT64 max_file_offset = std::numeric_limits<LONGLONG>::max();
|
||||
if (!request || (request->size && (!request->destination
|
||||
|| (!request->source && !request->file)))
|
||||
|| (request->file && (request->file_offset > max_file_offset - request->size))) {
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
Entry entry{Kind::request, *request};
|
||||
if (request->file && !request->compression) {
|
||||
const HRESULT result = request->file->GetHandle(&entry.handle);
|
||||
if (FAILED(result)) return result;
|
||||
}
|
||||
const HRESULT result = enqueue(entry);
|
||||
if (FAILED(result) && entry.handle) CloseHandle(entry.handle);
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE EnqueueStatus(Status* status, UINT index) override {
|
||||
auto* array = dynamic_cast<StatusArray*>(status);
|
||||
if (!array) return E_INVALIDARG;
|
||||
|
||||
Lock lock(mutex_);
|
||||
const HRESULT available = check_available();
|
||||
if (FAILED(available)) return available;
|
||||
const HRESULT result = array->begin(index);
|
||||
if (FAILED(result)) return result;
|
||||
|
||||
array->AddRef();
|
||||
Entry entry{Kind::status};
|
||||
entry.status = array;
|
||||
entry.index = index;
|
||||
append(entry);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE EnqueueSignal(ID3D12Fence* fence, UINT64 value) override {
|
||||
if (!fence) return E_POINTER;
|
||||
Entry entry{Kind::signal};
|
||||
entry.fence = fence;
|
||||
entry.value = value;
|
||||
fence->AddRef();
|
||||
const HRESULT result = enqueue(entry);
|
||||
if (FAILED(result)) fence->Release();
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE EnqueueSetEvent(HANDLE event) override {
|
||||
if (!event || event == INVALID_HANDLE_VALUE) return E_INVALIDARG;
|
||||
Entry entry{Kind::event};
|
||||
const HRESULT duplicated = duplicate_handle(event, &entry.handle);
|
||||
if (FAILED(duplicated)) return duplicated;
|
||||
const HRESULT result = enqueue(entry);
|
||||
if (FAILED(result)) CloseHandle(entry.handle);
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE Submit() override {
|
||||
Lock lock(mutex_);
|
||||
if (closed_) return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
|
||||
submit();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE RetrieveErrorRecord(ErrorRecord* out) override {
|
||||
if (!out) return E_POINTER;
|
||||
Lock lock(mutex_);
|
||||
*out = errors_;
|
||||
errors_ = {};
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE Query(QueueInfo* info) override {
|
||||
if (!info) return E_POINTER;
|
||||
Lock lock(mutex_);
|
||||
*info = {capacity_, capacity_ - size_};
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE Close() override {
|
||||
{
|
||||
Lock lock(mutex_);
|
||||
closed_ = true;
|
||||
submit();
|
||||
}
|
||||
if (work_) WaitForThreadpoolWorkCallbacks(work_, FALSE);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
~WorkQueue() override {
|
||||
Close();
|
||||
if (work_) CloseThreadpoolWork(work_);
|
||||
delete[] entries_;
|
||||
}
|
||||
|
||||
HRESULT check_available() const {
|
||||
if (closed_) return HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE);
|
||||
return size_ == capacity_ ? HRESULT_FROM_WIN32(ERROR_BUSY) : S_OK;
|
||||
}
|
||||
|
||||
void append(const Entry& entry) {
|
||||
entries_[(head_ + size_) % capacity_] = entry;
|
||||
++size_;
|
||||
}
|
||||
|
||||
HRESULT enqueue(const Entry& entry) {
|
||||
Lock lock(mutex_);
|
||||
const HRESULT result = check_available();
|
||||
if (FAILED(result)) return result;
|
||||
append(entry);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void submit() {
|
||||
submitted_ = size_;
|
||||
if (submitted_ && !active_) {
|
||||
active_ = true;
|
||||
SubmitThreadpoolWork(work_);
|
||||
}
|
||||
}
|
||||
|
||||
static void CALLBACK run(PTP_CALLBACK_INSTANCE, void* context, PTP_WORK) {
|
||||
static_cast<WorkQueue*>(context)->drain();
|
||||
}
|
||||
|
||||
void drain() {
|
||||
for (;;) {
|
||||
Entry entry{};
|
||||
{
|
||||
Lock lock(mutex_);
|
||||
if (!submitted_) {
|
||||
active_ = false;
|
||||
return;
|
||||
}
|
||||
entry = entries_[head_];
|
||||
}
|
||||
HRESULT result = S_OK;
|
||||
switch (entry.kind) {
|
||||
case Kind::request:
|
||||
if (entry.request.compression) {
|
||||
BX_STUB_LOG("XCRDAPI.dll", "compression");
|
||||
result = E_NOTIMPL;
|
||||
} else {
|
||||
result = read_request(entry.handle, entry.request);
|
||||
}
|
||||
if (entry.handle) CloseHandle(entry.handle);
|
||||
break;
|
||||
case Kind::status:
|
||||
entry.status->complete(entry.index, status_error_);
|
||||
entry.status->Release();
|
||||
status_error_ = S_OK;
|
||||
break;
|
||||
case Kind::signal:
|
||||
result = entry.fence->Signal(entry.value);
|
||||
entry.fence->Release();
|
||||
break;
|
||||
case Kind::event:
|
||||
if (!SetEvent(entry.handle)) result = win32_error();
|
||||
CloseHandle(entry.handle);
|
||||
break;
|
||||
}
|
||||
Lock lock(mutex_);
|
||||
if (FAILED(result)) {
|
||||
if (SUCCEEDED(status_error_)) status_error_ = result;
|
||||
if (!errors_.failure_count) errors_.first_error = result;
|
||||
++errors_.failure_count;
|
||||
}
|
||||
head_ = (head_ + 1) % capacity_;
|
||||
--size_;
|
||||
--submitted_;
|
||||
}
|
||||
}
|
||||
|
||||
SRWLOCK mutex_ = SRWLOCK_INIT;
|
||||
Entry* entries_;
|
||||
UINT capacity_;
|
||||
UINT head_ = 0;
|
||||
UINT size_ = 0;
|
||||
UINT submitted_ = 0;
|
||||
bool active_ = false;
|
||||
bool closed_ = false;
|
||||
PTP_WORK work_ = nullptr;
|
||||
HRESULT status_error_ = S_OK;
|
||||
ErrorRecord errors_{};
|
||||
};
|
||||
|
||||
class StorageFactory final : public Object<Factory, factory_iid> {
|
||||
public:
|
||||
HRESULT STDMETHODCALLTYPE OpenFile(PCWSTR path, REFIID iid, void** out) override {
|
||||
if (!out) return E_POINTER;
|
||||
*out = nullptr;
|
||||
if (!path || !*path) return E_INVALIDARG;
|
||||
HANDLE handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, nullptr,
|
||||
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE) return win32_error();
|
||||
auto* file = new (std::nothrow) StorageFile(handle);
|
||||
if (!file) {
|
||||
CloseHandle(handle);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
return publish(file, iid, out);
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CreateQueue(UINT capacity, REFIID iid, void** out) override {
|
||||
if (!out) return E_POINTER;
|
||||
*out = nullptr;
|
||||
if (!capacity || capacity > 65535) return E_INVALIDARG;
|
||||
auto* entries = new (std::nothrow) Entry[capacity];
|
||||
if (!entries) return E_OUTOFMEMORY;
|
||||
auto* queue = new (std::nothrow) WorkQueue(entries, capacity);
|
||||
if (!queue) {
|
||||
delete[] entries;
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
if (!queue->create_work()) {
|
||||
const HRESULT error = win32_error();
|
||||
queue->Release();
|
||||
return error;
|
||||
}
|
||||
return publish(queue, iid, out);
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE CreateStatusArray(UINT count, REFIID iid, void** out) override {
|
||||
if (!out) return E_POINTER;
|
||||
*out = nullptr;
|
||||
if (!count || count > 65535) return E_INVALIDARG;
|
||||
auto* slots = new (std::nothrow) StatusArray::Slot[count];
|
||||
if (!slots) return E_OUTOFMEMORY;
|
||||
auto* array = new (std::nothrow) StatusArray(slots, count);
|
||||
if (!array) {
|
||||
delete[] slots;
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
return publish(array, iid, out);
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE SetStagingBufferSize(UINT size) override {
|
||||
if (!size) return S_OK;
|
||||
BX_STUB_LOG("XCRDAPI.dll", "SetStagingBufferSize");
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
extern "C" HRESULT WINAPI DStorageGetFactory(REFIID riid, void** ppv) {
|
||||
if (!ppv) return E_POINTER;
|
||||
*ppv = nullptr;
|
||||
if (!IsEqualIID(riid, factory_iid) && !IsEqualIID(riid, IID_IUnknown)) {
|
||||
BX_STUB_LOG("XCRDAPI.dll", "DStorageGetFactory");
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
auto* factory = new (std::nothrow) StorageFactory;
|
||||
return factory ? publish(factory, riid, ppv) : E_OUTOFMEMORY;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
add_executable(test_xcrdapi main.cpp)
|
||||
target_include_directories(test_xcrdapi PRIVATE "${BX_ROOT_DIR}/shims/xcrdapi")
|
||||
target_link_libraries(test_xcrdapi PRIVATE xcrdapi kernel32 uuid)
|
||||
@@ -0,0 +1,120 @@
|
||||
#include "synthetic_storage.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
using namespace bx::storage;
|
||||
|
||||
#define CHECK(condition) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
std::fprintf(stderr, "xcrdapi:%d: %s (Win32 error %lu)\n", \
|
||||
__LINE__, #condition, static_cast<unsigned long>(GetLastError())); \
|
||||
return 1; \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
template<class Interface>
|
||||
struct Com {
|
||||
Interface* value = nullptr;
|
||||
|
||||
~Com() { if (value) value->Release(); }
|
||||
Interface* operator->() const { return value; }
|
||||
void** out() { return reinterpret_cast<void**>(&value); }
|
||||
};
|
||||
|
||||
struct TemporaryFile {
|
||||
WCHAR name[MAX_PATH]{};
|
||||
~TemporaryFile() { if (*name) DeleteFileW(name); }
|
||||
};
|
||||
|
||||
struct Event {
|
||||
HANDLE handle = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
~Event() { if (handle) CloseHandle(handle); }
|
||||
};
|
||||
|
||||
int main() {
|
||||
void* unsupported = nullptr;
|
||||
CHECK(DStorageGetFactory(file_iid, &unsupported) == E_NOINTERFACE && !unsupported);
|
||||
CHECK(DStorageGetFactory(factory_iid, nullptr) == E_POINTER);
|
||||
Com<Factory> factory;
|
||||
CHECK(DStorageGetFactory(factory_iid, factory.out()) == S_OK);
|
||||
|
||||
Com<IUnknown> identity;
|
||||
CHECK(factory->QueryInterface(IID_IUnknown, identity.out()) == S_OK);
|
||||
CHECK(identity.value == factory.value);
|
||||
CHECK(factory->SetStagingBufferSize(0) == S_OK);
|
||||
|
||||
TemporaryFile temporary;
|
||||
WCHAR directory[MAX_PATH];
|
||||
const DWORD directory_len = GetTempPathW(MAX_PATH, directory);
|
||||
CHECK(directory_len && directory_len < MAX_PATH);
|
||||
CHECK(GetTempFileNameW(directory, L"bxs", 0, temporary.name));
|
||||
const HANDLE writer = CreateFileW(temporary.name, GENERIC_WRITE, 0, nullptr,
|
||||
TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
CHECK(writer != INVALID_HANDLE_VALUE);
|
||||
constexpr char contents[] = "ABCDEF0123456789";
|
||||
DWORD written = 0;
|
||||
const BOOL wrote = WriteFile(writer, contents, sizeof(contents), &written, nullptr);
|
||||
CloseHandle(writer);
|
||||
CHECK(wrote && written == sizeof(contents));
|
||||
|
||||
Com<File> file;
|
||||
CHECK(factory->OpenFile(temporary.name, file_iid, file.out()) == S_OK);
|
||||
BY_HANDLE_FILE_INFORMATION file_info{};
|
||||
CHECK(file->GetFileInformation(&file_info) == S_OK);
|
||||
CHECK(file_info.nFileSizeHigh == 0 && file_info.nFileSizeLow == sizeof(contents));
|
||||
|
||||
Com<Status> status;
|
||||
CHECK(factory->CreateStatusArray(2, status_iid, status.out()) == S_OK);
|
||||
Event event;
|
||||
CHECK(event.handle);
|
||||
std::array<char, 5> first{}, second{}, copied{};
|
||||
Com<Queue> queue;
|
||||
CHECK(factory->CreateQueue(5, queue_iid, queue.out()) == S_OK);
|
||||
|
||||
Request read1{file.value, 2, nullptr, first.data(), 4, 0};
|
||||
Request read2{file.value, 10, nullptr, second.data(), 4, 0};
|
||||
Request copy{nullptr, 0, first.data(), copied.data(), 4, 0};
|
||||
CHECK(queue->EnqueueRequest(&read1) == S_OK);
|
||||
CHECK(queue->EnqueueRequest(&read2) == S_OK);
|
||||
CHECK(queue->EnqueueRequest(©) == S_OK);
|
||||
CHECK(queue->EnqueueStatus(status.value, 0) == S_OK);
|
||||
CHECK(queue->EnqueueSetEvent(event.handle) == S_OK);
|
||||
CHECK(queue->EnqueueRequest(©) == HRESULT_FROM_WIN32(ERROR_BUSY));
|
||||
CHECK(status->GetResult(0) == E_PENDING);
|
||||
CHECK(WaitForSingleObject(event.handle, 0) == WAIT_TIMEOUT);
|
||||
CHECK(first[0] == 0 && second[0] == 0 && copied[0] == 0);
|
||||
|
||||
CHECK(queue->Submit() == S_OK);
|
||||
CHECK(WaitForSingleObject(event.handle, 5000) == WAIT_OBJECT_0);
|
||||
CHECK(status->GetResult(0) == S_OK);
|
||||
CHECK(std::strcmp(first.data(), "CDEF") == 0);
|
||||
CHECK(std::strcmp(second.data(), "4567") == 0);
|
||||
CHECK(std::strcmp(copied.data(), "CDEF") == 0);
|
||||
|
||||
ErrorRecord error{};
|
||||
CHECK(queue->RetrieveErrorRecord(&error) == S_OK && error.failure_count == 0);
|
||||
Request past_end{file.value, sizeof(contents), nullptr, first.data(), 1, 0};
|
||||
Request compressed{nullptr, 0, first.data(), copied.data(), 4, 1};
|
||||
CHECK(queue->EnqueueRequest(&past_end) == S_OK);
|
||||
CHECK(queue->EnqueueRequest(&compressed) == S_OK);
|
||||
CHECK(queue->EnqueueStatus(status.value, 0) == S_OK);
|
||||
CHECK(queue->EnqueueStatus(status.value, 1) == S_OK);
|
||||
CHECK(queue->Submit() == S_OK);
|
||||
CHECK(file->Close() == S_OK);
|
||||
CHECK(file->GetFileInformation(&file_info) == HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE));
|
||||
CHECK(queue->Close() == S_OK);
|
||||
|
||||
CHECK(status->GetResult(0) == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF));
|
||||
CHECK(status->GetResult(1) == S_OK);
|
||||
CHECK(queue->RetrieveErrorRecord(&error) == S_OK);
|
||||
CHECK(error.failure_count == 2 && error.first_error == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF));
|
||||
CHECK(queue->RetrieveErrorRecord(&error) == S_OK && error.failure_count == 0);
|
||||
CHECK(queue->EnqueueRequest(©) == HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE));
|
||||
QueueInfo info{};
|
||||
CHECK(queue->Query(&info) == S_OK && info.capacity == 5 && info.available == 5);
|
||||
|
||||
std::puts("test_xcrdapi: passed");
|
||||
}
|
||||
Reference in new issue
Block a user