mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-23 11:26:42 +08:00
2008-01-29 Joel Sherrill <joel.sherrill@OARcorp.com>
* libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h, libcsupport/src/malloc_walk.c, libcsupport/src/posix_memalign.c, libcsupport/src/realloc.c, score/src/heapwalk.c: Add rtems_memalign as helper and as exposed nmemalign variant with few restrictions. Also turn on compilation of _Heap_Walk but make forced calls to it conditionally compiled. This should allow more flexibility to the user as to run-time checking of the heap. * libcsupport/src/rtems_memalign.c: New file.
This commit is contained in:
@@ -1,3 +1,14 @@
|
||||
2008-01-29 Joel Sherrill <joel.sherrill@OARcorp.com>
|
||||
|
||||
* libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h,
|
||||
libcsupport/src/malloc_walk.c, libcsupport/src/posix_memalign.c,
|
||||
libcsupport/src/realloc.c, score/src/heapwalk.c: Add rtems_memalign
|
||||
as helper and as exposed nmemalign variant with few restrictions.
|
||||
Also turn on compilation of _Heap_Walk but make forced calls to it
|
||||
conditionally compiled. This should allow more flexibility to the
|
||||
user as to run-time checking of the heap.
|
||||
* libcsupport/src/rtems_memalign.c: New file.
|
||||
|
||||
2008-01-28 Joel Sherrill <joel.sherrill@OARcorp.com>
|
||||
|
||||
* sapi/include/confdefs.h, score/src/mpci.c, score/src/objectmp.c,
|
||||
|
||||
@@ -79,12 +79,13 @@ ID_C_FILES = src/getegid.c src/geteuid.c src/getgid.c src/getgroups.c \
|
||||
src/setpgid.c src/setsid.c
|
||||
|
||||
MALLOC_C_FILES = src/malloc_initialize.c src/calloc.c src/malloc.c \
|
||||
src/realloc.c src/_calloc_r.c src/free.c src/_free_r.c src/_malloc_r.c \
|
||||
src/_realloc_r.c src/__brk.c src/__sbrk.c src/mallocfreespace.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_sbrk_helpers.c src/malloc_dirtier.c
|
||||
src/realloc.c src/_calloc_r.c src/free.c src/_free_r.c src/_malloc_r.c \
|
||||
src/_realloc_r.c src/__brk.c src/__sbrk.c src/mallocfreespace.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/rtems_memalign.c src/malloc_deferred.c \
|
||||
src/malloc_sbrk_helpers.c src/malloc_dirtier.c
|
||||
|
||||
PASSWORD_GROUP_C_FILES = src/getpwent.c
|
||||
|
||||
|
||||
@@ -125,4 +125,24 @@ void malloc_report_statistics_with_plugin(
|
||||
rtems_printk_plugin_t print
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* This method is a help memalign implementation which does all
|
||||
* error checking done by posix_memalign() EXCEPT it does NOT
|
||||
* place numeric restrictions on the alignment value.
|
||||
*
|
||||
* @param[in] pointer points to the user pointer
|
||||
* @param[in] alignment is the desired alignment
|
||||
* @param[in] size is the allocation request size in bytes
|
||||
*
|
||||
* @return This methods returns zero on success and a POSIX errno
|
||||
* value to indicate the failure condition. On success
|
||||
* *pointer will contain the address of the allocated memory.
|
||||
*/
|
||||
int rtems_memalign(
|
||||
void **pointer,
|
||||
size_t alignment,
|
||||
size_t size
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
#endif
|
||||
|
||||
#ifdef RTEMS_NEWLIB
|
||||
#include <sys/reent.h>
|
||||
#include "malloc_p.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void malloc_walk(size_t source, size_t printf_enabled)
|
||||
{
|
||||
#if defined(RTEMS_DEBUG)
|
||||
_Protected_heap_Walk( &RTEMS_Malloc_Heap, source, printf_enabled );
|
||||
#endif
|
||||
_Protected_heap_Walk( &RTEMS_Malloc_Heap, source, printf_enabled );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* posix_memalign()
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2007.
|
||||
* COPYRIGHT (c) 1989-2008.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
@@ -34,69 +34,13 @@ int posix_memalign(
|
||||
*/
|
||||
MSBUMP(memalign_calls, 1);
|
||||
|
||||
/*
|
||||
* Parameter error checks
|
||||
*/
|
||||
if ( !pointer )
|
||||
return EINVAL;
|
||||
|
||||
*pointer = NULL;
|
||||
|
||||
if (((alignment - 1) & alignment) != 0 || (alignment < sizeof(void *)))
|
||||
return EINVAL;
|
||||
|
||||
if ( !size )
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
* Do not attempt to allocate memory if not in correct system state.
|
||||
* rtems_memalign does all of the error checking work EXCEPT
|
||||
* for adding restrictionso on the alignment.
|
||||
*/
|
||||
if ( _System_state_Is_up(_System_state_Get()) &&
|
||||
!malloc_is_system_state_OK() )
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
*
|
||||
* If some free's have been deferred, then do them now.
|
||||
*/
|
||||
malloc_deferred_frees_process();
|
||||
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* If the support for a boundary area at the end of the heap
|
||||
* block allocated is turned on, then adjust the size.
|
||||
*/
|
||||
if (rtems_malloc_boundary_helpers)
|
||||
size += (*rtems_malloc_boundary_helpers->overhead)();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Perform the aligned allocation requested
|
||||
*/
|
||||
|
||||
return_this = _Protected_heap_Allocate_aligned(
|
||||
&RTEMS_Malloc_Heap,
|
||||
size,
|
||||
alignment
|
||||
);
|
||||
if ( !return_this )
|
||||
return ENOMEM;
|
||||
|
||||
/*
|
||||
* If configured, update the more involved statistics
|
||||
*/
|
||||
if ( rtems_malloc_statistics_helpers )
|
||||
(*rtems_malloc_statistics_helpers->at_malloc)(pointer);
|
||||
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* If configured, set the boundary area
|
||||
*/
|
||||
if (rtems_malloc_boundary_helpers)
|
||||
(*rtems_malloc_boundary_helpers->at_malloc)(return_this, size);
|
||||
#endif
|
||||
|
||||
*pointer = return_this;
|
||||
return 0;
|
||||
return rtems_memalign( pointer, alignment, size );
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -54,6 +54,11 @@ void *realloc(
|
||||
return (void *) 0;
|
||||
}
|
||||
|
||||
if ( !_Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &old_size) ) {
|
||||
errno = EINVAL;
|
||||
return (void *) 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* If block boundary integrity checking is enabled, then
|
||||
* we need to account for the boundary memory again.
|
||||
@@ -89,11 +94,6 @@ void *realloc(
|
||||
return (void *) 0;
|
||||
}
|
||||
|
||||
if ( !_Protected_heap_Get_block_size(&RTEMS_Malloc_Heap, ptr, &old_size) ) {
|
||||
errno = EINVAL;
|
||||
return (void *) 0;
|
||||
}
|
||||
|
||||
memcpy( new_area, ptr, (size < old_size) ? size : old_size );
|
||||
free( ptr );
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* rtems_memalign() - Raw aligned allocate from Protected Heap
|
||||
*
|
||||
* COPYRIGHT (c) 1989-2008.
|
||||
* 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
|
||||
|
||||
#ifdef RTEMS_NEWLIB
|
||||
#include "malloc_p.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
int rtems_memalign(
|
||||
void **pointer,
|
||||
size_t alignment,
|
||||
size_t size
|
||||
)
|
||||
{
|
||||
void *return_this;
|
||||
|
||||
/*
|
||||
* Parameter error checks
|
||||
*/
|
||||
if ( !pointer )
|
||||
return EINVAL;
|
||||
|
||||
*pointer = NULL;
|
||||
|
||||
/*
|
||||
* Do not attempt to allocate memory if not in correct system state.
|
||||
*/
|
||||
if ( _System_state_Is_up(_System_state_Get()) &&
|
||||
!malloc_is_system_state_OK() )
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
*
|
||||
* If some free's have been deferred, then do them now.
|
||||
*/
|
||||
malloc_deferred_frees_process();
|
||||
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* If the support for a boundary area at the end of the heap
|
||||
* block allocated is turned on, then adjust the size.
|
||||
*/
|
||||
if (rtems_malloc_boundary_helpers)
|
||||
size += (*rtems_malloc_boundary_helpers->overhead)();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Perform the aligned allocation requested
|
||||
*/
|
||||
|
||||
return_this = _Protected_heap_Allocate_aligned(
|
||||
&RTEMS_Malloc_Heap,
|
||||
size,
|
||||
alignment
|
||||
);
|
||||
if ( !return_this )
|
||||
return ENOMEM;
|
||||
|
||||
/*
|
||||
* If configured, update the more involved statistics
|
||||
*/
|
||||
if ( rtems_malloc_statistics_helpers )
|
||||
(*rtems_malloc_statistics_helpers->at_malloc)(pointer);
|
||||
|
||||
#if defined(RTEMS_MALLOC_BOUNDARY_HELPERS)
|
||||
/*
|
||||
* If configured, set the boundary area
|
||||
*/
|
||||
if (rtems_malloc_boundary_helpers)
|
||||
(*rtems_malloc_boundary_helpers->at_malloc)(return_this, size);
|
||||
#endif
|
||||
|
||||
*pointer = return_this;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -37,19 +37,6 @@
|
||||
* Output parameters: NONE
|
||||
*/
|
||||
|
||||
#if !defined(RTEMS_HEAP_DEBUG)
|
||||
|
||||
boolean _Heap_Walk(
|
||||
Heap_Control *the_heap,
|
||||
int source,
|
||||
boolean do_dump
|
||||
)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#else /* defined(RTEMS_HEAP_DEBUG) */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
boolean _Heap_Walk(
|
||||
@@ -182,4 +169,3 @@ boolean _Heap_Walk(
|
||||
return error;
|
||||
|
||||
}
|
||||
#endif /* defined(RTEMS_HEAP_DEBUG) */
|
||||
|
||||
Reference in New Issue
Block a user