From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: John Kleinschmidt <jkleinsc@github.com>
Date: Wed, 8 Jul 2020 10:46:13 -0400
Subject: fix: use proper page size for mac arm64

This fix temporarily sets page size to 16k for mac arm64 so that mksnapshot can run on x64
and generate a mac arm64 snapshot

diff --git a/src/base/platform/platform-posix.cc b/src/base/platform/platform-posix.cc
index ab0d7839a453d87a8404ca791c1022871e8fd606..821a3925e91c229873f75ac024c1b388b4d0c06e 100644
--- a/src/base/platform/platform-posix.cc
+++ b/src/base/platform/platform-posix.cc
@@ -165,9 +165,19 @@ void* Allocate(void* hint, size_t size, OS::MemoryPermission access,
                PageType page_type) {
   int prot = GetProtectionFromMemoryPermission(access);
   int flags = GetFlagsForMemoryPermission(access, page_type);
+#if defined(__APPLE__) && V8_TARGET_ARCH_ARM64 && defined(__x86_64__)
+  // XXX: This logic is simple and leaky as it is only used for mksnapshot.
+  size_t alignment = 16384;
+  void* result = mmap(hint, size + alignment, prot, flags, kMmapFd,
+                      kMmapFdOffset);
+  if (result == MAP_FAILED) return nullptr;
+  return reinterpret_cast<void*>(
+      RoundUp(reinterpret_cast<uintptr_t>(result), alignment));
+#else
   void* result = mmap(hint, size, prot, flags, kMmapFd, kMmapFdOffset);
   if (result == MAP_FAILED) return nullptr;
   return result;
+#endif
 }
 
 #endif  // !V8_OS_FUCHSIA
@@ -224,7 +234,9 @@ void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
 }
 
 int OS::ActivationFrameAlignment() {
-#if V8_TARGET_ARCH_ARM
+#if defined(__APPLE__) && V8_TARGET_ARCH_ARM
+  return 4;
+#elif V8_TARGET_ARCH_ARM
   // On EABI ARM targets this is required for fp correctness in the
   // runtime system.
   return 8;
