Pass the --clr-memory-model flag on the command line instead of MONO_DEBUG so its...
[mono-project.git] / mono / metadata / marshal.h
blob7501b687b174e91306743b7b57c491df5d15d852
1 /**
2 * \file
3 * Routines for marshaling complex types in P/Invoke methods.
4 *
5 * Author:
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>
20 #include <mono/metadata/method-builder.h>
21 #include <mono/metadata/remoting.h>
22 #include <mono/utils/mono-error.h>
23 #include <mono/metadata/icalls.h>
25 typedef gunichar2 *mono_bstr;
26 typedef const gunichar2 *mono_bstr_const;
28 #define mono_marshal_find_bitfield_offset(type, elem, byte_offset, bitmask) \
29 do { \
30 type tmp; \
31 memset (&tmp, 0, sizeof (tmp)); \
32 tmp.elem = 1; \
33 mono_marshal_find_nonzero_bit_offset ((guint8*)&tmp, sizeof (tmp), (byte_offset), (bitmask)); \
34 } while (0)
37 GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL(stringbuilder)
41 * This structure holds the state kept by the emit_ marshalling functions.
42 * This is exported so it can be used by cominterop.c.
44 typedef struct {
45 MonoMethodBuilder *mb;
46 MonoMethodSignature *sig;
47 MonoMethodPInvoke *piinfo;
48 int *orig_conv_args; /* Locals containing the original values of byref args */
49 int retobj_var;
50 int vtaddr_var;
51 MonoClass *retobj_class;
52 MonoMethodSignature *csig; /* Might need to be changed due to MarshalAs directives */
53 MonoImage *image; /* The image to use for looking up custom marshallers */
54 } EmitMarshalContext;
56 typedef enum {
58 * This is invoked to convert arguments from the current types to
59 * the underlying types expected by the platform routine. If required,
60 * the methods create a temporary variable with the proper type, and return
61 * the location for it (either the passed argument, or the newly allocated
62 * local slot).
64 MARSHAL_ACTION_CONV_IN,
67 * This operation is called to push the actual value that was optionally
68 * converted on the first stage
70 MARSHAL_ACTION_PUSH,
73 * Convert byref arguments back or free resources allocated during the
74 * CONV_IN stage
76 MARSHAL_ACTION_CONV_OUT,
79 * The result from the unmanaged call is at the top of the stack when
80 * this action is invoked. The result should be stored in the
81 * third local variable slot.
83 MARSHAL_ACTION_CONV_RESULT,
85 MARSHAL_ACTION_MANAGED_CONV_IN,
86 MARSHAL_ACTION_MANAGED_CONV_OUT,
87 MARSHAL_ACTION_MANAGED_CONV_RESULT
88 } MarshalAction;
91 * This is an extension of the MONO_WRAPPER_ enum to avoid adding more elements to that
92 * enum.
94 typedef enum {
95 WRAPPER_SUBTYPE_NONE,
96 /* Subtypes of MONO_WRAPPER_MANAGED_TO_MANAGED */
97 WRAPPER_SUBTYPE_ELEMENT_ADDR,
98 WRAPPER_SUBTYPE_STRING_CTOR,
99 /* Subtypes of MONO_WRAPPER_STELEMREF */
100 WRAPPER_SUBTYPE_VIRTUAL_STELEMREF,
101 /* Subtypes of MONO_WRAPPER_OTHER */
102 WRAPPER_SUBTYPE_FAST_MONITOR_ENTER,
103 WRAPPER_SUBTYPE_FAST_MONITOR_ENTER_V4,
104 WRAPPER_SUBTYPE_FAST_MONITOR_EXIT,
105 WRAPPER_SUBTYPE_PTR_TO_STRUCTURE,
106 WRAPPER_SUBTYPE_STRUCTURE_TO_PTR,
107 /* Subtypes of MONO_WRAPPER_CASTCLASS */
108 WRAPPER_SUBTYPE_CASTCLASS_WITH_CACHE,
109 WRAPPER_SUBTYPE_ISINST_WITH_CACHE,
110 /* Subtypes of MONO_WRAPPER_RUNTIME_INVOKE */
111 WRAPPER_SUBTYPE_RUNTIME_INVOKE_NORMAL,
112 WRAPPER_SUBTYPE_RUNTIME_INVOKE_DYNAMIC,
113 WRAPPER_SUBTYPE_RUNTIME_INVOKE_DIRECT,
114 WRAPPER_SUBTYPE_RUNTIME_INVOKE_VIRTUAL,
115 /* Subtypes of MONO_WRAPPER_MANAGED_TO_NATIVE */
116 WRAPPER_SUBTYPE_ICALL_WRAPPER, // specifically JIT icalls
117 WRAPPER_SUBTYPE_NATIVE_FUNC_AOT,
118 WRAPPER_SUBTYPE_PINVOKE,
119 /* Subtypes of MONO_WRAPPER_OTHER */
120 WRAPPER_SUBTYPE_SYNCHRONIZED_INNER,
121 WRAPPER_SUBTYPE_GSHAREDVT_IN,
122 WRAPPER_SUBTYPE_GSHAREDVT_OUT,
123 WRAPPER_SUBTYPE_ARRAY_ACCESSOR,
124 /* Subtypes of MONO_WRAPPER_MANAGED_TO_MANAGED */
125 WRAPPER_SUBTYPE_GENERIC_ARRAY_HELPER,
126 /* Subtypes of MONO_WRAPPER_DELEGATE_INVOKE */
127 WRAPPER_SUBTYPE_DELEGATE_INVOKE_VIRTUAL,
128 WRAPPER_SUBTYPE_DELEGATE_INVOKE_BOUND,
129 /* Subtypes of MONO_WRAPPER_OTHER */
130 WRAPPER_SUBTYPE_GSHAREDVT_IN_SIG,
131 WRAPPER_SUBTYPE_GSHAREDVT_OUT_SIG,
132 WRAPPER_SUBTYPE_INTERP_IN,
133 WRAPPER_SUBTYPE_INTERP_LMF,
134 WRAPPER_SUBTYPE_AOT_INIT
135 } WrapperSubtype;
137 typedef struct {
138 MonoMethod *method;
139 MonoClass *klass;
140 } NativeToManagedWrapperInfo;
142 typedef struct {
143 MonoMethod *method;
144 } StringCtorWrapperInfo;
146 typedef struct {
147 int kind;
148 } VirtualStelemrefWrapperInfo;
150 typedef struct {
151 guint32 rank, elem_size;
152 } ElementAddrWrapperInfo;
154 typedef struct {
155 MonoMethod *method;
156 /* For WRAPPER_SUBTYPE_RUNTIME_INVOKE_NORMAL */
157 MonoMethodSignature *sig;
158 } RuntimeInvokeWrapperInfo;
160 typedef struct {
161 MonoMethod *method;
162 } ManagedToNativeWrapperInfo;
164 typedef struct {
165 MonoMethod *method;
166 } SynchronizedWrapperInfo;
168 typedef struct {
169 MonoMethod *method;
170 } SynchronizedInnerWrapperInfo;
172 typedef struct {
173 MonoMethod *method;
174 } GenericArrayHelperWrapperInfo;
176 typedef struct {
177 MonoJitICallId jit_icall_id;
178 } ICallWrapperInfo;
180 typedef struct {
181 MonoMethod *method;
182 } ArrayAccessorWrapperInfo;
184 typedef struct {
185 MonoClass *klass;
186 } ProxyWrapperInfo;
188 typedef struct {
189 const char *gc_name;
190 int alloc_type;
191 } AllocatorWrapperInfo;
193 typedef struct {
194 MonoMethod *method;
195 } UnboxWrapperInfo;
197 typedef struct {
198 MonoMethod *method;
199 } RemotingWrapperInfo;
201 typedef struct {
202 MonoMethodSignature *sig;
203 } GsharedvtWrapperInfo;
205 typedef struct {
206 MonoMethod *method;
207 } DelegateInvokeWrapperInfo;
209 typedef struct {
210 MonoMethodSignature *sig;
211 } InterpInWrapperInfo;
213 typedef enum {
214 AOT_INIT_METHOD = 0,
215 AOT_INIT_METHOD_GSHARED_MRGCTX = 1,
216 AOT_INIT_METHOD_GSHARED_THIS = 2,
217 AOT_INIT_METHOD_GSHARED_VTABLE = 3
218 } MonoAotInitSubtype;
220 typedef struct {
221 // We emit this code when we init the module,
222 // and later match up the native code with this method
223 // using the name.
224 MonoAotInitSubtype subtype;
225 } AOTInitWrapperInfo;
228 * This structure contains additional information to uniquely identify a given wrapper
229 * method. It can be retrieved by mono_marshal_get_wrapper_info () for certain types
230 * of wrappers, i.e. ones which do not have a 1-1 association with a method/class.
232 typedef struct {
233 WrapperSubtype subtype;
234 union {
235 /* RUNTIME_INVOKE_... */
236 RuntimeInvokeWrapperInfo runtime_invoke;
237 /* STRING_CTOR */
238 StringCtorWrapperInfo string_ctor;
239 /* ELEMENT_ADDR */
240 ElementAddrWrapperInfo element_addr;
241 /* VIRTUAL_STELEMREF */
242 VirtualStelemrefWrapperInfo virtual_stelemref;
243 /* MONO_WRAPPER_NATIVE_TO_MANAGED */
244 NativeToManagedWrapperInfo native_to_managed;
245 /* MONO_WRAPPER_MANAGED_TO_NATIVE */
246 ManagedToNativeWrapperInfo managed_to_native;
247 /* SYNCHRONIZED */
248 SynchronizedWrapperInfo synchronized;
249 /* SYNCHRONIZED_INNER */
250 SynchronizedInnerWrapperInfo synchronized_inner;
251 /* GENERIC_ARRAY_HELPER */
252 GenericArrayHelperWrapperInfo generic_array_helper;
253 /* ICALL_WRAPPER */
254 ICallWrapperInfo icall;
255 /* ARRAY_ACCESSOR */
256 ArrayAccessorWrapperInfo array_accessor;
257 /* PROXY_ISINST etc. */
258 ProxyWrapperInfo proxy;
259 /* ALLOC */
260 AllocatorWrapperInfo alloc;
261 /* UNBOX */
262 UnboxWrapperInfo unbox;
263 /* MONO_WRAPPER_REMOTING_INVOKE/MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK/MONO_WRAPPER_XDOMAIN_INVOKE */
264 RemotingWrapperInfo remoting;
265 /* GSHAREDVT_IN_SIG/GSHAREDVT_OUT_SIG */
266 GsharedvtWrapperInfo gsharedvt;
267 /* DELEGATE_INVOKE */
268 DelegateInvokeWrapperInfo delegate_invoke;
269 /* INTERP_IN */
270 InterpInWrapperInfo interp_in;
271 /* AOT_INIT */
272 AOTInitWrapperInfo aot_init;
273 } d;
274 } WrapperInfo;
276 typedef enum {
277 STELEMREF_OBJECT, /*no check at all*/
278 STELEMREF_SEALED_CLASS, /*check vtable->klass->element_type */
279 STELEMREF_CLASS, /*only the klass->parents check*/
280 STELEMREF_CLASS_SMALL_IDEPTH, /* like STELEMREF_CLASS bit without the idepth check */
281 STELEMREF_INTERFACE, /*interfaces without variant generic arguments. */
282 STELEMREF_COMPLEX, /*arrays, MBR or types with variant generic args - go straight to icalls*/
283 STELEMREF_KIND_COUNT
284 } MonoStelemrefKind;
287 #define MONO_MARSHAL_CALLBACKS_VERSION 4
289 typedef struct {
290 int version;
291 int (*emit_marshal_array) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
292 int (*emit_marshal_boolean) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
293 int (*emit_marshal_ptr) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
294 int (*emit_marshal_char) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
295 int (*emit_marshal_scalar) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
297 int (*emit_marshal_custom) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
298 int (*emit_marshal_asany) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
299 int (*emit_marshal_vtype) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
300 int (*emit_marshal_string) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
301 int (*emit_marshal_safehandle) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
302 int (*emit_marshal_handleref) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
303 int (*emit_marshal_object) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
304 int (*emit_marshal_variant) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
305 void (*emit_castclass) (MonoMethodBuilder *mb);
306 void (*emit_struct_to_ptr) (MonoMethodBuilder *mb, MonoClass *klass);
307 void (*emit_ptr_to_struct) (MonoMethodBuilder *mb, MonoClass *klass);
308 void (*emit_isinst) (MonoMethodBuilder *mb);
309 void (*emit_virtual_stelemref) (MonoMethodBuilder *mb, const char **param_names, MonoStelemrefKind kind);
310 void (*emit_stelemref) (MonoMethodBuilder *mb);
311 void (*emit_array_address) (MonoMethodBuilder *mb, int rank, int elem_size);
312 void (*emit_native_wrapper) (MonoImage *image, MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func, gboolean aot, gboolean check_exceptions, gboolean func_param);
313 void (*emit_managed_wrapper) (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle);
314 void (*emit_runtime_invoke_body) (MonoMethodBuilder *mb, const char **param_names, MonoImage *image, MonoMethod *method, MonoMethodSignature *sig, MonoMethodSignature *callsig, gboolean virtual_, gboolean need_direct_wrapper);
315 void (*emit_runtime_invoke_dynamic) (MonoMethodBuilder *mb);
316 void (*emit_delegate_begin_invoke) (MonoMethodBuilder *mb, MonoMethodSignature *sig);
317 void (*emit_delegate_end_invoke) (MonoMethodBuilder *mb, MonoMethodSignature *sig);
318 void (*emit_delegate_invoke_internal) (MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodSignature *invoke_sig, gboolean static_method_with_first_arg_bound, gboolean callvirt, gboolean closed_over_null, MonoMethod *method, MonoMethod *target_method, MonoClass *target_class, MonoGenericContext *ctx, MonoGenericContainer *container);
319 void (*emit_synchronized_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoGenericContext *ctx, MonoGenericContainer *container, MonoMethod *enter_method, MonoMethod *exit_method, MonoMethod *gettypefromhandle_method);
320 void (*emit_unbox_wrapper) (MonoMethodBuilder *mb, MonoMethod *method);
321 void (*emit_array_accessor_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *sig, MonoGenericContext *ctx);
322 void (*emit_generic_array_helper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *csig);
323 void (*emit_thunk_invoke_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *csig);
324 void (*emit_create_string_hack) (MonoMethodBuilder *mb, MonoMethodSignature *csig, MonoMethod *res);
325 void (*emit_native_icall_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *csig, gboolean check_exceptions, gboolean aot, MonoMethodPInvoke *pinfo);
326 void (*emit_icall_wrapper) (MonoMethodBuilder *mb, MonoJitICallInfo *callinfo, MonoMethodSignature *csig2, gboolean check_exceptions);
327 void (*emit_return) (MonoMethodBuilder *mb);
328 void (*emit_vtfixup_ftnptr) (MonoMethodBuilder *mb, MonoMethod *method, int param_count, guint16 type);
329 void (*mb_skip_visibility) (MonoMethodBuilder *mb);
330 void (*mb_set_dynamic) (MonoMethodBuilder *mb);
331 void (*mb_emit_exception) (MonoMethodBuilder *mb, const char *exc_nspace, const char *exc_name, const char *msg);
332 void (*mb_emit_exception_for_error) (MonoMethodBuilder *mb, const MonoError *emitted_error);
333 void (*mb_emit_byte) (MonoMethodBuilder *mb, guint8 op);
334 } MonoMarshalCallbacks;
336 /*type of the function pointer of methods returned by mono_marshal_get_runtime_invoke*/
337 typedef MonoObject *(*RuntimeInvokeFunction) (MonoObject *this_obj, void **params, MonoObject **exc, void* compiled_method);
339 typedef void (*RuntimeInvokeDynamicFunction) (void *args, MonoObject **exc, void* compiled_method);
341 void
342 mono_install_marshal_callbacks (MonoMarshalCallbacks *cb);
344 /* marshaling helper functions */
346 void
347 mono_marshal_init (void);
349 void
350 mono_marshal_init_tls (void);
352 void
353 mono_marshal_cleanup (void);
355 gint32
356 mono_class_native_size (MonoClass *klass, guint32 *align);
358 MonoMarshalType *
359 mono_marshal_load_type_info (MonoClass* klass);
361 gint32
362 mono_marshal_type_size (MonoType *type, MonoMarshalSpec *mspec, guint32 *align,
363 gboolean as_field, gboolean unicode);
365 int
366 mono_type_native_stack_size (MonoType *type, guint32 *alignment);
368 mono_bstr
369 mono_ptr_to_bstr (const gunichar2* ptr, int slen);
371 void mono_delegate_free_ftnptr (MonoDelegate *delegate);
373 void
374 mono_marshal_ftnptr_eh_callback (guint32 gchandle);
376 MONO_PAL_API void
377 mono_marshal_set_last_error (void);
379 guint
380 mono_type_to_ldind (MonoType *type);
382 guint
383 mono_type_to_stind (MonoType *type);
385 /* functions to create various architecture independent helper functions */
387 MonoMethod *
388 mono_marshal_method_from_wrapper (MonoMethod *wrapper);
390 WrapperInfo*
391 mono_wrapper_info_create (MonoMethodBuilder *mb, WrapperSubtype subtype);
393 void
394 mono_marshal_set_wrapper_info (MonoMethod *method, WrapperInfo *info);
396 WrapperInfo*
397 mono_marshal_get_wrapper_info (MonoMethod *wrapper) MONO_LLVM_INTERNAL;
399 MonoMethod *
400 mono_marshal_get_delegate_begin_invoke (MonoMethod *method);
402 MonoMethod *
403 mono_marshal_get_delegate_end_invoke (MonoMethod *method);
405 MonoMethod *
406 mono_marshal_get_delegate_invoke (MonoMethod *method, MonoDelegate *del);
408 MonoMethod *
409 mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt, gboolean static_method_with_first_arg_bound, MonoMethod *target_method);
411 MonoMethod *
412 mono_marshal_get_runtime_invoke_full (MonoMethod *method, gboolean virtual_, gboolean need_direct_wrapper);
414 MonoMethod *
415 mono_marshal_get_runtime_invoke (MonoMethod *method, gboolean is_virtual);
417 MonoMethod*
418 mono_marshal_get_runtime_invoke_dynamic (void);
420 MonoMethod *
421 mono_marshal_get_runtime_invoke_for_sig (MonoMethodSignature *sig);
423 MonoMethodSignature*
424 mono_marshal_get_string_ctor_signature (MonoMethod *method);
426 MonoMethod *
427 mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, uint32_t this_loc, MonoError *exernal_error);
429 gpointer
430 mono_marshal_get_vtfixup_ftnptr (MonoImage *image, guint32 token, guint16 type);
432 MonoMethod *
433 mono_marshal_get_icall_wrapper (MonoJitICallInfo *callinfo, gboolean check_exceptions);
435 MonoMethod *
436 mono_marshal_get_aot_init_wrapper (MonoAotInitSubtype subtype) MONO_LLVM_INTERNAL;
438 const char *
439 mono_marshal_get_aot_init_wrapper_name (MonoAotInitSubtype subtype) MONO_LLVM_INTERNAL;
441 MonoMethod *
442 mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions, gboolean aot);
444 MonoMethod *
445 mono_marshal_get_native_func_wrapper (MonoImage *image, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func);
447 MonoMethod*
448 mono_marshal_get_native_func_wrapper_aot (MonoClass *klass);
450 MonoMethod *
451 mono_marshal_get_struct_to_ptr (MonoClass *klass);
453 MonoMethod *
454 mono_marshal_get_ptr_to_struct (MonoClass *klass);
456 MonoMethod *
457 mono_marshal_get_synchronized_wrapper (MonoMethod *method);
459 MonoMethod *
460 mono_marshal_get_synchronized_inner_wrapper (MonoMethod *method);
462 MonoMethod *
463 mono_marshal_get_unbox_wrapper (MonoMethod *method);
465 MonoMethod *
466 mono_marshal_get_castclass_with_cache (void);
468 MonoMethod *
469 mono_marshal_get_isinst_with_cache (void);
471 MonoMethod *
472 mono_marshal_get_stelemref (void);
474 MonoMethod*
475 mono_marshal_get_virtual_stelemref (MonoClass *array_class);
477 MonoMethod**
478 mono_marshal_get_virtual_stelemref_wrappers (int *nwrappers);
480 MonoMethod*
481 mono_marshal_get_array_address (int rank, int elem_size);
483 MonoMethod *
484 mono_marshal_get_array_accessor_wrapper (MonoMethod *method);
486 MonoMethod *
487 mono_marshal_get_generic_array_helper (MonoClass *klass, const gchar *name, MonoMethod *method);
489 MonoMethod *
490 mono_marshal_get_thunk_invoke_wrapper (MonoMethod *method);
492 MonoMethod*
493 mono_marshal_get_gsharedvt_in_wrapper (void);
495 MonoMethod*
496 mono_marshal_get_gsharedvt_out_wrapper (void);
498 void
499 mono_marshal_free_dynamic_wrappers (MonoMethod *method);
501 void
502 mono_marshal_lock_internal (void);
504 void
505 mono_marshal_unlock_internal (void);
507 /* marshaling internal calls */
509 void *
510 mono_marshal_alloc (gsize size, MonoError *error);
512 void
513 mono_marshal_free (gpointer ptr);
515 void
516 mono_marshal_free_array (gpointer *ptr, int size);
518 gboolean
519 mono_marshal_free_ccw (MonoObject* obj);
521 void
522 mono_cominterop_release_all_rcws (void);
524 MONO_API void *
525 mono_marshal_string_to_utf16 (MonoString *s);
527 void
528 mono_marshal_set_last_error_windows (int error);
530 void
531 mono_struct_delete_old (MonoClass *klass, char *ptr);
533 MonoObject*
534 mono_object_isinst_icall (MonoObject *obj, MonoClass *klass);
537 mono_emit_marshal (EmitMarshalContext *m, int argnum, MonoType *t,
538 MonoMarshalSpec *spec, int conv_arg,
539 MonoType **conv_arg_type, MarshalAction action);
541 MonoObject *
542 mono_marshal_isinst_with_cache (MonoObject *obj, MonoClass *klass, uintptr_t *cache);
544 MonoAsyncResult *
545 mono_delegate_begin_invoke (MonoDelegate *delegate, gpointer *params);
547 MonoObject *
548 mono_delegate_end_invoke (MonoDelegate *delegate, gpointer *params);
550 MonoMarshalNative
551 mono_marshal_get_string_encoding (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
553 MonoMarshalConv
554 mono_marshal_get_string_to_ptr_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
556 MonoMarshalConv
557 mono_marshal_get_stringbuilder_to_ptr_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
559 MonoMarshalConv
560 mono_marshal_get_ptr_to_stringbuilder_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec, gboolean *need_free);
562 MonoMarshalConv
563 mono_marshal_get_ptr_to_string_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec, gboolean *need_free);
565 MonoType*
566 mono_marshal_boolean_conv_in_get_local_type (MonoMarshalSpec *spec, guint8 *ldc_op /*out*/);
568 MonoClass*
569 mono_marshal_boolean_managed_conv_in_get_conv_arg_class (MonoMarshalSpec *spec, guint8 *ldop/*out*/);
571 gboolean
572 mono_pinvoke_is_unicode (MonoMethodPInvoke *piinfo);
574 gboolean
575 mono_marshal_need_free (MonoType *t, MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
577 MonoObject* mono_marshal_get_type_object (MonoClass *klass);
579 ICALL_EXPORT
580 guint32
581 ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error (void);
583 ICALL_EXPORT
584 mono_bstr
585 ves_icall_System_Runtime_InteropServices_Marshal_BufferToBSTR (const gunichar2 *ptr, int len);
587 ICALL_EXPORT
588 void
589 ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem (void *ptr);
591 ICALL_EXPORT
592 void
593 ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal (void *ptr);
595 ICALL_EXPORT
596 void
597 ves_icall_System_Runtime_InteropServices_Marshal_FreeBSTR (mono_bstr_const ptr);
599 ICALL_EXPORT
600 void*
601 ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement (MonoArray *arrayobj, int index);
603 ICALL_EXPORT
605 ves_icall_System_Runtime_InteropServices_Marshal_AddRefInternal (MonoIUnknown *pUnk);
607 ICALL_EXPORT
609 ves_icall_System_Runtime_InteropServices_Marshal_QueryInterfaceInternal (MonoIUnknown *pUnk, gconstpointer riid, gpointer* ppv);
611 ICALL_EXPORT
613 ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal (MonoIUnknown *pUnk);
615 MONO_API void
616 mono_win32_compat_CopyMemory (gpointer dest, gconstpointer source, gsize length);
618 MONO_API void
619 mono_win32_compat_FillMemory (gpointer dest, gsize length, guchar fill);
621 MONO_API void
622 mono_win32_compat_MoveMemory (gpointer dest, gconstpointer source, gsize length);
624 MONO_API void
625 mono_win32_compat_ZeroMemory (gpointer dest, gsize length);
627 void
628 mono_marshal_find_nonzero_bit_offset (guint8 *buf, int len, int *byte_offset, guint8 *bitmask) MONO_LLVM_INTERNAL;
630 MonoMethodSignature*
631 mono_signature_no_pinvoke (MonoMethod *method);
633 /* Called from cominterop.c/remoting.c */
635 void
636 mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func, gboolean aot, gboolean check_exceptions, gboolean func_param);
638 void
639 mono_marshal_emit_managed_wrapper (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle);
641 GHashTable*
642 mono_marshal_get_cache (GHashTable **var, GHashFunc hash_func, GCompareFunc equal_func);
644 MonoMethod*
645 mono_marshal_find_in_cache (GHashTable *cache, gpointer key);
647 MonoMethod*
648 mono_mb_create_and_cache (GHashTable *cache, gpointer key,
649 MonoMethodBuilder *mb, MonoMethodSignature *sig,
650 int max_stack);
651 void
652 mono_marshal_emit_thread_interrupt_checkpoint (MonoMethodBuilder *mb);
654 void
655 mono_marshal_emit_thread_force_interrupt_checkpoint (MonoMethodBuilder *mb);
657 void
658 mono_marshal_use_aot_wrappers (gboolean use);
661 mono_mb_emit_save_args (MonoMethodBuilder *mb, MonoMethodSignature *sig, gboolean save_this);
663 void
664 mono_mb_emit_restore_result (MonoMethodBuilder *mb, MonoType *return_type);
666 MonoMethod*
667 mono_mb_create (MonoMethodBuilder *mb, MonoMethodSignature *sig,
668 int max_stack, WrapperInfo *info);
670 MonoMethod*
671 mono_mb_create_and_cache_full (GHashTable *cache, gpointer key,
672 MonoMethodBuilder *mb, MonoMethodSignature *sig,
673 int max_stack, WrapperInfo *info, gboolean *out_found);
675 #endif /* __MONO_MARSHAL_H__ */