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.

93 lines
1.7 KiB

  1. #if !defined(FUSION_INC_FUSIONLASTWIN32ERROR_H_INCLUDED_)
  2. #define FUSION_INC_FUSIONLASTWIN32ERROR_H_INCLUDED_
  3. #pragma once
  4. #include <nt.h>
  5. #include <ntrtl.h>
  6. #include <nturtl.h>
  7. #include <windows.h>
  8. #if defined(_M_IX86) && defined(FUSION_WIN)
  9. inline DWORD FusionpGetLastWin32Error(void)
  10. /* This works fine. */
  11. {
  12. __asm
  13. {
  14. mov eax, fs:[0] _TEB.LastErrorValue
  15. }
  16. }
  17. inline void FusionpGetLastWin32Error(
  18. DWORD *pdwLastError
  19. )
  20. {
  21. *pdwLastError = ::FusionpGetLastWin32Error();
  22. }
  23. /* This works pretty ok. */
  24. __forceinline VOID FusionpSetLastWin32Error(DWORD dw)
  25. {
  26. NtCurrentTeb()->LastErrorValue = dw;
  27. }
  28. __forceinline void FusionpClearLastWin32Error(void)
  29. {
  30. if (::FusionpGetLastWin32Error() != NO_ERROR)
  31. {
  32. __asm
  33. {
  34. mov fs:[0] _TEB.LastErrorValue, 0
  35. }
  36. }
  37. }
  38. inline void FusionpRtlPopFrame(PTEB_ACTIVE_FRAME Frame)
  39. {
  40. NtCurrentTeb()->ActiveFrame = Frame->Previous;
  41. }
  42. inline void FusionpRtlPushFrame(PTEB_ACTIVE_FRAME Frame)
  43. {
  44. const PTEB Teb = NtCurrentTeb();
  45. Frame->Previous = Teb->ActiveFrame;
  46. Teb->ActiveFrame = Frame;
  47. }
  48. #else
  49. inline DWORD FusionpGetLastWin32Error(void)
  50. {
  51. return ::GetLastError();
  52. }
  53. inline void FusionpGetLastWin32Error(
  54. DWORD *pdwLastError
  55. )
  56. {
  57. *pdwLastError = ::GetLastError();
  58. }
  59. inline VOID FusionpSetLastWin32Error(DWORD dw)
  60. {
  61. ::SetLastError(dw);
  62. }
  63. inline void FusionpClearLastWin32Error(void)
  64. {
  65. ::SetLastError(ERROR_SUCCESS);
  66. }
  67. inline void FusionpRtlPopFrame(PTEB_ACTIVE_FRAME Frame)
  68. {
  69. ::RtlPopFrame(Frame);
  70. }
  71. inline void FusionpRtlPushFrame(PTEB_ACTIVE_FRAME Frame)
  72. {
  73. ::RtlPushFrame(Frame);
  74. }
  75. #endif
  76. #endif