Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on boot when proxying D3D12.dll #1

Open
techiew opened this issue Jul 3, 2023 · 0 comments
Open

Crash on boot when proxying D3D12.dll #1

techiew opened this issue Jul 3, 2023 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@techiew
Copy link
Owner

techiew commented Jul 3, 2023

Not sure why this happens. I've noticed some weird behavior with D3D12 though. Here is an extremely simple example D3D12 proxy DLL which illustrates said weird behavior:

#include <Windows.h>
 
FARPROC p[3];
void* pp = &p[0];
 
extern "C" {
    void RunAsm();
    HMODULE originalDll = 0;
    FARPROC funcAddr = NULL;
    
    // This works. Using individual FARPROC variables also works.
    void Proxy_D3D12CreateDevice() { funcAddr = *((FARPROC*)pp + 0); RunAsm(); }
    void Proxy_D3D12GetDebugInterface() { funcAddr = *((FARPROC*)pp + 1); RunAsm(); }
    void Proxy_D3D12SerializeRootSignature() { funcAddr = *((FARPROC*)pp + 2); RunAsm(); }
 
    // Declaring the functions like this does not work and causes an instant crash, seems to be unique to proxying D3D12...
    // No popups when crashing, crash cause is an access violation when checking with debugger
    // Game in question only imports these 3 functions, proxying everything does not make a difference.
    void Proxy_D3D12CreateDevice() { funcAddr = p[0]; RunAsm(); }
    void Proxy_D3D12GetDebugInterface() { funcAddr = p[1]; RunAsm(); }
    void Proxy_D3D12SerializeRootSignature() { funcAddr = p[2]; RunAsm(); }
}
 
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
    if (ul_reason_for_call == DLL_PROCESS_ATTACH)
    {
        originalDll = LoadLibraryEx(L".\\d3d12.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
        p[0] = GetProcAddress(originalDll, "D3D12CreateDevice");
        p[1] = GetProcAddress(originalDll, "D3D12GetDebugInterface");
        p[2] = GetProcAddress(originalDll, "D3D12SerializeRootSignature");
    }
    return TRUE;
}

This weird behavior may or may not be related to the crashing.

@techiew techiew added help wanted Extra attention is needed good first issue Good for newcomers and removed good first issue Good for newcomers labels Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant