Skip to content

Commit

Permalink
remove code preventing cross-compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Charlamb committed Jan 23, 2025
1 parent 3f490fd commit 4f1fbee
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 112 deletions.
12 changes: 0 additions & 12 deletions src/coreclr/unwinder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,3 @@ add_library_clr(unwinder_dac ${UNWINDER_SOURCES})
add_dependencies(unwinder_dac eventing_headers)
set_target_properties(unwinder_dac PROPERTIES DAC_COMPONENT TRUE)
target_compile_definitions(unwinder_dac PRIVATE FEATURE_NO_HOST)

add_library_clr(unwinder_cdac SHARED ${UNWINDER_SOURCES})
add_dependencies(unwinder_cdac eventing_headers)
target_link_libraries(unwinder_cdac PRIVATE ${STATIC_MT_CRT_LIB} ${STATIC_MT_VCRT_LIB})
target_compile_definitions(unwinder_cdac PRIVATE FEATURE_NO_HOST FEATURE_CDAC_UNWINDER)
install_clr(TARGETS unwinder_cdac DESTINATIONS cdaclibs COMPONENT debug INSTALL_ALL_ARTIFACTS)

add_library_clr(unwinder_cdac_static ${UNWINDER_SOURCES})
add_dependencies(unwinder_cdac_static eventing_headers)
target_link_libraries(unwinder_cdac_static PRIVATE ${STATIC_MT_CRT_LIB} ${STATIC_MT_VCRT_LIB})
target_compile_definitions(unwinder_cdac_static PRIVATE FEATURE_NO_HOST FEATURE_CDAC_UNWINDER)
install_clr(TARGETS unwinder_cdac_static DESTINATIONS cdaclibs COMPONENT debug)
6 changes: 4 additions & 2 deletions src/coreclr/unwinder/arm64/unwinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2335,7 +2335,7 @@ Return Value:
}

//
// pac (11111100): function has pointer authentication
// pac (11111100): function has pointer authentication
//

else if (CurCode == 0xfc) {
Expand Down Expand Up @@ -2759,6 +2759,7 @@ BOOL OOPStackUnwinderArm64::Unwind(T_CONTEXT * pContext)
return TRUE;
}

#ifndef FEATURE_CDAC_UNWINDER
BOOL DacUnwindStackFrame(T_CONTEXT *pContext, T_KNONVOLATILE_CONTEXT_POINTERS* pContextPointers)
{
OOPStackUnwinderArm64 unwinder;
Expand All @@ -2774,8 +2775,9 @@ BOOL DacUnwindStackFrame(T_CONTEXT *pContext, T_KNONVOLATILE_CONTEXT_POINTERS* p

return res;
}
#endif // FEATURE_CDAC_UNWINDER

#if defined(HOST_UNIX)
#if defined(HOST_UNIX) and !defined(FEATURE_CDAC_UNWINDER)

#undef PRUNTIME_FUNCTION

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,9 @@ private void UnwindUntilNative(TargetPointer ip, TargetPointer sp)
while (eman.GetCodeBlockHandle(new(context.Rip)) is CodeBlockHandle cbh)
{
TargetPointer methodDesc = eman.GetMethodDesc(cbh);
TargetPointer moduleBase = eman.GetModuleBaseAddress(cbh);
TargetPointer unwindInfo = eman.GetUnwindInfo(cbh, new(context.Rip));
Console.WriteLine($"IP: {context.InstructionPointer.Value:x16} SP: {context.StackPointer.Value:x16} MethodDesc: {methodDesc.Value:x16}");
try
{
Unwinder.AMD64Unwind(ref context, moduleBase.Value, new IntPtr((long)unwindInfo.Value), _target);
}
catch (System.Exception ex)
{
Expand Down Expand Up @@ -136,7 +133,6 @@ private void Unwind(TargetPointer ip, TargetPointer sp)
Rip = ip,
};
Console.WriteLine($"[AMD64Context: RIP={context.InstructionPointer.Value:x16} RSP={context.StackPointer.Value:x16}]");
Unwinder.AMD64Unwind(ref context, moduleBase.Value, new IntPtr((long)unwindInfo.Value), _target);
Console.WriteLine($"[AMD64Context: RIP={context.InstructionPointer.Value:x16} RSP={context.StackPointer.Value:x16}]");
}
catch (System.Exception ex)
Expand All @@ -150,91 +146,3 @@ private void Unwind(TargetPointer ip, TargetPointer sp)
}
}
};

internal static unsafe partial class Unwinder
{
[LibraryImport("unwinder_cdac", EntryPoint = "timesTwo")]
public static partial int TimesTwo(int x);

// ReadCallback allows the unwinder to read memory from the target process
// into an allocated buffer. This buffer is either allocated by the unwinder
// with its lifetime managed by the unwinder or allocated through GetAllocatedBuffer.
// In the latter case, the unwinder can only use the buffer for the duration of the
// unwind call. Once the call is over the cDAC will free all allocated buffers.
public delegate int ReadCallback(ulong address, void* buffer, int bufferSize);
public delegate int GetAllocatedBuffer(int bufferSize, void** buffer);

// cDAC version of GetRuntimeStackWalkInfo defined in codeman.cpp
// To maintain the same signature as the original function, we return void.
// If the moduleBase or funcEntry can not be found, both will be 0.
public delegate void GetStackWalkInfo(ulong controlPC, void* pModuleBase, void* pFuncEntry);

[LibraryImport("unwinder_cdac", EntryPoint = "amd64Unwind")]
private static partial int AMD64Unwind(
ref AMD64Context context,
[MarshalAs(UnmanagedType.FunctionPtr)] ReadCallback readCallback,
[MarshalAs(UnmanagedType.FunctionPtr)] GetAllocatedBuffer getAllocatedBuffer,
[MarshalAs(UnmanagedType.FunctionPtr)] GetStackWalkInfo getStackWalkInfo);

public static int AMD64Unwind(
ref AMD64Context context,
ulong moduleBase,
IntPtr functionEntry,
Target target)
{
ReadCallback readCallback;
GetAllocatedBuffer getAllocatedBuffer;
GetStackWalkInfo getStackWalkInfo;

// Move to IDisposable for freeing
List<IntPtr> allocatedRegions = [];

readCallback = (address, pBuffer, bufferSize) =>
{
Span<byte> span = new Span<byte>(pBuffer, bufferSize);
target.ReadBuffer(address, span);
return 0;
};
getAllocatedBuffer = (bufferSize, ppBuffer) =>
{
*ppBuffer = NativeMemory.Alloc((nuint)bufferSize);
IntPtr pBuffer = new(*ppBuffer);
//Console.WriteLine($"Allocating buffer at {pBuffer:x16}");
allocatedRegions.Add(pBuffer);
return 0;
};
getStackWalkInfo = (controlPC, pModuleBase, pFuncEntry) =>
{
IExecutionManager eman = target.Contracts.ExecutionManager;

if ((nuint)pModuleBase != 0) *(nuint*)pModuleBase = 0;
if ((nuint)pFuncEntry != 0) *(nuint*)pFuncEntry = 0;

try
{
if (eman.GetCodeBlockHandle(controlPC) is CodeBlockHandle cbh)
{
TargetPointer methodDesc = eman.GetMethodDesc(cbh);
TargetPointer moduleBase = eman.GetModuleBaseAddress(cbh);
TargetPointer unwindInfo = eman.GetUnwindInfo(cbh, controlPC);
if ((nuint)pModuleBase != 0) *(nuint*)pModuleBase = (nuint)moduleBase.Value;
if ((nuint)pFuncEntry != 0) *(nuint*)pFuncEntry = (nuint)unwindInfo.Value;
}
}
catch (System.Exception ex)
{
Console.WriteLine($"GetStackWalkInfo failed: {ex}");
}
};

int ret = AMD64Unwind(ref context, readCallback, getAllocatedBuffer, getStackWalkInfo);

foreach (IntPtr ptr in allocatedRegions)
{
//Console.WriteLine($"Freeing buffer at {ptr:x16}");
NativeMemory.Free(ptr.ToPointer());
}

return ret;
}
}
6 changes: 0 additions & 6 deletions src/native/managed/cdacreader/src/cdacreader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
<!-- <InstallRuntimeComponentDestination Include="sharedFramework" Condition="'$(RuntimeFlavor)' == 'coreclr'"/> -->
</ItemGroup>

<ItemGroup>
<DirectPInvoke Include="unwinder_cdac" />
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\unwinder_cdac.lib" Condition="'$(TargetsWindows)' == 'true'" />
<NativeLibrary Include="unwinder_cdac_static.a" Condition="'$(TargetsWindows)' != 'true'" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Diagnostics.DataContractReader\Microsoft.Diagnostics.DataContractReader.csproj" />
</ItemGroup>
Expand Down

0 comments on commit 4f1fbee

Please sign in to comment.