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.

244 lines
9.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: thop.hxx
  7. //
  8. // Contents: Defines the available thops
  9. //
  10. // History: 22-Feb-94 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #ifndef __THOP_HXX__
  14. #define __THOP_HXX__
  15. //
  16. // THOP is a single instruction to the interpreter that encodes,
  17. // decodes parameters sent via LRPC. A string of THOPs describes how to
  18. // marshal, unmarshal function's paramaters.
  19. //
  20. //
  21. typedef enum
  22. {
  23. THOP_END,
  24. // Basic types size of type (win3.1)
  25. THOP_SHORTLONG, // Signed ints 2b
  26. THOP_WORDDWORD, // Unsigned int 2b
  27. THOP_COPY, // Direct copies
  28. THOP_LPSTR, // LPSTR -- (zero terminated)
  29. THOP_LPLPSTR, // LPLPSTR -- (zero terminated)
  30. THOP_BUFFER, // void FAR* -- (size in next long)
  31. // Windows types
  32. THOP_HUSER, // HWND, HMENU 2b
  33. THOP_HGDI, // HDC, HICON 2b
  34. THOP_SIZE, // SIZE 4b
  35. THOP_RECT, // RECT 8b
  36. THOP_MSG, // MSG 18b
  37. // Ole types
  38. THOP_HRESULT, // HRESULT 4b
  39. THOP_STATSTG, // STATSTG > 38b + size of member lpstr
  40. THOP_DVTARGETDEVICE, // DVTARGETDEVICE > 16b
  41. THOP_STGMEDIUM, // STGMEDIUM > 12b + size of member lpstr
  42. THOP_FORMATETC, // FORMATETC > 18b + size of member tdev
  43. THOP_HACCEL, // HACCEL 2b
  44. THOP_OIFI, // OLEINPLACEFRAMEINFO 10b
  45. THOP_BINDOPTS, // BIND_OPTS > 12b
  46. THOP_LOGPALETTE, // LOGPALETTE > 8b
  47. THOP_SNB, // SNBs in storage Varies
  48. THOP_CRGIID, // ciid, rgiid pair from storage
  49. THOP_OLESTREAM, // OLESTREAM
  50. THOP_HTASK, // HTASK
  51. THOP_INTERFACEINFO, // INTERFACEINFO
  52. THOP_IFACE, // Known interface type
  53. THOP_IFACEOWNER, // For IFACE cases with weak references
  54. THOP_IFACENOADDREF, // For IFACE cases with no references by user (IOleCacheControl)
  55. THOP_IFACECLEAN, // For IRpcStubBuffer::DebugServerRelease
  56. THOP_IFACEGEN, // for QueryInterface, etc (refiid, **ppUnk)
  57. THOP_IFACEGENOWNER, // For IFACEGEN cases with weak references
  58. THOP_UNKOUTER, // Controling unknown
  59. THOP_UNKINNER, // Inner unknown
  60. THOP_ROUTINEINDEX, // Thop for indicating the call type index
  61. THOP_RETURNTYPE, // Thop for indicating return type of a routine if
  62. // not HRESULT
  63. THOP_NULL, // NULL ptr, for checking of reserved fields
  64. THOP_ERROR, // Invalid thop, for debugging
  65. THOP_ENUM, // Enumerator thop start
  66. THOP_CALLBACK, // Callback function and argument
  67. THOP_RPCOLEMESSAGE, // RPCOLEMESSAGE
  68. THOP_ALIAS32, // 16-bit alias for 32-bit quantity
  69. THOP_CLSCONTEXT, // Flags DWORD with special handling
  70. THOP_FILENAME, // String which is a filename, needs long/short cvt
  71. THOP_SIZEDSTRING, // String which cannot exceed a certain length
  72. THOP_LASTOP, // Marker for last op
  73. THOP_OPMASK = 0x3f, // Mask for basic operation code
  74. // Modifiers
  75. THOP_IOMASK = 0xc0,
  76. THOP_IN = 0x40, // FAR Pointer to in parameter
  77. THOP_OUT = 0x80, // FAR Pointer to out parameter
  78. THOP_INOUT = 0xc0 // FAR Pointer to in, out parameter
  79. } THOP_TYPE;
  80. typedef unsigned char THOP;
  81. #define ALIAS_CREATE 0
  82. #define ALIAS_RESOLVE 1
  83. #define ALIAS_REMOVE 2
  84. #define MAX_PARAMS 16
  85. typedef DWORD (__stdcall * VTBLFN)(DWORD dw);
  86. typedef struct tagSTACK16INFO
  87. {
  88. BYTE UNALIGNED *pbStart;
  89. BYTE UNALIGNED *pbCurrent;
  90. int iDir;
  91. } STACK16INFO;
  92. typedef struct tagSTACK32INFO
  93. {
  94. BYTE *pbStart;
  95. BYTE *pbCurrent;
  96. } STACK32INFO;
  97. typedef struct tagTHUNKINFO
  98. {
  99. STACK16INFO s16;
  100. STACK32INFO s32;
  101. THOP CONST *pThop;
  102. VTBLFN pvfn;
  103. SCODE scResult;
  104. BOOL fResultThunked;
  105. DWORD dwCallerProxy;
  106. CThkMgr *pThkMgr;
  107. IIDIDX iidx;
  108. DWORD dwMethod;
  109. IUnknown *this32;
  110. } THUNKINFO;
  111. // These are declared extern "C" because there was a bug in the
  112. // PPC compiler (aug '95) where the const related decorations on
  113. // the global data symbols was not done consistantly. By using
  114. // extern "C" the bug is simply avoided.
  115. // The problem was only with aThopFunctions*[] but I added
  116. // aThopEnumFunctions*[] for a consistent look and usage. A related
  117. // bug is fixed with apthopsApiThops[].
  118. extern "C" DWORD (* CONST aThopFunctions1632[])(THUNKINFO *);
  119. extern "C" DWORD (* CONST aThopFunctions3216[])(THUNKINFO *);
  120. extern "C" DWORD (* CONST aThopEnumFunctions1632[])(THUNKINFO *);
  121. extern "C" DWORD (* CONST aThopEnumFunctions3216[])(THUNKINFO *);
  122. #define SKIP_STACK16(s16, cb) \
  123. (s16)->pbCurrent = (s16)->iDir < 0 ? \
  124. (s16)->pbCurrent-(cb) : \
  125. (s16)->pbCurrent+(cb)
  126. #define PTR_STACK16(s16, cb) \
  127. ((s16)->pbCurrent-((s16)->iDir < 0 ? (cb) : 0))
  128. #define GET_STACK16(pti, val, typ) \
  129. if ((pti)->s16.iDir < 0) \
  130. { \
  131. (pti)->s16.pbCurrent -= sizeof(typ); \
  132. (val) = *(typ UNALIGNED *)(pti)->s16.pbCurrent; \
  133. } \
  134. else \
  135. { \
  136. (val) = *(typ UNALIGNED *)(pti)->s16.pbCurrent; \
  137. (pti)->s16.pbCurrent += sizeof(typ); \
  138. }
  139. #define TO_STACK16(pti, val, typ) \
  140. if ((pti)->s16.iDir < 0) \
  141. { \
  142. (pti)->s16.pbCurrent -= sizeof(typ); \
  143. *(typ UNALIGNED *)(pti)->s16.pbCurrent = (val); \
  144. } \
  145. else \
  146. { \
  147. *(typ UNALIGNED *)(pti)->s16.pbCurrent = (val); \
  148. (pti)->s16.pbCurrent += sizeof(typ); \
  149. }
  150. #define PEEK_STACK16(pti, val, typ) \
  151. (val) = *(typ UNALIGNED *)(pti)->s16.pbCurrent
  152. #define INDEX_STACK16(pti, val, typ, idx, predec) \
  153. (val) = *(typ UNALIGNED *)((pti)->s16.iDir < 0 ? \
  154. ((pti)->s16.pbCurrent+(idx)-(predec)) : \
  155. ((pti)->s16.pbCurrent-(idx)))
  156. #define SKIP_STACK32(s32, cb) \
  157. (s32)->pbCurrent += (cb)
  158. #define PTR_STACK32(s32) \
  159. (s32)->pbCurrent
  160. #define GET_STACK32(pti, val, typ) \
  161. (val) = *(typ *)(pti)->s32.pbCurrent; \
  162. SKIP_STACK32(&(pti)->s32, sizeof(typ))
  163. #define TO_STACK32(pti, val, typ) \
  164. *(typ *)(pti)->s32.pbCurrent = (val);\
  165. SKIP_STACK32(&(pti)->s32, sizeof(typ))
  166. #define PEEK_STACK32(pti, val, typ) \
  167. (val) = *(typ *)(pti)->s32.pbCurrent
  168. #define INDEX_STACK32(pti, val, typ, idx) \
  169. (val) = *(typ *)((pti)->s32.pbCurrent-(idx))
  170. #if DBG == 0
  171. // In debug builds this goes through a function that can emit
  172. // debug info about thops being executed
  173. #define EXECUTE_THOP1632(pti) \
  174. (*aThopFunctions1632[*((pti)->pThop) & THOP_OPMASK])(pti)
  175. #define EXECUTE_THOP3216(pti) \
  176. (*aThopFunctions3216[*((pti)->pThop) & THOP_OPMASK])(pti)
  177. #define EXECUTE_ENUMTHOP1632(pti) \
  178. (*aThopEnumFunctions1632[*(pti)->pThop])(pti)
  179. #define EXECUTE_ENUMTHOP3216(pti) \
  180. (*aThopEnumFunctions3216[*(pti)->pThop])(pti)
  181. #else
  182. DWORD EXECUTE_THOP1632(THUNKINFO *pti);
  183. DWORD EXECUTE_THOP3216(THUNKINFO *pti);
  184. DWORD EXECUTE_ENUMTHOP1632(THUNKINFO *pti);
  185. DWORD EXECUTE_ENUMTHOP3216(THUNKINFO *pti);
  186. #endif
  187. #define IS_THOP_IN(pti) ((*((pti)->pThop) & THOP_IN) == THOP_IN)
  188. #define IS_THOP_OUT(pti) ((*((pti)->pThop) & THOP_OUT) == THOP_OUT)
  189. // Max size of preallocated strings
  190. #define CBSTRINGPREALLOC 512
  191. #define CWCSTRINGPREALLOC (CBSTRINGPREALLOC/sizeof(WCHAR))
  192. // Max size?
  193. #define CCHMAXSTRING 0x1000
  194. // Max size of preallocated palettes
  195. #define NPALETTEPREALLOC 256
  196. // Size of a LOGPALETTE structure with N entries
  197. #define CBPALETTE(n) (sizeof(LOGPALETTE)+((n)-1)*sizeof(PALETTEENTRY))
  198. // Hide the exact field in the RPCOLEMESSAGE we use to store thunking data
  199. #define ROM_THUNK_FIELD(rom) ((rom)->reserved1)
  200. #endif // #ifndef __THOP_HXX__
  201.