OLD | NEW |
---|---|
1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 Google Inc. 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 ->WriteCorruptHeapInfo(corrupt_ranges, size, buffer, error_info); \ | 380 ->WriteCorruptHeapInfo(corrupt_ranges, size, buffer, error_info); \ |
381 } \ | 381 } \ |
382 } | 382 } |
383 | 383 |
384 void LaunchMessageBox(const base::StringPiece& message) { | 384 void LaunchMessageBox(const base::StringPiece& message) { |
385 // TODO(chrisha): Consider making this close itself with a timeout to prevent | 385 // TODO(chrisha): Consider making this close itself with a timeout to prevent |
386 // hangs on the waterfall. | 386 // hangs on the waterfall. |
387 ::MessageBoxA(nullptr, message.data(), nullptr, MB_OK | MB_ICONEXCLAMATION); | 387 ::MessageBoxA(nullptr, message.data(), nullptr, MB_OK | MB_ICONEXCLAMATION); |
388 } | 388 } |
389 | 389 |
390 std::unique_ptr<ReporterInterface> CreateCrashReporter(AsanLogger* logger) { | 390 AsanFeatureSet GenerateRandomFeatureSet() { |
391 AsanFeatureSet enabled_features = | |
392 static_cast<AsanFeatureSet>(base::RandGenerator(ASAN_FEATURE_MAX)); | |
393 DCHECK_LT(enabled_features, ASAN_FEATURE_MAX); | |
394 enabled_features &= kAsanValidFeatures; | |
395 return enabled_features; | |
396 } | |
397 | |
398 std::unique_ptr<ReporterInterface> CreateCrashReporter( | |
399 AsanLogger* logger, AsanFeatureSet* feature_set) { | |
400 DCHECK_NE(static_cast<AsanLogger*>(nullptr), logger); | |
401 DCHECK_NE(static_cast<AsanFeatureSet*>(nullptr), feature_set); | |
391 std::unique_ptr<ReporterInterface> reporter; | 402 std::unique_ptr<ReporterInterface> reporter; |
392 | 403 |
404 bool created_crashpad = false; | |
405 | |
393 // First try to grab the preferred crash reporter, overridden by the | 406 // First try to grab the preferred crash reporter, overridden by the |
394 // environment. | 407 // environment. |
395 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 408 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
396 std::string reporter_name; | 409 std::string reporter_name; |
397 if (env->GetVar("SYZYASAN_CRASH_REPORTER", &reporter_name)) { | 410 if (env->GetVar("SYZYASAN_CRASH_REPORTER", &reporter_name)) { |
398 if (reporter_name == "crashpad") | 411 if (reporter_name == "crashpad") { |
399 reporter.reset(reporters::CrashpadReporter::Create().release()); | 412 reporter.reset(reporters::CrashpadReporter::Create().release()); |
400 else if (reporter_name == "kasko") | 413 created_crashpad = (reporter.get() != nullptr); |
414 } else if (reporter_name == "kasko") { | |
401 reporter.reset(reporters::KaskoReporter::Create().release()); | 415 reporter.reset(reporters::KaskoReporter::Create().release()); |
402 else if (reporter_name == "breakpad") | 416 } else if (reporter_name == "breakpad") { |
403 reporter.reset(reporters::BreakpadReporter::Create().release()); | 417 reporter.reset(reporters::BreakpadReporter::Create().release()); |
418 } | |
404 | 419 |
405 if (reporter.get() != nullptr) { | 420 if (reporter.get() != nullptr) { |
406 logger->Write(base::StringPrintf( | 421 logger->Write(base::StringPrintf( |
407 "Using requested \"%s\" crash reporter.", reporter_name)); | 422 "Using requested \"%s\" crash reporter.", reporter_name)); |
408 return reporter; | 423 return reporter; |
409 } else { | 424 } else { |
410 logger->Write(base::StringPrintf( | 425 logger->Write(base::StringPrintf( |
411 "Unable to create requested \"%s\" crash reporter.", reporter_name)); | 426 "Unable to create requested \"%s\" crash reporter.", reporter_name)); |
412 } | 427 } |
413 } | 428 } |
414 | 429 |
415 // No crash reporter was explicitly specified, or it was unable to be | 430 // No crash reporter was explicitly specified, or it was unable to be |
416 // initialized. Try all of them, starting with the most recent. | 431 // initialized. Try all of them, starting with the most recent. |
417 | 432 |
418 // Don't try grabbing a Crashpad reporter by default, as we're not yet | 433 // Only create a crashpad reporter if the feature was enabled. |
419 // ready to ship this. | 434 if (reporter.get() == nullptr && |
420 // TODO(chrisha): Add Crashpad support behind a feature flag. | 435 (*feature_set & ASAN_FEATURE_ENABLE_CRASHPAD)) { |
436 reporter.reset(reporters::CrashpadReporter::Create().release()); | |
437 created_crashpad = (reporter.get() != nullptr); | |
438 } | |
421 | 439 |
422 // Try to initialize a Kasko crash reporter. | 440 // Try to initialize a Kasko crash reporter. |
423 if (reporter.get() == nullptr) | 441 if (reporter.get() == nullptr) |
424 reporter.reset(reporters::KaskoReporter::Create().release()); | 442 reporter.reset(reporters::KaskoReporter::Create().release()); |
425 | 443 |
426 // If that failed then try to initialize a Breakpad reporter. | 444 // If that failed then try to initialize a Breakpad reporter. |
427 if (reporter.get() == nullptr) | 445 if (reporter.get() == nullptr) |
428 reporter.reset(reporters::BreakpadReporter::Create().release()); | 446 reporter.reset(reporters::BreakpadReporter::Create().release()); |
429 | 447 |
448 // Ensure the feature flag (which will end up being reported as an | |
449 // experiment group in instrumented Chromen) reflects whether or not a | |
450 // crashpad reporter is in use. | |
451 if (created_crashpad) { | |
452 *feature_set |= ASAN_FEATURE_ENABLE_CRASHPAD; | |
453 } else { | |
454 *feature_set &= ~ASAN_FEATURE_ENABLE_CRASHPAD; | |
455 } | |
456 | |
430 return reporter; | 457 return reporter; |
431 } | 458 } |
432 | 459 |
433 } // namespace | 460 } // namespace |
434 | 461 |
435 base::Lock AsanRuntime::lock_; | 462 base::Lock AsanRuntime::lock_; |
436 AsanRuntime* AsanRuntime::runtime_ = NULL; | 463 AsanRuntime* AsanRuntime::runtime_ = NULL; |
437 LPTOP_LEVEL_EXCEPTION_FILTER AsanRuntime::previous_uef_ = NULL; | 464 LPTOP_LEVEL_EXCEPTION_FILTER AsanRuntime::previous_uef_ = NULL; |
438 bool AsanRuntime::uef_installed_ = false; | 465 bool AsanRuntime::uef_installed_ = false; |
439 | 466 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 if (!SetUpMemoryNotifier()) | 503 if (!SetUpMemoryNotifier()) |
477 return false; | 504 return false; |
478 if (!SetUpLogger()) | 505 if (!SetUpLogger()) |
479 return false; | 506 return false; |
480 if (!SetUpStackCache()) | 507 if (!SetUpStackCache()) |
481 return false; | 508 return false; |
482 if (!SetUpHeapManager()) | 509 if (!SetUpHeapManager()) |
483 return false; | 510 return false; |
484 WindowsHeapAdapter::SetUp(heap_manager_.get()); | 511 WindowsHeapAdapter::SetUp(heap_manager_.get()); |
485 | 512 |
486 if (params_.feature_randomization) { | 513 AsanFeatureSet feature_set = 0; |
487 AsanFeatureSet feature_set = GenerateRandomFeatureSet(); | 514 if (params_.feature_randomization) |
515 GenerateRandomFeatureSet(); | |
Sigurður Ásgeirsson
2016/05/18 14:24:51
uh??
Sigurður Ásgeirsson
2016/05/18 14:26:16
That is to say - this looks like a noop to me?
chrisha
2016/05/18 14:32:57
Indeed it is. Cut and paste error.
Also, as Seb p
| |
516 | |
517 // Creating the crash reporter may override a randomized feature, so do this | |
518 // before propagating paramters. The name 'disable_breakpad_reporting' is | |
519 // legacy; this actually means to disable all external crash reporting | |
520 // integration. | |
521 if (!params_.disable_breakpad_reporting) { | |
522 crash_reporter_.reset( | |
523 CreateCrashReporter(logger(), &feature_set).release()); | |
524 } | |
525 | |
526 // Propagate randomized features if they're enabled. | |
527 if (params_.feature_randomization) | |
488 PropagateFeatureSet(feature_set); | 528 PropagateFeatureSet(feature_set); |
489 } | |
490 | 529 |
491 // Propagates the flags values to the different modules. | 530 // Propagates the flags values to the different modules. |
492 PropagateParams(); | 531 PropagateParams(); |
493 | 532 |
494 // The name 'disable_breakpad_reporting' is legacy; this actually means to | |
495 // disable all external crash reporting integration. | |
496 if (!params_.disable_breakpad_reporting) | |
497 crash_reporter_.reset(CreateCrashReporter(logger()).release()); | |
498 | |
499 // Set up the appropriate error handler depending on whether or not | 533 // Set up the appropriate error handler depending on whether or not |
500 // we successfully found a crash reporter. | 534 // we successfully found a crash reporter. |
501 if (crash_reporter_.get() != nullptr) { | 535 if (crash_reporter_.get() != nullptr) { |
502 logger_->Write(base::StringPrintf( | 536 logger_->Write(base::StringPrintf( |
503 "SyzyASAN: Using %s for error reporting.", | 537 "SyzyASAN: Using %s for error reporting.", |
504 crash_reporter_->GetName())); | 538 crash_reporter_->GetName())); |
505 SetErrorCallBack(base::Bind(&CrashReporterErrorHandler)); | 539 SetErrorCallBack(base::Bind(&CrashReporterErrorHandler)); |
506 } else { | 540 } else { |
507 logger_->Write("SyzyASAN: Using default error reporting handler."); | 541 logger_->Write("SyzyASAN: Using default error reporting handler."); |
508 SetErrorCallBack(base::Bind(&DefaultErrorHandler)); | 542 SetErrorCallBack(base::Bind(&DefaultErrorHandler)); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
954 } | 988 } |
955 | 989 |
956 // Print the Windbg information to display the free stack if present. | 990 // Print the Windbg information to display the free stack if present. |
957 if (error_info->block_info.free_stack_size != NULL) { | 991 if (error_info->block_info.free_stack_size != NULL) { |
958 AsanDbgMessage(L"Free stack trace:"); | 992 AsanDbgMessage(L"Free stack trace:"); |
959 AsanDbgCmd(L"dps %p l%d", error_info->block_info.free_stack, | 993 AsanDbgCmd(L"dps %p l%d", error_info->block_info.free_stack, |
960 error_info->block_info.free_stack_size); | 994 error_info->block_info.free_stack_size); |
961 } | 995 } |
962 } | 996 } |
963 | 997 |
964 AsanFeatureSet AsanRuntime::GenerateRandomFeatureSet() { | |
965 AsanFeatureSet enabled_features = | |
966 static_cast<AsanFeatureSet>(base::RandGenerator(ASAN_FEATURE_MAX)); | |
967 DCHECK_LT(enabled_features, ASAN_FEATURE_MAX); | |
968 enabled_features &= kAsanValidFeatures; | |
969 return enabled_features; | |
970 } | |
971 | |
972 void AsanRuntime::PropagateFeatureSet(AsanFeatureSet feature_set) { | 998 void AsanRuntime::PropagateFeatureSet(AsanFeatureSet feature_set) { |
973 DCHECK_EQ(0U, feature_set & ~kAsanValidFeatures); | 999 DCHECK_EQ(0U, feature_set & ~kAsanValidFeatures); |
974 heap_manager_->enable_page_protections_ = | 1000 heap_manager_->enable_page_protections_ = |
975 (feature_set & ASAN_FEATURE_ENABLE_PAGE_PROTECTIONS) != 0; | 1001 (feature_set & ASAN_FEATURE_ENABLE_PAGE_PROTECTIONS) != 0; |
976 params_.enable_large_block_heap = | 1002 params_.enable_large_block_heap = |
977 (feature_set & ASAN_FEATURE_ENABLE_LARGE_BLOCK_HEAP) != 0; | 1003 (feature_set & ASAN_FEATURE_ENABLE_LARGE_BLOCK_HEAP) != 0; |
978 } | 1004 } |
979 | 1005 |
980 void AsanRuntime::GetBadAccessInformation(AsanErrorInfo* error_info) { | 1006 void AsanRuntime::GetBadAccessInformation(AsanErrorInfo* error_info) { |
981 base::AutoLock lock(lock_); | 1007 base::AutoLock lock(lock_); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1198 if (heap_manager_->enable_page_protections_) | 1224 if (heap_manager_->enable_page_protections_) |
1199 enabled_features |= ASAN_FEATURE_ENABLE_PAGE_PROTECTIONS; | 1225 enabled_features |= ASAN_FEATURE_ENABLE_PAGE_PROTECTIONS; |
1200 if (params_.enable_large_block_heap) | 1226 if (params_.enable_large_block_heap) |
1201 enabled_features |= ASAN_FEATURE_ENABLE_LARGE_BLOCK_HEAP; | 1227 enabled_features |= ASAN_FEATURE_ENABLE_LARGE_BLOCK_HEAP; |
1202 | 1228 |
1203 return enabled_features; | 1229 return enabled_features; |
1204 } | 1230 } |
1205 | 1231 |
1206 } // namespace asan | 1232 } // namespace asan |
1207 } // namespace agent | 1233 } // namespace agent |
OLD | NEW |