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.

245 lines
6.0 KiB

  1. /*++
  2. Copyright (C) 2000 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. lderror.cxx
  6. Abstract:
  7. This file contains the methods and class implementation
  8. necessary for the RPC surrogate used to load 64 bit dlls from
  9. within 32 bit apps.
  10. Author:
  11. Khaled Sedky (khaleds) 18-Jan-2000
  12. Revision History:
  13. --*/
  14. #define NOMINMAX
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #ifndef __LDERROR_HPP__
  20. #include "lderror.hpp"
  21. #endif
  22. LONG ErrorMap[] = {
  23. STATUS_INVALID_PARAMETER, ERROR_INVALID_PARAMETER,
  24. STATUS_INVALID_PORT_ATTRIBUTES, ERROR_INVALID_PARAMETER,
  25. STATUS_OBJECT_PATH_INVALID, ERROR_BAD_PATHNAME,
  26. STATUS_OBJECT_PATH_NOT_FOUND, ERROR_PATH_NOT_FOUND,
  27. STATUS_OBJECT_PATH_SYNTAX_BAD, ERROR_BAD_PATHNAME,
  28. STATUS_OBJECT_NAME_INVALID, ERROR_INVALID_NAME,
  29. STATUS_OBJECT_NAME_COLLISION, ERROR_ALREADY_EXISTS,
  30. STATUS_NO_MEMORY, ERROR_NOT_ENOUGH_MEMORY
  31. };
  32. /*++
  33. Function Name:
  34. TLd64BitDllsErrorHndlr :: TLd64BitDllsErrorHndlr
  35. Description:
  36. Constructor of Error Handler object.
  37. Parameters:
  38. None
  39. Return Value:
  40. None
  41. --*/
  42. TLd64BitDllsErrorHndlr ::
  43. TLd64BitDllsErrorHndlr(
  44. VOID
  45. )
  46. {
  47. }
  48. /*++
  49. Function Name:
  50. TLd64BitDllsErrorHndlr :: ~TLd64BitDllsErrorHndlr
  51. Description:
  52. Destructor of Error Handler object.
  53. Parameters:
  54. None
  55. Return Value:
  56. None
  57. --*/
  58. TLd64BitDllsErrorHndlr ::
  59. ~TLd64BitDllsErrorHndlr(
  60. VOID
  61. )
  62. {
  63. }
  64. /*++
  65. Function Name:
  66. TLd64BitDllsErrorHndlr :: GetLastErrorAsHRESULT
  67. Description:
  68. Converts GetLastError to HRESULT.
  69. Parameters:
  70. None
  71. Return Value:
  72. HRESULT : LastError as HRESULT
  73. --*/
  74. HRESULT
  75. TLd64BitDllsErrorHndlr ::
  76. GetLastErrorAsHRESULT(
  77. VOID
  78. ) const
  79. {
  80. DWORD Error = GetLastError();
  81. return HRESULT_FROM_WIN32(Error);
  82. }
  83. /*++
  84. Function Name:
  85. TLd64BitDllsErrorHndlr :: GetLastErrorAsHRESULT
  86. Description:
  87. Converts Input Win32 Error Code to HRESULT.
  88. Parameters:
  89. DWORD : Win32 ErrorCode
  90. Return Value:
  91. HRESULT : Win32 ErrorCode as HRESULT
  92. --*/
  93. HRESULT
  94. TLd64BitDllsErrorHndlr ::
  95. GetLastErrorAsHRESULT(
  96. IN DWORD Error
  97. ) const
  98. {
  99. return HRESULT_FROM_WIN32(Error);
  100. }
  101. /*++
  102. Function Name:
  103. TLd64BitDllsErrorHndlr :: GetLastErrorFromHRESULT
  104. Description:
  105. Converts HRESULT to Win32 Error Code.
  106. Parameters:
  107. HRESULT : hResult Code
  108. Return Value:
  109. DWORD : hResult converted to Win32 ErrorCode
  110. --*/
  111. DWORD
  112. TLd64BitDllsErrorHndlr ::
  113. GetLastErrorFromHRESULT(
  114. IN HRESULT hRes
  115. ) const
  116. {
  117. return HRESULTTOWIN32(hRes);
  118. }
  119. /*++
  120. Function Name:
  121. TLd64BitDllsErrorHndlr :: TranslateExceptionCode
  122. Description:
  123. Filters Exception Codes
  124. Parameters:
  125. None
  126. Return Value:
  127. DWORD: Filtered Exception Code.
  128. --*/
  129. DWORD
  130. TLd64BitDllsErrorHndlr ::
  131. TranslateExceptionCode(
  132. IN DWORD ExceptionCode
  133. ) const
  134. {
  135. DWORD TranslatedException;
  136. switch (ExceptionCode)
  137. {
  138. case EXCEPTION_ACCESS_VIOLATION:
  139. case EXCEPTION_DATATYPE_MISALIGNMENT:
  140. case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
  141. case EXCEPTION_FLT_DENORMAL_OPERAND:
  142. case EXCEPTION_FLT_DIVIDE_BY_ZERO:
  143. case EXCEPTION_FLT_INEXACT_RESULT:
  144. case EXCEPTION_FLT_INVALID_OPERATION:
  145. case EXCEPTION_FLT_OVERFLOW:
  146. case EXCEPTION_FLT_STACK_CHECK:
  147. case EXCEPTION_FLT_UNDERFLOW:
  148. case EXCEPTION_INT_DIVIDE_BY_ZERO:
  149. case EXCEPTION_INT_OVERFLOW:
  150. case EXCEPTION_PRIV_INSTRUCTION:
  151. case ERROR_NOACCESS:
  152. case RPC_S_INVALID_BOUND:
  153. {
  154. TranslatedException = ERROR_INVALID_PARAMETER;
  155. break;
  156. }
  157. default:
  158. {
  159. TranslatedException = ExceptionCode;
  160. break;
  161. }
  162. }
  163. return TranslatedException;
  164. }
  165. /*++
  166. Function Name:
  167. TLd64BitDllsErrorHndlr :: MapNtStatusToWin32Error
  168. Description:
  169. Converts NtStatus results to Win32 Error Codes
  170. Parameters:
  171. NTSTATUS: NtStatus result
  172. Return Value:
  173. DWORD: Win32 Error Code.
  174. --*/
  175. DWORD
  176. TLd64BitDllsErrorHndlr ::
  177. MapNtStatusToWin32Error(
  178. IN NTSTATUS Status
  179. ) const
  180. {
  181. DWORD ErrorCode = ERROR_INVALID_PARAMETER;
  182. for (int cNumOfMapEntries = 0;
  183. cNumOfMapEntries < sizeof(ErrorMap) / sizeof(ErrorMap[0]);
  184. cNumOfMapEntries += 2)
  185. {
  186. if (ErrorMap[cNumOfMapEntries] == Status)
  187. {
  188. ErrorCode = ErrorMap[cNumOfMapEntries+1];
  189. }
  190. }
  191. return ErrorCode;
  192. }