remove GenericVectorTests from rsp (#17366)
[mono-project.git] / mono / metadata / marshal.h
blobb65786cb5d3d92a1a96a0d5b2b002fb26f784ad6
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 WRAPPER_SUBTYPE_LLVM_FUNC
136 } WrapperSubtype;
138 typedef struct {
139 MonoMethod *method;
140 MonoClass *klass;
141 } NativeToManagedWrapperInfo;
143 typedef struct {
144 MonoMethod *method;
145 } StringCtorWrapperInfo;
147 typedef struct {
148 int kind;
149 } VirtualStelemrefWrapperInfo;
151 typedef struct {
152 guint32 rank, elem_size;
153 } ElementAddrWrapperInfo;
155 typedef struct {
156 MonoMethod *method;
157 /* For WRAPPER_SUBTYPE_RUNTIME_INVOKE_NORMAL */
158 MonoMethodSignature *sig;
159 } RuntimeInvokeWrapperInfo;
161 typedef struct {
162 MonoMethod *method;
163 } ManagedToNativeWrapperInfo;
165 typedef struct {
166 MonoMethod *method;
167 } SynchronizedWrapperInfo;
169 typedef struct {
170 MonoMethod *method;
171 } SynchronizedInnerWrapperInfo;
173 typedef struct {
174 MonoMethod *method;
175 } GenericArrayHelperWrapperInfo;
177 typedef struct {
178 MonoJitICallId jit_icall_id;
179 } ICallWrapperInfo;
181 typedef struct {
182 MonoMethod *method;
183 } ArrayAccessorWrapperInfo;
185 typedef struct {
186 MonoClass *klass;
187 } ProxyWrapperInfo;
189 typedef struct {
190 const char *gc_name;
191 int alloc_type;
192 } AllocatorWrapperInfo;
194 typedef struct {
195 MonoMethod *method;
196 } UnboxWrapperInfo;
198 typedef struct {
199 MonoMethod *method;
200 } RemotingWrapperInfo;
202 typedef struct {
203 MonoMethodSignature *sig;
204 } GsharedvtWrapperInfo;
206 typedef struct {
207 MonoMethod *method;
208 } DelegateInvokeWrapperInfo;
210 typedef struct {
211 MonoMethodSignature *sig;
212 } InterpInWrapperInfo;
214 typedef enum {
215 AOT_INIT_METHOD = 0,
216 AOT_INIT_METHOD_GSHARED_MRGCTX = 1,
217 AOT_INIT_METHOD_GSHARED_THIS = 2,
218 AOT_INIT_METHOD_GSHARED_VTABLE = 3
219 } MonoAotInitSubtype;
221 typedef struct {
222 // We emit this code when we init the module,
223 // and later match up the native code with this method
224 // using the name.
225 MonoAotInitSubtype subtype;
226 } AOTInitWrapperInfo;
228 typedef enum {
229 LLVM_FUNC_WRAPPER_GC_POLL = 0
230 } MonoLLVMFuncWrapperSubtype;
232 typedef struct {
233 // We emit this code when we init the module,
234 // and later match up the native code with this method
235 // using the name.
236 MonoLLVMFuncWrapperSubtype subtype;
237 } LLVMFuncWrapperInfo;
240 * This structure contains additional information to uniquely identify a given wrapper
241 * method. It can be retrieved by mono_marshal_get_wrapper_info () for certain types
242 * of wrappers, i.e. ones which do not have a 1-1 association with a method/class.
244 typedef struct {
245 WrapperSubtype subtype;
246 union {
247 /* RUNTIME_INVOKE_... */
248 RuntimeInvokeWrapperInfo runtime_invoke;
249 /* STRING_CTOR */
250 StringCtorWrapperInfo string_ctor;
251 /* ELEMENT_ADDR */
252 ElementAddrWrapperInfo element_addr;
253 /* VIRTUAL_STELEMREF */
254 VirtualStelemrefWrapperInfo virtual_stelemref;
255 /* MONO_WRAPPER_NATIVE_TO_MANAGED */
256 NativeToManagedWrapperInfo native_to_managed;
257 /* MONO_WRAPPER_MANAGED_TO_NATIVE */
258 ManagedToNativeWrapperInfo managed_to_native;
259 /* SYNCHRONIZED */
260 SynchronizedWrapperInfo synchronized;
261 /* SYNCHRONIZED_INNER */
262 SynchronizedInnerWrapperInfo synchronized_inner;
263 /* GENERIC_ARRAY_HELPER */
264 GenericArrayHelperWrapperInfo generic_array_helper;
265 /* ICALL_WRAPPER */
266 ICallWrapperInfo icall;
267 /* ARRAY_ACCESSOR */
268 ArrayAccessorWrapperInfo array_accessor;
269 /* PROXY_ISINST etc. */
270 ProxyWrapperInfo proxy;
271 /* ALLOC */
272 AllocatorWrapperInfo alloc;
273 /* UNBOX */
274 UnboxWrapperInfo unbox;
275 /* MONO_WRAPPER_REMOTING_INVOKE/MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK/MONO_WRAPPER_XDOMAIN_INVOKE */
276 RemotingWrapperInfo remoting;
277 /* GSHAREDVT_IN_SIG/GSHAREDVT_OUT_SIG */
278 GsharedvtWrapperInfo gsharedvt;
279 /* DELEGATE_INVOKE */
280 DelegateInvokeWrapperInfo delegate_invoke;
281 /* INTERP_IN */
282 InterpInWrapperInfo interp_in;
283 /* AOT_INIT */
284 AOTInitWrapperInfo aot_init;
285 /* LLVM_FUNC */
286 LLVMFuncWrapperInfo llvm_func;
287 } d;
288 } WrapperInfo;
290 typedef enum {
291 STELEMREF_OBJECT, /*no check at all*/
292 STELEMREF_SEALED_CLASS, /*check vtable->klass->element_type */
293 STELEMREF_CLASS, /*only the klass->parents check*/
294 STELEMREF_CLASS_SMALL_IDEPTH, /* like STELEMREF_CLASS bit without the idepth check */
295 STELEMREF_INTERFACE, /*interfaces without variant generic arguments. */
296 STELEMREF_COMPLEX, /*arrays, MBR or types with variant generic args - go straight to icalls*/
297 STELEMREF_KIND_COUNT
298 } MonoStelemrefKind;
301 #define MONO_MARSHAL_CALLBACKS_VERSION 4
303 typedef struct {
304 int version;
305 int (*emit_marshal_array) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
306 int (*emit_marshal_boolean) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
307 int (*emit_marshal_ptr) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
308 int (*emit_marshal_char) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
309 int (*emit_marshal_scalar) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
311 int (*emit_marshal_custom) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
312 int (*emit_marshal_asany) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
313 int (*emit_marshal_vtype) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
314 int (*emit_marshal_string) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
315 int (*emit_marshal_safehandle) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
316 int (*emit_marshal_handleref) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
317 int (*emit_marshal_object) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
318 int (*emit_marshal_variant) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
319 void (*emit_castclass) (MonoMethodBuilder *mb);
320 void (*emit_struct_to_ptr) (MonoMethodBuilder *mb, MonoClass *klass);
321 void (*emit_ptr_to_struct) (MonoMethodBuilder *mb, MonoClass *klass);
322 void (*emit_isinst) (MonoMethodBuilder *mb);
323 void (*emit_virtual_stelemref) (MonoMethodBuilder *mb, const char **param_names, MonoStelemrefKind kind);
324 void (*emit_stelemref) (MonoMethodBuilder *mb);
325 void (*emit_array_address) (MonoMethodBuilder *mb, int rank, int elem_size);
326 void (*emit_native_wrapper) (MonoImage *image, MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func, gboolean aot, gboolean check_exceptions, gboolean func_param);
327 void (*emit_managed_wrapper) (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle);
328 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);
329 void (*emit_runtime_invoke_dynamic) (MonoMethodBuilder *mb);
330 void (*emit_delegate_begin_invoke) (MonoMethodBuilder *mb, MonoMethodSignature *sig);
331 void (*emit_delegate_end_invoke) (MonoMethodBuilder *mb, MonoMethodSignature *sig);
332 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);
333 void (*emit_synchronized_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoGenericContext *ctx, MonoGenericContainer *container, MonoMethod *enter_method, MonoMethod *exit_method, MonoMethod *gettypefromhandle_method);
334 void (*emit_unbox_wrapper) (MonoMethodBuilder *mb, MonoMethod *method);
335 void (*emit_array_accessor_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *sig, MonoGenericContext *ctx);
336 void (*emit_generic_array_helper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *csig);
337 void (*emit_thunk_invoke_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *csig);
338 void (*emit_create_string_hack) (MonoMethodBuilder *mb, MonoMethodSignature *csig, MonoMethod *res);
339 void (*emit_native_icall_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *csig, gboolean check_exceptions, gboolean aot, MonoMethodPInvoke *pinfo);
340 void (*emit_icall_wrapper) (MonoMethodBuilder *mb, MonoJitICallInfo *callinfo, MonoMethodSignature *csig2, gboolean check_exceptions);
341 void (*emit_return) (MonoMethodBuilder *mb);
342 void (*emit_vtfixup_ftnptr) (MonoMethodBuilder *mb, MonoMethod *method, int param_count, guint16 type);
343 void (*mb_skip_visibility) (MonoMethodBuilder *mb);
344 void (*mb_set_dynamic) (MonoMethodBuilder *mb);
345 void (*mb_emit_exception) (MonoMethodBuilder *mb, const char *exc_nspace, const char *exc_name, const char *msg);
346 void (*mb_emit_exception_for_error) (MonoMethodBuilder *mb, const MonoError *emitted_error);
347 void (*mb_emit_byte) (MonoMethodBuilder *mb, guint8 op);
348 } MonoMarshalCallbacks;
350 /*type of the function pointer of methods returned by mono_marshal_get_runtime_invoke*/
351 typedef MonoObject *(*RuntimeInvokeFunction) (MonoObject *this_obj, void **params, MonoObject **exc, void* compiled_method);
353 typedef void (*RuntimeInvokeDynamicFunction) (void *args, MonoObject **exc, void* compiled_method);
355 void
356 mono_install_marshal_callbacks (MonoMarshalCallbacks *cb);
358 /* marshaling helper functions */
360 void
361 mono_marshal_init (void);
363 void
364 mono_marshal_init_tls (void);
366 void
367 mono_marshal_cleanup (void);
369 gint32
370 mono_class_native_size (MonoClass *klass, guint32 *align);
372 MonoMarshalType *
373 mono_marshal_load_type_info (MonoClass* klass);
375 gint32
376 mono_marshal_type_size (MonoType *type, MonoMarshalSpec *mspec, guint32 *align,
377 gboolean as_field, gboolean unicode);
379 int
380 mono_type_native_stack_size (MonoType *type, guint32 *alignment);
382 mono_bstr
383 mono_ptr_to_bstr (const gunichar2* ptr, int slen);
385 void mono_delegate_free_ftnptr (MonoDelegate *delegate);
387 void
388 mono_marshal_ftnptr_eh_callback (guint32 gchandle);
390 MONO_PAL_API void
391 mono_marshal_set_last_error (void);
393 void
394 mono_marshal_clear_last_error (void);
396 guint
397 mono_type_to_ldind (MonoType *type);
399 guint
400 mono_type_to_stind (MonoType *type);
402 /* functions to create various architecture independent helper functions */
404 MonoMethod *
405 mono_marshal_method_from_wrapper (MonoMethod *wrapper);
407 WrapperInfo*
408 mono_wrapper_info_create (MonoMethodBuilder *mb, WrapperSubtype subtype);
410 void
411 mono_marshal_set_wrapper_info (MonoMethod *method, WrapperInfo *info);
413 WrapperInfo*
414 mono_marshal_get_wrapper_info (MonoMethod *wrapper) MONO_LLVM_INTERNAL;
416 MonoMethod *
417 mono_marshal_get_delegate_begin_invoke (MonoMethod *method);
419 MonoMethod *
420 mono_marshal_get_delegate_end_invoke (MonoMethod *method);
422 MonoMethod *
423 mono_marshal_get_delegate_invoke (MonoMethod *method, MonoDelegate *del);
425 MonoMethod *
426 mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt, gboolean static_method_with_first_arg_bound, MonoMethod *target_method);
428 MonoMethod *
429 mono_marshal_get_runtime_invoke_full (MonoMethod *method, gboolean virtual_, gboolean need_direct_wrapper);
431 MonoMethod *
432 mono_marshal_get_runtime_invoke (MonoMethod *method, gboolean is_virtual);
434 MonoMethod*
435 mono_marshal_get_runtime_invoke_dynamic (void);
437 MonoMethod *
438 mono_marshal_get_runtime_invoke_for_sig (MonoMethodSignature *sig);
440 MonoMethodSignature*
441 mono_marshal_get_string_ctor_signature (MonoMethod *method);
443 MonoMethod *
444 mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, uint32_t this_loc, MonoError *exernal_error);
446 gpointer
447 mono_marshal_get_vtfixup_ftnptr (MonoImage *image, guint32 token, guint16 type);
449 MonoMethod *
450 mono_marshal_get_icall_wrapper (MonoJitICallInfo *callinfo, gboolean check_exceptions);
452 MonoMethod *
453 mono_marshal_get_aot_init_wrapper (MonoAotInitSubtype subtype) MONO_LLVM_INTERNAL;
455 const char *
456 mono_marshal_get_aot_init_wrapper_name (MonoAotInitSubtype subtype) MONO_LLVM_INTERNAL;
458 MonoMethod *
459 mono_marshal_get_llvm_func_wrapper (MonoLLVMFuncWrapperSubtype subtype) MONO_LLVM_INTERNAL;
461 MonoMethod *
462 mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions, gboolean aot);
464 MonoMethod *
465 mono_marshal_get_native_func_wrapper (MonoImage *image, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func);
467 MonoMethod*
468 mono_marshal_get_native_func_wrapper_aot (MonoClass *klass);
470 MonoMethod *
471 mono_marshal_get_struct_to_ptr (MonoClass *klass);
473 MonoMethod *
474 mono_marshal_get_ptr_to_struct (MonoClass *klass);
476 MonoMethod *
477 mono_marshal_get_synchronized_wrapper (MonoMethod *method);
479 MonoMethod *
480 mono_marshal_get_synchronized_inner_wrapper (MonoMethod *method);
482 MonoMethod *
483 mono_marshal_get_unbox_wrapper (MonoMethod *method);
485 MonoMethod *
486 mono_marshal_get_castclass_with_cache (void);
488 MonoMethod *
489 mono_marshal_get_isinst_with_cache (void);
491 MonoMethod *
492 mono_marshal_get_stelemref (void);
494 MonoMethod*
495 mono_marshal_get_virtual_stelemref (MonoClass *array_class);
497 MonoMethod**
498 mono_marshal_get_virtual_stelemref_wrappers (int *nwrappers);
500 MonoMethod*
501 mono_marshal_get_array_address (int rank, int elem_size);
503 MonoMethod *
504 mono_marshal_get_array_accessor_wrapper (MonoMethod *method);
506 MonoMethod *
507 mono_marshal_get_generic_array_helper (MonoClass *klass, const gchar *name, MonoMethod *method);
509 MonoMethod *
510 mono_marshal_get_thunk_invoke_wrapper (MonoMethod *method);
512 MonoMethod*
513 mono_marshal_get_gsharedvt_in_wrapper (void);
515 MonoMethod*
516 mono_marshal_get_gsharedvt_out_wrapper (void);
518 void
519 mono_marshal_free_dynamic_wrappers (MonoMethod *method);
521 void
522 mono_marshal_lock_internal (void);
524 void
525 mono_marshal_unlock_internal (void);
527 /* marshaling internal calls */
529 void *
530 mono_marshal_alloc (gsize size, MonoError *error);
532 void
533 mono_marshal_free (gpointer ptr);
535 void
536 mono_marshal_free_array (gpointer *ptr, int size);
538 gboolean
539 mono_marshal_free_ccw (MonoObject* obj);
541 void
542 mono_cominterop_release_all_rcws (void);
544 MONO_API void *
545 mono_marshal_string_to_utf16 (MonoString *s);
547 void
548 mono_marshal_set_last_error_windows (int error);
550 void
551 mono_struct_delete_old (MonoClass *klass, char *ptr);
554 mono_emit_marshal (EmitMarshalContext *m, int argnum, MonoType *t,
555 MonoMarshalSpec *spec, int conv_arg,
556 MonoType **conv_arg_type, MarshalAction action);
558 MonoObject *
559 mono_marshal_isinst_with_cache (MonoObject *obj, MonoClass *klass, uintptr_t *cache);
561 MonoAsyncResult *
562 mono_delegate_begin_invoke (MonoDelegate *delegate, gpointer *params);
564 MonoObject *
565 mono_delegate_end_invoke (MonoDelegate *delegate, gpointer *params);
567 MonoMarshalNative
568 mono_marshal_get_string_encoding (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
570 MonoMarshalConv
571 mono_marshal_get_string_to_ptr_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
573 MonoMarshalConv
574 mono_marshal_get_stringbuilder_to_ptr_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
576 MonoMarshalConv
577 mono_marshal_get_ptr_to_stringbuilder_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec, gboolean *need_free);
579 MonoMarshalConv
580 mono_marshal_get_ptr_to_string_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec, gboolean *need_free);
582 MonoType*
583 mono_marshal_boolean_conv_in_get_local_type (MonoMarshalSpec *spec, guint8 *ldc_op /*out*/);
585 MonoClass*
586 mono_marshal_boolean_managed_conv_in_get_conv_arg_class (MonoMarshalSpec *spec, guint8 *ldop/*out*/);
588 gboolean
589 mono_pinvoke_is_unicode (MonoMethodPInvoke *piinfo);
591 gboolean
592 mono_marshal_need_free (MonoType *t, MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
594 MonoObject* mono_marshal_get_type_object (MonoClass *klass);
596 ICALL_EXPORT
597 guint32
598 ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error (void);
600 ICALL_EXPORT
601 void
602 ves_icall_System_Runtime_InteropServices_Marshal_SetLastWin32Error (guint32 err);
604 ICALL_EXPORT
605 mono_bstr
606 ves_icall_System_Runtime_InteropServices_Marshal_BufferToBSTR (const gunichar2 *ptr, int len);
608 ICALL_EXPORT
609 void
610 ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem (void *ptr);
612 ICALL_EXPORT
613 void
614 ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal (void *ptr);
616 ICALL_EXPORT
617 void
618 ves_icall_System_Runtime_InteropServices_Marshal_FreeBSTR (mono_bstr_const ptr);
620 ICALL_EXPORT
622 ves_icall_System_Runtime_InteropServices_Marshal_AddRefInternal (MonoIUnknown *pUnk);
624 ICALL_EXPORT
626 ves_icall_System_Runtime_InteropServices_Marshal_QueryInterfaceInternal (MonoIUnknown *pUnk, gconstpointer riid, gpointer* ppv);
628 ICALL_EXPORT
630 ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal (MonoIUnknown *pUnk);
632 MONO_API void
633 mono_win32_compat_CopyMemory (gpointer dest, gconstpointer source, gsize length);
635 MONO_API void
636 mono_win32_compat_FillMemory (gpointer dest, gsize length, guchar fill);
638 MONO_API void
639 mono_win32_compat_MoveMemory (gpointer dest, gconstpointer source, gsize length);
641 MONO_API void
642 mono_win32_compat_ZeroMemory (gpointer dest, gsize length);
644 void
645 mono_marshal_find_nonzero_bit_offset (guint8 *buf, int len, int *byte_offset, guint8 *bitmask) MONO_LLVM_INTERNAL;
647 MonoMethodSignature*
648 mono_signature_no_pinvoke (MonoMethod *method);
650 /* Called from cominterop.c/remoting.c */
652 void
653 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);
655 void
656 mono_marshal_emit_managed_wrapper (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle);
658 GHashTable*
659 mono_marshal_get_cache (GHashTable **var, GHashFunc hash_func, GCompareFunc equal_func);
661 MonoMethod*
662 mono_marshal_find_in_cache (GHashTable *cache, gpointer key);
664 MonoMethod*
665 mono_mb_create_and_cache (GHashTable *cache, gpointer key,
666 MonoMethodBuilder *mb, MonoMethodSignature *sig,
667 int max_stack);
668 void
669 mono_marshal_emit_thread_interrupt_checkpoint (MonoMethodBuilder *mb);
671 void
672 mono_marshal_emit_thread_force_interrupt_checkpoint (MonoMethodBuilder *mb);
674 void
675 mono_marshal_use_aot_wrappers (gboolean use);
678 mono_mb_emit_save_args (MonoMethodBuilder *mb, MonoMethodSignature *sig, gboolean save_this);
680 void
681 mono_mb_emit_restore_result (MonoMethodBuilder *mb, MonoType *return_type);
683 MonoMethod*
684 mono_mb_create (MonoMethodBuilder *mb, MonoMethodSignature *sig,
685 int max_stack, WrapperInfo *info);
687 MonoMethod*
688 mono_mb_create_and_cache_full (GHashTable *cache, gpointer key,
689 MonoMethodBuilder *mb, MonoMethodSignature *sig,
690 int max_stack, WrapperInfo *info, gboolean *out_found);
692 #endif /* __MONO_MARSHAL_H__ */