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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "snapshot/win/cpu_context_win.h" 15 #include "snapshot/win/cpu_context_win.h"
16 16
17 #include <string.h> 17 #include <string.h>
18 18
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "snapshot/cpu_context.h" 20 #include "snapshot/cpu_context.h"
21 21
22 namespace crashpad { 22 namespace crashpad {
23 23
24 namespace {
25
26 template <class T>
27 void CommonInitializeX86Context(const T& context, CPUContextX86* out) {
28 memset(out, 0, sizeof(*out));
29
30 // 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.
31 // values for ContextFlags are identical.
32
33 if (context.ContextFlags & WOW64_CONTEXT_CONTROL) {
34 out->ebp = context.Ebp;
35 out->eip = context.Eip;
36 out->cs = static_cast<uint16_t>(context.SegCs);
37 out->eflags = context.EFlags;
38 out->esp = context.Esp;
39 out->ss = static_cast<uint16_t>(context.SegSs);
40 }
41
42 if (context.ContextFlags & WOW64_CONTEXT_INTEGER) {
43 out->eax = context.Eax;
44 out->ebx = context.Ebx;
45 out->ecx = context.Ecx;
46 out->edx = context.Edx;
47 out->edi = context.Edi;
48 out->esi = context.Esi;
49 }
50
51 if (context.ContextFlags & WOW64_CONTEXT_SEGMENTS) {
52 out->ds = static_cast<uint16_t>(context.SegDs);
53 out->es = static_cast<uint16_t>(context.SegEs);
54 out->fs = static_cast<uint16_t>(context.SegFs);
55 out->gs = static_cast<uint16_t>(context.SegGs);
56 }
57
58 if (context.ContextFlags & WOW64_CONTEXT_DEBUG_REGISTERS) {
59 out->dr0 = context.Dr0;
60 out->dr1 = context.Dr1;
61 out->dr2 = context.Dr2;
62 out->dr3 = context.Dr3;
63 // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see
64 // https://en.wikipedia.org/wiki/X86_debug_register.
65 out->dr4 = context.Dr6;
66 out->dr5 = context.Dr7;
67 out->dr6 = context.Dr6;
68 out->dr7 = context.Dr7;
69 }
70
71 if (context.ContextFlags & WOW64_CONTEXT_EXTENDED_REGISTERS) {
72 static_assert(sizeof(out->fxsave) == sizeof(context.ExtendedRegisters),
73 "types must be equivalent");
74 memcpy(&out->fxsave, &context.ExtendedRegisters, sizeof(out->fxsave));
75 } else if (context.ContextFlags & WOW64_CONTEXT_FLOATING_POINT) {
76 CHECK(false) << "TODO(scottmg): extract x87 data";
77 }
78 }
79
80 } // namespace
81
24 #if defined(ARCH_CPU_64_BITS) 82 #if defined(ARCH_CPU_64_BITS)
25 83
26 void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) { 84 void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) {
27 CHECK(false) << "TODO(scottmg) InitializeX86Context()"; 85 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.
86 << "non-wow64 context";
87 CommonInitializeX86Context(context, out);
28 } 88 }
29 89
30 void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) { 90 void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) {
31 memset(out, 0, sizeof(*out)); 91 memset(out, 0, sizeof(*out));
32 92
33 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_AMD64)) << "non-x64 context"; 93 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_AMD64)) << "non-x64 context";
34 94
35 if (context.ContextFlags & CONTEXT_CONTROL) { 95 if (context.ContextFlags & CONTEXT_CONTROL) {
36 out->cs = context.SegCs; 96 out->cs = context.SegCs;
37 out->rflags = context.EFlags; 97 out->rflags = context.EFlags;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 if (context.ContextFlags & CONTEXT_FLOATING_POINT) { 141 if (context.ContextFlags & CONTEXT_FLOATING_POINT) {
82 static_assert(sizeof(out->fxsave) == sizeof(context.FltSave), 142 static_assert(sizeof(out->fxsave) == sizeof(context.FltSave),
83 "types must be equivalent"); 143 "types must be equivalent");
84 memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave)); 144 memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave));
85 } 145 }
86 } 146 }
87 147
88 #else // ARCH_CPU_64_BITS 148 #else // ARCH_CPU_64_BITS
89 149
90 void InitializeX86Context(const CONTEXT& context, CPUContextX86* out) { 150 void InitializeX86Context(const CONTEXT& context, CPUContextX86* out) {
91 memset(out, 0, sizeof(*out));
92
93 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_i386)) << "non-x86 context"; 151 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_i386)) << "non-x86 context";
94 152 CommonInitializeX86Context(context, out);
95 if (context.ContextFlags & CONTEXT_CONTROL) {
96 out->ebp = context.Ebp;
97 out->eip = context.Eip;
98 out->cs = static_cast<uint16_t>(context.SegCs);
99 out->eflags = context.EFlags;
100 out->esp = context.Esp;
101 out->ss = static_cast<uint16_t>(context.SegSs);
102 }
103
104 if (context.ContextFlags & CONTEXT_INTEGER) {
105 out->eax = context.Eax;
106 out->ebx = context.Ebx;
107 out->ecx = context.Ecx;
108 out->edx = context.Edx;
109 out->edi = context.Edi;
110 out->esi = context.Esi;
111 }
112
113 if (context.ContextFlags & CONTEXT_SEGMENTS) {
114 out->ds = static_cast<uint16_t>(context.SegDs);
115 out->es = static_cast<uint16_t>(context.SegEs);
116 out->fs = static_cast<uint16_t>(context.SegFs);
117 out->gs = static_cast<uint16_t>(context.SegGs);
118 }
119
120 if (context.ContextFlags & CONTEXT_DEBUG_REGISTERS) {
121 out->dr0 = context.Dr0;
122 out->dr1 = context.Dr1;
123 out->dr2 = context.Dr2;
124 out->dr3 = context.Dr3;
125 // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see
126 // https://en.wikipedia.org/wiki/X86_debug_register.
127 out->dr4 = context.Dr6;
128 out->dr5 = context.Dr7;
129 out->dr6 = context.Dr6;
130 out->dr7 = context.Dr7;
131 }
132
133 if (context.ContextFlags & CONTEXT_EXTENDED_REGISTERS) {
134 static_assert(sizeof(out->fxsave) == sizeof(context.ExtendedRegisters),
135 "types must be equivalent");
136 memcpy(&out->fxsave, &context.ExtendedRegisters, sizeof(out->fxsave));
137 } else if (context.ContextFlags & CONTEXT_FLOATING_POINT) {
138 CHECK(false) << "TODO(scottmg): extract x87 data";
139 }
140 } 153 }
141 154
142 #endif // ARCH_CPU_64_BITS 155 #endif // ARCH_CPU_64_BITS
143 156
144 } // namespace crashpad 157 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698