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.

203 lines
7.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: thoputil.hxx
  7. //
  8. // Contents: Thunk routine utilities
  9. //
  10. // History: 01-Mar-94 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #ifndef __THOPUTIL_HXX__
  14. #define __THOPUTIL_HXX__
  15. // Alias manager for THOP_ALIAS32
  16. extern CAliases gAliases32;
  17. IIDIDX IidToIidIdx(REFIID riid);
  18. #ifdef COTASK_DEFINED
  19. #define TaskMalloc32 CoTaskMemAlloc
  20. #define TaskFree32 CoTaskMemFree
  21. #else
  22. LPVOID TaskMalloc32(SIZE_T cb);
  23. void TaskFree32(LPVOID pv);
  24. #endif
  25. DWORD TaskMalloc16( UINT uiSize );
  26. void TaskFree16( DWORD vpvoid );
  27. LPOLESTR Convert_VPSTR_to_LPOLESTR(THUNKINFO *pti,
  28. VPSTR vpstr,
  29. LPOLESTR lpOleStr,
  30. UINT uiSizeInPlace);
  31. //
  32. // Simple macro to free up any string allocated in the conversion process
  33. //
  34. #define Convert_VPSTR_to_LPOLESTR_free( lpOleStr, lpOleStrUsed ) \
  35. (((lpOleStr) == (lpOleStrUsed)) ? 0 : \
  36. (lpOleStrUsed == NULL) ? 0 : TaskFree32(lpOleStrUsed))
  37. SCODE Convert_LPOLESTR_to_VPSTR(LPCOLESTR lpOleStr,
  38. VPSTR vpstr,
  39. UINT uiSize32,
  40. UINT uiSize16);
  41. STDAPI_(DWORD) TransformHRESULT_1632( DWORD hresult );
  42. STDAPI_(DWORD) TransformHRESULT_3216( DWORD hresult );
  43. SHORT ClampLongToShort(LONG l);
  44. USHORT ClampULongToUShort(ULONG l);
  45. VOID * GetReadPtr16( THUNKINFO *pti, VPVOID vp16, DWORD dwSize );
  46. VOID * GetWritePtr16( THUNKINFO *pti, VPVOID vp16, DWORD dwSize );
  47. VOID * GetCodePtr16( THUNKINFO *pti, VPVOID vp16, DWORD dwSize );
  48. VOID * GetReadWritePtr16( THUNKINFO *pti, VPVOID vp16, DWORD dwSize );
  49. CHAR * GetStringPtr16( THUNKINFO *pti, VPVOID vp16, UINT cchMax,
  50. PUINT lpuiSize );
  51. VOID * ValidatePtr16(THUNKINFO *pti, VPVOID vp16, DWORD dwSize,
  52. THOP thopInOut);
  53. BOOL IsValidInterface16( THUNKINFO *pti, VPVOID vp );
  54. SCODE ConvertHGlobal1632(THUNKINFO *pti,
  55. HMEM16 hg16,
  56. THOP thopInOut,
  57. HGLOBAL *phg32,
  58. DWORD *pdwSize);
  59. SCODE ConvertHGlobal3216(THUNKINFO *pti,
  60. HGLOBAL hg32,
  61. THOP thopInOut,
  62. HMEM16 *phg16,
  63. DWORD *pdwSize);
  64. SCODE ConvertStgMed1632(THUNKINFO *pti,
  65. VPVOID vpsm16,
  66. STGMEDIUM *psm32,
  67. FORMATETC *pfe,
  68. BOOL fPassingOwnershipIn,
  69. DWORD *pdwSize);
  70. SCODE CleanStgMed32(THUNKINFO *pti,
  71. STGMEDIUM *psm32,
  72. VPVOID vpsm16,
  73. DWORD dwSize,
  74. BOOL fIsThunk,
  75. FORMATETC *pfe);
  76. SCODE ConvertStgMed3216(THUNKINFO *pti,
  77. STGMEDIUM *psm32,
  78. VPVOID vpsm16,
  79. FORMATETC *pfe,
  80. BOOL fPassingOwnershipIn,
  81. DWORD *pdwSize);
  82. SCODE CleanStgMed16(THUNKINFO *pti,
  83. VPVOID vpsm16,
  84. STGMEDIUM *psm32,
  85. DWORD dwSize,
  86. BOOL fIsThunk,
  87. FORMATETC *pfe);
  88. SCODE ConvertFetc1632(THUNKINFO *pti,
  89. VPVOID vpfe16,
  90. FORMATETC *pfe32,
  91. BOOL fFree);
  92. SCODE ConvertFetc3216(THUNKINFO *pti,
  93. FORMATETC *pfe32,
  94. VPVOID vpfe16,
  95. BOOL fFree);
  96. #if DBG == 1
  97. char *ThopName(THOP thop);
  98. char *EnumThopName(THOP thopEnum);
  99. char *GuidString(GUID const *pguid);
  100. char *IidOrInterfaceString(IID const *piid);
  101. char *IidIdxString(IIDIDX iidx);
  102. void DebugValidateProxy1632(VPVOID vpvProxy);
  103. void DebugValidateProxy3216(THUNK3216OBJ *ptoProxy);
  104. #else
  105. #define DebugValidateProxy1632(p)
  106. #define DebugValidateProxy3216(p)
  107. #endif
  108. #define StackAlloc16(cb) \
  109. ((VPVOID)TlsThkGetStack16()->Alloc(cb))
  110. #define StackFree16(vpv, cb) \
  111. TlsThkGetStack16()->Free((DWORD)vpv, cb)
  112. #define StackAlloc32(cb) \
  113. ((LPVOID)TlsThkGetStack32()->Alloc(cb))
  114. #define StackFree32(pv, cb) \
  115. TlsThkGetStack32()->Free((DWORD)pv, cb)
  116. #define STACKALLOC16(x) StackAlloc16(x)
  117. #define STACKFREE16(x,y) StackFree16(x, y)
  118. #define STACKALLOC32(x) (DWORD)_alloca(x)
  119. #define STACKFREE32(x, y)
  120. #if DBG == 1
  121. void RecordStackState16(SStackRecord *psr);
  122. void CheckStackState16(SStackRecord *psr);
  123. void RecordStackState32(SStackRecord *psr);
  124. void CheckStackState32(SStackRecord *psr);
  125. #endif
  126. typedef void *(*ALLOCROUTINE)(UINT cb);
  127. typedef void (*FREEROUTINE)(void *pv, UINT cb);
  128. void *ArTask16(UINT cb);
  129. void FrTask16(void *pv, UINT cb);
  130. void *ArTask32(UINT cb);
  131. void FrTask32(void *pv, UINT cb);
  132. void *ArStack16(UINT cb);
  133. void FrStack16(void *pv, UINT cb);
  134. void *ArStack32(UINT cb);
  135. void FrStack32(void *pv, UINT cb);
  136. SCODE ConvertDvtd1632(THUNKINFO *pti,
  137. VPVOID vpdvtd16,
  138. ALLOCROUTINE pfnAlloc,
  139. FREEROUTINE pfnFree,
  140. DVTARGETDEVICE **ppdvtd32,
  141. UINT *pcbSize);
  142. SCODE ConvertDvtd3216(THUNKINFO *pti,
  143. DVTARGETDEVICE *pdvtd32,
  144. ALLOCROUTINE pfnAlloc,
  145. FREEROUTINE pfnFree,
  146. VPVOID *ppvdvtd16,
  147. UINT *pcbSize);
  148. typedef void (*FIXEDHANDLERROUTINE)(BYTE *pbFrom, BYTE *pbTo,
  149. UINT cbFrom, UINT cbTo);
  150. void FhCopyMemory(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  151. void FhShortToLong(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  152. void FhLongToShort(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  153. void FhWordToDword(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  154. void FhDwordToWord(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  155. void FhGdiHandle1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  156. void FhGdiHandle3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  157. void FhUserHandle1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  158. void FhUserHandle3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  159. void FhHaccel1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  160. void FhHaccel3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  161. void FhHtask1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  162. void FhHtask3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  163. void FhHresult1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  164. void FhHresult3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  165. void FhNull(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  166. void FhRect1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  167. void FhRect3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  168. void FhSize1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  169. void FhSize3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  170. void FhMsg1632(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  171. void FhMsg3216(BYTE *pbFrom, BYTE *pbTo, UINT cbFrom, UINT cbTo);
  172. #endif // #ifndef __THOPUTIL_HXX__