feat_optionally_prevent_calling_v8_enablewebassemblytraphandler.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Shelley Vohr <[email protected]>
  3. Date: Thu, 16 Nov 2023 16:48:10 +0100
  4. Subject: feat: optionally prevent calling V8::EnableWebAssemblyTrapHandler
  5. V8::EnableWebAssemblyTrapHandler can be called only once or it will
  6. hard crash. We need to prevent Node.js calling it in the event it has
  7. already been called.
  8. This should be upstreamed.
  9. diff --git a/src/node.cc b/src/node.cc
  10. index 89e0e5524c2102b86bc5506fe49aa0c6fa0f30c1..e58f28e0f0ff8d61f35ec3c5a69aa37c66c25d78 100644
  11. --- a/src/node.cc
  12. +++ b/src/node.cc
  13. @@ -605,6 +605,7 @@ static void PlatformInit(ProcessInitializationFlags::Flags flags) {
  14. #endif
  15. }
  16. #endif // defined(_WIN32)
  17. + if (!(flags & ProcessInitializationFlags::kNoEnableWasmTrapHandler))
  18. V8::EnableWebAssemblyTrapHandler(false);
  19. #endif // NODE_USE_V8_WASM_TRAP_HANDLER
  20. }
  21. diff --git a/src/node.h b/src/node.h
  22. index 9ac0d5addcdd40d5c91d375b626099b95729548a..3ffc51783b0b6dee1c0f0a37d2f52cb1aec2fa3f 100644
  23. --- a/src/node.h
  24. +++ b/src/node.h
  25. @@ -272,6 +272,10 @@ enum Flags : uint32_t {
  26. // cppgc::InitializeProcess() before creating a Node.js environment
  27. // and call cppgc::ShutdownProcess() before process shutdown.
  28. kNoInitializeCppgc = 1 << 13,
  29. + // Do not initialize the Web Assembly trap handler. This is used by
  30. + // embedders to account for the case where it may already have been
  31. + // initialized - calling it more than once will hard crash.
  32. + kNoEnableWasmTrapHandler = 1 << 14,
  33. // Emulate the behavior of InitializeNodeWithArgs() when passing
  34. // a flags argument to the InitializeOncePerProcess() replacement