1 | /* |
---|
2 | * rtems_memalign() - Raw aligned allocate from Protected Heap |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2008. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #if HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #ifdef RTEMS_NEWLIB |
---|
19 | #include "malloc_p.h" |
---|
20 | |
---|
21 | #include <stdlib.h> |
---|
22 | #include <errno.h> |
---|
23 | |
---|
24 | int rtems_memalign( |
---|
25 | void **pointer, |
---|
26 | size_t alignment, |
---|
27 | size_t size |
---|
28 | ) |
---|
29 | { |
---|
30 | void *return_this; |
---|
31 | |
---|
32 | /* |
---|
33 | * Parameter error checks |
---|
34 | */ |
---|
35 | if ( !pointer ) |
---|
36 | return EINVAL; |
---|
37 | |
---|
38 | *pointer = NULL; |
---|
39 | |
---|
40 | /* |
---|
41 | * Do not attempt to allocate memory if not in correct system state. |
---|
42 | */ |
---|
43 | if ( _System_state_Is_up(_System_state_Get()) && |
---|
44 | !malloc_is_system_state_OK() ) |
---|
45 | return EINVAL; |
---|
46 | |
---|
47 | /* |
---|
48 | * |
---|
49 | * If some free's have been deferred, then do them now. |
---|
50 | */ |
---|
51 | malloc_deferred_frees_process(); |
---|
52 | |
---|
53 | #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS) |
---|
54 | /* |
---|
55 | * If the support for a boundary area at the end of the heap |
---|
56 | * block allocated is turned on, then adjust the size. |
---|
57 | */ |
---|
58 | if (rtems_malloc_boundary_helpers) |
---|
59 | size += (*rtems_malloc_boundary_helpers->overhead)(); |
---|
60 | #endif |
---|
61 | |
---|
62 | /* |
---|
63 | * Perform the aligned allocation requested |
---|
64 | */ |
---|
65 | |
---|
66 | return_this = _Protected_heap_Allocate_aligned( |
---|
67 | &RTEMS_Malloc_Heap, |
---|
68 | size, |
---|
69 | alignment |
---|
70 | ); |
---|
71 | if ( !return_this ) |
---|
72 | return ENOMEM; |
---|
73 | |
---|
74 | /* |
---|
75 | * If configured, update the more involved statistics |
---|
76 | */ |
---|
77 | if ( rtems_malloc_statistics_helpers ) |
---|
78 | (*rtems_malloc_statistics_helpers->at_malloc)(pointer); |
---|
79 | |
---|
80 | #if defined(RTEMS_MALLOC_BOUNDARY_HELPERS) |
---|
81 | /* |
---|
82 | * If configured, set the boundary area |
---|
83 | */ |
---|
84 | if (rtems_malloc_boundary_helpers) |
---|
85 | (*rtems_malloc_boundary_helpers->at_malloc)(return_this, size); |
---|
86 | #endif |
---|
87 | |
---|
88 | *pointer = return_this; |
---|
89 | return 0; |
---|
90 | } |
---|
91 | #endif |
---|