Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

phase-1 work: P1.3 caller-name IAT shim with 8 boundary tests passing

Veyra Goal Agent8d0d07d3a6e5
diff --git a/include/veyra/ngx/DlssNrRuntimeAdapter.h b/include/veyra/ngx/DlssNrRuntimeAdapter.h
index 556d360e..56d4a7d6 100644
--- a/include/veyra/ngx/DlssNrRuntimeAdapter.h
+++ b/include/veyra/ngx/DlssNrRuntimeAdapter.h
@@ -78,6 +78,11 @@ public:
HMODULE module() const { return module_; }
const std::wstring& dllPath() const { return dllPath_; }
+ // Test hooks for the --shim-test battery (P1.3). Callers must install the
+ // shim first; the hooks invoke the installed shim function directly.
+ static DWORD WINAPI testShimGetModuleFileNameW(HMODULE module, LPWSTR filename, DWORD size);
+ static HMODULE testCallerModule();
+
private:
HMODULE module_ = nullptr;
Exports exports_{};
diff --git a/loop/BACKLOG.md b/loop/BACKLOG.md
index 8fac96cb..0da3c137 100644
--- a/loop/BACKLOG.md
+++ b/loop/BACKLOG.md
@@ -21,7 +21,7 @@ Phase 0 gate:以 Playbook 第 16 节 Phase 0 为准。未完成 P0.9 禁止开
- [x] P1.0a(Reviewer P2 加固项,不降低任何门槛): 在接入 Evaluate 循环前把 ID3D12Fence 时间线计数器收敛为单一 owner(ring 从 device context 派生 fence 值或明确所有权注释),避免 Phase 1 起重复/非单调 fence 值。(2026-09-02:移除 context 冗余计数器,ring 为唯一 signaler,双 preset+device-info 回归通过。)
- [x] P1.1 先建立 phase1 gate 和确定性 RGBA8 测试帧/输出统计。(2026-09-02:phase1.ps1 fail-closed 建立并负向验证 exit 1;JSON 契约含输出统计/变体 hash/防陈旧字段;nr-default.json 就位;NGX SDK 310.7 已 staging。)
- [x] P1.2 封装 NGX Core、parameter block、DLSSNR runtime 和严格逆序 RAII。(2026-09-02:Init_with_ProjectID result=0x1 真实成功;exports 5/5;逆序释放干净;harness --load-only 双配置 PASS。)
-- [ ] P1.3 实现受隔离、可关闭的 caller-name 兼容层;禁止 patch DLL。
+- [x] P1.3 实现受隔离、可关闭的 caller-name 兼容层;禁止 patch DLL。(2026-09-02:IAT 单 owner shim + 8 项边界测试全过;DLL 文件从未被修改。)
- [ ] P1.4 严格按 Playbook 参数名与类型 Create Feature 18。
- [ ] P1.5 实现 Proxy→Feature18→Raw 的 D3D12 资源、barrier、subrect 与异步 4-slot 执行。
- [ ] P1.6 连续 300/300 Evaluate;验证输出非黑、非恒定、随输入/参数变化;记录 GPU timings/result/capture。
diff --git a/loop/JOURNAL.md b/loop/JOURNAL.md
index 43ff8605..ffc1043b 100644
--- a/loop/JOURNAL.md
+++ b/loop/JOURNAL.md
@@ -354,6 +354,29 @@ Result:
---
+## Cycle 013 — P1.3 caller-name 兼容层与边界测试
+
+### Before
+
+- Phase: 1
+- 唯一任务: 实现 DlssNrRuntimeAdapter 的隔离兼容层:解析已加载 snippet 的 PE import 表定位 KERNEL32/API-set 的 GetModuleFileNameW IAT slot(全局单 owner)→ VirtualProtect+InterlockedExchangePointer 安装 shim(仅对本 caller module 返回字面量 L"nvngx.dll",完整模拟 buffer/return/error 语义;其余全部转发原函数)→ 恢复并 FlushInstructionCache;harness 增加 --shim-test 六项边界测试(nSize==0 / 过小 / 恰好 10 wchar / 正常 / nullptr module / 非 caller module,含 sentinel last-error)。
+- 可证伪假设: 若 IAT 定位失败、shim 语义错误或恢复不完整,--shim-test 非零退出。
+- 预计修改文件: src/ngx/DlssNrRuntimeAdapter.cpp、include/veyra/ngx/DlssNrRuntimeAdapter.h、tools/nr_harness/main.cpp。
+- 快速检查命令: `build.ps1 -Preset x64-debug` → 0;`veyra_nr_harness.exe --shim-test --runtime-dir <abs>` → 0(六项全过 + 恢复验证)。
+- 预期新增证据: IAT slot 地址、原指针、安装/恢复日志、六项边界测试结果。
+
+### After
+
+- 实际修改: src/ngx/DlssNrRuntimeAdapter.cpp(PE import 表解析 FindImportedFunctionSlot、SnippetGetModuleFileNameW shim、install/restore 单 owner 逻辑)、头文件 test hooks、tools/nr_harness/main.cpp(--shim-test)。
+- 实际命令与 exit code: `build.ps1 -Preset x64-debug` → 0;`--shim-test` Debug 与 Release 均 exit 0,8 项全 PASS。
+- 新证据/日志路径: 真实定位 snippet IAT slot=0x00007FF9091DC080,original=0x00007FF9DD79BC00(KERNEL32);shim-test[PASS] ×8:caller-module-resolved(0x7FF6407D0000)、zero-size(ret=0、buffer 未动、lastError 保持 0x1234)、too-small-truncates(ret=5、"nvng"、lastError=0x7A=ERROR_INSUFFICIENT_BUFFER)、exact-10-wchars(ret=9、"nvngx.dll"、lastError 不变)、roomy-64、null-module-forwards(真实 exe 路径 85 字符)、other-module-forwards(KERNEL32.DLL)、restore-reported-clean + 卸载后"IAT slot restored to original function"。
+- 失败 fingerprint: 无。
+- 是否有进展,依据: 是——Playbook 8.3 的 10 步实现与全部边界语义经真实 snippet 验证;shim 只影响 snippet 自身 IAT、单 owner、可完全恢复、编译开关可整体移除(VEYRA_ENABLE_EXPERIMENTAL_DLSSNR)。
+- STATE/BACKLOG 更新: cycle.completed=13;BACKLOG P1.3 → DONE。
+- 下一唯一动作: P1.4 严格按 Playbook 8.5 参数名/类型实现 Create Feature 18(含 ScalingRatioCallback、全部 width/height 变体、node mask),并验证 handle 非空。
+
+---
+
复制下面模板开始每个新 cycle。必须先填 Before,再改代码;完成后填 After。
## Cycle NNN — 简短任务名
diff --git a/loop/STATE.json b/loop/STATE.json
index 0ff2c976..510de351 100644
--- a/loop/STATE.json
+++ b/loop/STATE.json
@@ -76,14 +76,14 @@
}
],
"cycle": {
- "completed": 12,
+ "completed": 13,
"maximum": 80,
"sameFailureAttempts": 0,
"maximumSameFailureAttempts": 3,
"noProgressCycles": 0,
"maximumNoProgressCycles": 5
},
- "currentTask": "P1.3: implement the isolated, removable caller-name compatibility layer (PE import walk -> GetModuleFileNameW IAT slot -> single-owner shim install/restore) with the six boundary tests from Playbook 8.3.",
+ "currentTask": "P1.4: create Feature 18 through the signed snippet with the exact Playbook 8.5 parameter names and types (all width/height variants, callback, node masks) and a non-null handle.",
"lastGate": {
"name": "phase0",
"status": "passed",
@@ -96,6 +96,6 @@
"lastGoodCommit": "1fb7afa5779a6c6a0a585d4ecf18a640260a2fcf",
"openP0P1Findings": [],
"blockers": [],
- "nextAction": "Implement P1.3 IAT caller shim + boundary tests, then P1.4 Feature 18 Create, P1.5 frame loop, P1.6 300 evaluates.",
- "updatedAt": "2026-09-02T22:10:00+08:00"
+ "nextAction": "Implement P1.4 Feature 18 Create (Playbook 8.4/8.5 order: core init -> load -> shim -> Init_Ext -> params -> CreateFeature), then P1.5 frame loop.",
+ "updatedAt": "2026-09-02T22:25:00+08:00"
}
diff --git a/src/ngx/DlssNrRuntimeAdapter.cpp b/src/ngx/DlssNrRuntimeAdapter.cpp
index d538a61a..65c31739 100644
--- a/src/ngx/DlssNrRuntimeAdapter.cpp
+++ b/src/ngx/DlssNrRuntimeAdapter.cpp
@@ -19,8 +19,127 @@ constexpr const char* kExportNames[] = {
"NVSDK_NGX_D3D12_Shutdown1",
};
+// ---------------------------------------------------------------------------
+// Caller-name compatibility shim (Playbook 8.3). The signed snippet queries
+// the calling module's file name via GetModuleFileNameW; when asked about the
+// Veyra caller module it must observe the literal L"nvngx.dll". The shim is
+// installed on the snippet's own IAT slot only - never a global Kernel32
+// hook - and only one adapter session may own the slot.
+// ---------------------------------------------------------------------------
+using GetModuleFileNameWFn = DWORD(WINAPI*)(HMODULE, LPWSTR, DWORD);
+
+GetModuleFileNameWFn g_realGetModuleFileNameW = nullptr;
+HMODULE g_callerModule = nullptr;
+bool g_shimOwnerActive = false;
+
+// 9 characters + NUL, matching what the snippet expects to observe.
+constexpr wchar_t kShimModuleName[] = L"nvngx.dll";
+constexpr DWORD kShimModuleNameChars = 9;
+
+__declspec(noinline) DWORD WINAPI SnippetGetModuleFileNameW(HMODULE module, LPWSTR filename, DWORD size)
+{
+ if (g_callerModule == nullptr) {
+ // Resolve the Veyra caller module from this shim function's own
+ // address; never guess by executable file name.
+ HMODULE caller = nullptr;
+ if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ reinterpret_cast<LPCWSTR>(&SnippetGetModuleFileNameW), &caller) != FALSE) {
+ g_callerModule = caller;
+ }
+ }
+
+ if (module == g_callerModule) {
+ if (size == 0) {
+ // No buffer access, no last-error change, return 0.
+ return 0;
+ }
+ if (size <= kShimModuleNameChars) {
+ // Too small: copy size-1 characters, NUL at [size-1], return size
+ // and set ERROR_INSUFFICIENT_BUFFER (real API semantics).
+ for (DWORD i = 0; i + 1 < size; ++i) {
+ filename[i] = kShimModuleName[i];
+ }
+ filename[size - 1] = L'\0';
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ return size;
+ }
+ for (DWORD i = 0; i <= kShimModuleNameChars; ++i) {
+ filename[i] = kShimModuleName[i];
+ }
+ return kShimModuleNameChars;
+ }
+
+ // Everything else (nullptr, other modules) forwards to the saved real
+ // function pointer with untouched semantics.
+ if (g_realGetModuleFileNameW == nullptr) {
+ SetLastError(ERROR_INVALID_FUNCTION);
+ return 0;
+ }
+ return g_realGetModuleFileNameW(module, filename, size);
+}
+
+// Walks the in-memory PE import table of `module` and returns the IAT slot
+// (address of the thunk function pointer) importing `functionName` from a
+// KERNEL32 or API-set DLL. Returns nullptr when no such import exists.
+void** FindImportedFunctionSlot(HMODULE module, const char* functionName)
+{
+ auto* base = reinterpret_cast<uint8_t*>(module);
+ const auto* dos = reinterpret_cast<const IMAGE_DOS_HEADER*>(base);
+ if (dos->e_magic != IMAGE_DOS_SIGNATURE) {
+ return nullptr;
+ }
+ const auto* nt = reinterpret_cast<const IMAGE_NT_HEADERS*>(base + dos->e_lfanew);
+ if (nt->Signature != IMAGE_NT_SIGNATURE) {
+ return nullptr;
+ }
+ const IMAGE_DATA_DIRECTORY& directory = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
+ if (directory.VirtualAddress == 0) {
+ return nullptr;
+ }
+
+ const auto* descriptor = reinterpret_cast<const IMAGE_IMPORT_DESCRIPTOR*>(base + directory.VirtualAddress);
+ for (; descriptor->Name != 0; ++descriptor) {
+ const char* dllName = reinterpret_cast<const char*>(base + descriptor->Name);
+ const bool isKernel32 = _stricmp(dllName, "kernel32.dll") == 0;
+ const bool isApiSet = _strnicmp(dllName, "api-ms-", 7) == 0 || _strnicmp(dllName, "ext-ms-", 7) == 0;
+ if (!isKernel32 && !isApiSet) {
+ continue;
+ }
+
+ const ULONGLONG lookupRva = descriptor->OriginalFirstThunk != 0 ? descriptor->OriginalFirstThunk : descriptor->FirstThunk;
+ if (lookupRva == 0) {
+ continue;
+ }
+ const auto* lookup = reinterpret_cast<const ULONGLONG*>(base + lookupRva);
+ auto* iat = reinterpret_cast<IMAGE_THUNK_DATA*>(base + descriptor->FirstThunk);
+ for (size_t i = 0; lookup[i] != 0; ++i) {
+ if (IMAGE_SNAP_BY_ORDINAL64(lookup[i])) {
+ continue;
+ }
+ const auto* byName = reinterpret_cast<const IMAGE_IMPORT_BY_NAME*>(base + static_cast<size_t>(lookup[i]));
+ if (strcmp(reinterpret_cast<const char*>(byName->Name), functionName) == 0) {
+ return reinterpret_cast<void**>(&iat[i].u1.Function);
+ }
+ }
+ }
+ return nullptr;
+}
+
} // namespace
+DWORD WINAPI DlssNrRuntimeAdapter::testShimGetModuleFileNameW(HMODULE module, LPWSTR filename, DWORD size)
+{
+ return SnippetGetModuleFileNameW(module, filename, size);
+}
+
+HMODULE DlssNrRuntimeAdapter::testCallerModule()
+{
+ if (g_callerModule == nullptr) {
+ (void)SnippetGetModuleFileNameW(nullptr, nullptr, 0); // force lazy resolution
+ }
+ return g_callerModule;
+}
+
DlssNrRuntimeAdapter::~DlssNrRuntimeAdapter()
{
unload();
@@ -84,15 +203,94 @@ bool DlssNrRuntimeAdapter::load(const std::wstring& runtimeDir, Status& status)
bool DlssNrRuntimeAdapter::installCallerCompatibility(Status& status)
{
- // Implemented in P1.3 together with its boundary test battery.
- (void)status;
- veyra::log::error("ngx", "nr-adapter: caller compatibility shim not implemented yet (P1.3)");
- return false;
+ if (module_ == nullptr) {
+ status = Status::InvalidArgument;
+ veyra::log::error("ngx", "caller-compat: snippet not loaded");
+ return false;
+ }
+ if (shimInstalled_) {
+ status = Status::InvalidArgument;
+ veyra::log::error("ngx", "caller-compat: shim already installed by this session");
+ return false;
+ }
+ if (g_shimOwnerActive) {
+ status = Status::InvalidArgument;
+ veyra::log::error("ngx", "caller-compat: another adapter session already owns the IAT slot");
+ return false;
+ }
+
+ void** slot = FindImportedFunctionSlot(module_, "GetModuleFileNameW");
+ if (slot == nullptr) {
+ status = Status::MissingExport;
+ veyra::log::error("ngx", "caller-compat: no GetModuleFileNameW import slot found in snippet IAT; refusing wider hooks");
+ return false;
+ }
+
+ originalGetModuleFileNameW_ = *slot;
+ if (originalGetModuleFileNameW_ == nullptr) {
+ status = Status::MissingExport;
+ veyra::log::error("ngx", "caller-compat: IAT slot is null before install");
+ return false;
+ }
+
+ g_realGetModuleFileNameW = reinterpret_cast<GetModuleFileNameWFn>(originalGetModuleFileNameW_);
+ g_callerModule = nullptr;
+ g_shimOwnerActive = true;
+ iatSlot_ = slot;
+
+ DWORD oldProtect = 0;
+ if (VirtualProtect(slot, sizeof(void*), PAGE_READWRITE, &oldProtect) == FALSE) {
+ status = Status::DeviceFailure;
+ veyra::log::error("ngx", std::format("caller-compat: VirtualProtect failed lastError={}", GetLastError()));
+ g_shimOwnerActive = false;
+ iatSlot_ = nullptr;
+ return false;
+ }
+
+ InterlockedExchangePointer(slot, reinterpret_cast<void*>(&SnippetGetModuleFileNameW));
+
+ DWORD restoredProtect = 0;
+ if (VirtualProtect(slot, sizeof(void*), oldProtect, &restoredProtect) == FALSE) {
+ status = Status::DeviceFailure;
+ veyra::log::error("ngx", std::format("caller-compat: VirtualProtect restore failed lastError={}", GetLastError()));
+ }
+ FlushInstructionCache(GetCurrentProcess(), slot, sizeof(void*));
+
+ shimInstalled_ = true;
+ veyra::log::info("ngx", std::format("caller-compat: shim installed slot=0x{:016X} original=0x{:016X} (LOCAL EXPERIMENTAL ONLY)",
+ reinterpret_cast<uintptr_t>(iatSlot_), reinterpret_cast<uintptr_t>(originalGetModuleFileNameW_)));
+ return true;
}
void DlssNrRuntimeAdapter::restoreCallerCompatibility()
{
- // Nothing to restore until P1.3 installs the shim.
+ if (!shimInstalled_ || iatSlot_ == nullptr) {
+ return;
+ }
+
+ DWORD oldProtect = 0;
+ if (VirtualProtect(iatSlot_, sizeof(void*), PAGE_READWRITE, &oldProtect) != FALSE) {
+ InterlockedExchangePointer(iatSlot_, originalGetModuleFileNameW_);
+ DWORD restoredProtect = 0;
+ (void)VirtualProtect(iatSlot_, sizeof(void*), oldProtect, &restoredProtect);
+ FlushInstructionCache(GetCurrentProcess(), iatSlot_, sizeof(void*));
+ }
+
+ const bool restoredCorrectly = *iatSlot_ == originalGetModuleFileNameW_;
+ if (!restoredCorrectly) {
+ veyra::log::error("ngx", std::format("caller-compat: IAT slot not restored to original actual=0x{:016X} expected=0x{:016X}",
+ reinterpret_cast<uintptr_t>(*iatSlot_), reinterpret_cast<uintptr_t>(originalGetModuleFileNameW_)));
+ }
+ else {
+ veyra::log::info("ngx", "caller-compat: IAT slot restored to original function");
+ }
+
+ g_shimOwnerActive = false;
+ g_callerModule = nullptr;
+ g_realGetModuleFileNameW = nullptr;
+ iatSlot_ = nullptr;
+ originalGetModuleFileNameW_ = nullptr;
+ shimInstalled_ = false;
}
void DlssNrRuntimeAdapter::unload()
diff --git a/tools/nr_harness/main.cpp b/tools/nr_harness/main.cpp
index 00efb2ad..ef3630b6 100644
--- a/tools/nr_harness/main.cpp
+++ b/tools/nr_harness/main.cpp
@@ -89,6 +89,117 @@ bool loadLocalIdentity(const std::wstring& runtimeDir, LocalIdentity& identity)
return true;
}
+// P1.3 caller-compatibility boundary battery (Playbook 8.3). Runs against the
+// installed shim without needing a D3D12 device or NGX core session.
+int runShimTest(const std::wstring& runtimeDir)
+{
+ const std::wstring dllPath = runtimeDir + L"\\nvngx_dlssnr.dll";
+ veyra::FileIdentity dllIdentity{};
+ veyra::IdentityError dllError = veyra::IdentityError::None;
+ if (!veyra::computeFileIdentity(dllPath, dllIdentity, dllError) ||
+ dllIdentity.sizeBytes != kExpectedDllSize ||
+ dllIdentity.sha256Upper != kExpectedDllSha256) {
+ veyra::log::error("harness", "shim-test: staged runtime identity mismatch");
+ return 3;
+ }
+
+ veyra::ngx::DlssNrRuntimeAdapter adapter;
+ veyra::Status status = veyra::Status::Ok;
+ if (!adapter.load(runtimeDir, status)) {
+ veyra::log::error("harness", std::format("shim-test: adapter load failed status={}", veyra::statusString(status)));
+ return 9;
+ }
+ if (!adapter.installCallerCompatibility(status)) {
+ veyra::log::error("harness", std::format("shim-test: shim install failed status={}", veyra::statusString(status)));
+ adapter.unload();
+ return 10;
+ }
+
+ constexpr DWORD kSentinelError = 0x1234;
+ int failures = 0;
+ const auto check = [&failures](const char* name, bool ok, const std::string& detail) {
+ veyra::log::info("harness", std::format("shim-test[{}] {} {}", ok ? "PASS" : "FAIL", name, detail));
+ if (!ok) {
+ ++failures;
+ }
+ };
+
+ HMODULE caller = veyra::ngx::DlssNrRuntimeAdapter::testCallerModule();
+ check("caller-module-resolved", caller != nullptr, std::format("module=0x{:016X}", reinterpret_cast<uintptr_t>(caller)));
+
+ // 1. size == 0: return 0, buffer untouched, last-error unchanged.
+ {
+ wchar_t buffer[16]{};
+ wmemset(buffer, 0xABCD, 16);
+ SetLastError(kSentinelError);
+ const DWORD ret = veyra::ngx::DlssNrRuntimeAdapter::testShimGetModuleFileNameW(caller, buffer, 0);
+ check("zero-size", ret == 0 && buffer[0] == static_cast<wchar_t>(0xABCD) && GetLastError() == kSentinelError,
+ std::format("ret={} buffer0=0x{:04X} lastError=0x{:X}", ret, static_cast<unsigned>(buffer[0]), GetLastError()));
+ }
+
+ // 2. too-small buffer (size 5): truncate, NUL at [size-1], return size,
+ // last-error ERROR_INSUFFICIENT_BUFFER.
+ {
+ wchar_t buffer[8]{};
+ SetLastError(kSentinelError);
+ const DWORD ret = veyra::ngx::DlssNrRuntimeAdapter::testShimGetModuleFileNameW(caller, buffer, 5);
+ const bool ok = ret == 5 && wcsncmp(buffer, L"nvng", 4) == 0 && buffer[4] == L'\0' &&
+ GetLastError() == ERROR_INSUFFICIENT_BUFFER;
+ check("too-small-truncates", ok,
+ std::format("ret={} buffer={} lastError=0x{:X} expectedError=0x{:X}", ret, narrow(buffer), GetLastError(), ERROR_INSUFFICIENT_BUFFER));
+ }
+
+ // 3. exact fit (10 wchar = 9 chars + NUL): return 9, full name, no error change.
+ {
+ wchar_t buffer[16]{};
+ SetLastError(kSentinelError);
+ const DWORD ret = veyra::ngx::DlssNrRuntimeAdapter::testShimGetModuleFileNameW(caller, buffer, 10);
+ check("exact-10-wchars", ret == 9 && wcscmp(buffer, L"nvngx.dll") == 0 && GetLastError() == kSentinelError,
+ std::format("ret={} buffer={} lastError=0x{:X}", ret, narrow(buffer), GetLastError()));
+ }
+
+ // 4. roomy buffer (64): same as exact fit.
+ {
+ wchar_t buffer[64]{};
+ SetLastError(kSentinelError);
+ const DWORD ret = veyra::ngx::DlssNrRuntimeAdapter::testShimGetModuleFileNameW(caller, buffer, 64);
+ check("roomy-64", ret == 9 && wcscmp(buffer, L"nvngx.dll") == 0,
+ std::format("ret={} buffer={}", ret, narrow(buffer)));
+ }
+
+ // 5. nullptr module forwards to the real API (current executable path).
+ {
+ wchar_t buffer[MAX_PATH]{};
+ SetLastError(kSentinelError);
+ const DWORD ret = veyra::ngx::DlssNrRuntimeAdapter::testShimGetModuleFileNameW(nullptr, buffer, MAX_PATH);
+ check("null-module-forwards", ret > 0 && ret < MAX_PATH && wcscmp(buffer, L"nvngx.dll") != 0,
+ std::format("ret={} path={}", ret, narrow(buffer)));
+ }
+
+ // 6. non-caller module (kernel32) forwards to the real API.
+ {
+ wchar_t buffer[MAX_PATH]{};
+ const HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll");
+ const DWORD ret = veyra::ngx::DlssNrRuntimeAdapter::testShimGetModuleFileNameW(kernel32, buffer, MAX_PATH);
+ check("other-module-forwards", kernel32 != nullptr && ret > 0 && wcsstr(buffer, L"KERNEL32") != nullptr,
+ std::format("ret={} path={}", ret, narrow(buffer)));
+ }
+
+ // 7. restore must clear the installed flag (unload verifies the slot again).
+ adapter.restoreCallerCompatibility();
+ check("restore-reported-clean", !adapter.callerCompatibilityInstalled(), "flag cleared");
+
+ // Reverse teardown (unload restores the IAT again as defense in depth).
+ adapter.unload();
+
+ if (failures != 0) {
+ veyra::log::error("harness", std::format("shim-test: FAIL ({} failing checks)", failures));
+ return 11;
+ }
+ veyra::log::info("harness", "shim-test: PASS (all boundary checks)");
+ return 0;
+}
+
int runLoadOnly(const std::wstring& runtimeDir)
{
// 1. Device context (debug layer follows the build configuration).
@@ -164,11 +275,15 @@ int wmain(int argc, wchar_t** argv)
std::wstring runtimeDir;
std::wstring logFile;
bool loadOnly = false;
+ bool shimTest = false;
for (int i = 1; i < argc; ++i) {
const std::wstring arg = argv[i];
if (arg == L"--load-only") {
loadOnly = true;
}
+ else if (arg == L"--shim-test") {
+ shimTest = true;
+ }
else if (arg == L"--runtime-dir" && i + 1 < argc) {
runtimeDir = argv[++i];
}
@@ -182,11 +297,14 @@ int wmain(int argc, wchar_t** argv)
}
int exitCode = 0;
- if (loadOnly && !runtimeDir.empty()) {
+ if (shimTest && !runtimeDir.empty()) {
+ exitCode = runShimTest(runtimeDir);
+ }
+ else if (loadOnly && !runtimeDir.empty()) {
exitCode = runLoadOnly(runtimeDir);
}
else {
- veyra::log::info("harness", "no mode selected; use --load-only --runtime-dir <abs> (frame loop arrives in P1.4-P1.6)");
+ veyra::log::info("harness", "no mode selected; use --load-only/--shim-test --runtime-dir <abs> (frame loop arrives in P1.4-P1.6)");
exitCode = 1;
}