Source code of Windows XP (NT5)
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.

62 lines
1.6 KiB

  1. ; GPFix.inc - definitions for GP exception handler code
  2. ; usage -
  3. ; 1) include gpfix.inc
  4. ; 2) bracket critical code with "beg_fault_trap handler" and
  5. ; "end_fault_trap"
  6. ; 3) define a handler entry point where execution should continue
  7. ; a) this must be in the same code segment as the faulty code
  8. ; b) two extra words (fault IP/fault) will be pushed on the stack when
  9. ; an exception occurs. They should be popped before continuing.
  10. ; This can be done with the 'fault_fix_stack' macro.
  11. ; They are there if you want to determine which instruction faulted.
  12. ; c) This handler can do whatever it likes. Usually, it will return
  13. ; an error code to the caller.
  14. ; 4) if you don't want to worry about the extra values on the stack,
  15. ; use the fix_fault_stack macro to remove them
  16. _bft_count = 0
  17. _eft_count = 0
  18. _bft_ macro handler, count
  19. _bft_&count:
  20. _hft_&count = handler
  21. endm
  22. ;
  23. ; Begin fault critical region. 'handler' is the address of
  24. ; the exception handler to jmp to if a fault occurs.
  25. ;
  26. beg_fault_trap macro handler
  27. if _bft_count - _eft_count
  28. .err
  29. %out Mismatched beg_fault_trap/end_fault_trap pairs in beg_fault_trap
  30. endif
  31. _bft_ handler, %_bft_count
  32. _bft_count = _bft_count + 1
  33. endm
  34. _eft_ macro count
  35. _eft_&count:
  36. _GPFIX SEGMENT
  37. dw seg _bft_&count, _bft_&count, _eft_&count, _hft_&count
  38. _GPFIX ENDS
  39. endm
  40. ;
  41. ; End fault critical region.
  42. ;
  43. end_fault_trap macro
  44. _eft_ %_eft_count
  45. _eft_count = _eft_count+1
  46. if _bft_count - _eft_count
  47. .err
  48. %out Mismatched beg_fault_trap/end_fault_trap pairs in end_fault_trap
  49. endif
  50. endm
  51. ;
  52. ; Clean up stack in fault handler.
  53. ;
  54. fault_fix_stack macro
  55. add sp, 4
  56. endm