Index: snapshot/win/cpu_context_win.cc |
diff --git a/snapshot/win/cpu_context_win.cc b/snapshot/win/cpu_context_win.cc |
index b2389ce9e9fe55ca6059df321f354a59cbd3ec0b..d4ce66daea53325609fd096246fe0b8daa205719 100644 |
--- a/snapshot/win/cpu_context_win.cc |
+++ b/snapshot/win/cpu_context_win.cc |
@@ -21,10 +21,70 @@ |
namespace crashpad { |
+namespace { |
+ |
+template <class T> |
+void CommonInitializeX86Context(const T& context, CPUContextX86* out) { |
+ LOG_IF(ERROR, !(context.ContextFlags & WOW64_CONTEXT_i386)) |
+ << "non-x86 context"; |
+ memset(out, 0, sizeof(*out)); |
+ |
+ // We assume in this function that the WOW64_CONTEXT_* and x86 CONTEXT_* |
+ // values for ContextFlags are identical. |
+ |
+ if (context.ContextFlags & WOW64_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 & WOW64_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 & WOW64_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 & WOW64_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 & WOW64_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 & WOW64_CONTEXT_FLOATING_POINT) { |
+ CHECK(false) << "TODO(scottmg): extract x87 data"; |
+ } |
+} |
+ |
+} // namespace |
+ |
#if defined(ARCH_CPU_64_BITS) |
void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) { |
- CHECK(false) << "TODO(scottmg) InitializeX86Context()"; |
+ CommonInitializeX86Context(context, out); |
} |
void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) { |
@@ -88,55 +148,7 @@ void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) { |
#else // ARCH_CPU_64_BITS |
void InitializeX86Context(const CONTEXT& context, CPUContextX86* out) { |
- 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"; |
- } |
+ CommonInitializeX86Context(context, out); |
} |
#endif // ARCH_CPU_64_BITS |