summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-01-08 22:59:14 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-01-08 22:59:14 +0000
commitcfcc4e202d928690c46a083ce594aa0d505bf302 (patch)
treeae22c4fd873aacb37662b661760f4d4ce021acc6 /cpukit/libcsupport
parent2008-01-08 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-cfcc4e202d928690c46a083ce594aa0d505bf302.tar.bz2
2008-01-08 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/Makefile.am: Add malloc_sbrk_helpers.c. * libcsupport/include/rtems/malloc.h, libcsupport/src/malloc.c, libcsupport/src/malloc_initialize.c, libcsupport/src/malloc_p.h, libcsupport/src/malloc_statistics_helpers.c: Make sbrk() support pluggable and optional. This eliminates the need for heap extend and sbrk in the minimum footprint which is ~2.5K on the SPARC. * sapi/include/confdefs.h: Add the following configuration points: + CONFIGURE_MALLOC_STATISTICS + CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK * libcsupport/src/malloc_sbrk_helpers.c: New file.
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r--cpukit/libcsupport/Makefile.am2
-rw-r--r--cpukit/libcsupport/include/rtems/malloc.h19
-rw-r--r--cpukit/libcsupport/src/malloc.c32
-rw-r--r--cpukit/libcsupport/src/malloc_initialize.c39
-rw-r--r--cpukit/libcsupport/src/malloc_p.h1
-rw-r--r--cpukit/libcsupport/src/malloc_sbrk_helpers.c111
-rw-r--r--cpukit/libcsupport/src/malloc_statistics_helpers.c5
7 files changed, 138 insertions, 71 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index 729237175b..67fc95d0db 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -84,7 +84,7 @@ MALLOC_C_FILES = src/malloc_initialize.c src/calloc.c src/malloc.c \
src/mallocinfo.c src/malloc_walk.c src/malloc_get_statistics.c \
src/malloc_report_statistics.c src/malloc_report_statistics_plugin.c \
src/malloc_statistics_helpers.c src/malloc_boundary.c src/posix_memalign.c \
- src/malloc_deferred.c
+ src/malloc_deferred.c src/malloc_sbrk_helpers.c
PASSWORD_GROUP_C_FILES = src/getpwent.c
diff --git a/cpukit/libcsupport/include/rtems/malloc.h b/cpukit/libcsupport/include/rtems/malloc.h
index 763830397a..6bb152bbf9 100644
--- a/cpukit/libcsupport/include/rtems/malloc.h
+++ b/cpukit/libcsupport/include/rtems/malloc.h
@@ -5,14 +5,14 @@
/*
* RTEMS Malloc Extensions
*
- * COPYRIGHT (c) 1989-1997.
+ * COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may in
* the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
- * $ld:
+ * $Id$
*/
#ifndef _RTEMS_MALLOC_H
@@ -45,11 +45,11 @@ typedef struct {
void (*initialize)(void);
void (*at_malloc)(void *);
void (*at_free)(void *);
-} rtems_malloc_statististics_functions_t;
+} rtems_malloc_statistics_functions_t;
-extern rtems_malloc_statististics_functions_t
+extern rtems_malloc_statistics_functions_t
rtems_malloc_statistics_helpers_table;
-extern rtems_malloc_statististics_functions_t *rtems_malloc_statistics_helpers;
+extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
/*
* Malloc boundary support plugin
@@ -65,7 +65,16 @@ typedef struct {
extern rtems_malloc_boundary_functions_t rtems_malloc_boundary_helpers_table;
extern rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers;
+/*
+ * Malloc Heap Extension (sbrk) plugin
+ */
+typedef struct {
+ void *(*initialize)(void *, size_t);
+ void *(*extend)(size_t);
+} rtems_malloc_sbrk_functions_t;
+extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table;
+extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers;
/** @brief Print Malloc Statistic Usage Report
*
diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c
index a77444dc2c..954d5f7690 100644
--- a/cpukit/libcsupport/src/malloc.c
+++ b/cpukit/libcsupport/src/malloc.c
@@ -27,9 +27,6 @@ void *malloc(
)
{
void *return_this;
- void *starting_address;
- uint32_t the_size;
- uint32_t sbrk_amount;
Chain_Node *to_be_freed;
MSBUMP(malloc_calls, 1);
@@ -77,33 +74,8 @@ void *malloc(
return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
if ( !return_this ) {
- /*
- * Round to the "requested sbrk amount" so hopefully we won't have
- * to grow again for a while. This effectively does sbrk() calls
- * in "page" amounts.
- */
-
- sbrk_amount = RTEMS_Malloc_Sbrk_amount;
-
- if ( sbrk_amount == 0 )
- return (void *) 0;
-
- the_size = ((size + sbrk_amount) / sbrk_amount * sbrk_amount);
-
- if ((starting_address = (void *)sbrk(the_size))
- == (void*) -1)
- return (void *) 0;
-
- if ( !_Protected_heap_Extend(
- &RTEMS_Malloc_Heap, starting_address, the_size) ) {
- sbrk(-the_size);
- errno = ENOMEM;
- return (void *) 0;
- }
-
- MSBUMP(space_available, the_size);
-
- return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
+ if (rtems_malloc_sbrk_helpers)
+ return_this = (*rtems_malloc_sbrk_helpers->extend)( size );
if ( !return_this ) {
errno = ENOMEM;
return (void *) 0;
diff --git a/cpukit/libcsupport/src/malloc_initialize.c b/cpukit/libcsupport/src/malloc_initialize.c
index 08fc351f7f..362d4477e2 100644
--- a/cpukit/libcsupport/src/malloc_initialize.c
+++ b/cpukit/libcsupport/src/malloc_initialize.c
@@ -22,7 +22,6 @@
Heap_Control RTEMS_Malloc_Heap;
Chain_Control RTEMS_Malloc_GC_list;
-size_t RTEMS_Malloc_Sbrk_amount;
rtems_malloc_statistics_t rtems_malloc_statistics;
void RTEMS_Malloc_Initialize(
@@ -33,8 +32,6 @@ void RTEMS_Malloc_Initialize(
{
uint32_t status;
void *starting_address;
- uintptr_t old_address;
- uintptr_t uaddress;
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
/*
@@ -55,36 +52,18 @@ void RTEMS_Malloc_Initialize(
*/
Chain_Initialize_empty(&RTEMS_Malloc_GC_list);
- /*
- * If the starting address is 0 then we are to attempt to
- * get length worth of memory using sbrk. Make sure we
- * align the address that we get back.
- */
-
starting_address = start;
- RTEMS_Malloc_Sbrk_amount = sbrk_amount;
-
- if (!starting_address) {
- uaddress = (uintptr_t)sbrk(length);
-
- if (uaddress == (uintptr_t) -1) {
- rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
- /* DOES NOT RETURN!!! */
- }
- if (uaddress & (CPU_HEAP_ALIGNMENT-1)) {
- old_address = uaddress;
- uaddress = (uaddress + CPU_HEAP_ALIGNMENT) & ~(CPU_HEAP_ALIGNMENT-1);
-
- /*
- * adjust the length by whatever we aligned by
- */
- length -= uaddress - old_address;
- }
-
- starting_address = (void *)uaddress;
+ /*
+ * Initialize the optional sbrk support for extending the heap
+ */
+ if (rtems_malloc_sbrk_helpers) {
+ starting_address = (*rtems_malloc_sbrk_helpers->initialize)(
+ start,
+ sbrk_amount
+ );
}
-
+
/*
* If the BSP is not clearing out the workspace, then it is most likely
* not clearing out the initial memory for the heap. There is no
diff --git a/cpukit/libcsupport/src/malloc_p.h b/cpukit/libcsupport/src/malloc_p.h
index 3c2cdddf87..a505d920a2 100644
--- a/cpukit/libcsupport/src/malloc_p.h
+++ b/cpukit/libcsupport/src/malloc_p.h
@@ -39,7 +39,6 @@
*/
extern Heap_Control RTEMS_Malloc_Heap;
extern Chain_Control RTEMS_Malloc_GC_list;
-extern size_t RTEMS_Malloc_Sbrk_amount;
/*
* Malloc Statistics Structure
diff --git a/cpukit/libcsupport/src/malloc_sbrk_helpers.c b/cpukit/libcsupport/src/malloc_sbrk_helpers.c
new file mode 100644
index 0000000000..ac992bba88
--- /dev/null
+++ b/cpukit/libcsupport/src/malloc_sbrk_helpers.c
@@ -0,0 +1,111 @@
+/*
+ * RTEMS Malloc Family Implementation --Initialization
+ *
+ *
+ * COPYRIGHT (c) 1989-2007.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/malloc.h>
+#include "malloc_p.h"
+
+#include <errno.h>
+
+size_t RTEMS_Malloc_Sbrk_amount;
+
+void *malloc_sbrk_initialize(
+ void *starting_address,
+ size_t length
+)
+{
+ uintptr_t old_address;
+ uintptr_t uaddress;
+
+ RTEMS_Malloc_Sbrk_amount = length;
+
+ /*
+ * If the starting address is 0 then we are to attempt to
+ * get length worth of memory using sbrk. Make sure we
+ * align the address that we get back.
+ */
+
+ if (!starting_address) {
+ uaddress = (uintptr_t)sbrk(length);
+
+ if (uaddress == (uintptr_t) -1) {
+ rtems_fatal_error_occurred( RTEMS_NO_MEMORY );
+ /* DOES NOT RETURN!!! */
+ }
+
+ if (uaddress & (CPU_HEAP_ALIGNMENT-1)) {
+ old_address = uaddress;
+ uaddress = (uaddress + CPU_HEAP_ALIGNMENT) & ~(CPU_HEAP_ALIGNMENT-1);
+
+ /*
+ * adjust the length by whatever we aligned by
+ */
+ length -= uaddress - old_address;
+ }
+
+ starting_address = (void *)uaddress;
+ }
+ return starting_address;
+}
+
+void *malloc_sbrk_extend_and_allocate(
+ size_t size
+)
+{
+ uint32_t sbrk_amount;
+ void *starting_address;
+ uint32_t the_size;
+ void *return_this;
+
+ /*
+ * Round to the "requested sbrk amount" so hopefully we won't have
+ * to grow again for a while. This effectively does sbrk() calls
+ * in "page" amounts.
+ */
+
+ sbrk_amount = RTEMS_Malloc_Sbrk_amount;
+
+ if ( sbrk_amount == 0 )
+ return (void *) 0;
+
+ the_size = ((size + sbrk_amount) / sbrk_amount * sbrk_amount);
+
+ starting_address = (void *) sbrk(the_size);
+ if ( starting_address == (void*) -1 )
+ return (void *) 0;
+
+ if ( !_Protected_heap_Extend(
+ &RTEMS_Malloc_Heap, starting_address, the_size) ) {
+ sbrk(-the_size);
+ errno = ENOMEM;
+ return (void *) 0;
+ }
+
+ MSBUMP(space_available, the_size);
+
+ return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
+ return return_this;
+}
+
+
+rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table = {
+ malloc_sbrk_initialize,
+ malloc_sbrk_extend_and_allocate
+};
+
+
diff --git a/cpukit/libcsupport/src/malloc_statistics_helpers.c b/cpukit/libcsupport/src/malloc_statistics_helpers.c
index 9e744a4c40..53d9bec99d 100644
--- a/cpukit/libcsupport/src/malloc_statistics_helpers.c
+++ b/cpukit/libcsupport/src/malloc_statistics_helpers.c
@@ -66,14 +66,11 @@ void rtems_malloc_statistics_at_free(
}
}
-rtems_malloc_statististics_functions_t rtems_malloc_statistics_helpers_table = {
+rtems_malloc_statistics_functions_t rtems_malloc_statistics_helpers_table = {
rtems_malloc_statistics_initialize,
rtems_malloc_statistics_at_malloc,
rtems_malloc_statistics_at_free,
};
-rtems_malloc_statististics_functions_t *rtems_malloc_statistics_helpers =
- &rtems_malloc_statistics_helpers_table;
-
#endif