enable_crashpad_linux_node_processes.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: VerteDinde <[email protected]>
  3. Date: Sun, 20 Nov 2022 21:45:20 -0800
  4. Subject: fix: enable crashpad for ELECTRON_RUN_AS_NODE linux processes
  5. Passes the crashpad handler PID and crashdump signal file descriptor
  6. to child processes spawned with `ELECTRON_RUN_AS_NODE` which is used
  7. by the crashpad client to connect with the handler process.
  8. diff --git a/lib/child_process.js b/lib/child_process.js
  9. index bb27670112c1ea42c7ff00883fe4b684544d9cd4..4d4da798ce59ce42e42d1f05fccf07699c033d46 100644
  10. --- a/lib/child_process.js
  11. +++ b/lib/child_process.js
  12. @@ -61,6 +61,7 @@ let debug = require('internal/util/debuglog').debuglog(
  13. );
  14. const { Buffer } = require('buffer');
  15. const { Pipe, constants: PipeConstants } = internalBinding('pipe_wrap');
  16. +const { getCrashdumpSignalFD, getCrashpadHandlerPID } = process._linkedBinding('electron_common_crashpad_support');
  17. const {
  18. AbortError,
  19. @@ -153,7 +154,6 @@ function fork(modulePath, args = [], options) {
  20. ArrayPrototypeSplice(execArgv, index - 1, 2);
  21. }
  22. }
  23. -
  24. args = [...execArgv, modulePath, ...args];
  25. if (typeof options.stdio === 'string') {
  26. @@ -609,6 +609,22 @@ function normalizeSpawnArguments(file, args, options) {
  27. 'options.windowsVerbatimArguments');
  28. }
  29. + const env = options.env || process.env;
  30. +
  31. + if ((process.platform === 'linux') &&
  32. + ObjectPrototypeHasOwnProperty(env, 'ELECTRON_RUN_AS_NODE') &&
  33. + (file === process.execPath)) {
  34. + // On Linux, pass the file descriptor which crashpad handler process
  35. + // uses to monitor the child process and PID of the handler process.
  36. + // https://source.chromium.org/chromium/chromium/src/+/110.0.5415.0:components/crash/core/app/crashpad_linux.cc;l=199-206
  37. + const fd = getCrashdumpSignalFD();
  38. + const pid = getCrashpadHandlerPID();
  39. + if (fd !== -1 && pid !== -1) {
  40. + env.CRASHDUMP_SIGNAL_FD = fd;
  41. + env.CRASHPAD_HANDLER_PID = pid;
  42. + }
  43. + }
  44. +
  45. if (options.shell) {
  46. validateArgumentNullCheck(options.shell, 'options.shell');
  47. const command = ArrayPrototypeJoin([file, ...args], ' ');
  48. @@ -642,7 +658,6 @@ function normalizeSpawnArguments(file, args, options) {
  49. ArrayPrototypeUnshift(args, file);
  50. }
  51. - const env = options.env || process.env;
  52. const envPairs = [];
  53. // process.env.NODE_V8_COVERAGE always propagates, making it possible to