static void*
ves_icall_marshal_alloc (gulong size);
+void
+mono_string_utf8_to_builder (MonoStringBuilder *sb, char *text);
+
+void
+mono_string_utf16_to_builder (MonoStringBuilder *sb, gunichar2 *text);
+
+gchar*
+mono_string_builder_to_utf8 (MonoStringBuilder *sb);
+
+gunichar2*
+mono_string_builder_to_utf16 (MonoStringBuilder *sb);
+
+void
+mono_string_to_byvalstr (gpointer dst, MonoString *src, int size);
+
+void
+mono_string_to_byvalwstr (gpointer dst, MonoString *src, int size);
+
+gpointer
+mono_delegate_to_ftnptr (MonoDelegate *delegate);
+
+MonoDelegate*
+mono_ftnptr_to_delegate (MonoClass *klass, gpointer ftn);
+
+gpointer
+mono_array_to_savearray (MonoArray *array);
+
+gpointer
+mono_array_to_lparray (MonoArray *array);
+
+void
+mono_free_lparray (MonoArray *array, gpointer* nativeArray);
+
+gpointer
+mono_marshal_asany (MonoObject *obj, MonoMarshalNative string_encoding, int param_attrs);
+
+void
+mono_marshal_free_asany (MonoObject *o, gpointer ptr, MonoMarshalNative string_encoding, int param_attrs);
+
+gpointer
+mono_array_to_savearray (MonoArray *array);
+
+gpointer
+mono_array_to_lparray (MonoArray *array);
+
+void
+mono_free_lparray (MonoArray *array, gpointer* nativeArray);
+
/* Lazy class loading functions */
static GENERATE_GET_CLASS_WITH_CACHE (string_builder, System.Text, StringBuilder)
static GENERATE_GET_CLASS_WITH_CACHE (date_time, System, DateTime)
+static GENERATE_TRY_GET_CLASS_WITH_CACHE (unmanaged_function_pointer_attribute, System.Runtime.InteropServices, UnmanagedFunctionPointerAttribute)
+static GENERATE_TRY_GET_CLASS_WITH_CACHE (icustom_marshaler, System.Runtime.InteropServices, ICustomMarshaler)
/* MonoMethod pointers to SafeHandle::DangerousAddRef and ::DangerousRelease */
static MonoMethod *sh_dangerous_add_ref;
static MonoMethod *sh_dangerous_release;
-
static void
init_safe_handle ()
{
sh_dangerous_add_ref = mono_class_get_method_from_name (
- mono_defaults.safehandle_class, "DangerousAddRef", 1);
+ mono_class_try_get_safehandle_class (), "DangerousAddRef", 1);
sh_dangerous_release = mono_class_get_method_from_name (
- mono_defaults.safehandle_class, "DangerousRelease", 0);
+ mono_class_try_get_safehandle_class (), "DangerousRelease", 0);
}
static void
static void
parse_unmanaged_function_pointer_attr (MonoClass *klass, MonoMethodPInvoke *piinfo)
{
- static MonoClass *UnmanagedFunctionPointerAttribute;
MonoCustomAttrInfo *cinfo;
MonoReflectionUnmanagedFunctionPointerAttribute *attr;
- if (!UnmanagedFunctionPointerAttribute)
- UnmanagedFunctionPointerAttribute = mono_class_from_name (mono_defaults.corlib, "System.Runtime.InteropServices", "UnmanagedFunctionPointerAttribute");
-
/* The attribute is only available in Net 2.0 */
- if (UnmanagedFunctionPointerAttribute) {
+ if (mono_class_try_get_unmanaged_function_pointer_attribute_class ()) {
/*
* The pinvoke attributes are stored in a real custom attribute so we have to
* construct it.
cinfo = mono_custom_attrs_from_class (klass);
if (cinfo && !mono_runtime_get_no_exec ()) {
MonoError error;
- attr = (MonoReflectionUnmanagedFunctionPointerAttribute*)mono_custom_attrs_get_attr_checked (cinfo, UnmanagedFunctionPointerAttribute, &error);
+ attr = (MonoReflectionUnmanagedFunctionPointerAttribute*)mono_custom_attrs_get_attr_checked (cinfo, mono_class_try_get_unmanaged_function_pointer_attribute_class (), &error);
if (attr) {
piinfo->piflags = (attr->call_conv << 8) | (attr->charset ? (attr->charset - 1) * 2 : 1) | attr->set_last_error;
} else {
return;
}
- if (klass != mono_defaults.safehandle_class) {
+ if (klass != mono_class_try_get_safehandle_class ()) {
if ((klass->flags & TYPE_ATTRIBUTE_LAYOUT_MASK) == TYPE_ATTRIBUTE_AUTO_LAYOUT) {
char *msg = g_strdup_printf ("Type %s which is passed to unmanaged code must have a StructLayout attribute.",
mono_type_full_name (&klass->byval_arg));
usize = info->fields [i + 1].offset - info->fields [i].offset;
}
- if (klass != mono_defaults.safehandle_class){
+ if (klass != mono_class_try_get_safehandle_class ()){
/*
* FIXME: Should really check for usize==0 and msize>0, but we apply
* the layout to the managed structure as well.
int pos2;
if (!ICustomMarshaler) {
- MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System.Runtime.InteropServices", "ICustomMarshaler");
+ MonoClass *klass = mono_class_try_get_icustom_marshaler_class ();
if (!klass) {
exception_msg = g_strdup ("Current profile doesn't support ICustomMarshaler");
goto handle_exception;
return mono_cominterop_emit_marshal_safearray (m, argnum, t, spec, conv_arg, conv_arg_type, action);
#endif
- if (mono_defaults.safehandle_class != NULL && t->data.klass &&
- mono_class_is_subclass_of (t->data.klass, mono_defaults.safehandle_class, FALSE))
+ if (mono_class_try_get_safehandle_class () != NULL && t->data.klass &&
+ mono_class_is_subclass_of (t->data.klass, mono_class_try_get_safehandle_class (), FALSE))
return emit_marshal_safehandle (m, argnum, t, spec, conv_arg, conv_arg_type, action);
return emit_marshal_object (m, argnum, t, spec, conv_arg, conv_arg_type, action);
}
#else
MonoMethodSignature *sig, *csig;
+ MonoExceptionClause *clause;
int i, *tmp_locals;
+ int leave_pos;
gboolean closed = FALSE;
- int coop_gc_var, coop_gc_dummy_local;
sig = m->sig;
csig = m->csig;
mono_mb_add_local (mb, sig->ret);
}
+ /*
+ * try {
+ * mono_jit_attach ();
+ *
+ * <interrupt check>
+ *
+ * ret = method (...);
+ * } finally {
+ * mono_jit_detach ();
+ * }
+ *
+ * return ret;
+ */
+
if (mono_threads_is_coop_enabled ()) {
- /* local 4, the local to be used when calling the reset_blocking funcs */
- /* tons of code hardcode 3 to be the return var */
- coop_gc_var = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
- /* local 5, the local used to get a stack address for suspend funcs */
- coop_gc_dummy_local = mono_mb_add_local (mb, &mono_defaults.int_class->byval_arg);
+ clause = g_new0 (MonoExceptionClause, 1);
+ clause->flags = MONO_EXCEPTION_CLAUSE_FINALLY;
}
mono_mb_emit_icon (mb, 0);
mono_mb_emit_stloc (mb, 2);
+ if (mono_threads_is_coop_enabled ()) {
+ /* try { */
+ clause->try_offset = mono_mb_get_label (mb);
+ }
+
/*
* Might need to attach the thread to the JIT or change the
* domain for the callback.
+ *
+ * Also does the (STARTING|BLOCKING|RUNNING) -> RUNNING thread state transtion
+ *
+ * mono_jit_attach ();
*/
mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
mono_mb_emit_byte (mb, CEE_MONO_JIT_ATTACH);
- if (mono_threads_is_coop_enabled ()) {
- /* XXX can we merge reset_blocking_start with JIT_ATTACH above and save one call? */
- mono_mb_emit_ldloc_addr (mb, coop_gc_dummy_local);
- mono_mb_emit_icall (mb, mono_threads_reset_blocking_start);
- mono_mb_emit_stloc (mb, coop_gc_var);
- }
+ /* <interrupt check> */
+ emit_thread_interrupt_checkpoint (mb);
/* we first do all conversions */
tmp_locals = (int *)alloca (sizeof (int) * sig->param_count);
}
}
- emit_thread_interrupt_checkpoint (mb);
-
if (sig->hasthis) {
if (target_handle) {
mono_mb_emit_icon (mb, (gint32)target_handle);
mono_mb_emit_ldarg (mb, i);
}
+ /* ret = method (...) */
mono_mb_emit_managed_call (mb, method, NULL);
if (mspecs [0] && mspecs [0]->native == MONO_NATIVE_CUSTOM) {
}
if (mono_threads_is_coop_enabled ()) {
- /* XXX merge reset_blocking_end with detach */
- mono_mb_emit_ldloc (mb, coop_gc_var);
- mono_mb_emit_ldloc_addr (mb, coop_gc_dummy_local);
- mono_mb_emit_icall (mb, mono_threads_reset_blocking_end);
+ leave_pos = mono_mb_emit_branch (mb, CEE_LEAVE);
+
+ /* } finally { */
+ clause->try_len = mono_mb_get_label (mb) - clause->try_offset;
+ clause->handler_offset = mono_mb_get_label (mb);
}
+ /*
+ * Also does the RUNNING -> (BLOCKING|RUNNING) thread state transition
+ *
+ * mono_jit_detach ();
+ */
mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
mono_mb_emit_byte (mb, CEE_MONO_JIT_DETACH);
+ if (mono_threads_is_coop_enabled ()) {
+ mono_mb_emit_byte (mb, CEE_ENDFINALLY);
+
+ /* } [endfinally] */
+ clause->handler_len = mono_mb_get_pos (mb) - clause->handler_offset;
+
+ mono_mb_patch_branch (mb, leave_pos);
+ }
+
+ /* return ret; */
if (m->retobj_var) {
mono_mb_emit_ldloc (mb, m->retobj_var);
mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
mono_mb_emit_byte (mb, CEE_RET);
}
+ if (mono_threads_is_coop_enabled ()) {
+ mono_mb_set_clauses (mb, 1, clause);
+ }
+
if (closed)
g_free (sig);
#endif
MonoMethod *
mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, uint32_t target_handle)
{
- static MonoClass *UnmanagedFunctionPointerAttribute;
MonoMethodSignature *sig, *csig, *invoke_sig;
MonoMethodBuilder *mb;
MonoMethod *res, *invoke;
mono_marshal_set_callconv_from_modopt (invoke, csig);
- /* Handle the UnmanagedFunctionPointerAttribute */
- if (!UnmanagedFunctionPointerAttribute)
- UnmanagedFunctionPointerAttribute = mono_class_from_name (mono_defaults.corlib, "System.Runtime.InteropServices", "UnmanagedFunctionPointerAttribute");
-
/* The attribute is only available in Net 2.0 */
- if (UnmanagedFunctionPointerAttribute) {
+ if (mono_class_try_get_unmanaged_function_pointer_attribute_class ()) {
MonoCustomAttrInfo *cinfo;
MonoCustomAttrEntry *attr;
if (cinfo) {
for (i = 0; i < cinfo->num_attrs; ++i) {
MonoClass *ctor_class = cinfo->attrs [i].ctor->klass;
- if (mono_class_has_parent (ctor_class, UnmanagedFunctionPointerAttribute)) {
+ if (mono_class_has_parent (ctor_class, mono_class_try_get_unmanaged_function_pointer_attribute_class ())) {
attr = &cinfo->attrs [i];
break;
}
return mono_ftnptr_to_delegate (klass, ftn);
}
+gpointer
+ves_icall_System_Runtime_InteropServices_Marshal_GetFunctionPointerForDelegateInternal (MonoDelegate *delegate)
+{
+ return mono_delegate_to_ftnptr (delegate);
+}
+
/**
* mono_marshal_is_loading_type_info:
*