Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[runtime] Redirect to our objc_msgSend wrapper functions when needed for .NET code. #10932

Merged
merged 5 commits into from
Mar 24, 2021
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
4 changes: 3 additions & 1 deletion runtime/exports.t4
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@
"const char *", "func",
"const char *", "tdll",
"const char *", "tfunc"
),
) {
Mode = DotNetMode.OnlyLegacy,
},

#endregion

Expand Down
5 changes: 5 additions & 0 deletions runtime/runtime-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ extern "C" {

void *xamarin_marshal_return_value (SEL sel, MonoType *mtype, const char *type, MonoObject *retval, bool retain, MonoMethod *method, MethodDescription *desc, GCHandle *exception_gchandle);

void xamarin_dyn_objc_msgSend ();
void xamarin_dyn_objc_msgSendSuper ();
void xamarin_dyn_objc_msgSend_stret ();
void xamarin_dyn_objc_msgSendSuper_stret ();

#ifdef __cplusplus
}
#endif
Expand Down
19 changes: 19 additions & 0 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,9 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
xamarin_initialize_dynamic_runtime (NULL);
#endif

#if !DOTNET
xamarin_insert_dllmap ();
#endif

MONO_ENTER_GC_UNSAFE;

Expand Down Expand Up @@ -2449,6 +2451,8 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
return exception_gchandle;
return handle;
}

#if !DOTNET
void
xamarin_insert_dllmap ()
{
Expand All @@ -2467,6 +2471,7 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
LOG (PRODUCT ": Added dllmap for objc_msgSend");
#endif // defined (__i386__) || defined (__x86_64__)
}
#endif // !DOTNET

#if DOTNET
void
Expand Down Expand Up @@ -2499,6 +2504,20 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;

if (!strcmp (libraryName, "__Internal")) {
symbol = dlsym (RTLD_DEFAULT, entrypointName);
#if defined (__i386__) || defined (__x86_64__)
} else if (!strcmp (libraryName, "/usr/lib/libobjc.dylib")) {
if (xamarin_marshal_objectivec_exception_mode != MarshalObjectiveCExceptionModeDisable) {
if (!strcmp (entrypointName, "objc_msgSend")) {
symbol = (void *) &xamarin_dyn_objc_msgSend;
} else if (!strcmp (entrypointName, "objc_msgSendSuper")) {
symbol = (void *) &xamarin_dyn_objc_msgSendSuper;
} else if (!strcmp (entrypointName, "objc_msgSend_stret")) {
symbol = (void *) &xamarin_dyn_objc_msgSend_stret;
} else if (!strcmp (entrypointName, "objc_msgSendSuper_stret")) {
symbol = (void *) &xamarin_dyn_objc_msgSendSuper_stret;
}
}
#endif // defined (__i386__) || defined (__x86_64__)
}

return symbol;
Expand Down
8 changes: 0 additions & 8 deletions tests/monotouch-test/ObjCRuntime/ExceptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ public void ObjCException ()
Assert.Ignore ("This test only works in debug mode in the simulator.");
#endif

#if NET && (__MACOS__ || __MACCATALYST__)
Assert.Ignore ("Exception marshalling hasn't been completely implemented on macOS/Mac Catalyst yet, due to removal of the dllmap support");
#endif

InstallHandlers ();

try {
Expand Down Expand Up @@ -149,10 +145,6 @@ public void ManagedExceptionPassthrough ()
#endif
var hasDebugger = global::System.Diagnostics.Debugger.IsAttached;

#if NET && (__MACOS__ || __MACCATALYST__)
Assert.Ignore ("Exception marshalling hasn't been completely implemented on macOS/Mac Catalyst yet, due to removal of the dllmap support");
#endif

InstallHandlers ();
try {
using (var e = new ManagedExceptionTest ()) {
Expand Down
1 change: 0 additions & 1 deletion tests/monotouch-test/dotnet/macOS/monotouch-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<DefineConstants>$(DefineConstants);MONOMAC;XAMMAC_TESTS</DefineConstants>
<DefineConstants Condition="'$(Configuration)' == 'Debug'">$(DefineConstants);DEBUG;DYNAMIC_REGISTRAR</DefineConstants>
<RootTestsDirectory>..\..\..</RootTestsDirectory>
<MonoBundlingExtraArgs>--marshal-objectivec-exceptions:disable</MonoBundlingExtraArgs>
</PropertyGroup>

<ItemGroup>
Expand Down
7 changes: 0 additions & 7 deletions tools/common/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,14 +1359,7 @@ public void SetObjectiveCExceptionMode ()
break;
case ApplePlatform.MacOSX:
case ApplePlatform.MacCatalyst:
#if NET
// Mono doesn't support dllmaps for Mac Catalyst / macOS in .NET for now:
// macOS: https://github.com/dotnet/runtime/issues/43204
// Mac Catalyst: https://github.com/dotnet/runtime/issues/48110
MarshalObjectiveCExceptions = MarshalObjectiveCExceptionMode.Disable;
#else
MarshalObjectiveCExceptions = EnableDebug ? MarshalObjectiveCExceptionMode.ThrowManagedException : MarshalObjectiveCExceptionMode.Disable;
#endif
break;
default:
throw ErrorHelper.CreateError (71, Errors.MX0071 /* Unknown platform: {0}. This usually indicates a bug in {1}; please file a bug report at https://github.com/xamarin/xamarin-macios/issues/new with a test case. */, Platform, ProductName);
Expand Down
5 changes: 0 additions & 5 deletions tools/common/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,7 @@ void GenerateMacMain (StringWriter sw)
sw.WriteLine ("\txamarin_executable_name = \"{0}\";", App.AssemblyName);
if (!App.IsDefaultMarshalManagedExceptionMode)
sw.WriteLine ("\txamarin_marshal_managed_exception_mode = MarshalManagedExceptionMode{0};", App.MarshalManagedExceptions);
#if NET
// We require support for dllmap, which isn't in .NET/macOS yet (https://github.com/dotnet/runtime/issues/43204), so disable
sw.WriteLine ("\txamarin_marshal_objectivec_exception_mode = MarshalObjectiveCExceptionModeDisable;");
#else
sw.WriteLine ("\txamarin_marshal_objectivec_exception_mode = MarshalObjectiveCExceptionMode{0};", App.MarshalObjectiveCExceptions);
#endif
if (App.DisableLldbAttach.HasValue ? App.DisableLldbAttach.Value : !App.EnableDebug)
sw.WriteLine ("\txamarin_disable_lldb_attach = true;");
if (App.DisableOmitFramePointer ?? App.EnableDebug)
Expand Down