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.

142 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. Except.h
  5. Abstract:
  6. This module prototypes the macros and routines used for exception handling.
  7. Author:
  8. Joe Linn [JoeLinn] 24-aug-1994
  9. Revision History:
  10. --*/
  11. #ifndef _EXCEPTION_STUFF_DEFINED_
  12. #define _EXCEPTION_STUFF_DEFINED_
  13. //
  14. // The following two macro are used by the Fsd/Fsp exception handlers to
  15. // process an exception. The first macro is the exception filter used in the
  16. // Fsd/Fsp to decide if an exception should be handled at this level.
  17. // The second macro decides if the exception is to be finished off by
  18. // completing the IRP, and cleaning up the Irp Context, or if we should
  19. // bugcheck. Exception values such as RxStatus(FILE_INVALID) (raised by
  20. // VerfySup.c) cause us to complete the Irp and cleanup, while exceptions
  21. // such as accvio cause us to bugcheck.
  22. //
  23. // The basic structure for fsd/fsp exception handling is as follows:
  24. //
  25. // RxFsdXxx(...)
  26. // {
  27. // try {
  28. //
  29. // ...
  30. //
  31. // } except(RxExceptionFilter( RxContext, GetExceptionCode() )) {
  32. //
  33. // Status = RxProcessException( RxContext, GetExceptionCode() );
  34. // }
  35. //
  36. // Return Status;
  37. // }
  38. //
  39. // To explicitly raise an exception that we expect, such as
  40. // RxStatus(FILE_INVALID), use the below macro RxRaiseStatus(). To raise a
  41. // status from an unknown origin (such as CcFlushCache()), use the macro
  42. // RxNormalizeAndRaiseStatus. This will raise the status if it is expected,
  43. // or raise RxStatus(UNEXPECTED_IO_ERROR) if it is not.
  44. //
  45. // Note that when using these two macros, the original status is placed in
  46. // RxContext->ExceptionStatus, signaling RxExceptionFilter and
  47. // RxProcessException that the status we actually raise is by definition
  48. // expected.
  49. //
  50. LONG
  51. RxExceptionFilter (
  52. IN PRX_CONTEXT RxContext,
  53. IN PEXCEPTION_POINTERS ExceptionPointer
  54. );
  55. NTSTATUS
  56. RxProcessException (
  57. IN PRX_CONTEXT RxContext,
  58. IN NTSTATUS ExceptionCode
  59. );
  60. #define CATCH_EXPECTED_EXCEPTIONS (FsRtlIsNtstatusExpected(GetExceptionCode()) ? \
  61. EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH )
  62. //
  63. // VOID
  64. // RxRaiseStatus (
  65. // IN PRIP_CONTEXT RxContext,
  66. // IN NT_STATUS Status
  67. // );
  68. //
  69. //
  70. #define RxRaiseStatus(RXCONTEXT,STATUS) { \
  71. ASSERT((RXCONTEXT)!=NULL); \
  72. if (RxContext!=NULL) {(RXCONTEXT)->StoredStatus = (STATUS); } \
  73. ExRaiseStatus( (STATUS) ); \
  74. }
  75. //
  76. // VOID
  77. // RxNormalAndRaiseStatus (
  78. // IN PRIP_CONTEXT RxContext,
  79. // IN NT_STATUS Status
  80. // );
  81. //
  82. #define RxNormalizeAndRaiseStatus(RXCONTEXT,STATUS) { \
  83. ASSERT((RXCONTEXT)!=NULL); \
  84. if (RxContext!=NULL) {(RXCONTEXT)->StoredStatus = (STATUS); } \
  85. if ((STATUS) == (STATUS_VERIFY_REQUIRED)) { ExRaiseStatus((STATUS)); } \
  86. ExRaiseStatus(FsRtlNormalizeNtstatus((STATUS),(STATUS_UNEXPECTED_IO_ERROR))); \
  87. }
  88. //
  89. // The following macros are used to establish the semantics needed
  90. // to do a return from within a try-finally clause. As a rule every
  91. // try clause must end with a label call try_exit. For example,
  92. //
  93. // try {
  94. // :
  95. // :
  96. //
  97. // try_exit: NOTHING;
  98. // } finally {
  99. //
  100. // :
  101. // :
  102. // }
  103. //
  104. // Every return statement executed inside of a try clause should use the
  105. // try_return macro. If the compiler fully supports the try-finally construct
  106. // then the macro should be
  107. //
  108. // #define try_return(S) { return(S); }
  109. //
  110. // If the compiler does not support the try-finally construct then the macro
  111. // should be
  112. //
  113. // #define try_return(S) { S; goto try_exit; }
  114. //
  115. #define try_return(S) { S; goto try_exit; }
  116. #endif // _EXCEPTION_STUFF_DEFINED_
  117.