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

Side by Side Diff: runtime/vm/code_patcher_x64.cc

Issue 131853006: Fix debugger stub patching on x64 architecture (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/code_patcher_mips.cc ('k') | runtime/vm/debugger.h » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64.
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/code_patcher.h" 9 #include "vm/code_patcher.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // No need to flush the instruction cache, since the code is not modified. 135 // No need to flush the instruction cache, since the code is not modified.
136 } 136 }
137 137
138 private: 138 private:
139 uword start_; 139 uword start_;
140 const Array& object_pool_; 140 const Array& object_pool_;
141 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); 141 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall);
142 }; 142 };
143 143
144 144
145 // The expected pattern of a call where the target is loaded from
146 // the object pool:
147 // 00: 4d 8b 9f imm32 mov R11, [PP + off]
148 // 07: 41 ff d3 call R11
149 // 10 <- return address
150 class PoolPointerCall : public ValueObject {
151 public:
152 explicit PoolPointerCall(uword return_address)
153 : start_(return_address - kCallPatternSize) {
154 ASSERT(IsValid(return_address));
155 }
156
157 static bool IsValid(uword return_address) {
158 uint8_t* code_bytes =
159 reinterpret_cast<uint8_t*>(return_address - kCallPatternSize);
160 return (code_bytes[0] == 0x4D) && (code_bytes[1] == 0x8B) &&
161 (code_bytes[2] == 0x9F) &&
162 (code_bytes[7] == 0x41) && (code_bytes[8] == 0xFF) &&
163 (code_bytes[9] == 0xD3);
164 }
165
166 int32_t pp_offset() const {
167 return *reinterpret_cast<int32_t*>(start_ + 3);
168 }
169
170 void set_pp_offset(int32_t offset) const {
171 *reinterpret_cast<int32_t*>(start_ + 3) = offset;
172 CPU::FlushICache(start_, kCallPatternSize);
173 }
174
175 private:
176 static const int kCallPatternSize = 7 + 3;
177 uword start_;
178 DISALLOW_IMPLICIT_CONSTRUCTORS(PoolPointerCall);
179 };
180
181
145 // The expected code pattern of a Dart closure call: 182 // The expected code pattern of a Dart closure call:
146 // 00: 49 ba imm64 mov R10, immediate 2 ; 10 bytes 183 // 00: 49 ba imm64 mov R10, immediate 2 ; 10 bytes
147 // 10: 4d 8b 9f imm32 mov R11, [PP + off] 184 // 10: 4d 8b 9f imm32 mov R11, [PP + off]
148 // 17: 41 ff d3 call R11 ; 3 bytes 185 // 17: 41 ff d3 call R11 ; 3 bytes
149 // 20: <- return_address 186 // 20: <- return_address
150 class ClosureCall : public ValueObject { 187 class ClosureCall : public ValueObject {
151 public: 188 public:
152 explicit ClosureCall(uword return_address) 189 explicit ClosureCall(uword return_address)
153 : start_(return_address - kCallPatternSize) { 190 : start_(return_address - kCallPatternSize) {
154 ASSERT(IsValid(return_address)); 191 ASSERT(IsValid(return_address));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 230
194 void CodePatcher::PatchStaticCallAt(uword return_address, 231 void CodePatcher::PatchStaticCallAt(uword return_address,
195 const Code& code, 232 const Code& code,
196 uword new_target) { 233 uword new_target) {
197 ASSERT(code.ContainsInstructionAt(return_address)); 234 ASSERT(code.ContainsInstructionAt(return_address));
198 StaticCall call(return_address, code); 235 StaticCall call(return_address, code);
199 call.set_target(new_target); 236 call.set_target(new_target);
200 } 237 }
201 238
202 239
240 int32_t CodePatcher::GetPoolOffsetAt(uword return_address) {
241 PoolPointerCall call(return_address);
242 return call.pp_offset();
243 }
244
245
246 void CodePatcher::SetPoolOffsetAt(uword return_address, int32_t offset) {
247 PoolPointerCall call(return_address);
248 call.set_pp_offset(offset);
249 }
250
251
203 void CodePatcher::PatchInstanceCallAt(uword return_address, 252 void CodePatcher::PatchInstanceCallAt(uword return_address,
204 const Code& code, 253 const Code& code,
205 uword new_target) { 254 uword new_target) {
206 ASSERT(code.ContainsInstructionAt(return_address)); 255 ASSERT(code.ContainsInstructionAt(return_address));
207 InstanceCall call(return_address, code); 256 InstanceCall call(return_address, code);
208 call.set_target(new_target); 257 call.set_target(new_target);
209 } 258 }
210 259
211 260
212 uword CodePatcher::GetInstanceCallAt(uword return_address, 261 uword CodePatcher::GetInstanceCallAt(uword return_address,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 329
281 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) { 330 RawObject* CodePatcher::GetEdgeCounterAt(uword pc, const Code& code) {
282 ASSERT(code.ContainsInstructionAt(pc)); 331 ASSERT(code.ContainsInstructionAt(pc));
283 EdgeCounter counter(pc, code); 332 EdgeCounter counter(pc, code);
284 return counter.edge_counter(); 333 return counter.edge_counter();
285 } 334 }
286 335
287 } // namespace dart 336 } // namespace dart
288 337
289 #endif // defined TARGET_ARCH_X64 338 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/code_patcher_mips.cc ('k') | runtime/vm/debugger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698