Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.Versioning;

namespace System.Runtime.InteropServices.ObjectiveC
Expand Down Expand Up @@ -39,6 +40,16 @@
out int memInSizeT,
out IntPtr mem);

[StackTraceHidden]

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug CoreCLR_Libraries)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug CoreCLR_Libraries)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 release CoreCLR_Libraries)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 release CoreCLR_Libraries)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug Libraries_CheckedCoreCLR)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-arm64 Debug Libraries_CheckedCoreCLR)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Libraries_CheckedCoreCLR)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Libraries_CheckedCoreCLR)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build tvos-arm64 Release AllSubsets_CoreCLR_Smoke)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build tvos-arm64 Release AllSubsets_CoreCLR_Smoke)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build ios-arm64 Release AllSubsets_CoreCLR_Smoke)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime (Build ios-arm64 Release AllSubsets_CoreCLR_Smoke)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests (Build osx-x64 release Runtime_Release)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests (Build osx-x64 release Runtime_Release)

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / dotnet-linker-tests

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHiddenAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs

View check run for this annotation

Azure Pipelines / runtime

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs#L43

src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/ObjectiveCMarshal.CoreCLR.cs(43,10): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'StackTraceHidden' could not be found (are you missing a using directive or an assembly reference?)
internal static void ThrowPendingExceptionObject()
{
Exception? ex = System.StubHelpers.StubHelpers.GetPendingExceptionObject();
if (ex is not null)
{
ExceptionDispatchInfo.Throw(ex);
}
}

[UnmanagedCallersOnly]
internal static unsafe void* InvokeUnhandledExceptionPropagation(Exception* pExceptionArg, IntPtr methodDesc, IntPtr* pContext, Exception* pException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,16 @@ protected override MethodILData CreateValueFromKey(MethodDesc key)
&& key.IsPInvoke
&& _compilationModuleGroup.GeneratesPInvoke(key))
{
methodIL = PInvokeILEmitter.EmitIL(key);
try
{
methodIL = PInvokeILEmitter.EmitIL(key);
}
catch (RequiresRuntimeJitException)
{
// The P/Invoke IL emitter will throw for known unsupported scenarios.
// We don't propagate the exception and keep methodIL as null - this causes a fall back to JIT during runtime.
// We store the null methodIL in the IL cache so we don't keep trying to emit unsupported P/Invoke IL.
}
}

return new MethodILData() { Method = key, MethodIL = methodIL };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,13 @@ public sealed override bool GeneratesPInvoke(MethodDesc method)
if (!VersionsWithMethodBody(method))
return false;

return !Marshaller.IsMarshallingRequired(method);
if (!Marshaller.IsMarshallingRequired(method))
return true;

if (MarshalHelpers.ShouldCheckForPendingException(method.Context.Target, method.GetPInvokeMethodMetadata()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed yesterday, this check here looks wrong. This check is already done as part of Marshaller.IsMarshallingRequired and I believe it should be removed from there. In your case, this method is returning true for pinvokes with non-blittable types that require check for pending exception. It should be returning false instead and I believe this is the reason you are forcefully catching the requires jit exception above. If the checks here would be correct, you shouldn't need to do that.

return true;

return false;
}

public sealed override bool TryGetModuleTokenForExternalType(TypeDesc type, out ModuleToken token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ private void EmitPInvokeCall(PInvokeILCodeStreams ilCodeStreams)

callsiteSetupCodeStream.Emit(ILOpcode.call, emitter.NewToken(rawTargetMethod));

if (MarshalHelpers.ShouldCheckForPendingException(context.Target, _importMetadata))
{
MetadataType objcMarshalType = context.SystemModule.GetKnownType(
"System.Runtime.InteropServices.ObjectiveC"u8, "ObjectiveCMarshal"u8);
callsiteSetupCodeStream.Emit(ILOpcode.call, emitter.NewToken(
objcMarshalType.GetKnownMethod("ThrowPendingExceptionObject"u8, null)));
}

static PInvokeTargetNativeMethod AllocateTargetNativeMethod(MethodDesc targetMethod, MethodSignature nativeSigArg)
{
var contextMethods = s_contexts.GetOrCreateValue(targetMethod.Context);
Expand All @@ -72,9 +80,6 @@ private MethodIL EmitIL()
if (!_importMetadata.Flags.PreserveSig)
throw new NotSupportedException();

if (MarshalHelpers.ShouldCheckForPendingException(_targetMethod.Context.Target, _importMetadata))
throw new NotSupportedException();

if (_targetMethod.IsUnmanagedCallersOnly)
throw new NotSupportedException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3125,23 +3125,11 @@ private bool pInvokeMarshalingRequired(CORINFO_METHOD_STRUCT_* handle, CORINFO_S
return true;
}

MethodIL stubIL = null;
try
MethodIL stubIL = _compilation.GetMethodIL(method);
if (stubIL == null)
{
stubIL = _compilation.GetMethodIL(method);
if (stubIL == null)
{
// This is the case of a PInvoke method that requires marshallers, which we can't use in this compilation
Debug.Assert(!_compilation.NodeFactory.CompilationModuleGroup.GeneratesPInvoke(method));
return true;
}
}
catch (RequiresRuntimeJitException)
{
// The PInvoke IL emitter will throw for known unsupported scenario. We cannot propagate the exception here since
// this interface call might be used to check if a certain pinvoke can be inlined in the caller. Throwing means that the
// caller will not get compiled. Instead, we'll return true to let the JIT know that it cannot inline the pinvoke, and
// the actual pinvoke call will be handled by a stub that we create and compile in the runtime.
// This is the case of a P/Invoke method that requires an IL stub, which we can't use in this compilation.
// Return true so the JIT won't inline the P/Invoke — it will be handled by a runtime-generated stub.
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ DEFINE_FIELD_U(_buckets, GCHandleSetObject, _buckets)
#ifdef FEATURE_OBJCMARSHAL
DEFINE_CLASS(OBJCMARSHAL, ObjectiveC, ObjectiveCMarshal)
DEFINE_METHOD(OBJCMARSHAL, INVOKEUNHANDLEDEXCEPTIONPROPAGATION, InvokeUnhandledExceptionPropagation, SM_PtrException_IntPtr_PtrIntPtr_PtrException_RetVoidPtr)
DEFINE_METHOD(OBJCMARSHAL, THROWPENDINGEXCEPTIONOBJECT, ThrowPendingExceptionObject, SM_RetVoid)
#endif // FEATURE_OBJCMARSHAL

DEFINE_CLASS(IENUMERATOR, Collections, IEnumerator)
Expand Down
Loading