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.

76 lines
2.5 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. long handler(PEXCEPTION_POINTERS p, BOOLEAN bThrow, BOOLEAN bContinueExecution)
  5. {
  6. DbgPrint("In handler... record %x, context %x\n", p->ExceptionRecord, p->ContextRecord);
  7. if(bThrow) {
  8. DbgPrint("In handler... throwing an exception...\n");
  9. try {
  10. RtlRaiseStatus(STATUS_INVALID_PARAMETER);
  11. }
  12. except(handler(GetExceptionInformation(), FALSE, FALSE)) {
  13. DbgPrint("In handler... executed handler\n");
  14. }
  15. }
  16. if (bContinueExecution) {
  17. DbgPrint("In handler... returning EXCEPTION_CONTINUE_EXECUTION...\n");
  18. return EXCEPTION_CONTINUE_EXECUTION;
  19. }
  20. DbgPrint("In handler... returning EXCEPTION_EXECUTE_HANDLER...\n");
  21. return EXCEPTION_EXECUTE_HANDLER;
  22. }
  23. int main(int argc, char *argv[])
  24. {
  25. int *p;
  26. p = NULL;
  27. DbgPrint("In main... throwing an exception...\n");
  28. try {
  29. *p = 1;
  30. } except (handler(GetExceptionInformation(), FALSE, FALSE)) {
  31. DbgPrint("In main... executed handler\n");
  32. }
  33. DbgPrint("In main... back from exception...\n");
  34. DbgPrint("In main... throwing an exception with RtlRaiseStatus...\n");
  35. try {
  36. RtlRaiseStatus(STATUS_INVALID_PARAMETER);
  37. } except (handler(GetExceptionInformation(), FALSE, FALSE)) {
  38. DbgPrint("In main... executed handler\n");
  39. }
  40. DbgPrint("In main... back from exception...\n");
  41. DbgPrint("In main... throwing an exception with an exception in exception handler...\n");
  42. try {
  43. RtlRaiseStatus(STATUS_INVALID_PARAMETER);
  44. } except (handler(GetExceptionInformation(), TRUE, FALSE)) {
  45. DbgPrint("In main... executed handler\n");
  46. }
  47. DbgPrint("In main... back from exception...\n");
  48. DbgPrint("In main... trowing an exception structure that is continueable...\n");
  49. try {
  50. EXCEPTION_RECORD Record;
  51. RtlZeroMemory(&Record, sizeof(EXCEPTION_RECORD));
  52. Record.ExceptionCode = STATUS_INVALID_PARAMETER;
  53. Record.ExceptionRecord = (PEXCEPTION_RECORD)NULL;
  54. Record.NumberParameters = 0;
  55. Record.ExceptionFlags = 0;
  56. RtlRaiseException(&Record);
  57. DbgPrint("In main... Execution was continued!\n");
  58. } except (handler(GetExceptionInformation(), FALSE, TRUE)) {
  59. DbgPrint("In main... executed handler\n");
  60. }
  61. DbgPrint("In main... back from exception...\n");
  62. return 1;
  63. }