From d5ec257356f371f2fef99efdbd32a5d9bd3be339 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Mon, 11 Feb 2013 14:12:08 -0500 Subject: 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 file changed, 18 insertions(+), 5 deletions(-) (limited to 'cpukit/score/src/objectextendinformation.c') diff --git a/cpukit/score/src/objectextendinformation.c b/cpukit/score/src/objectextendinformation.c index a6a5c253a1..07f4997970 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) -- cgit v1.2.3