/// </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;
/// </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;
/// 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;
/// <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,
// 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;
if (funcKind == CorJitFuncKind.CORJIT_FUNC_ROOT)
{
- if (this.MethodBeingCompiled.IsNativeCallable)
+ if (this.MethodBeingCompiled.IsUnmanagedCallersOnly)
flags |= FrameInfoFlags.ReversePInvoke;
}
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
}
}
- public override bool IsNativeCallable
+ public override bool IsUnmanagedCallersOnly
{
get
{
- return _wrappedMethod.IsNativeCallable;
+ return _wrappedMethod.IsUnmanagedCallersOnly;
}
}
/// Gets a value specifying whether this method is directly callable
/// by external unmanaged code.
/// </summary>
- public virtual bool IsNativeCallable
+ public virtual bool IsUnmanagedCallersOnly
{
get
{
}
}
- public override bool IsNativeCallable
+ public override bool IsUnmanagedCallersOnly
{
get
{
- return _methodDef.IsNativeCallable;
+ return _methodDef.IsUnmanagedCallersOnly;
}
}
}
}
- public override bool IsNativeCallable
+ public override bool IsUnmanagedCallersOnly
{
get
{
- return _typicalMethodDef.IsNativeCallable;
+ return _typicalMethodDef.IsUnmanagedCallersOnly;
}
}
InvalidProgramSpecific,
InvalidProgramVararg,
InvalidProgramCallVirtFinalize,
- InvalidProgramNativeCallable,
+ InvalidProgramUnmanagedCallersOnly,
InvalidProgramCallAbstractMethod,
InvalidProgramCallVirtStatic,
InvalidProgramNonStaticMethod,
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;
};
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
}
}
- 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;
}
}
}
if ((flags & CORINFO_CALLINFO_FLAGS.CORINFO_CALLINFO_LDFTN) != 0
- && originalMethod.IsNativeCallable)
+ && originalMethod.IsUnmanagedCallersOnly)
{
if (!originalMethod.Signature.IsStatic) // Must be a static method
{
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)
{
Unknown,
Coop,
- Preemptive // (e.g. NativeCallableAttribute)
+ Preemptive // (e.g. UnmanagedCallersOnlyAttribute)
};
// Non-CPU-specific helper functions called by the CPU-dependent code
#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"
#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.
// 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)
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;
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,
BOOL IsEmptyString(mdString token,
CORINFO_MODULE_HANDLE module);
- BOOL IsNativeCallableMethod(CORINFO_METHOD_HANDLE handle);
+ BOOL IsUnmanagedCallersOnlyMethod(CORINFO_METHOD_HANDLE handle);
BOOL IsCachingOfInliningHintsEnabled()
{
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);
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;
// 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.")
);
}
if (gcInfoDecoder.GetReversePInvokeFrameStackSlot() != NO_REVERSE_PINVOKE_FRAME)
{
- // Hijacking of NativeCallable method is not allowed
+ // Hijacking of UnmanagedCallersOnly method is not allowed
return false;
}
//
// 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)
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);
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);
};
#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;
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;
}
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)
{
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);
}
EX_THROW(EEMessageException, (kMissingMethodException, IDS_EE_MISSING_METHOD, W("?")));
}
- // If this call is for a LDFTN and the target method has the NativeCallableAttribute,
+ // If this call is for a LDFTN and the target method has the UnmanagedCallersOnlyAttribute,
// then validate it adheres to the limitations.
- if ((flags & CORINFO_CALLINFO_LDFTN) && pMD->HasNativeCallableAttribute())
+ if ((flags & CORINFO_CALLINFO_LDFTN) && pMD->HasUnmanagedCallersOnlyAttribute())
{
if (!pMD->IsStatic())
EX_THROW(EEResourceException, (kInvalidProgramException, W("InvalidProgram_NonStaticMethod")));
// Deferring X86 support until a need is observed or
// time permits investigation into all the potential issues.
// https://github.com/dotnet/runtime/issues/33582
- if (pMD->HasNativeCallableAttribute())
+ if (pMD->HasUnmanagedCallersOnlyAttribute())
{
pResult->addr = (void*)COMDelegate::ConvertToCallback(pMD);
}
}
#if !defined(TARGET_X86)
- if (ftn->HasNativeCallableAttribute())
+ if (ftn->HasUnmanagedCallersOnlyAttribute())
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_REVERSE_PINVOKE);
#endif // !TARGET_X86
#endif // !CROSSGEN_COMPILE
//*******************************************************************************
-BOOL MethodDesc::HasNativeCallableAttribute()
+BOOL MethodDesc::HasUnmanagedCallersOnlyAttribute()
{
CONTRACTL
{
if (IsILStub())
{
- return AsDynamicMethodDesc()->IsNativeCallableStub();
+ return AsDynamicMethodDesc()->IsUnmanagedCallersOnlyStub();
}
HRESULT hr = GetCustomAttribute(
- WellKnownAttribute::NativeCallable,
+ WellKnownAttribute::UnmanagedCallersOnly,
nullptr,
nullptr);
return (hr == S_OK) ? TRUE : FALSE;
return GetMethodTable()->IsInterface();
}
- BOOL HasNativeCallableAttribute();
+ BOOL HasUnmanagedCallersOnlyAttribute();
BOOL ShouldSuppressGCTransition();
#ifdef FEATURE_COMINTEROP
nomdILStubAttrs = mdMemberAccessMask | mdStatic, // method attributes (IL stubs)
// attributes (except mdStatic and mdMemberAccessMask) have different meaning for IL stubs
- // mdMemberAccessMask = 0x0007,
- nomdReverseStub = 0x0008,
- // mdStatic = 0x0010,
- nomdCALLIStub = 0x0020,
- nomdDelegateStub = 0x0040,
- nomdStructMarshalStub = 0x0080,
- nomdUnbreakable = 0x0100,
- nomdDelegateCOMStub = 0x0200, // CLR->COM or COM->CLR call via a delegate (WinRT specific)
- nomdSignatureNeedsRestore = 0x0400,
- nomdStubNeedsCOMStarted = 0x0800, // EnsureComStarted must be called before executing the method
- nomdMulticastStub = 0x1000,
- nomdUnboxingILStub = 0x2000,
- nomdWrapperDelegateStub = 0x4000,
- nomdNativeCallableStub = 0x8000,
+ // mdMemberAccessMask = 0x0007,
+ nomdReverseStub = 0x0008,
+ // mdStatic = 0x0010,
+ nomdCALLIStub = 0x0020,
+ nomdDelegateStub = 0x0040,
+ nomdStructMarshalStub = 0x0080,
+ nomdUnbreakable = 0x0100,
+ nomdDelegateCOMStub = 0x0200, // CLR->COM or COM->CLR call via a delegate (WinRT specific)
+ nomdSignatureNeedsRestore = 0x0400,
+ nomdStubNeedsCOMStarted = 0x0800, // EnsureComStarted must be called before executing the method
+ nomdMulticastStub = 0x1000,
+ nomdUnboxingILStub = 0x2000,
+ nomdWrapperDelegateStub = 0x4000,
+ nomdUnmanagedCallersOnlyStub = 0x8000,
nomdILStub = 0x00010000,
nomdLCGMethod = 0x00020000,
}
bool IsReverseStub() { LIMITED_METHOD_DAC_CONTRACT; _ASSERTE(IsILStub()); return (0 != (m_dwExtendedFlags & nomdReverseStub)); }
- bool IsNativeCallableStub() { LIMITED_METHOD_DAC_CONTRACT; _ASSERTE(IsILStub()); return (0 != (m_dwExtendedFlags & nomdNativeCallableStub)); }
+ bool IsUnmanagedCallersOnlyStub() { LIMITED_METHOD_DAC_CONTRACT; _ASSERTE(IsILStub()); return (0 != (m_dwExtendedFlags & nomdUnmanagedCallersOnlyStub)); }
bool IsCALLIStub() { LIMITED_METHOD_DAC_CONTRACT; _ASSERTE(IsILStub()); return (0 != (m_dwExtendedFlags & nomdCALLIStub)); }
bool IsDelegateStub() { LIMITED_METHOD_DAC_CONTRACT; _ASSERTE(IsILStub()); return (0 != (m_dwExtendedFlags & nomdDelegateStub)); }
bool IsCLRToCOMStub() { LIMITED_METHOD_CONTRACT; _ASSERTE(IsILStub()); return ((0 == (m_dwExtendedFlags & mdStatic)) && !IsReverseStub() && !IsDelegateStub() && !IsStructMarshalStub()); }
CallerGCMode callerGcMode = pConfig->GetCallerGCMode();
// If the method is eligible for tiering but is being
// called from a Preemptive GC Mode thread or the method
- // has the NativeCallableAttribute then the Tiered Compilation
+ // has the UnmanagedCallersOnlyAttribute then the Tiered Compilation
// should be disabled.
if (shouldTier
&& (callerGcMode == CallerGCMode::Preemptive
|| (callerGcMode == CallerGCMode::Unknown
- && HasNativeCallableAttribute())))
+ && HasUnmanagedCallersOnlyAttribute())))
{
NativeCodeVersion codeVersion = pConfig->GetCodeVersion();
if (codeVersion.IsDefaultVersion())
//=============================================================================
// This function generates the real code when from Preemptive mode.
-// It is specifically designed to work with the NativeCallableAttribute.
+// It is specifically designed to work with the UnmanagedCallersOnlyAttribute.
//=============================================================================
static PCODE PreStubWorker_Preemptive(
_In_ TransitionBlock* pTransitionBlock,
_In_ MethodDesc* pMD,
_In_opt_ Thread* currentThread)
{
- _ASSERTE(pMD->HasNativeCallableAttribute());
+ _ASSERTE(pMD->HasUnmanagedCallersOnlyAttribute());
PCODE pbRetVal = NULL;
MAKE_CURRENT_THREAD_AVAILABLE_EX(currentThread);
// No GC frame is needed here since there should be no OBJECTREFs involved
- // in this call due to NativeCallableAttribute semantics.
+ // in this call due to UnmanagedCallersOnlyAttribute semantics.
INSTALL_MANAGED_EXCEPTION_DISPATCHER;
INSTALL_UNWIND_AND_CONTINUE_HANDLER;
// This is a recompiling request which means the caller was
// in COOP mode since the code already ran.
- _ASSERTE(!pMethod->HasNativeCallableAttribute());
+ _ASSERTE(!pMethod->HasUnmanagedCallersOnlyAttribute());
config->SetCallerGCMode(CallerGCMode::Coop);
pCode = pMethod->PrepareCode(config);
LOG((LF_TIEREDCOMPILATION, LL_INFO10000, "TieredCompilationManager::CompileCodeVersion Method=0x%pM (%s::%s), code version id=0x%x, code ptr=0x%p\n",
IsByRefLike,
PrimaryInteropAssembly,
ManagedToNativeComInteropStub,
- NativeCallable,
+ UnmanagedCallersOnly,
TypeIdentifier,
UnmanagedFunctionPointer,
ThreadStatic,
return "System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute";
case WellKnownAttribute::ManagedToNativeComInteropStub:
return "System.Runtime.InteropServices.ManagedToNativeComInteropStubAttribute";
- case WellKnownAttribute::NativeCallable:
- return "System.Runtime.InteropServices.NativeCallableAttribute";
+ case WellKnownAttribute::UnmanagedCallersOnly:
+ return "System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute";
case WellKnownAttribute::TypeIdentifier:
return "System.Runtime.InteropServices.TypeIdentifierAttribute";
case WellKnownAttribute::UnmanagedFunctionPointer:
if (token != mdTokenNil)
{
_ASSERTE(TypeFromToken(token) == mdtMethodDef || TypeFromToken(token) == mdtMemberRef);
- _ASSERTE(!pTable->GetCompileInfo()->IsNativeCallableMethod(handle));
+ _ASSERTE(!pTable->GetCompileInfo()->IsUnmanagedCallersOnlyMethod(handle));
pTable->EncodeModule(
(TypeFromToken(token) == mdtMethodDef) ? ENCODE_METHOD_ENTRY_DEF_TOKEN : ENCODE_METHOD_ENTRY_REF_TOKEN,
#endif
#ifdef TARGET_X86
- if (GetCompileInfo()->IsNativeCallableMethod(m_currentMethodHandle))
+ if (GetCompileInfo()->IsUnmanagedCallersOnlyMethod(m_currentMethodHandle))
{
if (m_zapper->m_pOpt->m_verbose)
- m_zapper->Warning(W("ReadyToRun: Methods with NativeCallableAttribute not implemented\n"));
+ m_zapper->Warning(W("ReadyToRun: Methods with UnmanagedCallersOnlyAttribute not implemented\n"));
ThrowHR(E_NOTIMPL);
}
#endif // TARGET_X86
#endif
#ifdef TARGET_X86
- if (GetCompileInfo()->IsNativeCallableMethod(pResult->hMethod))
+ if (GetCompileInfo()->IsUnmanagedCallersOnlyMethod(pResult->hMethod))
{
if (m_zapper->m_pOpt->m_verbose)
- m_zapper->Warning(W("ReadyToRun: References to methods with NativeCallableAttribute not implemented\n"));
+ m_zapper->Warning(W("ReadyToRun: References to methods with UnmanagedCallersOnlyAttribute not implemented\n"));
ThrowHR(E_NOTIMPL);
}
#endif // TARGET_X86
add_subdirectory(PInvoke/AsAny)
add_subdirectory(PInvoke/SafeHandles)
add_subdirectory(PInvoke/Vector2_3_4)
-add_subdirectory(NativeCallable)
+add_subdirectory(UnmanagedCallersOnly)
add_subdirectory(PrimitiveMarshalling/Bool)
add_subdirectory(PrimitiveMarshalling/UIntPtr)
add_subdirectory(ArrayMarshalling/BoolArray)
+++ /dev/null
-project (NativeCallableDll)
-include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake")
-set(SOURCES NativeCallableDll.cpp )
-
-# add the executable
-add_library (NativeCallableDll SHARED ${SOURCES})
-target_link_libraries(NativeCallableDll ${LINK_LIBRARIES_ADDITIONAL})
-
-# add the install targets
-install (TARGETS NativeCallableDll DESTINATION bin)
--- /dev/null
+project (UnmanagedCallersOnlyDll)
+include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake")
+set(SOURCES UnmanagedCallersOnlyDll.cpp )
+
+# add the executable
+add_library (UnmanagedCallersOnlyDll SHARED ${SOURCES})
+target_link_libraries(UnmanagedCallersOnlyDll ${LINK_LIBRARIES_ADDITIONAL})
+
+# add the install targets
+install (TARGETS UnmanagedCallersOnlyDll DESTINATION bin)
public class Program
{
- public static class NativeCallableDll
+ public static class UnmanagedCallersOnlyDll
{
- [DllImport(nameof(NativeCallableDll))]
+ [DllImport(nameof(UnmanagedCallersOnlyDll))]
public static extern int CallManagedProc(IntPtr callbackProc, int n);
- [DllImport(nameof(NativeCallableDll))]
+ [DllImport(nameof(UnmanagedCallersOnlyDll))]
public static extern int CallManagedProcOnNewThread(IntPtr callbackProc, int n);
- [DllImport(nameof(NativeCallableDll))]
+ [DllImport(nameof(UnmanagedCallersOnlyDll))]
// Returns -1 if exception was throw and caught.
public static extern int CallManagedProcCatchException(IntPtr callbackProc, int n);
}
{
try
{
- TestNativeCallableValid();
- TestNativeCallableValid_OnNewNativeThread();
- TestNativeCallableValid_PrepareMethod();
+ TestUnmanagedCallersOnlyValid();
+ TestUnmanagedCallersOnlyValid_OnNewNativeThread();
+ TestUnmanagedCallersOnlyValid_PrepareMethod();
NegativeTest_NonStaticMethod();
NegativeTest_ViaDelegate();
NegativeTest_NonBlittable();
NegativeTest_NonInstantiatedGenericArguments();
NegativeTest_InstantiatedGenericArguments();
NegativeTest_FromInstantiatedGenericClass();
- TestNativeCallableViaUnmanagedCalli();
+ TestUnmanagedCallersOnlyViaUnmanagedCalli();
// Exception handling is only supported on Windows.
if (TestLibrary.Utilities.IsWindows)
{
- TestNativeCallableValid_ThrowException();
- TestNativeCallableViaUnmanagedCalli_ThrowException();
+ TestUnmanagedCallersOnlyValid_ThrowException();
+ TestUnmanagedCallersOnlyViaUnmanagedCalli_ThrowException();
}
if (args.Length != 0 && args[0].Equals("calli"))
return 100;
}
- [NativeCallable]
+ [UnmanagedCallersOnly]
public static int ManagedDoubleCallback(int n)
{
return DoubleImpl(n);
return 2 * n;
}
- public static void TestNativeCallableValid()
+ public static void TestUnmanagedCallersOnlyValid()
{
- Console.WriteLine($"Running {nameof(TestNativeCallableValid)}...");
+ Console.WriteLine($"Running {nameof(TestUnmanagedCallersOnlyValid)}...");
/*
- void NativeCallable()
+ void UnmanagedCallersOnly()
{
.locals init ([0] native int ptr)
IL_0000: nop
IL_0008: ldloc.0
IL_0009: ldc.i4 <n> local
- IL_000e: call bool NativeCallableDll::CallManagedProc(native int, int)
+ IL_000e: call bool UnmanagedCallersOnlyDll::CallManagedProc(native int, int)
IL_0013: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("NativeCallable", typeof(int), null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("UnmanagedCallersOnly", typeof(int), null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
int n = 12345;
il.Emit(OpCodes.Ldc_I4, n);
- il.Emit(OpCodes.Call, typeof(NativeCallableDll).GetMethod("CallManagedProc"));
+ il.Emit(OpCodes.Call, typeof(UnmanagedCallersOnlyDll).GetMethod("CallManagedProc"));
il.Emit(OpCodes.Ret);
- var testNativeMethod = (IntNativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(IntNativeMethodInvoker));
+ var testNativeMethod = (IntNativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(IntNativeMethodInvoker));
int expected = DoubleImpl(n);
Assert.AreEqual(expected, testNativeMethod());
}
- public static void TestNativeCallableValid_OnNewNativeThread()
+ public static void TestUnmanagedCallersOnlyValid_OnNewNativeThread()
{
- Console.WriteLine($"Running {nameof(TestNativeCallableValid_OnNewNativeThread)}...");
+ Console.WriteLine($"Running {nameof(TestUnmanagedCallersOnlyValid_OnNewNativeThread)}...");
/*
- void NativeCallableOnNewNativeThread()
+ void UnmanagedCallersOnlyOnNewNativeThread()
{
.locals init ([0] native int ptr)
IL_0000: nop
IL_0008: ldloc.0
IL_0009: ldc.i4 <n> local
- IL_000e: call bool NativeCallableDll::CallManagedProcOnNewThread(native int, int)
+ IL_000e: call bool UnmanagedCallersOnlyDll::CallManagedProcOnNewThread(native int, int)
IL_0013: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("NativeCallableOnNewNativeThread", typeof(int), null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("UnmanagedCallersOnlyOnNewNativeThread", typeof(int), null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
int n = 12345;
il.Emit(OpCodes.Ldc_I4, n);
- il.Emit(OpCodes.Call, typeof(NativeCallableDll).GetMethod("CallManagedProcOnNewThread"));
+ il.Emit(OpCodes.Call, typeof(UnmanagedCallersOnlyDll).GetMethod("CallManagedProcOnNewThread"));
il.Emit(OpCodes.Ret);
- var testNativeMethod = (IntNativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(IntNativeMethodInvoker));
+ var testNativeMethod = (IntNativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(IntNativeMethodInvoker));
int expected = DoubleImpl(n);
Assert.AreEqual(expected, testNativeMethod());
}
- [NativeCallable]
+ [UnmanagedCallersOnly]
public static int ManagedCallback_Prepared(int n)
{
return DoubleImpl(n);
}
- // This test is about the interaction between Tiered Compilation and the NativeCallableAttribute.
- public static void TestNativeCallableValid_PrepareMethod()
+ // This test is about the interaction between Tiered Compilation and the UnmanagedCallersOnlyAttribute.
+ public static void TestUnmanagedCallersOnlyValid_PrepareMethod()
{
- Console.WriteLine($"Running {nameof(TestNativeCallableValid_PrepareMethod)}...");
+ Console.WriteLine($"Running {nameof(TestUnmanagedCallersOnlyValid_PrepareMethod)}...");
/*
- void NativeCallableOnNewNativeThread()
+ void UnmanagedCallersOnlyOnNewNativeThread()
{
.locals init ([0] native int ptr)
IL_0000: nop
IL_0008: ldloc.0
IL_0009: ldc.i4 <n> local
- IL_000e: call bool NativeCallableDll::CallManagedProcOnNewThread(native int, int)
+ IL_000e: call bool UnmanagedCallersOnlyDll::CallManagedProcOnNewThread(native int, int)
IL_0013: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("NativeCallableValid_PrepareMethod", typeof(int), null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("UnmanagedCallersOnlyValid_PrepareMethod", typeof(int), null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
int n = 12345;
il.Emit(OpCodes.Ldc_I4, n);
- il.Emit(OpCodes.Call, typeof(NativeCallableDll).GetMethod("CallManagedProcOnNewThread"));
+ il.Emit(OpCodes.Call, typeof(UnmanagedCallersOnlyDll).GetMethod("CallManagedProcOnNewThread"));
il.Emit(OpCodes.Ret);
- var testNativeMethod = (IntNativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(IntNativeMethodInvoker));
+ var testNativeMethod = (IntNativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(IntNativeMethodInvoker));
// Call enough to attempt to trigger Tiered Compilation from a new thread.
for (int i = 0; i < 100; ++i)
private const int CallbackThrowsErrorCode = 27;
- [NativeCallable]
+ [UnmanagedCallersOnly]
public static int CallbackThrows(int val)
{
throw new Exception() { HResult = CallbackThrowsErrorCode };
}
- public static void TestNativeCallableValid_ThrowException()
+ public static void TestUnmanagedCallersOnlyValid_ThrowException()
{
- Console.WriteLine($"Running {nameof(TestNativeCallableValid_ThrowException)}...");
+ Console.WriteLine($"Running {nameof(TestUnmanagedCallersOnlyValid_ThrowException)}...");
/*
- void NativeCallableValid_ThrowException()
+ void UnmanagedCallersOnlyValid_ThrowException()
{
.locals init ([0] native int ptr)
IL_0000: nop
IL_0008: ldloc.0
IL_0009: ldc.i4 <n> local
- IL_000e: call bool NativeCallableDll::CallManagedProcCatchException(native int, int)
+ IL_000e: call bool UnmanagedCallersOnlyDll::CallManagedProcCatchException(native int, int)
IL_0013: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("NativeCallableValid_ThrowException", typeof(int), null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("UnmanagedCallersOnlyValid_ThrowException", typeof(int), null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
int n = 12345;
il.Emit(OpCodes.Ldc_I4, n);
- il.Emit(OpCodes.Call, typeof(NativeCallableDll).GetMethod("CallManagedProcCatchException"));
+ il.Emit(OpCodes.Call, typeof(UnmanagedCallersOnlyDll).GetMethod("CallManagedProcCatchException"));
il.Emit(OpCodes.Ret);
- var testNativeMethod = (IntNativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(IntNativeMethodInvoker));
+ var testNativeMethod = (IntNativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(IntNativeMethodInvoker));
// Method should have thrown and caught an exception.
Assert.AreEqual(-1, testNativeMethod());
}
}
- [NativeCallable]
+ [UnmanagedCallersOnly]
public void CallbackNonStatic()
{
- Assert.Fail($"Instance functions with attribute {nameof(NativeCallableAttribute)} are invalid");
+ Assert.Fail($"Instance functions with attribute {nameof(UnmanagedCallersOnlyAttribute)} are invalid");
}
public static void NegativeTest_NonStaticMethod()
Console.WriteLine($"Running {nameof(NegativeTest_NonStaticMethod)}...");
/*
- void TestNativeCallableNonStatic()
+ void TestUnmanagedCallersOnlyNonStatic()
{
.locals init ([0] native int ptr)
IL_0000: nop
IL_0008: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("TestNativeCallableNonStatic", null, null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("TestUnmanagedCallersOnlyNonStatic", null, null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ret);
- var testNativeMethod = (NativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(NativeMethodInvoker));
+ var testNativeMethod = (NativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(NativeMethodInvoker));
// Try invoking method
Assert.Throws<InvalidProgramException>(() => { testNativeMethod(); });
}
- [NativeCallable]
+ [UnmanagedCallersOnly]
public static void CallbackMethodNonBlittable(bool x1)
{
- Assert.Fail($"Functions with attribute {nameof(NativeCallableAttribute)} cannot have non-blittable arguments");
+ Assert.Fail($"Functions with attribute {nameof(UnmanagedCallersOnlyAttribute)} cannot have non-blittable arguments");
}
public static void NegativeTest_NonBlittable()
Console.WriteLine($"Running {nameof(NegativeTest_NonBlittable)}...");
/*
- void TestNativeCallableNonBlittable()
+ void TestUnmanagedCallersOnlyNonBlittable()
{
.locals init ([0] native int ptr)
IL_0000: nop
IL_0008: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("TestNativeCallableNonBlittable", null, null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("TestUnmanagedCallersOnlyNonBlittable", null, null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ret);
- var testNativeMethod = (NativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(NativeMethodInvoker));
+ var testNativeMethod = (NativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(NativeMethodInvoker));
// Try invoking method
Assert.Throws<InvalidProgramException>(() => { testNativeMethod(); });
}
- [NativeCallable]
+ [UnmanagedCallersOnly]
public static void CallbackMethodGeneric<T>(T arg)
{
- Assert.Fail($"Functions with attribute {nameof(NativeCallableAttribute)} cannot have generic arguments");
+ Assert.Fail($"Functions with attribute {nameof(UnmanagedCallersOnlyAttribute)} cannot have generic arguments");
}
public static void NegativeTest_NonInstantiatedGenericArguments()
Console.WriteLine($"Running {nameof(NegativeTest_NonInstantiatedGenericArguments)}...");
/*
- void TestNativeCallableNonInstGenericArguments()
+ void TestUnmanagedCallersOnlyNonInstGenericArguments()
{
.locals init ([0] native int ptr)
IL_0000: nop
IL_0008: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("TestNativeCallableNonInstGenericArguments", null, null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("TestUnmanagedCallersOnlyNonInstGenericArguments", null, null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ret);
- var testNativeMethod = (NativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(NativeMethodInvoker));
+ var testNativeMethod = (NativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(NativeMethodInvoker));
// Try invoking method
Assert.Throws<InvalidProgramException>(() => { testNativeMethod(); });
Console.WriteLine($"Running {nameof(NegativeTest_InstantiatedGenericArguments)}...");
/*
- void TestNativeCallableInstGenericArguments()
+ void TestUnmanagedCallersOnlyInstGenericArguments()
{
.locals init ([0] native int ptr)
IL_0000: nop
IL_0008: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("TestNativeCallableInstGenericArguments", null, null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("TestUnmanagedCallersOnlyInstGenericArguments", null, null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ret);
- var testNativeMethod = (NativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(NativeMethodInvoker));
+ var testNativeMethod = (NativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(NativeMethodInvoker));
// Try invoking method
Assert.Throws<InvalidProgramException>(() => { testNativeMethod(); });
public class GenericClass<T>
{
- [NativeCallable]
+ [UnmanagedCallersOnly]
public static void CallbackMethod(int n)
{
- Assert.Fail($"Functions with attribute {nameof(NativeCallableAttribute)} within a generic type are invalid");
+ Assert.Fail($"Functions with attribute {nameof(UnmanagedCallersOnlyAttribute)} within a generic type are invalid");
}
}
Console.WriteLine($"Running {nameof(NegativeTest_FromInstantiatedGenericClass)}...");
/*
- void TestNativeCallableInstGenericType()
+ void TestUnmanagedCallersOnlyInstGenericType()
{
.locals init ([0] native int ptr)
IL_0000: nop
IL_0008: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("TestNativeCallableInstGenericClass", null, null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("TestUnmanagedCallersOnlyInstGenericClass", null, null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ret);
- var testNativeMethod = (NativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(NativeMethodInvoker));
+ var testNativeMethod = (NativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(NativeMethodInvoker));
// Try invoking method
Assert.Throws<InvalidProgramException>(() => { testNativeMethod(); });
}
- [NativeCallable]
+ [UnmanagedCallersOnly]
public static void CallbackViaCalli(int val)
{
- Assert.Fail($"Functions with attribute {nameof(NativeCallableAttribute)} cannot be called via calli");
+ Assert.Fail($"Functions with attribute {nameof(UnmanagedCallersOnlyAttribute)} cannot be called via calli");
}
public static void NegativeTest_ViaCalli()
Console.WriteLine($"{nameof(NegativeTest_ViaCalli)} function via calli instruction. The CLR _will_ crash.");
/*
- void TestNativeCallableViaCalli()
+ void TestUnmanagedCallersOnlyViaCalli()
{
.locals init (native int V_0)
IL_0000: nop
IL_0014: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("TestNativeCallableViaCalli", null, null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("TestUnmanagedCallersOnlyViaCalli", null, null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
il.Emit(OpCodes.Nop);
il.Emit(OpCodes.Ret);
- NativeMethodInvoker testNativeMethod = (NativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(NativeMethodInvoker));
+ NativeMethodInvoker testNativeMethod = (NativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(NativeMethodInvoker));
// It is not possible to catch the resulting ExecutionEngineException exception.
// To observe the crashing behavior set a breakpoint in the ReversePInvokeBadTransition() function
testNativeMethod();
}
- [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ [UnmanagedCallersOnly(CallingConvention = CallingConvention.StdCall)]
public static int CallbackViaUnmanagedCalli(int val)
{
return DoubleImpl(val);
}
- public static void TestNativeCallableViaUnmanagedCalli()
+ public static void TestUnmanagedCallersOnlyViaUnmanagedCalli()
{
- Console.WriteLine($"Running {nameof(TestNativeCallableViaUnmanagedCalli)}...");
+ Console.WriteLine($"Running {nameof(TestUnmanagedCallersOnlyViaUnmanagedCalli)}...");
/*
- void NativeCallableViaCalli()
+ void UnmanagedCallersOnlyViaCalli()
{
.locals init (native int V_0)
IL_0000: nop
IL_0014: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("NativeCallableViaUnmanagedCalli", typeof(int), null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("UnmanagedCallersOnlyViaUnmanagedCalli", typeof(int), null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
il.Emit(OpCodes.Ret);
- IntNativeMethodInvoker testNativeMethod = (IntNativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(IntNativeMethodInvoker));
+ IntNativeMethodInvoker testNativeMethod = (IntNativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(IntNativeMethodInvoker));
int expected = DoubleImpl(n);
Assert.AreEqual(expected, testNativeMethod());
}
- [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ [UnmanagedCallersOnly(CallingConvention = CallingConvention.StdCall)]
public static int CallbackViaUnmanagedCalliThrows(int val)
{
throw new Exception() { HResult = CallbackThrowsErrorCode };
}
- public static void TestNativeCallableViaUnmanagedCalli_ThrowException()
+ public static void TestUnmanagedCallersOnlyViaUnmanagedCalli_ThrowException()
{
- Console.WriteLine($"Running {nameof(TestNativeCallableViaUnmanagedCalli_ThrowException)}...");
+ Console.WriteLine($"Running {nameof(TestUnmanagedCallersOnlyViaUnmanagedCalli_ThrowException)}...");
/*
- void NativeCallableViaUnmanagedCalli_ThrowException()
+ void UnmanagedCallersOnlyViaUnmanagedCalli_ThrowException()
{
.locals init (native int V_0)
IL_0000: nop
IL_0014: ret
}
*/
- DynamicMethod testNativeCallable = new DynamicMethod("NativeCallableViaUnmanagedCalli_ThrowException", typeof(int), null, typeof(Program).Module);
- ILGenerator il = testNativeCallable.GetILGenerator();
+ DynamicMethod testUnmanagedCallersOnly = new DynamicMethod("UnmanagedCallersOnlyViaUnmanagedCalli_ThrowException", typeof(int), null, typeof(Program).Module);
+ ILGenerator il = testUnmanagedCallersOnly.GetILGenerator();
il.DeclareLocal(typeof(IntPtr));
il.Emit(OpCodes.Nop);
il.Emit(OpCodes.Ret);
- IntNativeMethodInvoker testNativeMethod = (IntNativeMethodInvoker)testNativeCallable.CreateDelegate(typeof(IntNativeMethodInvoker));
+ IntNativeMethodInvoker testNativeMethod = (IntNativeMethodInvoker)testUnmanagedCallersOnly.CreateDelegate(typeof(IntNativeMethodInvoker));
try
{
</PropertyGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Interop.settings.targets))" />
<ItemGroup>
- <Compile Include="NativeCallableTest.cs" />
+ <Compile Include="UnmanagedCallersOnlyTest.cs" />
</ItemGroup>
<ItemGroup>
<!-- This is needed to make sure native binary gets installed in the right location -->
<value>Collection was of a fixed size.</value>
</data>
<data name="InvalidProgram_GenericMethod" xml:space="preserve">
- <value>Generic methods with NativeCallableAttribute are invalid.</value>
+ <value>Generic methods with UnmanagedCallersOnlyAttribute are invalid.</value>
</data>
<data name="InvalidOperation_SpanOverlappedOperation" xml:space="preserve">
<value>This operation is invalid on overlapping buffers.</value>
<data name="NotSupported_MustBeModuleBuilder" xml:space="preserve">
<value>Module argument must be a ModuleBuilder.</value>
</data>
- <data name="NotSupported_NativeCallableTarget" xml:space="preserve">
- <value>Methods with NativeCallableAttribute cannot be used as delegate target.</value>
+ <data name="NotSupported_UnmanagedCallersOnlyTarget" xml:space="preserve">
+ <value>Methods with UnmanagedCallersOnlyAttribute cannot be used as delegate target.</value>
</data>
<data name="NotSupported_NoCodepageData" xml:space="preserve">
<value>No data is available for encoding {0}. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.</value>
</data>
<data name="InvalidProgram_NonBlittableTypes" xml:space="preserve">
- <value>Non-blittable parameter types are invalid for NativeCallable methods.</value>
+ <value>Non-blittable parameter types are invalid for UnmanagedCallersOnly methods.</value>
</data>
<data name="NotSupported_NonReflectedType" xml:space="preserve">
<value>Not supported in a non-reflected type.</value>
</data>
<data name="InvalidProgram_NonStaticMethod" xml:space="preserve">
- <value>Non-static methods with NativeCallableAttribute are invalid.</value>
+ <value>Non-static methods with UnmanagedCallersOnlyAttribute are invalid.</value>
</data>
<data name="NotSupported_NoParentDefaultConstructor" xml:space="preserve">
<value>Parent does not have a default constructor. The default constructor must be explicitly defined.</value>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MarshalAsAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MarshalDirectiveException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\MemoryMarshal.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeCallableAttribute.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\NativeLibrary.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OptionalAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\InteropServices\OutAttribute.cs" />
}
// EnumCalendarInfoExEx callback itself.
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ // [UnmanagedCallersOnly(CallingConvention = CallingConvention.StdCall)]
private static unsafe Interop.BOOL EnumCalendarInfoCallback(char* lpCalendarInfoString, uint calendar, IntPtr pReserved, void* lParam)
{
ref EnumData context = ref Unsafe.As<byte, EnumData>(ref *(byte*)lParam);
public List<int> calendars; // list of calendars found so far
}
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ // [UnmanagedCallersOnly(CallingConvention = CallingConvention.StdCall)]
private static unsafe Interop.BOOL EnumCalendarsCallback(char* lpCalendarInfoString, uint calendar, IntPtr reserved, void* lParam)
{
ref NlsEnumCalendarsData context = ref Unsafe.As<byte, NlsEnumCalendarsData>(ref *(byte*)lParam);
}
// EnumSystemLocaleEx callback.
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ // [UnmanagedCallersOnly(CallingConvention = CallingConvention.StdCall)]
private static unsafe Interop.BOOL EnumSystemLocalesProc(char* lpLocaleString, uint flags, void* contextHandle)
{
ref EnumLocaleData context = ref Unsafe.As<byte, EnumLocaleData>(ref *(byte*)contextHandle);
}
// EnumSystemLocaleEx callback.
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ // [UnmanagedCallersOnly(CallingConvention = CallingConvention.StdCall)]
private static unsafe Interop.BOOL EnumAllSystemLocalesProc(char* lpLocaleString, uint flags, void* contextHandle)
{
ref EnumData context = ref Unsafe.As<byte, EnumData>(ref *(byte*)contextHandle);
}
// EnumTimeFormatsEx callback itself.
- // [NativeCallable(CallingConvention = CallingConvention.StdCall)]
+ // [UnmanagedCallersOnly(CallingConvention = CallingConvention.StdCall)]
private static unsafe Interop.BOOL EnumTimeCallback(char* lpTimeFormatString, void* lParam)
{
ref EnumData context = ref Unsafe.As<byte, EnumData>(ref *(byte*)lParam);
namespace System.Runtime.InteropServices
{
- // Used for the CallingConvention named argument to the DllImport and NativeCallable attribute
+ // Used for the CallingConvention named argument to the DllImport and UnmanagedCallersOnly attribute
public enum CallingConvention
{
Winapi = 1,
namespace System.Runtime.InteropServices
{
/// <summary>
- /// Any method marked with <see cref="System.Runtime.InteropServices.NativeCallableAttribute" /> can be directly called from
+ /// Any method marked with <see cref="System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute" /> can be directly called from
/// native code. The function token can be loaded to a local variable using the <see href="https://docs.microsoft.com/dotnet/csharp/language-reference/operators/pointer-related-operators#address-of-operator-">address-of</see> operator
/// in C# and passed as a callback to a native method.
/// </summary>
/// * Must only have <see href="https://docs.microsoft.com/dotnet/framework/interop/blittable-and-non-blittable-types">blittable</see> arguments.
/// </remarks>
[AttributeUsage(AttributeTargets.Method)]
- public sealed class NativeCallableAttribute : Attribute
+ public sealed class UnmanagedCallersOnlyAttribute : Attribute
{
- public NativeCallableAttribute()
+ public UnmanagedCallersOnlyAttribute()
{
}
public CallingConvention CallingConvention;
/// <summary>
- /// Optional. If omitted, then the method is native callable, but no export is emitted during compilation.
+ /// Optional. If omitted, no named export is emitted during compilation.
/// </summary>
public string? EntryPoint;
}
protected static void GetIUnknownImpl(out System.IntPtr fpQueryInterface, out System.IntPtr fpAddRef, out System.IntPtr fpRelease) { throw null; }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Method)]
- public sealed class NativeCallableAttribute : System.Attribute
+ public sealed class UnmanagedCallersOnlyAttribute : System.Attribute
{
- public NativeCallableAttribute() { }
+ public UnmanagedCallersOnlyAttribute() { }
public System.Runtime.InteropServices.CallingConvention CallingConvention;
public string? EntryPoint;
}