Files
rtems/cpukit/libcsupport/src/rtems_memalign.c
Sebastian Huber 9d1f394345 malloc: Add _Malloc_System_state()
Replace malloc_is_system_state_OK() with _Malloc_System_state() to allow
early allocations, e.g. in bsp_start().  Here the _Thread_Executing is
NULL, thus an _API_Mutex_Lock() would lead to a NULL pointer access.

Move malloc() support code to general case
rtems_heap_allocate_aligned_with_boundary().  Use
rtems_heap_allocate_aligned_with_boundary() to avoid duplicated code.
2016-02-25 11:35:54 +01:00

54 lines
916 B
C

/**
* @file
*
* @brief RTEMS Variation on Aligned Memory Allocation
* @ingroup MallocSupport
*/
/*
* 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.org/license/LICENSE.
*/
#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;
/*
* Perform the aligned allocation requested
*/
return_this = rtems_heap_allocate_aligned_with_boundary( size, alignment, 0 );
if ( !return_this )
return ENOMEM;
*pointer = return_this;
return 0;
}
#endif