Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions runtime/coreclr-bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,30 @@
return rv;
}

MonoException *
xamarin_create_system_exception (const char *message)
{
MonoException *rv = xamarin_bridge_create_exception (XamarinExceptionTypes_System_Exception, message);
LOG_CORECLR (stderr, "%s (%p) => %p\n", __func__, message, rv);
return rv;
}

MonoException *
xamarin_create_system_invalid_cast_exception (const char *message)
{
MonoException *rv = xamarin_bridge_create_exception (XamarinExceptionTypes_System_InvalidCastException, message);
LOG_CORECLR (stderr, "%s (%p) => %p\n", __func__, message, rv);
return rv;
}

MonoException *
xamarin_create_system_entry_point_not_found_exception (const char *entrypoint)
{
MonoException *rv = xamarin_bridge_create_exception (XamarinExceptionTypes_System_EntryPointNotFoundException, entrypoint);
LOG_CORECLR (stderr, "%s (%p) => %p\n", __func__, entrypoint, rv);
return rv;
}

MonoMethodSignature *
mono_method_signature (MonoMethod* method)
{
Expand Down
9 changes: 9 additions & 0 deletions runtime/delegates.t4
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@
OnlyCoreCLR = true,
},

new XDelegate ("MonoObject *", "MonoObject *", "xamarin_bridge_create_exception",
"enum XamarinExceptionTypes", "Runtime.ExceptionType", "type",
"const char *", "IntPtr", "arg0"
) {
WrappedManagedFunction = "CreateException",
OnlyDynamicUsage = false,
OnlyCoreCLR = true,
},

new XDelegate ("MonoMethodSignature *", "IntPtr", "xamarin_bridge_method_get_signature",
"MonoObject *", "MonoObject *", "method"
) {
Expand Down
4 changes: 3 additions & 1 deletion runtime/exports.t4
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@
"const char *", "name_space",
"const char *", "name",
"const char *", "msg"
),
) {
XamarinRuntime = RuntimeMode.MonoVM,
},

new Export ("MonoException *", "mono_get_exception_out_of_memory"),

Expand Down
18 changes: 18 additions & 0 deletions runtime/monovm-bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,24 @@
return cls == mono_get_string_class ();
}

MonoException *
xamarin_create_system_invalid_cast_exception (const char *message)
{
return (MonoException *) mono_exception_from_name_msg (mono_get_corlib (), "System", "InvalidCastException", message);
}

MonoException *
xamarin_create_system_exception (const char *message)
{
return (MonoException *) mono_exception_from_name_msg (mono_get_corlib (), "System", "Exception", message);
}

MonoException *
xamarin_create_system_entry_point_not_found_exception (const char *entrypoint)
{
return (MonoException *) mono_exception_from_name_msg (mono_get_corlib (), "System", "EntryPointNotFoundException", entrypoint);
}

#if DOTNET

bool
Expand Down
6 changes: 3 additions & 3 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
// COOP: calls mono, needs to be in UNSAFE mode.
MONO_ASSERT_GC_UNSAFE;

return (MonoException *) mono_exception_from_name_msg (mono_get_corlib (), "System", "Exception", msg);
return xamarin_create_system_exception (msg);
}

MonoMethod *
Expand Down Expand Up @@ -648,7 +648,7 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
"Additional information:\n"
"\tSelector: %s\n"
"\tMethod: %s\n", from_name, class_getName(from_class), to_name, sel_getName (sel), method_full_name);
MonoException *mono_ex = mono_exception_from_name_msg (mono_get_corlib (), "System", "InvalidCastException", msg);
MonoException *mono_ex = xamarin_create_system_invalid_cast_exception (msg);
mono_free (from_name);
mono_free (to_name);
xamarin_free (msg);
Expand Down Expand Up @@ -759,7 +759,7 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
//
// char *method_full_name = mono_method_full_name (method, TRUE);
// char *msg = xamarin_strdup_printf (m, obj, object_getClassName (obj), class_getName (expected_class), sel, method_full_name, index);
// MonoException *mono_ex = mono_exception_from_name_msg (mono_get_corlib (), "System", "InvalidCastException", msg);
// MonoException *mono_ex = xamarin_create_system_invalid_cast_exception (msg);
// xamarin_free (msg);
// mono_free (method_full_name);
// mono_raise_exception (mono_ex);
Expand Down
7 changes: 7 additions & 0 deletions runtime/xamarin/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ enum XamarinLookupTypes : int {
XamarinLookupTypes_ObjCRuntime_INativeObject,
};

