Skip to content

Commit

Permalink
linux, x86/x64: set fpregs to nullptr in CaptureContext()
Browse files Browse the repository at this point in the history
uc_mcontext.fpregs is a pointer to the floating point context, but
CaptureContext() doesn't yet capture floating point context.

This error manages to slip by unit tests when run all together, but
fails when CrashpadClient.SimulateCrash is run by itself.

Bug: crashpad:30
Change-Id: I7adc30648642912d66a7ba8cf9973c9bc0fbd8bc
Reviewed-on: https://chromium-review.googlesource.com/1011504
Reviewed-by: Scott Graham <[email protected]>
Commit-Queue: Joshua Peraza <[email protected]>
  • Loading branch information
Joshua Peraza authored and Commit Bot committed Apr 12, 2018
1 parent 091308b commit dd4ba4c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
9 changes: 1 addition & 8 deletions client/crashpad_client_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,12 @@ bool CrashpadClient::StartHandlerForClient(
void CrashpadClient::DumpWithoutCrash(NativeCPUContext* context) {
DCHECK(g_crash_handler);

#if defined(ARCH_CPU_X86)
memset(&context->__fpregs_mem, 0, sizeof(context->__fpregs_mem));
context->__fpregs_mem.status = 0xffff0000;
#elif defined(ARCH_CPU_X86_64)
memset(&context->__fpregs_mem, 0, sizeof(context->__fpregs_mem));
#elif defined(ARCH_CPU_ARMEL)
#if defined(ARCH_CPU_ARMEL)
memset(context->uc_regspace, 0, sizeof(context->uc_regspace));
#elif defined(ARCH_CPU_ARM64)
memset(context->uc_mcontext.__reserved,
0,
sizeof(context->uc_mcontext.__reserved));
#else
#error Port.
#endif

siginfo_t siginfo;
Expand Down
7 changes: 5 additions & 2 deletions util/misc/capture_context_linux.S
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ CAPTURECONTEXT_SYMBOL2:
movl %ecx, 0x5c(%eax) // context->uc_mcontext.xss

// TODO(jperaza): save floating-point registers.
xorl %ecx, %ecx
movl %ecx, 0x60(%eax) // context->uc_mcontext.fpregs

// Clean up by restoring clobbered registers, even those considered volatile
// by the ABI, so that the captured context represents the state at this
Expand Down Expand Up @@ -224,14 +226,15 @@ CAPTURECONTEXT_SYMBOL2:
movq %r8, 0xd0(%rdi) // context->uc_mcontext.oldmask
movq %r8, 0xd8(%rdi) // context->uc_mcontext.cr2

// TODO(jperaza): save floating-point registers.
movq %r8, 0xe0(%rdi) // context->uc_mcontext.fpregs

// Clean up by restoring clobbered registers, even those considered volatile
// by the ABI, so that the captured context represents the state at this
// function’s exit.
movq 0x90(%rdi), %rax
movq 0x28(%rdi), %r8

// TODO(jperaza): save floating-point registers.

popfq

popq %rbp
Expand Down
5 changes: 4 additions & 1 deletion util/misc/capture_context_test_util_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ namespace test {

void SanityCheckContext(const NativeCPUContext& context) {
#if defined(ARCH_CPU_X86)
// Nothing to do here yet.
// TODO(jperaza): fpregs is nullptr until CaptureContext() supports capturing
// floating point context.
EXPECT_EQ(context.uc_mcontext.fpregs, nullptr);
#elif defined(ARCH_CPU_X86_64)
EXPECT_EQ(context.uc_mcontext.gregs[REG_RDI],
FromPointerCast<intptr_t>(&context));
EXPECT_EQ(context.uc_mcontext.fpregs, nullptr);
#elif defined(ARCH_CPU_ARMEL)
EXPECT_EQ(context.uc_mcontext.arm_r0, FromPointerCast<uintptr_t>(&context));
#elif defined(ARCH_CPU_ARM64)
Expand Down

0 comments on commit dd4ba4c

Please sign in to comment.