mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-07 16:13:07 +00:00
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.
This commit is contained in:
@@ -1,3 +1,18 @@
|
|||||||
|
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.
|
||||||
|
|
||||||
2008-01-08 Joel Sherrill <joel.sherrill@OARcorp.com>
|
2008-01-08 Joel Sherrill <joel.sherrill@OARcorp.com>
|
||||||
|
|
||||||
* score/Makefile.am: Add missing file.
|
* score/Makefile.am: Add missing file.
|
||||||
|
|||||||
@@ -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/mallocinfo.c src/malloc_walk.c src/malloc_get_statistics.c \
|
||||||
src/malloc_report_statistics.c src/malloc_report_statistics_plugin.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_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
|
PASSWORD_GROUP_C_FILES = src/getpwent.c
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
/*
|
/*
|
||||||
* RTEMS Malloc Extensions
|
* RTEMS Malloc Extensions
|
||||||
*
|
*
|
||||||
* COPYRIGHT (c) 1989-1997.
|
* COPYRIGHT (c) 1989-2007.
|
||||||
* On-Line Applications Research Corporation (OAR).
|
* On-Line Applications Research Corporation (OAR).
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may in
|
* The license and distribution terms for this file may in
|
||||||
* the file LICENSE in this distribution or at
|
* the file LICENSE in this distribution or at
|
||||||
* http://www.rtems.com/license/LICENSE.
|
* http://www.rtems.com/license/LICENSE.
|
||||||
*
|
*
|
||||||
* $ld:
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _RTEMS_MALLOC_H
|
#ifndef _RTEMS_MALLOC_H
|
||||||
@@ -45,11 +45,11 @@ typedef struct {
|
|||||||
void (*initialize)(void);
|
void (*initialize)(void);
|
||||||
void (*at_malloc)(void *);
|
void (*at_malloc)(void *);
|
||||||
void (*at_free)(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;
|
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
|
* 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_table;
|
||||||
extern rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers;
|
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
|
/** @brief Print Malloc Statistic Usage Report
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -27,9 +27,6 @@ void *malloc(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
void *return_this;
|
void *return_this;
|
||||||
void *starting_address;
|
|
||||||
uint32_t the_size;
|
|
||||||
uint32_t sbrk_amount;
|
|
||||||
Chain_Node *to_be_freed;
|
Chain_Node *to_be_freed;
|
||||||
|
|
||||||
MSBUMP(malloc_calls, 1);
|
MSBUMP(malloc_calls, 1);
|
||||||
@@ -77,33 +74,8 @@ void *malloc(
|
|||||||
return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
|
return_this = _Protected_heap_Allocate( &RTEMS_Malloc_Heap, size );
|
||||||
|
|
||||||
if ( !return_this ) {
|
if ( !return_this ) {
|
||||||
/*
|
if (rtems_malloc_sbrk_helpers)
|
||||||
* Round to the "requested sbrk amount" so hopefully we won't have
|
return_this = (*rtems_malloc_sbrk_helpers->extend)( size );
|
||||||
* 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 ( !return_this ) {
|
if ( !return_this ) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return (void *) 0;
|
return (void *) 0;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
Heap_Control RTEMS_Malloc_Heap;
|
Heap_Control RTEMS_Malloc_Heap;
|
||||||
Chain_Control RTEMS_Malloc_GC_list;
|
Chain_Control RTEMS_Malloc_GC_list;
|
||||||
size_t RTEMS_Malloc_Sbrk_amount;
|
|
||||||
rtems_malloc_statistics_t rtems_malloc_statistics;
|
rtems_malloc_statistics_t rtems_malloc_statistics;
|
||||||
|
|
||||||
void RTEMS_Malloc_Initialize(
|
void RTEMS_Malloc_Initialize(
|
||||||
@@ -33,8 +32,6 @@ void RTEMS_Malloc_Initialize(
|
|||||||
{
|
{
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
void *starting_address;
|
void *starting_address;
|
||||||
uintptr_t old_address;
|
|
||||||
uintptr_t uaddress;
|
|
||||||
|
|
||||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||||
/*
|
/*
|
||||||
@@ -55,34 +52,16 @@ void RTEMS_Malloc_Initialize(
|
|||||||
*/
|
*/
|
||||||
Chain_Initialize_empty(&RTEMS_Malloc_GC_list);
|
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;
|
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
|
* Initialize the optional sbrk support for extending the heap
|
||||||
*/
|
*/
|
||||||
length -= uaddress - old_address;
|
if (rtems_malloc_sbrk_helpers) {
|
||||||
}
|
starting_address = (*rtems_malloc_sbrk_helpers->initialize)(
|
||||||
|
start,
|
||||||
starting_address = (void *)uaddress;
|
sbrk_amount
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -39,7 +39,6 @@
|
|||||||
*/
|
*/
|
||||||
extern Heap_Control RTEMS_Malloc_Heap;
|
extern Heap_Control RTEMS_Malloc_Heap;
|
||||||
extern Chain_Control RTEMS_Malloc_GC_list;
|
extern Chain_Control RTEMS_Malloc_GC_list;
|
||||||
extern size_t RTEMS_Malloc_Sbrk_amount;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Malloc Statistics Structure
|
* Malloc Statistics Structure
|
||||||
|
|||||||
111
cpukit/libcsupport/src/malloc_sbrk_helpers.c
Normal file
111
cpukit/libcsupport/src/malloc_sbrk_helpers.c
Normal file
@@ -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
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -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_initialize,
|
||||||
rtems_malloc_statistics_at_malloc,
|
rtems_malloc_statistics_at_malloc,
|
||||||
rtems_malloc_statistics_at_free,
|
rtems_malloc_statistics_at_free,
|
||||||
};
|
};
|
||||||
|
|
||||||
rtems_malloc_statististics_functions_t *rtems_malloc_statistics_helpers =
|
|
||||||
&rtems_malloc_statistics_helpers_table;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -242,6 +242,30 @@ extern int rtems_telnetd_maximum_ptys;
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RTEMS Malloc configuration
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <rtems/malloc.h>
|
||||||
|
|
||||||
|
#ifdef CONFIGURE_INIT
|
||||||
|
rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers =
|
||||||
|
#ifndef CONFIGURE_MALLOC_STATISTICS
|
||||||
|
NULL;
|
||||||
|
#else
|
||||||
|
&rtems_malloc_statistics_helpers_table;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIGURE_INIT
|
||||||
|
rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers =
|
||||||
|
#ifndef CONFIGURE_MALLOC_BSP_SUPPORTS_SBRK
|
||||||
|
NULL;
|
||||||
|
#else
|
||||||
|
&rtems_malloc_sbrk_helpers_table;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default User Initialization Task Table. This table guarantees that
|
* Default User Initialization Task Table. This table guarantees that
|
||||||
* one user initialization table is defined.
|
* one user initialization table is defined.
|
||||||
|
|||||||
Reference in New Issue
Block a user