From: Mike McLaughlin Date: Fri, 28 Apr 2023 17:36:38 +0000 (-0700) Subject: Deal with 8.0 DAC passing bigger thread context to data target's GetThreadContext... X-Git-Tag: accepted/tizen/unified/riscv/20231226.055542~39^2^2~71 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ddbcaa3164f2947e5a41db7317442c7a9a88643d;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Deal with 8.0 DAC passing bigger thread context to data target's GetThreadContext() (#3856) --- diff --git a/src/SOS/SOS.Hosting/CorDebugDataTargetWrapper.cs b/src/SOS/SOS.Hosting/CorDebugDataTargetWrapper.cs index d229f23f8..5e69c4753 100644 --- a/src/SOS/SOS.Hosting/CorDebugDataTargetWrapper.cs +++ b/src/SOS/SOS.Hosting/CorDebugDataTargetWrapper.cs @@ -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 diff --git a/src/SOS/SOS.Hosting/DataTargetWrapper.cs b/src/SOS/SOS.Hosting/DataTargetWrapper.cs index 301fdaab5..303e88d82 100644 --- a/src/SOS/SOS.Hosting/DataTargetWrapper.cs +++ b/src/SOS/SOS.Hosting/DataTargetWrapper.cs @@ -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) { diff --git a/src/SOS/SOS.Hosting/DbgEng/DebugAdvanced.cs b/src/SOS/SOS.Hosting/DbgEng/DebugAdvanced.cs index 83958ee62..5ac700035 100644 --- a/src/SOS/SOS.Hosting/DbgEng/DebugAdvanced.cs +++ b/src/SOS/SOS.Hosting/DbgEng/DebugAdvanced.cs @@ -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 } diff --git a/src/SOS/SOS.Hosting/LLDBServices.cs b/src/SOS/SOS.Hosting/LLDBServices.cs index 30ea3dbb8..5ac39d92a 100644 --- a/src/SOS/SOS.Hosting/LLDBServices.cs +++ b/src/SOS/SOS.Hosting/LLDBServices.cs @@ -443,7 +443,7 @@ namespace SOS.Hosting IntPtr self, uint threadId, uint contextFlags, - uint contextSize, + int contextSize, IntPtr context); [UnmanagedFunctionPointer(CallingConvention.Winapi)] diff --git a/src/SOS/SOS.Hosting/SOSHost.cs b/src/SOS/SOS.Hosting/SOSHost.cs index 4dadf27fa..03d011d0d 100644 --- a/src/SOS/SOS.Hosting/SOSHost.cs +++ b/src/SOS/SOS.Hosting/SOSHost.cs @@ -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; }