|
6 | 6 |
|
7 | 7 | #include <algorithm> |
8 | 8 |
|
| 9 | +#include "base/base_switches.h" |
9 | 10 | #include "base/command_line.h" |
10 | 11 | #include "base/containers/contains.h" |
11 | 12 | #include "content/public/renderer/render_frame.h" |
|
17 | 18 | #include "shell/common/node_includes.h" |
18 | 19 | #include "shell/common/node_util.h" |
19 | 20 | #include "shell/common/options_switches.h" |
20 | | -#include "shell/common/v8_util.h" |
21 | 21 | #include "shell/renderer/electron_render_frame_observer.h" |
22 | 22 | #include "shell/renderer/web_worker_observer.h" |
23 | 23 | #include "third_party/blink/public/common/web_preferences/web_preferences.h" |
|
26 | 26 | #include "third_party/blink/renderer/core/execution_context/execution_context.h" // nogncheck |
27 | 27 | #include "third_party/blink/renderer/core/frame/web_local_frame_impl.h" // nogncheck |
28 | 28 |
|
| 29 | +#if BUILDFLAG(IS_LINUX) && (defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM64)) |
| 30 | +#define ENABLE_WEB_ASSEMBLY_TRAP_HANDLER_LINUX |
| 31 | +#include "components/crash/core/app/crashpad.h" // nogncheck |
| 32 | +#include "content/public/common/content_switches.h" |
| 33 | +#include "v8/include/v8-wasm-trap-handler-posix.h" |
| 34 | +#endif |
| 35 | + |
29 | 36 | namespace electron { |
30 | 37 |
|
31 | 38 | ElectronRendererClient::ElectronRendererClient() |
@@ -240,9 +247,45 @@ void ElectronRendererClient::WillDestroyWorkerContextOnWorkerThread( |
240 | 247 | } |
241 | 248 |
|
242 | 249 | void ElectronRendererClient::SetUpWebAssemblyTrapHandler() { |
243 | | - // content/renderer layer already takes care of the feature flag detection |
244 | | - // so no need to check for features::kWebAssemblyTrapHandler here. |
245 | | - electron::SetUpWebAssemblyTrapHandler(); |
| 250 | +// See CL:5372409 - copied from ShellContentRendererClient. |
| 251 | +#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) |
| 252 | + // Mac and Windows use the default implementation (where the default v8 trap |
| 253 | + // handler gets set up). |
| 254 | + ContentRendererClient::SetUpWebAssemblyTrapHandler(); |
| 255 | + return; |
| 256 | +#elif defined(ENABLE_WEB_ASSEMBLY_TRAP_HANDLER_LINUX) |
| 257 | + const bool crash_reporter_enabled = |
| 258 | + crash_reporter::GetHandlerSocket(nullptr, nullptr); |
| 259 | + |
| 260 | + if (crash_reporter_enabled) { |
| 261 | + // If either --enable-crash-reporter or --enable-crash-reporter-for-testing |
| 262 | + // is enabled it should take care of signal handling for us, use the default |
| 263 | + // implementation which doesn't register an additional handler. |
| 264 | + ContentRendererClient::SetUpWebAssemblyTrapHandler(); |
| 265 | + return; |
| 266 | + } |
| 267 | + |
| 268 | + const bool use_v8_default_handler = |
| 269 | + base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 270 | + ::switches::kDisableInProcessStackTraces); |
| 271 | + |
| 272 | + if (use_v8_default_handler) { |
| 273 | + // There is no signal handler yet, but it's okay if v8 registers one. |
| 274 | + v8::V8::EnableWebAssemblyTrapHandler(/*use_v8_signal_handler=*/true); |
| 275 | + return; |
| 276 | + } |
| 277 | + |
| 278 | + if (base::debug::SetStackDumpFirstChanceCallback( |
| 279 | + v8::TryHandleWebAssemblyTrapPosix)) { |
| 280 | + // Crashpad and Breakpad are disabled, but the in-process stack dump |
| 281 | + // handlers are enabled, so set the callback on the stack dump handlers. |
| 282 | + v8::V8::EnableWebAssemblyTrapHandler(/*use_v8_signal_handler=*/false); |
| 283 | + return; |
| 284 | + } |
| 285 | + |
| 286 | + // As the registration of the callback failed, we don't enable trap |
| 287 | + // handlers. |
| 288 | +#endif // defined(ENABLE_WEB_ASSEMBLY_TRAP_HANDLER_LINUX) |
246 | 289 | } |
247 | 290 |
|
248 | 291 | node::Environment* ElectronRendererClient::GetEnvironment( |
|
0 commit comments