Clear the init-locals bit for CoreLib to workaround #1279 (#13728)
authorJan Kotas <jkotas@microsoft.com>
Fri, 1 Sep 2017 17:57:33 +0000 (10:57 -0700)
committerGitHub <noreply@github.com>
Fri, 1 Sep 2017 17:57:33 +0000 (10:57 -0700)
* Clear the init-locals bit for CoreLib to workaround #1279

* Yet another place that depends on zero init locals

src/mscorlib/shared/System/Diagnostics/Tracing/TraceLogging/TraceLoggingEventSource.cs
src/mscorlib/src/System/Globalization/TextInfo.Windows.cs
src/mscorlib/src/System/RtType.cs
src/vm/jitinterface.cpp

index aba1671..251189c 100644 (file)
@@ -442,7 +442,10 @@ namespace System.Diagnostics.Tracing
             var pinCount = eventTypes.pinCount;
             var scratch = stackalloc byte[eventTypes.scratchSize];
             var descriptors = stackalloc EventData[eventTypes.dataCount + 3];
+
             var pins = stackalloc GCHandle[pinCount];
+            for (int i = 0; i < pinCount; i++)
+                pins[i] = default(GCHandle);
 
             fixed (byte*
                 pMetadata0 = this.providerMetadata,
@@ -619,7 +622,10 @@ namespace System.Diagnostics.Tracing
                     var pinCount = eventTypes.pinCount;
                     var scratch = stackalloc byte[eventTypes.scratchSize];
                     var descriptors = stackalloc EventData[eventTypes.dataCount + 3];
+
                     var pins = stackalloc GCHandle[pinCount];
+                    for (int i = 0; i < pinCount; i++)
+                        pins[i] = default(GCHandle);
 
                     fixed (byte*
                         pMetadata0 = this.providerMetadata,
@@ -744,9 +750,9 @@ namespace System.Diagnostics.Tracing
         {
             DataCollector.ThreadInstance.Disable();
 
-            for (int i = 0; i != cPins; i++)
+            for (int i = 0; i < cPins; i++)
             {
-                if (IntPtr.Zero != (IntPtr)pPins[i])
+                if (pPins[i].IsAllocated)
                 {
                     pPins[i].Free();
                 }
index cc7c4df..58dfe32 100644 (file)
@@ -18,9 +18,9 @@ namespace System.Globalization
 
             const uint LCMAP_SORTHANDLE = 0x20000000;
 
-            long handle;
+            IntPtr handle;
             int ret = Interop.Kernel32.LCMapStringEx(_textInfoName, LCMAP_SORTHANDLE, null, 0, &handle, IntPtr.Size, null, null, IntPtr.Zero);
-            _sortHandle = ret > 0 ? (IntPtr)handle : IntPtr.Zero;
+            _sortHandle = ret > 0 ? handle : IntPtr.Zero;
         }
 
         private unsafe string ChangeCase(string s, bool toUpper)
index df9d419..a41fff1 100644 (file)
@@ -618,7 +618,11 @@ namespace System
                         while (RuntimeTypeHandle.IsGenericVariable(declaringType))
                             declaringType = declaringType.GetBaseType();
 
-                        bool* overrides = stackalloc bool[RuntimeTypeHandle.GetNumVirtuals(declaringType)];
+                        int numVirtuals = RuntimeTypeHandle.GetNumVirtuals(declaringType);
+
+                        bool* overrides = stackalloc bool[numVirtuals];
+                        new Span<bool>(overrides, numVirtuals).Clear();
+
                         bool isValueType = declaringType.IsValueType;
 
                         do
index d8113ec..71af406 100644 (file)
@@ -7192,31 +7192,41 @@ getMethodInfoHelper(
         bool fILIntrinsic = false;
 
         MethodTable * pMT  = ftn->GetMethodTable();
-      
-        if (MscorlibBinder::IsClass(pMT, CLASS__JIT_HELPERS))
-        {
-            fILIntrinsic = getILIntrinsicImplementation(ftn, methInfo);
-        }
-        else if (MscorlibBinder::IsClass(pMT, CLASS__UNSAFE))
-        {
-            fILIntrinsic = getILIntrinsicImplementationForUnsafe(ftn, methInfo);
-        }
-        else if (MscorlibBinder::IsClass(pMT, CLASS__INTERLOCKED))
-        {
-            fILIntrinsic = getILIntrinsicImplementationForInterlocked(ftn, methInfo);
-        }
-        else if (MscorlibBinder::IsClass(pMT, CLASS__VOLATILE))
-        {
-            fILIntrinsic = getILIntrinsicImplementationForVolatile(ftn, methInfo);
-        }
-        else if (MscorlibBinder::IsClass(pMT, CLASS__RUNTIME_HELPERS))
+
+        if (pMT->GetModule()->IsSystem())
         {
-            fILIntrinsic = getILIntrinsicImplementationForRuntimeHelpers(ftn, methInfo);
+            if (MscorlibBinder::IsClass(pMT, CLASS__JIT_HELPERS))
+            {
+                fILIntrinsic = getILIntrinsicImplementation(ftn, methInfo);
+            }
+            else if (MscorlibBinder::IsClass(pMT, CLASS__UNSAFE))
+            {
+                fILIntrinsic = getILIntrinsicImplementationForUnsafe(ftn, methInfo);
+            }
+            else if (MscorlibBinder::IsClass(pMT, CLASS__INTERLOCKED))
+            {
+                fILIntrinsic = getILIntrinsicImplementationForInterlocked(ftn, methInfo);
+            }
+            else if (MscorlibBinder::IsClass(pMT, CLASS__VOLATILE))
+            {
+                fILIntrinsic = getILIntrinsicImplementationForVolatile(ftn, methInfo);
+            }
+            else if (MscorlibBinder::IsClass(pMT, CLASS__RUNTIME_HELPERS))
+            {
+                fILIntrinsic = getILIntrinsicImplementationForRuntimeHelpers(ftn, methInfo);
+            }
         }
 
         if (!fILIntrinsic)
         {
             getMethodInfoILMethodHeaderHelper(header, methInfo);
+
+            // Workaround for https://github.com/dotnet/coreclr/issues/1279
+            // Set init locals bit to zero for system module unless profiler may have overrided it. Remove once we have
+            // better solution for this issue.
+            if (pMT->GetModule()->IsSystem() && !(CORProfilerDisableAllNGenImages() || CORProfilerUseProfileImages()))
+                methInfo->options = (CorInfoOptions)0;
+
             pLocalSig = header->LocalVarSig;
             cbLocalSig = header->cbLocalVarSig;
         }