Skip to content

Commit

Permalink
Change return value type from HResult to int to avoid crash on Linux …
Browse files Browse the repository at this point in the history
…x86 (#3129)
  • Loading branch information
o-lek authored Jul 7, 2022
1 parent 141c2b0 commit baa1518
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 61 deletions.
46 changes: 23 additions & 23 deletions src/SOS/SOS.Extensions/DebuggerServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,32 +365,32 @@ public HResult AddModuleSymbol(string symbolFileName)
[StructLayout(LayoutKind.Sequential)]
private readonly unsafe struct IDebuggerServicesVTable
{
public readonly delegate* unmanaged[Stdcall]<IntPtr, out DebuggerServices.OperatingSystem, HResult> GetOperatingSystem;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out DEBUG_CLASS, out DEBUG_CLASS_QUALIFIER, HResult> GetDebuggeeType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out IMAGE_FILE_MACHINE, HResult> GetExecutingProcessorType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, byte*, byte*, IntPtr*, int, HResult> AddCommand;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out DebuggerServices.OperatingSystem, int> GetOperatingSystem;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out DEBUG_CLASS, out DEBUG_CLASS_QUALIFIER, int> GetDebuggeeType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out IMAGE_FILE_MACHINE, int> GetExecutingProcessorType;
public readonly delegate* unmanaged[Stdcall]<IntPtr, byte*, byte*, IntPtr*, int, int> AddCommand;
public readonly delegate* unmanaged[Stdcall]<IntPtr, DEBUG_OUTPUT, byte*, void> OutputString;
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, byte*, uint, out int, HResult> ReadVirtual;
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, byte*, uint, out int, HResult> WriteVirtual;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out uint, out uint, HResult> GetNumberModules;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, ulong, byte*, uint, out uint, byte*, uint, uint*, byte*, uint, uint*, HResult> GetModuleNames;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, out ulong, out ulong, out uint, out uint, HResult> GetModuleInfo;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, ulong, byte*, byte*, uint, uint*, HResult> GetModuleVersionInformation;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out uint, HResult> GetNumberThreads;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, uint, uint*, uint*, HResult> GetThreadIdsByIndex;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, uint, uint, byte*, HResult> GetThreadContextBySystemId;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out uint, HResult> GetCurrentProcessSystemId;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out uint, HResult> GetCurrentThreadSystemId;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, HResult> SetCurrentThreadSystemId;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, out ulong, HResult> GetThreadTeb;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, uint, byte*, HResult> VirtualUnwind;
public readonly delegate* unmanaged[Stdcall]<IntPtr, byte*, uint, out uint, HResult> GetSymbolPath;
public readonly delegate* unmanaged[Stdcall]<IntPtr, int, ulong, byte*, int, out uint, out ulong, HResult> GetSymbolByOffset;
public readonly delegate* unmanaged[Stdcall]<IntPtr, int, byte*, out ulong, HResult> GetOffsetBySymbol;
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, byte*, uint, out int, int> ReadVirtual;
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, byte*, uint, out int, int> WriteVirtual;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out uint, out uint, int> GetNumberModules;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, ulong, byte*, uint, out uint, byte*, uint, uint*, byte*, uint, uint*, int> GetModuleNames;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, out ulong, out ulong, out uint, out uint, int> GetModuleInfo;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, ulong, byte*, byte*, uint, uint*, int> GetModuleVersionInformation;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out uint, int> GetNumberThreads;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, uint, uint*, uint*, int> GetThreadIdsByIndex;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, uint, uint, byte*, int> GetThreadContextBySystemId;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out uint, int> GetCurrentProcessSystemId;
public readonly delegate* unmanaged[Stdcall]<IntPtr, out uint, int> GetCurrentThreadSystemId;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, int> SetCurrentThreadSystemId;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, out ulong, int> GetThreadTeb;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint, uint, byte*, int> VirtualUnwind;
public readonly delegate* unmanaged[Stdcall]<IntPtr, byte*, uint, out uint, int> GetSymbolPath;
public readonly delegate* unmanaged[Stdcall]<IntPtr, int, ulong, byte*, int, out uint, out ulong, int> GetSymbolByOffset;
public readonly delegate* unmanaged[Stdcall]<IntPtr, int, byte*, out ulong, int> GetOffsetBySymbol;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint> GetOutputWidth;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint*, HResult> SupportsDml;
public readonly delegate* unmanaged[Stdcall]<IntPtr, uint*, int> SupportsDml;
public readonly delegate* unmanaged[Stdcall]<IntPtr, DEBUG_OUTPUT, byte*, void> OutputDmlString;
public readonly delegate* unmanaged[Stdcall]<IntPtr, IntPtr, byte*, HResult> AddModuleSymbol;
public readonly delegate* unmanaged[Stdcall]<IntPtr, IntPtr, byte*, int> AddModuleSymbol;
}
}
}
4 changes: 2 additions & 2 deletions src/SOS/SOS.Extensions/RemoteMemoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public bool FreeMemory(ulong address, uint size, uint typeFlags)
[StructLayout(LayoutKind.Sequential)]
private readonly unsafe struct IRemoteMemoryServiceVTable
{
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, uint, uint, uint, out ulong, HResult> AllocVirtual;
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, uint, uint, HResult> FreeVirtual;
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, uint, uint, uint, out ulong, int> AllocVirtual;
public readonly delegate* unmanaged[Stdcall]<IntPtr, ulong, uint, uint, int> FreeVirtual;
}
}
}
60 changes: 30 additions & 30 deletions src/SOS/SOS.Hosting/DataTargetWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected override void Destroy()

