1 | /** |
---|
2 | * @file rtems/malloc.h |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * RTEMS Malloc Extensions |
---|
7 | * |
---|
8 | * COPYRIGHT (c) 1989-2007. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may in |
---|
12 | * the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _RTEMS_MALLOC_H |
---|
19 | #define _RTEMS_MALLOC_H |
---|
20 | |
---|
21 | #include <rtems.h> |
---|
22 | #include <rtems/bspIo.h> |
---|
23 | |
---|
24 | #include <stdint.h> |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif |
---|
29 | |
---|
30 | /* |
---|
31 | * Malloc Statistics Structure |
---|
32 | */ |
---|
33 | typedef struct { |
---|
34 | uint32_t space_available; /* current size of malloc area */ |
---|
35 | uint32_t malloc_calls; /* # calls to malloc */ |
---|
36 | uint32_t memalign_calls; /* # calls to memalign */ |
---|
37 | uint32_t free_calls; |
---|
38 | uint32_t realloc_calls; |
---|
39 | uint32_t calloc_calls; |
---|
40 | uint32_t max_depth; /* most ever malloc'd at 1 time */ |
---|
41 | uintmax_t lifetime_allocated; |
---|
42 | uintmax_t lifetime_freed; |
---|
43 | } rtems_malloc_statistics_t; |
---|
44 | |
---|
45 | /* |
---|
46 | * Malloc statistics plugin |
---|
47 | */ |
---|
48 | typedef struct { |
---|
49 | void (*initialize)(void); |
---|
50 | void (*at_malloc)(void *); |
---|
51 | void (*at_free)(void *); |
---|
52 | } rtems_malloc_statistics_functions_t; |
---|
53 | |
---|
54 | extern rtems_malloc_statistics_functions_t |
---|
55 | rtems_malloc_statistics_helpers_table; |
---|
56 | extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers; |
---|
57 | |
---|
58 | /* |
---|
59 | * Malloc boundary support plugin |
---|
60 | */ |
---|
61 | typedef struct { |
---|
62 | void (*initialize)(void); |
---|
63 | uint32_t (*overhead)(void); |
---|
64 | void (*at_malloc)(void *, size_t); |
---|
65 | void (*at_free)(void *); |
---|
66 | void (*at_realloc)(void *, size_t); |
---|
67 | } rtems_malloc_boundary_functions_t; |
---|
68 | |
---|
69 | extern rtems_malloc_boundary_functions_t rtems_malloc_boundary_helpers_table; |
---|
70 | extern rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers; |
---|
71 | |
---|
72 | /* |
---|
73 | * Malloc Heap Extension (sbrk) plugin |
---|
74 | */ |
---|
75 | typedef struct { |
---|
76 | void *(*initialize)(void *, size_t); |
---|
77 | void *(*extend)(size_t); |
---|
78 | } rtems_malloc_sbrk_functions_t; |
---|
79 | |
---|
80 | extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table; |
---|
81 | extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers; |
---|
82 | |
---|
83 | /* |
---|
84 | * Malloc Plugin to Dirty Memory at Allocation Time |
---|
85 | */ |
---|
86 | typedef void (*rtems_malloc_dirtier_t)(void *, size_t); |
---|
87 | extern rtems_malloc_dirtier_t *rtems_malloc_dirty_helper; |
---|
88 | |
---|
89 | /** @brief Dirty memory function |
---|
90 | * |
---|
91 | * This method fills the specified area with a non-zero pattern |
---|
92 | * to aid in debugging programs which do not initialize their |
---|
93 | * memory allocated from the heap. |
---|
94 | */ |
---|
95 | void rtems_malloc_dirty_memory( |
---|
96 | void *start, |
---|
97 | size_t size |
---|
98 | ); |
---|
99 | |
---|
100 | /** @brief Print Malloc Statistic Usage Report |
---|
101 | * |
---|
102 | * This method fills in the called provided malloc statistics area. |
---|
103 | * |
---|
104 | * @return This method returns 0 if successful and -1 on error. |
---|
105 | */ |
---|
106 | int malloc_get_statistics( |
---|
107 | rtems_malloc_statistics_t *stats |
---|
108 | ); |
---|
109 | |
---|
110 | /** @brief Print Malloc Statistic Usage Report |
---|
111 | * |
---|
112 | * This method prints a malloc statistics report. |
---|
113 | * |
---|
114 | * @note It uses printk to print the report. |
---|
115 | */ |
---|
116 | void malloc_report_statistics(void); |
---|
117 | |
---|
118 | /** @brief Print Malloc Statistic Usage Report |
---|
119 | * |
---|
120 | * This method prints a malloc statistics report. |
---|
121 | * |
---|
122 | * @param[in] context is the context to pass to the print handler |
---|
123 | * @param[in] print is the print handler |
---|
124 | * |
---|
125 | * @note It uses the CALLER's routine to print the report. |
---|
126 | */ |
---|
127 | void malloc_report_statistics_with_plugin( |
---|
128 | void *context, |
---|
129 | rtems_printk_plugin_t print |
---|
130 | ); |
---|
131 | |
---|
132 | /** |
---|
133 | * |
---|
134 | * This method is a help memalign implementation which does all |
---|
135 | * error checking done by posix_memalign() EXCEPT it does NOT |
---|
136 | * place numeric restrictions on the alignment value. |
---|
137 | * |
---|
138 | * @param[in] pointer points to the user pointer |
---|
139 | * @param[in] alignment is the desired alignment |
---|
140 | * @param[in] size is the allocation request size in bytes |
---|
141 | * |
---|
142 | * @return This methods returns zero on success and a POSIX errno |
---|
143 | * value to indicate the failure condition. On success |
---|
144 | * *pointer will contain the address of the allocated memory. |
---|
145 | */ |
---|
146 | int rtems_memalign( |
---|
147 | void **pointer, |
---|
148 | size_t alignment, |
---|
149 | size_t size |
---|
150 | ); |
---|
151 | |
---|
152 | /** |
---|
153 | * @brief Allocates a memory area of size @a size bytes from the heap. |
---|
154 | * |
---|
155 | * If the alignment parameter @a alignment is not equal to zero, the allocated |
---|
156 | * memory area will begin at an address aligned by this value. |
---|
157 | * |
---|
158 | * If the boundary parameter @a boundary is not equal to zero, the allocated |
---|
159 | * memory area will fulfill a boundary constraint. The boundary value |
---|
160 | * specifies the set of addresses which are aligned by the boundary value. The |
---|
161 | * interior of the allocated memory area will not contain an element of this |
---|
162 | * set. The begin or end address of the area may be a member of the set. |
---|
163 | * |
---|
164 | * A size value of zero will return a unique address which may be freed with |
---|
165 | * free(). |
---|
166 | * |
---|
167 | * The memory allocated by this function can be released with a call to free(). |
---|
168 | * |
---|
169 | * @return A pointer to the begin of the allocated memory area, or @c NULL if |
---|
170 | * no memory is available or the parameters are inconsistent. |
---|
171 | */ |
---|
172 | void *rtems_heap_allocate_aligned_with_boundary( |
---|
173 | size_t size, |
---|
174 | uintptr_t alignment, |
---|
175 | uintptr_t boundary |
---|
176 | ); |
---|
177 | |
---|
178 | #ifdef __cplusplus |
---|
179 | } |
---|
180 | #endif |
---|
181 | |
---|
182 | #endif |
---|