Skip to content

Commit a25e98d

Browse files
committed
feeedback
1 parent 624737e commit a25e98d

File tree

8 files changed

+28
-9
lines changed

8 files changed

+28
-9
lines changed

src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static partial class PlatformDetection
3333
public static bool IsNotMonoInterpreter => !IsMonoInterpreter;
3434
public static bool IsMonoAOT => Environment.GetEnvironmentVariable("MONO_AOT_MODE") == "aot";
3535
public static bool IsNotMonoAOT => Environment.GetEnvironmentVariable("MONO_AOT_MODE") != "aot";
36+
public static bool IsNotMonoAOTOrBrowser => IsNotMonoAOT && !IsBrowser;
3637
public static bool IsNativeAot => IsNotMonoRuntime && !IsReflectionEmitSupported;
3738
public static bool IsNotNativeAot => !IsNativeAot;
3839
public static bool IsFreeBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"));

src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ private static IntPtr InternalGetFunctionPointer(AssemblyLoadContext alc,
350350
{
351351
Delegate d = Delegate.CreateDelegate(delegateType, type, methodName)!;
352352

353+
#pragma warning disable CA1416 // This call site is reachable on all platforms.
353354
functionPtr = Marshal.GetFunctionPointerForDelegate(d);
355+
#pragma warning restore CA1416
354356

355357
lock (s_delegates)
356358
{

src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,15 +1137,21 @@ public static TDelegate GetDelegateForFunctionPointer<TDelegate>(IntPtr ptr)
11371137

11381138
[RequiresDynamicCode("Marshalling code for the delegate might not be available. Use the GetFunctionPointerForDelegate<TDelegate> overload instead.")]
11391139
[EditorBrowsable(EditorBrowsableState.Never)]
1140+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("browser")]
1141+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("wasi")]
11401142
public static IntPtr GetFunctionPointerForDelegate(Delegate d)
11411143
{
11421144
ArgumentNullException.ThrowIfNull(d);
11431145

1146+
if (OperatingSystem.IsWasi() || OperatingSystem.IsBrowser()) throw new PlatformNotSupportedException(SR.PlatformNotSupported_DynamicEntrypoint);
1147+
11441148
return GetFunctionPointerForDelegateInternal(d);
11451149
}
11461150

11471151
[UnconditionalSuppressMessage("AotAnalysis", "IL3050:AotUnfriendlyApi",
11481152
Justification = "AOT compilers can see the T.")]
1153+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("browser")]
1154+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("wasi")]
11491155
public static IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d) where TDelegate : notnull
11501156
{
11511157
return GetFunctionPointerForDelegate((Delegate)(object)d);

src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,11 @@ public static void FreeHGlobal(System.IntPtr hglobal) { }
10701070
public static System.IntPtr GetExceptionPointers() { throw null; }
10711071
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Marshalling code for the delegate might not be available. Use the GetFunctionPointerForDelegate<TDelegate> overload instead.")]
10721072
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
1073+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("browser")]
1074+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("wasi")]
10731075
public static System.IntPtr GetFunctionPointerForDelegate(System.Delegate d) { throw null; }
1076+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("browser")]
1077+
[System.Runtime.Versioning.SupportedOSPlatformAttribute("wasi")]
10741078
public static System.IntPtr GetFunctionPointerForDelegate<TDelegate>(TDelegate d) where TDelegate : notnull { throw null; }
10751079
[System.Diagnostics.CodeAnalysis.RequiresAssemblyFiles("Windows only assigns HINSTANCE to assemblies loaded from disk. This API will return -1 for modules without a file on disk.")]
10761080
public static System.IntPtr GetHINSTANCE(System.Reflection.Module m) { throw null; }

src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetDelegateForFunctionPointerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace System.Runtime.InteropServices.Tests
1313
{
14-
[ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)]
14+
[ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))]
1515
public class GetDelegateForFunctionPointerTests
1616
{
1717
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))]

src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetFunctionPointerForDelegateTests.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ namespace System.Runtime.InteropServices.Tests
1010
{
1111
public class GetFunctionPointerForDelegateTests
1212
{
13-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))]
14-
[ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)]
13+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOTOrBrowser))]
1514
public void GetFunctionPointerForDelegate_NormalDelegateNonGeneric_ReturnsExpected()
1615
{
1716
MethodInfo targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static);
@@ -23,8 +22,7 @@ public void GetFunctionPointerForDelegate_NormalDelegateNonGeneric_ReturnsExpect
2322
Assert.Equal(pointer1, pointer2);
2423
}
2524

26-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))]
27-
[ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)]
25+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOTOrBrowser))]
2826
public void GetFunctionPointerForDelegate_MarshalledDelegateNonGeneric_ReturnsExpected()
2927
{
3028
MethodInfo targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static);
@@ -40,8 +38,7 @@ public void GetFunctionPointerForDelegate_MarshalledDelegateNonGeneric_ReturnsEx
4038
Assert.Equal(pointer1, pointer2);
4139
}
4240

43-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))]
44-
[ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)]
41+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOTOrBrowser))]
4542
public void GetFunctionPointerForDelegate_NormalDelegateGeneric_ReturnsExpected()
4643
{
4744
MethodInfo targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static);
@@ -53,8 +50,7 @@ public void GetFunctionPointerForDelegate_NormalDelegateGeneric_ReturnsExpected(
5350
Assert.Equal(pointer1, pointer2);
5451
}
5552

56-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOT))]
57-
[ActiveIssue("https://github.com/dotnet/runtime/issues/39187", TestPlatforms.Browser)]
53+
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoAOTOrBrowser))]
5854
public void GetFunctionPointerForDelegate_MarshalledDelegateGeneric_ReturnsExpected()
5955
{
6056
MethodInfo targetMethod = typeof(GetFunctionPointerForDelegateTests).GetMethod(nameof(Method), BindingFlags.NonPublic | BindingFlags.Static);

src/mono/browser/runtime/runtime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ init_icall_table (void)
197197
static void*
198198
get_native_to_interp (MonoMethod *method, void *extra_arg)
199199
{
200+
assert (method);
201+
200202
void *addr = NULL;
201203
MONO_ENTER_GC_UNSAFE;
202204
MonoClass *klass = mono_method_get_class (method);

src/mono/mono/mini/interp/interp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,6 +3469,14 @@ interp_create_method_pointer (MonoMethod *method, gboolean compile, MonoError *e
34693469
if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED) {
34703470
WrapperInfo *info = mono_marshal_get_wrapper_info (method);
34713471
MonoMethod *orig_method = info->d.native_to_managed.method;
3472+
if (!orig_method) {
3473+
char *s = mono_method_get_full_name (method);
3474+
char *msg = g_strdup_printf ("No native to managed transition for method '%s', missing [UnmanagedCallersOnly] attribute.", s);
3475+
mono_error_set_platform_not_supported (error, msg);
3476+
g_free (s);
3477+
g_free (msg);
3478+
return NULL;
3479+
}
34723480

34733481
/*
34743482
* These are called from native code. Ask the host app for a trampoline.

0 commit comments

Comments
 (0)