Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2c83eb5

Browse files
mralephcommit-bot@chromium.org
authored andcommitted
[vm] Integrate dart binary with Crashpad on Windows.
dart binary would instantiate CrashpadClient if DART_CRASHPAD_HANDLER and DART_CRASHPAD_CRASHES_DIR environment variables are set. - DART_CRASHPAD_HANDLER should contain the path to the crashpad_handler binary that would handle the crash and write minidump; - DART_CRASHPAD_CRASHES_DIR should contain the path to the crashpad database which would be used to store minidumps. Rewrite --copy-crash-dumps support on windows to use Crashpad integration instead of editing Windows registry. Embedding crashpad required to roll a new zlib version because Crashpad depends on the zlib. This version of zlib is buildable with its own BUILD.gn so our custom BUILD.gn is removed. Change-Id: I048aad16b234e1d750f0a24782b04e3b6e19703d Reviewed-on: https://dart-review.googlesource.com/c/81007 Commit-Queue: Vyacheslav Egorov <vegorov@google.com> Reviewed-by: Zach Anderson <zra@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
1 parent b9999b6 commit 2c83eb5

15 files changed

Lines changed: 380 additions & 185 deletions

File tree

DEPS

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ vars = {
144144
"web_socket_channel_tag": "1.0.9",
145145
"WebCore_rev": "fb11e887f77919450e497344da570d780e078bc8",
146146
"yaml_tag": "2.1.15",
147-
"zlib_rev": "c3d0a6190f2f8c924a05ab6cc97b8f975bddd33f",
147+
"zlib_rev": "c44fb7248079cc3d5563b14b3f758aee60d6b415",
148+
"crashpad_rev": "bf327d8ceb6a669607b0dbab5a83a275d03f99ed",
149+
"minichromium_rev": "8d641e30a8b12088649606b912c2bc4947419ccc",
150+
"googletest_rev": "f854f1d27488996dc8a6db3c9453f80b02585e12",
148151
}
149152

150153
deps = {
@@ -376,11 +379,23 @@ deps = {
376379
"@" + Var("web_socket_channel_tag"),
377380
Var("dart_root") + "/third_party/pkg/yaml":
378381
Var("dart_git") + "yaml.git" + "@" + Var("yaml_tag"),
379-
Var("dart_root") + "/third_party/cygwin": {
380-
"url": Var("chromium_git") + "/chromium/deps/cygwin.git" + "@" +
382+
}
383+
384+
deps_os = {
385+
"win": {
386+
Var("dart_root") + "/third_party/cygwin":
387+
Var("chromium_git") + "/chromium/deps/cygwin.git" + "@" +
381388
"c89e446b273697fadf3a10ff1007a97c0b7de6df",
382-
"condition": "checkout_win",
383-
},
389+
Var("dart_root") + "/third_party/crashpad/crashpad":
390+
Var("chromium_git") + "/crashpad/crashpad.git" + "@" +
391+
Var("crashpad_rev"),
392+
Var("dart_root") + "/third_party/mini_chromium/mini_chromium":
393+
Var("chromium_git") + "/chromium/mini_chromium" + "@" +
394+
Var("minichromium_rev"),
395+
Var("dart_root") + "/third_party/googletest":
396+
Var("fuchsia_git") + "/third_party/googletest" + "@" +
397+
Var("googletest_rev"),
398+
}
384399
}
385400

386401
# TODO(iposva): Move the necessary tools so that hooks can be run

build/config/BUILDCONFIG.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ if (is_debug) {
269269
}
270270
_native_compiler_configs += [ _default_optimization_config ]
271271

272+
# zlib's BUILD.gn expects to have this config among default configs.
273+
_native_compiler_configs += [ "//build/config/compiler:default_optimization" ]
274+
272275
# Symbol setup.
273276
_default_symbols_config = "//build/config/compiler:symbols"
274277
_native_compiler_configs += [ _default_symbols_config ]

build/config/compiler/BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,13 @@ config("no_optimize") {
748748
}
749749
}
750750

751+
# These are two named configs that zlib's BUILD.gn expects to exist.
752+
config("default_optimization") {
753+
}
754+
755+
config("optimize_speed") {
756+
}
757+
751758
# Symbols ----------------------------------------------------------------------
752759

