2009-08-06 Chris Johns <chrisj@rtems.org>

* score/src/objectextendinformation.c: Ensure that nothing is moved or
	copied until all memory is successfully allocated.
This commit is contained in:
Joel Sherrill
2009-08-06 20:43:30 +00:00
parent f0bf33260a
commit ac893a9731
2 changed files with 54 additions and 22 deletions

View File

@@ -1,3 +1,8 @@
2009-08-06 Chris Johns <chrisj@rtems.org>
* score/src/objectextendinformation.c: Ensure that nothing is moved or
copied until all memory is successfully allocated.
2009-08-06 Joel Sherrill <joel.sherrill@OARcorp.com> 2009-08-06 Joel Sherrill <joel.sherrill@OARcorp.com>
* posix/src/mqueuecreatesupp.c, posix/src/mqueuenametoid.c, * posix/src/mqueuecreatesupp.c, posix/src/mqueuenametoid.c,

View File

@@ -53,6 +53,7 @@ void _Objects_Extend_information(
uint32_t index_base; uint32_t index_base;
uint32_t minimum_index; uint32_t minimum_index;
uint32_t index; uint32_t index;
void *new_object_block;
/* /*
* Search for a free block of indexes. The block variable ends up set * Search for a free block of indexes. The block variable ends up set
@@ -76,6 +77,29 @@ void _Objects_Extend_information(
} }
} }
/*
* Allocate the name table, and the objects and if it fails either return or
* generate a fatal error depending on auto-extending being active.
*/
new_object_block =
_Workspace_Allocate(
(information->allocation_size * information->size)
);
if ( new_object_block == NULL ) {
if ( information->auto_extend ) {
return;
}
else {
_Internal_error_Occurred(
INTERNAL_ERROR_CORE,
true,
INTERNAL_ERROR_WORKSPACE_ALLOCATION
);
}
}
/* /*
* If the index_base is the maximum we need to grow the tables. * If the index_base is the maximum we need to grow the tables.
*/ */
@@ -112,15 +136,23 @@ void _Objects_Extend_information(
block_count++; block_count++;
maximum = information->maximum + information->allocation_size; maximum = (uint32_t) information->maximum + information->allocation_size;
/* /*
* We need to limit the number of objects to the maximum number * We need to limit the number of objects to the maximum number
* representable in the index portion of the object Id. In the * representable in the index portion of the object Id. In the
* case of 16-bit Ids, this is only 256 object instances. * case of 16-bit Ids, this is only 256 object instances.
*/ */
if ( maximum > OBJECTS_ID_FINAL_INDEX ) if ( maximum > OBJECTS_ID_FINAL_INDEX ) {
if ( !_Workspace_Free( new_object_block ) ) {
_Internal_error_Occurred(
INTERNAL_ERROR_CORE,
true,
INTERNAL_ERROR_WORKSPACE_ALLOCATION
);
}
return; return;
}
/* /*
* Allocate the tables and break it up. * Allocate the tables and break it up.
@@ -131,9 +163,17 @@ void _Objects_Extend_information(
((maximum + minimum_index) * sizeof(Objects_Control *)); ((maximum + minimum_index) * sizeof(Objects_Control *));
object_blocks = (void**) _Workspace_Allocate( block_size ); object_blocks = (void**) _Workspace_Allocate( block_size );
if ( !object_blocks ) if ( !object_blocks ) {
if ( !_Workspace_Free( new_object_block ) ) {
_Internal_error_Occurred(
INTERNAL_ERROR_CORE,
true,
INTERNAL_ERROR_WORKSPACE_ALLOCATION
);
}
return; return;
}
/* /*
* Break the block into the various sections. * Break the block into the various sections.
*/ */
@@ -197,7 +237,7 @@ void _Objects_Extend_information(
information->object_blocks = object_blocks; information->object_blocks = object_blocks;
information->inactive_per_block = inactive_per_block; information->inactive_per_block = inactive_per_block;
information->local_table = local_table; information->local_table = local_table;
information->maximum = maximum; information->maximum = (Objects_Maximum) maximum;
information->maximum_id = _Objects_Build_id( information->maximum_id = _Objects_Build_id(
information->the_api, information->the_api,
information->the_class, information->the_class,
@@ -214,24 +254,10 @@ void _Objects_Extend_information(
} }
/* /*
* Allocate the name table, and the objects * Assign the new object block to the object block table.
*/ */
if ( information->auto_extend ) { information->object_blocks[ block ] = new_object_block;
information->object_blocks[ block ] =
_Workspace_Allocate(
(information->allocation_size * information->size)
);
if ( !information->object_blocks[ block ] )
return;
}
else {
information->object_blocks[ block ] =
_Workspace_Allocate_or_fatal_error(
(information->allocation_size * information->size)
);
}
/* /*
* Initialize objects .. add to a local chain first. * Initialize objects .. add to a local chain first.
@@ -265,5 +291,6 @@ void _Objects_Extend_information(
} }
information->inactive_per_block[ block ] = information->allocation_size; information->inactive_per_block[ block ] = information->allocation_size;
information->inactive += information->allocation_size; information->inactive =
(Objects_Maximum)(information->inactive + information->allocation_size);
} }