Remove a few raw pointers, correct some signatures, remove some unnecessary handles...
[mono-project.git] / mono / metadata / marshal.h
blob632c409feea5fea584a92f531c91460386c256aa
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_UNKNOWN */
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,
117 WRAPPER_SUBTYPE_NATIVE_FUNC_AOT,
118 WRAPPER_SUBTYPE_PINVOKE,
119 /* Subtypes of MONO_WRAPPER_UNKNOWN */
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_UNKNOWN */
130 WRAPPER_SUBTYPE_GSHAREDVT_IN_SIG,
131 WRAPPER_SUBTYPE_GSHAREDVT_OUT_SIG,
132 WRAPPER_SUBTYPE_INTERP_IN,
133 WRAPPER_SUBTYPE_INTERP_LMF
134 } WrapperSubtype;
136 typedef struct {
137 MonoMethod *method;
138 MonoClass *klass;
139 } NativeToManagedWrapperInfo;
141 typedef struct {
142 MonoMethod *method;
143 } StringCtorWrapperInfo;
145 typedef struct {
146 int kind;
147 } VirtualStelemrefWrapperInfo;
149 typedef struct {
150 guint32 rank, elem_size;
151 } ElementAddrWrapperInfo;
153 typedef struct {
154 MonoMethod *method;
155 /* For WRAPPER_SUBTYPE_RUNTIME_INVOKE_NORMAL */
156 MonoMethodSignature *sig;
157 } RuntimeInvokeWrapperInfo;
159 typedef struct {
160 MonoMethod *method;
161 } ManagedToNativeWrapperInfo;
163 typedef struct {
164 MonoMethod *method;
165 } SynchronizedWrapperInfo;
167 typedef struct {
168 MonoMethod *method;
169 } SynchronizedInnerWrapperInfo;
171 typedef struct {
172 MonoMethod *method;
173 } GenericArrayHelperWrapperInfo;
175 typedef struct {
176 gpointer func;
177 } ICallWrapperInfo;
179 typedef struct {
180 MonoMethod *method;
181 } ArrayAccessorWrapperInfo;
183 typedef struct {
184 MonoClass *klass;
185 } ProxyWrapperInfo;
187 typedef struct {
188 const char *gc_name;
189 int alloc_type;
190 } AllocatorWrapperInfo;
192 typedef struct {
193 MonoMethod *method;
194 } UnboxWrapperInfo;
196 typedef struct {
197 MonoMethod *method;
198 } RemotingWrapperInfo;
200 typedef struct {
201 MonoMethodSignature *sig;
202 } GsharedvtWrapperInfo;
204 typedef struct {
205 MonoMethod *method;
206 } DelegateInvokeWrapperInfo;
208 typedef struct {
209 MonoMethodSignature *sig;
210 } InterpInWrapperInfo;
213 * This structure contains additional information to uniquely identify a given wrapper
214 * method. It can be retrieved by mono_marshal_get_wrapper_info () for certain types
215 * of wrappers, i.e. ones which do not have a 1-1 association with a method/class.
217 typedef struct {
218 WrapperSubtype subtype;
219 union {
220 /* RUNTIME_INVOKE_... */
221 RuntimeInvokeWrapperInfo runtime_invoke;
222 /* STRING_CTOR */
223 StringCtorWrapperInfo string_ctor;
224 /* ELEMENT_ADDR */
225 ElementAddrWrapperInfo element_addr;
226 /* VIRTUAL_STELEMREF */
227 VirtualStelemrefWrapperInfo virtual_stelemref;
228 /* MONO_WRAPPER_NATIVE_TO_MANAGED */
229 NativeToManagedWrapperInfo native_to_managed;
230 /* MONO_WRAPPER_MANAGED_TO_NATIVE */
231 ManagedToNativeWrapperInfo managed_to_native;
232 /* SYNCHRONIZED */
233 SynchronizedWrapperInfo synchronized;
234 /* SYNCHRONIZED_INNER */
235 SynchronizedInnerWrapperInfo synchronized_inner;
236 /* GENERIC_ARRAY_HELPER */
237 GenericArrayHelperWrapperInfo generic_array_helper;
238 /* ICALL_WRAPPER */
239 ICallWrapperInfo icall;
240 /* ARRAY_ACCESSOR */
241 ArrayAccessorWrapperInfo array_accessor;
242 /* PROXY_ISINST etc. */
243 ProxyWrapperInfo proxy;
244 /* ALLOC */
245 AllocatorWrapperInfo alloc;
246 /* UNBOX */
247 UnboxWrapperInfo unbox;
248 /* MONO_WRAPPER_REMOTING_INVOKE/MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK/MONO_WRAPPER_XDOMAIN_INVOKE */
249 RemotingWrapperInfo remoting;
250 /* GSHAREDVT_IN_SIG/GSHAREDVT_OUT_SIG */
251 GsharedvtWrapperInfo gsharedvt;
252 /* DELEGATE_INVOKE */
253 DelegateInvokeWrapperInfo delegate_invoke;
254 /* INTERP_IN */
255 InterpInWrapperInfo interp_in;
256 } d;
257 } WrapperInfo;
259 typedef enum {
260 STELEMREF_OBJECT, /*no check at all*/
261 STELEMREF_SEALED_CLASS, /*check vtable->klass->element_type */
262 STELEMREF_CLASS, /*only the klass->parents check*/
263 STELEMREF_CLASS_SMALL_IDEPTH, /* like STELEMREF_CLASS bit without the idepth check */
264 STELEMREF_INTERFACE, /*interfaces without variant generic arguments. */
265 STELEMREF_COMPLEX, /*arrays, MBR or types with variant generic args - go straight to icalls*/
266 STELEMREF_KIND_COUNT
267 } MonoStelemrefKind;
270 #define MONO_MARSHAL_CALLBACKS_VERSION 2
272 typedef struct {
273 int version;
274 int (*emit_marshal_array) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
275 int (*emit_marshal_boolean) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
276 int (*emit_marshal_ptr) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
277 int (*emit_marshal_char) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
278 int (*emit_marshal_scalar) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
280 int (*emit_marshal_custom) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
281 int (*emit_marshal_asany) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
282 int (*emit_marshal_vtype) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
283 int (*emit_marshal_string) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
284 int (*emit_marshal_safehandle) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
285 int (*emit_marshal_handleref) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
286 int (*emit_marshal_object) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
287 int (*emit_marshal_variant) (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action);
288 void (*emit_castclass) (MonoMethodBuilder *mb);
289 void (*emit_struct_to_ptr) (MonoMethodBuilder *mb, MonoClass *klass);
290 void (*emit_ptr_to_struct) (MonoMethodBuilder *mb, MonoClass *klass);
291 void (*emit_isinst) (MonoMethodBuilder *mb);
292 void (*emit_virtual_stelemref) (MonoMethodBuilder *mb, const char **param_names, MonoStelemrefKind kind);
293 void (*emit_stelemref) (MonoMethodBuilder *mb);
294 void (*emit_array_address) (MonoMethodBuilder *mb, int rank, int elem_size);
295 void (*emit_native_wrapper) (MonoImage *image, MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func, gboolean aot, gboolean check_exceptions, gboolean func_param);
296 void (*emit_managed_wrapper) (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle);
297 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);
298 void (*emit_runtime_invoke_dynamic) (MonoMethodBuilder *mb);
299 void (*emit_delegate_begin_invoke) (MonoMethodBuilder *mb, MonoMethodSignature *sig);
300 void (*emit_delegate_end_invoke) (MonoMethodBuilder *mb, MonoMethodSignature *sig);
301 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);
302 void (*emit_synchronized_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoGenericContext *ctx, MonoGenericContainer *container, MonoMethod *enter_method, MonoMethod *exit_method, MonoMethod *gettypefromhandle_method);
303 void (*emit_unbox_wrapper) (MonoMethodBuilder *mb, MonoMethod *method);
304 void (*emit_array_accessor_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *sig, MonoGenericContext *ctx);
305 void (*emit_generic_array_helper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *csig);
306 void (*emit_thunk_invoke_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *csig);
307 void (*emit_create_string_hack) (MonoMethodBuilder *mb, MonoMethodSignature *csig, MonoMethod *res);
308 void (*emit_native_icall_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *csig, gboolean check_exceptions, gboolean aot, MonoMethodPInvoke *pinfo);
309 void (*emit_icall_wrapper) (MonoMethodBuilder *mb, MonoMethodSignature *sig, gconstpointer func, MonoMethodSignature *csig2, gboolean check_exceptions);
310 void (*emit_vtfixup_ftnptr) (MonoMethodBuilder *mb, MonoMethod *method, int param_count, guint16 type);
311 void (*mb_skip_visibility) (MonoMethodBuilder *mb);
312 void (*mb_set_dynamic) (MonoMethodBuilder *mb);
313 void (*mb_emit_exception) (MonoMethodBuilder *mb, const char *exc_nspace, const char *exc_name, const char *msg);
314 void (*mb_emit_byte) (MonoMethodBuilder *mb, guint8 op);
315 } MonoMarshalCallbacks;
317 G_BEGIN_DECLS
319 /*type of the function pointer of methods returned by mono_marshal_get_runtime_invoke*/
320 typedef MonoObject *(*RuntimeInvokeFunction) (MonoObject *this_obj, void **params, MonoObject **exc, void* compiled_method);
322 typedef void (*RuntimeInvokeDynamicFunction) (void *args, MonoObject **exc, void* compiled_method);
324 void
325 mono_install_marshal_callbacks (MonoMarshalCallbacks *cb);
327 /* marshaling helper functions */
329 void
330 mono_marshal_init (void);
332 void
333 mono_marshal_init_tls (void);
335 void
336 mono_marshal_cleanup (void);
338 gint32
339 mono_class_native_size (MonoClass *klass, guint32 *align);
341 MonoMarshalType *
342 mono_marshal_load_type_info (MonoClass* klass);
344 gint32
345 mono_marshal_type_size (MonoType *type, MonoMarshalSpec *mspec, guint32 *align,
346 gboolean as_field, gboolean unicode);
348 int
349 mono_type_native_stack_size (MonoType *type, guint32 *alignment);
351 gpointer
352 mono_string_to_ansibstr (MonoString *string_obj);
354 mono_bstr
355 mono_ptr_to_bstr (const gunichar2* ptr, int slen);
357 gpointer
358 mono_string_to_bstr(MonoString* str);
360 void mono_delegate_free_ftnptr (MonoDelegate *delegate);
362 gpointer
363 mono_marshal_asany (MonoObject *obj, MonoMarshalNative string_encoding, int param_attrs);
365 void
366 mono_marshal_free_asany (MonoObject *o, gpointer ptr, MonoMarshalNative string_encoding, int param_attrs);
368 void
369 mono_free_lparray (MonoArray *array, gpointer* nativeArray);
371 void
372 mono_marshal_ftnptr_eh_callback (guint32 gchandle);
374 MONO_PAL_API void
375 mono_marshal_set_last_error (void);
377 guint
378 mono_type_to_ldind (MonoType *type);
380 guint
381 mono_type_to_stind (MonoType *type);
383 void
384 mono_byvalarray_to_byte_array (MonoArray *arr, gpointer native_arr, guint32 elnum);
386 MonoString *
387 mono_string_from_byvalstr (const char *data, int len);
389 MonoString *
390 mono_string_from_byvalwstr (gunichar2 *data, int len);
392 /* functions to create various architecture independent helper functions */
394 MonoMethod *
395 mono_marshal_method_from_wrapper (MonoMethod *wrapper);
397 WrapperInfo*
398 mono_wrapper_info_create (MonoMethodBuilder *mb, WrapperSubtype subtype);
400 void
401 mono_marshal_set_wrapper_info (MonoMethod *method, WrapperInfo *info);
403 WrapperInfo*
404 mono_marshal_get_wrapper_info (MonoMethod *wrapper) MONO_LLVM_INTERNAL;
406 MonoMethod *
407 mono_marshal_get_delegate_begin_invoke (MonoMethod *method);
409 MonoMethod *
410 mono_marshal_get_delegate_end_invoke (MonoMethod *method);
412 MonoMethod *
413 mono_marshal_get_delegate_invoke (MonoMethod *method, MonoDelegate *del);
415 MonoMethod *
416 mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt, gboolean static_method_with_first_arg_bound, MonoMethod *target_method);
418 MonoMethod *
419 mono_marshal_get_runtime_invoke_full (MonoMethod *method, gboolean virtual_, gboolean need_direct_wrapper);
421 MonoMethod *
422 mono_marshal_get_runtime_invoke (MonoMethod *method, gboolean is_virtual);
424 MonoMethod*
425 mono_marshal_get_runtime_invoke_dynamic (void);
427 MonoMethod *
428 mono_marshal_get_runtime_invoke_for_sig (MonoMethodSignature *sig);
430 MonoMethodSignature*
431 mono_marshal_get_string_ctor_signature (MonoMethod *method);
433 MonoMethod *
434 mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, uint32_t this_loc, MonoError *exernal_error);
436 gpointer
437 mono_marshal_get_vtfixup_ftnptr (MonoImage *image, guint32 token, guint16 type);
439 MonoMethod *
440 mono_marshal_get_icall_wrapper (MonoMethodSignature *sig, const char *name, gconstpointer func, gboolean check_exceptions);
442 MonoMethod *
443 mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions, gboolean aot);
445 MonoMethod *
446 mono_marshal_get_native_func_wrapper (MonoImage *image, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func);
448 MonoMethod*
449 mono_marshal_get_native_func_wrapper_aot (MonoClass *klass);
451 MonoMethod *
452 mono_marshal_get_struct_to_ptr (MonoClass *klass);
454 MonoMethod *
455 mono_marshal_get_ptr_to_struct (MonoClass *klass);
457 MonoMethod *
458 mono_marshal_get_synchronized_wrapper (MonoMethod *method);
460 MonoMethod *
461 mono_marshal_get_synchronized_inner_wrapper (MonoMethod *method);
463 MonoMethod *
464 mono_marshal_get_unbox_wrapper (MonoMethod *method);
466 MonoMethod *
467 mono_marshal_get_castclass_with_cache (void);
469 MonoMethod *
470 mono_marshal_get_isinst_with_cache (void);
472 MonoMethod *
473 mono_marshal_get_stelemref (void);
475 MonoMethod*
476 mono_marshal_get_virtual_stelemref (MonoClass *array_class);
478 MonoMethod**
479 mono_marshal_get_virtual_stelemref_wrappers (int *nwrappers);
481 MonoMethod*
482 mono_marshal_get_array_address (int rank, int elem_size);
484 MonoMethod *
485 mono_marshal_get_array_accessor_wrapper (MonoMethod *method);
487 MonoMethod *
488 mono_marshal_get_generic_array_helper (MonoClass *klass, const gchar *name, MonoMethod *method);
490 MonoMethod *
491 mono_marshal_get_thunk_invoke_wrapper (MonoMethod *method);
493 MonoMethod*
494 mono_marshal_get_gsharedvt_in_wrapper (void);
496 MonoMethod*
497 mono_marshal_get_gsharedvt_out_wrapper (void);
499 void
500 mono_marshal_free_dynamic_wrappers (MonoMethod *method);
502 void
503 mono_marshal_lock_internal (void);
505 void
506 mono_marshal_unlock_internal (void);
508 /* marshaling internal calls */
510 void *
511 mono_marshal_alloc (gsize size, MonoError *error);
513 void
514 mono_marshal_free (gpointer ptr);
516 void
517 mono_marshal_free_array (gpointer *ptr, int size);
519 gboolean
520 mono_marshal_free_ccw (MonoObject* obj);
522 void
523 mono_cominterop_release_all_rcws (void);
525 ICALL_EXPORT
526 MonoString*
527 ves_icall_mono_string_from_utf16 (const gunichar2 *data);
529 ICALL_EXPORT
530 char*
531 ves_icall_mono_string_to_utf8 (MonoString *str);
533 void *
534 mono_marshal_string_to_utf16_copy (MonoString *s);
536 MonoString*
537 mono_string_new_len_wrapper (const char *text, guint length);
539 MonoDelegate*
540 mono_ftnptr_to_delegate (MonoClass *klass, gpointer ftn);
542 MONO_API void *
543 mono_marshal_string_to_utf16 (MonoString *s);
545 #ifndef HOST_WIN32
546 gpointer
547 mono_string_to_utf8str (MonoString *string_obj);
548 #endif
550 MonoStringBuilder *
551 mono_string_utf8_to_builder2 (const char *text);
553 MonoStringBuilder *
554 mono_string_utf16_to_builder2 (const gunichar2 *text);
556 gchar*
557 mono_string_builder_to_utf8 (MonoStringBuilder *sb);
559 gunichar2*
560 mono_string_builder_to_utf16 (MonoStringBuilder *sb);
562 void
563 mono_string_utf8_to_builder (MonoStringBuilder *sb, const char *text);
565 void
566 mono_string_utf16_to_builder (MonoStringBuilder *sb, const gunichar2 *text);
568 void
569 mono_string_to_byvalstr (gpointer dst, MonoString *src, int size);
571 void
572 mono_string_to_byvalwstr (gpointer dst, MonoString *src, int size);
574 gpointer
575 mono_delegate_to_ftnptr (MonoDelegate *delegate);
577 gpointer
578 mono_array_to_savearray (MonoArray *array);
580 void
581 mono_free_lparray (MonoArray *array, gpointer* nativeArray);
583 void
584 mono_array_to_byte_byvalarray (gpointer native_arr, MonoArray *arr, guint32 elnum);
586 gpointer
587 mono_array_to_lparray (MonoArray *array);
589 void
590 mono_marshal_set_last_error_windows (int error);
592 void
593 mono_struct_delete_old (MonoClass *klass, char *ptr);
595 MonoObject*
596 mono_object_isinst_icall (MonoObject *obj, MonoClass *klass);
598 ICALL_EXPORT
599 MonoString*
600 ves_icall_string_new_wrapper (const char *text);
603 mono_emit_marshal (EmitMarshalContext *m, int argnum, MonoType *t,
604 MonoMarshalSpec *spec, int conv_arg,
605 MonoType **conv_arg_type, MarshalAction action);
607 MonoObject *
608 mono_marshal_isinst_with_cache (MonoObject *obj, MonoClass *klass, uintptr_t *cache);
610 MonoAsyncResult *
611 mono_delegate_begin_invoke (MonoDelegate *delegate, gpointer *params);
613 MonoObject *
614 mono_delegate_end_invoke (MonoDelegate *delegate, gpointer *params);
616 MonoMarshalNative
617 mono_marshal_get_string_encoding (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
619 MonoMarshalConv
620 mono_marshal_get_string_to_ptr_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
622 MonoMarshalConv
623 mono_marshal_get_stringbuilder_to_ptr_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
625 MonoMarshalConv
626 mono_marshal_get_ptr_to_stringbuilder_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec, gboolean *need_free);
628 MonoMarshalConv
629 mono_marshal_get_ptr_to_string_conv (MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec, gboolean *need_free);
631 MonoType*
632 mono_marshal_boolean_conv_in_get_local_type (MonoMarshalSpec *spec, guint8 *ldc_op /*out*/);
634 MonoClass*
635 mono_marshal_boolean_managed_conv_in_get_conv_arg_class (MonoMarshalSpec *spec, guint8 *ldop/*out*/);
637 gboolean
638 mono_pinvoke_is_unicode (MonoMethodPInvoke *piinfo);
640 gboolean
641 mono_marshal_need_free (MonoType *t, MonoMethodPInvoke *piinfo, MonoMarshalSpec *spec);
643 MonoThreadInfo*
644 mono_icall_start (HandleStackMark *stackmark, MonoError *error);
646 void
647 mono_icall_end (MonoThreadInfo *info, HandleStackMark *stackmark, MonoError *error);
649 MonoObjectHandle
650 mono_icall_handle_new (gpointer rawobj);
652 gpointer
653 mono_icall_handle_new_interior (gpointer rawobj);
655 MonoObject* mono_marshal_get_type_object (MonoClass *klass);
657 ICALL_EXPORT
658 void*
659 ves_icall_marshal_alloc (gsize size);
661 ICALL_EXPORT
662 void
663 ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged (MonoArrayHandle src, gint32 start_index,
664 gpointer dest, gint32 length, gconstpointer managed_source_addr, MonoError *error);
666 ICALL_EXPORT
667 void
668 ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged (gconstpointer src, gint32 start_index,
669 MonoArrayHandle dest, gint32 length, gpointer managed_dest_addr, MonoError *error);
671 ICALL_EXPORT
672 MonoStringHandle
673 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi (const char *ptr, MonoError *error);
675 ICALL_EXPORT
676 MonoStringHandle
677 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len (const char *ptr, gint32 len, MonoError *error);
679 ICALL_EXPORT
680 MonoStringHandle
681 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni (const gunichar2 *ptr, MonoError *error);
683 ICALL_EXPORT
684 MonoStringHandle
685 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringUni_len (const gunichar2 *ptr, gint32 len, MonoError *error);
687 ICALL_EXPORT
688 MonoStringHandle
689 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringBSTR (mono_bstr_const ptr, MonoError *error);
691 ICALL_EXPORT
692 guint32
693 ves_icall_System_Runtime_InteropServices_Marshal_GetComSlotForMethodInfoInternal (MonoReflectionMethodHandle m, MonoError *error);
695 ICALL_EXPORT
696 guint32
697 ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error (void);
699 ICALL_EXPORT
700 guint32
701 ves_icall_System_Runtime_InteropServices_Marshal_SizeOf (MonoReflectionTypeHandle rtype, MonoError *error);
703 ICALL_EXPORT
704 void
705 ves_icall_System_Runtime_InteropServices_Marshal_StructureToPtr (MonoObjectHandle obj, gpointer dst, MonoBoolean delete_old, MonoError *error);
707 ICALL_EXPORT
708 void
709 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure (gconstpointer src, MonoObjectHandle dst, MonoError *error);
711 ICALL_EXPORT
712 MonoObjectHandle
713 ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructure_type (gconstpointer src, MonoReflectionTypeHandle type, MonoError *error);
715 ICALL_EXPORT
717 ves_icall_System_Runtime_InteropServices_Marshal_OffsetOf (MonoReflectionTypeHandle type, MonoStringHandle field_name, MonoError *error);
719 ICALL_EXPORT
720 mono_bstr
721 ves_icall_System_Runtime_InteropServices_Marshal_BufferToBSTR (const gunichar2 *ptr, int len);
723 ICALL_EXPORT
724 char*
725 ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi (const gunichar2 *s, int length, MonoError *error);
727 ICALL_EXPORT
728 gunichar2*
729 ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalUni (const gunichar2 *s, int length, MonoError *error);
731 ICALL_EXPORT
732 void
733 ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure (gpointer src, MonoReflectionTypeHandle type, MonoError *error);
735 ICALL_EXPORT
736 void*
737 ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMem (int size, MonoError *error);
739 ICALL_EXPORT
740 void*
741 ves_icall_System_Runtime_InteropServices_Marshal_AllocCoTaskMemSize (gsize size, MonoError *error);
743 ICALL_EXPORT
744 void
745 ves_icall_System_Runtime_InteropServices_Marshal_FreeCoTaskMem (void *ptr);
747 ICALL_EXPORT
748 gpointer
749 ves_icall_System_Runtime_InteropServices_Marshal_ReAllocCoTaskMem (gpointer ptr, int size, MonoError *error);
751 ICALL_EXPORT
752 void*
753 ves_icall_System_Runtime_InteropServices_Marshal_AllocHGlobal (gsize size, MonoError *error);
755 ICALL_EXPORT
756 gpointer
757 ves_icall_System_Runtime_InteropServices_Marshal_ReAllocHGlobal (gpointer ptr, gsize size, MonoError *error);
759 ICALL_EXPORT
760 void
761 ves_icall_System_Runtime_InteropServices_Marshal_FreeHGlobal (void *ptr);
763 ICALL_EXPORT
764 void
765 ves_icall_System_Runtime_InteropServices_Marshal_FreeBSTR (mono_bstr_const ptr);
767 ICALL_EXPORT
768 void*
769 ves_icall_System_Runtime_InteropServices_Marshal_UnsafeAddrOfPinnedArrayElement (MonoArray *arrayobj, int index);
771 ICALL_EXPORT
772 MonoDelegateHandle
773 ves_icall_System_Runtime_InteropServices_Marshal_GetDelegateForFunctionPointerInternal (void *ftn, MonoReflectionTypeHandle type, MonoError *error);
775 ICALL_EXPORT
776 gpointer
777 ves_icall_System_Runtime_InteropServices_Marshal_GetFunctionPointerForDelegateInternal (MonoDelegateHandle delegate, MonoError *error);
779 ICALL_EXPORT
781 ves_icall_System_Runtime_InteropServices_Marshal_AddRefInternal (MonoIUnknown *pUnk);
783 ICALL_EXPORT
785 ves_icall_System_Runtime_InteropServices_Marshal_QueryInterfaceInternal (MonoIUnknown *pUnk, gconstpointer riid, gpointer* ppv);
787 ICALL_EXPORT
789 ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal (MonoIUnknown *pUnk);
791 ICALL_EXPORT
792 void*
793 ves_icall_System_Runtime_InteropServices_Marshal_GetIUnknownForObjectInternal (MonoObjectHandle object, MonoError *error);
795 ICALL_EXPORT
796 MonoObjectHandle
797 ves_icall_System_Runtime_InteropServices_Marshal_GetObjectForCCW (void* pUnk, MonoError *error);
799 ICALL_EXPORT
800 void*
801 ves_icall_System_Runtime_InteropServices_Marshal_GetIDispatchForObjectInternal (MonoObjectHandle object, MonoError *error);
803 ICALL_EXPORT
804 void*
805 ves_icall_System_Runtime_InteropServices_Marshal_GetCCW (MonoObjectHandle object, MonoReflectionTypeHandle type, MonoError *error);
807 ICALL_EXPORT
808 MonoBoolean
809 ves_icall_System_Runtime_InteropServices_Marshal_IsComObject (MonoObjectHandle object, MonoError *error);
811 ICALL_EXPORT
812 gint32
813 ves_icall_System_Runtime_InteropServices_Marshal_ReleaseComObjectInternal (MonoObjectHandle object, MonoError *error);
815 ICALL_EXPORT
816 MonoObjectHandle
817 ves_icall_System_ComObject_CreateRCW (MonoReflectionTypeHandle ref_type, MonoError *error);
819 ICALL_EXPORT
820 void
821 mono_System_ComObject_ReleaseInterfaces (MonoComObjectHandle obj);
823 ICALL_EXPORT
824 void
825 ves_icall_System_ComObject_ReleaseInterfaces (MonoComObjectHandle obj, MonoError *error);
827 ICALL_EXPORT
828 gpointer
829 ves_icall_System_ComObject_GetInterfaceInternal (MonoComObjectHandle obj, MonoReflectionTypeHandle ref_type, MonoBoolean throw_exception, MonoError *error);
831 ICALL_EXPORT
832 void
833 ves_icall_Mono_Interop_ComInteropProxy_AddProxy (gpointer pUnk, MonoComInteropProxyHandle proxy, MonoError *error);
835 ICALL_EXPORT
836 MonoComInteropProxyHandle
837 ves_icall_Mono_Interop_ComInteropProxy_FindProxy (gpointer pUnk, MonoError *error);
839 MONO_API void
840 mono_win32_compat_CopyMemory (gpointer dest, gconstpointer source, gsize length);
842 MONO_API void
843 mono_win32_compat_FillMemory (gpointer dest, gsize length, guchar fill);
845 MONO_API void
846 mono_win32_compat_MoveMemory (gpointer dest, gconstpointer source, gsize length);
848 MONO_API void
849 mono_win32_compat_ZeroMemory (gpointer dest, gsize length);
851 void
852 mono_marshal_find_nonzero_bit_offset (guint8 *buf, int len, int *byte_offset, guint8 *bitmask) MONO_LLVM_INTERNAL;
854 MonoMethodSignature*
855 mono_signature_no_pinvoke (MonoMethod *method);
857 /* Called from cominterop.c/remoting.c */
859 void
860 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);
862 void
863 mono_marshal_emit_managed_wrapper (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle);
865 GHashTable*
866 mono_marshal_get_cache (GHashTable **var, GHashFunc hash_func, GCompareFunc equal_func);
868 MonoMethod*
869 mono_marshal_find_in_cache (GHashTable *cache, gpointer key);
871 MonoMethod*
872 mono_mb_create_and_cache (GHashTable *cache, gpointer key,
873 MonoMethodBuilder *mb, MonoMethodSignature *sig,
874 int max_stack);
875 void
876 mono_marshal_emit_thread_interrupt_checkpoint (MonoMethodBuilder *mb);
878 void
879 mono_marshal_emit_thread_force_interrupt_checkpoint (MonoMethodBuilder *mb);
881 void
882 mono_marshal_use_aot_wrappers (gboolean use);
884 MonoObject *
885 mono_marshal_xdomain_copy_value (MonoObject *val, MonoError *error);
887 ICALL_EXPORT
888 MonoObject *
889 ves_icall_mono_marshal_xdomain_copy_value (MonoObject *val);
892 mono_mb_emit_save_args (MonoMethodBuilder *mb, MonoMethodSignature *sig, gboolean save_this);
894 void
895 mono_mb_emit_restore_result (MonoMethodBuilder *mb, MonoType *return_type);
897 MonoMethod*
898 mono_mb_create (MonoMethodBuilder *mb, MonoMethodSignature *sig,
899 int max_stack, WrapperInfo *info);
901 MonoMethod*
902 mono_mb_create_and_cache_full (GHashTable *cache, gpointer key,
903 MonoMethodBuilder *mb, MonoMethodSignature *sig,
904 int max_stack, WrapperInfo *info, gboolean *out_found);
906 G_END_DECLS
908 #endif /* __MONO_MARSHAL_H__ */