summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/src/posix_memalign.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-12-19 16:03:54 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-12-19 16:03:54 +0000
commit8e30a269a21cd61ca1387e666e458e52c0b153ab (patch)
tree4d1cc760d319a170b335b9e90ea9d26162ffc687 /cpukit/libcsupport/src/posix_memalign.c
parent2007-12-18 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-8e30a269a21cd61ca1387e666e458e52c0b153ab.tar.bz2
2007-12-19 Joel Sherrill <joel.sherrill@OARcorp.com>
* libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h, libcsupport/src/free.c, libcsupport/src/malloc.c, libcsupport/src/malloc_p.h, libcsupport/src/malloc_report_statistics_plugin.c, libmisc/shell/shell.c, libmisc/shell/shell.h, score/src/objectinitializeinformation.c: Add posix_memalign. Split out management of deferred frees to subroutines. * libcsupport/src/malloc_deferred.c, libcsupport/src/posix_memalign.c: New files.
Diffstat (limited to 'cpukit/libcsupport/src/posix_memalign.c')
-rw-r--r--cpukit/libcsupport/src/posix_memalign.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/cpukit/libcsupport/src/posix_memalign.c b/cpukit/libcsupport/src/posix_memalign.c
new file mode 100644
index 0000000000..c3dae3449e
--- /dev/null
+++ b/cpukit/libcsupport/src/posix_memalign.c
@@ -0,0 +1,102 @@
+/*
+ * posix_memalign()
+ *
+ * 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
+
+#ifdef RTEMS_NEWLIB
+#include "malloc_p.h"
+
+#include <stdlib.h>
+#include <errno.h>
+
+int posix_memalign(
+ void **pointer,
+ size_t alignment,
+ size_t size
+)
+{
+ void *return_this;
+
+ /*
+ * Update call statistics
+ */
+ 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.
+ */
+ malloc_process_deferred_frees();
+
+ #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