#region ICLRDataTarget

private HResult GetMachineType(
private int GetMachineType(
IntPtr self,
out IMAGE_FILE_MACHINE machineType)
{
Expand All @@ -121,15 +121,15 @@ private HResult GetMachineType(
return HResult.S_OK;
}

private HResult GetPointerSize(
private int GetPointerSize(
IntPtr self,
out int pointerSize)
{
pointerSize = _memoryService.PointerSize;
return HResult.S_OK;
}

private HResult GetImageBase(
private int GetImageBase(
IntPtr self,
string imagePath,
out ulong baseAddress)
Expand All @@ -144,7 +144,7 @@ private HResult GetImageBase(
return HResult.E_FAIL;
}

private HResult ReadVirtual(
private int ReadVirtual(
IntPtr self,
ulong address,
IntPtr buffer,
Expand All @@ -163,7 +163,7 @@ private HResult ReadVirtual(
return HResult.S_OK;
}

private HResult WriteVirtual(
private int WriteVirtual(
IntPtr self,
ulong address,
IntPtr buffer,
Expand All @@ -180,7 +180,7 @@ private HResult WriteVirtual(
return HResult.S_OK;
}

private HResult GetTLSValue(
private int GetTLSValue(
IntPtr self,
uint threadId,
uint index,
Expand All @@ -189,7 +189,7 @@ private HResult GetTLSValue(
return HResult.E_NOTIMPL;
}

private HResult SetTLSValue(
private int SetTLSValue(
IntPtr self,
uint threadId,
uint index,
Expand All @@ -198,7 +198,7 @@ private HResult SetTLSValue(
return HResult.E_NOTIMPL;
}

private HResult GetCurrentThreadID(
private int GetCurrentThreadID(
IntPtr self,
out uint threadId)
{
Expand All @@ -212,7 +212,7 @@ private HResult GetCurrentThreadID(
return HResult.E_FAIL;
}

private HResult GetThreadContext(
private int GetThreadContext(
IntPtr self,
uint threadId,
uint contextFlags,
Expand Down Expand Up @@ -241,7 +241,7 @@ private HResult GetThreadContext(
return HResult.S_OK;
}

private HResult SetThreadContext(
private int SetThreadContext(
IntPtr self,
uint threadId,
int contextSize,
Expand All @@ -250,7 +250,7 @@ private HResult SetThreadContext(
return HResult.E_NOTIMPL;
}

private HResult Request(
private int Request(
IntPtr self,
uint reqCode,
uint inBufferSize,
Expand All @@ -265,7 +265,7 @@ private HResult Request(

#region ICLRDataTarget2

private HResult AllocVirtual(
private int AllocVirtual(
IntPtr self,
ulong address,
uint size,
Expand All @@ -283,7 +283,7 @@ private HResult AllocVirtual(
return HResult.S_OK;
}

private HResult FreeVirtual(
private int FreeVirtual(
IntPtr self,
ulong address,
uint size,
Expand Down Expand Up @@ -325,7 +325,7 @@ private int VirtualUnwind(

#region ICLRMetadataLocator

private HResult GetMetadata(
private int GetMetadata(
IntPtr self,
string fileName,
uint imageTimestamp,
Expand All @@ -344,7 +344,7 @@ private HResult GetMetadata(

#region ICLRRuntimeLocator

private HResult GetRuntimeBase(
private int GetRuntimeBase(
IntPtr self,
out ulong address)
{
Expand All @@ -357,73 +357,73 @@ private HResult GetRuntimeBase(
#region ICLRDataTarget delegates

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetMachineTypeDelegate(
private delegate int GetMachineTypeDelegate(
[In] IntPtr self,
[Out] out IMAGE_FILE_MACHINE machineType);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetPointerSizeDelegate(
private delegate int GetPointerSizeDelegate(
[In] IntPtr self,
[Out] out int pointerSize);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetImageBaseDelegate(
private delegate int GetImageBaseDelegate(
[In] IntPtr self,
[In][MarshalAs(UnmanagedType.LPWStr)] string imagePath,
[Out] out ulong baseAddress);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult ReadVirtualDelegate(
private delegate int ReadVirtualDelegate(
[In] IntPtr self,
[In] ulong address,
[In] IntPtr buffer,
[In] uint bytesRequested,
[Out] uint* bytesRead);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult WriteVirtualDelegate(
private delegate int WriteVirtualDelegate(
[In] IntPtr self,
[In] ulong address,
[In] IntPtr buffer,
[In] uint bytesRequested,
[Out] uint* bytesWritten);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetTLSValueDelegate(
private delegate int GetTLSValueDelegate(
[In] IntPtr self,
[In] uint threadId,
[In] uint index,
[Out] ulong* value);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult SetTLSValueDelegate(
private delegate int SetTLSValueDelegate(
[In] IntPtr self,
[In] uint threadId,
[In] uint index,
[In] ulong value);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetCurrentThreadIDDelegate(
private delegate int GetCurrentThreadIDDelegate(
[In] IntPtr self,
[Out] out uint threadId);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetThreadContextDelegate(
private delegate int GetThreadContextDelegate(
[In] IntPtr self,
[In] uint threadId,
[In] uint contextFlags,
[In] int contextSize,
[Out] IntPtr context);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult SetThreadContextDelegate(
private delegate int SetThreadContextDelegate(
[In] IntPtr self,
[In] uint threadId,
[In] int contextSize,
[In] IntPtr context);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult RequestDelegate(
private delegate int RequestDelegate(
[In] IntPtr self,
[In] uint reqCode,
[In] uint inBufferSize,
Expand All @@ -436,7 +436,7 @@ private delegate HResult RequestDelegate(
#region ICLRDataTarget2 delegates

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult AllocVirtualDelegate(
private delegate int AllocVirtualDelegate(
[In] IntPtr self,
[In] ulong address,
[In] uint size,
Expand All @@ -445,7 +445,7 @@ private delegate HResult AllocVirtualDelegate(
[Out] ulong* buffer);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult FreeVirtualDelegate(
private delegate int FreeVirtualDelegate(
[In] IntPtr self,
[In] ulong address,
[In] uint size,
Expand All @@ -467,7 +467,7 @@ private delegate int VirtualUnwindDelegate(
#region ICLRMetadataLocator delegate

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetMetadataDelegate(
private delegate int GetMetadataDelegate(
[In] IntPtr self,
[In][MarshalAs(UnmanagedType.LPWStr)] string fileName,
[In] uint imageTimestamp,
Expand All @@ -484,7 +484,7 @@ [In] [MarshalAs(UnmanagedType.LPArray, SizeConst = 16)] byte[] mvid,
#region ICLRRuntimeLocator delegate

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetRuntimeBaseDelegate(
private delegate int GetRuntimeBaseDelegate(
[In] IntPtr self,
[Out] out ulong address);

Expand Down
6 changes: 3 additions & 3 deletions src/SOS/SOS.Hosting/HostWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public HostWrapper(IHost host, Func<TargetWrapper> getTarget)
/// </summary>
/// <param name="targetWrapper">target wrapper address returned</param>
/// <returns>S_OK</returns>
private HResult GetCurrentTarget(IntPtr self, out IntPtr targetWrapper)
private int GetCurrentTarget(IntPtr self, out IntPtr targetWrapper)
{
TargetWrapper wrapper = _getTarget();
if (wrapper == null)
Expand All @@ -70,13 +70,13 @@ private delegate HostType GetHostTypeDelegate(
[In] IntPtr self);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
internal delegate HResult GetServiceDelegate(
internal delegate int GetServiceDelegate(
[In] IntPtr self,
[In] in Guid guid,
[Out] out IntPtr ptr);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetCurrentTargetDelegate(
private delegate int GetCurrentTargetDelegate(
[In] IntPtr self,
[Out] out IntPtr target);

Expand Down
2 changes: 1 addition & 1 deletion src/SOS/SOS.Hosting/ServiceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public COMCallableIUnknown GetServiceWrapper(in Guid serviceId)
/// <param name="serviceId">guid of the service</param>
/// <param name="service">pointer to return service instance</param>
/// <returns>S_OK or E_NOINTERFACE</returns>
public HResult GetService(IntPtr self, in Guid guid, out IntPtr ptr)
public int GetService(IntPtr self, in Guid guid, out IntPtr ptr)
{
ptr = IntPtr.Zero;

Expand Down
4 changes: 2 additions & 2 deletions src/SOS/SOS.Hosting/TargetWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private string GetTempDirectory(
return _target.GetTempDirectory();
}

private HResult GetRuntime(
private int GetRuntime(
IntPtr self,
IntPtr* ppRuntime)
{
Expand Down Expand Up @@ -120,7 +120,7 @@ private delegate string GetTempDirectoryDelegate(
[In] IntPtr self);

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
private delegate HResult GetRuntimeDelegate(
private delegate int GetRuntimeDelegate(
[In] IntPtr self,
[Out] IntPtr* ppRuntime);

Expand Down

0 comments on commit baa1518

Please sign in to comment.