| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/profiler/win32_stack_frame_unwinder.h" | 9 #include "base/profiler/win32_stack_frame_unwinder.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 scoped_ptr<Win32StackFrameUnwinder> unwinder = CreateUnwinder(); | 368 scoped_ptr<Win32StackFrameUnwinder> unwinder = CreateUnwinder(); |
| 369 CONTEXT context = {0}; | 369 CONTEXT context = {0}; |
| 370 ScopedModuleHandle module; | 370 ScopedModuleHandle module; |
| 371 unwind_functions_->SetNoRuntimeFunction(image_base_for_questionable_module, | 371 unwind_functions_->SetNoRuntimeFunction(image_base_for_questionable_module, |
| 372 &context); | 372 &context); |
| 373 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); | 373 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); |
| 374 EXPECT_TRUE(module.IsValid()); | 374 EXPECT_TRUE(module.IsValid()); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 | 377 |
| 378 // Checks that frames with RUNTIME_FUNCTION structures with nonsensical values | |
| 379 // are not unwound. | |
| 380 TEST_F(Win32StackFrameUnwinderTest, RuntimeFunctionSanityCheck) { | |
| 381 const DWORD64 image_base_for_sanity_check = 3072; | |
| 382 { | |
| 383 // Test the expected case: end address greater than begin address and | |
| 384 // instruction pointer between the two. | |
| 385 scoped_ptr<Win32StackFrameUnwinder> unwinder = CreateUnwinder(); | |
| 386 CONTEXT context = {0}; | |
| 387 ScopedModuleHandle module; | |
| 388 RUNTIME_FUNCTION runtime_function = {0}; | |
| 389 runtime_function.BeginAddress = 128; | |
| 390 runtime_function.EndAddress = 512; | |
| 391 unwind_functions_->SetHasRuntimeFunction(image_base_for_sanity_check, | |
| 392 runtime_function, 256, | |
| 393 &context); | |
| 394 EXPECT_TRUE(unwinder->TryUnwind(&context, &module)); | |
| 395 EXPECT_TRUE(module.IsValid()); | |
| 396 } | |
| 397 | |
| 398 { | |
| 399 // Test begin address greater than end address. | |
| 400 scoped_ptr<Win32StackFrameUnwinder> unwinder = CreateUnwinder(); | |
| 401 CONTEXT context = {0}; | |
| 402 ScopedModuleHandle module; | |
| 403 RUNTIME_FUNCTION runtime_function = {0}; | |
| 404 runtime_function.BeginAddress = 512; | |
| 405 runtime_function.EndAddress = 128; | |
| 406 unwind_functions_->SetHasRuntimeFunction(image_base_for_sanity_check, | |
| 407 runtime_function, 256, | |
| 408 &context); | |
| 409 EXPECT_FALSE(unwinder->TryUnwind(&context, &module)); | |
| 410 } | |
| 411 | |
| 412 { | |
| 413 // Test instruction pointer before begin address. | |
| 414 scoped_ptr<Win32StackFrameUnwinder> unwinder = CreateUnwinder(); | |
| 415 CONTEXT context = {0}; | |
| 416 ScopedModuleHandle module; | |
| 417 RUNTIME_FUNCTION runtime_function = {0}; | |
| 418 runtime_function.BeginAddress = 128; | |
| 419 runtime_function.EndAddress = 512; | |
| 420 unwind_functions_->SetHasRuntimeFunction(image_base_for_sanity_check, | |
| 421 runtime_function, 50, | |
| 422 &context); | |
| 423 EXPECT_FALSE(unwinder->TryUnwind(&context, &module)); | |
| 424 } | |
| 425 | |
| 426 { | |
| 427 // Test instruction pointer after end address. | |
| 428 scoped_ptr<Win32StackFrameUnwinder> unwinder = CreateUnwinder(); | |
| 429 CONTEXT context = {0}; | |
| 430 ScopedModuleHandle module; | |
| 431 RUNTIME_FUNCTION runtime_function = {0}; | |
| 432 runtime_function.BeginAddress = 128; | |
| 433 runtime_function.EndAddress = 512; | |
| 434 unwind_functions_->SetHasRuntimeFunction(image_base_for_sanity_check, | |
| 435 runtime_function, 600, | |
| 436 &context); | |
| 437 EXPECT_FALSE(unwinder->TryUnwind(&context, &module)); | |
| 438 } | |
| 439 } | |
| 440 | |
| 441 } // namespace base | 378 } // namespace base |
| OLD | NEW |