// Keep in sync with Runtime.ExceptionType in Runtime.CoreCLR.cs
enum XamarinExceptionTypes : int {
XamarinExceptionTypes_System_Exception,
XamarinExceptionTypes_System_InvalidCastException,
XamarinExceptionTypes_System_EntryPointNotFoundException,
};

extern bool mono_use_llvm; // this is defined inside mono

#if DEBUG
Expand Down
3 changes: 3 additions & 0 deletions runtime/xamarin/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ void xamarin_process_managed_exception_gchandle (GCHandle gchandle);
void xamarin_throw_product_exception (int code, const char *message);
GCHandle xamarin_create_product_exception (int code, const char *message);
GCHandle xamarin_create_product_exception_with_inner_exception (int code, GCHandle inner_exception_gchandle /* will be freed */, const char *message);
MonoException * xamarin_create_system_exception (const char *message);
MonoException * xamarin_create_system_invalid_cast_exception (const char *message);
MonoException * xamarin_create_system_entry_point_not_found_exception (const char *entrypoint);
NSString * xamarin_print_all_exceptions (GCHandle handle);

id xamarin_invoke_objc_method_implementation (id self, SEL sel, IMP xamarin_impl);
Expand Down
29 changes: 29 additions & 0 deletions src/ObjCRuntime/Runtime.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ internal enum TypeLookup {
ObjCRuntime_INativeObject,
}

// Keep in sync with XamarinExceptionType in main.h
internal enum ExceptionType {
System_Exception,
System_InvalidCastException,
System_EntryPointNotFoundException,
}

// This struct must be kept in sync with the _MonoObject struct in coreclr-bridge.h
[StructLayout (LayoutKind.Sequential)]
internal struct MonoObject {
Expand Down Expand Up @@ -66,6 +73,28 @@ internal static void RegisterToggleReferenceCoreCLR (NSObject obj, IntPtr handle
Console.WriteLine ("Not implemented: RegisterToggleReferenceCoreCLR");
}

static unsafe MonoObject* CreateException (ExceptionType type, IntPtr arg0)
{
Exception rv = null;
var str0 = Marshal.PtrToStringAuto (arg0);

switch (type) {
case ExceptionType.System_Exception:
rv = new System.Exception (str0);
break;
case ExceptionType.System_InvalidCastException:
rv = new System.InvalidCastException (str0);
break;
case ExceptionType.System_EntryPointNotFoundException:
rv = new System.EntryPointNotFoundException (str0);
break;
default:
throw new ArgumentOutOfRangeException (nameof (type));
}

return (MonoObject*) GetMonoObject (rv);
}

// Returns a retained MonoObject. Caller must release.
static IntPtr FindAssembly (IntPtr assembly_name)
{
Expand Down
2 changes: 1 addition & 1 deletion tools/common/StaticRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4782,7 +4782,7 @@ string TryGeneratePInvokeWrapper (PInvokeWrapperGenerator state, MethodDefinitio
sb.WriteLine ("{");
if (is_stret) {
sb.StringBuilder.AppendLine ("#if defined (__arm64__)");
sb.WriteLine ("xamarin_process_managed_exception ((MonoObject *) mono_exception_from_name_msg (mono_get_corlib (), \"System\", \"EntryPointNotFoundException\", \"{0}\"));", pinfo.EntryPoint);
sb.WriteLine ("xamarin_process_managed_exception (xamarin_create_system_entry_point_not_found_exception (\"{0}\"));", pinfo.EntryPoint);
sb.StringBuilder.AppendLine ("#else");
}
sb.WriteLine ("@try {");
Expand Down