diff options
author | danmosemsft <danmose@microsoft.com> | 2017-02-11 07:20:12 -0800 |
---|---|---|
committer | danmosemsft <danmose@microsoft.com> | 2017-02-11 07:20:12 -0800 |
commit | 56d4ba8a9338c3ff7378d18378f38ad847f130f2 (patch) | |
tree | 40b9463880286b1bc0b4c3f858680f1ff210c933 /src/vm | |
parent | 8be2f9bb0039e2c49f59c4fb66cebf5467485ba2 (diff) | |
download | coreclr-56d4ba8a9338c3ff7378d18378f38ad847f130f2.tar.gz coreclr-56d4ba8a9338c3ff7378d18378f38ad847f130f2.tar.bz2 coreclr-56d4ba8a9338c3ff7378d18378f38ad847f130f2.zip |
Revert "Remove always defined FEATURE_CORESYSTEM"
This reverts commit 751771a8976f909af772e35c167bd7e3ffbe44c8.
Diffstat (limited to 'src/vm')
-rw-r--r-- | src/vm/assembly.cpp | 2 | ||||
-rw-r--r-- | src/vm/classnames.h | 2 | ||||
-rw-r--r-- | src/vm/comutilnative.cpp | 6 | ||||
-rw-r--r-- | src/vm/dllimport.cpp | 64 | ||||
-rw-r--r-- | src/vm/dllimport.h | 14 | ||||
-rw-r--r-- | src/vm/domainfile.cpp | 106 | ||||
-rw-r--r-- | src/vm/dwreport.cpp | 12 | ||||
-rw-r--r-- | src/vm/ecalllist.h | 3 | ||||
-rw-r--r-- | src/vm/eventreporter.cpp | 25 | ||||
-rw-r--r-- | src/vm/eventtrace.cpp | 20 | ||||
-rw-r--r-- | src/vm/excep.cpp | 12 | ||||
-rw-r--r-- | src/vm/gcenv.os.cpp | 4 | ||||
-rw-r--r-- | src/vm/i386/cgenx86.cpp | 58 | ||||
-rw-r--r-- | src/vm/i386/stublinkerx86.cpp | 42 | ||||
-rw-r--r-- | src/vm/interoputil.cpp | 8 | ||||
-rw-r--r-- | src/vm/jithelpers.cpp | 2 | ||||
-rw-r--r-- | src/vm/jitinterface.cpp | 2 | ||||
-rw-r--r-- | src/vm/methodtablebuilder.cpp | 2 | ||||
-rw-r--r-- | src/vm/notifyexternals.cpp | 26 | ||||
-rw-r--r-- | src/vm/runtimecallablewrapper.cpp | 2 | ||||
-rw-r--r-- | src/vm/securitydeclarative.cpp | 2 | ||||
-rw-r--r-- | src/vm/securitymeta.cpp | 4 | ||||
-rw-r--r-- | src/vm/securitymeta.h | 2 | ||||
-rw-r--r-- | src/vm/securitytransparentassembly.cpp | 3 | ||||
-rw-r--r-- | src/vm/util.cpp | 81 | ||||
-rw-r--r-- | src/vm/win32threadpool.cpp | 4 |
26 files changed, 504 insertions, 4 deletions
diff --git a/src/vm/assembly.cpp b/src/vm/assembly.cpp index e71fffc326..cc24ec7038 100644 --- a/src/vm/assembly.cpp +++ b/src/vm/assembly.cpp @@ -3286,6 +3286,7 @@ BOOL Assembly::CanBeShared(DomainAssembly *pDomainAssembly) #endif // FEATURE_LOADER_OPTIMIZATION +#if defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) BOOL Assembly::AllowUntrustedCaller() { CONTRACTL @@ -3298,6 +3299,7 @@ BOOL Assembly::AllowUntrustedCaller() return ModuleSecurityDescriptor::GetModuleSecurityDescriptor(this)->IsAPTCA(); } +#endif // defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) void DECLSPEC_NORETURN Assembly::ThrowTypeLoadException(LPCUTF8 pszFullName, UINT resIDWhy) { diff --git a/src/vm/classnames.h b/src/vm/classnames.h index 7664158afa..455924cb21 100644 --- a/src/vm/classnames.h +++ b/src/vm/classnames.h @@ -161,9 +161,11 @@ #define g_SecuritySafeCriticalAttribute "System.Security.SecuritySafeCriticalAttribute" +#if defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) #define g_SecurityAPTCA "System.Security.AllowPartiallyTrustedCallersAttribute" #define g_SecurityPartialTrustVisibilityLevel "System.Security.PartialTrustVisibilityLevel" #define g_PartialTrustVisibilityLevel "PartialTrustVisibilityLevel" +#endif // defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) #define g_ReferenceAssemblyAttribute "System.Runtime.CompilerServices.ReferenceAssemblyAttribute" diff --git a/src/vm/comutilnative.cpp b/src/vm/comutilnative.cpp index 04ad7a8c1a..1c9703a0ac 100644 --- a/src/vm/comutilnative.cpp +++ b/src/vm/comutilnative.cpp @@ -1500,6 +1500,12 @@ void QCALLTYPE Buffer::MemMove(void *dst, void *src, size_t length) { QCALL_CONTRACT; +#if defined(FEATURE_CORECLR) && !defined(FEATURE_CORESYSTEM) + // Callers of memcpy do expect and handle access violations in some scenarios. + // Access violations in the runtime dll are turned into fail fast by the vector exception handler by default. + // We need to supress this behavior for CoreCLR using AVInRuntimeImplOkayHolder because of memcpy is statically linked in. + AVInRuntimeImplOkayHolder avOk; +#endif memmove(dst, src, length); } diff --git a/src/vm/dllimport.cpp b/src/vm/dllimport.cpp index 98e58c60c7..15d964a999 100644 --- a/src/vm/dllimport.cpp +++ b/src/vm/dllimport.cpp @@ -6129,6 +6129,9 @@ static HMODULE LocalLoadLibraryHelper( LPCWSTR name, DWORD flags, LoadLibErrorTr #ifndef FEATURE_PAL if ((flags & 0xFFFFFF00) != 0 +#ifndef FEATURE_CORESYSTEM + && NDirect::SecureLoadLibrarySupported() +#endif // !FEATURE_CORESYSTEM ) { hmod = CLRLoadLibraryEx(name, NULL, flags & 0xFFFFFF00); @@ -6181,6 +6184,62 @@ static HMODULE LocalLoadLibraryDirectHelper(LPCWSTR name, DWORD flags, LoadLibEr } +#if !defined(FEATURE_CORESYSTEM) + +#define NATIVE_DLL(d) L#d, L#d W(".dll") + +const LPCWSTR wellKnownModules[] = +{ + NATIVE_DLL(advapi32), + NATIVE_DLL(gdi32), + NATIVE_DLL(gdiplus), + NATIVE_DLL(kernel32), + NATIVE_DLL(mscoree), + NATIVE_DLL(ole32), + NATIVE_DLL(shfolder), + NATIVE_DLL(user32), + NATIVE_DLL(version) +}; + +BOOL CompareLibNames (UPTR val1, UPTR val2) +{ + CONTRACTL { + MODE_ANY; + NOTHROW; + GC_NOTRIGGER; + } + CONTRACTL_END; + + LPCWSTR wszStr1 = (LPCWSTR)(val1 << 1); + LPCWSTR wszStr2 = (LPCWSTR)val2; + + if (SString::_wcsicmp(wszStr1, wszStr2) == 0) + return TRUE; + + return FALSE; +} + +PtrHashMap * NDirect::s_pWellKnownNativeModules = NULL; +bool NDirect::s_fSecureLoadLibrarySupported = false; + +HINSTANCE NDirect::CheckForWellKnownModules(LPCWSTR wszLibName, LoadLibErrorTracker *pErrorTracker) +{ + STANDARD_VM_CONTRACT; + + ModuleHandleHolder hMod; + ULONG hash = HashiString(wszLibName); + LPCWSTR wszName = NULL; + wszName = (LPCWSTR) s_pWellKnownNativeModules->LookupValue((UPTR) hash, (LPVOID)wszLibName); + + if (wszName != (LPCWSTR)INVALIDENTRY) + { + hMod = LocalLoadLibraryHelper(wszLibName, 0, pErrorTracker); + } + + return hMod.Extract(); +} + +#endif // !FEATURE_CORESYSTEM #define TOLOWER(a) (((a) >= W('A') && (a) <= W('Z')) ? (W('a') + (a - W('A'))) : (a)) #define TOHEX(a) ((a)>=10 ? W('a')+(a)-10 : W('0')+(a)) @@ -6395,6 +6454,9 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke return hmod.Extract(); } +#if !defined(FEATURE_CORESYSTEM) + hmod = CheckForWellKnownModules(wszLibName, pErrorTracker); +#endif #ifdef FEATURE_PAL // In the PAL version of CoreCLR, the CLR module itself exports the functionality @@ -6406,7 +6468,7 @@ HINSTANCE NDirect::LoadLibraryModule(NDirectMethodDesc * pMD, LoadLibErrorTracke hmod = GetCLRModule(); #endif // FEATURE_PAL -#if !defined(PLATFORM_UNIX) +#if defined(FEATURE_CORESYSTEM) && !defined(PLATFORM_UNIX) if (hmod == NULL) { // Try to go straight to System32 for Windows API sets. This is replicating quick check from diff --git a/src/vm/dllimport.h b/src/vm/dllimport.h index ca046614f0..ab5b212b8c 100644 --- a/src/vm/dllimport.h +++ b/src/vm/dllimport.h @@ -133,6 +133,20 @@ private: static HMODULE LoadLibraryModuleViaHost(NDirectMethodDesc * pMD, AppDomain* pDomain, const wchar_t* wszLibName); #endif //defined(FEATURE_HOST_ASSEMBLY_RESOLVER) +#if !defined(FEATURE_CORESYSTEM) + static HINSTANCE CheckForWellKnownModules(LPCWSTR wszLibName, LoadLibErrorTracker *pErrorTracker); + static PtrHashMap *s_pWellKnownNativeModules; + + // Indicates if the OS supports the new secure LoadLibraryEx flags introduced in KB2533623 + static bool s_fSecureLoadLibrarySupported; + +public: + static bool SecureLoadLibrarySupported() + { + LIMITED_METHOD_CONTRACT; + return s_fSecureLoadLibrarySupported; + } +#endif // !FEATURE_CORESYSTEM }; //---------------------------------------------------------------- diff --git a/src/vm/domainfile.cpp b/src/vm/domainfile.cpp index e66ebaef8b..bf7fc57774 100644 --- a/src/vm/domainfile.cpp +++ b/src/vm/domainfile.cpp @@ -3373,7 +3373,113 @@ bool DomainAssembly::GetDebuggingOverrides(DWORD *pdwFlags) } CONTRACTL_END; +#if defined(DEBUGGING_SUPPORTED) && !defined(FEATURE_CORESYSTEM) + // TODO FIX in V5.0 + // Any touch of the file system is relatively expensive even in the warm case. + // + // Ideally we remove the .INI feature completely (if we need something put it in the .exe.config file) + // + // However because of compatibility concerns, we won't do this until the next side-by-side release + // In the mean time don't check in the case where we have already loaded the NGEN image, as the + // JIT overrides don't mean anything in that case as we won't be jitting anyway. + // This avoids doing these probes for framework DLLs right away. + if (GetFile()->HasNativeImage()) + return false; + + _ASSERTE(pdwFlags); + + bool fHasBits = false; + WCHAR *pFileName = NULL; + HRESULT hr = S_OK; + UINT cbExtOrValue = 4; + WCHAR *pTail = NULL; + size_t len = 0; + WCHAR *lpFileName = NULL; + + const WCHAR *wszFileName = GetFile()->GetPath(); + + if (wszFileName == NULL) + { + return false; + } + + // lpFileName is a copy of the original, and will be edited. + CQuickBytes qb; + len = wcslen(wszFileName); + size_t cchlpFileName = (len + 1); + lpFileName = (WCHAR*)qb.AllocThrows(cchlpFileName * sizeof(WCHAR)); + wcscpy_s(lpFileName, cchlpFileName, wszFileName); + + pFileName = wcsrchr(lpFileName, W('\\')); + + if (pFileName == NULL) + { + pFileName = lpFileName; + } + + if (*pFileName == W('\\')) + { + pFileName++; //move the pointer past the last '\' + } + + _ASSERTE(wcslen(W(".INI")) == cbExtOrValue); + + if (pFileName == NULL || (pTail=wcsrchr(pFileName, W('.'))) == NULL || (wcslen(pTail)<cbExtOrValue)) + { + return false; + } + + wcscpy_s(pTail, cchlpFileName - (pTail - lpFileName), W(".INI")); + + // Win2K has a problem if multiple processes call GetPrivateProfile* on the same + // non-existent .INI file simultaneously. The OS livelocks in the kernel (i.e. + // outside of user space) and remains there at full CPU for several minutes. Then + // it breaks out. Here is our work-around, while we pursue a fix in a future + // version of the OS. + if (WszGetFileAttributes(lpFileName) == INVALID_FILE_ATTRIBUTES) + return false; + + // Having modified the filename, we use the full path + // to actually get the file. + if ((cbExtOrValue=WszGetPrivateProfileInt(DE_INI_FILE_SECTION_NAME, + DE_INI_FILE_KEY_TRACK_INFO, + INVALID_INI_INT, + lpFileName)) != INVALID_INI_INT) + { + if (cbExtOrValue != 0) + { + *pdwFlags |= DACF_OBSOLETE_TRACK_JIT_INFO; + } + else + { + *pdwFlags &= (~DACF_OBSOLETE_TRACK_JIT_INFO); + } + + fHasBits = true; + } + + if ((cbExtOrValue=WszGetPrivateProfileInt(DE_INI_FILE_SECTION_NAME, + DE_INI_FILE_KEY_ALLOW_JIT_OPTS, + INVALID_INI_INT, + lpFileName)) != INVALID_INI_INT) + { + if (cbExtOrValue != 0) + { + *pdwFlags |= DACF_ALLOW_JIT_OPTS; + } + else + { + *pdwFlags &= (~DACF_ALLOW_JIT_OPTS); + } + + fHasBits = true; + } + + return fHasBits; + +#else // DEBUGGING_SUPPORTED && !FEATURE_CORESYSTEM return false; +#endif // DEBUGGING_SUPPORTED && !FEATURE_CORESYSTEM } diff --git a/src/vm/dwreport.cpp b/src/vm/dwreport.cpp index e119fa7301..6414ff5c0e 100644 --- a/src/vm/dwreport.cpp +++ b/src/vm/dwreport.cpp @@ -127,8 +127,13 @@ public: operator HMODULE() { return hModule; } }; +#ifndef FEATURE_CORESYSTEM +#define WER_MODULE_NAME_W WINDOWS_KERNEL32_DLLNAME_W +typedef SimpleModuleHolder<WszGetModuleHandle, false> WerModuleHolder; +#else #define WER_MODULE_NAME_W W("api-ms-win-core-windowserrorreporting-l1-1-0.dll") typedef SimpleModuleHolder<CLRLoadLibrary, true> WerModuleHolder; +#endif //------------------------------------------------------------------------------ // Description @@ -211,11 +216,13 @@ BOOL RegisterOutOfProcessWatsonCallbacks() WCHAR wszDACName[] = MAIN_DAC_MODULE_NAME_W W(".dll"); WerModuleHolder hWerModule(WER_MODULE_NAME_W); +#ifdef FEATURE_CORESYSTEM if ((hWerModule == NULL) && !RunningOnWin8()) { // If we are built for CoreSystemServer, but are running on Windows 7, we need to look elsewhere hWerModule = WerModuleHolder(W("Kernel32.dll")); } +#endif if (hWerModule == NULL) { @@ -257,10 +264,15 @@ BOOL RegisterOutOfProcessWatsonCallbacks() LL_ERROR, "WATSON support: failed to register DAC dll with WerRegisterRuntimeExceptionModule"); +#ifdef FEATURE_CORESYSTEM // For CoreSys we *could* be running on a platform that doesn't have Watson proper // (the APIs might exist but they just fail). // WerRegisterRuntimeExceptionModule may return E_NOIMPL. return TRUE; +#else // FEATURE_CORESYSTEM + _ASSERTE(! "WATSON support: failed to register DAC dll with WerRegisterRuntimeExceptionModule"); + return FALSE; +#endif // FEATURE_CORESYSTEM } STRESS_LOG0(LF_STARTUP, diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h index b427d6311d..fba50a7ca9 100644 --- a/src/vm/ecalllist.h +++ b/src/vm/ecalllist.h @@ -266,6 +266,9 @@ FCFuncStart(gEnvironmentFuncs) FCFuncElement("GetCommandLineArgsNative", SystemNative::GetCommandLineArgs) FCFuncElement("get_CurrentProcessorNumber", SystemNative::GetCurrentProcessorNumber) +#if defined(FEATURE_COMINTEROP) && !defined(FEATURE_CORESYSTEM) + QCFuncElement("WinRTSupported", SystemNative::WinRTSupported) +#endif // FEATURE_COMINTEROP FCFuncElementSig("FailFast", &gsig_SM_Str_RetVoid, SystemNative::FailFast) FCFuncElementSig("FailFast", &gsig_SM_Str_Exception_RetVoid, SystemNative::FailFastWithException) FCFuncEnd() diff --git a/src/vm/eventreporter.cpp b/src/vm/eventreporter.cpp index e10aed9441..a96c525439 100644 --- a/src/vm/eventreporter.cpp +++ b/src/vm/eventreporter.cpp @@ -448,8 +448,33 @@ BOOL ShouldLogInEventLog() } CONTRACTL_END; +#ifndef FEATURE_CORESYSTEM + // If the process is being debugged, don't log + if ((CORDebuggerAttached() || IsDebuggerPresent()) +#ifdef _DEBUG + // Allow debug to be able to break in + && + CLRConfig::GetConfigValue(CLRConfig::INTERNAL_BreakOnUncaughtException) == 0 +#endif + ) + { + return FALSE; + } + + static LONG fOnce = 0; + if (fOnce == 1 || FastInterlockExchange(&fOnce, 1) == 1) + { + return FALSE; + } + + if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_logFatalError) == 0) + return FALSE; + else + return TRUE; +#else // no event log on Apollo return FALSE; +#endif //!FEATURE_CORESYSTEM } //--------------------------------------------------------------------------------------- diff --git a/src/vm/eventtrace.cpp b/src/vm/eventtrace.cpp index 4285f6e5b4..ba2f3dae57 100644 --- a/src/vm/eventtrace.cpp +++ b/src/vm/eventtrace.cpp @@ -4310,6 +4310,26 @@ HRESULT ETW::CEtwTracer::Register() { WRAPPER_NO_CONTRACT; +#ifndef FEATURE_CORESYSTEM + OSVERSIONINFO osVer; + osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + + if (GetOSVersion(&osVer) == FALSE) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + else if (osVer.dwMajorVersion < ETW_SUPPORTED_MAJORVER) { + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + } + + // if running on OS < Longhorn, skip registration unless reg key is set + // since ETW reg is expensive (in both time and working set) on older OSes + if (osVer.dwMajorVersion < ETW_ENABLED_MAJORVER && !g_fEnableETW && !CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_PreVistaETWEnabled)) + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); + + // If running on OS >= Longhorn, skip registration if ETW is not enabled + if (osVer.dwMajorVersion >= ETW_ENABLED_MAJORVER && !g_fEnableETW && !CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_VistaAndAboveETWEnabled)) + return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); +#endif EventRegisterMicrosoft_Windows_DotNETRuntime(); EventRegisterMicrosoft_Windows_DotNETRuntimePrivate(); diff --git a/src/vm/excep.cpp b/src/vm/excep.cpp index 3a4685eb11..277a9d9820 100644 --- a/src/vm/excep.cpp +++ b/src/vm/excep.cpp @@ -4149,6 +4149,18 @@ void RaiseFailFastExceptionOnWin7(PEXCEPTION_RECORD pExceptionRecord, PCONTEXT p LIMITED_METHOD_CONTRACT; _ASSERTE(RunningOnWin7()); +#ifndef FEATURE_CORESYSTEM + typedef void (WINAPI * RaiseFailFastExceptionFnPtr)(PEXCEPTION_RECORD, PCONTEXT, DWORD); + RaiseFailFastExceptionFnPtr RaiseFailFastException; + + HINSTANCE hKernel32 = WszGetModuleHandle(WINDOWS_KERNEL32_DLLNAME_W); + if (hKernel32 == NULL) + return; + + RaiseFailFastException = (RaiseFailFastExceptionFnPtr)GetProcAddress(hKernel32, "RaiseFailFastException"); + if (RaiseFailFastException == NULL) + return; +#endif // enable preemptive mode before call into OS to allow runtime suspend to finish GCX_PREEMP(); diff --git a/src/vm/gcenv.os.cpp b/src/vm/gcenv.os.cpp index 29f912ce41..784984472d 100644 --- a/src/vm/gcenv.os.cpp +++ b/src/vm/gcenv.os.cpp @@ -71,7 +71,9 @@ bool GCToOSInterface::SetCurrentThreadIdealAffinity(GCThreadAffinity* affinity) bool success = true; -#if !defined(FEATURE_PAL) +#if !defined(FEATURE_CORESYSTEM) + SetThreadIdealProcessor(GetCurrentThread(), (DWORD)affinity->Processor); +#elif !defined(FEATURE_PAL) PROCESSOR_NUMBER proc; if (affinity->Group != -1) diff --git a/src/vm/i386/cgenx86.cpp b/src/vm/i386/cgenx86.cpp index 1c6737b259..528629c3a2 100644 --- a/src/vm/i386/cgenx86.cpp +++ b/src/vm/i386/cgenx86.cpp @@ -94,7 +94,65 @@ void ClearRegDisplayArgumentAndScratchRegisters(REGDISPLAY * pRD) // BOOL Runtime_Test_For_SSE2() { +#ifdef FEATURE_CORESYSTEM return TRUE; +#else + + BOOL result = IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE); + + if (result == FALSE) + return FALSE; + + // ********************************************************************** + // *** *** + // *** IMPORTANT NOTE: *** + // *** *** + // *** All of these RunningOnXXX APIs return true when *** + // *** the OS that you are running on is that OS or later. *** + // *** For example RunningOnWin2003() will return true *** + // *** when you are running on Win2k3, Vista, Win7 or later. *** + // *** *** + // ********************************************************************** + + + // Windows 7 and later should alwys be using SSE2 instructions + // this is true for both for native and Wow64 + // + if (RunningOnWin7()) + return TRUE; + + if (RunningInWow64()) + { + // There is an issue with saving/restoring the SSE2 registers under wow64 + // So we figure out if we are running on an impacted OS and Service Pack level + // See DevDiv Bugs 89587 for the wow64 bug. + // + + _ASSERTE(ExOSInfoAvailable()); // This is always available on Vista and later + + // + // The issue is fixed in Windows Server 2008 or Vista/SP1 + // + // It is not fixed in Vista/RTM, so check for that case + // + if ((ExOSInfoRunningOnServer() == FALSE)) + { + OSVERSIONINFOEX osvi; + + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + osvi.wServicePackMajor = 0; + + DWORDLONG dwlConditionMask = 0; + VER_SET_CONDITION( dwlConditionMask, CLR_VER_SERVICEPACKMAJOR, VER_EQUAL); + + if (VerifyVersionInfo(&osvi, CLR_VER_SERVICEPACKMAJOR, dwlConditionMask)) + result = FALSE; + } + } + + return result; +#endif } //--------------------------------------------------------------- diff --git a/src/vm/i386/stublinkerx86.cpp b/src/vm/i386/stublinkerx86.cpp index 61577463c6..63b9e87367 100644 --- a/src/vm/i386/stublinkerx86.cpp +++ b/src/vm/i386/stublinkerx86.cpp @@ -3871,6 +3871,48 @@ VOID StubLinkerCPU::EmitDisable(CodeLabel *pForwardRef, BOOL fCallIn, X86Reg Thr // jnz RarePath X86EmitCondJump(pForwardRef, X86CondCode::kJNZ); +#if defined(FEATURE_COMINTEROP) && !defined(FEATURE_CORESYSTEM) + // If we are checking whether the current thread holds the loader lock, vector + // such cases to the rare disable pathway, where we can check again. + if (fCallIn && ShouldCheckLoaderLock()) + { + X86EmitPushReg(kEAX); + X86EmitPushReg(kEDX); + + if (ThreadReg == kECX) + X86EmitPushReg(kECX); + + // BOOL AuxUlibIsDLLSynchronizationHeld(BOOL *IsHeld) + // + // So we need to be sure that both the return value and the passed BOOL are both TRUE. + // If either is FALSE, then the call failed or the lock is not held. Either way, the + // probe should not fire. + + X86EmitPushReg(kEDX); // BOOL temp + Emit8(0x54); // push ESP because arg is &temp + X86EmitCall(NewExternalCodeLabel((LPVOID) AuxUlibIsDLLSynchronizationHeld), 0); + + // callee has popped. + X86EmitPopReg(kEDX); // recover temp + + CodeLabel *pPopLabel = NewCodeLabel(); + + Emit16(0xc085); // test eax, eax + X86EmitCondJump(pPopLabel, X86CondCode::kJZ); + + Emit16(0xd285); // test edx, edx + + EmitLabel(pPopLabel); // retain the conditional flags across the pops + + if (ThreadReg == kECX) + X86EmitPopReg(kECX); + + X86EmitPopReg(kEDX); + X86EmitPopReg(kEAX); + + X86EmitCondJump(pForwardRef, X86CondCode::kJNZ); + } +#endif #ifdef _DEBUG if (ThreadReg != kECX) diff --git a/src/vm/interoputil.cpp b/src/vm/interoputil.cpp index f4dc236b80..ffd54d004e 100644 --- a/src/vm/interoputil.cpp +++ b/src/vm/interoputil.cpp @@ -2520,12 +2520,20 @@ HRESULT GetCLSIDFromProgID(__in_z WCHAR *strProgId, GUID *pGuid) HRESULT hr = S_OK; +#ifdef FEATURE_CORESYSTEM LeaveRuntimeHolderNoThrow lrh((size_t)CLSIDFromProgID); +#else + LeaveRuntimeHolderNoThrow lrh((size_t)CLSIDFromProgIDEx); +#endif hr = lrh.GetHR(); if (FAILED(hr)) return hr; +#ifdef FEATURE_CORESYSTEM return CLSIDFromProgID(strProgId, pGuid); +#else + return CLSIDFromProgIDEx(strProgId, pGuid); +#endif } #endif // FEATURE_CLASSIC_COMINTEROP diff --git a/src/vm/jithelpers.cpp b/src/vm/jithelpers.cpp index 6d4fd897c4..c8c4ba647c 100644 --- a/src/vm/jithelpers.cpp +++ b/src/vm/jithelpers.cpp @@ -538,7 +538,7 @@ ftype BankersRound(ftype value) if ((value -(integerPart +0.5)) == 0.0) { // round to even -#if defined(_TARGET_ARM_) +#if defined(_TARGET_ARM_) && defined(FEATURE_CORESYSTEM) // @ARMTODO: On ARM when building on CoreSystem (where we link against the system CRT) an attempt to // use fmod(float, float) fails to link (apparently this is converted to a reference to fmodf, which // is not included in the system CRT). Use the double version instead. diff --git a/src/vm/jitinterface.cpp b/src/vm/jitinterface.cpp index 8ea9016179..5411b968a0 100644 --- a/src/vm/jitinterface.cpp +++ b/src/vm/jitinterface.cpp @@ -12769,6 +12769,7 @@ PCODE UnsafeJitFunction(MethodDesc* ftn, COR_ILMETHOD_DECODER* ILHeader, CORJIT_ "Jitted Entry at" FMT_ADDR "method %s::%s %s\n", DBG_ADDR(nativeEntry), ftn->m_pszDebugClassName, ftn->m_pszDebugMethodName, ftn->m_pszDebugMethodSignature)); +#if defined(FEATURE_CORESYSTEM) #ifdef _DEBUG LPCUTF8 pszDebugClassName = ftn->m_pszDebugClassName; @@ -12783,6 +12784,7 @@ PCODE UnsafeJitFunction(MethodDesc* ftn, COR_ILMETHOD_DECODER* ILHeader, CORJIT_ //DbgPrintf("Jitted Entry at" FMT_ADDR "method %s::%s %s size %08x\n", DBG_ADDR(nativeEntry), // pszDebugClassName, pszDebugMethodName, pszDebugMethodSignature, sizeOfCode); +#endif ClrFlushInstructionCache(nativeEntry, sizeOfCode); ret = (PCODE)nativeEntry; diff --git a/src/vm/methodtablebuilder.cpp b/src/vm/methodtablebuilder.cpp index 68148d7683..303edc4683 100644 --- a/src/vm/methodtablebuilder.cpp +++ b/src/vm/methodtablebuilder.cpp @@ -5172,6 +5172,7 @@ void MethodTableBuilder::SetSecurityFlagsOnMethod(bmtRTMethod* pParentMethod, pNewMD->SetRequiresLinktimeCheck(); } +#if defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) // All public methods on public types will do a link demand of // full trust, unless AllowUntrustedCaller attribute is set if ( @@ -5199,6 +5200,7 @@ void MethodTableBuilder::SetSecurityFlagsOnMethod(bmtRTMethod* pParentMethod, pNewMD->SetRequiresLinktimeCheck(); } } +#endif // defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) // If it's a delegate BeginInvoke, we need to do a HostProtection check for synchronization if(!pNewMD->RequiresLinktimeCheck() && IsDelegate()) diff --git a/src/vm/notifyexternals.cpp b/src/vm/notifyexternals.cpp index 1d69edf0b8..df1cce4e5b 100644 --- a/src/vm/notifyexternals.cpp +++ b/src/vm/notifyexternals.cpp @@ -30,6 +30,32 @@ BOOL ShouldCheckLoaderLock(BOOL fForMDA /*= TRUE*/) } CONTRACTL_END; +#ifdef FEATURE_CORESYSTEM // CoreSystem does not support this. return FALSE; +#else + // Because of how C++ generates code, we must use default initialization to + // 0 here. Any explicit initialization will result in thread-safety problems. + static BOOL fInited; + static BOOL fShouldCheck; + static BOOL fShouldCheck_ForMDA; + + if (VolatileLoad(&fInited) == FALSE) + { + fShouldCheck_ForMDA = FALSE; + + fShouldCheck = AuxUlibInitialize(); // may fail + +#ifdef MDA_SUPPORTED + if (fShouldCheck) + { + MdaLoaderLock* pProbe = MDA_GET_ASSISTANT(LoaderLock); + if (pProbe) + fShouldCheck_ForMDA = TRUE; + } +#endif // MDA_SUPPORTED + VolatileStore(&fInited, TRUE); + } + return (fForMDA ? fShouldCheck_ForMDA : fShouldCheck); +#endif // FEATURE_CORESYSTEM } diff --git a/src/vm/runtimecallablewrapper.cpp b/src/vm/runtimecallablewrapper.cpp index dace892bf7..a3f71279d9 100644 --- a/src/vm/runtimecallablewrapper.cpp +++ b/src/vm/runtimecallablewrapper.cpp @@ -702,6 +702,7 @@ IUnknown *AppXComClassFactory::CreateInstanceInternal(IUnknown *pOuter, BOOL *pf HRESULT hr; +#ifdef FEATURE_CORESYSTEM // This works around a bug in the Windows 7 loader that prevents us from loading the // forwarder for this function typedef HRESULT (*CoCreateInstanceFromAppFnPtr) (REFCLSID rclsid, IUnknown *punkOuter, DWORD dwClsCtx, @@ -722,6 +723,7 @@ IUnknown *AppXComClassFactory::CreateInstanceInternal(IUnknown *pOuter, BOOL *pf _ASSERTE(false); IfFailThrow(E_FAIL); } +#endif LeaveRuntimeHolder lrh((size_t)CoCreateInstanceFromApp); diff --git a/src/vm/securitydeclarative.cpp b/src/vm/securitydeclarative.cpp index 1d0f5c34f7..a21bdb0485 100644 --- a/src/vm/securitydeclarative.cpp +++ b/src/vm/securitydeclarative.cpp @@ -642,6 +642,7 @@ LinktimeCheckReason SecurityDeclarative::GetLinktimeCheckReason(MethodDesc *pMD, LinktimeCheckReason reason = LinktimeCheckReason_None; +#if defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) ModuleSecurityDescriptor *pMSD = ModuleSecurityDescriptor::GetModuleSecurityDescriptor(pMD->GetAssembly()); // If the method does not allow partially trusted callers, then the check is because we need to ensure all @@ -650,6 +651,7 @@ LinktimeCheckReason SecurityDeclarative::GetLinktimeCheckReason(MethodDesc *pMD, { reason |= LinktimeCheckReason_AptcaCheck; } +#endif // defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) // // If the method has a LinkDemand on it for either CAS or non-CAS permissions, get those and set the diff --git a/src/vm/securitymeta.cpp b/src/vm/securitymeta.cpp index 8bff148516..008a4081c8 100644 --- a/src/vm/securitymeta.cpp +++ b/src/vm/securitymeta.cpp @@ -1468,6 +1468,7 @@ VOID ModuleSecurityDescriptor::Fixup(DataImage *image) } #endif +#if defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) //--------------------------------------------------------------------------------------- // @@ -1510,6 +1511,7 @@ TokenSecurityDescriptorFlags ParseAptcaAttribute(const BYTE *pbAptcaBlob, DWORD return aptcaFlags; } +#endif // defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) //--------------------------------------------------------------------------------------- // @@ -1615,6 +1617,7 @@ TokenSecurityDescriptorFlags TokenSecurityDescriptor::ReadSecurityAttributes(IMD szAttributeNamespace != NULL && strcmp(g_SecurityNS, szAttributeNamespace) == 0) { +#if defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) if (strcmp(g_SecurityAPTCA + sizeof(g_SecurityNS), szAttributeName) == 0) { // Check the visibility parameter @@ -1630,6 +1633,7 @@ TokenSecurityDescriptorFlags TokenSecurityDescriptor::ReadSecurityAttributes(IMD flags |= aptcaFlags; } else +#endif // defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) if (strcmp(g_SecurityCriticalAttribute + sizeof(g_SecurityNS), szAttributeName) == 0) { flags |= TokenSecurityDescriptorFlags_Critical; diff --git a/src/vm/securitymeta.h b/src/vm/securitymeta.h index 403133cf74..00ff923883 100644 --- a/src/vm/securitymeta.h +++ b/src/vm/securitymeta.h @@ -630,8 +630,10 @@ public: inline SecurityRuleSet GetSecurityRuleSet(); +#if defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) // Does the assembly allow partially trusted callers inline BOOL IsAPTCA(); +#endif // defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) private: diff --git a/src/vm/securitytransparentassembly.cpp b/src/vm/securitytransparentassembly.cpp index f9ac18cd62..7488dd555d 100644 --- a/src/vm/securitytransparentassembly.cpp +++ b/src/vm/securitytransparentassembly.cpp @@ -1238,10 +1238,12 @@ public: ModuleSecurityDescriptorFlags moduleFlags = ModuleSecurityDescriptorFlags_None; +#if defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) if (tokenFlags & TokenSecurityDescriptorFlags_APTCA) { moduleFlags |= ModuleSecurityDescriptorFlags_IsAPTCA; } +#endif // defined(FEATURE_APTCA) || defined(FEATURE_CORESYSTEM) if (tokenFlags & TokenSecurityDescriptorFlags_Critical) { @@ -1324,7 +1326,6 @@ public: } }; - // // Shared transparency behavior objects // diff --git a/src/vm/util.cpp b/src/vm/util.cpp index ac0da8d3de..cc52b917e3 100644 --- a/src/vm/util.cpp +++ b/src/vm/util.cpp @@ -369,6 +369,20 @@ void NPrintToHandleA(HANDLE Handle, const char *pszString, size_t BytesToWrite) DWORD dwChunkToWrite = (DWORD) min(BytesToWrite, maxWriteFileSize); // No CharNextExA on CoreSystem, we just assume no multi-byte characters (this code path shouldn't be // used in the production codepath for currently supported CoreSystem based products anyway). +#ifndef FEATURE_CORESYSTEM + if (dwChunkToWrite < BytesToWrite) { + break; + // must go by char to find biggest string that will fit, taking DBCS chars into account + //dwChunkToWrite = 0; + //const char *charNext = pszString; + //while (dwChunkToWrite < maxWriteFileSize-2 && charNext) { + // charNext = CharNextExA(0, pszString+dwChunkToWrite, 0); + // dwChunkToWrite = (DWORD)(charNext - pszString); + //} + //if (dwChunkToWrite == 0) + // break; + } +#endif // !FEATURE_CORESYSTEM // Try to write to handle. If this is not a CUI app, then this is probably // not going to work unless the dev took special pains to set their own console @@ -2229,11 +2243,78 @@ DWORD GetLogicalCpuCountFallback() if(LogicalNum > 1) { +#ifdef FEATURE_CORESYSTEM // CoreSystem doesn't expose GetProcessAffinityMask or SetProcessAffinityMask or anything // functionally equivalent. Just assume 1:1 mapping if we get here (in reality we shouldn't since // all CoreSystems support GetLogicalProcessorInformation so GetLogicalCpuCountFromOS should have // taken care of everything. goto fDone; +#else // FEATURE_CORESYSTEM + HANDLE hCurrentProcessHandle; + DWORD_PTR dwProcessAffinity; + DWORD_PTR dwSystemAffinity; + DWORD_PTR dwAffinityMask; + + // Calculate the appropriate shifts and mask based on the + // number of logical processors. + + BYTE i = 1, PHY_ID_MASK = 0xFF, PHY_ID_SHIFT = 0; + while (i < LogicalNum) + { + i *= 2; + PHY_ID_MASK <<= 1; + PHY_ID_SHIFT++; + } + hCurrentProcessHandle = GetCurrentProcess(); + + GetProcessAffinityMask(hCurrentProcessHandle, &dwProcessAffinity, &dwSystemAffinity); + + // Check if available process affinity mask is equal to the available system affinity mask + // If the masks are equal, then all the processors the OS utilizes are available to the + // application. + + if (dwProcessAffinity != dwSystemAffinity) + { + retVal = 0; + goto fDone; + } + + dwAffinityMask = 1; + + // loop over all processors, running APIC ID retrieval code starting + // with the first one by setting process affinity. + while (dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity) + { + // Check if this CPU is available + if (dwAffinityMask & dwProcessAffinity) + { + if (SetProcessAffinityMask(hCurrentProcessHandle, dwAffinityMask)) + { + BYTE APIC_ID, LOG_ID, PHY_ID; + __SwitchToThread(0, CALLER_LIMITS_SPINNING); // Give OS time to switch CPU + + getextcpuid(0,1, buffer); //call cpuid with EAX=1 + + APIC_ID = (dwBuffer[1] & INITIAL_APIC_ID_BITS) >> 24; + LOG_ID = APIC_ID & ~PHY_ID_MASK; + PHY_ID = APIC_ID >> PHY_ID_SHIFT; + if (LOG_ID != 0) + lProcCounter++; + } + } + dwAffinityMask = dwAffinityMask << 1; + } + // Reset the processor affinity + + SetProcessAffinityMask(hCurrentProcessHandle, dwProcessAffinity); + + // Check if HT is enabled on all the processors + if(lProcCounter > 0 && (lProcCounter == (DWORD)(PhysicalNum / LogicalNum))) + { + retVal = lProcCounter; + goto fDone; + } +#endif // FEATURE_CORESYSTEM } } fDone: diff --git a/src/vm/win32threadpool.cpp b/src/vm/win32threadpool.cpp index 90be10a99b..e8a05c383f 100644 --- a/src/vm/win32threadpool.cpp +++ b/src/vm/win32threadpool.cpp @@ -495,7 +495,11 @@ void ThreadpoolMgr::InitPlatformVariables() CONTRACT_VIOLATION(GCViolation|FaultViolation); hNtDll = CLRLoadLibrary(W("ntdll.dll")); _ASSERTE(hNtDll); +#ifdef FEATURE_CORESYSTEM hCoreSynch = CLRLoadLibrary(W("api-ms-win-core-synch-l1-1-0.dll")); +#else + hCoreSynch = CLRLoadLibrary(W("kernel32.dll")); +#endif _ASSERTE(hCoreSynch); } |