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 2ce1e8a7dcca2ba153d387d11970c72b5f43c167..590303d1b78e2c28d7c3338196b12fcf14f65b28 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 38802b1e9acf9b3e99fdc4f39770e896393befe3..0cb9c73a6cc24cbd547936e9cf8dd67c4723bfa2 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -585,7 +585,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{
@@ -593,6 +594,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.
