2
0

win32_linker.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright (C) 2023, Greg Manning <gmanning@rapitasystems.com>
  3. *
  4. * This hook, __pfnDliFailureHook2, is documented in the microsoft documentation here:
  5. * https://learn.microsoft.com/en-us/cpp/build/reference/error-handling-and-notification
  6. * It gets called when a delay-loaded DLL encounters various errors.
  7. * We handle the specific case of a DLL looking for a "qemu.exe",
  8. * and give it the running executable (regardless of what it is named).
  9. *
  10. * This work is licensed under the terms of the GNU LGPL, version 2 or later.
  11. * See the COPYING.LIB file in the top-level directory.
  12. */
  13. #include <windows.h>
  14. #include <delayimp.h>
  15. FARPROC WINAPI dll_failure_hook(unsigned dliNotify, PDelayLoadInfo pdli);
  16. PfnDliHook __pfnDliFailureHook2 = dll_failure_hook;
  17. FARPROC WINAPI dll_failure_hook(unsigned dliNotify, PDelayLoadInfo pdli) {
  18. if (dliNotify == dliFailLoadLib) {
  19. /* If the failing request was for qemu.exe, ... */
  20. if (strcmp(pdli->szDll, "qemu.exe") == 0) {
  21. /* Then pass back a pointer to the top level module. */
  22. HMODULE top = GetModuleHandle(NULL);
  23. return (FARPROC) top;
  24. }
  25. }
  26. /* Otherwise we can't do anything special. */
  27. return 0;
  28. }