Deal with 8.0 DAC passing bigger thread context to data target's GetThreadContext...
authorMike McLaughlin <mikem@microsoft.com>
Fri, 28 Apr 2023 17:36:38 +0000 (10:36 -0700)
committerGitHub <noreply@github.com>
Fri, 28 Apr 2023 17:36:38 +0000 (10:36 -0700)
src/SOS/SOS.Hosting/CorDebugDataTargetWrapper.cs
src/SOS/SOS.Hosting/DataTargetWrapper.cs
src/SOS/SOS.Hosting/DbgEng/DebugAdvanced.cs
src/SOS/SOS.Hosting/LLDBServices.cs
src/SOS/SOS.Hosting/SOSHost.cs

index d229f23f828c3ef56108d0d1e2835b5a1280e22d..5e69c4753205a786d133800da513b17000e1c05b 100644 (file)
@@ -143,7 +143,7 @@ namespace SOS.Hosting
             IntPtr self,
             uint threadId,
             uint contextFlags,
-            uint contextSize,
+            int contextSize,
             IntPtr context)
         {
             byte[] registerContext;
@@ -157,7 +157,7 @@ namespace SOS.Hosting
             }
             try
             {
-                Marshal.Copy(registerContext, 0, context, (int)contextSize);
+                Marshal.Copy(registerContext, 0, context, Math.Min(registerContext.Length, contextSize));
             }
             catch (Exception ex) when (ex is ArgumentOutOfRangeException or ArgumentNullException)
             {
@@ -246,7 +246,7 @@ namespace SOS.Hosting
             [In] IntPtr self,
             [In] uint threadId,
             [In] uint contextFlags,
-            [In] uint contextSize,
+            [In] int contextSize,
             [Out] IntPtr context);
 
         #endregion
index 301fdaab5086861b98d67f59aa69cb4f67091909..303e88d825009b84d9b60760d889fa8cdb994e77 100644 (file)
@@ -231,7 +231,7 @@ namespace SOS.Hosting
             }
             try
             {
-                Marshal.Copy(registerContext, 0, context, contextSize);
+                Marshal.Copy(registerContext, 0, context, Math.Min(registerContext.Length, contextSize));
             }
             catch (Exception ex) when (ex is ArgumentOutOfRangeException or ArgumentNullException)
             {
index 83958ee622afad2adfe023f08b5d321c78e87d6a..5ac700035758998371fba7e52b28df3b0c7359c6 100644 (file)
@@ -24,13 +24,13 @@ namespace SOS.Hosting.DbgEng
         private delegate int GetThreadContextDelegate(
             [In] IntPtr self,
             [In] IntPtr context,
-            [In] uint contextSize);
+            [In] int contextSize);
 
         [UnmanagedFunctionPointer(CallingConvention.Winapi)]
         private delegate int SetThreadContextDelegate(
             [In] IntPtr self,
             [In] IntPtr context,
-            [In] uint contextSize);
+            [In] int contextSize);
 
         #endregion
     }
index 30ea3dbb8df735619d882258f5087f17cdda7f94..5ac39d92a0dc68003d2ac903f14f56752f91774a 100644 (file)
@@ -443,7 +443,7 @@ namespace SOS.Hosting
             IntPtr self,
             uint threadId,
             uint contextFlags,
-            uint contextSize,
+            int contextSize,
             IntPtr context);
 
         [UnmanagedFunctionPointer(CallingConvention.Winapi)]
index 4dadf27fa40b029f4a38334b0aa4620e8c8d30db..03d011d0da3a3528b344c69817d6b87f107577a9 100644 (file)
@@ -575,7 +575,7 @@ namespace SOS.Hosting
         internal int GetThreadContext(
             IntPtr self,
             IntPtr context,
-            uint contextSize)
+            int contextSize)
         {
             IThread thread = ContextService.GetCurrentThread();
             if (thread is not null)
@@ -589,7 +589,7 @@ namespace SOS.Hosting
             IntPtr self,
             uint threadId,
             uint contextFlags,
-            uint contextSize,
+            int contextSize,
             IntPtr context)
         {
             byte[] registerContext;
@@ -603,7 +603,7 @@ namespace SOS.Hosting
             }
             try
             {
-                Marshal.Copy(registerContext, 0, context, (int)contextSize);
+                Marshal.Copy(registerContext, 0, context, Math.Min(registerContext.Length, contextSize));
             }
             catch (Exception ex) when (ex is ArgumentOutOfRangeException or ArgumentNullException)
             {
@@ -615,7 +615,7 @@ namespace SOS.Hosting
         internal static int SetThreadContext(
             IntPtr self,
             IntPtr context,
-            uint contextSize)
+            int contextSize)
         {
             return DebugClient.NotImplemented;
         }