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

Side by Side Diff: third_party/crashpad/crashpad/snapshot/win/cpu_context_win.cc

Issue 1505213004: Copy Crashpad into the Chrome tree instead of importing it via DEPS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 5 years 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
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "snapshot/win/cpu_context_win.h"
16
17 #include <string.h>
18
19 #include "base/logging.h"
20 #include "snapshot/cpu_context.h"
21
22 namespace crashpad {
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
84 #if defined(ARCH_CPU_64_BITS)
85
86 void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) {
87 CommonInitializeX86Context(context, out);
88 }
89
90 void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) {
91 memset(out, 0, sizeof(*out));
92
93 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_AMD64)) << "non-x64 context";
94
95 if (context.ContextFlags & CONTEXT_CONTROL) {
96 out->cs = context.SegCs;
97 out->rflags = context.EFlags;
98 out->rip = context.Rip;
99 out->rsp = context.Rsp;
100 // SegSs ignored.
101 }
102
103 if (context.ContextFlags & CONTEXT_INTEGER) {
104 out->rax = context.Rax;
105 out->rbx = context.Rbx;
106 out->rcx = context.Rcx;
107 out->rdx = context.Rdx;
108 out->rdi = context.Rdi;
109 out->rsi = context.Rsi;
110 out->rbp = context.Rbp;
111 out->r8 = context.R8;
112 out->r9 = context.R9;
113 out->r10 = context.R10;
114 out->r11 = context.R11;
115 out->r12 = context.R12;
116 out->r13 = context.R13;
117 out->r14 = context.R14;
118 out->r15 = context.R15;
119 }
120
121 if (context.ContextFlags & CONTEXT_SEGMENTS) {
122 out->fs = context.SegFs;
123 out->gs = context.SegGs;
124 // SegDs ignored.
125 // SegEs ignored.
126 }
127
128 if (context.ContextFlags & CONTEXT_DEBUG_REGISTERS) {
129 out->dr0 = context.Dr0;
130 out->dr1 = context.Dr1;
131 out->dr2 = context.Dr2;
132 out->dr3 = context.Dr3;
133 // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see
134 // https://en.wikipedia.org/wiki/X86_debug_register.
135 out->dr4 = context.Dr6;
136 out->dr5 = context.Dr7;
137 out->dr6 = context.Dr6;
138 out->dr7 = context.Dr7;
139 }
140
141 if (context.ContextFlags & CONTEXT_FLOATING_POINT) {
142 static_assert(sizeof(out->fxsave) == sizeof(context.FltSave),
143 "types must be equivalent");
144 memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave));
145 }
146 }
147
148 #else // ARCH_CPU_64_BITS
149
150 void InitializeX86Context(const CONTEXT& context, CPUContextX86* out) {
151 CommonInitializeX86Context(context, out);
152 }
153
154 #endif // ARCH_CPU_64_BITS
155
156 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698