diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-02-25 09:02:43 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-02-25 11:35:54 +0100 |
commit | 9d1f39434585e8d3f8897d95a2bfe1ddccb79aec (patch) | |
tree | 2d3a0868f410cff137871f5ce493df4f27a22b1a /cpukit/libcsupport/src/malloc.c | |
parent | malloc: Use dedicated lock for deferred frees (diff) | |
download | rtems-9d1f39434585e8d3f8897d95a2bfe1ddccb79aec.tar.bz2 |
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.
Diffstat (limited to '')
-rw-r--r-- | cpukit/libcsupport/src/malloc.c | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/cpukit/libcsupport/src/malloc.c b/cpukit/libcsupport/src/malloc.c index 73203e5b1c..03e2208ef4 100644 --- a/cpukit/libcsupport/src/malloc.c +++ b/cpukit/libcsupport/src/malloc.c @@ -31,44 +31,17 @@ void *malloc( void *return_this; /* - * If some free's have been deferred, then do them now. - */ - malloc_deferred_frees_process(); - - /* * Validate the parameters */ if ( !size ) return (void *) 0; - /* - * Do not attempt to allocate memory if not in correct system state. - */ - if ( !malloc_is_system_state_OK() ) - return NULL; - - /* - * Try to give a segment in the current heap if there is not - * enough space then try to grow the heap. - * If this fails then return a NULL pointer. - */ - - return_this = _Protected_heap_Allocate( RTEMS_Malloc_Heap, size ); - + return_this = rtems_heap_allocate_aligned_with_boundary( size, 0, 0 ); if ( !return_this ) { - return_this = (*rtems_malloc_extend_handler)( RTEMS_Malloc_Heap, size ); - if ( !return_this ) { - errno = ENOMEM; - return (void *) 0; - } + errno = ENOMEM; + return (void *) 0; } - /* - * If the user wants us to dirty the allocated memory, then do it. - */ - if ( rtems_malloc_dirty_helper ) - (*rtems_malloc_dirty_helper)( return_this, size ); - return return_this; } |