enable_crashpad_linux_node_processes.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 9dd33ecbac3a5d516f9bff76fdbe1a8aece531f2..0464ecc7b53389cdff97a7fe4cb01582e8b72dbb 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. @@ -162,7 +163,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. @@ -625,6 +625,21 @@ function normalizeSpawnArguments(file, args, options) {
  27. 'options.windowsVerbatimArguments');
  28. }
  29. + if (process.platform === 'linux') {
  30. + if (ObjectPrototypeHasOwnProperty(options.env || process.env, 'ELECTRON_RUN_AS_NODE') &&
  31. + (file === process.execPath)) {
  32. + // On Linux, pass the file descriptor which crashpad handler process
  33. + // uses to monitor the child process and PID of the handler process.
  34. + // https://source.chromium.org/chromium/chromium/src/+/110.0.5415.0:components/crash/core/app/crashpad_linux.cc;l=199-206
  35. + const fd = getCrashdumpSignalFD();
  36. + const pid = getCrashpadHandlerPID();
  37. + if (fd !== -1 && pid !== -1) {
  38. + options.env.CRASHDUMP_SIGNAL_FD = fd;
  39. + options.env.CRASHPAD_HANDLER_PID = pid;
  40. + }
  41. + }
  42. + }
  43. +
  44. if (options.shell) {
  45. validateArgumentNullCheck(options.shell, 'options.shell');
  46. const command = ArrayPrototypeJoin([file, ...args], ' ');