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

Side by Side Diff: snapshot/cpu_context_mac_test.cc

Issue 628403002: Fix collision between 49c03db12965 and 56503fef865d (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 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/cpu_context_mac.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 { 232 {
233 CPUContextX86_64 cpu_context_x86_64 = {}; 233 CPUContextX86_64 cpu_context_x86_64 = {};
234 internal::InitializeCPUContextX86_64(&cpu_context_x86_64, 234 internal::InitializeCPUContextX86_64(&cpu_context_x86_64,
235 THREAD_STATE_NONE, 235 THREAD_STATE_NONE,
236 NULL, 236 NULL,
237 0, 237 0,
238 &x86_thread_state64, 238 &x86_thread_state64,
239 &x86_float_state64, 239 &x86_float_state64,
240 &x86_debug_state64); 240 &x86_debug_state64);
241 EXPECT_EQ(10u, cpu_context_x86_64.rax); 241 EXPECT_EQ(10u, cpu_context_x86_64.rax);
242 EXPECT_EQ(11u, cpu_context_x86_64.fxsave64.ftw); 242 EXPECT_EQ(11u, cpu_context_x86_64.fxsave.ftw);
243 EXPECT_EQ(12u, cpu_context_x86_64.dr0); 243 EXPECT_EQ(12u, cpu_context_x86_64.dr0);
244 } 244 }
245 245
246 // Supply context in a CPU-specific “flavor” parameter expected to be used 246 // Supply context in a CPU-specific “flavor” parameter expected to be used
247 // instead of the supplied thread, float, or debug state parameters. Do this 247 // instead of the supplied thread, float, or debug state parameters. Do this
248 // once for each of the three valid flavors. This simulates how 248 // once for each of the three valid flavors. This simulates how
249 // InitializeCPUContextX86_64() might be used to initialize the context in an 249 // InitializeCPUContextX86_64() might be used to initialize the context in an
250 // exception handler, where the exception handler may have received the 250 // exception handler, where the exception handler may have received the
251 // “flavor” parameter and this context should be used to initialize the 251 // “flavor” parameter and this context should be used to initialize the
252 // CPUContextX86_64. 252 // CPUContextX86_64.
253 253
254 { 254 {
255 x86_thread_state64_t alt_x86_thread_state64 = {}; 255 x86_thread_state64_t alt_x86_thread_state64 = {};
256 alt_x86_thread_state64.__rax = 13; 256 alt_x86_thread_state64.__rax = 13;
257 257
258 CPUContextX86_64 cpu_context_x86_64 = {}; 258 CPUContextX86_64 cpu_context_x86_64 = {};
259 internal::InitializeCPUContextX86_64( 259 internal::InitializeCPUContextX86_64(
260 &cpu_context_x86_64, 260 &cpu_context_x86_64,
261 x86_THREAD_STATE64, 261 x86_THREAD_STATE64,
262 reinterpret_cast<natural_t*>(&alt_x86_thread_state64), 262 reinterpret_cast<natural_t*>(&alt_x86_thread_state64),
263 x86_THREAD_STATE64_COUNT, 263 x86_THREAD_STATE64_COUNT,
264 &x86_thread_state64, 264 &x86_thread_state64,
265 &x86_float_state64, 265 &x86_float_state64,
266 &x86_debug_state64); 266 &x86_debug_state64);
267 EXPECT_EQ(13u, cpu_context_x86_64.rax); 267 EXPECT_EQ(13u, cpu_context_x86_64.rax);
268 EXPECT_EQ(11u, cpu_context_x86_64.fxsave64.ftw); 268 EXPECT_EQ(11u, cpu_context_x86_64.fxsave.ftw);
269 EXPECT_EQ(12u, cpu_context_x86_64.dr0); 269 EXPECT_EQ(12u, cpu_context_x86_64.dr0);
270 } 270 }
271 271
272 { 272 {
273 x86_float_state64_t alt_x86_float_state64 = {}; 273 x86_float_state64_t alt_x86_float_state64 = {};
274 alt_x86_float_state64.__fpu_ftw = 14; 274 alt_x86_float_state64.__fpu_ftw = 14;
275 275
276 CPUContextX86_64 cpu_context_x86_64 = {}; 276 CPUContextX86_64 cpu_context_x86_64 = {};
277 internal::InitializeCPUContextX86_64( 277 internal::InitializeCPUContextX86_64(
278 &cpu_context_x86_64, 278 &cpu_context_x86_64,
279 x86_FLOAT_STATE64, 279 x86_FLOAT_STATE64,
280 reinterpret_cast<natural_t*>(&alt_x86_float_state64), 280 reinterpret_cast<natural_t*>(&alt_x86_float_state64),
281 x86_FLOAT_STATE64_COUNT, 281 x86_FLOAT_STATE64_COUNT,
282 &x86_thread_state64, 282 &x86_thread_state64,
283 &x86_float_state64, 283 &x86_float_state64,
284 &x86_debug_state64); 284 &x86_debug_state64);
285 EXPECT_EQ(10u, cpu_context_x86_64.rax); 285 EXPECT_EQ(10u, cpu_context_x86_64.rax);
286 EXPECT_EQ(14u, cpu_context_x86_64.fxsave64.ftw); 286 EXPECT_EQ(14u, cpu_context_x86_64.fxsave.ftw);
287 EXPECT_EQ(12u, cpu_context_x86_64.dr0); 287 EXPECT_EQ(12u, cpu_context_x86_64.dr0);
288 } 288 }
289 289
290 { 290 {
291 x86_debug_state64_t alt_x86_debug_state64 = {}; 291 x86_debug_state64_t alt_x86_debug_state64 = {};
292 alt_x86_debug_state64.__dr0 = 15; 292 alt_x86_debug_state64.__dr0 = 15;
293 293
294 CPUContextX86_64 cpu_context_x86_64 = {}; 294 CPUContextX86_64 cpu_context_x86_64 = {};
295 internal::InitializeCPUContextX86_64( 295 internal::InitializeCPUContextX86_64(
296 &cpu_context_x86_64, 296 &cpu_context_x86_64,
297 x86_DEBUG_STATE64, 297 x86_DEBUG_STATE64,
298 reinterpret_cast<natural_t*>(&alt_x86_debug_state64), 298 reinterpret_cast<natural_t*>(&alt_x86_debug_state64),
299 x86_DEBUG_STATE64_COUNT, 299 x86_DEBUG_STATE64_COUNT,
300 &x86_thread_state64, 300 &x86_thread_state64,
301 &x86_float_state64, 301 &x86_float_state64,
302 &x86_debug_state64); 302 &x86_debug_state64);
303 EXPECT_EQ(10u, cpu_context_x86_64.rax); 303 EXPECT_EQ(10u, cpu_context_x86_64.rax);
304 EXPECT_EQ(11u, cpu_context_x86_64.fxsave64.ftw); 304 EXPECT_EQ(11u, cpu_context_x86_64.fxsave.ftw);
305 EXPECT_EQ(15u, cpu_context_x86_64.dr0); 305 EXPECT_EQ(15u, cpu_context_x86_64.dr0);
306 } 306 }
307 307
308 // Supply context in a universal “flavor” parameter expected to be used 308 // Supply context in a universal “flavor” parameter expected to be used
309 // instead of the supplied thread, float, or debug state parameters. The 309 // instead of the supplied thread, float, or debug state parameters. The
310 // universal format allows an exception handler to be registered to receive 310 // universal format allows an exception handler to be registered to receive
311 // thread, float, or debug state without having to know in advance whether it 311 // thread, float, or debug state without having to know in advance whether it
312 // will be receiving the state from a 32-bit or 64-bit process. For 312 // will be receiving the state from a 32-bit or 64-bit process. For
313 // CPUContextX86_64, only the 64-bit form is supported. 313 // CPUContextX86_64, only the 64-bit form is supported.
314 314
315 { 315 {
316 x86_thread_state x86_thread_state_3264 = {}; 316 x86_thread_state x86_thread_state_3264 = {};
317 x86_thread_state_3264.tsh.flavor = x86_THREAD_STATE64; 317 x86_thread_state_3264.tsh.flavor = x86_THREAD_STATE64;
318 x86_thread_state_3264.tsh.count = x86_THREAD_STATE64_COUNT; 318 x86_thread_state_3264.tsh.count = x86_THREAD_STATE64_COUNT;
319 x86_thread_state_3264.uts.ts64.__rax = 16; 319 x86_thread_state_3264.uts.ts64.__rax = 16;
320 320
321 CPUContextX86_64 cpu_context_x86_64 = {}; 321 CPUContextX86_64 cpu_context_x86_64 = {};
322 internal::InitializeCPUContextX86_64( 322 internal::InitializeCPUContextX86_64(
323 &cpu_context_x86_64, 323 &cpu_context_x86_64,
324 x86_THREAD_STATE, 324 x86_THREAD_STATE,
325 reinterpret_cast<natural_t*>(&x86_thread_state_3264), 325 reinterpret_cast<natural_t*>(&x86_thread_state_3264),
326 x86_THREAD_STATE_COUNT, 326 x86_THREAD_STATE_COUNT,
327 &x86_thread_state64, 327 &x86_thread_state64,
328 &x86_float_state64, 328 &x86_float_state64,
329 &x86_debug_state64); 329 &x86_debug_state64);
330 EXPECT_EQ(16u, cpu_context_x86_64.rax); 330 EXPECT_EQ(16u, cpu_context_x86_64.rax);
331 EXPECT_EQ(11u, cpu_context_x86_64.fxsave64.ftw); 331 EXPECT_EQ(11u, cpu_context_x86_64.fxsave.ftw);
332 EXPECT_EQ(12u, cpu_context_x86_64.dr0); 332 EXPECT_EQ(12u, cpu_context_x86_64.dr0);
333 } 333 }
334 334
335 { 335 {
336 x86_float_state x86_float_state_3264 = {}; 336 x86_float_state x86_float_state_3264 = {};
337 x86_float_state_3264.fsh.flavor = x86_FLOAT_STATE64; 337 x86_float_state_3264.fsh.flavor = x86_FLOAT_STATE64;
338 x86_float_state_3264.fsh.count = x86_FLOAT_STATE64_COUNT; 338 x86_float_state_3264.fsh.count = x86_FLOAT_STATE64_COUNT;
339 x86_float_state_3264.ufs.fs64.__fpu_ftw = 17; 339 x86_float_state_3264.ufs.fs64.__fpu_ftw = 17;
340 340
341 CPUContextX86_64 cpu_context_x86_64 = {}; 341 CPUContextX86_64 cpu_context_x86_64 = {};
342 internal::InitializeCPUContextX86_64( 342 internal::InitializeCPUContextX86_64(
343 &cpu_context_x86_64, 343 &cpu_context_x86_64,
344 x86_FLOAT_STATE, 344 x86_FLOAT_STATE,
345 reinterpret_cast<natural_t*>(&x86_float_state_3264), 345 reinterpret_cast<natural_t*>(&x86_float_state_3264),
346 x86_FLOAT_STATE_COUNT, 346 x86_FLOAT_STATE_COUNT,
347 &x86_thread_state64, 347 &x86_thread_state64,
348 &x86_float_state64, 348 &x86_float_state64,
349 &x86_debug_state64); 349 &x86_debug_state64);
350 EXPECT_EQ(10u, cpu_context_x86_64.rax); 350 EXPECT_EQ(10u, cpu_context_x86_64.rax);
351 EXPECT_EQ(17u, cpu_context_x86_64.fxsave64.ftw); 351 EXPECT_EQ(17u, cpu_context_x86_64.fxsave.ftw);
352 EXPECT_EQ(12u, cpu_context_x86_64.dr0); 352 EXPECT_EQ(12u, cpu_context_x86_64.dr0);
353 } 353 }
354 354
355 { 355 {
356 x86_debug_state x86_debug_state_3264 = {}; 356 x86_debug_state x86_debug_state_3264 = {};
357 x86_debug_state_3264.dsh.flavor = x86_DEBUG_STATE64; 357 x86_debug_state_3264.dsh.flavor = x86_DEBUG_STATE64;
358 x86_debug_state_3264.dsh.count = x86_DEBUG_STATE64_COUNT; 358 x86_debug_state_3264.dsh.count = x86_DEBUG_STATE64_COUNT;
359 x86_debug_state_3264.uds.ds64.__dr0 = 18; 359 x86_debug_state_3264.uds.ds64.__dr0 = 18;
360 360
361 CPUContextX86_64 cpu_context_x86_64 = {}; 361 CPUContextX86_64 cpu_context_x86_64 = {};
362 internal::InitializeCPUContextX86_64( 362 internal::InitializeCPUContextX86_64(
363 &cpu_context_x86_64, 363 &cpu_context_x86_64,
364 x86_DEBUG_STATE, 364 x86_DEBUG_STATE,
365 reinterpret_cast<natural_t*>(&x86_debug_state_3264), 365 reinterpret_cast<natural_t*>(&x86_debug_state_3264),
366 x86_DEBUG_STATE_COUNT, 366 x86_DEBUG_STATE_COUNT,
367 &x86_thread_state64, 367 &x86_thread_state64,
368 &x86_float_state64, 368 &x86_float_state64,
369 &x86_debug_state64); 369 &x86_debug_state64);
370 EXPECT_EQ(10u, cpu_context_x86_64.rax); 370 EXPECT_EQ(10u, cpu_context_x86_64.rax);
371 EXPECT_EQ(11u, cpu_context_x86_64.fxsave64.ftw); 371 EXPECT_EQ(11u, cpu_context_x86_64.fxsave.ftw);
372 EXPECT_EQ(18u, cpu_context_x86_64.dr0); 372 EXPECT_EQ(18u, cpu_context_x86_64.dr0);
373 } 373 }
374 374
375 // Supply inappropriate “flavor” contexts to test that 375 // Supply inappropriate “flavor” contexts to test that
376 // InitializeCPUContextX86() detects the problem and refuses to use the 376 // InitializeCPUContextX86() detects the problem and refuses to use the
377 // supplied “flavor” context, falling back to the thread, float, and debug 377 // supplied “flavor” context, falling back to the thread, float, and debug
378 // states. 378 // states.
379 379
380 { 380 {
381 x86_thread_state32_t x86_thread_state32 = {}; 381 x86_thread_state32_t x86_thread_state32 = {};
382 382
383 CPUContextX86_64 cpu_context_x86_64 = {}; 383 CPUContextX86_64 cpu_context_x86_64 = {};
384 internal::InitializeCPUContextX86_64( 384 internal::InitializeCPUContextX86_64(
385 &cpu_context_x86_64, 385 &cpu_context_x86_64,
386 x86_THREAD_STATE32, 386 x86_THREAD_STATE32,
387 reinterpret_cast<natural_t*>(&x86_thread_state32), 387 reinterpret_cast<natural_t*>(&x86_thread_state32),
388 x86_THREAD_STATE32_COUNT, 388 x86_THREAD_STATE32_COUNT,
389 &x86_thread_state64, 389 &x86_thread_state64,
390 &x86_float_state64, 390 &x86_float_state64,
391 &x86_debug_state64); 391 &x86_debug_state64);
392 EXPECT_EQ(10u, cpu_context_x86_64.rax); 392 EXPECT_EQ(10u, cpu_context_x86_64.rax);
393 EXPECT_EQ(11u, cpu_context_x86_64.fxsave64.ftw); 393 EXPECT_EQ(11u, cpu_context_x86_64.fxsave.ftw);
394 EXPECT_EQ(12u, cpu_context_x86_64.dr0); 394 EXPECT_EQ(12u, cpu_context_x86_64.dr0);
395 } 395 }
396 396
397 { 397 {
398 x86_thread_state x86_thread_state_3264 = {}; 398 x86_thread_state x86_thread_state_3264 = {};
399 x86_thread_state_3264.tsh.flavor = x86_THREAD_STATE32; 399 x86_thread_state_3264.tsh.flavor = x86_THREAD_STATE32;
400 x86_thread_state_3264.tsh.count = x86_THREAD_STATE32_COUNT; 400 x86_thread_state_3264.tsh.count = x86_THREAD_STATE32_COUNT;
401 401
402 CPUContextX86_64 cpu_context_x86_64 = {}; 402 CPUContextX86_64 cpu_context_x86_64 = {};
403 internal::InitializeCPUContextX86_64( 403 internal::InitializeCPUContextX86_64(
404 &cpu_context_x86_64, 404 &cpu_context_x86_64,
405 x86_THREAD_STATE, 405 x86_THREAD_STATE,
406 reinterpret_cast<natural_t*>(&x86_thread_state_3264), 406 reinterpret_cast<natural_t*>(&x86_thread_state_3264),
407 x86_THREAD_STATE_COUNT, 407 x86_THREAD_STATE_COUNT,
408 &x86_thread_state64, 408 &x86_thread_state64,
409 &x86_float_state64, 409 &x86_float_state64,
410 &x86_debug_state64); 410 &x86_debug_state64);
411 EXPECT_EQ(10u, cpu_context_x86_64.rax); 411 EXPECT_EQ(10u, cpu_context_x86_64.rax);
412 EXPECT_EQ(11u, cpu_context_x86_64.fxsave64.ftw); 412 EXPECT_EQ(11u, cpu_context_x86_64.fxsave.ftw);
413 EXPECT_EQ(12u, cpu_context_x86_64.dr0); 413 EXPECT_EQ(12u, cpu_context_x86_64.dr0);
414 } 414 }
415 } 415 }
416 416
417 #endif 417 #endif
418 418
419 } // namespace 419 } // namespace
OLDNEW
« no previous file with comments | « snapshot/cpu_context_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698