android_webview
apps
ash
base
blink
build
build_overrides
cc
chrome
chrome_cleaner
chrome_elf
chromecast
chromeos
cloud_print
components
content
app
browser
child
common
gpu
ppapi_plugin
public
renderer
accessibility
android
appcache
blob_storage
browser_plugin
cache_storage
device_sensors
devtools
dom_storage
fetchers
fileapi
gpu
image_capture
image_downloader
indexed_db
input
installedapp
java
loader
manifest
media
media_capture_from_element
media_recorder
mojo
mus
notifications
origin_trials
p2p
pepper
presentation
push_messaging
service_worker
shared_worker
BUILD.gn
DEPS
OWNERS
blink_platform_audio_hardware_browsertest.cc
bmp_image_decoder_unittest.cc
browser_render_view_browsertest.cc
categorized_worker_pool.cc
categorized_worker_pool.h
categorized_worker_pool_unittest.cc
child_frame_compositing_helper.cc
child_frame_compositing_helper.h
child_frame_compositing_helper_unittest.cc
child_frame_compositor.h
child_message_filter.cc
child_message_filter.h
clipboard_utils.cc
clipboard_utils.h
content_security_policy_util.cc
content_security_policy_util.h
context_menu_params_builder.cc
context_menu_params_builder.h
crash_helpers.cc
crash_helpers.h
cursor_utils.cc
cursor_utils.h
dom_automation_controller.cc
dom_automation_controller.h
dom_serializer_browsertest.cc
drop_data_builder.cc
drop_data_builder.h
effective_connection_type_helper.cc
effective_connection_type_helper.h
external_popup_menu.cc
external_popup_menu.h
external_popup_menu_browsertest.cc
file_info_util.cc
file_info_util.h
frame_blame_context.cc
frame_blame_context.h
frame_owner_properties.cc
frame_owner_properties.h
gamepad_shared_memory_reader.cc
gamepad_shared_memory_reader.h
gin_browsertest.cc
history_entry.cc
history_entry.h
history_serialization.cc
history_serialization.h
ico_image_decoder_unittest.cc
idle_user_detector.cc
idle_user_detector.h
ime_event_guard.cc
ime_event_guard.h
in_process_renderer_thread.cc
in_process_renderer_thread.h
internal_document_state_data.cc
internal_document_state_data.h
layout_test_dependencies.cc
layout_test_dependencies.h
menu_item_builder.cc
menu_item_builder.h
message_delivery_policy.h
mouse_lock_dispatcher.cc
mouse_lock_dispatcher.h
mouse_lock_dispatcher_browsertest.cc
navigation_state_impl.cc
navigation_state_impl.h
net_info_helper.cc
net_info_helper.h
peripheral_content_heuristic.cc
peripheral_content_heuristic.h
peripheral_content_heuristic_unittest.cc
render_frame_impl.cc
render_frame_impl.h
render_frame_impl_browsertest.cc
render_frame_metadata_observer_impl.cc
render_frame_metadata_observer_impl.h
render_frame_proxy.cc
render_frame_proxy.h
render_process.cc
render_process.h
render_process_impl.cc
render_process_impl.h
render_thread_impl.cc
render_thread_impl.h
render_thread_impl_browsertest.cc
render_thread_impl_discardable_memory_browsertest.cc
render_thread_impl_unittest.cc
render_view_browsertest.cc
render_view_browsertest_mac.mm
render_view_fuchsia.cc
render_view_impl.cc
render_view_impl.h
render_view_impl_android.cc
render_view_linux.cc
render_view_win.cc
render_widget.cc
render_widget.h
render_widget_browsertest.cc
render_widget_fullscreen_pepper.cc
render_widget_fullscreen_pepper.h
render_widget_mouse_lock_dispatcher.cc
render_widget_mouse_lock_dispatcher.h
render_widget_owner_delegate.h
render_widget_unittest.cc
renderer_blink_platform_impl.cc
renderer_blink_platform_impl.h
renderer_main.cc
renderer_main_platform_delegate.h
renderer_main_platform_delegate_android.cc
renderer_main_platform_delegate_fuchsia.cc
renderer_main_platform_delegate_linux.cc
renderer_main_platform_delegate_mac.mm
renderer_main_platform_delegate_win.cc
renderer_webapplicationcachehost_impl.cc
renderer_webapplicationcachehost_impl.h
renderer_webcookiejar_impl.cc
renderer_webcookiejar_impl.h
resizing_mode_selector.cc
resizing_mode_selector.h
resource_timing_info_conversions.cc
resource_timing_info_conversions.h
sad_plugin.cc
sad_plugin.h
sandbox_mac_v2_unittest.mm
savable_resources.cc
savable_resources.h
savable_resources_browsertest.cc
seccomp_sandbox_status_android.cc
seccomp_sandbox_status_android.h
shared_memory_seqlock_reader.cc
shared_memory_seqlock_reader.h
skia_benchmarking_extension.cc
skia_benchmarking_extension.h
skia_benchmarking_extension_unittest.cc
speech_recognition_dispatcher.cc
speech_recognition_dispatcher.h
stats_collection_controller.cc
stats_collection_controller.h
stats_collection_observer.cc
stats_collection_observer.h
storage_util.cc
storage_util.h
text_input_client_observer.cc
text_input_client_observer.h
theme_helper_mac.h
theme_helper_mac.mm
top_level_blame_context.cc
top_level_blame_context.h
v8_value_converter_impl.cc
v8_value_converter_impl.h
v8_value_converter_impl_unittest.cc
visual_state_browsertest.cc
web_database_observer_impl.cc
web_database_observer_impl.h
web_frame_utils.cc
web_frame_utils.h
web_ui_extension.cc
web_ui_extension.h
web_ui_extension_data.cc
web_ui_extension_data.h
webclipboard_impl_browsertest.cc
webfileutilities_impl.cc
webfileutilities_impl.h
webgraphicscontext3d_provider_impl.cc
webgraphicscontext3d_provider_impl.h
webpublicsuffixlist_impl.cc
webpublicsuffixlist_impl.h
webscrollbarbehavior_impl_aura.cc
webscrollbarbehavior_impl_aura.h
webscrollbarbehavior_impl_mac.h
webscrollbarbehavior_impl_mac.mm
worker_thread_message_filter.cc
worker_thread_message_filter.h
worker_thread_registry.cc
worker_thread_registry.h
worker_thread_registry_unittest.cc
shell
test
utility
zygote
BUILD.gn
DEPS
OWNERS
README.md
content_resources.grd
courgette
crypto
dbus
device
docs
extensions
gin
google_apis
google_update
gpu
headless
infra
ios
ipc
jingle
mash
media
mojo
native_client_sdk
net
notification_helper
pdf
ppapi
printing
remoting
rlz
sandbox
services
skia
sql
storage
styleguide
testing
third_party
tools
ui
url
webrunner
.clang-format
.eslintrc.js
.git-blame-ignore-revs
.gitattributes
.gitignore
.gn
.vpython
AUTHORS
BUILD.gn
CODE_OF_CONDUCT.md
DEPS
ENG_REVIEW_OWNERS
LICENSE
LICENSE.chromium_os
OWNERS
PRESUBMIT.py
PRESUBMIT_test.py
PRESUBMIT_test_mocks.py
README.md
WATCHLISTS
codereview.settings

