3 * marshal.h: Routines for marshaling complex types in P/Invoke methods.
6 * Paolo Molaro (lupus@ximian.com)
8 * (C) 2002 Ximian, Inc. http://www.ximian.com
12 #ifndef __MONO_MARSHAL_H__
13 #define __MONO_MARSHAL_H__
15 #include <mono/metadata/class.h>
16 #include <mono/metadata/object-internals.h>
17 #include <mono/metadata/class-internals.h>
18 #include <mono/metadata/opcodes.h>
19 #include <mono/metadata/reflection.h>
21 #define mono_marshal_find_bitfield_offset(type, elem, byte_offset, bitmask) \
24 memset (&tmp, 0, sizeof (tmp)); \
26 mono_marshal_find_nonzero_bit_offset ((guint8*)&tmp, sizeof (tmp), (byte_offset), (bitmask)); \
31 /* marshaling helper functions */
34 mono_marshal_init (void) MONO_INTERNAL;
37 mono_marshal_cleanup (void) MONO_INTERNAL;
40 mono_class_native_size (MonoClass *klass, guint32 *align) MONO_INTERNAL;
43 mono_marshal_load_type_info (MonoClass* klass) MONO_INTERNAL;
46 mono_marshal_type_size (MonoType *type, MonoMarshalSpec *mspec, guint32 *align,
47 gboolean as_field, gboolean unicode) MONO_INTERNAL;
50 mono_type_native_stack_size (MonoType *type, guint32 *alignment) MONO_INTERNAL;
53 mono_array_to_savearray (MonoArray *array) MONO_INTERNAL;
56 mono_array_to_lparray (MonoArray *array) MONO_INTERNAL;
59 mono_string_utf8_to_builder (MonoStringBuilder *sb, char *text) MONO_INTERNAL;
62 mono_string_utf16_to_builder (MonoStringBuilder *sb, gunichar2 *text) MONO_INTERNAL;
65 mono_string_builder_to_utf8 (MonoStringBuilder *sb) MONO_INTERNAL;
68 mono_string_builder_to_utf16 (MonoStringBuilder *sb) MONO_INTERNAL;
71 mono_string_to_ansibstr (MonoString *string_obj) MONO_INTERNAL;
74 mono_string_to_bstr (MonoString *string_obj) MONO_INTERNAL;
77 mono_string_to_byvalstr (gpointer dst, MonoString *src, int size) MONO_INTERNAL;
80 mono_string_to_byvalwstr (gpointer dst, MonoString *src, int size) MONO_INTERNAL;
83 mono_delegate_to_ftnptr (MonoDelegate *delegate) MONO_INTERNAL;
86 mono_ftnptr_to_delegate (MonoClass *klass, gpointer ftn) MONO_INTERNAL;
88 void mono_delegate_free_ftnptr (MonoDelegate *delegate) MONO_INTERNAL;
91 mono_marshal_set_last_error (void) MONO_INTERNAL;
94 mono_marshal_asany (MonoObject *obj, MonoMarshalNative string_encoding, int param_attrs) MONO_INTERNAL;
97 mono_marshal_free_asany (MonoObject *o, gpointer ptr, MonoMarshalNative string_encoding, int param_attrs) MONO_INTERNAL;
100 mono_marshal_get_write_barrier (void) MONO_INTERNAL;
103 mono_type_to_ldind (MonoType *type) MONO_INTERNAL;
106 mono_type_to_stind (MonoType *type) MONO_INTERNAL;
108 /* functions to create various architecture independent helper functions */
111 mono_marshal_method_from_wrapper (MonoMethod *wrapper) MONO_INTERNAL;
114 mono_marshal_get_remoting_invoke (MonoMethod *method) MONO_INTERNAL;
117 mono_marshal_get_xappdomain_invoke (MonoMethod *method) MONO_INTERNAL;
120 mono_marshal_get_remoting_invoke_for_target (MonoMethod *method, MonoRemotingTarget target_type) MONO_INTERNAL;
123 mono_marshal_get_remoting_invoke_with_check (MonoMethod *method) MONO_INTERNAL;
126 mono_marshal_get_delegate_begin_invoke (MonoMethod *method) MONO_INTERNAL;
129 mono_marshal_get_delegate_end_invoke (MonoMethod *method) MONO_INTERNAL;
132 mono_marshal_get_delegate_invoke (MonoMethod *method, MonoDelegate *del) MONO_INTERNAL;
135 mono_marshal_get_runtime_invoke (MonoMethod *method) MONO_INTERNAL;
138 mono_marshal_get_static_rgctx_invoke (MonoMethod *method) MONO_INTERNAL;
141 mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, MonoObject *this) MONO_INTERNAL;
144 mono_marshal_get_vtfixup_ftnptr (MonoImage *image, guint32 token, guint16 type) MONO_INTERNAL;
147 mono_marshal_get_icall_wrapper (MonoMethodSignature *sig, const char *name, gconstpointer func, gboolean check_exceptions) MONO_INTERNAL;
150 mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions, gboolean aot) MONO_INTERNAL;
153 mono_marshal_get_native_func_wrapper (MonoImage *image, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func) MONO_INTERNAL;
156 mono_marshal_get_struct_to_ptr (MonoClass *klass) MONO_INTERNAL;
159 mono_marshal_get_ptr_to_struct (MonoClass *klass) MONO_INTERNAL;
162 mono_marshal_get_stfld_wrapper (MonoType *type) MONO_INTERNAL;
165 mono_marshal_get_ldfld_wrapper (MonoType *type) MONO_INTERNAL;
168 mono_marshal_get_ldflda_wrapper (MonoType *type) MONO_INTERNAL;
171 mono_marshal_get_ldfld_remote_wrapper (MonoClass *klass) MONO_INTERNAL;
174 mono_marshal_get_stfld_remote_wrapper (MonoClass *klass) MONO_INTERNAL;
177 mono_marshal_get_synchronized_wrapper (MonoMethod *method) MONO_INTERNAL;
180 mono_marshal_get_unbox_wrapper (MonoMethod *method) MONO_INTERNAL;
183 mono_marshal_get_isinst (MonoClass *klass) MONO_INTERNAL;
186 mono_marshal_get_castclass (MonoClass *klass) MONO_INTERNAL;
189 mono_marshal_get_proxy_cancast (MonoClass *klass) MONO_INTERNAL;
192 mono_marshal_get_stelemref (void) MONO_INTERNAL;
195 mono_marshal_get_array_address (int rank, int elem_size) MONO_INTERNAL;
198 mono_marshal_get_generic_array_helper (MonoClass *class, MonoClass *iface,
199 gchar *name, MonoMethod *method) MONO_INTERNAL;
202 mono_marshal_get_thunk_invoke_wrapper (MonoMethod *method) MONO_INTERNAL;
204 /* marshaling internal calls */
207 mono_marshal_alloc (gulong size) MONO_INTERNAL;
210 mono_marshal_free (gpointer ptr) MONO_INTERNAL;
213 mono_marshal_free_array (gpointer *ptr, int size) MONO_INTERNAL;
216 mono_marshal_free_ccw (MonoObject* obj) MONO_INTERNAL;
219 ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged (MonoArray *src, gint32 start_index,
220 gpointer dest, gint32 length) MONO_INTERNAL;
223 ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged (gpointer src, gint32 start_index,
224 MonoArray *dest, gint32 length) MONO_INTERNAL;
227 ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr (gpointer ptr, gint32 offset) MONO_INTERNAL;
230 ves_icall_System_Runtime_InteropServices_Marshal_ReadByte (gpointer ptr, gint32 offset) MONO_INTERNAL;
233 ves_icall_System_Runtime_InteropServices_Marshal_ReadInt16 (gpointer ptr, gint32 offset) MONO_INTERNAL;
236 ves_icall_System_Runtime_InteropServices_Marshal_ReadInt32 (gpointer ptr, gint32 offset) MONO_INTERNAL;
239 ves_icall_System_Runtime_InteropServices_Marshal_ReadInt64 (gpointer ptr, gint32 offset) MONO_INTERNAL;
242 ves_icall_System_Runtime_InteropServices_Marshal_WriteByte (gpointer ptr, gint32 offset, unsigned char val) MONO_INTERNAL;
245 ves_icall_System_Runtime_InteropServices_Marshal_WriteIntPtr (gpointer ptr, gint32 offset, gpointer val) MONO_INTERNAL;
248 ves_icall_System_Runtime_InteropServices_Marshal_WriteInt16 (gpointer ptr, gint32 offset, gint16 val) MONO_INTERNAL;
251 ves_icall_System_Runtime_InteropServices_Marshal_WriteInt32 (gpointer ptr, gint32 offset, gint32 val) MONO_INTERNAL;
254 ves_icall_System_Runtime_InteropServices_Marshal_WriteInt64 (gpointer ptr, gint32 offset, gint64 val) MONO_INTERNAL;
257 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi (char *ptr) MONO_INTERNAL;
260 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len (char *ptr, gint32 len) MONO_INTERNAL;
263 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni (guint16 *ptr) MONO_INTERNAL;
266 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len (guint16 *ptr, gint32 len) MONO_INTERNAL;
269 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR (gpointer ptr) MONO_INTERNAL;
272 ves_icall_System_Runtime_InteropServices_Marshal_GetComSlotForMethodInfoInternal (MonoReflectionMethod *m) MONO_INTERNAL;
275 ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error (void) MONO_INTERNAL;
278 ves_icall_System_Runtime_InteropServices_Marshal_SizeOf (MonoReflectionType *rtype) MONO_INTERNAL;
281 ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr (MonoObject *obj, gpointer dst, MonoBoolean delete_old) MONO_INTERNAL;
284 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure (gpointer src, MonoObject *dst) MONO_INTERNAL;
287 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type (gpointer src, MonoReflectionType *type) MONO_INTERNAL;
290 ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf (MonoReflectionType *type, MonoString *field_name) MONO_INTERNAL;
293 ves_icall_System_Runtime_InteropServices_Marshal_StringToBSTR (MonoString *string) MONO_INTERNAL;
296 ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi (MonoString *string) MONO_INTERNAL;
299 ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni (MonoString *string) MONO_INTERNAL;
302 ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure (gpointer src, MonoReflectionType *type) MONO_INTERNAL;
305 ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem (int size) MONO_INTERNAL;
308 ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem (void *ptr) MONO_INTERNAL;
311 ves_icall_System_Runtime_InteropServices_Marshal_ReAllocCoTaskMem (gpointer ptr, int size) MONO_INTERNAL;
314 ves_icall_System_Runtime_InteropServices_Marshal_AllocHGlobal (int size) MONO_INTERNAL;
317 ves_icall_System_Runtime_InteropServices_Marshal_ReAllocHGlobal (gpointer ptr, int size) MONO_INTERNAL;
320 ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal (void *ptr) MONO_INTERNAL;
323 ves_icall_System_Runtime_InteropServices_Marshal_FreeBSTR (void *ptr) MONO_INTERNAL;
326 ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement (MonoArray *arrayobj, int index) MONO_INTERNAL;
329 ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal (void *ftn, MonoReflectionType *type) MONO_INTERNAL;
332 ves_icall_System_Runtime_InteropServices_Marshal_AddRefInternal (gpointer pUnk) MONO_INTERNAL;
335 ves_icall_System_Runtime_InteropServices_Marshal_QueryInterfaceInternal (gpointer pUnk, gpointer riid, gpointer* ppv) MONO_INTERNAL;
338 ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal (gpointer pUnk) MONO_INTERNAL;
341 ves_icall_System_Runtime_InteropServices_Marshal_GetIUnknownForObjectInternal (MonoObject* object) MONO_INTERNAL;
344 ves_icall_System_Runtime_InteropServices_Marshal_GetObjectForCCW (void* pUnk) MONO_INTERNAL;
347 ves_icall_System_Runtime_InteropServices_Marshal_GetIDispatchForObjectInternal (MonoObject* object) MONO_INTERNAL;
350 ves_icall_System_Runtime_InteropServices_Marshal_GetCCW (MonoObject* object, MonoReflectionType* type) MONO_INTERNAL;
353 ves_icall_System_Runtime_InteropServices_Marshal_IsComObject (MonoObject* object) MONO_INTERNAL;
356 ves_icall_System_Runtime_InteropServices_Marshal_ReleaseComObjectInternal (MonoObject* object) MONO_INTERNAL;
359 ves_icall_System_ComObject_CreateRCW (MonoReflectionType *type) MONO_INTERNAL;
362 ves_icall_System_ComObject_ReleaseInterfaces(MonoComObject* obj) MONO_INTERNAL;
365 ves_icall_System_ComObject_GetInterfaceInternal (MonoComObject* obj, MonoReflectionType* type, MonoBoolean throw_exception) MONO_INTERNAL;
368 ves_icall_Mono_Interop_ComInteropProxy_AddProxy (gpointer pUnk, MonoComInteropProxy* proxy) MONO_INTERNAL;
371 ves_icall_Mono_Interop_ComInteropProxy_FindProxy (gpointer pUnk) MONO_INTERNAL;
374 mono_win32_compat_CopyMemory (gpointer dest, gconstpointer source, gsize length);
377 mono_win32_compat_FillMemory (gpointer dest, gsize length, guchar fill);
380 mono_win32_compat_MoveMemory (gpointer dest, gconstpointer source, gsize length);
383 mono_win32_compat_ZeroMemory (gpointer dest, gsize length);
386 mono_marshal_find_nonzero_bit_offset (guint8 *buf, int len, int *byte_offset, guint8 *bitmask) MONO_INTERNAL;
389 mono_signature_no_pinvoke (MonoMethod *method) MONO_INTERNAL;
393 #endif /* __MONO_MARSHAL_H__ */