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

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: . 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 <int Control,
Mark Mentovai 2015/09/18 15:44:06 These flags have the same value regardless of whet
scottmg 2015/09/18 19:45:26 Ah, I noticed they were identical, but not that th
27 int Integer,
28 int Segments,
29 int FloatingPoint,
30 int DebugRegisters,
31 int ExtendedRegisters,
32 class T>
33 void CommonInitializeX86Context(const T& context, CPUContextX86* out) {
34 memset(out, 0, sizeof(*out));
35
36 if (context.ContextFlags & Control) {
37 out->ebp = context.Ebp;
38 out->eip = context.Eip;
39 out->cs = static_cast<uint16_t>(context.SegCs);
40 out->eflags = context.EFlags;
41 out->esp = context.Esp;
42 out->ss = static_cast<uint16_t>(context.SegSs);
43 }
44
45 if (context.ContextFlags & Integer) {
46 out->eax = context.Eax;
47 out->ebx = context.Ebx;
48 out->ecx = context.Ecx;
49 out->edx = context.Edx;
50 out->edi = context.Edi;
51 out->esi = context.Esi;
52 }
53
54 if (context.ContextFlags & Segments) {
55 out->ds = static_cast<uint16_t>(context.SegDs);
56 out->es = static_cast<uint16_t>(context.SegEs);
57 out->fs = static_cast<uint16_t>(context.SegFs);
58 out->gs = static_cast<uint16_t>(context.SegGs);
59 }
60
61 if (context.ContextFlags & DebugRegisters) {
62 out->dr0 = context.Dr0;
63 out->dr1 = context.Dr1;
64 out->dr2 = context.Dr2;
65 out->dr3 = context.Dr3;
66 // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see
67 // https://en.wikipedia.org/wiki/X86_debug_register.
68 out->dr4 = context.Dr6;
69 out->dr5 = context.Dr7;
70 out->dr6 = context.Dr6;
71 out->dr7 = context.Dr7;
72 }
73
74 if (context.ContextFlags & ExtendedRegisters) {
75 static_assert(sizeof(out->fxsave) == sizeof(context.ExtendedRegisters),
76 "types must be equivalent");
77 memcpy(&out->fxsave, &context.ExtendedRegisters, sizeof(out->fxsave));
78 } else if (context.ContextFlags & FloatingPoint) {
79 CHECK(false) << "TODO(scottmg): extract x87 data";
80 }
81 }
82
83 } // namespace
84
24 #if defined(ARCH_CPU_64_BITS) 85 #if defined(ARCH_CPU_64_BITS)
25 86
26 void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) { 87 void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) {
27 CHECK(false) << "TODO(scottmg) InitializeX86Context()"; 88 LOG_IF(ERROR, !(context.ContextFlags & WOW64_CONTEXT_i386))
89 << "non-wow64 context";
90 CommonInitializeX86Context<WOW64_CONTEXT_CONTROL,
91 WOW64_CONTEXT_INTEGER,
92 WOW64_CONTEXT_SEGMENTS,
93 WOW64_CONTEXT_FLOATING_POINT,
94 WOW64_CONTEXT_DEBUG_REGISTERS,
95 WOW64_CONTEXT_EXTENDED_REGISTERS>(context, out);
28 } 96 }
29 97
30 void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) { 98 void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) {
31 memset(out, 0, sizeof(*out)); 99 memset(out, 0, sizeof(*out));
32 100
33 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_AMD64)) << "non-x64 context"; 101 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_AMD64)) << "non-x64 context";
34 102
35 if (context.ContextFlags & CONTEXT_CONTROL) { 103 if (context.ContextFlags & CONTEXT_CONTROL) {
36 out->cs = context.SegCs; 104 out->cs = context.SegCs;
37 out->rflags = context.EFlags; 105 out->rflags = context.EFlags;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 if (context.ContextFlags & CONTEXT_FLOATING_POINT) { 149 if (context.ContextFlags & CONTEXT_FLOATING_POINT) {
82 static_assert(sizeof(out->fxsave) == sizeof(context.FltSave), 150 static_assert(sizeof(out->fxsave) == sizeof(context.FltSave),
83 "types must be equivalent"); 151 "types must be equivalent");
84 memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave)); 152 memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave));
85 } 153 }
86 } 154 }
87 155
88 #else // ARCH_CPU_64_BITS 156 #else // ARCH_CPU_64_BITS
89 157
90 void InitializeX86Context(const CONTEXT& context, CPUContextX86* out) { 158 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"; 159 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_i386)) << "non-x86 context";
94 160 CommonInitializeX86Context<CONTEXT_CONTROL,
95 if (context.ContextFlags & CONTEXT_CONTROL) { 161 CONTEXT_INTEGER,
96 out->ebp = context.Ebp; 162 CONTEXT_SEGMENTS,
97 out->eip = context.Eip; 163 CONTEXT_FLOATING_POINT,
98 out->cs = static_cast<uint16_t>(context.SegCs); 164 CONTEXT_DEBUG_REGISTERS,
99 out->eflags = context.EFlags; 165 CONTEXT_EXTENDED_REGISTERS>(context, out);
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 } 166 }
141 167
142 #endif // ARCH_CPU_64_BITS 168 #endif // ARCH_CPU_64_BITS
143 169
144 } // namespace crashpad 170 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698