OSDN Git Service

Fix negative array size checking
authorMathieu Chartier <mathieuc@google.com>
Wed, 10 Aug 2016 17:08:58 +0000 (10:08 -0700)
committerMathieu Chartier <mathieuc@google.com>
Wed, 10 Aug 2016 17:46:23 +0000 (10:46 -0700)
Mask out the alignment after the size check. Was broken in previous
CL.

Test: target test 412 --64 with CC + baker

Bug: 30162165
Change-Id: Ic4eb7229fb742490cd9193baf0faa2be6b454f38

runtime/arch/arm64/quick_entrypoints_arm64.S
runtime/generated/asm_support_gen.h
tools/cpp-define-generator/constant_globals.def

index 439f8d4..48b9d44 100644 (file)
@@ -1938,10 +1938,13 @@ END art_quick_alloc_object_rosalloc
                                                               // (for 64 bit alignment).
     and    \xTemp0, \xTemp0, #4
     add    \xTemp1, \xTemp1, \xTemp0
-    and    \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED   // Round up the object size by the
-                                                              // object alignment. (addr + 7) & ~7.
-                                                              // Add by 7 is done above.
-
+    and    \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED64 // Apply alignemnt mask
+                                                              // (addr + 7) & ~7. The mask must
+                                                              // be 64 bits to keep high bits in
+                                                              // case of overflow.
+    // Negative sized arrays are handled here since xCount holds a zero extended 32 bit value.
+    // Negative ints become large 64 bit unsigned ints which will always be larger than max signed
+    // 32 bit int. Since the max shift for arrays is 3, it can not become a negative 64 bit int.
     cmp    \xTemp1, #MIN_LARGE_OBJECT_THRESHOLD               // Possibly a large object, go slow
     bhs    \slowPathLabel                                     // path.
 
@@ -1955,7 +1958,6 @@ END art_quick_alloc_object_rosalloc
     sub    \xTemp2, \xTemp2, \xTemp0
     cmp    \xTemp1, \xTemp2
     bhi    \slowPathLabel
-
     // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
                                                               // Move old thread_local_pos to x0
                                                               // for the return value.
index 3d3cc4e..32ec292 100644 (file)
@@ -98,6 +98,8 @@ DEFINE_CHECK_EQ(static_cast<uint32_t>(LOCK_WORD_MARK_BIT_MASK_SHIFTED), (static_
 DEFINE_CHECK_EQ(static_cast<size_t>(OBJECT_ALIGNMENT_MASK), (static_cast<size_t>(art::kObjectAlignment - 1)))
 #define OBJECT_ALIGNMENT_MASK_TOGGLED 0xfffffff8
 DEFINE_CHECK_EQ(static_cast<uint32_t>(OBJECT_ALIGNMENT_MASK_TOGGLED), (static_cast<uint32_t>(~static_cast<uint32_t>(art::kObjectAlignment - 1))))
+#define OBJECT_ALIGNMENT_MASK_TOGGLED64 0xfffffffffffffff8
+DEFINE_CHECK_EQ(static_cast<uint64_t>(OBJECT_ALIGNMENT_MASK_TOGGLED64), (static_cast<uint64_t>(~static_cast<uint64_t>(art::kObjectAlignment - 1))))
 #define ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE 128
 DEFINE_CHECK_EQ(static_cast<int32_t>(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), (static_cast<int32_t>((art::gc::allocator::RosAlloc::kMaxThreadLocalBracketSize))))
 #define ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT 3
index 1e24d64..a3ccc72 100644 (file)
@@ -25,6 +25,7 @@
 
 DEFINE_OBJECT_EXPR(ALIGNMENT_MASK,         size_t,   art::kObjectAlignment - 1)
 DEFINE_OBJECT_EXPR(ALIGNMENT_MASK_TOGGLED, uint32_t, ~static_cast<uint32_t>(art::kObjectAlignment - 1))
+DEFINE_OBJECT_EXPR(ALIGNMENT_MASK_TOGGLED64, uint64_t, ~static_cast<uint64_t>(art::kObjectAlignment - 1))
 
 #undef DEFINE_OBJECT_EXPR