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

Side by Side Diff: syzygy/agent/asan/runtime.cc

Issue 2576003002: Add the ability to defer the initialization of the SyzyAsan crash reporter. (Closed)
Patch Set: x64 def file. Created 3 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
OLDNEW
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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 base::Lock AsanRuntime::lock_; 453 base::Lock AsanRuntime::lock_;
454 AsanRuntime* AsanRuntime::runtime_ = NULL; 454 AsanRuntime* AsanRuntime::runtime_ = NULL;
455 LPTOP_LEVEL_EXCEPTION_FILTER AsanRuntime::previous_uef_ = NULL; 455 LPTOP_LEVEL_EXCEPTION_FILTER AsanRuntime::previous_uef_ = NULL;
456 bool AsanRuntime::uef_installed_ = false; 456 bool AsanRuntime::uef_installed_ = false;
457 457
458 AsanRuntime::AsanRuntime() 458 AsanRuntime::AsanRuntime()
459 : logger_(), 459 : logger_(),
460 stack_cache_(), 460 stack_cache_(),
461 asan_error_callback_(), 461 asan_error_callback_(),
462 heap_manager_(), 462 heap_manager_(),
463 random_key_(::__rdtsc()) { 463 random_key_(::__rdtsc()),
464 crash_reporter_initialized_(false) {
464 ::common::SetDefaultAsanParameters(&params_); 465 ::common::SetDefaultAsanParameters(&params_);
465 starting_ticks_ = ::GetTickCount(); 466 starting_ticks_ = ::GetTickCount();
466 } 467 }
467 468
468 AsanRuntime::~AsanRuntime() { 469 AsanRuntime::~AsanRuntime() {
469 } 470 }
470 471
471 bool AsanRuntime::SetUp(const std::wstring& flags_command_line) { 472 bool AsanRuntime::SetUp(const std::wstring& flags_command_line) {
472 base::AutoLock auto_lock(lock_); 473 base::AutoLock auto_lock(lock_);
473 DCHECK(!runtime_); 474 DCHECK(!runtime_);
(...skipping 20 matching lines...) Expand all
494 if (!SetUpMemoryNotifier()) 495 if (!SetUpMemoryNotifier())
495 return false; 496 return false;
496 if (!SetUpLogger()) 497 if (!SetUpLogger())
497 return false; 498 return false;
498 if (!SetUpStackCache()) 499 if (!SetUpStackCache())
499 return false; 500 return false;
500 if (!SetUpHeapManager()) 501 if (!SetUpHeapManager())
501 return false; 502 return false;
502 WindowsHeapAdapter::SetUp(heap_manager_.get()); 503 WindowsHeapAdapter::SetUp(heap_manager_.get());
503 504
504 // Determine the preferred crash reporter type, as specified in the
505 // environment. If this isn't present it defaults to
506 // kDefaultCrashReporterType, in which case experiments or command-line flags
507 // may specify the crash reporter to use.
508 CrashReporterType crash_reporter_type =
509 GetCrashReporterTypeFromEnvironment(logger());
510
511 if (params_.feature_randomization) { 505 if (params_.feature_randomization) {
512 AsanFeatureSet feature_set = GenerateRandomFeatureSet(); 506 AsanFeatureSet feature_set = GenerateRandomFeatureSet();
513 PropagateFeatureSet(feature_set); 507 PropagateFeatureSet(feature_set);
514 } 508 }
515 509
516 // Propagates the flags values to the different modules. 510 // Propagates the flags values to the different modules.
517 PropagateParams(); 511 PropagateParams();
518 512
519 // The name 'disable_breakpad_reporting' is legacy; this actually means to 513 if (!params_.defer_crash_reporter_initialization)
520 // disable all external crash reporting integration. 514 InitializeCrashReporter();
521 if (!params_.disable_breakpad_reporting) {
522 // This will create the crash reporter with a preference for creating a
523 // reporter of the hinted type. If such a reporter isn't available, it will
524 // fall back to trying to create the most 'modern' reporter available.
525 crash_reporter_.reset(CreateCrashReporterWithTypeHint(
526 logger(), crash_reporter_type).release());
527 }
528
529 // Set up the appropriate error handler depending on whether or not
530 // we successfully initialized a crash reporter.
531 if (crash_reporter_.get() != nullptr) {
532 logger_->Write(base::StringPrintf(
533 "SyzyASAN: Using %s for error reporting.",
534 crash_reporter_->GetName()));
535 SetErrorCallBack(base::Bind(&CrashReporterErrorHandler));
536 } else {
537 logger_->Write("SyzyASAN: Using default error reporting handler.");
538 SetErrorCallBack(base::Bind(&DefaultErrorHandler));
539 }
540 515
541 // Install the unhandled exception handler. This is only installed once 516 // Install the unhandled exception handler. This is only installed once
542 // across all runtime instances in a process so we check that it hasn't 517 // across all runtime instances in a process so we check that it hasn't
543 // already been installed. 518 // already been installed.
544 // TODO(chrisha): Conditionally install this based on the crash reporter in 519 // TODO(chrisha): Conditionally install this based on the crash reporter in
545 // use. Eventually, Crashpad will provide us a callback instead of having us 520 // use. Eventually, Crashpad will provide us a callback instead of having us
546 // register the handler ourselves. 521 // register the handler ourselves.
547 if (!uef_installed_) { 522 if (!uef_installed_) {
548 uef_installed_ = true; 523 uef_installed_ = true;
549 previous_uef_ = ::SetUnhandledExceptionFilter(&UnhandledExceptionFilter); 524 previous_uef_ = ::SetUnhandledExceptionFilter(&UnhandledExceptionFilter);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 void AsanRuntime::PropagateParams() { 791 void AsanRuntime::PropagateParams() {
817 // This function has to be kept in sync with the AsanParameters struct. These 792 // This function has to be kept in sync with the AsanParameters struct. These
818 // checks will ensure that this is the case. 793 // checks will ensure that this is the case.
819 #ifdef _WIN64 794 #ifdef _WIN64
820 static_assert(sizeof(::common::AsanParameters) == 64, 795 static_assert(sizeof(::common::AsanParameters) == 64,
821 "Must propagate parameters."); 796 "Must propagate parameters.");
822 #else 797 #else
823 static_assert(sizeof(::common::AsanParameters) == 60, 798 static_assert(sizeof(::common::AsanParameters) == 60,
824 "Must propagate parameters."); 799 "Must propagate parameters.");
825 #endif 800 #endif
826 static_assert(::common::kAsanParametersVersion == 14, 801 static_assert(::common::kAsanParametersVersion == 15,
827 "Must update parameters version."); 802 "Must update parameters version.");
828 803
829 // Push the configured parameter values to the appropriate endpoints. 804 // Push the configured parameter values to the appropriate endpoints.
830 heap_manager_->set_parameters(params_); 805 heap_manager_->set_parameters(params_);
831 StackCaptureCache::set_compression_reporting_period(params_.reporting_period); 806 StackCaptureCache::set_compression_reporting_period(params_.reporting_period);
832 common::StackCapture::set_bottom_frames_to_skip( 807 common::StackCapture::set_bottom_frames_to_skip(
833 params_.bottom_frames_to_skip); 808 params_.bottom_frames_to_skip);
834 stack_cache_->set_max_num_frames(params_.max_num_frames); 809 stack_cache_->set_max_num_frames(params_.max_num_frames);
835 // ignored_stack_ids is used locally by AsanRuntime. 810 // ignored_stack_ids is used locally by AsanRuntime.
836 logger_->set_log_as_text(params_.log_as_text); 811 logger_->set_log_as_text(params_.log_as_text);
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 AsanFeatureSet AsanRuntime::GetEnabledFeatureSet() { 1195 AsanFeatureSet AsanRuntime::GetEnabledFeatureSet() {
1221 AsanFeatureSet enabled_features = static_cast<AsanFeatureSet>(0U); 1196 AsanFeatureSet enabled_features = static_cast<AsanFeatureSet>(0U);
1222 if (heap_manager_->enable_page_protections_) 1197 if (heap_manager_->enable_page_protections_)
1223 enabled_features |= ASAN_FEATURE_ENABLE_PAGE_PROTECTIONS; 1198 enabled_features |= ASAN_FEATURE_ENABLE_PAGE_PROTECTIONS;
1224 if (params_.enable_large_block_heap) 1199 if (params_.enable_large_block_heap)
1225 enabled_features |= ASAN_FEATURE_ENABLE_LARGE_BLOCK_HEAP; 1200 enabled_features |= ASAN_FEATURE_ENABLE_LARGE_BLOCK_HEAP;
1226 1201
1227 return enabled_features; 1202 return enabled_features;
1228 } 1203 }
1229 1204
1205 void AsanRuntime::InitializeCrashReporter() {
1206 DCHECK_EQ(nullptr, crash_reporter_.get());
1207 DCHECK(!crash_reporter_initialized_);
chrisha 2017/01/11 18:57:28 Document this contract in the function description
Sébastien Marchand 2017/01/11 21:38:08 Done. Turned this into a CHECK.
1208
1209 crash_reporter_initialized_ = true;
1210
1211 // Determine the preferred crash reporter type, as specified in the
1212 // environment. If this isn't present it defaults to
1213 // kDefaultCrashReporterType, in which case experiments or command-line flags
1214 // may specify the crash reporter to use.
1215 CrashReporterType crash_reporter_type =
1216 GetCrashReporterTypeFromEnvironment(logger());
1217
1218 // The name 'disable_breakpad_reporting' is legacy; this actually means to
1219 // disable all external crash reporting integration.
1220 if (!params_.disable_breakpad_reporting) {
1221 // This will create the crash reporter with a preference for creating a
1222 // reporter of the hinted type. If such a reporter isn't available, it will
1223 // fall back to trying to create the most 'modern' reporter available.
1224 crash_reporter_.reset(CreateCrashReporterWithTypeHint(
1225 logger(), crash_reporter_type).release());
1226 }
1227
1228 // Set up the appropriate error handler depending on whether or not
1229 // we successfully initialized a crash reporter.
1230 if (crash_reporter_.get() != nullptr) {
1231 logger_->Write(base::StringPrintf("SyzyASAN: Using %s for error reporting.",
1232 crash_reporter_->GetName()));
1233 SetErrorCallBack(base::Bind(&CrashReporterErrorHandler));
1234 } else {
1235 logger_->Write("SyzyASAN: Using default error reporting handler.");
1236 SetErrorCallBack(base::Bind(&DefaultErrorHandler));
1237 }
1238 }
1239
1230 } // namespace asan 1240 } // namespace asan
1231 } // namespace agent 1241 } // namespace agent
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698