Commit ea7ff6f0 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

Eliminate another GetModuleHandle/GetProcAddress thunking instance to chrome_elf.

Bug: 
Cq-Include-Trybots: master.tryserver.chromium.win:win10_chromium_x64_rel_ng
Change-Id: Ie52b94fb16a240c5f6549560e6e99982fc28b924
Reviewed-on: https://chromium-review.googlesource.com/596416
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarRobert Shield <robertshield@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Reviewed-by: default avatarBrett Wilson <brettw@chromium.org>
Reviewed-by: default avatarScott Graham <scottmg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491794}
parent 810fa82b
...@@ -348,6 +348,7 @@ static_library("test_support") { ...@@ -348,6 +348,7 @@ static_library("test_support") {
deps += [ deps += [
"//chrome:chrome_initial", "//chrome:chrome_initial",
"//chrome/install_static:install_static_util", "//chrome/install_static:install_static_util",
"//chrome_elf:test_stubs",
"//sandbox/win:sandbox", "//sandbox/win:sandbox",
] ]
} }
......
...@@ -239,7 +239,7 @@ void ChromeCrashReporterClient::InitializeCrashReportingForProcess() { ...@@ -239,7 +239,7 @@ void ChromeCrashReporterClient::InitializeCrashReportingForProcess() {
instance = new ChromeCrashReporterClient(); instance = new ChromeCrashReporterClient();
ANNOTATE_LEAKING_OBJECT_PTR(instance); ANNOTATE_LEAKING_OBJECT_PTR(instance);
base::string16 process_type = install_static::GetSwitchValueFromCommandLine( std::wstring process_type = install_static::GetSwitchValueFromCommandLine(
::GetCommandLine(), install_static::kProcessType); ::GetCommandLine(), install_static::kProcessType);
// Don't set up Crashpad crash reporting in the Crashpad handler itself, nor // Don't set up Crashpad crash reporting in the Crashpad handler itself, nor
// in the fallback crash handler for the Crashpad handler process. // in the fallback crash handler for the Crashpad handler process.
...@@ -247,8 +247,7 @@ void ChromeCrashReporterClient::InitializeCrashReportingForProcess() { ...@@ -247,8 +247,7 @@ void ChromeCrashReporterClient::InitializeCrashReportingForProcess() {
process_type != install_static::kFallbackHandler) { process_type != install_static::kFallbackHandler) {
crash_reporter::SetCrashReporterClient(instance); crash_reporter::SetCrashReporterClient(instance);
// Pass along the user data directory from the browser process. std::wstring user_data_dir;
base::string16 user_data_dir;
if (process_type.empty()) if (process_type.empty())
install_static::GetUserDataDirectory(&user_data_dir, nullptr); install_static::GetUserDataDirectory(&user_data_dir, nullptr);
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#include "chrome/browser/downgrade/user_data_downgrade.h" #include "chrome/browser/downgrade/user_data_downgrade.h"
#include "chrome/child/v8_breakpad_support_win.h" #include "chrome/child/v8_breakpad_support_win.h"
#include "chrome/common/child_process_logging.h" #include "chrome/common/child_process_logging.h"
#include "chrome_elf/chrome_elf_main.h"
#include "sandbox/win/src/sandbox.h" #include "sandbox/win/src/sandbox.h"
#include "ui/base/resource/resource_bundle_win.h" #include "ui/base/resource/resource_bundle_win.h"
#endif #endif
...@@ -390,38 +391,20 @@ struct MainFunction { ...@@ -390,38 +391,20 @@ struct MainFunction {
// Initializes the user data dir. Must be called before InitializeLocalState(). // Initializes the user data dir. Must be called before InitializeLocalState().
void InitializeUserDataDir(base::CommandLine* command_line) { void InitializeUserDataDir(base::CommandLine* command_line) {
#if defined(OS_WIN) #if defined(OS_WIN)
// Reach out to chrome_elf for the truth on the user data directory.
// Note that in tests, this links to chrome_elf_test_stubs.
wchar_t user_data_dir_buf[MAX_PATH], invalid_user_data_dir_buf[MAX_PATH]; wchar_t user_data_dir_buf[MAX_PATH], invalid_user_data_dir_buf[MAX_PATH];
GetUserDataDirectoryThunk(user_data_dir_buf, arraysize(user_data_dir_buf),
using GetUserDataDirectoryThunkFunction = invalid_user_data_dir_buf,
void (*)(wchar_t*, size_t, wchar_t*, size_t); arraysize(invalid_user_data_dir_buf));
HMODULE elf_module = GetModuleHandle(chrome::kChromeElfDllName); base::FilePath user_data_dir(user_data_dir_buf);
if (elf_module) { if (invalid_user_data_dir_buf[0] != 0) {
// If we're in a test, chrome_elf won't be loaded. chrome::SetInvalidSpecifiedUserDataDir(
GetUserDataDirectoryThunkFunction get_user_data_directory_thunk = base::FilePath(invalid_user_data_dir_buf));
reinterpret_cast<GetUserDataDirectoryThunkFunction>( command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
GetProcAddress(elf_module, "GetUserDataDirectoryThunk"));
get_user_data_directory_thunk(
user_data_dir_buf, arraysize(user_data_dir_buf),
invalid_user_data_dir_buf, arraysize(invalid_user_data_dir_buf));
base::FilePath user_data_dir(user_data_dir_buf);
if (invalid_user_data_dir_buf[0] != 0) {
chrome::SetInvalidSpecifiedUserDataDir(
base::FilePath(invalid_user_data_dir_buf));
command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
}
CHECK(PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
user_data_dir, false, true));
} else {
// In tests, just respect the flag if given.
base::FilePath user_data_dir =
command_line->GetSwitchValuePath(switches::kUserDataDir);
if (!user_data_dir.empty()) {
if (user_data_dir.EndsWithSeparator())
user_data_dir = user_data_dir.StripTrailingSeparators();
CHECK(PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
user_data_dir, false, true));
}
} }
CHECK(PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
user_data_dir, false, true));
#else // OS_WIN #else // OS_WIN
base::FilePath user_data_dir = base::FilePath user_data_dir =
command_line->GetSwitchValuePath(switches::kUserDataDir); command_line->GetSwitchValuePath(switches::kUserDataDir);
......
...@@ -93,8 +93,8 @@ void ConfigureCrashReporting(const InstallerState& installer_state) { ...@@ -93,8 +93,8 @@ void ConfigureCrashReporting(const InstallerState& installer_state) {
} }
} }
crash_reporter::InitializeCrashpadWithEmbeddedHandler( crash_reporter::InitializeCrashpadWithEmbeddedHandler(true,
true, "Chrome Installer", std::string()); "Chrome Installer", "");
// Set up the metrics client id (a la child_process_logging::Init()). // Set up the metrics client id (a la child_process_logging::Init()).
std::unique_ptr<metrics::ClientInfo> client_info = std::unique_ptr<metrics::ClientInfo> client_info =
......
...@@ -66,6 +66,22 @@ shared_library("chrome_elf") { ...@@ -66,6 +66,22 @@ shared_library("chrome_elf") {
} }
} }
# For code that isn't Chrome-the browser, like test binaries, these stubs stand
# in for chrome_elf.;
static_library("test_stubs") {
testonly = true
sources = [
"chrome_elf_main.h",
"chrome_elf_test_stubs.cc",
]
deps = [
"//base",
"//chrome/common:constants",
]
}
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
## source sets ## source sets
##------------------------------------------------------------------------------ ##------------------------------------------------------------------------------
...@@ -144,7 +160,7 @@ static_library("crash") { ...@@ -144,7 +160,7 @@ static_library("crash") {
] ]
deps = [ deps = [
":hook_util", ":hook_util",
"//base:base", # This needs to go. DEP of app, crash_keys, client. "//base", # This needs to go. DEP of app, crash_keys, client.
"//base:base_static", # pe_image "//base:base_static", # pe_image
"//chrome/install_static:install_static_util", "//chrome/install_static:install_static_util",
"//components/crash/content/app:app", "//components/crash/content/app:app",
......
...@@ -2,6 +2,7 @@ include_rules = [ ...@@ -2,6 +2,7 @@ include_rules = [
"+sandbox", "+sandbox",
"+breakpad/src/client", "+breakpad/src/client",
"+chrome/app/chrome_crash_reporter_client_win.h", "+chrome/app/chrome_crash_reporter_client_win.h",
"+chrome/common/chrome_switches.h",
"+chrome/common/chrome_version.h", "+chrome/common/chrome_version.h",
"+chrome/install_static", "+chrome/install_static",
"+third_party/crashpad/crashpad/client/crashpad_client.h", "+third_party/crashpad/crashpad/client/crashpad_client.h",
......
...@@ -29,10 +29,10 @@ void SignalChromeElf() { ...@@ -29,10 +29,10 @@ void SignalChromeElf() {
blacklist::ResetBeacon(); blacklist::ResetBeacon();
} }
extern "C" void GetUserDataDirectoryThunk(wchar_t* user_data_dir, void GetUserDataDirectoryThunk(wchar_t* user_data_dir,
size_t user_data_dir_length, size_t user_data_dir_length,
wchar_t* invalid_user_data_dir, wchar_t* invalid_user_data_dir,
size_t invalid_user_data_dir_length) { size_t invalid_user_data_dir_length) {
std::wstring user_data_dir_str, invalid_user_data_dir_str; std::wstring user_data_dir_str, invalid_user_data_dir_str;
bool ret = install_static::GetUserDataDirectory(&user_data_dir_str, bool ret = install_static::GetUserDataDirectory(&user_data_dir_str,
&invalid_user_data_dir_str); &invalid_user_data_dir_str);
......
...@@ -5,8 +5,23 @@ ...@@ -5,8 +5,23 @@
#ifndef CHROME_ELF_CHROME_ELF_MAIN_H_ #ifndef CHROME_ELF_CHROME_ELF_MAIN_H_
#define CHROME_ELF_CHROME_ELF_MAIN_H_ #define CHROME_ELF_CHROME_ELF_MAIN_H_
extern "C" void SignalInitializeCrashReporting(); // These functions are the cross-module import interface to chrome_elf.dll.
extern "C" void SignalChromeElf(); // It is used chrome.exe, chrome.dll and other clients of chrome_elf.
extern "C" void DumpProcessWithoutCrash(); // In tests, these functions are stubbed by implementations in
// chrome_elf_test_stubs.cc.
extern "C" {
void DumpProcessWithoutCrash();
void GetUserDataDirectoryThunk(wchar_t* user_data_dir,
size_t user_data_dir_length,
wchar_t* invalid_user_data_dir,
size_t invalid_user_data_dir_length);
// This function is a temporary workaround for https://crbug.com/655788. We
// need to come up with a better way to initialize crash reporting that can
// happen inside DllMain().
void SignalInitializeCrashReporting();
void SignalChromeElf();
} // extern "C"
#endif // CHROME_ELF_CHROME_ELF_MAIN_H_ #endif // CHROME_ELF_CHROME_ELF_MAIN_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome_elf/chrome_elf_main.h"
// This function is a temporary workaround for https://crbug.com/655788. We
// need to come up with a better way to initialize crash reporting that can
// happen inside DllMain().
void SignalInitializeCrashReporting() {}
void SignalChromeElf() {}
void GetUserDataDirectoryThunk(wchar_t* user_data_dir,
size_t user_data_dir_length,
wchar_t* invalid_user_data_dir,
size_t invalid_user_data_dir_length) {
// In tests, just respect the user-data-dir switch if given.
base::FilePath user_data_dir_path =
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kUserDataDir);
if (!user_data_dir_path.empty() && user_data_dir_path.EndsWithSeparator())
user_data_dir_path = user_data_dir_path.StripTrailingSeparators();
wcsncpy_s(user_data_dir, user_data_dir_length,
user_data_dir_path.value().c_str(), _TRUNCATE);
wcsncpy_s(invalid_user_data_dir, invalid_user_data_dir_length, L"",
_TRUNCATE);
}
...@@ -119,18 +119,8 @@ void InitializeCrashpadImpl(bool initial_client, ...@@ -119,18 +119,8 @@ void InitializeCrashpadImpl(bool initial_client,
} }
// database_path is only valid in the browser process. // database_path is only valid in the browser process.
#if defined(OS_WIN)
internal::PlatformCrashpadInitializationOptions init_options = {};
init_options.user_data_dir = user_data_dir;
base::FilePath database_path = internal::PlatformCrashpadInitialization(
initial_client, browser_process, embedded_handler, &init_options);
#else
DCHECK(user_data_dir.empty());
base::FilePath database_path = internal::PlatformCrashpadInitialization( base::FilePath database_path = internal::PlatformCrashpadInitialization(
initial_client, browser_process, embedded_handler, nullptr); initial_client, browser_process, embedded_handler, user_data_dir);
#endif
crashpad::CrashpadInfo* crashpad_info = crashpad::CrashpadInfo* crashpad_info =
crashpad::CrashpadInfo::GetCrashpadInfo(); crashpad::CrashpadInfo::GetCrashpadInfo();
......
...@@ -120,21 +120,14 @@ void GetPlatformCrashpadAnnotations( ...@@ -120,21 +120,14 @@ void GetPlatformCrashpadAnnotations(
std::map<std::string, std::string>* annotations); std::map<std::string, std::string>* annotations);
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
struct PlatformCrashpadInitializationOptions { // The platform-specific portion of InitializeCrashpad(). On windows, if
#if defined(OS_WIN) // user_data_dir is non-empty, the user data directory will be passed to the
// On Windows, if |user_data_dir| is non-empty, it will be passed to the // handler process for use by Chrome Crashpad extensions.
// handler process for use by Chrome Crashpad extensions.
std::string user_data_dir;
#endif
};
// The platform-specific portion of InitializeCrashpad().
// Returns the database path, if initializing in the browser process. // Returns the database path, if initializing in the browser process.
base::FilePath PlatformCrashpadInitialization( base::FilePath PlatformCrashpadInitialization(bool initial_client,
bool initial_client, bool browser_process,
bool browser_process, bool embedded_handler,
bool embedded_handler, const std::string& user_data_dir);
PlatformCrashpadInitializationOptions* init_options);
} // namespace internal } // namespace internal
......
...@@ -35,7 +35,7 @@ base::FilePath PlatformCrashpadInitialization( ...@@ -35,7 +35,7 @@ base::FilePath PlatformCrashpadInitialization(
bool initial_client, bool initial_client,
bool browser_process, bool browser_process,
bool embedded_handler, bool embedded_handler,
PlatformCrashpadInitializationOptions* init_options) { const std::string& user_data_dir) {
base::FilePath database_path; // Only valid in the browser process. base::FilePath database_path; // Only valid in the browser process.
base::FilePath metrics_path; // Only valid in the browser process. base::FilePath metrics_path; // Only valid in the browser process.
DCHECK(!embedded_handler); // This is not used on Mac. DCHECK(!embedded_handler); // This is not used on Mac.
......
...@@ -56,7 +56,7 @@ base::FilePath PlatformCrashpadInitialization( ...@@ -56,7 +56,7 @@ base::FilePath PlatformCrashpadInitialization(
bool initial_client, bool initial_client,
bool browser_process, bool browser_process,
bool embedded_handler, bool embedded_handler,
PlatformCrashpadInitializationOptions* init_options) { const std::string& user_data_dir) {
base::FilePath database_path; // Only valid in the browser process. base::FilePath database_path; // Only valid in the browser process.
base::FilePath metrics_path; // Only valid in the browser process. base::FilePath metrics_path; // Only valid in the browser process.
...@@ -107,14 +107,11 @@ base::FilePath PlatformCrashpadInitialization( ...@@ -107,14 +107,11 @@ base::FilePath PlatformCrashpadInitialization(
// standalone crashpad_handler.exe (for tests, etc.). // standalone crashpad_handler.exe (for tests, etc.).
std::vector<std::string> start_arguments; std::vector<std::string> start_arguments;
if (embedded_handler) { if (embedded_handler) {
// The command line manipulations here want to be refactored into the
// crash_reporter::CrashReporterClient interface.
// See https://crbug.com/752102.
start_arguments.push_back(std::string("--type=") + start_arguments.push_back(std::string("--type=") +
switches::kCrashpadHandler); switches::kCrashpadHandler);
if (init_options && !init_options->user_data_dir.empty()) { if (!user_data_dir.empty()) {
start_arguments.push_back("--user-data-dir=" + start_arguments.push_back(std::string("--user-data-dir=") +
init_options->user_data_dir); user_data_dir);
} }
// The prefetch argument added here has to be documented in // The prefetch argument added here has to be documented in
// chrome_switches.cc, below the kPrefetchArgument* constants. A constant // chrome_switches.cc, below the kPrefetchArgument* constants. A constant
......
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