CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
143 lines
4.6 KiB
C++
143 lines
4.6 KiB
C++
//===-- sanitizer_unwind_win.cpp ------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
/// Sanitizer unwind Windows specific functions.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "sanitizer_platform.h"
|
|
#if SANITIZER_WINDOWS
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#define NOGDI
|
|
#include <windows.h>
|
|
|
|
#include "sanitizer_dbghelp.h" // for StackWalk64
|
|
#include "sanitizer_stacktrace.h"
|
|
#include "sanitizer_symbolizer.h" // for InitializeDbgHelpIfNeeded
|
|
|
|
using namespace __sanitizer;
|
|
|
|
#if !SANITIZER_GO
|
|
void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
|
|
CHECK_GE(max_depth, 2);
|
|
// FIXME: CaptureStackBackTrace might be too slow for us.
|
|
// FIXME: Compare with StackWalk64.
|
|
// FIXME: Look at LLVMUnhandledExceptionFilter in Signals.inc
|
|
size = CaptureStackBackTrace(1, Min(max_depth, kStackTraceMax),
|
|
(void **)&trace_buffer[0], 0);
|
|
if (size == 0)
|
|
return;
|
|
|
|
// Skip the RTL frames by searching for the PC in the stacktrace.
|
|
uptr pc_location = LocatePcInTrace(pc);
|
|
PopStackFrames(pc_location);
|
|
|
|
// Replace the first frame with the PC because the frame in the
|
|
// stacktrace might be incorrect.
|
|
trace_buffer[0] = pc;
|
|
}
|
|
|
|
PVOID CALLBACK FallbackFunctionTableAccess(HANDLE hProcess,
|
|
DWORD64 dwAddrBase) {
|
|
// First try DbgHelp's function.
|
|
if (PVOID pResult =
|
|
__sanitizer::SymFunctionTableAccess64(hProcess, dwAddrBase)) {
|
|
return pResult;
|
|
}
|
|
|
|
// Fall back to RtlLookupFunctionEntry for dynamic code.
|
|
// Function registered with RtlAddFunctionTable is not necessarily registered
|
|
// with DbgHelp, so this is required to cover some edge cases (e.g. JIT
|
|
// compilers can use Rtl* functions).
|
|
# if SANITIZER_WINDOWS64
|
|
DWORD64 dw64ImageBase = 0;
|
|
return RtlLookupFunctionEntry(dwAddrBase, &dw64ImageBase, nullptr);
|
|
# else
|
|
return nullptr;
|
|
# endif
|
|
}
|
|
|
|
DWORD64 CALLBACK FallbackGetModuleBase(HANDLE hProcess, DWORD64 dwAddr) {
|
|
if (DWORD64 dwResult = __sanitizer::SymGetModuleBase64(hProcess, dwAddr)) {
|
|
return dwResult;
|
|
}
|
|
|
|
// Both GetModuleBase and FunctionTableAccess must provide this fallback,
|
|
// otherwise dynamic functions won't be properly unwound.
|
|
# if SANITIZER_WINDOWS64
|
|
DWORD64 dw64ImageBase = 0;
|
|
if (RtlLookupFunctionEntry(dwAddr, &dw64ImageBase, nullptr)) {
|
|
return dw64ImageBase;
|
|
}
|
|
# endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
# ifdef __clang__
|
|
# pragma clang diagnostic push
|
|
# pragma clang diagnostic ignored "-Wframe-larger-than="
|
|
# endif
|
|
void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
|
|
CHECK(context);
|
|
CHECK_GE(max_depth, 2);
|
|
CONTEXT ctx = *(CONTEXT *)context;
|
|
STACKFRAME64 stack_frame;
|
|
memset(&stack_frame, 0, sizeof(stack_frame));
|
|
|
|
InitializeDbgHelpIfNeeded();
|
|
|
|
size = 0;
|
|
# if SANITIZER_WINDOWS64
|
|
# if SANITIZER_ARM64
|
|
int machine_type = IMAGE_FILE_MACHINE_ARM64;
|
|
stack_frame.AddrPC.Offset = ctx.Pc;
|
|
stack_frame.AddrFrame.Offset = ctx.Fp;
|
|
stack_frame.AddrStack.Offset = ctx.Sp;
|
|
# else
|
|
int machine_type = IMAGE_FILE_MACHINE_AMD64;
|
|
stack_frame.AddrPC.Offset = ctx.Rip;
|
|
stack_frame.AddrFrame.Offset = ctx.Rbp;
|
|
stack_frame.AddrStack.Offset = ctx.Rsp;
|
|
# endif
|
|
# else
|
|
# if SANITIZER_ARM
|
|
int machine_type = IMAGE_FILE_MACHINE_ARM;
|
|
stack_frame.AddrPC.Offset = ctx.Pc;
|
|
stack_frame.AddrFrame.Offset = ctx.R11;
|
|
stack_frame.AddrStack.Offset = ctx.Sp;
|
|
# elif SANITIZER_MIPS32
|
|
int machine_type = IMAGE_FILE_MACHINE_R4000;
|
|
stack_frame.AddrPC.Offset = ctx.Fir;
|
|
stack_frame.AddrFrame.Offset = ctx.IntS8;
|
|
stack_frame.AddrStack.Offset = ctx.IntSp;
|
|
# else
|
|
int machine_type = IMAGE_FILE_MACHINE_I386;
|
|
stack_frame.AddrPC.Offset = ctx.Eip;
|
|
stack_frame.AddrFrame.Offset = ctx.Ebp;
|
|
stack_frame.AddrStack.Offset = ctx.Esp;
|
|
# endif
|
|
# endif
|
|
stack_frame.AddrPC.Mode = AddrModeFlat;
|
|
stack_frame.AddrFrame.Mode = AddrModeFlat;
|
|
stack_frame.AddrStack.Mode = AddrModeFlat;
|
|
while (StackWalk64(machine_type, GetCurrentProcess(), GetCurrentThread(),
|
|
&stack_frame, &ctx, NULL, FallbackFunctionTableAccess,
|
|
FallbackGetModuleBase, NULL) &&
|
|
size < Min(max_depth, kStackTraceMax)) {
|
|
trace_buffer[size++] = (uptr)stack_frame.AddrPC.Offset;
|
|
}
|
|
}
|
|
# ifdef __clang__
|
|
# pragma clang diagnostic pop
|
|
# endif
|
|
# endif // #if !SANITIZER_GO
|
|
|
|
#endif // SANITIZER_WINDOWS
|