Leaked source code of windows server 2003
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.

134 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 "precomp.h"
  15. #include "server.h"
  16. #include "dload.h"
  17. PfnDliHook __pfnDliFailureHook = DelayLoadFailureHook;
  18. FARPROC
  19. LookupHandler(
  20. IN PDelayLoadInfo pDelayInfo
  21. )
  22. /*++
  23. Routine Description:
  24. This routine handle finding a delay load handler when a delay load library error
  25. occurrs. Currently this routine only handles failures for delay loading the router.
  26. The router is delay loaded for boot performance issues. When the router cannot be loaded
  27. it is fatal. Currently we simply terminate the process, it would be better to log an
  28. event prior to terminating but this would require event logging code which we only have in
  29. localspl.dll In the future we should build event logging code for all components. Server,
  30. router, and all print providers.
  31. Arguments:
  32. pDelayInfo - pointer to delay load information, i.e. dll name
  33. procedure name etc.
  34. Return Value:
  35. NULL procedure address
  36. Note:
  37. --*/
  38. {
  39. //
  40. // If the router cannot be loaded or a procedure address cannot be found then
  41. // terminate not much else can be done, the router is a critical comonent of the
  42. // spooler process it must be available.
  43. //
  44. if (!_stricmp(pDelayInfo->szDll, "spoolss.dll"))
  45. {
  46. DBGMSG(DBG_WARN, ("Delay load module or address not found in spoolss.dll.\n"));
  47. ExitProcess(-1);
  48. }
  49. return NULL;
  50. }
  51. FARPROC
  52. WINAPI
  53. DelayLoadFailureHook(
  54. IN UINT unReason,
  55. IN PDelayLoadInfo pDelayInfo
  56. )
  57. /*++
  58. Routine Description:
  59. Called when a delay loaded library or procedure address fails.
  60. Arguments:
  61. unReason - reason for delay load failure
  62. pDelayInfo - pointer to delay load failure information
  63. Return Value:
  64. The procedure or module handle
  65. Note:
  66. --*/
  67. {
  68. FARPROC ReturnValue = NULL;
  69. switch(unReason)
  70. {
  71. //
  72. // For a failed LoadLibrary, we will return the HINSTANCE of this module.
  73. // This will cause the loader to try a GetProcAddress in this module for the
  74. // function. This will subsequently fail and then we will be called
  75. // for dliFailGetProc below.
  76. //
  77. case dliFailLoadLib:
  78. ReturnValue = (FARPROC)GetModuleHandle(NULL);
  79. break;
  80. //
  81. // Try to find an error handler for this DLL/procedure.
  82. //
  83. case dliFailGetProc:
  84. ReturnValue = LookupHandler(pDelayInfo);
  85. break;
  86. //
  87. // Unknown reason failure.
  88. //
  89. default:
  90. break;
  91. }
  92. return ReturnValue;
  93. }