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.

224 lines
10 KiB

  1. /***
  2. *trnsctrl.h - routines that do special transfer of control
  3. *
  4. * Copyright (c) 1993-2001, 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. *Revision History:
  17. * 05-24-93 BS Module created.
  18. * 03-03-94 TL Added Mips (_M_MRX000 >= 4000) changes
  19. * 09-02-94 SKS This header file added.
  20. * 09-13-94 GJF Merged in changes from/for DEC Alpha (from Al Doser,
  21. * dated 6/21).
  22. * 10-09-94 BWT Add unknown machine merge from John Morgan
  23. * 02-14-95 CFW Clean up Mac merge.
  24. * 03-29-95 CFW Add error message to internal headers.
  25. * 04-11-95 JWM _CallSettingFrame() is now extern "C".
  26. * 12-14-95 JWM Add "#pragma once".
  27. * 02-24-97 GJF Detab-ed.
  28. * 06-01-97 TL Added P7 changes
  29. * 02-11-99 TL IA64: catch bug fix.
  30. * 05-17-99 PML Remove all Macintosh support.
  31. * 06-05-01 GB AMD64 Eh support Added.
  32. * 06-08-00 RDL VS#111429: IA64 workaround for AV while handling throw.
  33. * 07-13-01 GB ReWrite of C++Eh for AMD64 and IA64
  34. * 07-15-01 PML Remove all ALPHA, MIPS, and PPC code
  35. *
  36. ****/
  37. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  38. #pragma once
  39. #endif
  40. #ifndef _INC_TRNSCTRL
  41. #define _INC_TRNSCTRL
  42. #ifndef _CRTBLD
  43. /*
  44. * This is an internal C runtime header file. It is used when building
  45. * the C runtimes only. It is not to be used as a public header file.
  46. */
  47. #error ERROR: Use of C runtime library internal header file.
  48. #endif /* _CRTBLD */
  49. #if defined(_M_AMD64) /*IFSTRIP=IGN*/
  50. typedef struct FrameInfo {
  51. PVOID pExceptionObject;
  52. struct FrameInfo * pNext;
  53. } FRAMEINFO;
  54. extern void _UnlinkFrame(FRAMEINFO *pFrameInfo);
  55. extern FRAMEINFO* _FindFrameInfo(PVOID, FRAMEINFO*);
  56. extern VOID _JumpToContinuation(unsigned __int64, CONTEXT*, EHExceptionRecord*);
  57. extern BOOL _ExecutionInCatch(DispatcherContext*, FuncInfo*);
  58. extern VOID __FrameUnwindToEmptyState(EHRegistrationNode*, DispatcherContext*, FuncInfo*);
  59. extern VOID _FindAndUnlinkFrame(FRAMEINFO *);
  60. extern FRAMEINFO* _CreateFrameInfo(FRAMEINFO*, PVOID);
  61. extern int _IsExceptionObjectToBeDestroyed(PVOID);
  62. extern "C" VOID _UnwindNestedFrames( EHRegistrationNode*,
  63. EHExceptionRecord*,
  64. CONTEXT* ,
  65. EHRegistrationNode*,
  66. void*,
  67. __ehstate_t,
  68. FuncInfo *,
  69. DispatcherContext*,
  70. BOOLEAN
  71. );
  72. extern "C" PVOID __CxxCallCatchBlock(EXCEPTION_RECORD*);
  73. extern "C" PVOID _CallSettingFrame( void*, EHRegistrationNode*, ULONG );
  74. extern "C" BOOL _CallSETranslator( EHExceptionRecord*,
  75. EHRegistrationNode*,
  76. CONTEXT*,
  77. DispatcherContext*,
  78. FuncInfo*,
  79. ULONG,
  80. EHRegistrationNode*);
  81. extern "C" VOID _EHRestoreContext(CONTEXT* pContext);
  82. extern "C" unsigned __int64 _GetImageBase(VOID);
  83. extern "C" unsigned __int64 _GetThrowImageBase(VOID);
  84. extern "C" VOID _SetThrowImageBase(unsigned __int64 NewThrowImageBase);
  85. extern TryBlockMapEntry *_GetRangeOfTrysToCheck(EHRegistrationNode *,
  86. FuncInfo *,
  87. int,
  88. __ehstate_t,
  89. unsigned *,
  90. unsigned *,
  91. DispatcherContext*
  92. );
  93. extern EHRegistrationNode *_GetEstablisherFrame(EHRegistrationNode*,
  94. DispatcherContext*,
  95. FuncInfo*,
  96. EHRegistrationNode*
  97. );
  98. #define _CallMemberFunction0(pthis, pmfn) (*(VOID(*)(PVOID))pmfn)(pthis)
  99. #define _CallMemberFunction1(pthis, pmfn, pthat) (*(VOID(*)(PVOID,PVOID))pmfn)(pthis,pthat)
  100. #define _CallMemberFunction2(pthis, pmfn, pthat, val2 ) (*(VOID(*)(PVOID,PVOID,int))pmfn)(pthis,pthat,val2)
  101. #define OffsetToAddress( off, FP ) (void*)(((char*)FP) + off)
  102. #define UNWINDSTATE(base,offset) *((int*)((char*)base + offset))
  103. #define UNWINDTRYBLOCK(base,offset) *((int*)( (char*)(OffsetToAddress(offset,base)) + 4 ))
  104. #define UNWINDHELP(base,offset) *((__int64*)((char*)base + offset))
  105. #elif defined(_M_IA64) /*IFSTRIP=IGN*/
  106. typedef struct FrameInfo {
  107. PVOID pExceptionObject;
  108. struct FrameInfo * pNext;
  109. } FRAMEINFO;
  110. extern void _UnlinkFrame(FRAMEINFO *pFrameInfo);
  111. extern FRAMEINFO* _FindFrameInfo(PVOID, FRAMEINFO*);
  112. extern VOID _JumpToContinuation(unsigned __int64, CONTEXT*, EHExceptionRecord*);
  113. extern BOOL _ExecutionInCatch(DispatcherContext*, FuncInfo*);
  114. extern VOID __FrameUnwindToEmptyState(EHRegistrationNode*, DispatcherContext*, FuncInfo*);
  115. extern VOID _FindAndUnlinkFrame(FRAMEINFO *);
  116. extern FRAMEINFO* _CreateFrameInfo(FRAMEINFO*, PVOID);
  117. extern int _IsExceptionObjectToBeDestroyed(PVOID);
  118. extern "C" VOID _UnwindNestedFrames( EHRegistrationNode*,
  119. EHExceptionRecord*,
  120. CONTEXT* ,
  121. EHRegistrationNode*,
  122. void*,
  123. __ehstate_t,
  124. FuncInfo *,
  125. DispatcherContext*,
  126. BOOLEAN
  127. );
  128. extern "C" PVOID __CxxCallCatchBlock(EXCEPTION_RECORD*);
  129. extern "C" PVOID _CallSettingFrame( void*, EHRegistrationNode*, ULONG );
  130. extern "C" BOOL _CallSETranslator( EHExceptionRecord*, EHRegistrationNode*, CONTEXT*, DispatcherContext*, FuncInfo*, ULONG, EHRegistrationNode*);
  131. extern "C" VOID _EHRestoreContext(CONTEXT* pContext);
  132. extern "C" unsigned __int64 _GetImageBase(VOID);
  133. extern "C" unsigned __int64 _GetThrowImageBase(VOID);
  134. extern "C" VOID _SetImageBase(unsigned __int64 ImageBaseToRestore);
  135. extern "C" VOID _SetThrowImageBase(unsigned __int64 NewThrowImageBase);
  136. extern "C" VOID _MoveContext(CONTEXT* pTarget, CONTEXT* pSource);
  137. extern TryBlockMapEntry *_GetRangeOfTrysToCheck(EHRegistrationNode *, FuncInfo *, int, __ehstate_t, unsigned *, unsigned *, DispatcherContext*);
  138. extern EHRegistrationNode *_GetEstablisherFrame(EHRegistrationNode*, DispatcherContext*, FuncInfo*, EHRegistrationNode*);
  139. #define _CallMemberFunction0(pthis, pmfn) (*(VOID(*)(PVOID))pmfn)(pthis)
  140. #define _CallMemberFunction1(pthis, pmfn, pthat) (*(VOID(*)(PVOID,PVOID))pmfn)(pthis,pthat)
  141. #define _CallMemberFunction2(pthis, pmfn, pthat, val2 ) (*(VOID(*)(PVOID,PVOID,int))pmfn)(pthis,pthat,val2)
  142. #define OffsetToAddress( off, FP ) (void*)(((char*)FP) + off)
  143. #define UNWINDSTATE(base,offset) *((int*)((char*)base + offset))
  144. #define UNWINDTRYBLOCK(base,offset) *((int*)( (char*)(OffsetToAddress(offset,base)) + 4 ))
  145. #define UNWINDHELP(base,offset) *((__int64*)((char*)base + offset))
  146. #elif defined(_M_IX86) // x86
  147. //
  148. // For calling funclets (including the catch)
  149. //
  150. extern "C" void * __stdcall _CallSettingFrame( void *, EHRegistrationNode *, unsigned long );
  151. extern void __stdcall _JumpToContinuation( void *, EHRegistrationNode * );
  152. //
  153. // For calling member functions:
  154. //
  155. extern void __stdcall _CallMemberFunction0( void *pthis, void *pmfn );
  156. extern void __stdcall _CallMemberFunction1( void *pthis, void *pmfn, void *pthat );
  157. extern void __stdcall _CallMemberFunction2( void *pthis, void *pmfn, void *pthat, int val2 );
  158. //
  159. // Translate an ebp-relative offset to a hard address based on address of
  160. // registration node:
  161. //
  162. #if !CC_EXPLICITFRAME
  163. #define OffsetToAddress( off, RN ) \
  164. (void*)((char*)RN \
  165. + FRAME_OFFSET \
  166. + off)
  167. #else
  168. #define OffsetToAddress( off, RN ) (void*)(((char*)RN->frame) + off)
  169. #endif
  170. //
  171. // Call RtlUnwind in a returning fassion
  172. //
  173. extern void __stdcall _UnwindNestedFrames( EHRegistrationNode*, EHExceptionRecord* );
  174. //
  175. // Do the nitty-gritty of calling the catch block safely
  176. //
  177. void *_CallCatchBlock2( EHRegistrationNode *, FuncInfo*, void*, int, unsigned long );
  178. //
  179. // Link together all existing catch objects to determine when they should be destroyed
  180. //
  181. typedef struct FrameInfo {
  182. PVOID pExceptionObject;
  183. struct FrameInfo * pNext;
  184. } FRAMEINFO;
  185. extern FRAMEINFO * _CreateFrameInfo(FRAMEINFO*, PVOID);
  186. extern BOOL IsExceptionObjectToBeDestroyed(PVOID);
  187. extern void _FindAndUnlinkFrame(FRAMEINFO*);
  188. //
  189. // Ditto the SE translator
  190. //
  191. BOOL _CallSETranslator( EHExceptionRecord*, EHRegistrationNode*, void*, DispatcherContext*, FuncInfo*, int, EHRegistrationNode*);
  192. extern TryBlockMapEntry *_GetRangeOfTrysToCheck(FuncInfo *, int, __ehstate_t, unsigned *, unsigned *);
  193. #else
  194. #pragma message("Special transfer of control routines not defined for this platform")
  195. #endif
  196. #endif /* _INC_TRNSCTRL */