bstinson / rpms / mozjs60

Forked from rpms/mozjs60 5 years ago
Clone

Blame SOURCES/enddianness.patch

e43f4b
From f66d410f3ba767efb91c6b9545d373267cd975f2 Mon Sep 17 00:00:00 2001
e43f4b
From: rpm-build <rpm-build>
e43f4b
Date: Sat, 7 Sep 2019 20:43:40 +0200
e43f4b
Subject: [PATCH] enddianness.patch
e43f4b
e43f4b
Bug 1488552 - Ensure proper running on 64-bit and 32-bit BE platforms.
e43f4b
---
e43f4b
 js/src/gc/Marking-inl.h       | 16 ++++++++++++++++
e43f4b
 js/src/gc/RelocationOverlay.h | 13 ++++++++++++-
e43f4b
 js/src/jsfriendapi.h          |  8 ++++++++
e43f4b
 js/src/vm/StringType.h        | 13 +++++++++++++
e43f4b
 4 files changed, 49 insertions(+), 1 deletion(-)
e43f4b
e43f4b
diff --git a/js/src/gc/Marking-inl.h b/js/src/gc/Marking-inl.h
e43f4b
index 6d2a4c7..c773c21 100644
e43f4b
--- a/js/src/gc/Marking-inl.h
e43f4b
+++ b/js/src/gc/Marking-inl.h
e43f4b
@@ -82,12 +82,28 @@ inline void RelocationOverlay::forwardTo(Cell* cell) {
e43f4b
   MOZ_ASSERT(!isForwarded());
e43f4b
   // The location of magic_ is important because it must never be valid to see
e43f4b
   // the value Relocated there in a GC thing that has not been moved.
e43f4b
+#if MOZ_LITTLE_ENDIAN || JS_BITS_PER_WORD == 32
e43f4b
+  // On 32-bit, the magic_ aliases with whatever comes after the first
e43f4b
+  // pointer; on little-endian 64-bit, the magic_ aliases with the
e43f4b
+  // 32 most significant bits of the pointer, which are the second half.
e43f4b
   static_assert(offsetof(RelocationOverlay, magic_) ==
e43f4b
                     offsetof(JSObject, group_) + sizeof(uint32_t),
e43f4b
                 "RelocationOverlay::magic_ is in the wrong location");
e43f4b
   static_assert(offsetof(RelocationOverlay, magic_) ==
e43f4b
                     offsetof(js::Shape, base_) + sizeof(uint32_t),
e43f4b
                 "RelocationOverlay::magic_ is in the wrong location");
e43f4b
+#elif JS_BITS_PER_WORD == 64
e43f4b
+  // On big-endian 64-bit, the magic_ aliases with the 32 most
e43f4b
+  // significant bits of the pointer, but now that's the first half.
e43f4b
+  static_assert(offsetof(RelocationOverlay, magic_) ==
e43f4b
+                    offsetof(JSObject, group_),
e43f4b
+                "RelocationOverlay::magic_ is in the wrong location");
e43f4b
+  static_assert(offsetof(RelocationOverlay, magic_) ==
e43f4b
+                    offsetof(js::Shape, base_),
e43f4b
+                "RelocationOverlay::magic_ is in the wrong location");
e43f4b
+#else
e43f4b
+#  error "Unknown endianness or word size"
e43f4b
+#endif
e43f4b
   static_assert(
e43f4b
       offsetof(RelocationOverlay, magic_) == offsetof(JSString, d.u1.length),
e43f4b
       "RelocationOverlay::magic_ is in the wrong location");
e43f4b
diff --git a/js/src/gc/RelocationOverlay.h b/js/src/gc/RelocationOverlay.h
e43f4b
index a568843..399a541 100644
e43f4b
--- a/js/src/gc/RelocationOverlay.h
e43f4b
+++ b/js/src/gc/RelocationOverlay.h
e43f4b
@@ -33,14 +33,25 @@ class RelocationOverlay {
e43f4b
   /* See comment in js/public/HeapAPI.h. */
e43f4b
   static const uint32_t Relocated = js::gc::Relocated;
e43f4b
 
e43f4b
+#if MOZ_LITTLE_ENDIAN || JS_BITS_PER_WORD == 32
e43f4b
   /*
e43f4b
-   * Keep the low 32 bits untouched. Use them to distinguish strings from
e43f4b
+   * Keep the first 32 bits untouched. Use them to distinguish strings from
e43f4b
    * objects in the nursery.
e43f4b
    */
e43f4b
   uint32_t preserve_;
e43f4b
 
e43f4b
   /* Set to Relocated when moved. */
e43f4b
   uint32_t magic_;
e43f4b
+#elif JS_BITS_PER_WORD == 64
e43f4b
+  /*
e43f4b
+   * On big-endian, we need to reorder to keep preserve_ lined up with the
e43f4b
+   * low 32 bits of the aligned group_ pointer in JSObject.
e43f4b
+   */
e43f4b
+  uint32_t magic_;
e43f4b
+  uint32_t preserve_;
e43f4b
+#else
e43f4b
+#  error "Unknown endianness or word size"
e43f4b
+#endif
e43f4b
 
e43f4b
   /* The location |this| was moved to. */
e43f4b
   Cell* newLocation_;
e43f4b
diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h
e43f4b
index 4b8d18a..70ce0a1 100644
e43f4b
--- a/js/src/jsfriendapi.h
e43f4b
+++ b/js/src/jsfriendapi.h
e43f4b
@@ -9,6 +9,7 @@
e43f4b
 
e43f4b
 #include "mozilla/Atomics.h"
e43f4b
 #include "mozilla/Casting.h"
e43f4b
+#include "mozilla/EndianUtils.h"
e43f4b
 #include "mozilla/Maybe.h"
e43f4b
 #include "mozilla/MemoryReporting.h"
e43f4b
 #include "mozilla/UniquePtr.h"
e43f4b
@@ -609,8 +610,15 @@ struct String {
e43f4b
   static const uint32_t LATIN1_CHARS_BIT = JS_BIT(6);
e43f4b
   static const uint32_t EXTERNAL_FLAGS = LINEAR_BIT | NON_ATOM_BIT | JS_BIT(5);
e43f4b
   static const uint32_t TYPE_FLAGS_MASK = JS_BIT(6) - 1;
e43f4b
+#if MOZ_LITTLE_ENDIAN || JS_BITS_PER_WORD == 32
e43f4b
   uint32_t flags;
e43f4b
   uint32_t length;
e43f4b
+#elif JS_BITS_PER_WORD == 64
e43f4b
+  uint32_t length;
e43f4b
+  uint32_t flags;
e43f4b
+#else
e43f4b
+#  error "Unknown endianness or word size"
e43f4b
+#endif
e43f4b
   union {
e43f4b
     const JS::Latin1Char* nonInlineCharsLatin1;
e43f4b
     const char16_t* nonInlineCharsTwoByte;
e43f4b
diff --git a/js/src/vm/StringType.h b/js/src/vm/StringType.h
e43f4b
index cde3427..c3400db 100644
e43f4b
--- a/js/src/vm/StringType.h
e43f4b
+++ b/js/src/vm/StringType.h
e43f4b
@@ -7,6 +7,7 @@
e43f4b
 #ifndef vm_StringType_h
e43f4b
 #define vm_StringType_h
e43f4b
 
e43f4b
+#include "mozilla/EndianUtils.h"
e43f4b
 #include "mozilla/MemoryReporting.h"
e43f4b
 #include "mozilla/PodOperations.h"
e43f4b
 #include "mozilla/Range.h"
e43f4b
@@ -168,8 +169,20 @@ class JSString : public js::gc::Cell {
e43f4b
   struct Data {
e43f4b
     union {
e43f4b
       struct {
e43f4b
+#if MOZ_LITTLE_ENDIAN || JS_BITS_PER_WORD == 32
e43f4b
         uint32_t flags;  /* JSString */
e43f4b
         uint32_t length; /* JSString */
e43f4b
+#elif JS_BITS_PER_WORD == 64
e43f4b
+        /*
e43f4b
+         * On big-endian, we need to reorder to keep flags lined up
e43f4b
+         * with the low 32 bits of the aligned group_ pointer in
e43f4b
+         * JSObject.
e43f4b
+         */
e43f4b
+        uint32_t length; /* JSString */
e43f4b
+        uint32_t flags;  /* JSString */
e43f4b
+#else
e43f4b
+#  error "Unknown endianness or word size"
e43f4b
+#endif
e43f4b
       };
e43f4b
       uintptr_t flattenData; /* JSRope (temporary while flattening) */
e43f4b
     } u1;
e43f4b
-- 
e43f4b
2.23.0
e43f4b