+#include <mono/metadata/method-builder.h>
+
+#define mono_marshal_find_bitfield_offset(type, elem, byte_offset, bitmask) \
+ do { \
+ type tmp; \
+ memset (&tmp, 0, sizeof (tmp)); \
+ tmp.elem = 1; \
+ mono_marshal_find_nonzero_bit_offset ((guint8*)&tmp, sizeof (tmp), (byte_offset), (bitmask)); \
+ } while (0)
+
+/*
+ * This structure holds the state kept by the emit_ marshalling functions.
+ * This is exported so it can be used by cominterop.c.
+ */
+typedef struct {
+ MonoMethodBuilder *mb;
+ MonoMethodSignature *sig;
+ MonoMethodPInvoke *piinfo;
+ int *orig_conv_args; /* Locals containing the original values of byref args */
+ int retobj_var;
+ MonoClass *retobj_class;
+ MonoMethodSignature *csig; /* Might need to be changed due to MarshalAs directives */
+ MonoImage *image; /* The image to use for looking up custom marshallers */
+} EmitMarshalContext;
+
+typedef enum {
+ /*
+ * This is invoked to convert arguments from the current types to
+ * the underlying types expected by the platform routine. If required,
+ * the methods create a temporary variable with the proper type, and return
+ * the location for it (either the passed argument, or the newly allocated
+ * local slot).
+ */
+ MARSHAL_ACTION_CONV_IN,
+
+ /*
+ * This operation is called to push the actual value that was optionally
+ * converted on the first stage
+ */
+ MARSHAL_ACTION_PUSH,
+
+ /*
+ * Convert byref arguments back or free resources allocated during the
+ * CONV_IN stage
+ */
+ MARSHAL_ACTION_CONV_OUT,
+
+ /*
+ * The result from the unmanaged call is at the top of the stack when
+ * this action is invoked. The result should be stored in the
+ * third local variable slot.
+ */
+ MARSHAL_ACTION_CONV_RESULT,
+
+ MARSHAL_ACTION_MANAGED_CONV_IN,
+ MARSHAL_ACTION_MANAGED_CONV_OUT,
+ MARSHAL_ACTION_MANAGED_CONV_RESULT
+} MarshalAction;
+
+/*
+ * This is an extension of the MONO_WRAPPER_ enum to avoid adding more elements to that
+ * enum.
+ */
+typedef enum {
+ WRAPPER_SUBTYPE_NONE,
+ /* Subtypes of MONO_WRAPPER_MANAGED_TO_MANAGED */
+ WRAPPER_SUBTYPE_ELEMENT_ADDR,
+ WRAPPER_SUBTYPE_STRING_CTOR,
+ /* Subtypes of MONO_WRAPPER_STELEMREF */
+ WRAPPER_SUBTYPE_VIRTUAL_STELEMREF,
+ /* Subtypes of MONO_WRAPPER_UNKNOWN */
+ WRAPPER_SUBTYPE_FAST_MONITOR_ENTER,
+ WRAPPER_SUBTYPE_FAST_MONITOR_ENTER_V4,
+ WRAPPER_SUBTYPE_FAST_MONITOR_EXIT,
+ WRAPPER_SUBTYPE_PTR_TO_STRUCTURE,
+ WRAPPER_SUBTYPE_STRUCTURE_TO_PTR,
+ /* Subtypes of MONO_WRAPPER_CASTCLASS */
+ WRAPPER_SUBTYPE_CASTCLASS_WITH_CACHE,
+ WRAPPER_SUBTYPE_ISINST_WITH_CACHE,
+ /* Subtypes of MONO_WRAPPER_RUNTIME_INVOKE */
+ WRAPPER_SUBTYPE_RUNTIME_INVOKE_DYNAMIC,
+ WRAPPER_SUBTYPE_RUNTIME_INVOKE_DIRECT,
+ WRAPPER_SUBTYPE_RUNTIME_INVOKE_VIRTUAL,
+ /* Subtypes of MONO_WRAPPER_MANAGED_TO_NATIVE */
+ WRAPPER_SUBTYPE_ICALL_WRAPPER,
+ WRAPPER_SUBTYPE_NATIVE_FUNC_AOT,
+ /* Subtypes of MONO_WRAPPER_UNKNOWN */
+ WRAPPER_SUBTYPE_SYNCHRONIZED_INNER,
+ /* Subtypes of MONO_WRAPPER_MANAGED_TO_MANAGED */
+ WRAPPER_SUBTYPE_GENERIC_ARRAY_HELPER
+} WrapperSubtype;
+
+typedef struct {
+ MonoMethod *method;
+ MonoClass *klass;
+} NativeToManagedWrapperInfo;
+
+typedef struct {
+ MonoMethod *method;
+} StringCtorWrapperInfo;
+
+typedef struct {
+ int kind;
+} VirtualStelemrefWrapperInfo;
+
+typedef struct {
+ guint32 rank, elem_size;
+} ElementAddrWrapperInfo;
+
+typedef struct {
+ MonoMethod *method;
+} RuntimeInvokeWrapperInfo;
+
+typedef struct {
+ MonoMethod *method;
+} ManagedToNativeWrapperInfo;
+
+typedef struct {
+ MonoMethod *method;
+} SynchronizedInnerWrapperInfo;
+
+typedef struct {
+ MonoMethod *method;
+} GenericArrayHelperWrapperInfo;
+
+/*
+ * This structure contains additional information to uniquely identify a given wrapper
+ * method. It can be retrieved by mono_marshal_get_wrapper_info () for certain types
+ * of wrappers, i.e. ones which do not have a 1-1 association with a method/class.
+ */
+typedef struct {
+ WrapperSubtype subtype;
+ union {
+ /* RUNTIME_INVOKE_... */
+ RuntimeInvokeWrapperInfo runtime_invoke;
+ /* STRING_CTOR */
+ StringCtorWrapperInfo string_ctor;
+ /* ELEMENT_ADDR */
+ ElementAddrWrapperInfo element_addr;
+ /* VIRTUAL_STELEMREF */
+ VirtualStelemrefWrapperInfo virtual_stelemref;
+ /* MONO_WRAPPER_NATIVE_TO_MANAGED */
+ NativeToManagedWrapperInfo native_to_managed;
+ /* MONO_WRAPPER_MANAGED_TO_NATIVE */
+ ManagedToNativeWrapperInfo managed_to_native;
+ /* SYNCHRONIZED_INNER */
+ SynchronizedInnerWrapperInfo synchronized_inner;
+ /* GENERIC_ARRAY_HELPER */
+ GenericArrayHelperWrapperInfo generic_array_helper;
+ } d;
+} WrapperInfo;