V8's side of this function fails safely, leaving trap handlers disabled and relying on bounds checks. There's no reason to make this a fatal failure here. This also lets us remove the special cases around sanitizers, operating systems, and architectures, because V8 knows what configurations are supported for trap handlers. Change-Id: I461af9590f336e912f94e5cf169f50ddd985b839 Reviewed-on: https://chromium-review.googlesource.com/988257 Reviewed-by: Kentaro Hara <haraken@chromium.org> Commit-Queue: Eric Holk <eholk@chromium.org> Cr-Commit-Position: refs/heads/master@{#547534}
222 lines
8.4 KiB
C++
222 lines
8.4 KiB
C++
// Copyright (c) 2012 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 "content/renderer/render_process_impl.h"
|
|
|
|
#include "build/build_config.h"
|
|
|
|
#if defined(OS_WIN)
|
|
#include <windows.h>
|
|
#include <objidl.h>
|
|
#include <mlang.h>
|
|
#endif
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <algorithm>
|
|
#include <utility>
|
|
|
|
#include "base/base_switches.h"
|
|
#include "base/bind.h"
|
|
#include "base/command_line.h"
|
|
#include "base/compiler_specific.h"
|
|
#include "base/debug/crash_logging.h"
|
|
#include "base/debug/stack_trace.h"
|
|
#include "base/feature_list.h"
|
|
#include "base/memory/ptr_util.h"
|
|
#include "base/sys_info.h"
|
|
#include "base/task_scheduler/initialization_util.h"
|
|
#include "base/time/time.h"
|
|
#include "content/common/task_scheduler.h"
|
|
#include "content/public/common/bindings_policy.h"
|
|
#include "content/public/common/content_client.h"
|
|
#include "content/public/common/content_features.h"
|
|
#include "content/public/common/content_switches.h"
|
|
#include "content/public/renderer/content_renderer_client.h"
|
|
#include "services/service_manager/embedder/switches.h"
|
|
#include "third_party/WebKit/public/web/WebFrame.h"
|
|
#include "v8/include/v8.h"
|
|
|
|
#if defined(OS_WIN)
|
|
#include "base/win/win_util.h"
|
|
#endif
|
|
|
|
namespace {
|
|
|
|
void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) {
|
|
if (base::FeatureList::IsEnabled(feature)) {
|
|
v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
|
|
}
|
|
}
|
|
|
|
void SetV8FlagIfNotFeature(const base::Feature& feature, const char* v8_flag) {
|
|
if (!base::FeatureList::IsEnabled(feature)) {
|
|
v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
|
|
}
|
|
}
|
|
|
|
void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) {
|
|
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
|
|
v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
|
|
}
|
|
}
|
|
|
|
std::unique_ptr<base::TaskScheduler::InitParams>
|
|
GetDefaultTaskSchedulerInitParams() {
|
|
|
|
constexpr int kMaxNumThreadsInBackgroundPool = 1;
|
|
constexpr int kMaxNumThreadsInBackgroundBlockingPool = 1;
|
|
constexpr int kMaxNumThreadsInForegroundPoolLowerBound = 2;
|
|
constexpr int kMaxNumThreadsInForegroundBlockingPool = 1;
|
|
constexpr auto kSuggestedReclaimTime = base::TimeDelta::FromSeconds(30);
|
|
|
|
return std::make_unique<base::TaskScheduler::InitParams>(
|
|
base::SchedulerWorkerPoolParams(kMaxNumThreadsInBackgroundPool,
|
|
kSuggestedReclaimTime),
|
|
base::SchedulerWorkerPoolParams(kMaxNumThreadsInBackgroundBlockingPool,
|
|
kSuggestedReclaimTime),
|
|
base::SchedulerWorkerPoolParams(
|
|
std::max(
|
|
kMaxNumThreadsInForegroundPoolLowerBound,
|
|
content::GetMinThreadsInRendererTaskSchedulerForegroundPool()),
|
|
kSuggestedReclaimTime),
|
|
base::SchedulerWorkerPoolParams(kMaxNumThreadsInForegroundBlockingPool,
|
|
kSuggestedReclaimTime));
|
|
}
|
|
|
|
#if DCHECK_IS_CONFIGURABLE
|
|
void V8DcheckCallbackHandler(const char* file, int line, const char* message) {
|
|
// TODO(siggi): Set a crash key or a breadcrumb so the fact that we hit a
|
|
// V8 DCHECK gets out in the crash report.
|
|
::logging::LogMessage(file, line, logging::LOG_DCHECK).stream() << message;
|
|
}
|
|
#endif // DCHECK_IS_CONFIGURABLE
|
|
|
|
} // namespace
|
|
|
|
namespace content {
|
|
|
|
RenderProcessImpl::RenderProcessImpl(
|
|
std::unique_ptr<base::TaskScheduler::InitParams> task_scheduler_init_params)
|
|
: RenderProcess("Renderer", std::move(task_scheduler_init_params)),
|
|
enabled_bindings_(0) {
|
|
#if DCHECK_IS_CONFIGURABLE
|
|
// Some official builds ship with DCHECKs compiled in. Failing DCHECKs then
|
|
// are either fatal or simply log the error, based on a feature flag.
|
|
// Make sure V8 follows suit by setting a Dcheck handler that forwards to
|
|
// the Chrome base logging implementation.
|
|
v8::V8::SetDcheckErrorHandler(&V8DcheckCallbackHandler);
|
|
|
|
if (!base::FeatureList::IsEnabled(base::kDCheckIsFatalFeature)) {
|
|
// These V8 flags default on in this build configuration. This triggers
|
|
// additional verification and code generation, which both slows down V8,
|
|
// and can lead to fatal CHECKs. Turn these flags down to get something
|
|
// closer to V8s normal performance and behavior.
|
|
constexpr char kDisabledFlags[] =
|
|
"--noturbo_verify "
|
|
"--noverify_csa "
|
|
"--noturbo_verify_allocation "
|
|
"--nodebug_code";
|
|
|
|
v8::V8::SetFlagsFromString(kDisabledFlags, sizeof(kDisabledFlags));
|
|
}
|
|
#endif // DCHECK_IS_CONFIGURABLE
|
|
|
|
if (base::SysInfo::IsLowEndDevice()) {
|
|
std::string optimize_flag("--optimize-for-size");
|
|
v8::V8::SetFlagsFromString(optimize_flag.c_str(),
|
|
static_cast<int>(optimize_flag.size()));
|
|
}
|
|
|
|
SetV8FlagIfHasSwitch(switches::kDisableJavaScriptHarmonyShipping,
|
|
"--noharmony-shipping");
|
|
SetV8FlagIfHasSwitch(switches::kJavaScriptHarmony, "--harmony");
|
|
SetV8FlagIfFeature(features::kModuleScriptsDynamicImport,
|
|
"--harmony-dynamic-import");
|
|
SetV8FlagIfFeature(features::kModuleScriptsImportMetaUrl,
|
|
"--harmony-import-meta");
|
|
SetV8FlagIfFeature(features::kAsmJsToWebAssembly, "--validate-asm");
|
|
SetV8FlagIfNotFeature(features::kAsmJsToWebAssembly, "--no-validate-asm");
|
|
SetV8FlagIfNotFeature(features::kWebAssembly,
|
|
"--wasm-disable-structured-cloning");
|
|
|
|
SetV8FlagIfFeature(features::kV8VmFuture, "--future");
|
|
SetV8FlagIfNotFeature(features::kV8VmFuture, "--no-future");
|
|
SetV8FlagIfFeature(features::kSharedArrayBuffer,
|
|
"--harmony-sharedarraybuffer");
|
|
SetV8FlagIfNotFeature(features::kSharedArrayBuffer,
|
|
"--no-harmony-sharedarraybuffer");
|
|
|
|
SetV8FlagIfNotFeature(features::kWebAssemblyTrapHandler,
|
|
"--no-wasm-trap-handler");
|
|
SetV8FlagIfFeature(features::kArrayPrototypeValues,
|
|
"--harmony-array-prototype-values");
|
|
SetV8FlagIfNotFeature(features::kArrayPrototypeValues,
|
|
"--no-harmony-array-prototype-values");
|
|
#if defined(OS_LINUX) && defined(ARCH_CPU_X86_64) && !defined(OS_ANDROID)
|
|
if (base::FeatureList::IsEnabled(features::kWebAssemblyTrapHandler)) {
|
|
bool use_v8_signal_handler = false;
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
|
if (!command_line->HasSwitch(
|
|
service_manager::switches::kDisableInProcessStackTraces)) {
|
|
base::debug::SetStackDumpFirstChanceCallback(v8::V8::TryHandleSignal);
|
|
} else if (!command_line->HasSwitch(switches::kEnableCrashReporter) &&
|
|
!command_line->HasSwitch(
|
|
switches::kEnableCrashReporterForTesting)) {
|
|
// If we are using WebAssembly trap handling but both Breakpad and
|
|
// in-process stack traces are disabled then there will be no signal
|
|
// handler. In this case, we fall back on V8's default handler
|
|
// (https://crbug.com/798150).
|
|
use_v8_signal_handler = true;
|
|
}
|
|
// TODO(eholk): report UMA stat for how often this succeeds
|
|
v8::V8::EnableWebAssemblyTrapHandler(use_v8_signal_handler);
|
|
}
|
|
#endif
|
|
|
|
const base::CommandLine& command_line =
|
|
*base::CommandLine::ForCurrentProcess();
|
|
|
|
if (command_line.HasSwitch(switches::kJavaScriptFlags)) {
|
|
std::string flags(
|
|
command_line.GetSwitchValueASCII(switches::kJavaScriptFlags));
|
|
v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size()));
|
|
}
|
|
|
|
if (command_line.HasSwitch(switches::kDomAutomationController))
|
|
enabled_bindings_ |= BINDINGS_POLICY_DOM_AUTOMATION;
|
|
if (command_line.HasSwitch(switches::kStatsCollectionController))
|
|
enabled_bindings_ |= BINDINGS_POLICY_STATS_COLLECTION;
|
|
}
|
|
|
|
RenderProcessImpl::~RenderProcessImpl() {
|
|
#ifndef NDEBUG
|
|
int count = blink::WebFrame::InstanceCount();
|
|
if (count)
|
|
DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES";
|
|
#endif
|
|
|
|
GetShutDownEvent()->Signal();
|
|
}
|
|
|
|
std::unique_ptr<RenderProcess> RenderProcessImpl::Create() {
|
|
auto task_scheduler_init_params =
|
|
content::GetContentClient()->renderer()->GetTaskSchedulerInitParams();
|
|
if (!task_scheduler_init_params)
|
|
task_scheduler_init_params = GetDefaultTaskSchedulerInitParams();
|
|
|
|
return base::WrapUnique(
|
|
new RenderProcessImpl(std::move(task_scheduler_init_params)));
|
|
}
|
|
|
|
void RenderProcessImpl::AddBindings(int bindings) {
|
|
enabled_bindings_ |= bindings;
|
|
}
|
|
|
|
int RenderProcessImpl::GetEnabledBindings() const {
|
|
return enabled_bindings_;
|
|
}
|
|
|
|
} // namespace content
|