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

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: mac 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
« no previous file with comments | « snapshot/snapshot_test.gyp ('k') | snapshot/win/crashpad_snapshot_test_crashing_child.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 LOG_IF(ERROR, !(context.ContextFlags & WOW64_CONTEXT_i386))
29 << "non-x86 context";
30 memset(out, 0, sizeof(*out));
31
32 // We assume in this function that the WOW64_CONTEXT_* and x86 CONTEXT_*
33 // values for ContextFlags are identical.
34
35 if (context.ContextFlags & WOW64_CONTEXT_CONTROL) {
36 out->ebp = context.Ebp;
37 out->eip = context.Eip;
38 out->cs = static_cast<uint16_t>(context.SegCs);
39 out->eflags = context.EFlags;
40 out->esp = context.Esp;
41 out->ss = static_cast<uint16_t>(context.SegSs);
42 }
43
44 if (context.ContextFlags & WOW64_CONTEXT_INTEGER) {
45 out->eax = context.Eax;
46 out->ebx = context.Ebx;
47 out->ecx = context.Ecx;
48 out->edx = context.Edx;
49 out->edi = context.Edi;
50 out->esi = context.Esi;
51 }
52
53 if (context.ContextFlags & WOW64_CONTEXT_SEGMENTS) {
54 out->ds = static_cast<uint16_t>(context.SegDs);
55 out->es = static_cast<uint16_t>(context.SegEs);
56 out->fs = static_cast<uint16_t>(context.SegFs);
57 out->gs = static_cast<uint16_t>(context.SegGs);
58 }
59
60 if (context.ContextFlags & WOW64_CONTEXT_DEBUG_REGISTERS) {
61 out->dr0 = context.Dr0;
62 out->dr1 = context.Dr1;
63 out->dr2 = context.Dr2;
64 out->dr3 = context.Dr3;
65 // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see
66 // https://en.wikipedia.org/wiki/X86_debug_register.
67 out->dr4 = context.Dr6;
68 out->dr5 = context.Dr7;
69 out->dr6 = context.Dr6;
70 out->dr7 = context.Dr7;
71 }
72
73 if (context.ContextFlags & WOW64_CONTEXT_EXTENDED_REGISTERS) {
74 static_assert(sizeof(out->fxsave) == sizeof(context.ExtendedRegisters),
75 "types must be equivalent");
76 memcpy(&out->fxsave, &context.ExtendedRegisters, sizeof(out->fxsave));
77 } else if (context.ContextFlags & WOW64_CONTEXT_FLOATING_POINT) {
78 CHECK(false) << "TODO(scottmg): extract x87 data";
79 }
80 }
81
82 } // namespace
83
24 #if defined(ARCH_CPU_64_BITS) 84 #if defined(ARCH_CPU_64_BITS)
25 85
26 void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) { 86 void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) {
27 CHECK(false) << "TODO(scottmg) InitializeX86Context()"; 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)); 151 CommonInitializeX86Context(context, out);
92
93 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_i386)) << "non-x86 context";
94
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 } 152 }
141 153
142 #endif // ARCH_CPU_64_BITS 154 #endif // ARCH_CPU_64_BITS
143 155
144 } // namespace crashpad 156 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/snapshot_test.gyp ('k') | snapshot/win/crashpad_snapshot_test_crashing_child.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698