[add]posix_memalign
This commit is contained in:
@ -27,10 +27,20 @@
|
||||
#pragma import(__use_no_heap)
|
||||
#endif /* __CC_ARM */
|
||||
|
||||
#if defined (__clang__) && defined (RT_USING_CPLUSPLUS)
|
||||
#define RT_USING_POSIX_MEMALIGN
|
||||
#endif
|
||||
|
||||
#include <sys/errno.h>
|
||||
|
||||
void *malloc(size_t n)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
#ifndef RT_USING_POSIX_MEMALIGN
|
||||
return rt_malloc(n);
|
||||
#else
|
||||
return rt_malloc_align(n, RT_ALIGN_SIZE);
|
||||
#endif
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
return RT_NULL;
|
||||
@ -63,9 +73,36 @@ RTM_EXPORT(calloc);
|
||||
void free(void *rmem)
|
||||
{
|
||||
#ifdef RT_USING_HEAP
|
||||
#ifndef RT_USING_POSIX_MEMALIGN
|
||||
rt_free(rmem);
|
||||
#else
|
||||
rt_free_align(rmem);
|
||||
#endif
|
||||
#else
|
||||
_NO_HEAP_ERROR();
|
||||
#endif
|
||||
}
|
||||
RTM_EXPORT(free);
|
||||
|
||||
#if defined RT_USING_POSIX_MEMALIGN
|
||||
int posix_memalign(void **ptr, size_t align, size_t size)
|
||||
{
|
||||
if ((align & (align - 1)) != 0)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if(align != RT_ALIGN(align, sizeof(void *)))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*ptr = rt_malloc_align(size, align);
|
||||
|
||||
if(*ptr == RT_NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user