From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Mon, 27 Nov 2023 17:23:29 +0100
Subject: build: only create cppgc heap on non-32 bit platforms

Node.js crashes during heap marking when using cppgc on 32 bit platforms. Disable for now.

Crash occurs in the following stack:
* MarkingVisitorBase<ConcreteVisitor>::VisitEmbedderTracingSubClassWithEmbedderTracing
* MarkingWorklists::Local::PushExtractedWrapper
* CppMarkingState::MarkAndPush
* CppMarkingState::MarkAndPush
* WrappableInfo::From
* Crash

See https://gist.github.com/codebytere/275ec8923253fd6559b3d36115f7b31b for more.

This should be fixed and re-enabled on all platforms.

diff --git a/BUILD.gn b/BUILD.gn
index 541e7d2b8ee05677b64a3ea39c1422560fd5df75..8d63fea3304b36654992fe718ceeb3931ef86d39 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -181,6 +181,10 @@ config("node_internal_config") {
   }
   defines += [ "NODE_ARCH=\"$node_arch\"" ]
 
+  if (target_cpu == "x86" || target_cpu == "arm") {
+    defines += [ "NODE_RUNNING_32_BIT" ]
+  }
+
   if (target_os == "win") {
     node_platform = "win32"
   } else if (target_os == "mac") {
diff --git a/src/env.cc b/src/env.cc
index a429d5526d0af66eef94132b196e42994e3f6448..ba575a04340b91709fb6c8710ab160a4ca1f8b77 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -546,7 +546,8 @@ IsolateData::IsolateData(Isolate* isolate,
     // for embedder ID, V8 could accidentally enable cppgc on them. So
     // safe guard against this.
     DCHECK_NE(descriptor.wrappable_type_index, BaseObject::kSlot);
-  } else {
+  } else  {
+#if !defined(NODE_RUNNING_32_BIT)
     cpp_heap_ = CppHeap::Create(
         platform,
         CppHeapCreateParams{
@@ -554,6 +555,7 @@ IsolateData::IsolateData(Isolate* isolate,
             WrapperDescriptor(
                 BaseObject::kEmbedderType, BaseObject::kSlot, cppgc_id)});
     isolate->AttachCppHeap(cpp_heap_.get());
+#endif
   }
   // We do not care about overflow since we just want this to be different
   // from the cppgc id.
