summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-01-29 17:28:27 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-01-29 17:28:27 +0000
commite0a66c157439fc5512e3406542a5a96667f2e452 (patch)
treedc2d7ae38579af1757a1a0f40dfe31a0450d8b4f /cpukit/libcsupport
parent2008-01-29 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-e0a66c157439fc5512e3406542a5a96667f2e452.tar.bz2
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.
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r--cpukit/libcsupport/Makefile.am13
-rw-r--r--cpukit/libcsupport/include/rtems/malloc.h20
-rw-r--r--cpukit/libcsupport/src/malloc_walk.c7
-rw-r--r--cpukit/libcsupport/src/posix_memalign.c64
-rw-r--r--cpukit/libcsupport/src/realloc.c10
-rw-r--r--cpukit/libcsupport/src/rtems_memalign.c91
6 files changed, 130 insertions, 75 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index a36ce089cc..f62c9f96ac 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -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
diff --git a/cpukit/libcsupport/include/rtems/malloc.h b/cpukit/libcsupport/include/rtems/malloc.h
index e347082819..d5b5eb691d 100644
--- a/cpukit/libcsupport/include/rtems/malloc.h
+++ b/cpukit/libcsupport/include/rtems/malloc.h
@@ -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
diff --git a/cpukit/libcsupport/src/malloc_walk.c b/cpukit/libcsupport/src/malloc_walk.c
index a376282077..a0d7d3213c 100644
--- a/cpukit/libcsupport/src/malloc_walk.c
+++ b/cpukit/libcsupport/src/malloc_walk.c
@@ -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
diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c
index 34b6b627e6..19d469e0c1 100644
--- a/cpukit/libcsupport/src/posix_memalign.c
+++ b/cpukit/libcsupport/src/posix_memalign.c
@@ -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.
- */
- 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.
+ * rtems_memalign does all of the error checking work EXCEPT
+ * for adding restrictionso on the alignment.
*/
- 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
diff --git a/cpukit/libcsupport/src/realloc.c b/cpukit/libcsupport/src/realloc.c
index cba244cc37..745568c49d 100644
--- a/cpukit/libcsupport/src/realloc.c
+++ b/cpukit/libcsupport/src/realloc.c
@@ -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 );
diff --git a/cpukit/libcsupport/src/rtems_memalign.c b/cpukit/libcsupport/src/rtems_memalign.c
new file mode 100644
index 0000000000..679d8c7af7
--- /dev/null
+++ b/cpukit/libcsupport/src/rtems_memalign.c
@@ -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