Skip to content

Commit

Permalink
Update CrossGen2.
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronRobinsonMSFT committed May 17, 2021
1 parent 2f8e56c commit ce00259
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Interop/MethodDesc.Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,21 @@ public PInvokeMetadata(string module, string entrypoint, PInvokeFlags flags)
Module = module;
Flags = flags;
}

public bool CheckPendingException()

This comment has been minimized.

Copy link
@jkotas

jkotas May 17, 2021

Member

This should be in Marshal* (Marshaller, MarshalUtils or MarshalHelpers. We try to avoid putting policy-heavy methods directly on the core type system types in the managed type system.

{
const string ObjectiveCLibrary = "/usr/lib/libobjc.dylib";
const string ObjectiveCMsgSend = "objc_msgSend";

// This is for the objc_msgSend suite of functions.
// objc_msgSend
// objc_msgSend_fpret
// objc_msgSend_stret
// objc_msgSendSuper
// objc_msgSendSuper_stret
return Module.Equals(ObjectiveCLibrary)
&& Name.StartsWith(ObjectiveCMsgSend);
}
}

partial class InstantiatedMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void EmitPInvokeCall(PInvokeILCodeStreams ilCodeStreams)

MetadataType stubHelpersType = InteropTypes.GetStubHelpers(context);

// if the SetLastError flag is set in DllImport, clear the error code before doing P/Invoke
// if the SetLastError flag is set in DllImport, clear the error code before doing P/Invoke
if (_importMetadata.Flags.SetLastError)
{
callsiteSetupCodeStream.Emit(ILOpcode.call, emitter.NewToken(
Expand Down Expand Up @@ -78,6 +78,9 @@ private MethodIL EmitIL()
if (!_importMetadata.Flags.PreserveSig)
throw new NotSupportedException();

if (_importMetadata.CheckPendingException())

This comment has been minimized.

Copy link
@jkotas

jkotas May 17, 2021

Member

It may make sense to do this for OSX only.

throw new NotSupportedException();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,18 @@ public static bool IsMarshallingRequired(MethodDesc targetMethod)
if (targetMethod.IsUnmanagedCallersOnly)
return true;

PInvokeFlags flags = targetMethod.GetPInvokeMethodMetadata().Flags;
PInvokeMetadata metadata = targetMethod.GetPInvokeMethodMetadata();
PInvokeFlags flags = metadata.Flags;

if (flags.SetLastError)
return true;

if (!flags.PreserveSig)
return true;

if (metadata.CheckPendingException())
return true;

var marshallers = GetMarshallersForMethod(targetMethod);
for (int i = 0; i < marshallers.Length; i++)
{
Expand Down

0 comments on commit ce00259

Please sign in to comment.