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.

350 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. nativcom.h
  5. Abstract:
  6. Public header for COM-marshaling facilities provided by msjava.dll.
  7. --*/
  8. #ifndef _NATIVCOM_
  9. #define _NATIVCOM_
  10. #include <windows.h>
  11. #include <native.h>
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. //----------------------------------------------------------------------------
  16. // COM and J/Direct data wrapper helpers...
  17. //----------------------------------------------------------------------------
  18. // Replaces the data pointer contained in the data wrapper with a new blob of
  19. // non-GC'ed heap memory. The previous blob, if any, will be freed if its
  20. // owned by the VM.
  21. JAVAVMAPI
  22. void*
  23. __cdecl
  24. jcdwNewData(
  25. HObject * phJCDW,
  26. unsigned int numBytes
  27. );
  28. // Returns the data pointer to the non GC'ed heap memory contained by the data
  29. // wrapper object.
  30. JAVAVMAPI
  31. void*
  32. __cdecl
  33. jcdwGetData(
  34. HObject *phJCDW
  35. );
  36. // Replaces the data pointer that this data wrapper represents with the
  37. // specified
  38. JAVAVMAPI
  39. int
  40. __cdecl
  41. jcdwSetData(
  42. HObject *phJCDW,
  43. LPVOID pv
  44. );
  45. // Returns TRUE if the VM allocated the non GC'ed heap memory contained by the
  46. // data wrapper.
  47. JAVAVMAPI
  48. int
  49. __cdecl
  50. jcdw_memory_freed_on_gc(
  51. HObject *phJCDW
  52. );
  53. // Returns TRUE if the VM frees the non GC'ed heap memory that this data
  54. // wrapper contains when the data wrapper is garbage collected.
  55. JAVAVMAPI
  56. int
  57. __cdecl
  58. jcdw_java_owned(
  59. HObject *phJCDW
  60. );
  61. // Returns the size of the non GC'ed heap memory contained by the data wrapper
  62. // object.
  63. JAVAVMAPI
  64. unsigned int
  65. __cdecl
  66. jcdwSizeOf(
  67. HObject *phJCDW
  68. );
  69. // Returns the size of the non GC'ed heap memory used by instances of the
  70. // supplied java/lang/Class object.
  71. JAVAVMAPI
  72. unsigned int
  73. __cdecl
  74. jcdwClassSizeOf(
  75. HObject *phJavaClass
  76. );
  77. // Returns the byte offset within the non GC'ed heap memory to the specified
  78. // field name.
  79. JAVAVMAPI
  80. unsigned int
  81. __cdecl
  82. jcdwOffsetOf(
  83. HObject *phJCDW,
  84. PCUTF8 putfFieldName
  85. );
  86. // Returns the byte offset within the non GC'ed heap memory to the specified
  87. // field name from the supplied java/lang/Class object.
  88. JAVAVMAPI
  89. unsigned int
  90. __cdecl
  91. jcdwClassOffsetOf(
  92. HObject *phJCDWClass,
  93. PCUTF8 putfFieldName
  94. );
  95. // Given an object, propagates field values from the Java object to the object's
  96. // associated native memory.
  97. // Returns FALSE on error, else TRUE.
  98. JAVAVMAPI
  99. int
  100. __cdecl
  101. jcdwPropagateToNative(
  102. HObject *phJCDW
  103. );
  104. // Given an object, propagates field values from the object's associated native
  105. // memory to the Java object. If fFreeIndirectNativeMemory is TRUE, the native
  106. // memory used for any reference fields (Strings, custom marshaled fields, ...)
  107. // will be released.
  108. // Returns FALSE on error, else TRUE.
  109. JAVAVMAPI
  110. int
  111. __cdecl
  112. jcdwPropagateToJava(
  113. HObject *phJCDW,
  114. BOOL fFreeIndirectNativeMemory
  115. );
  116. // Returns a Java callable wrapper that can be used to access the specified
  117. // interface pointer. The VM will keep a reference to this interface pointer.
  118. // If 'fAssumeThreadSafe' is FALSE, the VM will auto-marshal all COM calls to
  119. // the current COM context.
  120. JAVAVMAPI
  121. HObject *
  122. __cdecl
  123. convert_IUnknown_to_Java_Object(
  124. IUnknown *punk,
  125. HObject *phJavaClass,
  126. int fAssumeThreadSafe
  127. );
  128. // Returns a Java callable wrapper that can be used to access the specified
  129. // interface pointer. The VM will keep a reference to this interface pointer.
  130. // If 'fAssumeThreadSafe' is FALSE, the VM will auto-marshal all COM calls to
  131. // the current COM context.
  132. JAVAVMAPI
  133. HObject *
  134. __cdecl
  135. convert_IUnknown_to_Java_Object2(
  136. IUnknown *punk,
  137. ClassClass *pClassClass,
  138. int fFreeThreaded
  139. );
  140. // Returns an interface pointer usable from the current COM context.
  141. JAVAVMAPI
  142. IUnknown *
  143. __cdecl
  144. convert_Java_Object_to_IUnknown(
  145. HObject *phJavaObject,
  146. const IID *pIID
  147. );
  148. // Returns a data wrapper object of the supplied Class type that points at the
  149. // supplied data pointer. The memory is not owned by the VM.
  150. JAVAVMAPI
  151. HObject *
  152. __cdecl
  153. convert_ptr_to_jcdw(
  154. void *pExtData,
  155. HObject *phJavaClass
  156. );
  157. //----------------------------------------------------------------------------
  158. // Map HRESULT to ComException.
  159. //----------------------------------------------------------------------------
  160. JAVAVMAPI
  161. void
  162. __cdecl
  163. SignalErrorHResult(
  164. HRESULT theHRESULT
  165. );
  166. //----------------------------------------------------------------------------
  167. // Map Java exception to HRESULT.
  168. //----------------------------------------------------------------------------
  169. JAVAVMAPI
  170. HRESULT
  171. __cdecl
  172. HResultFromException(
  173. HObject *exception_object
  174. );
  175. typedef HObject *JAVAARG;
  176. //----------------------------------------------------------------------------
  177. // Information structure for Java->COM Custom Method hook.
  178. //----------------------------------------------------------------------------
  179. typedef struct {
  180. DWORD cbSize; // size of structure in bytes
  181. IUnknown *punk; // pointer to interface being invoked
  182. const volatile JAVAARG *pJavaArgs; // pointer to Java argument stack
  183. } J2CMethodHookInfo;
  184. //----------------------------------------------------------------------------
  185. // Information structure for COM->Java Custom Method hook.
  186. //----------------------------------------------------------------------------
  187. typedef struct {
  188. DWORD cbSize; // size of structure in bytes
  189. struct methodblock *javaMethod; // java method to call
  190. LPVOID pComArgs; // pointer to COM method argument stack
  191. const volatile JAVAARG *ppThis; // pointer to pointer to Java this
  192. // Store the COM result here.
  193. union {
  194. HRESULT resHR;
  195. DWORD resDWORD;
  196. double resDouble;
  197. };
  198. } C2JMethodHookInfo;
  199. JAVAVMAPI
  200. WORD
  201. __cdecl
  202. j2chook_getsizeofuserdata(
  203. J2CMethodHookInfo *phookinfo
  204. );
  205. JAVAVMAPI
  206. LPVOID
  207. __cdecl
  208. j2chook_getuserdata(
  209. J2CMethodHookInfo *phookinfo
  210. );
  211. // Returns the vtable index of the target method.
  212. JAVAVMAPI
  213. WORD
  214. __cdecl
  215. j2chook_getvtblindex(
  216. J2CMethodHookInfo *phookinfo
  217. );
  218. // Returns the methodblock of the target method.
  219. JAVAVMAPI
  220. struct methodblock*
  221. __cdecl
  222. j2chook_getmethodblock(
  223. J2CMethodHookInfo *phookinfo
  224. );
  225. JAVAVMAPI
  226. WORD
  227. __cdecl
  228. c2jhook_getsizeofuserdata(
  229. C2JMethodHookInfo *phookinfo
  230. );
  231. JAVAVMAPI
  232. LPVOID
  233. __cdecl
  234. c2jhook_getuserdata(
  235. C2JMethodHookInfo *phookinfo
  236. );
  237. // Returns the class defining the interface method. This is the class
  238. // containing the MCCustomMethod descriptor.
  239. JAVAVMAPI
  240. ClassClass *
  241. __cdecl
  242. c2jhook_getexposingclass(
  243. C2JMethodHookInfo *phookinfo
  244. );
  245. //----------------------------------------------------------------------------
  246. // Thread marshaling helpers
  247. //
  248. // The MarshalCall<> APIs will reexecute the RNI method on the supplied thread
  249. // id or on the apartment thread for the supplied Java object. The APIs will
  250. // return the following sets of HRESULTS:
  251. //
  252. // S_OK The call successfully was marshaled to the target thread.
  253. // The marshaled call may have generated an exception, which can
  254. // bechecked by calling exceptionOccurred.
  255. // S_FALSE The call did not require marshaling to the other thread--
  256. // the currently executing thread is the target thread.
  257. // E_<> An error occurred inside the MarshalCall<> API (invalid
  258. // arguments, out of memory, etc).
  259. //
  260. // The typical use of these APIs is to call the appropriate MarshalCall<> API
  261. // and if the HRESULT is S_FALSE, then execute the rest of the RNI method,
  262. // otherwise return with the value contained in pResult.
  263. //----------------------------------------------------------------------------
  264. typedef void * JAVATID;
  265. #define JAVATID_MAIN_APARTMENT ((JAVATID) 0x00000001)
  266. #define JAVATID_SERVER_APARTMENT ((JAVATID) 0x00000002)
  267. JAVAVMAPI
  268. HRESULT
  269. __cdecl
  270. MarshalCallToJavaThreadId(
  271. JAVATID tid,
  272. int64_t *pResult
  273. );
  274. JAVAVMAPI
  275. HRESULT
  276. __cdecl
  277. MarshalCallToJavaObjectHostThread(
  278. HObject *phobj,
  279. int64_t *pResult
  280. );
  281. #ifdef __cplusplus
  282. }
  283. #endif
  284. #endif