Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. All rights reserved
  4. Module Name:
  5. dload.c
  6. Abstract:
  7. Handles delay load of the router, spoolss.dll
  8. Author:
  9. Steve Kiraly (SteveKi) 26-Oct-2000
  10. Environment:
  11. User Mode -Win32
  12. Revision History:
  13. --*/
  14. #include <windows.h>
  15. #include <rpc.h>
  16. #include <winspool.h>
  17. #include <offsets.h>
  18. #include <delayimp.h>
  19. #include "server.h"
  20. #include "winspl.h"
  21. #include "dload.h"
  22. PfnDliHook __pfnDliFailureHook = DelayLoadFailureHook;
  23. FARPROC
  24. LookupHandler(
  25. IN PDelayLoadInfo pDelayInfo
  26. )
  27. /*++
  28. Routine Description:
  29. This routine handle finding a delay load handler when a delay load library error
  30. occurrs. Currently this routine only handles failures for delay loading the router.
  31. The router is delay loaded for boot performance issues. When the router cannot be loaded
  32. it is fatal. Currently we simply terminate the process, it would be better to log an
  33. event prior to terminating but this would require event logging code which we only have in
  34. localspl.dll In the future we should build event logging code for all components. Server,
  35. router, and all print providers.
  36. Arguments:
  37. pDelayInfo - pointer to delay load information, i.e. dll name
  38. procedure name etc.
  39. Return Value:
  40. NULL procedure address
  41. Note:
  42. --*/
  43. {
  44. //
  45. // If the router cannot be loaded or a procedure address cannot be found then
  46. // terminate not much else can be done, the router is a critical comonent of the
  47. // spooler process it must be available.
  48. //
  49. if (!_stricmp(pDelayInfo->szDll, "spoolss.dll"))
  50. {
  51. #if DBG
  52. OutputDebugString(L"Delay load module or address not found in spoolss.dll.\n");
  53. DebugBreak();
  54. #endif
  55. ExitProcess(-1);
  56. }
  57. return NULL;
  58. }
  59. FARPROC
  60. WINAPI
  61. DelayLoadFailureHook(
  62. IN UINT unReason,
  63. IN PDelayLoadInfo pDelayInfo
  64. )
  65. /*++
  66. Routine Description:
  67. Called when a delay loaded library or procedure address fails.
  68. Arguments:
  69. unReason - reason for delay load failure
  70. pDelayInfo - pointer to delay load failure information
  71. Return Value:
  72. The procedure or module handle
  73. Note:
  74. --*/
  75. {
  76. FARPROC ReturnValue = NULL;
  77. switch(unReason)
  78. {
  79. //
  80. // For a failed LoadLibrary, we will return the HINSTANCE of this module.
  81. // This will cause the loader to try a GetProcAddress in this module for the
  82. // function. This will subsequently fail and then we will be called
  83. // for dliFailGetProc below.
  84. //
  85. case dliFailLoadLib:
  86. ReturnValue = (FARPROC)GetModuleHandle(NULL);
  87. break;
  88. //
  89. // Try to find an error handler for this DLL/procedure.
  90. //
  91. case dliFailGetProc:
  92. ReturnValue = LookupHandler(pDelayInfo);
  93. break;
  94. //
  95. // Unknown reason failure.
  96. //
  97. default:
  98. break;
  99. }
  100. return ReturnValue;
  101. }