void *rtems_cache_coherent_allocate( size_t size, uintptr_t alignment, uintptr_t boundary ) { void *ptr; Heap_Control *heap; _RTEMS_Lock_allocator(); heap = cache_coherent_heap; if ( heap == NULL ) { heap = RTEMS_Malloc_Heap; } ptr = _Heap_Allocate_aligned_with_boundary( heap, size, alignment, boundary ); _RTEMS_Unlock_allocator(); return ptr; }
void *rtems_heap_allocate_aligned_with_boundary( size_t size, uintptr_t alignment, uintptr_t boundary ) { Heap_Control *heap = RTEMS_Malloc_Heap; void *p; switch ( _Malloc_System_state() ) { case MALLOC_SYSTEM_STATE_NORMAL: _Malloc_Process_deferred_frees(); p = _Protected_heap_Allocate_aligned_with_boundary( heap, size, alignment, boundary ); break; case MALLOC_SYSTEM_STATE_NO_PROTECTION: p = _Heap_Allocate_aligned_with_boundary( heap, size, alignment, boundary ); break; default: /* * Do not attempt to allocate memory if not in correct system state. */ return NULL; } if ( p == NULL && alignment == 0 && boundary == 0 ) { p = (*rtems_malloc_extend_handler)( heap, size ); } /* * If the user wants us to dirty the allocated memory, then do it. */ if ( p != NULL && rtems_malloc_dirty_helper != NULL ) (*rtems_malloc_dirty_helper)( p, size ); return p; }
static void *test_alloc_two_pages(void) { void *alloc_begin_ptr = _Heap_Allocate_aligned_with_boundary( &TestHeap, 3 * TestHeap.page_size / 2, 0, 0 ); test_check_alloc_simple( alloc_begin_ptr, 3 * TestHeap.page_size / 2, 0, 0 ); rtems_test_assert( alloc_begin_ptr != NULL ); return alloc_begin_ptr; }
static void *test_alloc_one_page(void) { void *alloc_begin_ptr = _Heap_Allocate_aligned_with_boundary( &TestHeap, 1, 0, 0 ); test_check_alloc_simple( alloc_begin_ptr, 1, 0, 0 ); rtems_test_assert( alloc_begin_ptr != NULL ); return alloc_begin_ptr; }
void *_Protected_heap_Allocate_aligned_with_boundary( Heap_Control *heap, uintptr_t size, uintptr_t alignment, uintptr_t boundary ) { void *p; _RTEMS_Lock_allocator(); p = _Heap_Allocate_aligned_with_boundary( heap, size, alignment, boundary ); _RTEMS_Unlock_allocator(); return p; }
static void *test_alloc_simple( uintptr_t alloc_size, uintptr_t alignment, uintptr_t boundary ) { void *alloc_begin_ptr = _Heap_Allocate_aligned_with_boundary( &TestHeap, alloc_size, alignment, boundary ); test_check_alloc_simple( alloc_begin_ptr, alloc_size, alignment, boundary ); rtems_test_assert( alloc_begin_ptr != NULL ); return alloc_begin_ptr; }
static void *test_alloc( uintptr_t alloc_size, uintptr_t alignment, uintptr_t boundary, void *expected_alloc_begin_ptr ) { void *alloc_begin_ptr = _Heap_Allocate_aligned_with_boundary( &TestHeap, alloc_size, alignment, boundary ); test_check_alloc( alloc_begin_ptr, expected_alloc_begin_ptr, alloc_size, alignment, boundary ); return alloc_begin_ptr; }
static void *test_allocate_block(void) { return _Heap_Allocate_aligned_with_boundary( &TestHeap, 1, 0, 0 ); }