home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / trnsctrl.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  11KB  |  260 lines

  1. /***
  2. *trnsctrl.h - routines that do special transfer of control
  3. *
  4. *       Copyright (c) 1993-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Declaration of routines that do special transfer of control.
  8. *       (and a few other implementation-dependant things).
  9. *
  10. *       Implementations of these routines are in assembly (very implementation
  11. *       dependant).  Currently, these are implemented as naked functions with
  12. *       inline asm.
  13. *
  14. *       [Internal]
  15. *
  16. ****/
  17.  
  18. #if _MSC_VER > 1000
  19. #pragma once
  20. #endif  /* _MSC_VER > 1000 */
  21.  
  22. #ifndef _INC_TRNSCTRL
  23. #define _INC_TRNSCTRL
  24.  
  25. #ifndef _CRTBLD
  26. /*
  27.  * This is an internal C runtime header file. It is used when building
  28.  * the C runtimes only. It is not to be used as a public header file.
  29.  */
  30. #error ERROR: Use of C runtime library internal header file.
  31. #endif  /* _CRTBLD */
  32.  
  33. #if _M_MRX000 >= 4000
  34.  
  35. typedef struct FrameInfo {
  36.                 PULONG                          pEstablisherFrame;
  37.                 PRUNTIME_FUNCTION       pFunctionEntry;
  38.                 CONTEXT*                        pExitContext;
  39.                 struct FrameInfo        *pNext;
  40. } FRAMEINFO;
  41.  
  42. extern FRAMEINFO*       _CreateFrameInfo(FRAMEINFO*, DispatcherContext*, PULONG, CONTEXT*);
  43. extern CONTEXT*         _FindAndUnlinkFrame(PVOID, FRAMEINFO*);
  44. extern VOID                     _JumpToContinuation( ULONG, CONTEXT*);
  45. extern PVOID            _OffsetToAddress( ptrdiff_t, PULONG, ULONG );
  46.  
  47. extern "C" VOID         _UnwindNestedFrames( EHRegistrationNode*, EHExceptionRecord*, CONTEXT* );
  48. extern "C" VOID         _NLG_Notify( PVOID, PVOID );
  49. extern "C" PVOID        _CallSettingFrame( PVOID, PULONG, ULONG );
  50. extern "C" PVOID        _CallCatchBlock2( EHRegistrationNode*, FuncInfo*, PVOID, ULONG, ULONG );
  51. extern "C" BOOL         _CallSETranslator( EHExceptionRecord*, EHRegistrationNode*, CONTEXT*, DispatcherContext*, FuncInfo*, ULONG, EHRegistrationNode*, ULONG);
  52. extern "C" VOID         _EHRestoreContext(CONTEXT* pContext);
  53. extern "C" CONTEXT*     _GetUnwindContext(VOID);
  54. extern "C" VOID         _MoveContext(CONTEXT* pTarget, CONTEXT* pSource);
  55. extern TryBlockMapEntry *_GetRangeOfTrysToCheck(EHRegistrationNode *, FuncInfo *, int, __ehstate_t, unsigned *, unsigned *);
  56. extern VOID             _DestructExceptionObject(EHExceptionRecord *, BOOLEAN);
  57.  
  58. #define _CallMemberFunction0(pthis, pmfn)                               (*(VOID(*)(PVOID))pmfn)(pthis)
  59. #define _CallMemberFunction1(pthis, pmfn, pthat)                (*(VOID(*)(PVOID,PVOID))pmfn)(pthis,pthat)
  60. #define _CallMemberFunction2(pthis, pmfn, pthat, val2 ) (*(VOID(*)(PVOID,PVOID,int))pmfn)(pthis,pthat,val2)
  61.  
  62. #define UNWINDHELP(base,offset,index)                                   (((char*)base) + (int)offset)[index]
  63.  
  64. #elif defined (_M_IA64)
  65.  
  66. typedef struct FrameInfo {
  67.                 EHRegistrationNode      EstablisherFrame;
  68.                 PRUNTIME_FUNCTION       pFunctionEntry;
  69.                 CONTEXT*                pExitContext;
  70.                 __ehstate_t             State;
  71.                 struct FrameInfo        *pNext;
  72. } FRAMEINFO;
  73.  
  74. extern FRAMEINFO*       _CreateFrameInfo(FRAMEINFO*, DispatcherContext*, EHRegistrationNode*, CONTEXT*, __ehstate_t);
  75. extern CONTEXT*         _FindAndUnlinkFrame(PVOID, FRAMEINFO*);
  76. extern FRAMEINFO*       _FindFrameInfo(DispatcherContext*, FRAMEINFO*);
  77. extern VOID             _JumpToContinuation( ULONG, CONTEXT*, EHExceptionRecord*);
  78. extern BOOL             _ExecutionInCatch(DispatcherContext*,  FuncInfo*);
  79.  
  80. extern VOID             __FrameUnwindToEmptyState(EHRegistrationNode*, DispatcherContext*, FuncInfo*);
  81. extern "C" VOID         _UnwindNestedFrames( EHRegistrationNode*, EHExceptionRecord*, CONTEXT* );
  82. extern "C" VOID         _NLG_Notify( PVOID, PVOID );
  83. extern "C" PVOID        _CallSettingFrame( void (*func)(void), EHRegistrationNode*, ULONG );
  84. extern "C" BOOL         _CallSETranslator( EHExceptionRecord*, EHRegistrationNode*, CONTEXT*, DispatcherContext*, FuncInfo*, ULONG, EHRegistrationNode*);
  85. extern "C" VOID         _EHRestoreContext(CONTEXT* pContext);
  86. extern "C" VOID         _SaveUnwindContext(CONTEXT* pContext);
  87. extern "C" CONTEXT*     _GetUnwindContext(VOID);
  88. extern "C" VOID         _MoveContext(CONTEXT* pTarget, CONTEXT* pSource);
  89. extern TryBlockMapEntry *_GetRangeOfTrysToCheck(EHRegistrationNode *, FuncInfo *, int, __ehstate_t, unsigned *, unsigned *, DispatcherContext*);
  90. extern VOID             _DestructExceptionObject(EHExceptionRecord *, BOOLEAN);
  91. extern EHRegistrationNode *_GetEstablisherFrame(EHRegistrationNode*, DispatcherContext*, FuncInfo*, EHRegistrationNode*);
  92.  
  93. #define _CallMemberFunction0(pthis, pmfn)               (*(VOID(*)(PVOID))pmfn)(pthis)
  94. #define _CallMemberFunction1(pthis, pmfn, pthat)        (*(VOID(*)(PVOID,PVOID))pmfn)(pthis,pthat)
  95. #define _CallMemberFunction2(pthis, pmfn, pthat, val2 ) (*(VOID(*)(PVOID,PVOID,int))pmfn)(pthis,pthat,val2)
  96.  
  97. #define UNWINDSTATE(base,offset) *((int*)((char*)base + offset))
  98. #define UNWINDTRYBLOCK(base,offset) *((int*)((char*)base + offset + sizeof(int)))
  99. #define UNWINDHELP(base,offset) *((__int64*)((char*)base + offset))
  100.  
  101. #define OffsetToAddress( off, FP )  (void*)(((char*)FP) + off)
  102.  
  103. #elif defined (_M_ALPHA)
  104.  
  105. //
  106. // For Debugger handling of stepping with non-local gotos
  107. //
  108.  
  109. extern "C" VOID     __NLG_Notify( PVOID, PVOID, ULONG );
  110.  
  111. //
  112. // For calling funclets (including the catch)
  113. //
  114. extern "C" void * _CallSettingFrame (
  115.     void *funcAddress,
  116.     void *realFP,
  117.     unsigned long NLGCode
  118.     );
  119.  
  120. extern void _JumpToContinuation(
  121.     void               *TargetIp,    // The target address
  122.     EHRegistrationNode *TargetFrame  // The target virtual frame ptr
  123.     );
  124.  
  125. //
  126. // For calling member functions:
  127. //
  128. extern "C" void _CallMemberFunction0( void *pthis, void *pmfn );
  129. extern "C" void _CallMemberFunction1( void *pthis, void *pmfn, void *pthat );
  130. extern "C" void _CallMemberFunction2( void *pthis, void *pmfn, void *pthat, int val2 );
  131.  
  132. //
  133. // Translate an frame relative offset to a hard address based on address of
  134. // a frame pointer (real or virtual).
  135. //
  136. #define OffsetToAddress( off, FP )  (void*)(((char*)FP) + off)
  137.  
  138. //
  139. // Call RtlUnwind in a returning fashion
  140. //
  141. extern "C" VOID _UnwindNestedFrames (
  142.     IN EHRegistrationNode *TargetFrame,
  143.     IN EHExceptionRecord *ExceptionRecord
  144.     );
  145.  
  146. //
  147. // Ditto the SE translator
  148. //
  149. BOOL _CallSETranslator( EHExceptionRecord*, EHRegistrationNode*, void*,
  150.                         DispatcherContext*, FuncInfo*, int,
  151.                         EHRegistrationNode*);
  152.  
  153. extern TryBlockMapEntry *_GetRangeOfTrysToCheck(FuncInfo *, int, __ehstate_t, unsigned *, unsigned *);
  154. extern VOID _DestructExceptionObject(EHExceptionRecord *, BOOLEAN);
  155. #elif defined (_M_IX86)
  156.  
  157. //
  158. // For calling funclets (including the catch)
  159. //
  160. extern "C" void * __stdcall _CallSettingFrame( void *, EHRegistrationNode *, unsigned long );
  161. extern void   __stdcall _JumpToContinuation( void *, EHRegistrationNode * );
  162.  
  163. //
  164. // For calling member functions:
  165. //
  166. extern void __stdcall _CallMemberFunction0( void *pthis, void *pmfn );
  167. extern void __stdcall _CallMemberFunction1( void *pthis, void *pmfn, void *pthat );
  168. extern void __stdcall _CallMemberFunction2( void *pthis, void *pmfn, void *pthat, int val2 );
  169.  
  170. //
  171. // Translate an ebp-relative offset to a hard address based on address of
  172. // registration node:
  173. //
  174. #if !CC_EXPLICITFRAME
  175. #define OffsetToAddress( off, RN )      \
  176.                 (void*)((char*)RN \
  177.                                 + FRAME_OFFSET \
  178.                                 + off)
  179. #else  /* !CC_EXPLICITFRAME */
  180. #define OffsetToAddress( off, RN )      (void*)(((char*)RN->frame) + off)
  181. #endif  /* !CC_EXPLICITFRAME */
  182.  
  183. //
  184. // Call RtlUnwind in a returning fassion
  185. //
  186. extern void __stdcall _UnwindNestedFrames( EHRegistrationNode*, EHExceptionRecord* );
  187.  
  188. //
  189. // Do the nitty-gritty of calling the catch block safely
  190. //
  191. void *_CallCatchBlock2( EHRegistrationNode *, FuncInfo*, void*, int, unsigned long );
  192.  
  193. //
  194. // Ditto the SE translator
  195. //
  196. BOOL _CallSETranslator( EHExceptionRecord*, EHRegistrationNode*, void*, DispatcherContext*, FuncInfo*, int, EHRegistrationNode*);
  197.  
  198. extern TryBlockMapEntry *_GetRangeOfTrysToCheck(FuncInfo *, int, __ehstate_t, unsigned *, unsigned *);
  199. extern VOID _DestructExceptionObject(EHExceptionRecord *, BOOLEAN);
  200.  
  201. #elif defined (_M_MPPC) || defined (_M_PPC)
  202. typedef struct FrameInfo {
  203.     PULONG pEstablisherFrame;
  204.     ULONG ControlPc;
  205.     PRUNTIME_FUNCTION pFunctionEntry;
  206.     CONTEXT *pExitContext;
  207.     __ehstate_t state;
  208.     struct FrameInfo *pNext;
  209. } FRAMEINFO;
  210.  
  211. extern "C" PVOID _CallSettingFrame(PVOID, PULONG, ULONG);
  212. extern "C" VOID _GetStackLimits(PULONG, PULONG);
  213. extern EHRegistrationNode *_GetEstablisherFrame(DispatcherContext *, int *);
  214. extern FRAMEINFO *_CreateFrameInfo(FRAMEINFO *, DispatcherContext *, PULONG, CONTEXT *, __ehstate_t);
  215. extern "C" VOID _JumpToContinuation(ULONG, CONTEXT *);
  216. extern "C" VOID _UnwindNestedFrames(EHRegistrationNode *, EHExceptionRecord *, CONTEXT *);
  217. extern CONTEXT *_FindAndUnlinkFrame(PVOID, FRAMEINFO *);
  218. extern FRAMEINFO *_FindFrameInfo(ULONG, FRAMEINFO *);
  219. extern VOID __FrameUnwindToEmptyState(EHRegistrationNode *, DispatcherContext *, FuncInfo *);
  220. extern BOOL _UnwindNestedCatch(EHRegistrationNode *, DispatcherContext *);
  221.  
  222. extern BOOL _CallSETranslator(EHExceptionRecord *, EHRegistrationNode *, CONTEXT *, DispatcherContext *, FuncInfo *, ULONG, EHRegistrationNode *);
  223. extern TryBlockMapEntry *_GetRangeOfTrysToCheck(FuncInfo *, int, __ehstate_t, unsigned *, unsigned *);
  224. extern VOID _DestructExceptionObject(EHExceptionRecord *, BOOLEAN);
  225.  
  226. #define OffsetToAddress(off, pRN) \
  227.     ((void *)((char *)(pRN) + (off)))
  228. #define _CallMemberFunction0(pthis, pmfn) \
  229.     (*(VOID(*)(PVOID))(pmfn))(pthis)
  230. #define _CallMemberFunction1(pthis, pmfn, pthat) \
  231.     (*(VOID(*)(PVOID, PVOID))(pmfn))(pthis, pthat)
  232. #define _CallMemberFunction2(pthis, pmfn, pthat, val2) \
  233.     (*(VOID(*)(PVOID, PVOID, int))(pmfn))(pthis, pthat, val2)
  234.  
  235. #if defined (_M_MPPC)
  236. extern VOID _AllocExceptionData(PEXCEPTION_RECORD *, PCONTEXT *);
  237. extern VOID _FreeExceptionData(EHExceptionRecord *);
  238. extern ULONG _ConvertCFAddress(ULONG, DispatcherContext *, int);
  239.  
  240. #define CFREL_TO_ABS            0
  241. #define ABS_TO_CFREL            1
  242.  
  243. #define TOC_LINK                (-1)
  244. #else  /* defined (_M_MPPC) */
  245. #define TOC_LINK                2
  246. #endif  /* defined (_M_MPPC) */
  247.  
  248. #define SET_UNWIND_FLAG(rTOC)   ((rTOC) |= 1)
  249. #define CLEAR_UNWIND_FLAG(rTOC) ((rTOC) &= ~1)
  250. #define CHECK_UNWIND_FLAG(rTOC) (((rTOC) & 1) != 0)
  251. #define SET_UNWIND_FRAME(pRN)   SET_UNWIND_FLAG(((PULONG)(pRN))[TOC_LINK])
  252. #define CHECK_UNWIND_FRAME(pRN) CHECK_UNWIND_FLAG(((PULONG)(pRN))[TOC_LINK])
  253. #else  /* defined (_M_MPPC) || defined (_M_PPC) */
  254.  
  255. #pragma message("Special transfer of control routines not defined for this platform")
  256.  
  257. #endif  /* defined (_M_MPPC) || defined (_M_PPC) */
  258.  
  259. #endif  /* _INC_TRNSCTRL */
  260.