Index: snapshot/win/cpu_context_win.cc |
diff --git a/snapshot/win/cpu_context_win.cc b/snapshot/win/cpu_context_win.cc |
index a77ea24798a1d24cbb90af836a74e96d45c46c74..b2389ce9e9fe55ca6059df321f354a59cbd3ec0b 100644 |
--- a/snapshot/win/cpu_context_win.cc |
+++ b/snapshot/win/cpu_context_win.cc |
@@ -28,48 +28,115 @@ void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) { |
} |
void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) { |
- out->rax = context.Rax; |
- out->rbx = context.Rbx; |
- out->rcx = context.Rcx; |
- out->rdx = context.Rdx; |
- out->rdi = context.Rdi; |
- out->rsi = context.Rsi; |
- out->rbp = context.Rbp; |
- out->rsp = context.Rsp; |
- out->r8 = context.R8; |
- out->r9 = context.R9; |
- out->r10 = context.R10; |
- out->r11 = context.R11; |
- out->r12 = context.R12; |
- out->r13 = context.R13; |
- out->r14 = context.R14; |
- out->r15 = context.R15; |
- out->rip = context.Rip; |
- out->rflags = context.EFlags; |
- out->cs = context.SegCs; |
- out->fs = context.SegFs; |
- out->gs = context.SegGs; |
- |
- out->dr0 = context.Dr0; |
- out->dr1 = context.Dr1; |
- out->dr2 = context.Dr2; |
- out->dr3 = context.Dr3; |
- // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see |
- // http://en.wikipedia.org/wiki/X86_debug_register. |
- out->dr4 = context.Dr6; |
- out->dr5 = context.Dr7; |
- out->dr6 = context.Dr6; |
- out->dr7 = context.Dr7; |
- |
- static_assert(sizeof(out->fxsave) == sizeof(context.FltSave), |
- "types must be equivalent"); |
- memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave)); |
+ memset(out, 0, sizeof(*out)); |
+ |
+ LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_AMD64)) << "non-x64 context"; |
+ |
+ if (context.ContextFlags & CONTEXT_CONTROL) { |
+ out->cs = context.SegCs; |
+ out->rflags = context.EFlags; |
+ out->rip = context.Rip; |
+ out->rsp = context.Rsp; |
+ // SegSs ignored. |
+ } |
+ |
+ if (context.ContextFlags & CONTEXT_INTEGER) { |
+ out->rax = context.Rax; |
+ out->rbx = context.Rbx; |
+ out->rcx = context.Rcx; |
+ out->rdx = context.Rdx; |
+ out->rdi = context.Rdi; |
+ out->rsi = context.Rsi; |
+ out->rbp = context.Rbp; |
+ out->r8 = context.R8; |
+ out->r9 = context.R9; |
+ out->r10 = context.R10; |
+ out->r11 = context.R11; |
+ out->r12 = context.R12; |
+ out->r13 = context.R13; |
+ out->r14 = context.R14; |
+ out->r15 = context.R15; |
+ } |
+ |
+ if (context.ContextFlags & CONTEXT_SEGMENTS) { |
+ out->fs = context.SegFs; |
+ out->gs = context.SegGs; |
+ // SegDs ignored. |
Mark Mentovai
2015/09/16 20:52:58
Here’s a question that’s got nothing to do with th
|
+ // SegEs ignored. |
+ } |
+ |
+ if (context.ContextFlags & CONTEXT_DEBUG_REGISTERS) { |
+ out->dr0 = context.Dr0; |
+ out->dr1 = context.Dr1; |
+ out->dr2 = context.Dr2; |
+ out->dr3 = context.Dr3; |
+ // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see |
+ // https://en.wikipedia.org/wiki/X86_debug_register. |
+ out->dr4 = context.Dr6; |
+ out->dr5 = context.Dr7; |
+ out->dr6 = context.Dr6; |
+ out->dr7 = context.Dr7; |
+ } |
+ |
+ if (context.ContextFlags & CONTEXT_FLOATING_POINT) { |
+ static_assert(sizeof(out->fxsave) == sizeof(context.FltSave), |
+ "types must be equivalent"); |
+ memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave)); |
+ } |
} |
#else // ARCH_CPU_64_BITS |
void InitializeX86Context(const CONTEXT& context, CPUContextX86* out) { |
- CHECK(false) << "TODO(scottmg) InitializeX86Context()"; |
+ memset(out, 0, sizeof(*out)); |
+ |
+ LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_i386)) << "non-x86 context"; |
+ |
+ if (context.ContextFlags & CONTEXT_CONTROL) { |
+ out->ebp = context.Ebp; |
+ out->eip = context.Eip; |
+ out->cs = static_cast<uint16_t>(context.SegCs); |
+ out->eflags = context.EFlags; |
+ out->esp = context.Esp; |
+ out->ss = static_cast<uint16_t>(context.SegSs); |
+ } |
+ |
+ if (context.ContextFlags & CONTEXT_INTEGER) { |
+ out->eax = context.Eax; |
+ out->ebx = context.Ebx; |
+ out->ecx = context.Ecx; |
+ out->edx = context.Edx; |
+ out->edi = context.Edi; |
+ out->esi = context.Esi; |
+ } |
+ |
+ if (context.ContextFlags & CONTEXT_SEGMENTS) { |
+ out->ds = static_cast<uint16_t>(context.SegDs); |
+ out->es = static_cast<uint16_t>(context.SegEs); |
+ out->fs = static_cast<uint16_t>(context.SegFs); |
+ out->gs = static_cast<uint16_t>(context.SegGs); |
+ } |
+ |
+ if (context.ContextFlags & CONTEXT_DEBUG_REGISTERS) { |
+ out->dr0 = context.Dr0; |
+ out->dr1 = context.Dr1; |
+ out->dr2 = context.Dr2; |
+ out->dr3 = context.Dr3; |
+ // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see |
+ // https://en.wikipedia.org/wiki/X86_debug_register. |
+ out->dr4 = context.Dr6; |
+ out->dr5 = context.Dr7; |
+ out->dr6 = context.Dr6; |
+ out->dr7 = context.Dr7; |
+ } |
+ |
+ if (context.ContextFlags & CONTEXT_EXTENDED_REGISTERS) { |
+ static_assert(sizeof(out->fxsave) == sizeof(context.ExtendedRegisters), |
+ "types must be equivalent"); |
+ memcpy(&out->fxsave, &context.ExtendedRegisters, sizeof(out->fxsave)); |
+ } else if (context.ContextFlags & CONTEXT_FLOATING_POINT) { |
+ CHECK(false) << "TODO(scottmg): extract x87 data"; |
+ } |
} |
#endif // ARCH_CPU_64_BITS |