Commit f1f52ab3 authored by Vlad Tsyrklevich's avatar Vlad Tsyrklevich

GWP-ASan: Perform early start-up initialization

GWP-ASan is a debug allocator intended to find memory errors in the
wild. In order to detect as many as bugs as possible, it should start as
early as possible, e.g. soon after it's dependency, FeatureList, has
been initialized. Since content/ doesn't call into ChromeMainDelegate
for child processes after FeatureList has been initialized, create a new
delegate method for post-FeatureList initialization and enable GWP-ASan
at that point.

Bug: 896019
Change-Id: I9c081602cd32a71d5d9eb774bd9818757d9b7e95
Reviewed-on: https://chromium-review.googlesource.com/c/1343347Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611041}
parent 73558153
......@@ -409,6 +409,7 @@ if (is_win) {
"//chrome/install_static:secondary_module",
"//chrome_elf",
"//components/crash/content/app",
"//components/gwp_asan/client",
"//components/policy:generated",
"//content/app/resources",
"//content/public/common:service_names",
......@@ -515,6 +516,7 @@ if (is_win) {
"//chrome_elf",
"//components/browser_watcher:browser_watcher_client",
"//components/crash/content/app",
"//components/gwp_asan/client",
"//content/public/app:child",
"//content/public/common:service_names",
"//headless:headless_shell_child_lib",
......
......@@ -365,6 +365,7 @@ static_library("test_support") {
"//chrome:chrome_initial",
"//chrome/install_static:install_static_util",
"//chrome_elf:test_stubs",
"//components/gwp_asan/client",
"//sandbox/win:sandbox",
]
}
......
......@@ -17,6 +17,7 @@ include_rules = [
"+components/component_updater",
"+components/content_settings/core/common/content_settings_pattern.h",
"+components/crash",
"+components/gwp_asan/client/gwp_asan.h",
"+components/nacl/common",
"+components/nacl/renderer/plugin/ppapi_entrypoints.h",
"+components/nacl/zygote",
......
......@@ -46,6 +46,7 @@
#include "components/crash/content/app/crash_reporter_client.h"
#include "components/crash/core/common/crash_key.h"
#include "components/crash/core/common/crash_keys.h"
#include "components/gwp_asan/client/gwp_asan.h"
#include "components/nacl/common/buildflags.h"
#include "components/services/heap_profiling/public/cpp/allocator_shim.h"
#include "components/services/heap_profiling/public/cpp/stream.h"
......@@ -515,6 +516,7 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) {
DCHECK(chrome_feature_list_creator_);
chrome_feature_list_creator_->CreateFeatureList();
PostFieldTrialInitialization();
// Initializes the resouce bundle and determines the locale.
std::string actual_locale =
......@@ -530,6 +532,12 @@ bool ChromeMainDelegate::ShouldCreateFeatureList() {
}
#endif
void ChromeMainDelegate::PostFieldTrialInitialization() {
#if defined(OS_WIN)
gwp_asan::EnableForMalloc();
#endif
}
bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) {
#if defined(OS_CHROMEOS)
chromeos::BootTimesRecorder::Get()->SaveChromeMainStats();
......
......@@ -67,6 +67,7 @@ class ChromeMainDelegate : public content::ContentMainDelegate {
void PostEarlyInitialization(bool is_running_tests) override;
bool ShouldCreateFeatureList() override;
#endif
void PostFieldTrialInitialization() override;
content::ContentBrowserClient* CreateContentBrowserClient() override;
content::ContentGpuClient* CreateContentGpuClient() override;
......
......@@ -484,6 +484,7 @@ int RunZygote(ContentMainDelegate* delegate) {
main_params.zygote_child = true;
InitializeFieldTrialAndFeatureList();
delegate->PostFieldTrialInitialization();
service_manager::SandboxType sandbox_type =
service_manager::SandboxTypeFromCommandLine(command_line);
......@@ -838,8 +839,10 @@ int ContentMainRunnerImpl::Run(bool start_service_manager_only) {
// Run this logic on all child processes. Zygotes will run this at a later
// point in time when the command line has been updated.
if (!process_type.empty() &&
process_type != service_manager::switches::kZygoteProcess)
process_type != service_manager::switches::kZygoteProcess) {
InitializeFieldTrialAndFeatureList();
delegate_->PostFieldTrialInitialization();
}
#endif
MainFunctionParams main_params(command_line);
......@@ -862,6 +865,7 @@ int ContentMainRunnerImpl::Run(bool start_service_manager_only) {
if (delegate_->ShouldCreateFeatureList()) {
DCHECK(!field_trial_list_);
field_trial_list_ = SetUpFieldTrialsAndFeatureList();
delegate_->PostFieldTrialInitialization();
}
startup_data_->thread = BrowserProcessSubThread::CreateIOThread();
......
......@@ -124,10 +124,16 @@ class CONTENT_EXPORT ContentMainDelegate {
// Allows the embedder to perform its own initialization after content
// performed its own and already brought up MessageLoop, TaskScheduler, field
// tials and FeatureList (by default).
// trials and FeatureList (by default).
// |is_running_tests| indicates whether it is running in tests.
virtual void PostEarlyInitialization(bool is_running_tests) {}
// Allows the embedder to perform initialization once field trials/FeatureList
// initialization has completed if ShouldCreateFeatureList() returns true.
// Otherwise, the embedder is responsible for calling this method once feature
// list initialization is complete.
virtual void PostFieldTrialInitialization() {}
protected:
friend class ContentClientInitializer;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment