[rtems commit] PR1560: _Objects_Extend_information improper alignment

Gedare Bloom gedare at rtems.org
Mon Feb 11 20:19:52 UTC 2013


Module:    rtems
Branch:    master
Commit:    d5ec257356f371f2fef99efdbd32a5d9bd3be339
Changeset: http://git.rtems.org/rtems/commit/?id=d5ec257356f371f2fef99efdbd32a5d9bd3be339

Author:    Gedare Bloom <gedare at rtems.org>
Date:      Mon Feb 11 14:12:08 2013 -0500

PR1560: _Objects_Extend_information improper alignment

_Objects_Extend_information uses a sizeof(uint32_t) offset that leads to
improper alignment in case the CPU (actually, heap) alignment is 8 or higher.
The problem is solved by adding enough padding to align the sub-tables.

---

 cpukit/score/src/objectextendinformation.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/cpukit/score/src/objectextendinformation.c b/cpukit/score/src/objectextendinformation.c
index a6a5c25..07f4997 100644
--- a/cpukit/score/src/objectextendinformation.c
+++ b/cpukit/score/src/objectextendinformation.c
@@ -141,10 +141,15 @@ void _Objects_Extend_information(
     block_count++;
 
     /*
-     *  Allocate the tables and break it up.
+     *  Allocate the tables and break it up. The tables are:
+     *      1. object_locks        : void*
+     *      2. inactive_per_blocks : uint32_t
+     *      3. local_table         : Objects_Name*
      */
-    block_size = block_count *
-           (sizeof(void *) + sizeof(uint32_t) + sizeof(Objects_Name *)) +
+    #define ALIGN_BLOCK_SIZE(_s) \
+        (((_s) + (CPU_ALIGNMENT - 1)) & ~(CPU_ALIGNMENT - 1))
+    block_size = ALIGN_BLOCK_SIZE( block_count * sizeof(void*) ) +
+          ALIGN_BLOCK_SIZE( block_count * sizeof(uint32_t) ) +
           ((maximum + minimum_index) * sizeof(Objects_Control *));
     if ( information->auto_extend ) {
       object_blocks = _Workspace_Allocate( block_size );
@@ -160,9 +165,17 @@ void _Objects_Extend_information(
      *  Break the block into the various sections.
      */
     inactive_per_block = (uint32_t *) _Addresses_Add_offset(
-        object_blocks, block_count * sizeof(void*) );
+        object_blocks,
+        ALIGN_BLOCK_SIZE( block_count * sizeof(void*) )
+    );
     local_table = (Objects_Control **) _Addresses_Add_offset(
-        inactive_per_block, block_count * sizeof(uint32_t) );
+        inactive_per_block,
+        ALIGN_BLOCK_SIZE( block_count * sizeof(uint32_t) )
+    );
+    if ( !_Addresses_Is_aligned( local_table ) ) {
+      local_table = (Objects_Control **)
+        (((uintptr_t)local_table + CPU_ALIGNMENT - 1) & ~(CPU_ALIGNMENT - 1));
+    }
 
     /*
      *  Take the block count down. Saves all the (block_count - 1)




More information about the vc mailing list