Skip to content

Commit

Permalink
Simulator should have a 48-bit address space
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=258999
rdar://111137299

Reviewed by Yusuke Suzuki.

If you allocate a lot of memory in the simulator, eventually you will
fail one of the CompactPtr assertions because the simulator actually
acts like macOS with respect to virtual memory.

Mach's max address size is defined incorrectly for this case, so we guard
against that on our side.

* Source/JavaScriptCore/runtime/StructureID.h:
* Source/WTF/wtf/CompactPtr.h:
* Source/WTF/wtf/PlatformHave.h:
* Source/WTF/wtf/PlatformOS.h:
* Source/bmalloc/bmalloc/BPlatform.h:
* Source/bmalloc/libpas/src/libpas/pas_root.c:

Canonical link: https://commits.webkit.org/265930@main
  • Loading branch information
Justin Michaud committed Jul 11, 2023
1 parent 6e20509 commit fa76f5e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/StructureID.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Structure;
#if CPU(ADDRESS64)

// We would like to define this value in PlatformEnable.h, but it is not possible since the following is relying on MACH_VM_MAX_ADDRESS.
#if CPU(ARM64) && OS(DARWIN)
#if CPU(ARM64) && OS(DARWIN) && !PLATFORM(IOS_FAMILY_SIMULATOR)
#if MACH_VM_MAX_ADDRESS_RAW < (1ULL << 36)
#define ENABLE_STRUCTURE_ID_WITH_SHIFT 1
static_assert(MACH_VM_MAX_ADDRESS_RAW == MACH_VM_MAX_ADDRESS);
Expand Down
3 changes: 2 additions & 1 deletion Source/WTF/wtf/CompactPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <wtf/Forward.h>
#include <wtf/GetPtr.h>
#include <wtf/HashFunctions.h>
#include <wtf/Platform.h>
#include <wtf/RawPtrTraits.h>
#include <wtf/StdLibExtras.h>

Expand All @@ -40,7 +41,7 @@
namespace WTF {

#if CPU(ADDRESS64)
#if CPU(ARM64) && OS(DARWIN)
#if CPU(ARM64) && OS(DARWIN) && !PLATFORM(IOS_FAMILY_SIMULATOR)
#if MACH_VM_MAX_ADDRESS_RAW < (1ULL << 36)
#define HAVE_36BIT_ADDRESS 1
#endif
Expand Down
11 changes: 11 additions & 0 deletions Source/WTF/wtf/PlatformHave.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
#define HAVE_ARM_IDIV_INSTRUCTIONS 1
#endif

#if CPU(ADDRESS64)
#if OS(DARWIN) && !PLATFORM(IOS_FAMILY_SIMULATOR)
#define WTF_OS_CONSTANT_EFFECTIVE_ADDRESS_WIDTH (WTF::getMSBSetConstexpr(MACH_VM_MAX_ADDRESS) + 1)
#else
/* We strongly assume that effective address width is <= 48 in 64bit architectures (e.g. NaN boxing). */
#define WTF_OS_CONSTANT_EFFECTIVE_ADDRESS_WIDTH 48
#endif
#else
#define WTF_OS_CONSTANT_EFFECTIVE_ADDRESS_WIDTH 32
#endif

#if PLATFORM(COCOA)
#define HAVE_AUDIT_TOKEN 1
#endif
Expand Down
13 changes: 0 additions & 13 deletions Source/WTF/wtf/PlatformOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,6 @@
#define WTF_OS_UNIX 1
#endif


#if CPU(ADDRESS64)
#if OS(DARWIN)
#define WTF_OS_CONSTANT_EFFECTIVE_ADDRESS_WIDTH (WTF::getMSBSetConstexpr(MACH_VM_MAX_ADDRESS) + 1)
#else
/* We strongly assume that effective address width is <= 48 in 64bit architectures (e.g. NaN boxing). */
#define WTF_OS_CONSTANT_EFFECTIVE_ADDRESS_WIDTH 48
#endif
#else
#define WTF_OS_CONSTANT_EFFECTIVE_ADDRESS_WIDTH 32
#endif


/* Asserts, invariants for macro definitions */

#define WTF_OS_WIN ERROR "USE WINDOWS WITH OS NOT WIN"
Expand Down
2 changes: 1 addition & 1 deletion Source/bmalloc/bmalloc/BPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
#endif

#if BCPU(ADDRESS64)
#if BOS(DARWIN)
#if BOS(DARWIN) && !BPLATFORM(IOS_FAMILY_SIMULATOR)
#define BOS_EFFECTIVE_ADDRESS_WIDTH (bmalloc::getMSBSetConstexpr(MACH_VM_MAX_ADDRESS) + 1)
#else
/* We strongly assume that effective address width is <= 48 in 64bit architectures (e.g. NaN boxing). */
Expand Down
2 changes: 1 addition & 1 deletion Source/bmalloc/libpas/src/libpas/pas_root.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ pas_root* pas_root_ensure_for_libmalloc_enumeration(void)
#define PAS_SYSTEM_COMPACT_POINTER_SIZE 4

#if PAS_CPU(ADDRESS64)
#if PAS_ARM64 && PAS_OS(DARWIN)
#if PAS_ARM64 && PAS_OS(DARWIN) && !PAS_PLATFORM(IOS_FAMILY_SIMULATOR)
#if MACH_VM_MAX_ADDRESS_RAW < (1ULL << 36)
#define PAS_HAVE_36BIT_ADDRESS 1
#endif
Expand Down

0 comments on commit fa76f5e

Please sign in to comment.