Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

NativeCallableAttribute to UnmanagedCallersOnlyAttribute #35592

Merged
merged 2 commits into from
Apr 29, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo
/// </summary>
/// <param name="pCxtInt">Pointer to a <see cref="ComActivationContextInternal"/> instance</param>
[CLSCompliant(false)]
[NativeCallable]
[UnmanagedCallersOnly]
public static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInternal* pCxtInt)
{
ref ComActivationContextInternal cxtInt = ref *pCxtInt;
Expand Down Expand Up @@ -268,7 +268,7 @@ public static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInte
/// </summary>
/// <param name="pCxtInt">Pointer to a <see cref="ComActivationContextInternal"/> instance</param>
[CLSCompliant(false)]
[NativeCallable]
[UnmanagedCallersOnly]
public static unsafe int RegisterClassForTypeInternal(ComActivationContextInternal* pCxtInt)
{
ref ComActivationContextInternal cxtInt = ref *pCxtInt;
Expand Down Expand Up @@ -308,7 +308,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
/// Internal entry point for unregistering a managed COM server API from native code
/// </summary>
[CLSCompliant(false)]
[NativeCallable]
[UnmanagedCallersOnly]
public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInternal* pCxtInt)
{
ref ComActivationContextInternal cxtInt = ref *pCxtInt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static string MarshalToString(IntPtr arg, string argName)
/// <param name="delegateTypeNative">Assembly qualified delegate type name</param>
/// <param name="reserved">Extensibility parameter (currently unused)</param>
/// <param name="functionHandle">Pointer where to store the function pointer result</param>
[NativeCallable]
[UnmanagedCallersOnly]
public static int LoadAssemblyAndGetFunctionPointer(IntPtr assemblyPathNative,
IntPtr typeNameNative,
IntPtr methodNameNative,
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/inc/corcompile.h
Original file line number Diff line number Diff line change
Expand Up @@ -1728,8 +1728,8 @@ class ICorCompileInfo
// to 1 on the clone. The buffer has to be large enough to hold the stub object and the code
virtual HRESULT GetStubClone(void *pStub, BYTE *pBuffer, DWORD dwBufferSize) = 0;

// true if the method has [NativeCallableAttribute]
virtual BOOL IsNativeCallableMethod(CORINFO_METHOD_HANDLE handle) = 0;
// true if the method has [UnmanagedCallersOnlyAttribute]
virtual BOOL IsUnmanagedCallersOnlyMethod(CORINFO_METHOD_HANDLE handle) = 0;

virtual BOOL GetIsGeneratingNgenPDB() = 0;
virtual void SetIsGeneratingNgenPDB(BOOL fGeneratingNgenPDB) = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2623,7 +2623,7 @@ private void allocUnwindInfo(byte* pHotCode, byte* pColdCode, uint startOffset,

if (funcKind == CorJitFuncKind.CORJIT_FUNC_ROOT)
{
if (this.MethodBeingCompiled.IsNativeCallable)
if (this.MethodBeingCompiled.IsUnmanagedCallersOnly)
flags |= FrameInfoFlags.ReversePInvoke;
}

Expand Down Expand Up @@ -2912,12 +2912,12 @@ private uint getJitFlags(ref CORJIT_FLAGS flags, uint sizeInBytes)
if (targetArchitecture == TargetArchitecture.ARM && !_compilation.TypeSystemContext.Target.IsWindows)
flags.Set(CorJitFlag.CORJIT_FLAG_RELATIVE_CODE_RELOCS);

if (this.MethodBeingCompiled.IsNativeCallable)
if (this.MethodBeingCompiled.IsUnmanagedCallersOnly)
{
#if READYTORUN
if (targetArchitecture == TargetArchitecture.X86)
{
throw new RequiresRuntimeJitException("ReadyToRun: Methods with NativeCallableAttribute not implemented");
throw new RequiresRuntimeJitException("ReadyToRun: Methods with UnmanagedCallersOnlyAttribute not implemented");
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public override bool IsSynchronized
}
}

public override bool IsNativeCallable
public override bool IsUnmanagedCallersOnly
{
get
{
return _wrappedMethod.IsNativeCallable;
return _wrappedMethod.IsUnmanagedCallersOnly;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public virtual bool IsSynchronized
/// Gets a value specifying whether this method is directly callable
/// by external unmanaged code.
/// </summary>
public virtual bool IsNativeCallable
public virtual bool IsUnmanagedCallersOnly
{
get
{
Expand Down Expand Up @@ -230,11 +230,11 @@ public override bool IsSynchronized
}
}

public override bool IsNativeCallable
public override bool IsUnmanagedCallersOnly
{
get
{
return _methodDef.IsNativeCallable;
return _methodDef.IsUnmanagedCallersOnly;
}
}

Expand Down Expand Up @@ -322,11 +322,11 @@ public override bool IsSynchronized
}
}

public override bool IsNativeCallable
public override bool IsUnmanagedCallersOnly
{
get
{
return _typicalMethodDef.IsNativeCallable;
return _typicalMethodDef.IsUnmanagedCallersOnly;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public enum ExceptionStringID
InvalidProgramSpecific,
InvalidProgramVararg,
InvalidProgramCallVirtFinalize,
InvalidProgramNativeCallable,
InvalidProgramUnmanagedCallersOnly,
InvalidProgramCallAbstractMethod,
InvalidProgramCallVirtStatic,
InvalidProgramNonStaticMethod,
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/src/tools/Common/TypeSystem/Ecma/EcmaMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static class MethodFlags

public const int AttributeMetadataCache = 0x02000;
public const int Intrinsic = 0x04000;
public const int NativeCallable = 0x08000;
public const int UnmanagedCallersOnly = 0x08000;
public const int RuntimeExport = 0x10000;
};

Expand Down Expand Up @@ -197,9 +197,9 @@ private int InitializeMethodFlags(int mask)
else
if (metadataReader.StringComparer.Equals(namespaceHandle, "System.Runtime.InteropServices"))
{
if (metadataReader.StringComparer.Equals(nameHandle, "NativeCallableAttribute"))
if (metadataReader.StringComparer.Equals(nameHandle, "UnmanagedCallersOnlyAttribute"))
{
flags |= MethodFlags.NativeCallable;
flags |= MethodFlags.UnmanagedCallersOnly;
}
}
else
Expand Down Expand Up @@ -334,11 +334,11 @@ public override bool IsSynchronized
}
}

public override bool IsNativeCallable
public override bool IsUnmanagedCallersOnly
{
get
{
return (GetMethodFlags(MethodFlags.AttributeMetadataCache | MethodFlags.NativeCallable) & MethodFlags.NativeCallable) != 0;
return (GetMethodFlags(MethodFlags.AttributeMetadataCache | MethodFlags.UnmanagedCallersOnly) & MethodFlags.UnmanagedCallersOnly) != 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ private void ceeInfoGetCallInfo(
}

if ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_LDFTN) != 0
&& originalMethod.IsNativeCallable)
&& originalMethod.IsUnmanagedCallersOnly)
{
if (!originalMethod.Signature.IsStatic) // Must be a static method
{
Expand Down Expand Up @@ -1534,9 +1534,9 @@ private void getCallInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_RESO
out useInstantiatingStub);

var targetDetails = _compilation.TypeSystemContext.Target;
if (targetDetails.Architecture == TargetArchitecture.X86 && targetMethod.IsNativeCallable)
if (targetDetails.Architecture == TargetArchitecture.X86 && targetMethod.IsUnmanagedCallersOnly)
{
throw new RequiresRuntimeJitException("ReadyToRun: References to methods with NativeCallableAttribute not implemented");
throw new RequiresRuntimeJitException("ReadyToRun: References to methods with UnmanagedCallersOnlyAttribute not implemented");
}

if (pResult->thisTransform == CORINFO_THIS_TRANSFORM.CORINFO_BOX_THIS)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/cgensys.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum class CallerGCMode
{
Unknown,
Coop,
Preemptive // (e.g. NativeCallableAttribute)
Preemptive // (e.g. UnmanagedCallersOnlyAttribute)
};

// Non-CPU-specific helper functions called by the CPU-dependent code
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/classnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
#define g_CompilerServicesIntrinsicAttribute "System.Runtime.CompilerServices.IntrinsicAttribute"
#define g_UnmanagedFunctionPointerAttribute "System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute"
#define g_DefaultDllImportSearchPathsAttribute "System.Runtime.InteropServices.DefaultDllImportSearchPathsAttribute"
#define g_NativeCallableAttribute "System.Runtime.InteropServices.NativeCallableAttribute"
#define g_UnmanagedCallersOnlyAttribute "System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute"
#define g_FixedBufferAttribute "System.Runtime.CompilerServices.FixedBufferAttribute"

#define g_CompilerServicesTypeDependencyAttribute "System.Runtime.CompilerServices.TypeDependencyAttribute"
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/src/vm/comdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,18 +1153,18 @@ PCODE COMDelegate::ConvertToCallback(MethodDesc* pMD)

#if !defined(FEATURE_STUBS_AS_IL)

// System.Runtime.InteropServices.NativeCallableAttribute
// System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute
BYTE* pData = NULL;
LONG cData = 0;
CorPinvokeMap callConv = (CorPinvokeMap)0;

HRESULT hr = pMD->GetCustomAttribute(WellKnownAttribute::NativeCallable, (const VOID **)(&pData), (ULONG *)&cData);
HRESULT hr = pMD->GetCustomAttribute(WellKnownAttribute::UnmanagedCallersOnly, (const VOID **)(&pData), (ULONG *)&cData);
IfFailThrow(hr);

if (cData > 0)
{
CustomAttributeParser ca(pData, cData);
// NativeCallable has two optional named arguments CallingConvention and EntryPoint.
// UnmanagedCallersOnly has two optional named arguments CallingConvention and EntryPoint.
CaNamedArg namedArgs[2];
CaTypeCtor caType(SERIALIZATION_TYPE_STRING);
// First, the void constructor.
Expand Down Expand Up @@ -2945,11 +2945,11 @@ MethodDesc* COMDelegate::GetDelegateCtor(TypeHandle delegateType, MethodDesc *pT
// associated with the instantiation.
BOOL fMaybeCollectibleAndStatic = FALSE;

// Do not allow static methods with [NativeCallableAttribute] to be a delegate target.
// A native callable method is special and allowing it to be delegate target will destabilize the runtime.
if (pTargetMethod->HasNativeCallableAttribute())
// Do not allow static methods with [UnmanagedCallersOnlyAttribute] to be a delegate target.
// A method marked UnmanagedCallersOnly is special and allowing it to be delegate target will destabilize the runtime.
if (pTargetMethod->HasUnmanagedCallersOnlyAttribute())
{
COMPlusThrow(kNotSupportedException, W("NotSupported_NativeCallableTarget"));
COMPlusThrow(kNotSupportedException, W("NotSupported_UnmanagedCallersOnlyTarget"));
}

if (isStatic)
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/src/vm/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,11 +1223,11 @@ BOOL CEEPreloader::CanEmbedFunctionEntryPoint(

MethodDesc * pMethod = GetMethod(methodHandle);

// Methods with native callable attribute are special , since
// they are used as LDFTN targets.Native Callable methods
// Methods with UnmanagedCallersOnlyAttribute are special, since
// they are used as LDFTN targets. UnmanagedCallersOnly methods
// uses the same code path as reverse pinvoke and embedding them
// in an ngen image require saving the reverse pinvoke stubs.
if (pMethod->HasNativeCallableAttribute())
if (pMethod->HasUnmanagedCallersOnlyAttribute())
return FALSE;

return TRUE;
Expand Down Expand Up @@ -1272,12 +1272,12 @@ BOOL CEEPreloader::DoesMethodNeedRestoringBeforePrestubIsRun(
return FALSE;
}

BOOL CEECompileInfo::IsNativeCallableMethod(CORINFO_METHOD_HANDLE handle)
BOOL CEECompileInfo::IsUnmanagedCallersOnlyMethod(CORINFO_METHOD_HANDLE handle)
{
WRAPPER_NO_CONTRACT;

MethodDesc * pMethod = GetMethod(handle);
return pMethod->HasNativeCallableAttribute();
return pMethod->HasUnmanagedCallersOnlyAttribute();
}

BOOL CEEPreloader::CanSkipDependencyActivation(CORINFO_METHOD_HANDLE context,
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class CEECompileInfo : public ICorCompileInfo
BOOL IsEmptyString(mdString token,
CORINFO_MODULE_HANDLE module);

BOOL IsNativeCallableMethod(CORINFO_METHOD_HANDLE handle);
BOOL IsUnmanagedCallersOnlyMethod(CORINFO_METHOD_HANDLE handle);

BOOL IsCachingOfInliningHintsEnabled()
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/corhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ HRESULT CorHost2::CreateDelegate(
if (pMD==NULL || !pMD->IsStatic() || pMD->HasClassOrMethodInstantiation())
ThrowHR(COR_E_MISSINGMETHOD);

if (pMD->HasNativeCallableAttribute())
if (pMD->HasUnmanagedCallersOnlyAttribute())
{
if (NDirect::MarshalingRequired(pMD, pMD->GetSig(), pMD->GetModule()))
ThrowHR(COR_E_INVALIDPROGRAM);
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/src/vm/dllimportcallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,16 +848,17 @@ UMEntryThunk *UMEntryThunkCache::GetUMEntryThunk(MethodDesc *pMD)
RETURN pThunk;
}

// FailFast if a native callable method invoked directly from managed code.
// UMThunkStub.asm check the mode and call this function to failfast.
// FailFast if a method marked UnmanagedCallersOnlyAttribute is
// invoked directly from managed code. UMThunkStub.asm check the
// mode and call this function to failfast.
extern "C" VOID STDCALL ReversePInvokeBadTransition()
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
// Fail
EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(
COR_E_EXECUTIONENGINE,
W("Invalid Program: attempted to call a NativeCallable method from managed code.")
W("Invalid Program: attempted to call a UnmanagedCallersOnly method from managed code.")
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/eetwain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5757,7 +5757,7 @@ bool EECodeManager::GetReturnAddressHijackInfo(GCInfoToken gcInfoToken, ReturnKi

if (gcInfoDecoder.GetReversePInvokeFrameStackSlot() != NO_REVERSE_PINVOKE_FRAME)
{
// Hijacking of NativeCallable method is not allowed
// Hijacking of UnmanagedCallersOnly method is not allowed
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/excep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8101,7 +8101,7 @@ LONG WINAPI CLRVectoredExceptionHandlerShim(PEXCEPTION_POINTERS pExceptionInfo)
//
// 1) We have a valid Thread object (implies exception on managed thread)
// 2) Not a valid Thread object but the IP is in the execution engine (implies native thread within EE faulted)
// 3) The exception occurred in a GC marked location when no thread exists (i.e. reverse P/Invoke with NativeCallableAttribute).
// 3) The exception occurred in a GC marked location when no thread exists (i.e. reverse P/Invoke with UnmanagedCallersOnlyAttribute).
if (pThread || fExceptionInEE)
{
if (!bIsGCMarker)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ lExit: ;
GcInfoDecoder gcInfoDecoder(codeInfo.GetGCInfoToken(), DECODE_REVERSE_PINVOKE_VAR);
if (gcInfoDecoder.GetReversePInvokeFrameStackSlot() != NO_REVERSE_PINVOKE_FRAME)
{
// Exception is being propagated from a native callable method into its native caller.
// Exception is being propagated from a method marked UnmanagedCallersOnlyAttribute into its native caller.
// The explicit frame chain needs to be unwound at this boundary.
bool fIsSO = pExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW;
CleanUpForSecondPass(pThread, fIsSO, (void*)MemoryStackFp, (void*)MemoryStackFp);
Expand Down Expand Up @@ -4630,7 +4630,7 @@ VOID DECLSPEC_NORETURN UnwindManagedExceptionPass1(PAL_SEHException& ex, CONTEXT

if (gcInfoDecoder.GetReversePInvokeFrameStackSlot() != NO_REVERSE_PINVOKE_FRAME)
{
// Propagating exception from a method marked by NativeCallable attribute is prohibited on Unix
// Propagating exception from a method marked by UnmanagedCallersOnly attribute is prohibited on Unix
if (!GetThread()->HasThreadStateNC(Thread::TSNC_ProcessedUnhandledException))
{
LONG disposition = InternalUnhandledExceptionFilter_Worker(&ex.ExceptionPointers);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -2788,7 +2788,7 @@ class UMThkCallFrame : public UnmanagedToManagedFrame
};
#endif // TARGET_X86 && !TARGET_UNIX

// Frame for the Reverse PInvoke (i.e. NativeCallableAttribute).
// Frame for the Reverse PInvoke (i.e. UnmanagedCallersOnlyAttribute).
struct ReversePInvokeFrame
{
Thread* currentThread;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/vm/gccover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,10 +1403,10 @@ BOOL OnGcCoverageInterrupt(PCONTEXT regs)
if (!pThread)
{
// No thread at the moment so we aren't doing coverage for this function.
// This should only occur for methods with the NativeCallableAttribute,
// This should only occur for methods with the UnmanagedCallersOnlyAttribute,
// where the call could be coming from a thread unknown to the CLR and
// we haven't created a thread yet - see PreStubWorker_Preemptive().
_ASSERTE(pMD->HasNativeCallableAttribute());
_ASSERTE(pMD->HasUnmanagedCallersOnlyAttribute());
RemoveGcCoverageInterrupt(instrPtr, savedInstrPtr);
return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/i386/umthunkstub.S
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ LOCAL_LABEL(HaveThread):

mov dword ptr [ebp - UMThunkStub_THREAD_OFFSET], eax

// FailFast if a native callable method is invoked via ldftn and calli.
// FailFast if a method marked UnmanagedCallersOnlyAttribute is invoked via ldftn and calli.
cmp dword ptr [eax + Thread_m_fPreemptiveGCDisabled], 1
jz LOCAL_LABEL(InvalidTransition)

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/vm/ilstubcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ MethodDesc* ILStubCache::CreateNewMethodDesc(LoaderHeap* pCreationHeap, MethodTa
{
pMD->m_dwExtendedFlags |= DynamicMethodDesc::nomdReverseStub;
#if !defined(TARGET_X86)
pMD->m_dwExtendedFlags |= DynamicMethodDesc::nomdNativeCallableStub;
pMD->m_dwExtendedFlags |= DynamicMethodDesc::nomdUnmanagedCallersOnlyStub;
#endif
pMD->GetILStubResolver()->SetStubType(ILStubResolver::NativeToCLRInteropStub);
}
Expand Down
Loading