Bug 1325771 - js:vm: Make sure AccessorShape and Shape have at least 4 bytes alignment. r?jandem draft
authorJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Thu, 22 Dec 2016 22:23:54 +0100
changeset 458871 6bbe86126168479a54c4c50fc6801a6c93d4277e
parent 458870 373fd1ad9a4d04da33d6fa3c17d6570a4da18179
child 458872 e2fa1647bd3a602661a908c386c9178ba696d923
push id41085
push userbmo:mh+mozilla@glandium.org
push dateWed, 11 Jan 2017 07:28:36 +0000
reviewersjandem
bugs1325771
milestone53.0a1
Bug 1325771 - js:vm: Make sure AccessorShape and Shape have at least 4 bytes alignment. r?jandem
js/src/jsfriendapi.h
js/src/vm/Shape.h
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -17,16 +17,20 @@
 #include "jsbytecode.h"
 #include "jspubtd.h"
 
 #include "js/CallArgs.h"
 #include "js/CallNonGenericMethod.h"
 #include "js/Class.h"
 #include "js/Utility.h"
 
+#ifndef __GNUC__
+#define __attribute__(x)
+#endif
+
 #if JS_STACK_GROWTH_DIRECTION > 0
 # define JS_CHECK_STACK_SIZE(limit, sp) (MOZ_LIKELY((uintptr_t)(sp) < (limit)))
 #else
 # define JS_CHECK_STACK_SIZE(limit, sp) (MOZ_LIKELY((uintptr_t)(sp) > (limit)))
 #endif
 
 class JSAtom;
 struct JSErrorFormatString;
@@ -521,17 +525,18 @@ struct BaseShape {
 
 class Shape {
 public:
     shadow::BaseShape* base;
     jsid              _1;
     uint32_t          slotInfo;
 
     static const uint32_t FIXED_SLOTS_SHIFT = 27;
-};
+
+} __attribute__ ((aligned(4))); /* ensure alignment is at least 4 bytes */
 
 /**
  * This layout is shared by all native objects. For non-native objects, the
  * group may always be accessed safely, and other members may be as well,
  * depending on the object's specific layout.
  */
 struct Object {
     shadow::ObjectGroup* group;
--- a/js/src/vm/Shape.h
+++ b/js/src/vm/Shape.h
@@ -25,16 +25,20 @@
 #include "gc/Marking.h"
 #include "gc/Rooting.h"
 #include "js/HashTable.h"
 #include "js/MemoryMetrics.h"
 #include "js/RootingAPI.h"
 #include "js/UbiNode.h"
 #include "vm/ObjectGroup.h"
 
+#ifndef __GNUC__
+#define __attribute__(x)
+#endif
+
 #ifdef _MSC_VER
 #pragma warning(push)
 #pragma warning(disable:4800)
 #pragma warning(push)
 #pragma warning(disable:4100) /* Silence unreferenced formal parameter warnings */
 #endif
 
 /*
@@ -1038,17 +1042,18 @@ class Shape : public gc::TenuredCell
     void fixupDictionaryShapeAfterMovingGC();
     void fixupShapeTreeAfterMovingGC();
 
     static void staticAsserts() {
         JS_STATIC_ASSERT(offsetof(Shape, base_) == offsetof(js::shadow::Shape, base));
         JS_STATIC_ASSERT(offsetof(Shape, slotInfo) == offsetof(js::shadow::Shape, slotInfo));
         JS_STATIC_ASSERT(FIXED_SLOTS_SHIFT == js::shadow::Shape::FIXED_SLOTS_SHIFT);
     }
-};
+
+} __attribute__ ((aligned(4))); /* ensure alignment is at least 4 bytes */
 
 /* Fat Shape used for accessor properties. */
 class AccessorShape : public Shape
 {
     friend class Shape;
     friend class NativeObject;
 
     union {
@@ -1060,17 +1065,18 @@ class AccessorShape : public Shape
         SetterOp rawSetter;     /* setter hook for shape */
         JSObject* setterObj;    /* user-defined callable "set" object or
                                    null if shape->hasSetterValue() */
     };
 
   public:
     /* Get a shape identical to this one, without parent/kids information. */
     inline AccessorShape(const StackShape& other, uint32_t nfixed);
-};
+
+} __attribute__ ((aligned(4))); /* ensure alignment is at least 4 bytes */
 
 inline
 StackBaseShape::StackBaseShape(Shape* shape)
   : flags(shape->getObjectFlags()),
     clasp(shape->getObjectClass())
 {}
 
 class MOZ_RAII AutoRooterGetterSetter