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

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

Issue 1336823002: win x86: Grab bag of restructuring to get tests working on x86-on-x86 (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fixes2 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 | « no previous file | snapshot/win/cpu_context_win_test.cc » ('j') | snapshot/win/process_reader_win.cc » ('J')
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,
(...skipping 10 matching lines...) Expand all
21 21
22 namespace crashpad { 22 namespace crashpad {
23 23
24 #if defined(ARCH_CPU_64_BITS) 24 #if defined(ARCH_CPU_64_BITS)
25 25
26 void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) { 26 void InitializeX86Context(const WOW64_CONTEXT& context, CPUContextX86* out) {
27 CHECK(false) << "TODO(scottmg) InitializeX86Context()"; 27 CHECK(false) << "TODO(scottmg) InitializeX86Context()";
28 } 28 }
29 29
30 void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) { 30 void InitializeX64Context(const CONTEXT& context, CPUContextX86_64* out) {
31 out->rax = context.Rax; 31 memset(out, 0, sizeof(*out));
32 out->rbx = context.Rbx;
33 out->rcx = context.Rcx;
34 out->rdx = context.Rdx;
35 out->rdi = context.Rdi;
36 out->rsi = context.Rsi;
37 out->rbp = context.Rbp;
38 out->rsp = context.Rsp;
39 out->r8 = context.R8;
40 out->r9 = context.R9;
41 out->r10 = context.R10;
42 out->r11 = context.R11;
43 out->r12 = context.R12;
44 out->r13 = context.R13;
45 out->r14 = context.R14;
46 out->r15 = context.R15;
47 out->rip = context.Rip;
48 out->rflags = context.EFlags;
49 out->cs = context.SegCs;
50 out->fs = context.SegFs;
51 out->gs = context.SegGs;
52 32
53 out->dr0 = context.Dr0; 33 LOG_IF(ERROR, !(context.ContextFlags & CONTEXT_AMD64)) << "non-x64 context";
54 out->dr1 = context.Dr1;
55 out->dr2 = context.Dr2;
56 out->dr3 = context.Dr3;
57 // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see
58 // http://en.wikipedia.org/wiki/X86_debug_register.
59 out->dr4 = context.Dr6;
60 out->dr5 = context.Dr7;
61 out->dr6 = context.Dr6;
62 out->dr7 = context.Dr7;
63 34
64 static_assert(sizeof(out->fxsave) == sizeof(context.FltSave), 35 if (context.ContextFlags & CONTEXT_CONTROL) {
65 "types must be equivalent"); 36 out->cs = context.SegCs;
66 memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave)); 37 out->rflags = context.EFlags;
38 out->rip = context.Rip;
39 out->rsp = context.Rsp;
40 // SegSs ignored.
41 }
42
43 if (context.ContextFlags & CONTEXT_INTEGER) {
44 out->rax = context.Rax;
45 out->rbx = context.Rbx;
46 out->rcx = context.Rcx;
47 out->rdx = context.Rdx;
48 out->rdi = context.Rdi;
49 out->rsi = context.Rsi;
50 out->rbp = context.Rbp;
51 out->r8 = context.R8;
52 out->r9 = context.R9;
53 out->r10 = context.R10;
54 out->r11 = context.R11;
55 out->r12 = context.R12;
56 out->r13 = context.R13;
57 out->r14 = context.R14;
58 out->r15 = context.R15;
59 }
60
61 if (context.ContextFlags & CONTEXT_SEGMENTS) {
62 out->fs = context.SegFs;
63 out->gs = context.SegGs;
64 // SegDs ignored.
Mark Mentovai 2015/09/16 20:52:58 Here’s a question that’s got nothing to do with th
65 // SegEs ignored.
66 }
67
68 if (context.ContextFlags & CONTEXT_DEBUG_REGISTERS) {
69 out->dr0 = context.Dr0;
70 out->dr1 = context.Dr1;
71 out->dr2 = context.Dr2;
72 out->dr3 = context.Dr3;
73 // DR4 and DR5 are obsolete synonyms for DR6 and DR7, see
74 // https://en.wikipedia.org/wiki/X86_debug_register.
75 out->dr4 = context.Dr6;
76 out->dr5 = context.Dr7;
77 out->dr6 = context.Dr6;
78 out->dr7 = context.Dr7;
79 }
80
81 if (context.ContextFlags & CONTEXT_FLOATING_POINT) {
82 static_assert(sizeof(out->fxsave) == sizeof(context.FltSave),
83 "types must be equivalent");
84 memcpy(&out->fxsave, &context.FltSave.ControlWord, sizeof(out->fxsave));
85 }
67 } 86 }
68 87
69 #else // ARCH_CPU_64_BITS 88 #else // ARCH_CPU_64_BITS
70 89
71 void InitializeX86Context(const CONTEXT& context, CPUContextX86* out) { 90 void InitializeX86Context(const CONTEXT& context, CPUContextX86* out) {
72 CHECK(false) << "TODO(scottmg) InitializeX86Context()"; 91 memset(out, 0, sizeof(*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 }
73 } 140 }
74 141
75 #endif // ARCH_CPU_64_BITS 142 #endif // ARCH_CPU_64_BITS
76 143
77 } // namespace crashpad 144 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | snapshot/win/cpu_context_win_test.cc » ('j') | snapshot/win/process_reader_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698