From e0416c0125d05331e444a8fa1db35eb32d82baa9 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 11 Nov 2017 15:12:23 -0800 Subject: [PATCH] Define CORERT for ProjectN builds CoreRT is component of ProjectN (aka .NET Native for UWP), but our current defines do not reflect it because of CORERT is not defined in ProjectN builds. This creates confusion for folks outside the core runtime team, and conflicts with our documentation. For example, https://github.com/dotnet/corert/blob/master/Documentation/intro-to-corert.md says "CoreRT is the .NET Core runtime that is optimized for AOT scenarios, which .NET Native targets". It does not say "CoreRT is the .NET Core runtime optimized for AOT scenarios that uses RyuJIT backend" or anything like that. - Before this change: PROJECTN: defined in closed source ProjectN builds CORERT: defined in open source CoreRT builds CORECLR: defined in CoreCLR builds - After this change: PROJECTN: defined in closed source ProjectN builds (same) CORERT: defined in both open source CoreRT builds and closed source ProjectN builds (different) CORECLR: defined in CoreCLR builds (same) [tfs-changeset: 1680901] --- dir.props | 2 +- .../CompilerHelpers/StartupCodeHelpers.cs | 6 +- src/Common/src/Internal/Runtime/EEType.cs | 2 +- .../Internal/Runtime/TypeManagerHandle.RVA.cs | 8 +- .../UtcDictionaryLayoutNode.cs | 2 +- .../Compiler/UtcStackTraceEmissionPolicy.cs | 7 +- src/Native/Runtime/EHHelpers.cpp | 8 +- src/Native/Runtime/MathHelpers.cpp | 6 +- src/Native/Runtime/MiscHelpers.cpp | 22 +- src/Native/Runtime/RuntimeInstance.cpp | 2 +- src/Native/Runtime/TypeManager.cpp | 2 +- .../Runtime/amd64/ExceptionHandling.asm | 12 +- src/Native/Runtime/inc/rhbinder.h | 6 +- src/Native/Runtime/startup.cpp | 4 +- src/Native/Runtime/thread.cpp | 12 +- src/Native/Runtime/thread.h | 8 +- .../Runtime/windows/PalRedhawkMinWin.cpp | 8 +- .../src/System/Runtime/EEType.Runtime.cs | 8 +- .../src/System/Runtime/EETypePtr.cs | 4 +- .../src/System/RuntimeTypeHandle.cs | 2 +- .../Collections/ListDictionaryInternal.cs | 8 +- .../shared/System/DefaultBinder.cs | 6 +- .../shared/System/ReadOnlySpan.cs | 2 - .../System/Reflection/MethodInfo.Internal.cs | 7 +- .../Reflection/SignatureTypeExtensions.cs | 6 +- .../System/Resources/RuntimeResourceSet.cs | 8 +- .../AsyncValueTaskMethodBuilder.cs | 10 +- .../shared/System/Span.cs | 2 - .../shared/System/UnitySerializationHolder.cs | 6 +- .../Runtime/Augments/RuntimeAugments.cs | 8 +- .../CompilerHelpers/ReflectionHelpers.cs | 12 +- .../StartupCodeHelpers.Reflection.cs | 26 +- .../src/System/Array.CoreRT.cs | 2 +- .../System/Collections/Generic/Comparer.cs | 8 +- .../Collections/Generic/EqualityComparer.cs | 8 +- .../src/System/Exception.cs | 2 +- .../ClassConstructorRunner.cs | 2 +- .../src/System/Runtime/RuntimeImports.cs | 22 +- .../src/System/Threading/Interlocked.cs | 436 +++++++++--------- .../src/System/Threading/Lock.cs | 8 +- .../CompilerHelpers/LibraryInitializer.cs | 2 +- .../src/Shared/ComCallableObject.cs | 4 +- .../src/Shared/McgComHelpers.cs | 2 +- .../src/Shared/McgIntrinsics.cs | 2 +- .../src/Shared/McgMarshal.cs | 12 +- .../src/Shared/McgModuleManager.cs | 2 +- .../src/Shared/McgTypeHelpers.cs | 26 +- .../src/Shared/__ComObject.cs | 16 +- ...EnvironmentImplementation.MappingTables.cs | 12 +- ...PointerTypeFieldAccessorForStaticFields.cs | 5 +- ...ferenceTypeFieldAccessorForStaticFields.cs | 5 +- .../ValueTypeFieldAccessorForStaticFields.cs | 5 +- .../TypeLoader/ConstrainedCallSupport.cs | 4 +- .../Runtime/TypeLoader/EETypeCreator.cs | 2 +- .../TypeLoader/ExternalReferencesTable.cs | 42 +- .../Runtime/TypeLoader/TypeBuilder.cs | 24 +- .../TypeLoaderEnvironment.FieldAccess.cs | 6 +- ...peLoaderEnvironment.LdTokenResultLookup.cs | 44 +- .../TypeLoaderEnvironment.Metadata.cs | 10 +- .../TypeLoader/genericdictionarycell.cs | 2 +- .../TypeSystem/TypeSystemContext.Runtime.cs | 2 +- 61 files changed, 466 insertions(+), 483 deletions(-) diff --git a/dir.props b/dir.props index 4b766f49c..028d688d0 100644 --- a/dir.props +++ b/dir.props @@ -214,7 +214,7 @@ - + CORERT;$(DefineConstants) diff --git a/src/Common/src/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs b/src/Common/src/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs index af73c636a..b1dffffd4 100644 --- a/src/Common/src/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs +++ b/src/Common/src/Internal/Runtime/CompilerHelpers/StartupCodeHelpers.cs @@ -86,7 +86,7 @@ namespace Internal.Runtime.CompilerHelpers section->TypeManager = typeManager; section->ModuleIndex = moduleIndex; -#if CORERT +#if !PROJECTN // Initialize statics if any are present IntPtr staticsSection = RuntimeImports.RhGetModuleSection(typeManager, ReadyToRunSectionType.GCStaticRegion, out length); if (staticsSection != IntPtr.Zero) @@ -141,7 +141,7 @@ namespace Internal.Runtime.CompilerHelpers } } -#if CORERT +#if !PROJECTN private static unsafe void InitializeStatics(IntPtr gcStaticRegionStart, int length) { IntPtr gcStaticRegionEnd = (IntPtr)((byte*)gcStaticRegionStart + length); @@ -172,7 +172,7 @@ namespace Internal.Runtime.CompilerHelpers } } } -#endif // CORERT +#endif // !PROJECTN } [StructLayout(LayoutKind.Sequential)] diff --git a/src/Common/src/Internal/Runtime/EEType.cs b/src/Common/src/Internal/Runtime/EEType.cs index 266c9dec9..c9852dd80 100644 --- a/src/Common/src/Internal/Runtime/EEType.cs +++ b/src/Common/src/Internal/Runtime/EEType.cs @@ -1184,7 +1184,7 @@ namespace Internal.Runtime } } #endif -#endif // CORERT +#endif // EETYPE_TYPE_MANAGER internal unsafe EETypeRareFlags RareFlags { diff --git a/src/Common/src/Internal/Runtime/TypeManagerHandle.RVA.cs b/src/Common/src/Internal/Runtime/TypeManagerHandle.RVA.cs index a7aee07d0..b3fed2ac5 100644 --- a/src/Common/src/Internal/Runtime/TypeManagerHandle.RVA.cs +++ b/src/Common/src/Internal/Runtime/TypeManagerHandle.RVA.cs @@ -71,11 +71,11 @@ namespace System.Runtime [CLSCompliant(false)] public unsafe byte* ConvertRVAToPointer(uint rva) { -#if CORERT - Environment.FailFast("RVA fixups not supported in CoreRT"); - return null; -#else +#if PROJECTN return ((byte*)OsModuleBase) + rva; +#else + Environment.FailFast("RVA fixups not supported"); + return null; #endif } diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/UtcDictionaryLayoutNode.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/UtcDictionaryLayoutNode.cs index c5038e064..d268fa17b 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/UtcDictionaryLayoutNode.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/UtcDictionaryLayoutNode.cs @@ -38,7 +38,7 @@ namespace ILCompiler.DependencyAnalysis } -#if CORERT +#if !PROJECTN public override void EnsureEntry(GenericLookupResult lookupResult) => throw new NotImplementedException(); public override int GetSlotForEntry(GenericLookupResult entry) => throw new NotImplementedException(); public override IEnumerable Entries => throw new NotImplementedException(); diff --git a/src/ILCompiler.Compiler/src/Compiler/UtcStackTraceEmissionPolicy.cs b/src/ILCompiler.Compiler/src/Compiler/UtcStackTraceEmissionPolicy.cs index 1c44d690e..c17a8fb31 100644 --- a/src/ILCompiler.Compiler/src/Compiler/UtcStackTraceEmissionPolicy.cs +++ b/src/ILCompiler.Compiler/src/Compiler/UtcStackTraceEmissionPolicy.cs @@ -122,7 +122,7 @@ namespace ILCompiler /// string GetAppExeDirectory() { -#if !CORERT +#if PROJECTN var process = Process.GetCurrentProcess(); string fullPath = process.MainModule.FileName; return Path.GetDirectoryName(fullPath); @@ -137,10 +137,7 @@ namespace ILCompiler /// void LoadExceptionFile(string exceptionFileName) { -#if CORERT - Debug.Assert(false); - return; -#else +#if PROJECTN if (!File.Exists(exceptionFileName)) return; diff --git a/src/Native/Runtime/EHHelpers.cpp b/src/Native/Runtime/EHHelpers.cpp index 2b4817386..d0f818f12 100644 --- a/src/Native/Runtime/EHHelpers.cpp +++ b/src/Native/Runtime/EHHelpers.cpp @@ -361,10 +361,7 @@ static bool InWriteBarrierHelper(UIntNative faultingIP) (UIntNative)&RhpCheckedAssignRefAVLocation, (UIntNative)&RhpCheckedLockCmpXchgAVLocation, (UIntNative)&RhpCheckedXchgAVLocation, -#ifdef CORERT - (UIntNative)&RhpLockCmpXchg32AVLocation, - (UIntNative)&RhpLockCmpXchg64AVLocation, -#else +#ifdef PROJECTN (UIntNative)&RhpCopyMultibyteDestAVLocation, (UIntNative)&RhpCopyMultibyteSrcAVLocation, (UIntNative)&RhpCopyMultibyteNoGCRefsDestAVLocation, @@ -373,6 +370,9 @@ static bool InWriteBarrierHelper(UIntNative faultingIP) (UIntNative)&RhpCopyMultibyteWithWriteBarrierSrcAVLocation, (UIntNative)&RhpCopyAnyWithWriteBarrierDestAVLocation, (UIntNative)&RhpCopyAnyWithWriteBarrierSrcAVLocation, +#else + (UIntNative)&RhpLockCmpXchg32AVLocation, + (UIntNative)&RhpLockCmpXchg64AVLocation, #endif }; diff --git a/src/Native/Runtime/MathHelpers.cpp b/src/Native/Runtime/MathHelpers.cpp index e299c26bb..88a26a556 100644 --- a/src/Native/Runtime/MathHelpers.cpp +++ b/src/Native/Runtime/MathHelpers.cpp @@ -15,8 +15,8 @@ EXTERN_C REDHAWK_API UInt64 REDHAWK_CALLCONV RhpDbl2ULng(double val) return((UInt64)val); } -// CORERT Specific - on Project N the arguments to these helpers are inverted -#ifdef CORERT +// On ProjectN the arguments to these helpers are inverted +#ifndef PROJECTN #undef min #undef max #include @@ -80,7 +80,7 @@ EXTERN_C REDHAWK_API float REDHAWK_CALLCONV RhpFltRound(float value) return roundf(value); } -#endif // CORERT +#endif // !PROJECTN #ifdef _ARM_ EXTERN_C REDHAWK_API Int32 REDHAWK_CALLCONV RhpIDiv(Int32 i, Int32 j) diff --git a/src/Native/Runtime/MiscHelpers.cpp b/src/Native/Runtime/MiscHelpers.cpp index 44571df7e..f11129d1d 100644 --- a/src/Native/Runtime/MiscHelpers.cpp +++ b/src/Native/Runtime/MiscHelpers.cpp @@ -185,9 +185,7 @@ COOP_PINVOKE_HELPER(HANDLE, RhGetOSModuleFromPointer, (PTR_VOID pPointerVal)) COOP_PINVOKE_HELPER(HANDLE, RhGetOSModuleFromEEType, (EEType * pEEType)) { -#if CORERT - return pEEType->GetTypeManagerPtr()->AsTypeManager()->GetOsModuleHandle(); -#else +#if PROJECTN #if EETYPE_TYPE_MANAGER if (pEEType->HasTypeManager()) return pEEType->GetTypeManagerPtr()->AsTypeManager()->GetOsModuleHandle(); @@ -210,14 +208,14 @@ COOP_PINVOKE_HELPER(HANDLE, RhGetOSModuleFromEEType, (EEType * pEEType)) // We should never get here (an EEType not located in any module) so fail fast to indicate the bug. RhFailFast(); return NULL; -#endif // !CORERT +#else + return pEEType->GetTypeManagerPtr()->AsTypeManager()->GetOsModuleHandle(); +#endif // PROJECTN } COOP_PINVOKE_HELPER(TypeManagerHandle, RhGetModuleFromEEType, (EEType * pEEType)) { -#if CORERT - return *pEEType->GetTypeManagerPtr(); -#else +#if PROJECTN #if EETYPE_TYPE_MANAGER if (pEEType->HasTypeManager()) return *pEEType->GetTypeManagerPtr(); @@ -244,7 +242,9 @@ COOP_PINVOKE_HELPER(TypeManagerHandle, RhGetModuleFromEEType, (EEType * pEEType) // We should never get here (an EEType not located in any module) so fail fast to indicate the bug. RhFailFast(); return TypeManagerHandle::Null(); -#endif // !CORERT +#else + return *pEEType->GetTypeManagerPtr(); +#endif // PROJECTN } COOP_PINVOKE_HELPER(Boolean, RhFindBlob, (TypeManagerHandle *pTypeManagerHandle, UInt32 blobId, UInt8 ** ppbBlob, UInt32 * pcbBlob)) @@ -268,7 +268,7 @@ COOP_PINVOKE_HELPER(Boolean, RhFindBlob, (TypeManagerHandle *pTypeManagerHandle, return pBlob != NULL; } -#if !CORERT +#if PROJECTN else { HANDLE hOsModule = typeManagerHandle.AsOsModule(); @@ -307,7 +307,7 @@ COOP_PINVOKE_HELPER(Boolean, RhFindBlob, (TypeManagerHandle *pTypeManagerHandle, } END_FOREACH_MODULE } -#endif // !CORERT +#endif // PROJECTN // If we get here we were passed a bad module handle and should fail fast since this indicates a nasty bug // (which could lead to the wrong blob being returned in some cases). @@ -384,7 +384,7 @@ COOP_PINVOKE_HELPER(UInt8 *, RhGetThreadStaticFieldAddress, (EEType * pEEType, U } else { -#if EETYPE_TYPE_MANAGER && !CORERT /* TODO: CORERT */ +#if EETYPE_TYPE_MANAGER && PROJECTN /* TODO: CORERT */ if (pEEType->HasTypeManager()) { TypeManager* pTypeManager = pEEType->GetTypeManagerPtr()->AsTypeManager(); diff --git a/src/Native/Runtime/RuntimeInstance.cpp b/src/Native/Runtime/RuntimeInstance.cpp index 76823ed87..9bda02075 100644 --- a/src/Native/Runtime/RuntimeInstance.cpp +++ b/src/Native/Runtime/RuntimeInstance.cpp @@ -715,7 +715,7 @@ bool RuntimeInstance::CreateGenericAndStaticInfo(EEType * pEEType, } NewArrayHolder pGcStaticData; -#ifndef CORERT +#ifdef PROJECTN if (gcStaticDataSize > 0) { // The value of gcStaticDataSize is read from native layout info in the managed layer, where diff --git a/src/Native/Runtime/TypeManager.cpp b/src/Native/Runtime/TypeManager.cpp index c4e8ce6df..5f80ef792 100644 --- a/src/Native/Runtime/TypeManager.cpp +++ b/src/Native/Runtime/TypeManager.cpp @@ -180,7 +180,7 @@ HANDLE TypeManager::GetOsModuleHandle() bool TypeManagerHandle::IsTypeManager() { -#if !CORERT +#if PROJECTN if (((uintptr_t)_value & 1) == 0) return false; #endif diff --git a/src/Native/Runtime/amd64/ExceptionHandling.asm b/src/Native/Runtime/amd64/ExceptionHandling.asm index b2fb7e036..566dad71f 100644 --- a/src/Native/Runtime/amd64/ExceptionHandling.asm +++ b/src/Native/Runtime/amd64/ExceptionHandling.asm @@ -424,11 +424,11 @@ endif movdqa xmm14,[r8 + OFFSETOF__REGDISPLAY__Xmm + 8*10h] movdqa xmm15,[r8 + OFFSETOF__REGDISPLAY__Xmm + 9*10h] -ifdef CORERT ;; @TODO Reconcile +ifdef PROJECTN ;; @TODO Reconcile + mov rcx, [rsp + rsp_offsetof_arguments + 0h] ;; rcx <- exception object +else mov rcx, [r8 + OFFSETOF__REGDISPLAY__SP] ;; rcx <- establisher frame mov rdx, [rsp + rsp_offsetof_arguments + 0h] ;; rdx <- exception object -else - mov rcx, [rsp + rsp_offsetof_arguments + 0h] ;; rcx <- exception object endif call qword ptr [rsp + rsp_offsetof_arguments + 8h] ;; call handler funclet @@ -666,11 +666,11 @@ NESTED_ENTRY RhpCallFilterFunclet, _TEXT mov rbp, [rax] mov rax, rdx ;; rax <- handler funclet address -ifdef CORERT ;; @TODO Reconcile +ifdef PROJECTN ;; @TODO Reconcile + ;; RCX still contains the exception object +else mov rdx, rcx ;; rdx <- exception object mov rcx, [r8 + OFFSETOF__REGDISPLAY__SP] ;; rcx <- establisher frame -else - ;; RCX still contains the exception object endif call rax diff --git a/src/Native/Runtime/inc/rhbinder.h b/src/Native/Runtime/inc/rhbinder.h index 8a932e406..356b9acd8 100644 --- a/src/Native/Runtime/inc/rhbinder.h +++ b/src/Native/Runtime/inc/rhbinder.h @@ -689,7 +689,7 @@ enum PInvokeTransitionFrameFlags #pragma warning(push) #pragma warning(disable:4200) // nonstandard extension used: zero-sized array in struct/union class Thread; -#if defined(USE_PORTABLE_HELPERS) && defined(CORERT) +#if defined(USE_PORTABLE_HELPERS) //the members of this structure are currently unused except m_pThread and exist only to allow compilation //of StackFrameIterator their values are not currently being filled in and will require significant rework //in order to satisfy the runtime requirements of StackFrameIterator @@ -700,7 +700,7 @@ struct PInvokeTransitionFrame // can be an invalid pointer in universal transition cases (which never need to call GetThread) uint32_t m_dwFlags; // PInvokeTransitionFrameFlags }; -#else // USE_PORTABLE_HELPERS && CORERT +#else // USE_PORTABLE_HELPERS struct PInvokeTransitionFrame { #ifdef _TARGET_ARM_ @@ -722,7 +722,7 @@ struct PInvokeTransitionFrame #endif UIntTarget m_PreservedRegs[]; }; -#endif // USE_PORTABLE_HELPERS && CORERT +#endif // USE_PORTABLE_HELPERS #pragma warning(pop) #ifdef _TARGET_AMD64_ diff --git a/src/Native/Runtime/startup.cpp b/src/Native/Runtime/startup.cpp index 4b2a7be4f..80f576919 100644 --- a/src/Native/Runtime/startup.cpp +++ b/src/Native/Runtime/startup.cpp @@ -147,7 +147,7 @@ static void CheckForPalFallback() void DetectCPUFeatures() { -#if !defined(CORERT) // @TODO: CORERT: DetectCPUFeatures +#ifdef PROJECTN // @TODO: CORERT: DetectCPUFeatures #ifdef _X86_ // We depend on fxsave / fxrstor. These were added to Pentium II and later, so they're pretty well guaranteed to be @@ -167,7 +167,7 @@ void DetectCPUFeatures() g_fHasFastFxsave = true; #endif -#endif // !CORERT +#endif // PROJECTN } #ifdef PROFILE_STARTUP diff --git a/src/Native/Runtime/thread.cpp b/src/Native/Runtime/thread.cpp index c106963fc..ec5c69654 100644 --- a/src/Native/Runtime/thread.cpp +++ b/src/Native/Runtime/thread.cpp @@ -289,10 +289,10 @@ void Thread::Construct() m_numDynamicTypesTlsCells = 0; m_pDynamicTypesTlsCells = NULL; -#if CORERT +#ifndef PROJECTN m_pThreadLocalModuleStatics = NULL; m_numThreadLocalModuleStatics = 0; -#endif // CORERT +#endif // PROJECTN // NOTE: We do not explicitly defer to the GC implementation to initialize the alloc_context. The // alloc_context will be initialized to 0 via the static initialization of tls_CurrentThread. If the @@ -380,7 +380,7 @@ void Thread::Destroy() delete[] m_pDynamicTypesTlsCells; } -#if CORERT +#ifndef PROJECTN if (m_pThreadLocalModuleStatics != NULL) { for (UInt32 i = 0; i < m_numThreadLocalModuleStatics; i++) @@ -392,7 +392,7 @@ void Thread::Destroy() } delete[] m_pThreadLocalModuleStatics; } -#endif // CORERT +#endif // !PROJECTN RedhawkGCInterface::ReleaseAllocContext(GetAllocContext()); @@ -1199,7 +1199,7 @@ COOP_PINVOKE_HELPER(Object *, RhpGetThreadAbortException, ()) return pCurThread->GetThreadAbortException(); } -#if CORERT +#ifndef PROJECTN Object* Thread::GetThreadStaticStorageForModule(UInt32 moduleIndex) { // Return a pointer to the TLS storage if it has already been @@ -1282,7 +1282,7 @@ COOP_PINVOKE_HELPER(UInt8*, RhCurrentNativeThreadId, ()) return (UInt8*)ThreadStore::RawGetCurrentThread(); #endif // PLATFORM_UNIX } -#endif // CORERT +#endif // !PROJECTN // Standard calling convention variant and actual implementation for RhpReversePInvokeAttachOrTrapThread EXTERN_C NOINLINE void FASTCALL RhpReversePInvokeAttachOrTrapThread2(ReversePInvokeFrame * pFrame) diff --git a/src/Native/Runtime/thread.h b/src/Native/Runtime/thread.h index 63a89c715..8ff608932 100644 --- a/src/Native/Runtime/thread.h +++ b/src/Native/Runtime/thread.h @@ -93,10 +93,10 @@ struct ThreadBuffer UInt32 m_numDynamicTypesTlsCells; PTR_PTR_UInt8 m_pDynamicTypesTlsCells; -#if CORERT +#ifndef PROJECTN PTR_PTR_VOID m_pThreadLocalModuleStatics; UInt32 m_numThreadLocalModuleStatics; -#endif // CORERT +#endif // PROJECTN }; struct ReversePInvokeFrame @@ -261,10 +261,10 @@ public: Object * GetThreadAbortException(); void SetThreadAbortException(Object *exception); -#if CORERT +#ifndef PROJECTN Object* GetThreadStaticStorageForModule(UInt32 moduleIndex); Boolean SetThreadStaticStorageForModule(Object * pStorage, UInt32 moduleIndex); -#endif // CORERT +#endif // PROJECTN }; #ifndef GCENV_INCLUDED diff --git a/src/Native/Runtime/windows/PalRedhawkMinWin.cpp b/src/Native/Runtime/windows/PalRedhawkMinWin.cpp index c70ab884e..209b5c0b9 100644 --- a/src/Native/Runtime/windows/PalRedhawkMinWin.cpp +++ b/src/Native/Runtime/windows/PalRedhawkMinWin.cpp @@ -17,7 +17,7 @@ #include #include #include -#ifndef CORERT +#ifdef PROJECTN #include #endif @@ -1377,7 +1377,7 @@ REDHAWK_PALEXPORT _Ret_maybenull_ void* REDHAWK_PALAPI PalSetWerDataBuffer(_In_ static LARGE_INTEGER g_performanceFrequency; -#ifndef CORERT +#ifdef PROJECTN static bool g_roInitialized; #endif @@ -1391,7 +1391,7 @@ bool GCToOSInterface::Initialize() return false; } -#ifndef CORERT +#ifdef PROJECTN // TODO: Remove the RoInitialize call when we implement non-WinRT framework for classic apps HRESULT hr = RoInitialize(RO_INIT_MULTITHREADED); @@ -1415,7 +1415,7 @@ bool GCToOSInterface::Initialize() // Must be called on the same thread as Initialize. void GCToOSInterface::Shutdown() { -#ifndef CORERT +#ifdef PROJECTN if (g_roInitialized) { RoUninitialize(); diff --git a/src/Runtime.Base/src/System/Runtime/EEType.Runtime.cs b/src/Runtime.Base/src/System/Runtime/EEType.Runtime.cs index 4bd520a25..3a1e8a954 100644 --- a/src/Runtime.Base/src/System/Runtime/EEType.Runtime.cs +++ b/src/Runtime.Base/src/System/Runtime/EEType.Runtime.cs @@ -29,12 +29,12 @@ namespace Internal.Runtime if (pGetArrayEEType != IntPtr.Zero) return (EEType*)CalliIntrinsics.Call(pGetArrayEEType); } -#if CORERT - EH.FallbackFailFast(RhFailFastReason.InternalError, null); - return null; -#else +#if PROJECTN fixed (EEType* pThis = &this) return InternalCalls.RhpGetArrayBaseType(pThis); +#else + EH.FallbackFailFast(RhFailFastReason.InternalError, null); + return null; #endif } diff --git a/src/Runtime.Base/src/System/Runtime/EETypePtr.cs b/src/Runtime.Base/src/System/Runtime/EETypePtr.cs index 26355a84a..1ea073625 100644 --- a/src/Runtime.Base/src/System/Runtime/EETypePtr.cs +++ b/src/Runtime.Base/src/System/Runtime/EETypePtr.cs @@ -40,8 +40,8 @@ namespace System return (Internal.Runtime.EEType*)(void*)_value; } -#if CORERT - // This only works on CoreRT (with no fallback) because Runtime.Base doesn't have enough infrastructure +#if !PROJECTN + // This does not work on ProjectN (with no fallback) because Runtime.Base doesn't have enough infrastructure // to let us express typeof(T).TypeHandle.ToEETypePtr(). [Intrinsic] internal static EETypePtr EETypePtrOf() diff --git a/src/Runtime.Base/src/System/RuntimeTypeHandle.cs b/src/Runtime.Base/src/System/RuntimeTypeHandle.cs index 018057b33..37c592696 100644 --- a/src/Runtime.Base/src/System/RuntimeTypeHandle.cs +++ b/src/Runtime.Base/src/System/RuntimeTypeHandle.cs @@ -21,7 +21,7 @@ namespace System { private EETypePtr _pEEType; -#if CORERT +#if !PROJECTN [Intrinsic] internal static unsafe IntPtr GetValueInternal(RuntimeTypeHandle handle) { diff --git a/src/System.Private.CoreLib/shared/System/Collections/ListDictionaryInternal.cs b/src/System.Private.CoreLib/shared/System/Collections/ListDictionaryInternal.cs index 28593d3c8..a8b7a187d 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/ListDictionaryInternal.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/ListDictionaryInternal.cs @@ -19,11 +19,11 @@ namespace System.Collections /// will be smaller and faster than a Hashtable if the number of elements is 10 or less. /// This should not be used if performance is important for large numbers of elements. [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] -#if CORECLR - internal -#else + [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] +#if CORERT public +#else + internal #endif class ListDictionaryInternal : IDictionary { diff --git a/src/System.Private.CoreLib/shared/System/DefaultBinder.cs b/src/System.Private.CoreLib/shared/System/DefaultBinder.cs index b6c12b121..f8d8c0c16 100644 --- a/src/System.Private.CoreLib/shared/System/DefaultBinder.cs +++ b/src/System.Private.CoreLib/shared/System/DefaultBinder.cs @@ -8,10 +8,10 @@ using CultureInfo = System.Globalization.CultureInfo; namespace System { -#if CORECLR - internal -#else +#if CORERT public sealed +#else + internal #endif partial class DefaultBinder : Binder { diff --git a/src/System.Private.CoreLib/shared/System/ReadOnlySpan.cs b/src/System.Private.CoreLib/shared/System/ReadOnlySpan.cs index 9f491f6de..28fb2e33e 100644 --- a/src/System.Private.CoreLib/shared/System/ReadOnlySpan.cs +++ b/src/System.Private.CoreLib/shared/System/ReadOnlySpan.cs @@ -173,9 +173,7 @@ namespace System return Unsafe.Add(ref _pointer.Value, index); } #else -#if CORERT [Intrinsic] -#endif [MethodImpl(MethodImplOptions.AggressiveInlining)] [NonVersionable] get diff --git a/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.Internal.cs b/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.Internal.cs index a36ef900d..2806be639 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.Internal.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.Internal.cs @@ -6,11 +6,10 @@ namespace System.Reflection { public abstract partial class MethodInfo : MethodBase { -#if CORECLR - internal +#if CORERT + public // Needs to be public so that Reflection.Core can see it. #else - // Not an api but needs to be public so that Reflection.Core can access it. - public + internal #endif virtual int GenericParameterCount => GetGenericArguments().Length; } diff --git a/src/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs b/src/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs index f0a33d0ba..5847944f1 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/SignatureTypeExtensions.cs @@ -8,10 +8,10 @@ using System.Diagnostics; namespace System.Reflection { -#if CORECLR - internal -#else +#if CORERT public // Needs to be public so that Reflection.Core can see it. +#else + internal #endif static class SignatureTypeExtensions { diff --git a/src/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs b/src/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs index eadc92c7f..a63e68c19 100644 --- a/src/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs +++ b/src/System.Private.CoreLib/shared/System/Resources/RuntimeResourceSet.cs @@ -160,10 +160,10 @@ namespace System.Resources // into smaller chunks, each of size sqrt(n), would be substantially better for // resource files containing thousands of resources. // -#if CORECLR - internal -#else +#if CORERT public // On CoreRT, this must be public because of need to whitelist past the ReflectionBlock. +#else + internal #endif sealed class RuntimeResourceSet : ResourceSet, IEnumerable { @@ -431,4 +431,4 @@ namespace System.Resources return value; } } -} \ No newline at end of file +} diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs index 813d9e5cd..b5ecd7924 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs @@ -25,14 +25,14 @@ namespace System.Runtime.CompilerServices /// Creates an instance of the struct. /// The initialized instance. public static AsyncValueTaskMethodBuilder Create() => -#if CORECLR - // _methodBuilder should be initialized to AsyncTaskMethodBuilder.Create(), but on coreclr - // that Create() is a nop, so we can just return the default here. - default(AsyncValueTaskMethodBuilder); -#else +#if CORERT // corert's AsyncTaskMethodBuilder.Create() currently does additional debugger-related // work, so we need to delegate to it. new AsyncValueTaskMethodBuilder() { _methodBuilder = AsyncTaskMethodBuilder.Create() }; +#else + // _methodBuilder should be initialized to AsyncTaskMethodBuilder.Create(), but on coreclr + // that Create() is a nop, so we can just return the default here. + default(AsyncValueTaskMethodBuilder); #endif /// Begins running the builder with the associated state machine. diff --git a/src/System.Private.CoreLib/shared/System/Span.cs b/src/System.Private.CoreLib/shared/System/Span.cs index aec83dea8..90ef2fca0 100644 --- a/src/System.Private.CoreLib/shared/System/Span.cs +++ b/src/System.Private.CoreLib/shared/System/Span.cs @@ -185,9 +185,7 @@ namespace System return ref Unsafe.Add(ref _pointer.Value, index); } #else -#if CORERT [Intrinsic] -#endif [MethodImpl(MethodImplOptions.AggressiveInlining)] [NonVersionable] get diff --git a/src/System.Private.CoreLib/shared/System/UnitySerializationHolder.cs b/src/System.Private.CoreLib/shared/System/UnitySerializationHolder.cs index bbfebff8a..2f3035670 100644 --- a/src/System.Private.CoreLib/shared/System/UnitySerializationHolder.cs +++ b/src/System.Private.CoreLib/shared/System/UnitySerializationHolder.cs @@ -11,10 +11,10 @@ namespace System /// This only exists for compatibility with .NET Framework. /// [Serializable] -#if CORECLR - internal +#if CORERT + public #else - public // On CoreRT this must be public. + internal #endif sealed class UnitySerializationHolder : ISerializable, IObjectReference { diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs index 5df0b6ace..d973489ad 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs @@ -592,10 +592,7 @@ namespace Internal.Runtime.Augments [Intrinsic] public static RuntimeTypeHandle GetCanonType(CanonTypeKind kind) { -#if CORERT - // Compiler needs to expand this. This is not expressible in IL. - throw new NotSupportedException(); -#else +#if PROJECTN switch (kind) { case CanonTypeKind.NormalCanon: @@ -606,6 +603,9 @@ namespace Internal.Runtime.Augments Debug.Assert(false); return default(RuntimeTypeHandle); } +#else + // Compiler needs to expand this. This is not expressible in IL. + throw new NotSupportedException(); #endif } diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ReflectionHelpers.cs b/src/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ReflectionHelpers.cs index e156e6306..5aaba3819 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ReflectionHelpers.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ReflectionHelpers.cs @@ -39,12 +39,12 @@ namespace Internal.Runtime.CompilerHelpers [System.Runtime.CompilerServices.DependencyReductionRoot] public static MethodBase GetCurrentMethodNonGeneric(RuntimeMethodHandle methodHandle) { -#if CORERT - return MethodBase.GetMethodFromHandle(methodHandle); -#else +#if PROJECTN // The compiler should ideally provide us with a RuntimeMethodHandle for the uninstantiated thing, // but the Project N toolchain cannot express a RuntimeMethodHandle for a generic definition of a generic method. return MethodBase.GetMethodFromHandle(methodHandle).MetadataDefinitionMethod; +#else + return MethodBase.GetMethodFromHandle(methodHandle); #endif } @@ -52,12 +52,12 @@ namespace Internal.Runtime.CompilerHelpers [System.Runtime.CompilerServices.DependencyReductionRoot] public static MethodBase GetCurrentMethodGeneric(RuntimeMethodHandle methodHandle, RuntimeTypeHandle typeHandle) { -#if CORERT - return MethodBase.GetMethodFromHandle(methodHandle, typeHandle); -#else +#if PROJECTN // The compiler should ideally provide us with a RuntimeMethodHandle for the uninstantiated thing, // but the Project N toolchain cannot express a RuntimeMethodHandle for a generic definition of a generic method. return MethodBase.GetMethodFromHandle(methodHandle, typeHandle).MetadataDefinitionMethod; +#else + return MethodBase.GetMethodFromHandle(methodHandle, typeHandle); #endif } } diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/StartupCode/StartupCodeHelpers.Reflection.cs b/src/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/StartupCode/StartupCodeHelpers.Reflection.cs index 18cf2328a..5d5efbc93 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/StartupCode/StartupCodeHelpers.Reflection.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/StartupCode/StartupCodeHelpers.Reflection.cs @@ -14,19 +14,7 @@ namespace Internal.Runtime.CompilerHelpers // ProjectN doesn't have access to a convenient always-reflection-enabled type to use. // (We can't use the type because of IL2IL toolchain limitations.) -#if CORERT - private static RuntimeTypeHandle s_entryAssemblyType; - - internal static void InitializeEntryAssembly(RuntimeTypeHandle entryAssemblyType) - { - s_entryAssemblyType = entryAssemblyType; - } - - internal static Assembly GetEntryAssembly() - { - return Type.GetTypeFromHandle(s_entryAssemblyType).Assembly; - } -#else +#if PROJECTN private static string s_entryAssemblyName; // The only reason why this is public is because the Project N IL2IL toolchain will remove this method @@ -46,6 +34,18 @@ namespace Internal.Runtime.CompilerHelpers } return null; } +#else + private static RuntimeTypeHandle s_entryAssemblyType; + + internal static void InitializeEntryAssembly(RuntimeTypeHandle entryAssemblyType) + { + s_entryAssemblyType = entryAssemblyType; + } + + internal static Assembly GetEntryAssembly() + { + return Type.GetTypeFromHandle(s_entryAssemblyType).Assembly; + } #endif } } diff --git a/src/System.Private.CoreLib/src/System/Array.CoreRT.cs b/src/System.Private.CoreLib/src/System/Array.CoreRT.cs index 503b0b0a7..02a190089 100644 --- a/src/System.Private.CoreLib/src/System/Array.CoreRT.cs +++ b/src/System.Private.CoreLib/src/System/Array.CoreRT.cs @@ -957,7 +957,7 @@ namespace System // correctness as well. private static EqualityComparer GetComparerForReferenceTypesOnly() { -#if !CORERT +#if PROJECTN // When T is a reference type or a universal canon type, then this will redirect to EqualityComparer.Default. return null; #else diff --git a/src/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs b/src/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs index 1121c12a8..e01f37892 100644 --- a/src/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs +++ b/src/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs @@ -21,13 +21,13 @@ namespace System.Collections.Generic [Intrinsic] private static Comparer Create() { -#if CORERT - // CORERT: TODO: https://github.com/dotnet/corert/issues/763 - return (_default = new DefaultComparer()); -#else +#if PROJECTN // The compiler will overwrite the Create method with optimized // instantiation-specific implementation. throw new NotSupportedException(); +#else + // CORERT: TODO: https://github.com/dotnet/corert/issues/763 + return (_default = new DefaultComparer()); #endif } diff --git a/src/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs b/src/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs index 131112c61..d28928caf 100644 --- a/src/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs @@ -22,13 +22,13 @@ namespace System.Collections.Generic [Intrinsic] private static EqualityComparer Create() { -#if CORERT - // CORERT: TODO: https://github.com/dotnet/corert/issues/763 - return (_default = new DefaultEqualityComparer()); -#else +#if PROJECTN // The compiler will overwrite the Create method with optimized // instantiation-specific implementation. throw new NotSupportedException(); +#else + // CORERT: TODO: https://github.com/dotnet/corert/issues/763 + return (_default = new DefaultEqualityComparer()); #endif } diff --git a/src/System.Private.CoreLib/src/System/Exception.cs b/src/System.Private.CoreLib/src/System/Exception.cs index d8fdaf34b..6e4aba99c 100644 --- a/src/System.Private.CoreLib/src/System/Exception.cs +++ b/src/System.Private.CoreLib/src/System/Exception.cs @@ -452,7 +452,7 @@ namespace System // CORERT-TODO: RhpEtwExceptionThrown // https://github.com/dotnet/corert/issues/2457 -#if !CORERT +#if PROJECTN if (isFirstFrame) { string typeName = !outOfMemory ? ex.GetType().ToString() : "System.OutOfMemoryException"; diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ClassConstructorRunner.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ClassConstructorRunner.cs index 44dfdeea0..51abcf771 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ClassConstructorRunner.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ClassConstructorRunner.cs @@ -30,7 +30,7 @@ namespace System.Runtime.CompilerServices // // No attempt is made to detect or break deadlocks due to other synchronization mechanisms. //============================================================================================================== -#if !CORERT +#if PROJECTN [RuntimeExport("CheckStaticClassConstruction")] public static unsafe void* CheckStaticClassConstruction(void* returnValue, StaticClassConstructionContext* pContext) { diff --git a/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index bf089391c..e2165d596 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -529,7 +529,14 @@ namespace System.Runtime return RhGetModuleSection(ref module, section, out length); } -#if CORERT +#if PROJECTN + [MethodImplAttribute(MethodImplOptions.InternalCall)] + [RuntimeImport(RuntimeLibrary, "RhGetLoadedOSModules")] + internal static extern uint RhGetLoadedOSModules(IntPtr[] resultArray); + [MethodImplAttribute(MethodImplOptions.InternalCall)] + [RuntimeImport(RuntimeLibrary, "RhGetLoadedModules")] + internal static extern uint RhGetLoadedModules(TypeManagerHandle[] resultArray); +#else internal static uint RhGetLoadedOSModules(IntPtr[] resultArray) { IntPtr[] loadedModules = Internal.Runtime.CompilerHelpers.StartupCodeHelpers.OSModules; @@ -549,13 +556,6 @@ namespace System.Runtime } return (uint)loadedModules.Length; } -#else - [MethodImplAttribute(MethodImplOptions.InternalCall)] - [RuntimeImport(RuntimeLibrary, "RhGetLoadedOSModules")] - internal static extern uint RhGetLoadedOSModules(IntPtr[] resultArray); - [MethodImplAttribute(MethodImplOptions.InternalCall)] - [RuntimeImport(RuntimeLibrary, "RhGetLoadedModules")] - internal static extern uint RhGetLoadedModules(TypeManagerHandle[] resultArray); #endif [MethodImplAttribute(MethodImplOptions.InternalCall)] @@ -578,7 +578,7 @@ namespace System.Runtime [RuntimeImport(RuntimeLibrary, "RhGetThreadStaticFieldAddress")] internal static extern unsafe byte* RhGetThreadStaticFieldAddress(EETypePtr pEEType, int threadStaticsBlockOffset, int fieldOffset); -#if CORERT +#if !PROJECTN [MethodImplAttribute(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "RhGetThreadStaticStorageForModule")] internal static unsafe extern Array RhGetThreadStaticStorageForModule(Int32 moduleIndex); @@ -747,7 +747,7 @@ namespace System.Runtime [RuntimeImport(RuntimeLibrary, "RhpEtwExceptionThrown")] internal extern static unsafe void RhpEtwExceptionThrown(char* exceptionTypeName, char* exceptionMessage, IntPtr faultingIP, long hresult); -#if CORERT +#if !PROJECTN // // Interlocked helpers // @@ -778,7 +778,7 @@ namespace System.Runtime [MethodImplAttribute(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "RhpMemoryBarrier")] internal extern static void MemoryBarrier(); -#endif // CORERT +#endif // !PROJECTN [Intrinsic] [MethodImplAttribute(MethodImplOptions.InternalCall)] diff --git a/src/System.Private.CoreLib/src/System/Threading/Interlocked.cs b/src/System.Private.CoreLib/src/System/Threading/Interlocked.cs index 5cce895c0..31f75ffc8 100644 --- a/src/System.Private.CoreLib/src/System/Threading/Interlocked.cs +++ b/src/System.Private.CoreLib/src/System/Threading/Interlocked.cs @@ -10,223 +10,7 @@ namespace System.Threading { public static class Interlocked { -#if CORERT - - #region CompareExchange - - [Intrinsic] - public static int CompareExchange(ref int location1, int value, int comparand) - { - return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); - } - - [Intrinsic] - public static long CompareExchange(ref long location1, long value, long comparand) - { - return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); - } - - [Intrinsic] - public static IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand) - { - return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); - } - - [Intrinsic] - public static unsafe float CompareExchange(ref float location1, float value, float comparand) - { - float ret; - *(int*)&ret = CompareExchange(ref Unsafe.As(ref location1), *(int*)&value, *(int*)&comparand); - return ret; - } - - [Intrinsic] - public static unsafe double CompareExchange(ref double location1, double value, double comparand) - { - double ret; - *(long*)&ret = CompareExchange(ref Unsafe.As(ref location1), *(long*)&value, *(long*)&comparand); - return ret; - } - - [Intrinsic] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T CompareExchange(ref T location1, T value, T comparand) where T : class - { - return Unsafe.As(RuntimeImports.InterlockedCompareExchange(ref Unsafe.As(ref location1), value, comparand)); - } - - [Intrinsic] - public static object CompareExchange(ref object location1, object value, object comparand) - { - return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); - } - - #endregion - - #region Exchange - - [Intrinsic] - public static int Exchange(ref int location1, int value) - { - int oldValue; - - do - { - oldValue = location1; - } while (CompareExchange(ref location1, value, oldValue) != oldValue); - - return oldValue; - } - - [Intrinsic] - public static long Exchange(ref long location1, long value) - { - long oldValue; - - do - { - oldValue = location1; - } while (CompareExchange(ref location1, value, oldValue) != oldValue); - - return oldValue; - } - - [Intrinsic] - public static IntPtr Exchange(ref IntPtr location1, IntPtr value) - { - IntPtr oldValue; - - do - { - oldValue = location1; - } while (CompareExchange(ref location1, value, oldValue) != oldValue); - - return oldValue; - } - - [Intrinsic] - public static unsafe float Exchange(ref float location1, float value) - { - float ret; - *(int*)&ret = Exchange(ref Unsafe.As(ref location1), *(int*)&value); - return ret; - } - - [Intrinsic] - public static unsafe double Exchange(ref double location1, double value) - { - double ret; - *(long*)&ret = Exchange(ref Unsafe.As(ref location1), *(long*)&value); - return ret; - } - - [Intrinsic] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T Exchange(ref T location1, T value) where T : class - { - return Unsafe.As(RuntimeImports.InterlockedExchange(ref Unsafe.As(ref location1), value)); - } - - [Intrinsic] - public static object Exchange(ref object location1, object value) - { - return RuntimeImports.InterlockedExchange(ref location1, value); - } - - #endregion - - #region Increment - - [Intrinsic] - public static int Increment(ref int location) - { - return ExchangeAdd(ref location, 1) + 1; - } - - [Intrinsic] - public static long Increment(ref long location) - { - return ExchangeAdd(ref location, 1) + 1; - } - - #endregion - - #region Decrement - - [Intrinsic] - public static int Decrement(ref int location) - { - return ExchangeAdd(ref location, -1) - 1; - } - - [Intrinsic] - public static long Decrement(ref long location) - { - return ExchangeAdd(ref location, -1) - 1; - } - - #endregion - - #region Add - - [Intrinsic] - public static int Add(ref int location1, int value) - { - return ExchangeAdd(ref location1, value) + value; - } - - [Intrinsic] - public static long Add(ref long location1, long value) - { - return ExchangeAdd(ref location1, value) + value; - } - - [Intrinsic] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static int ExchangeAdd(ref int location1, int value) - { - int oldValue; - - do - { - oldValue = location1; - } while (CompareExchange(ref location1, oldValue + value, oldValue) != oldValue); - - return oldValue; - } - - [Intrinsic] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static long ExchangeAdd(ref long location1, long value) - { - long oldValue; - - do - { - oldValue = location1; - } while (CompareExchange(ref location1, oldValue + value, oldValue) != oldValue); - - return oldValue; - } - - #endregion - - #region MemoryBarrier - [Intrinsic] - public static void MemoryBarrier() - { - RuntimeImports.MemoryBarrier(); - } - #endregion - - #region Read - public static long Read(ref long location) - { - return CompareExchange(ref location, 0, 0); - } - #endregion - -#else // CORERT +#if PROJECTN #region CompareExchange @@ -494,7 +278,223 @@ namespace System.Threading } #endregion -#endif // CORERT +#else // PROJECTN + + #region CompareExchange + + [Intrinsic] + public static int CompareExchange(ref int location1, int value, int comparand) + { + return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); + } + + [Intrinsic] + public static long CompareExchange(ref long location1, long value, long comparand) + { + return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); + } + + [Intrinsic] + public static IntPtr CompareExchange(ref IntPtr location1, IntPtr value, IntPtr comparand) + { + return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); + } + + [Intrinsic] + public static unsafe float CompareExchange(ref float location1, float value, float comparand) + { + float ret; + *(int*)&ret = CompareExchange(ref Unsafe.As(ref location1), *(int*)&value, *(int*)&comparand); + return ret; + } + + [Intrinsic] + public static unsafe double CompareExchange(ref double location1, double value, double comparand) + { + double ret; + *(long*)&ret = CompareExchange(ref Unsafe.As(ref location1), *(long*)&value, *(long*)&comparand); + return ret; + } + + [Intrinsic] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T CompareExchange(ref T location1, T value, T comparand) where T : class + { + return Unsafe.As(RuntimeImports.InterlockedCompareExchange(ref Unsafe.As(ref location1), value, comparand)); + } + + [Intrinsic] + public static object CompareExchange(ref object location1, object value, object comparand) + { + return RuntimeImports.InterlockedCompareExchange(ref location1, value, comparand); + } + + #endregion + + #region Exchange + + [Intrinsic] + public static int Exchange(ref int location1, int value) + { + int oldValue; + + do + { + oldValue = location1; + } while (CompareExchange(ref location1, value, oldValue) != oldValue); + + return oldValue; + } + + [Intrinsic] + public static long Exchange(ref long location1, long value) + { + long oldValue; + + do + { + oldValue = location1; + } while (CompareExchange(ref location1, value, oldValue) != oldValue); + + return oldValue; + } + + [Intrinsic] + public static IntPtr Exchange(ref IntPtr location1, IntPtr value) + { + IntPtr oldValue; + + do + { + oldValue = location1; + } while (CompareExchange(ref location1, value, oldValue) != oldValue); + + return oldValue; + } + + [Intrinsic] + public static unsafe float Exchange(ref float location1, float value) + { + float ret; + *(int*)&ret = Exchange(ref Unsafe.As(ref location1), *(int*)&value); + return ret; + } + + [Intrinsic] + public static unsafe double Exchange(ref double location1, double value) + { + double ret; + *(long*)&ret = Exchange(ref Unsafe.As(ref location1), *(long*)&value); + return ret; + } + + [Intrinsic] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T Exchange(ref T location1, T value) where T : class + { + return Unsafe.As(RuntimeImports.InterlockedExchange(ref Unsafe.As(ref location1), value)); + } + + [Intrinsic] + public static object Exchange(ref object location1, object value) + { + return RuntimeImports.InterlockedExchange(ref location1, value); + } + + #endregion + + #region Increment + + [Intrinsic] + public static int Increment(ref int location) + { + return ExchangeAdd(ref location, 1) + 1; + } + + [Intrinsic] + public static long Increment(ref long location) + { + return ExchangeAdd(ref location, 1) + 1; + } + + #endregion + + #region Decrement + + [Intrinsic] + public static int Decrement(ref int location) + { + return ExchangeAdd(ref location, -1) - 1; + } + + [Intrinsic] + public static long Decrement(ref long location) + { + return ExchangeAdd(ref location, -1) - 1; + } + + #endregion + + #region Add + + [Intrinsic] + public static int Add(ref int location1, int value) + { + return ExchangeAdd(ref location1, value) + value; + } + + [Intrinsic] + public static long Add(ref long location1, long value) + { + return ExchangeAdd(ref location1, value) + value; + } + + [Intrinsic] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int ExchangeAdd(ref int location1, int value) + { + int oldValue; + + do + { + oldValue = location1; + } while (CompareExchange(ref location1, oldValue + value, oldValue) != oldValue); + + return oldValue; + } + + [Intrinsic] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static long ExchangeAdd(ref long location1, long value) + { + long oldValue; + + do + { + oldValue = location1; + } while (CompareExchange(ref location1, oldValue + value, oldValue) != oldValue); + + return oldValue; + } + + #endregion + + #region MemoryBarrier + [Intrinsic] + public static void MemoryBarrier() + { + RuntimeImports.MemoryBarrier(); + } + #endregion + + #region Read + public static long Read(ref long location) + { + return CompareExchange(ref location, 0, 0); + } + #endregion + +#endif // PROJECTN public static void MemoryBarrierProcessWide() { diff --git a/src/System.Private.CoreLib/src/System/Threading/Lock.cs b/src/System.Private.CoreLib/src/System/Threading/Lock.cs index f91fb539c..9669b21eb 100644 --- a/src/System.Private.CoreLib/src/System/Threading/Lock.cs +++ b/src/System.Private.CoreLib/src/System/Threading/Lock.cs @@ -60,12 +60,12 @@ namespace System.Threading } } -#if CORERT - private static IntPtr CurrentNativeThreadId => (IntPtr)RuntimeImports.RhCurrentNativeThreadId(); -#else +#if PROJECTN // Use a compiler intrinsic for .NET Native private static IntPtr CurrentNativeThreadId => (IntPtr)Environment.CurrentNativeThreadId; -#endif // CORERT +#else + private static IntPtr CurrentNativeThreadId => (IntPtr)RuntimeImports.RhCurrentNativeThreadId(); +#endif // PROJECTN // On platforms where CurrentNativeThreadId redirects to ManagedThreadId.Current the inlined // version of Lock.Acquire has the ManagedThreadId.Current call not inlined, while the non-inlined diff --git a/src/System.Private.Interop/src/Internal/Runtime/CompilerHelpers/LibraryInitializer.cs b/src/System.Private.Interop/src/Internal/Runtime/CompilerHelpers/LibraryInitializer.cs index ff45c4130..c3f448e6b 100644 --- a/src/System.Private.Interop/src/Internal/Runtime/CompilerHelpers/LibraryInitializer.cs +++ b/src/System.Private.Interop/src/Internal/Runtime/CompilerHelpers/LibraryInitializer.cs @@ -20,7 +20,7 @@ namespace Internal.Runtime.CompilerHelpers { public static void InitializeLibrary() { -#if !CORERT +#if PROJECTN __vtable_IUnknown.Initialize(); McgModuleManager.Initialize(); #endif diff --git a/src/System.Private.Interop/src/Shared/ComCallableObject.cs b/src/System.Private.Interop/src/Shared/ComCallableObject.cs index dea259223..a78ff69db 100644 --- a/src/System.Private.Interop/src/Shared/ComCallableObject.cs +++ b/src/System.Private.Interop/src/Shared/ComCallableObject.cs @@ -1109,7 +1109,7 @@ namespace System.Runtime.InteropServices internal static void InitRefCountedHandleCallback() { // TODO: -#if !CORERT +#if PROJECTN // // Register the callback to ref-counted handles // Inside this callback we'll determine whether the ref count handle to the target object @@ -1482,7 +1482,7 @@ namespace System.Runtime.InteropServices } } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT // TODO: Dynamic Boxing support // TODO: Optimize--it is possible that the following dynamic code is faster than above static code(CCWTemplate) // if we cann't find a interfaceType for giving guid, try to enumerate all interfaces implemented by this target object to see anyone matchs given guid diff --git a/src/System.Private.Interop/src/Shared/McgComHelpers.cs b/src/System.Private.Interop/src/Shared/McgComHelpers.cs index e2a26b919..90de9b3ea 100644 --- a/src/System.Private.Interop/src/Shared/McgComHelpers.cs +++ b/src/System.Private.Interop/src/Shared/McgComHelpers.cs @@ -610,7 +610,7 @@ namespace System.Runtime.InteropServices internal static __ComGenericInterfaceDispatcher CreateGenericComDispatcher(RuntimeTypeHandle genericDispatcherDef, RuntimeTypeHandle[] genericArguments, __ComObject comThisPointer) { -#if !RHTESTCL && !CORECLR && !CORERT +#if !RHTESTCL && PROJECTN Debug.Assert(genericDispatcherDef.IsGenericTypeDefinition()); Debug.Assert(genericArguments != null && genericArguments.Length > 0); diff --git a/src/System.Private.Interop/src/Shared/McgIntrinsics.cs b/src/System.Private.Interop/src/Shared/McgIntrinsics.cs index 4bd120511..6c18ea147 100644 --- a/src/System.Private.Interop/src/Shared/McgIntrinsics.cs +++ b/src/System.Private.Interop/src/Shared/McgIntrinsics.cs @@ -365,7 +365,7 @@ namespace System.Runtime.InteropServices // We need to call via an imported stub to do a stdcall without triggering GC // We can't use managed calli because the native target address could potentially satisfy a magic // bit check and causing the stub to believe it is a managed method which leads to crash. -#if !RHTESTCL && !CORECLR && !CORERT +#if !RHTESTCL && PROJECTN [MethodImplAttribute(InternalCall)] #if X86 [RuntimeImport("*", "@StdCallCOOP0@8")] diff --git a/src/System.Private.Interop/src/Shared/McgMarshal.cs b/src/System.Private.Interop/src/Shared/McgMarshal.cs index 29fba4115..bf51b8d35 100644 --- a/src/System.Private.Interop/src/Shared/McgMarshal.cs +++ b/src/System.Private.Interop/src/Shared/McgMarshal.cs @@ -1150,10 +1150,10 @@ namespace System.Runtime.InteropServices /// public static IntPtr GetCurrentCalleeOpenStaticDelegateFunctionPointer() { -#if RHTESTCL || CORECLR || CORERT - throw new NotSupportedException(); -#else +#if !RHTESTCL && PROJECTN return PInvokeMarshal.GetCurrentCalleeOpenStaticDelegateFunctionPointer(); +#else + throw new NotSupportedException(); #endif } @@ -1162,10 +1162,10 @@ namespace System.Runtime.InteropServices /// public static T GetCurrentCalleeDelegate() where T : class // constraint can't be System.Delegate { -#if RHTESTCL || CORECLR || CORERT - throw new NotSupportedException(); -#else +#if !RHTESTCL && PROJECTN return PInvokeMarshal.GetCurrentCalleeDelegate(); +#else + throw new NotSupportedException(); #endif } #endregion diff --git a/src/System.Private.Interop/src/Shared/McgModuleManager.cs b/src/System.Private.Interop/src/Shared/McgModuleManager.cs index ab41c5cdd..0c7856dcb 100644 --- a/src/System.Private.Interop/src/Shared/McgModuleManager.cs +++ b/src/System.Private.Interop/src/Shared/McgModuleManager.cs @@ -680,7 +680,7 @@ namespace System.Runtime.InteropServices } } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT // Dynamic boxing support // TODO: Consider to use the field boxingStub for all projected reference types. // TODO: now it is only used for boxing "System.Uri". diff --git a/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs b/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs index d67870760..a6e80880c 100644 --- a/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs +++ b/src/System.Private.Interop/src/Shared/McgTypeHelpers.cs @@ -26,7 +26,7 @@ using System.Runtime; using Internal.NativeFormat; using System.Runtime.CompilerServices; -#if !RHTESTCL && !CORECLR && !CORERT +#if !RHTESTCL && PROJECTN using Internal.Runtime.Augments; using Internal.Runtime.TypeLoader; #endif @@ -321,7 +321,7 @@ namespace System.Runtime.InteropServices return; } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop) { name = DynamicInteropTypeHelper.GetTypeName(typeHandle, out isWinRT); @@ -455,7 +455,7 @@ namespace System.Runtime.InteropServices bool isWinRT; Type type = McgModuleManager.GetTypeFromName(name, out isWinRT); -#if !RHTESTCL && !CORECLR && !CORERT +#if !RHTESTCL && PROJECTN if (type == null && McgModuleManager.UseDynamicInterop && nativeTypeKind == (int)TypeKind.Metadata) { type = DynamicInteropTypeHelper.GetTypeFromWinRTName(name, nativeTypeKind); @@ -894,7 +894,7 @@ namespace System.Runtime.InteropServices return !McgModuleManager.GetInterfaceDataByIndex(moduleIndex, interfaceIndex).DynamicAdapterClassType.IsNull(); ; } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop && interfaceType.IsGenericType()) return false; #endif @@ -1102,7 +1102,7 @@ namespace System.Runtime.InteropServices return mcgGenericArgumentMarshalInfo.IteratorType; } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop) return DynamicInteropTypeHelper.ReplaceOpenGenericTypeInGenericInstantiation( interfaceType, @@ -1120,7 +1120,7 @@ namespace System.Runtime.InteropServices return mcgGenericArgumentMarshalInfo.ElementClassType; } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop) { RuntimeTypeHandle[] genericTypeArgumentHandles; @@ -1141,7 +1141,7 @@ namespace System.Runtime.InteropServices return mcgGenericArgumentMarshalInfo.ElementInterfaceType; } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop) { RuntimeTypeHandle[] genericTypeArgumentHandles; @@ -1161,7 +1161,7 @@ namespace System.Runtime.InteropServices return mcgGenericArgumentMarshalInfo.VectorViewType; } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop) return DynamicInteropTypeHelper.ReplaceOpenGenericTypeInGenericInstantiation( interfaceType, @@ -1179,7 +1179,7 @@ namespace System.Runtime.InteropServices return mcgGenericArgumentMarshalInfo.AsyncOperationType; } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop) return DynamicInteropTypeHelper.ReplaceOpenGenericTypeInGenericInstantiation( interfaceType, @@ -1197,7 +1197,7 @@ namespace System.Runtime.InteropServices return (int)mcgGenericArgumentMarshalInfo.ElementSize; } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop) { RuntimeTypeHandle[] genericTypeArgumentHandles; @@ -1220,7 +1220,7 @@ namespace System.Runtime.InteropServices string ccwRuntimeClassName; if (McgModuleManager.TryGetCCWRuntimeClassName(ccwType, out ccwRuntimeClassName)) return ccwRuntimeClassName; -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop) return DynamicInteropCCWTemplateHelper.GetCCWRuntimeClassName(ccwType); #endif @@ -1331,7 +1331,7 @@ namespace System.Runtime.InteropServices } } -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT private static void GetIIDsImpl_dynamic(RuntimeTypeHandle typeHandle, System.Collections.Generic.Internal.List iids) { // Enumerate interfaces from itself and its baseclass @@ -1363,7 +1363,7 @@ namespace System.Runtime.InteropServices } // if there isn't any data about this type, just return empty list -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT if (McgModuleManager.UseDynamicInterop) GetIIDsImpl_dynamic(ccwType, iids); #endif diff --git a/src/System.Private.Interop/src/Shared/__ComObject.cs b/src/System.Private.Interop/src/Shared/__ComObject.cs index 1b3695e12..b68a81e0b 100644 --- a/src/System.Private.Interop/src/Shared/__ComObject.cs +++ b/src/System.Private.Interop/src/Shared/__ComObject.cs @@ -26,7 +26,7 @@ using System.Runtime; using Internal.NativeFormat; -#if !RHTESTCL && !CORECLR && !CORERT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT using Internal.Runtime.Augments; using Internal.Runtime.TypeLoader; #endif @@ -72,7 +72,7 @@ namespace System /// [EditorBrowsable(EditorBrowsableState.Never)] [CLSCompliant(false)] -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT public unsafe class __ComObject : CastableObject, ICastable #else public unsafe class __ComObject : ICastable @@ -161,7 +161,7 @@ namespace System [DebuggerBrowsable(DebuggerBrowsableState.Never)] private RCWFinalizer m_finalizer; -#if !RHTESTCL && !CORECLR && !CORERT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT [DebuggerBrowsable(DebuggerBrowsableState.Never)] private static readonly System.Collections.Generic.Dictionary s_DynamicRCWAdapters = new System.Collections.Generic.Dictionary(); @@ -333,7 +333,7 @@ namespace System static __ComObject() { -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT // Projected types s_DynamicRCWAdapters[typeof(IEnumerable<>).TypeHandle] = typeof(IEnumerable_RCWAdapter<>).TypeHandle; s_DynamicRCWAdapters[typeof(IList<>).TypeHandle] = typeof(IList_RCWAdapter<>).TypeHandle; @@ -1326,7 +1326,7 @@ namespace System } #endif -#if !RHTESTCL && !CORECLR && !CORERT +#if !RHTESTCL && PROJECTN // // Search the existing cached interfaces in the simple cache that we can cast to the input interface type @@ -1571,7 +1571,7 @@ namespace System #endregion #region CastableObject implementation for weakly typed RCWs -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT object CastToICollectionHelper(RuntimeTypeHandle genericTypeDef, RuntimeTypeHandle[] genericArguments, bool testForIDictionary) { Debug.Assert(genericTypeDef.Equals(typeof(ICollection<>).TypeHandle) || genericTypeDef.Equals(typeof(IReadOnlyCollection<>).TypeHandle)); @@ -1871,7 +1871,7 @@ namespace System // bool hasValidDispatcher = true; -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT hasValidDispatcher = McgModuleManager.UseDynamicInterop && interfaceType.IsGenericType() ? !interfaceType.GetDispatchClassType().IsInvalid() : true; @@ -2267,7 +2267,7 @@ namespace System if (dynamicAdapter != null) return dynamicAdapter; -#if !RHTESTCL && !CORECLR && !CORERT && ENABLE_WINRT +#if !RHTESTCL && PROJECTN && ENABLE_WINRT // Try dynamic rcw, The Caller will generate/throw exception if return null Exception e; dynamicAdapter = CastToInterface(requestedType, /*produceCastErrorException*/ false, out e); diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs index 540fff054..cd873da35 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs @@ -1313,7 +1313,12 @@ namespace Internal.Reflection.Execution else { Debug.Assert((fieldAccessMetadata.Flags & FieldTableFlags.IsUniversalCanonicalEntry) == 0); -#if CORERT +#if PROJECTN + // The fieldAccessMetadata.Offset value is not really a field offset, but a static field RVA. We'll use the + // field's address as a 'staticsBase', and just use a field offset of zero. + fieldOffset = 0; + staticsBase = TypeLoaderEnvironment.RvaToNonGenericStaticFieldAddress(fieldAccessMetadata.MappingTableModule, fieldAccessMetadata.Offset); +#else if (isGcStatic) { fieldOffset = fieldAccessMetadata.Offset; @@ -1326,11 +1331,6 @@ namespace Internal.Reflection.Execution fieldOffset = 0; staticsBase = fieldAccessMetadata.Cookie; } -#else - // The fieldAccessMetadata.Offset value is not really a field offset, but a static field RVA. We'll use the - // field's address as a 'staticsBase', and just use a field offset of zero. - fieldOffset = 0; - staticsBase = TypeLoaderEnvironment.RvaToNonGenericStaticFieldAddress(fieldAccessMetadata.MappingTableModule, fieldAccessMetadata.Offset); #endif } diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/PointerTypeFieldAccessorForStaticFields.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/PointerTypeFieldAccessorForStaticFields.cs index 2ae40c768..7f1efc19f 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/PointerTypeFieldAccessorForStaticFields.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/PointerTypeFieldAccessorForStaticFields.cs @@ -16,7 +16,7 @@ namespace Internal.Reflection.Execution.FieldAccessors unsafe protected sealed override Object GetFieldBypassCctor() { -#if CORERT +#if !PROJECTN if (IsGcStatic) { // The _staticsBase variable points to a GC handle, which points at the GC statics base of the type. @@ -30,8 +30,7 @@ namespace Internal.Reflection.Execution.FieldAccessors unsafe protected sealed override void UncheckedSetFieldBypassCctor(Object value) { - -#if CORERT +#if !PROJECTN if (IsGcStatic) { // The _staticsBase variable points to a GC handle, which points at the GC statics base of the type. diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/ReferenceTypeFieldAccessorForStaticFields.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/ReferenceTypeFieldAccessorForStaticFields.cs index 424f50578..5abb9ac7b 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/ReferenceTypeFieldAccessorForStaticFields.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/ReferenceTypeFieldAccessorForStaticFields.cs @@ -16,7 +16,7 @@ namespace Internal.Reflection.Execution.FieldAccessors unsafe protected sealed override Object GetFieldBypassCctor() { -#if CORERT +#if !PROJECTN if (IsGcStatic) { // The _staticsBase variable points to a GC handle, which points at the GC statics base of the type. @@ -30,8 +30,7 @@ namespace Internal.Reflection.Execution.FieldAccessors unsafe protected sealed override void UncheckedSetFieldBypassCctor(Object value) { - -#if CORERT +#if !PROJECTN if (IsGcStatic) { // The _staticsBase variable points to a GC handle, which points at the GC statics base of the type. diff --git a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/ValueTypeFieldAccessorForStaticFields.cs b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/ValueTypeFieldAccessorForStaticFields.cs index b54c6cb10..bb54d91f9 100644 --- a/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/ValueTypeFieldAccessorForStaticFields.cs +++ b/src/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/FieldAccessors/ValueTypeFieldAccessorForStaticFields.cs @@ -16,7 +16,7 @@ namespace Internal.Reflection.Execution.FieldAccessors unsafe protected sealed override Object GetFieldBypassCctor() { -#if CORERT +#if !PROJECTN if (IsGcStatic) { // The _staticsBase variable points to a GC handle, which points at the GC statics base of the type. @@ -30,8 +30,7 @@ namespace Internal.Reflection.Execution.FieldAccessors unsafe protected sealed override void UncheckedSetFieldBypassCctor(Object value) { - -#if CORERT +#if !PROJECTN if (IsGcStatic) { // The _staticsBase variable points to a GC handle, which points at the GC statics base of the type. diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ConstrainedCallSupport.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ConstrainedCallSupport.cs index 35b1c3b65..eb2e3a5e2 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ConstrainedCallSupport.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ConstrainedCallSupport.cs @@ -36,7 +36,7 @@ namespace Internal.Runtime.TypeLoader #endif private delegate IntPtr RuntimeCacheFuncSignatureDel(IntPtr context, IntPtr callDescIntPtr, object contextObject, out IntPtr auxResult); -#if !CORERT +#if PROJECTN [DllImport("*", ExactSpelling = true, EntryPoint = "ConstrainedCallSupport_GetStubs")] private extern static unsafe void ConstrainedCallSupport_GetStubs(out IntPtr constrainedCallSupport_DerefThisAndCall_CommonCallingStub, out IntPtr constrainedCallSupport_DirectConstrainedCall_CommonCallingStub); #endif @@ -54,7 +54,7 @@ namespace Internal.Runtime.TypeLoader static ConstrainedCallSupport() { // TODO: export this unmanaged API in CoreRT -#if !CORERT +#if PROJECTN ConstrainedCallSupport_GetStubs(out s_constrainedCallSupport_DerefThisAndCall_CommonCallingStub, out s_constrainedCallSupport_DirectConstrainedCall_CommonCallingStub); #else diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs index 19cfb88aa..c2f02dcc6 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs @@ -457,7 +457,7 @@ namespace Internal.Runtime.TypeLoader pEEType->OptionalFieldsPtr = (byte*)pEEType + cbEEType; optionalFields.WriteToEEType(pEEType, cbOptionalFieldsSize); -#if CORERT +#if !PROJECTN pEEType->PointerToTypeManager = PermanentAllocatedMemoryBlobs.GetPointerToIntPtr(moduleInfo.Handle.GetIntPtrUNSAFE()); #endif pEEType->DynamicModule = dynamicModulePtr; diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ExternalReferencesTable.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ExternalReferencesTable.cs index 6fd8a1dc4..3c6a9d382 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ExternalReferencesTable.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ExternalReferencesTable.cs @@ -77,30 +77,23 @@ namespace Internal.Runtime.TypeLoader unsafe public uint GetRvaFromIndex(uint index) { -#if CORERT - // The usage of this API will need to go away since this is not fully portable - // and we'll not be able to support this for CppCodegen. - throw new PlatformNotSupportedException(); -#else +#if PROJECTN Debug.Assert(!_moduleHandle.IsNull); if (index >= _elementsCount) throw new BadImageFormatException(); return ((TableElement*)_elements)[index]; +#else + // The usage of this API will need to go away since this is not fully portable + // and we'll not be able to support this for CppCodegen. + throw new PlatformNotSupportedException(); #endif } unsafe public IntPtr GetIntPtrFromIndex(uint index) { -#if CORERT - if (index >= _elementsCount) - throw new BadImageFormatException(); - - // TODO: indirection through IAT - int* pRelPtr32 = &((int*)_elements)[index]; - return (IntPtr)((byte*)pRelPtr32 + *pRelPtr32); -#else +#if PROJECTN uint rva = GetRvaFromIndex(index); if ((rva & IndirectionConstants.RVAPointsToIndirection) != 0) { @@ -111,19 +104,19 @@ namespace Internal.Runtime.TypeLoader { return (IntPtr)(_moduleHandle.ConvertRVAToPointer(rva)); } -#endif - } - - unsafe public IntPtr GetFunctionPointerFromIndex(uint index) - { -#if CORERT +#else if (index >= _elementsCount) throw new BadImageFormatException(); // TODO: indirection through IAT int* pRelPtr32 = &((int*)_elements)[index]; return (IntPtr)((byte*)pRelPtr32 + *pRelPtr32); -#else +#endif + } + + unsafe public IntPtr GetFunctionPointerFromIndex(uint index) + { +#if PROJECTN uint rva = GetRvaFromIndex(index); if ((rva & DynamicInvokeMapEntry.IsImportMethodFlag) == DynamicInvokeMapEntry.IsImportMethodFlag) @@ -134,6 +127,13 @@ namespace Internal.Runtime.TypeLoader { return (IntPtr)(_moduleHandle.ConvertRVAToPointer(rva)); } +#else + if (index >= _elementsCount) + throw new BadImageFormatException(); + + // TODO: indirection through IAT + int* pRelPtr32 = &((int*)_elements)[index]; + return (IntPtr)((byte*)pRelPtr32 + *pRelPtr32); #endif } @@ -154,7 +154,7 @@ namespace Internal.Runtime.TypeLoader return GetIntPtrFromIndex(index); } -#if CORERT +#if !PROJECTN unsafe public IntPtr GetFieldAddressFromIndex(uint index) { if (index >= _elementsCount) diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeBuilder.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeBuilder.cs index 2dad626d2..7cb0cf289 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeBuilder.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeBuilder.cs @@ -505,7 +505,7 @@ namespace Internal.Runtime.TypeLoader // If so, use that, otherwise, run down the template type loader path with the universal template if ((state.TemplateType == null) || isTemplateUniversalCanon) { -#if !CORERT +#if PROJECTN // CanonAlike types do not get dictionaries if ((state.TemplateType == null) && (type.IsConstructedOverType(type.Context.CanonAlikeTypeArray))) return; @@ -643,7 +643,7 @@ namespace Internal.Runtime.TypeLoader TypeLoaderLogger.WriteLine("Found BagElementKind.DictionaryLayout"); Debug.Assert(!isTemplateUniversalCanon, "Universal template nativelayout do not have DictionaryLayout"); -#if !CORERT +#if PROJECTN if (type.IsConstructedOverType(type.Context.CanonAlikeTypeArray)) { TypeLoaderLogger.WriteLine("Type is CanonAlike, skip generation of dictionary"); @@ -1682,9 +1682,16 @@ namespace Internal.Runtime.TypeLoader NativeReader reader; uint offset; -#if !CORERT +#if PROJECTN // If the system module is compiled with as a type manager, all modules are compiled as such - if (ModuleList.Instance.SystemModule.Handle.IsTypeManager) + if (!ModuleList.Instance.SystemModule.Handle.IsTypeManager) + { + IntPtr moduleHandle = RuntimeAugments.GetOSModuleFromPointer(signature); + typeManager = new TypeManagerHandle(moduleHandle); + reader = TypeLoaderEnvironment.Instance.GetNativeLayoutInfoReader(typeManager); + offset = reader.AddressToOffset(signature); + } + else #endif { // The first is a pointer that points to the TypeManager indirection cell. @@ -1694,15 +1701,6 @@ namespace Internal.Runtime.TypeLoader offset = checked((uint)new IntPtr(lazySignature[1]).ToInt32()); reader = TypeLoaderEnvironment.Instance.GetNativeLayoutInfoReader(typeManager); } -#if !CORERT - else - { - IntPtr moduleHandle = RuntimeAugments.GetOSModuleFromPointer(signature); - typeManager = new TypeManagerHandle(moduleHandle); - reader = TypeLoaderEnvironment.Instance.GetNativeLayoutInfoReader(typeManager); - offset = reader.AddressToOffset(signature); - } -#endif NativeParser parser = new NativeParser(reader, offset); diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.FieldAccess.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.FieldAccess.cs index 3149f10a7..2cd5b9156 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.FieldAccess.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.FieldAccess.cs @@ -236,14 +236,14 @@ namespace Internal.Runtime.TypeLoader } else { -#if CORERT +#if PROJECTN + fieldOffset = (int)externalReferences.GetRvaFromIndex(entryParser.GetUnsigned()); +#else fieldOffset = 0; fieldAddressCookie = externalReferences.GetFieldAddressFromIndex(entryParser.GetUnsigned()); if((entryFlags & FieldTableFlags.IsGcSection) != 0) fieldOffset = (int)entryParser.GetUnsigned(); -#else - fieldOffset = (int)externalReferences.GetRvaFromIndex(entryParser.GetUnsigned()); #endif } } diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.LdTokenResultLookup.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.LdTokenResultLookup.cs index 4b5e4ca47..3c6ecf107 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.LdTokenResultLookup.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.LdTokenResultLookup.cs @@ -256,9 +256,17 @@ namespace Internal.Runtime.TypeLoader RuntimeFieldHandleInfo* fieldData = *(RuntimeFieldHandleInfo**)&runtimeFieldHandle; RuntimeSignature signature; -#if !CORERT +#if PROJECTN // If the system module is compiled with as a type manager, all modules are compiled as such - if (ModuleList.Instance.SystemModule.Handle.IsTypeManager) + if (!ModuleList.Instance.SystemModule.Handle.IsTypeManager) + { + IntPtr moduleHandle = RuntimeAugments.GetOSModuleFromPointer(fieldData->NativeLayoutInfoSignature); + + signature = RuntimeSignature.CreateFromNativeLayoutSignature( + new TypeManagerHandle(moduleHandle), + GetNativeLayoutInfoReader(new TypeManagerHandle(moduleHandle)).AddressToOffset(fieldData->NativeLayoutInfoSignature)); + } + else #endif { // The native layout info signature is a pair. @@ -270,16 +278,6 @@ namespace Internal.Runtime.TypeLoader new TypeManagerHandle(*(IntPtr*)nativeLayoutInfoSignatureData[0]), (uint)nativeLayoutInfoSignatureData[1].ToInt32()); } -#if !CORERT - else - { - IntPtr moduleHandle = RuntimeAugments.GetOSModuleFromPointer(fieldData->NativeLayoutInfoSignature); - - signature = RuntimeSignature.CreateFromNativeLayoutSignature( - new TypeManagerHandle(moduleHandle), - GetNativeLayoutInfoReader(new TypeManagerHandle(moduleHandle)).AddressToOffset(fieldData->NativeLayoutInfoSignature)); - } -#endif RuntimeSignature remainingSignature; if (!GetTypeFromSignatureAndContext(signature, null, null, out declaringTypeHandle, out remainingSignature)) @@ -425,9 +423,17 @@ namespace Internal.Runtime.TypeLoader RuntimeMethodHandleInfo* methodData = *(RuntimeMethodHandleInfo**)&runtimeMethodHandle; RuntimeSignature signature; -#if !CORERT +#if PROJECTN // If the system module is compiled with as a type manager, all modules are compiled as such - if (ModuleList.Instance.SystemModule.Handle.IsTypeManager) + if (!ModuleList.Instance.SystemModule.Handle.IsTypeManager) + { + IntPtr moduleHandle = RuntimeAugments.GetOSModuleFromPointer(methodData->NativeLayoutInfoSignature); + + signature = RuntimeSignature.CreateFromNativeLayoutSignature( + new TypeManagerHandle(moduleHandle), + GetNativeLayoutInfoReader(new TypeManagerHandle(moduleHandle)).AddressToOffset(methodData->NativeLayoutInfoSignature)); + } + else #endif { // The native layout info signature is a pair. @@ -439,16 +445,6 @@ namespace Internal.Runtime.TypeLoader new TypeManagerHandle(*(IntPtr*)nativeLayoutInfoSignatureData[0]), (uint)nativeLayoutInfoSignatureData[1].ToInt32()); } -#if !CORERT - else - { - IntPtr moduleHandle = RuntimeAugments.GetOSModuleFromPointer(methodData->NativeLayoutInfoSignature); - - signature = RuntimeSignature.CreateFromNativeLayoutSignature( - new TypeManagerHandle(moduleHandle), - GetNativeLayoutInfoReader(new TypeManagerHandle(moduleHandle)).AddressToOffset(methodData->NativeLayoutInfoSignature)); - } -#endif RuntimeSignature remainingSignature; return GetMethodFromSignatureAndContext(signature, null, null, out declaringTypeHandle, out nameAndSignature, out genericMethodArgs, out remainingSignature); diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.Metadata.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.Metadata.cs index 826531e4f..bde93220d 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.Metadata.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.Metadata.cs @@ -847,14 +847,14 @@ namespace Internal.Runtime.TypeLoader // done at runtime. When working with the CoreRT ABI, the correct slot numbers will be written to the map, // and no adjustments will be performed at runtime. // - -#if CORERT + +#if PROJECTN CanonicallyEquivalentEntryLocator canonHelper = new CanonicallyEquivalentEntryLocator( - methodHandleDeclaringType, + Instance.GetTypeDefinition(methodHandleDeclaringType), CanonicalFormKind.Specific); #else CanonicallyEquivalentEntryLocator canonHelper = new CanonicallyEquivalentEntryLocator( - Instance.GetTypeDefinition(methodHandleDeclaringType), + methodHandleDeclaringType, CanonicalFormKind.Specific); #endif @@ -931,7 +931,7 @@ namespace Internal.Runtime.TypeLoader { uint slot = entryParser.GetUnsigned(); -#if !CORERT +#if PROJECTN RuntimeTypeHandle searchForSharedGenericTypesInParentHierarchy = declaringTypeOfVirtualInvoke; while (!searchForSharedGenericTypesInParentHierarchy.IsNull()) { diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/genericdictionarycell.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/genericdictionarycell.cs index f605485ed..b2f22df97 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/genericdictionarycell.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/genericdictionarycell.cs @@ -756,7 +756,7 @@ namespace Internal.Runtime.TypeLoader bool methodRequestedIsCanonical = Method.IsCanonicalMethod(CanonicalFormKind.Specific); MethodDesc canonAlikeForm; -#if !CORERT +#if PROJECTN if (methodRequestedIsCanonical) { canonAlikeForm = Method.ReplaceTypesInConstructionOfMethod(Method.Context.CanonTypeArray, Method.Context.CanonAlikeTypeArray); diff --git a/src/System.Private.TypeLoader/src/Internal/TypeSystem/TypeSystemContext.Runtime.cs b/src/System.Private.TypeLoader/src/Internal/TypeSystem/TypeSystemContext.Runtime.cs index 75564a154..81eda7cca 100644 --- a/src/System.Private.TypeLoader/src/Internal/TypeSystem/TypeSystemContext.Runtime.cs +++ b/src/System.Private.TypeLoader/src/Internal/TypeSystem/TypeSystemContext.Runtime.cs @@ -647,7 +647,7 @@ namespace Internal.TypeSystem _typesToFlushTypeSystemStateFrom = null; } -#if !CORERT +#if PROJECTN private TypeDesc _canonAlikeType; public TypeDesc CanonAlikeType