753760
config("symbols") {

build/config/win/BUILD.gn

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ config("common_linker_setup") {
7373
# exceeds maximum allowable size (80000000)
7474
# which started happening more regularly after VS2013 Update 4.
7575
"/maxilksize:2147483647",
76-
77-
# Force the creation of a .lib file for all executable() targets.
78-
"/EXPORT:main",
7976
]
8077

8178
# ASLR makes debugging with windbg difficult because Chrome.exe and

build/toolchain/win/BUILD.gn

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ tool_wrapper_path = rebase_path("tool_wrapper.py", root_build_dir)
2222

2323
# Setup the Visual Studio state.
2424
toolchain_data = exec_script("setup_toolchain.py",
25-
[
26-
visual_studio_path,
27-
windows_sdk_path,
28-
visual_studio_runtime_dirs,
29-
current_cpu,
30-
],
31-
"scope")
25+
[
26+
visual_studio_path,
27+
windows_sdk_path,
28+
visual_studio_runtime_dirs,
29+
current_cpu,
30+
],
31+
"scope")
3232

3333
if (vc_bin_dir == "") {
3434
vc_bin_dir = toolchain_data.vc_bin_dir
@@ -164,6 +164,26 @@ template("msvc_toolchain") {
164164
rspfile_content = "{{libs}} {{solibs}} {{inputs_newline}} {{ldflags}}"
165165
}
166166

167+
tool("solink_module") {
168+
dllname = "{{output_dir}}/{{target_output_name}}{{output_extension}}" # e.g. foo.dll
169+
pdbname = "${dllname}.pdb"
170+
rspfile = "${dllname}.rsp"
171+
172+
command = "$python_path $tool_wrapper_path link-wrapper $env False link.exe /nologo /DLL /OUT:$dllname /PDB:$pdbname @$rspfile"
173+
default_output_extension = ".dll"
174+
default_output_dir = "{{root_out_dir}}"
175+
description = "LINK_MODULE(DLL) {{output}}"
176+
outputs = [
177+
dllname,
178+
pdbname,
179+
]
180+
runtime_outputs = outputs
181+
182+
# The use of inputs_newline is to work around a fixed per-line buffer
183+
# size in the linker.
184+
rspfile_content = "{{libs}} {{solibs}} {{inputs_newline}} {{ldflags}}"
185+
}
186+
167187
tool("link") {
168188
binary_output =
169189
"{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
@@ -194,8 +214,7 @@ template("msvc_toolchain") {
194214
}
195215

196216
tool("copy") {
197-
command =
198-
"$python_path $tool_wrapper_path recursive-mirror {{source}} {{output}}"
217+
command = "$python_path $tool_wrapper_path recursive-mirror {{source}} {{output}}"
199218
description = "COPY {{source}} {{output}}"
200219
}
201220

runtime/bin/BUILD.gn

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,24 @@ template("dart_executable") {
675675
deps += [ "//third_party/tcmalloc" ]
676676
}
677677

678+
include_dirs = [
679+
"..",
680+
"//third_party",
681+
]
682+
683+
if (dart_use_crashpad) {
684+
assert(is_win, "dart_use_crashpad is only supported on Windows")
685+
deps += [
686+
"//third_party/crashpad/crashpad/client",
687+
"//third_party/mini_chromium/mini_chromium/base",
688+
689+
# This binary is used to handle crashes of the dart binary.
690+
"//third_party/crashpad/crashpad/handler:crashpad_handler",
691+
]
692+
include_dirs += [ "//third_party/crashpad" ]
693+
defines += [ "DART_USE_CRASHPAD" ]
694+
}
695+
678696
sources = [
679697
"dart_embedder_api_impl.cc",
680698
"error_exit.cc",
@@ -690,11 +708,6 @@ template("dart_executable") {
690708
"vmservice_impl.h",
691709
] + extra_sources
692710

693-
include_dirs = [
694-
"..",
695-
"//third_party",
696-
]
697-
698711
if (is_win) {
699712
ldflags = [ "/EXPORT:Dart_True" ]
700713
} else {

runtime/bin/filter.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ ZLibDeflateFilter::~ZLibDeflateFilter() {
293293

294294
bool ZLibDeflateFilter::Init() {
295295
int window_bits = window_bits_;
296+
if ((raw_ || gzip_) && (window_bits == 8)) {
297+
// zlib deflater does not work with windows size of 8 bits. Old versions
298+
// of zlib would silently upgrade window size to 9 bits, newer versions
299+
// return Z_STREAM_ERROR if window size is 8 bits but the stream header
300+
// is suppressed. To maintain the old behavior upgrade window size here.
301+
// This is safe because you can inflate a stream deflated with zlib
302+
// using 9-bits with 8-bits window.
303+
// For more details see https://crbug.com/691074.
304+
window_bits = 9;
305+
}
296306
if (raw_) {
297307
window_bits = -window_bits;
298308
} else if (gzip_) {

runtime/bin/main.cc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#include "include/dart_embedder_api.h"
1212
#include "include/dart_tools_api.h"
1313

14+
#if defined(DART_USE_CRASHPAD)
15+
#include "crashpad/client/crashpad_client.h"
16+
#include "crashpad/client/crashpad_info.h"
17+
#endif
18+
1419
#include "bin/builtin.h"
1520
#include "bin/console.h"
1621
#include "bin/dartutils.h"
@@ -947,6 +952,45 @@ Dart_Handle GetVMServiceAssetsArchiveCallback() {
947952
static Dart_GetVMServiceAssetsArchive GetVMServiceAssetsArchiveCallback = NULL;
948953
#endif // !defined(NO_OBSERVATORY)
949954

955+
#if defined(DART_USE_CRASHPAD)
956+
#if !defined(HOST_OS_WINDOWS)
957+
#error "Currently we only support Crashpad on Windows"
958+
#endif
959+
960+
static void ConfigureCrashpadClient(crashpad::CrashpadClient* client) {
961+
// DART_CRASHPAD_HANDLER and DART_CRASHPAD_CRASHES_DIR are set by the
962+
// testing framework.
963+
wchar_t* handler = _wgetenv(L"DART_CRASHPAD_HANDLER");
964+
wchar_t* crashes_dir = _wgetenv(L"DART_CRASHPAD_CRASHES_DIR");
965+
if (handler == nullptr || crashes_dir == nullptr) {
966+
return;
967+
}
968+
969+
// Crashpad uses STL so we use it here too even though in general we
970+
// avoid it.
971+
const base::FilePath handler_path{std::wstring(handler)};
972+
const base::FilePath crashes_dir_path{std::wstring(crashes_dir)};
973+
const std::string url("");
974+
std::map<std::string, std::string> annotations;
975+
char* test_name = getenv("DART_TEST_NAME");
976+
if (test_name != nullptr) {
977+
annotations["dart_test_name"] = test_name;
978+
}
979+
980+
std::vector<std::string> arguments;
981+
if (!client->StartHandler(handler_path, crashes_dir_path, crashes_dir_path,
982+
url, annotations, arguments,
983+
/*restartable=*/true,
984+
/*asynchronous_start=*/false)) {
985+
Log::PrintErr("Failed to start the crash handler!\n");
986+
Platform::Exit(kErrorExitCode);
987+
}
988+
crashpad::CrashpadInfo::GetCrashpadInfo()
989+
->set_gather_indirectly_referenced_memory(crashpad::TriState::kEnabled,
990+
/*limit=*/500 * MB);
991+
}
992+
#endif // DART_USE_CRASHPAD
993+
950994
void main(int argc, char** argv) {
951995
char* script_name;
952996
const int EXTRA_VM_ARGUMENTS = 10;
@@ -1010,6 +1054,11 @@ void main(int argc, char** argv) {
10101054
}
10111055
DartUtils::SetEnvironment(Options::environment());
10121056

1057+
#if defined(DART_USE_CRASHPAD)
1058+
crashpad::CrashpadClient crashpad_client;
1059+
ConfigureCrashpadClient(&crashpad_client);
1060+
#endif
1061+
10131062
Loader::InitOnce();
10141063

10151064
#if defined(DART_LINK_APP_SNAPSHOT)

runtime/bin/zlib/BUILD.gn

Lines changed: 0 additions & 54 deletions
This file was deleted.

runtime/runtime_args.gni

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ declare_args() {
4242
# verified at the operating system level.
4343
dart_use_fallback_root_certificates = false
4444

45-
# The BUILD.gn file that we pull from chromium as part of zlib has a
46-
# dependence on //base, which we don't pull in. In a standalone build of the
47-
# VM, we set this to //runtime/bin/zlib where we have a BUILD.gn file without
48-
# a dependence on //base.
45+
# TODO(vegorov): Can we eliminate this?
4946
dart_zlib_path = "//third_party/zlib"
5047

5148
# Whether to link the standalone VM against tcmalloc. The standalone build of
5249
# the VM enables this only for Linux builds.
5350
dart_use_tcmalloc = false
5451

52+
# Whether to link Crashpad library for crash handling. Only supported on
53+
# Windows for now.
54+
dart_use_crashpad = false
55+
5556
# Controls the kind of core snapshot linked into the standalone VM. Using a
5657
# core-jit snapshot breaks the ability to change various flags that affect
5758
# code generation.

0 commit comments

Comments
 (0)