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.

146 lines
2.6 KiB

  1. // from base\ntos\rtl\error.c
  2. // should be gotten from a static .lib
  3. /*++
  4. Copyright (c) 1991 Microsoft Corporation
  5. Module Name:
  6. error.c
  7. Abstract:
  8. This module contains a routine for converting NT status codes
  9. to DOS/OS|2 error codes.
  10. Author:
  11. David Treadwell (davidtr) 04-Apr-1991
  12. Revision History:
  13. --*/
  14. #include "spprecmp.h"
  15. #define _NTOS_ /* prevent #including ntos.h, only use functions exports from ntdll/ntoskrnl */
  16. #include "nt.h"
  17. #include "ntrtl.h"
  18. #include "nturtl.h"
  19. #include "winerror.h"
  20. #if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
  21. #pragma alloc_text(PAGE, RtlGetLastNtStatus)
  22. #pragma alloc_text(PAGE, RtlGetLastWin32Error)
  23. #pragma alloc_text(PAGE, RtlNtStatusToDosError)
  24. #pragma alloc_text(PAGE, RtlRestoreLastWin32Error)
  25. #pragma alloc_text(PAGE, RtlSetLastWin32Error)
  26. #pragma alloc_text(PAGE, RtlSetLastWin32ErrorAndNtStatusFromNtStatus)
  27. #endif
  28. //
  29. // Ensure that the Registry ERROR_SUCCESS error code and the
  30. // NO_ERROR error code remain equal and zero.
  31. //
  32. #if ERROR_SUCCESS != 0 || NO_ERROR != 0
  33. #error Invalid value for ERROR_SUCCESS.
  34. #endif
  35. NTSYSAPI
  36. ULONG
  37. RtlNtStatusToDosError (
  38. IN NTSTATUS Status
  39. )
  40. /*++
  41. Routine Description:
  42. This routine converts an NT status code to its DOS/OS|2 equivalent.
  43. Remembers the Status code value in the TEB.
  44. Arguments:
  45. Status - Supplies the status value to convert.
  46. Return Value:
  47. The matching DOS/OS|2 error code.
  48. --*/
  49. {
  50. PTEB Teb;
  51. Teb = NtCurrentTeb();
  52. if (Teb) {
  53. try {
  54. Teb->LastStatusValue = Status;
  55. } except (EXCEPTION_EXECUTE_HANDLER) {
  56. }
  57. }
  58. return RtlNtStatusToDosErrorNoTeb( Status );
  59. }
  60. NTSYSAPI
  61. NTSTATUS
  62. NTAPI
  63. RtlGetLastNtStatus(
  64. VOID
  65. )
  66. {
  67. return NtCurrentTeb()->LastStatusValue;
  68. }
  69. NTSYSAPI
  70. LONG
  71. NTAPI
  72. RtlGetLastWin32Error(
  73. VOID
  74. )
  75. {
  76. return NtCurrentTeb()->LastErrorValue;
  77. }
  78. NTSYSAPI
  79. VOID
  80. NTAPI
  81. RtlSetLastWin32ErrorAndNtStatusFromNtStatus(
  82. NTSTATUS Status
  83. )
  84. {
  85. //
  86. // RtlNtStatusToDosError stores into NtCurrentTeb()->LastStatusValue.
  87. //
  88. RtlSetLastWin32Error(RtlNtStatusToDosError(Status));
  89. }
  90. NTSYSAPI
  91. VOID
  92. NTAPI
  93. RtlSetLastWin32Error(
  94. LONG Win32Error
  95. )
  96. {
  97. //
  98. // Arguably this should clear or reset the last nt status, but it does not
  99. // touch it.
  100. //
  101. NtCurrentTeb()->LastErrorValue = Win32Error;
  102. }
  103. NTSYSAPI
  104. VOID
  105. NTAPI
  106. RtlRestoreLastWin32Error(
  107. LONG Win32Error
  108. )
  109. {
  110. #if DBG
  111. if ((LONG)NtCurrentTeb()->LastErrorValue != Win32Error)
  112. #endif
  113. NtCurrentTeb()->LastErrorValue = Win32Error;
  114. }