diff options
author | Joel Sherrill <joel.sherrill@oarcorp.com> | 2012-07-17 11:57:49 -0500 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@oarcorp.com> | 2012-07-17 11:57:49 -0500 |
commit | feb3415b29c2810ba4c649ace5b215090d50fa27 (patch) | |
tree | 6743769437d4048b4fb2454e224bcd95eda78de8 | |
parent | Merge branch 'master' of ssh://git.rtems.org/data/git/rtems (diff) | |
parent | libnetworking: Silence set but not used warnings (diff) | |
download | rtems-feb3415b29c2810ba4c649ace5b215090d50fa27.tar.bz2 |
Merge branch 'master' of ssh://git.rtems.org/data/git/rtems
21 files changed, 117 insertions, 88 deletions
diff --git a/c/src/lib/libbsp/sparc/shared/startup/linkcmds.base b/c/src/lib/libbsp/sparc/shared/startup/linkcmds.base index 47e67836bd..e61a55475a 100644 --- a/c/src/lib/libbsp/sparc/shared/startup/linkcmds.base +++ b/c/src/lib/libbsp/sparc/shared/startup/linkcmds.base @@ -128,9 +128,9 @@ SECTIONS *(_bsd_set_sysinit_*); _bsd__stop_set_sysinit_set = .; - bsp_section_rodata_end = .; + . = ALIGN (16); + _endtext = .; } >ram - _endtext = .; .rela.dyn : { *(.rela.init) diff --git a/cpukit/libcsupport/include/rtems/malloc.h b/cpukit/libcsupport/include/rtems/malloc.h index 7f56a842e5..d178e8a00d 100644 --- a/cpukit/libcsupport/include/rtems/malloc.h +++ b/cpukit/libcsupport/include/rtems/malloc.h @@ -186,12 +186,16 @@ rtems_status_code rtems_heap_extend( /** * @brief Greedy allocate that empties the heap. * - * Afterward the heap has at most @a remaining_free_space free space left in - * one free block. All other blocks are used. + * Afterward the heap has at most @a block_count allocateable blocks of sizes + * specified by @a block_sizes. The @a block_sizes must point to an array with + * @a block_count members. All other blocks are used. * * @see rtems_heap_greedy_free(). */ -void *rtems_heap_greedy_allocate( size_t remaining_free_space ); +void *rtems_heap_greedy_allocate( + const uintptr_t *block_sizes, + size_t block_count +); /** * @brief Frees space of a greedy allocation. diff --git a/cpukit/libcsupport/src/rtems_heap_greedy.c b/cpukit/libcsupport/src/rtems_heap_greedy.c index d363fe4d3b..7e5dc16e7e 100644 --- a/cpukit/libcsupport/src/rtems_heap_greedy.c +++ b/cpukit/libcsupport/src/rtems_heap_greedy.c @@ -18,12 +18,15 @@ #include "malloc_p.h" -void *rtems_heap_greedy_allocate( size_t remaining_free_space ) +void *rtems_heap_greedy_allocate( + const uintptr_t *block_sizes, + size_t block_count +) { void *opaque; _RTEMS_Lock_allocator(); - opaque = _Heap_Greedy_allocate( RTEMS_Malloc_Heap, remaining_free_space ); + opaque = _Heap_Greedy_allocate( RTEMS_Malloc_Heap, block_sizes, block_count ); _RTEMS_Unlock_allocator(); return opaque; diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h index b7f79cb9be..27c6fb4483 100644 --- a/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h +++ b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h @@ -47,7 +47,7 @@ extern int soconnsleep (struct socket *so); extern void soconnwakeup (struct socket *so); #define splnet() 0 #define splimp() 0 -#define splx(_s) do { (_s) = 0; } while(0) +#define splx(_s) do { (_s) = 0; (void) (_s); } while(0) /* to avoid warnings */ void *memcpy(void *dest, const void *src, size_t n); diff --git a/cpukit/rtems/include/rtems/rtems/support.h b/cpukit/rtems/include/rtems/rtems/support.h index bdabc59e8b..b2c6471c31 100644 --- a/cpukit/rtems/include/rtems/rtems/support.h +++ b/cpukit/rtems/include/rtems/rtems/support.h @@ -102,12 +102,16 @@ bool rtems_workspace_free( /** * @brief Greedy allocate that empties the workspace. * - * Afterward the workspace has at most @a remaining_free_space free space left - * in one free block. All other blocks are used. + * Afterward the heap has at most @a block_count allocateable blocks of sizes + * specified by @a block_sizes. The @a block_sizes must point to an array with + * @a block_count members. All other blocks are used. * * @see rtems_workspace_greedy_free(). */ -void *rtems_workspace_greedy_allocate( size_t remaining_free_space ); +void *rtems_workspace_greedy_allocate( + const uintptr_t *block_sizes, + size_t block_count +); /** * @brief Frees space of a greedy allocation. diff --git a/cpukit/rtems/src/workspacegreedy.c b/cpukit/rtems/src/workspacegreedy.c index 6d8fd9b937..03781412b2 100644 --- a/cpukit/rtems/src/workspacegreedy.c +++ b/cpukit/rtems/src/workspacegreedy.c @@ -19,12 +19,15 @@ #include <rtems/rtems/support.h> #include <rtems/score/wkspace.h> -void *rtems_workspace_greedy_allocate( size_t remaining_free_space ) +void *rtems_workspace_greedy_allocate( + const uintptr_t *block_sizes, + size_t block_count +) { void *opaque; _Thread_Disable_dispatch(); - opaque = _Heap_Greedy_allocate( &_Workspace_Area, remaining_free_space ); + opaque = _Heap_Greedy_allocate( &_Workspace_Area, block_sizes, block_count ); _Thread_Enable_dispatch(); return opaque; diff --git a/cpukit/score/include/rtems/score/heap.h b/cpukit/score/include/rtems/score/heap.h index 9208d17ef4..8e6220cc2e 100644 --- a/cpukit/score/include/rtems/score/heap.h +++ b/cpukit/score/include/rtems/score/heap.h @@ -549,14 +549,16 @@ void _Heap_Iterate( /** * @brief Greedy allocate that empties the heap. * - * Afterward the heap has at most @a remaining_free_space free space left in - * one free block. All other blocks are used. + * Afterward the heap has at most @a block_count allocateable blocks of sizes + * specified by @a block_sizes. The @a block_sizes must point to an array with + * @a block_count members. All other blocks are used. * * @see _Heap_Greedy_free(). */ Heap_Block *_Heap_Greedy_allocate( Heap_Control *heap, - uintptr_t remaining_free_space + const uintptr_t *block_sizes, + size_t block_count ); /** diff --git a/cpukit/score/src/heapgreedy.c b/cpukit/score/src/heapgreedy.c index 4b38b7858a..4711bd5833 100644 --- a/cpukit/score/src/heapgreedy.c +++ b/cpukit/score/src/heapgreedy.c @@ -20,17 +20,31 @@ Heap_Block *_Heap_Greedy_allocate( Heap_Control *heap, - uintptr_t remaining_free_space + const uintptr_t *block_sizes, + size_t block_count ) { - void *free_space = remaining_free_space > 0 ? - _Heap_Allocate( heap, remaining_free_space ) - : NULL; Heap_Block *const free_list_tail = _Heap_Free_list_tail( heap ); - Heap_Block *current = _Heap_Free_list_first( heap ); + Heap_Block *allocated_blocks = NULL; Heap_Block *blocks = NULL; + Heap_Block *current; + size_t i; - while ( current != free_list_tail ) { + for (i = 0; i < block_count; ++i) { + void *next = _Heap_Allocate( heap, block_sizes [i] ); + + if ( next != NULL ) { + Heap_Block *next_block = _Heap_Block_of_alloc_area( + (uintptr_t) next, + heap->page_size + ); + + next_block->next = allocated_blocks; + allocated_blocks = next_block; + } + } + + while ( (current = _Heap_Free_list_first( heap )) != free_list_tail ) { _Heap_Block_allocate( heap, current, @@ -40,10 +54,13 @@ Heap_Block *_Heap_Greedy_allocate( current->next = blocks; blocks = current; - current = _Heap_Free_list_first( heap ); } - _Heap_Free( heap, free_space ); + while ( allocated_blocks != NULL ) { + current = allocated_blocks; + allocated_blocks = allocated_blocks->next; + _Heap_Free( heap, (void *) _Heap_Alloc_area_of_block( current ) ); + } return blocks; } diff --git a/testsuites/fstests/fsimfsgeneric01/init.c b/testsuites/fstests/fsimfsgeneric01/init.c index d7abad3ee2..9fd4bad43a 100644 --- a/testsuites/fstests/fsimfsgeneric01/init.c +++ b/testsuites/fstests/fsimfsgeneric01/init.c @@ -367,7 +367,7 @@ static void test_imfs_make_generic_node_errors(void) rtems_test_assert(errno == ENOTSUP); mt_entry->type = type; - opaque = rtems_heap_greedy_allocate(0); + opaque = rtems_heap_greedy_allocate(NULL, 0); errno = 0; rv = IMFS_make_generic_node( path, diff --git a/testsuites/libtests/block11/init.c b/testsuites/libtests/block11/init.c index 095d8bdf2d..b850aba950 100644 --- a/testsuites/libtests/block11/init.c +++ b/testsuites/libtests/block11/init.c @@ -229,6 +229,8 @@ static void test_blkdev_imfs_parameters(void) static void test_blkdev_imfs_errors(void) { + static uintptr_t disk_size [] = { sizeof(rtems_disk_device) + sizeof(int) }; + rtems_status_code sc; int rv; ramdisk *rd; @@ -257,7 +259,7 @@ static void test_blkdev_imfs_errors(void) ); rtems_test_assert(sc == RTEMS_INVALID_NUMBER); - opaque = rtems_heap_greedy_allocate(0); + opaque = rtems_heap_greedy_allocate(NULL, 0); sc = rtems_blkdev_create( rda, BLOCK_SIZE, @@ -268,7 +270,7 @@ static void test_blkdev_imfs_errors(void) rtems_test_assert(sc == RTEMS_NO_MEMORY); rtems_heap_greedy_free(opaque); - opaque = rtems_heap_greedy_allocate(sizeof(rtems_disk_device) + sizeof(int)); + opaque = rtems_heap_greedy_allocate(disk_size, 1); sc = rtems_blkdev_create( rda, BLOCK_SIZE, @@ -342,7 +344,7 @@ static void test_blkdev_imfs_errors(void) ); rtems_test_assert(sc == RTEMS_INVALID_NUMBER); - opaque = rtems_heap_greedy_allocate(0); + opaque = rtems_heap_greedy_allocate(NULL, 0); sc = rtems_blkdev_create_partition( rda1, rda, @@ -352,7 +354,7 @@ static void test_blkdev_imfs_errors(void) rtems_test_assert(sc == RTEMS_NO_MEMORY); rtems_heap_greedy_free(opaque); - opaque = rtems_heap_greedy_allocate(sizeof(rtems_disk_device) + sizeof(int)); + opaque = rtems_heap_greedy_allocate(disk_size, 1); sc = rtems_blkdev_create_partition( rda1, rda, diff --git a/testsuites/libtests/devfs02/init.c b/testsuites/libtests/devfs02/init.c index 47a70a8a50..ad37aeb94d 100644 --- a/testsuites/libtests/devfs02/init.c +++ b/testsuites/libtests/devfs02/init.c @@ -62,7 +62,7 @@ rtems_task Init( puts( "Init - restore device table size" ); rootloc->mt_entry->immutable_fs_info = data; - opaque = rtems_heap_greedy_allocate( 0 ); + opaque = rtems_heap_greedy_allocate( NULL, 0 ); puts( "Init - attempt to create a node - expect ENOMEM" ); status = mknod( "/node", S_IFBLK, 0LL ); diff --git a/testsuites/libtests/termios01/init.c b/testsuites/libtests/termios01/init.c index 0b5d01accf..9649ffa762 100644 --- a/testsuites/libtests/termios01/init.c +++ b/testsuites/libtests/termios01/init.c @@ -473,7 +473,7 @@ static rtems_task Init( test_termios_baud2number(); test_termios_number_to_baud(); - sc = rtems_termios_bufsize( 256, 138, 64 ); + sc = rtems_termios_bufsize( 256, 128, 64 ); directive_failed( sc, "rtems_termios_bufsize" ); /* diff --git a/testsuites/libtests/termios01/termios_testdriver.c b/testsuites/libtests/termios01/termios_testdriver.c index 70e0d491af..c53b5b4c7a 100644 --- a/testsuites/libtests/termios01/termios_testdriver.c +++ b/testsuites/libtests/termios01/termios_testdriver.c @@ -23,6 +23,7 @@ #include <termios.h> #include <rtems/termiostypes.h> #include <rtems/libcsupport.h> +#include <rtems/malloc.h> #include "termios_testdriver.h" /* forward declarations to avoid warnings */ @@ -162,9 +163,7 @@ rtems_device_driver termios_test_driver_open( rtems_status_code sc; int rc; rtems_libio_open_close_args_t *args = arg; - void *alloc_ptr = (void *)0; - static int test = 0; - size_t freeMemory; + static bool firstCall = true; static const rtems_termios_callbacks Callbacks = { NULL, /* firstOpen */ @@ -182,39 +181,26 @@ rtems_device_driver termios_test_driver_open( rtems_test_exit(0); } - freeMemory = malloc_free_space(); - if( test == 0 ) { - alloc_ptr = malloc( freeMemory - 4 ); - - sc = rtems_termios_open (major, minor, arg, &Callbacks); - rtems_test_assert( sc == RTEMS_NO_MEMORY ); - - free( alloc_ptr ); - alloc_ptr = malloc( freeMemory - 4 - 10 - - sizeof( struct rtems_termios_tty ) ); - - sc = rtems_termios_open (major, minor, arg, &Callbacks); - rtems_test_assert( sc == RTEMS_NO_MEMORY ); - - free( alloc_ptr ); - alloc_ptr = malloc( freeMemory - 4 - 20 - - sizeof( struct rtems_termios_tty ) - - 128 ); - - sc = rtems_termios_open (major, minor, arg, &Callbacks); - rtems_test_assert( sc == RTEMS_NO_MEMORY ); - - free( alloc_ptr ); - alloc_ptr = malloc( freeMemory - 4 - 20 - - sizeof( struct rtems_termios_tty ) - - 128 - - 80 ); - - sc = rtems_termios_open (major, minor, arg, &Callbacks); - rtems_test_assert( sc == RTEMS_NO_MEMORY ); + if( firstCall ) { + static const uintptr_t allocSizes [] = { + sizeof( struct rtems_termios_tty ), + 128, + 64, + 256 + }; + + size_t i; + + firstCall = false; - free( alloc_ptr ); - test = 1; + for (i = 0; i < sizeof( allocSizes ) / sizeof( allocSizes [0] ); ++i) { + void *opaque = rtems_heap_greedy_allocate( allocSizes, i ); + + sc = rtems_termios_open( major, minor, arg, &Callbacks ); + rtems_test_assert( sc == RTEMS_NO_MEMORY ); + + rtems_heap_greedy_free( opaque ); + } } sc = rtems_termios_open (major, minor, arg, &Callbacks); diff --git a/testsuites/psxtests/psxchroot01/test.c b/testsuites/psxtests/psxchroot01/test.c index 1e3f3ffc91..7bb4a61a4a 100644 --- a/testsuites/psxtests/psxchroot01/test.c +++ b/testsuites/psxtests/psxchroot01/test.c @@ -65,6 +65,10 @@ int main( ) #endif { + static const uintptr_t global_location_size [] = { + sizeof(rtems_filesystem_global_location_t) + }; + int status; void *opaque; /* @@ -108,9 +112,7 @@ int main( rtems_test_assert( errno == ENOTDIR ); puts( "allocate most of memory - attempt to fail chroot - expect ENOMEM" ); - opaque = rtems_heap_greedy_allocate( - sizeof(rtems_filesystem_global_location_t) - ); + opaque = rtems_heap_greedy_allocate( global_location_size, 1 ); status = chroot( "/one" ); rtems_test_assert( status == -1 ); diff --git a/testsuites/psxtests/psximfs02/init.c b/testsuites/psxtests/psximfs02/init.c index 10e97bba60..73724bd62a 100644 --- a/testsuites/psxtests/psximfs02/init.c +++ b/testsuites/psxtests/psximfs02/init.c @@ -35,15 +35,24 @@ rtems_task Init( rtems_task_argument argument ) { + static const char mount_point [] = "dir01"; + static const char fs_type [] = RTEMS_FILESYSTEM_TYPE_IMFS; + static const char slink_2_name [] = "node-slink-2"; + static const uintptr_t mount_table_entry_size [] = { + sizeof( rtems_filesystem_mount_table_entry_t ) + + sizeof( fs_type ) + + sizeof( rtems_filesystem_global_location_t ) + }; + static const uintptr_t slink_2_name_size [] = { + sizeof( slink_2_name ) + }; + int status = 0; void *opaque; char linkname_n[20] = {0}; char linkname_p[20] = {0}; int i; struct stat stat_buf; - static const char mount_point [] = "dir01"; - static const char fs_type [] = RTEMS_FILESYSTEM_TYPE_IMFS; - static const char slink_2_name [] = "node-slink-2"; puts( "\n\n*** TEST IMFS 02 ***" ); @@ -97,11 +106,7 @@ rtems_task Init( rtems_test_assert( errno == EACCES ); puts( "Allocate most of heap" ); - opaque = rtems_heap_greedy_allocate( - sizeof( rtems_filesystem_mount_table_entry_t ) - + sizeof( fs_type ) - + sizeof( rtems_filesystem_global_location_t ) - ); + opaque = rtems_heap_greedy_allocate( mount_table_entry_size, 1 ); printf( "Attempt to mount a fs at %s -- expect ENOMEM", mount_point ); status = mount( NULL, @@ -120,7 +125,7 @@ rtems_task Init( rtems_test_assert( status == 0 ); puts( "Allocate most of heap" ); - opaque = rtems_heap_greedy_allocate( 0 ); + opaque = rtems_heap_greedy_allocate( NULL, 0 ); puts( "Attempt to create /node-link-2 for /node -- expect ENOMEM" ); status = link( "/node", "/node-link-2" ); @@ -136,7 +141,7 @@ rtems_task Init( rtems_heap_greedy_free( opaque ); puts( "Allocate most of heap" ); - opaque = rtems_heap_greedy_allocate( sizeof( slink_2_name ) ); + opaque = rtems_heap_greedy_allocate( slink_2_name_size, 1 ); printf( "Attempt to create %s for /node -- expect ENOMEM", slink_2_name ); status = symlink( "/node", slink_2_name ); diff --git a/testsuites/psxtests/psxkey01/init.c b/testsuites/psxtests/psxkey01/init.c index dbd73d10f8..3383c8da3c 100644 --- a/testsuites/psxtests/psxkey01/init.c +++ b/testsuites/psxtests/psxkey01/init.c @@ -41,7 +41,7 @@ void *POSIX_Init( Init_id = pthread_self(); printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id ); - rtems_workspace_greedy_allocate( 0 ); + rtems_workspace_greedy_allocate( NULL, 0 ); puts("Init: pthread_key_create - ENOMEM (Workspace not available)"); empty_line(); diff --git a/testsuites/psxtests/psxmsgq02/init.c b/testsuites/psxtests/psxmsgq02/init.c index 4f5910a675..53c4769ba2 100644 --- a/testsuites/psxtests/psxmsgq02/init.c +++ b/testsuites/psxtests/psxmsgq02/init.c @@ -47,7 +47,7 @@ void *POSIX_Init( Init_id = pthread_self(); printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id ); - rtems_workspace_greedy_allocate( 0 ); + rtems_workspace_greedy_allocate( NULL, 0 ); attr.mq_maxmsg = MAXMSG; attr.mq_msgsize = MSGSIZE; diff --git a/testsuites/psxtests/psxobj01/init.c b/testsuites/psxtests/psxobj01/init.c index aee8bf7e52..3f639da80a 100644 --- a/testsuites/psxtests/psxobj01/init.c +++ b/testsuites/psxtests/psxobj01/init.c @@ -74,7 +74,7 @@ rtems_task Init( /* out of memory error ONLY when POSIX is enabled */ puts( "INIT - _Objects_Set_name fails - out of memory" ); - rtems_workspace_greedy_allocate( 0 ); + rtems_workspace_greedy_allocate( NULL, 0 ); bc = _Objects_Set_name( &TestClass, &_Thread_Executing->Object, name ); rtems_test_assert( bc == false ); diff --git a/testsuites/psxtests/psxpipe01/init.c b/testsuites/psxtests/psxpipe01/init.c index d2e0381a53..f342fd4f85 100644 --- a/testsuites/psxtests/psxpipe01/init.c +++ b/testsuites/psxtests/psxpipe01/init.c @@ -19,6 +19,7 @@ #include <unistd.h> #include <errno.h> #include <rtems/libcsupport.h> +#include <rtems/malloc.h> /* forward declarations to avoid warnings */ rtems_task Init(rtems_task_argument ignored); @@ -30,7 +31,7 @@ rtems_task Init( int fd[2] = {0,0}; int dummy_fd[2] = {0,0}; int status = 0; - void *alloc_ptr = (void *)0; + void *opaque = NULL; puts( "*** TEST POSIX PIPE CREATION - 01 ***" ); @@ -55,7 +56,7 @@ rtems_task Init( status |= close( fd[1] ); rtems_test_assert( status == 0 ); - alloc_ptr = malloc( malloc_free_space() - 4 ); + opaque = rtems_heap_greedy_allocate( NULL, 0 ); /* case where mkfifo fails */ puts( "Init - attempt to create pipe -- expect ENOMEM" ); @@ -63,7 +64,7 @@ rtems_task Init( rtems_test_assert( status == -1 ); rtems_test_assert( errno == ENOMEM ); - free( alloc_ptr ); + rtems_heap_greedy_free( opaque ); dummy_fd[0] = open( "/file01", O_RDONLY | O_CREAT, S_IRWXU ); rtems_test_assert( dummy_fd[0] != -1 ); diff --git a/testsuites/sptests/spfatal22/testcase.h b/testsuites/sptests/spfatal22/testcase.h index 188ff1d43f..268c48aed5 100644 --- a/testsuites/sptests/spfatal22/testcase.h +++ b/testsuites/sptests/spfatal22/testcase.h @@ -18,7 +18,7 @@ void force_error() { - rtems_heap_greedy_allocate( 0 ); + rtems_heap_greedy_allocate( NULL, 0 ); rtems_libio_init(); } diff --git a/testsuites/sptests/spprivenv01/init.c b/testsuites/sptests/spprivenv01/init.c index 609f85cae5..29b3b98561 100644 --- a/testsuites/sptests/spprivenv01/init.c +++ b/testsuites/sptests/spprivenv01/init.c @@ -47,7 +47,7 @@ rtems_task Init( puts( "\n\n*** TEST USER ENVIRONMENT ROUTINE - 01 ***" ); puts( "Init - allocating most of heap -- OK" ); - opaque = rtems_heap_greedy_allocate( 0 ); + opaque = rtems_heap_greedy_allocate( NULL, 0 ); puts( "Init - attempt to reset env - expect RTEMS_NO_MEMORY" ); sc = rtems_libio_set_private_env(); @@ -57,7 +57,7 @@ rtems_task Init( rtems_heap_greedy_free( opaque ); puts( "Init - allocating most of workspace memory" ); - opaque = rtems_workspace_greedy_allocate( 0 ); + opaque = rtems_workspace_greedy_allocate( NULL, 0 ); puts( "Init - attempt to reset env - expect RTEMS_TOO_MANY" ); sc = rtems_libio_set_private_env(); |