Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: snapshot/win/cpu_context_win.cc

Issue 1349313003: win: support x64 reading x86 (wow64) (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fixes Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7d0582415925a1ca131aeb073b94f2e1762b2e48 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) {
+ memset(out, 0, sizeof(*out));
+
+ // We assume in this function that the WOW64_CONTEXT_* and x64 CONTEXT_*
Mark Mentovai 2015/09/18 22:10:50 x86, not x64
scottmg 2015/09/18 22:25:00 Oops, done.
+ // 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()";
+ LOG_IF(ERROR, !(context.ContextFlags & WOW64_CONTEXT_i386))
Mark Mentovai 2015/09/18 22:10:50 You can move this LOG into the common function too
scottmg 2015/09/18 22:25:00 Done.
+ << "non-wow64 context";
+ CommonInitializeX86Context(context, out);
}
void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) {
@@ -88,55 +148,8 @@ 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

Powered by Google App Engine
This is Rietveld 408576698