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 | /* |
---|
27 | * Malloc Statistics Structure |
---|
28 | */ |
---|
29 | typedef struct { |
---|
30 | uint32_t space_available; /* current size of malloc area */ |
---|
31 | uint32_t malloc_calls; /* # calls to malloc */ |
---|
32 | uint32_t memalign_calls; /* # calls to memalign */ |
---|
33 | uint32_t free_calls; |
---|
34 | uint32_t realloc_calls; |
---|
35 | uint32_t calloc_calls; |
---|
36 | uint32_t max_depth; /* most ever malloc'd at 1 time */ |
---|
37 | uintmax_t lifetime_allocated; |
---|
38 | uintmax_t lifetime_freed; |
---|
39 | } rtems_malloc_statistics_t; |
---|
40 | |
---|
41 | /* |
---|
42 | * Malloc statistics plugin |
---|
43 | */ |
---|
44 | typedef struct { |
---|
45 | void (*initialize)(void); |
---|
46 | void (*at_malloc)(void *); |
---|
47 | void (*at_free)(void *); |
---|
48 | } rtems_malloc_statistics_functions_t; |
---|
49 | |
---|
50 | extern rtems_malloc_statistics_functions_t |
---|
51 | rtems_malloc_statistics_helpers_table; |
---|
52 | extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers; |
---|
53 | |
---|
54 | /* |
---|
55 | * Malloc boundary support plugin |
---|
56 | */ |
---|
57 | typedef struct { |
---|
58 | void (*initialize)(void); |
---|
59 | uint32_t (*overhead)(void); |
---|
60 | void (*at_malloc)(void *, size_t); |
---|
61 | void (*at_free)(void *); |
---|
62 | void (*at_realloc)(void *, size_t); |
---|
63 | } rtems_malloc_boundary_functions_t; |
---|
64 | |
---|
65 | extern rtems_malloc_boundary_functions_t rtems_malloc_boundary_helpers_table; |
---|
66 | extern rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers; |
---|
67 | |
---|
68 | /* |
---|
69 | * Malloc Heap Extension (sbrk) plugin |
---|
70 | */ |
---|
71 | typedef struct { |
---|
72 | void *(*initialize)(void *, size_t); |
---|
73 | void *(*extend)(size_t); |
---|
74 | } rtems_malloc_sbrk_functions_t; |
---|
75 | |
---|
76 | extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table; |
---|
77 | extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers; |
---|
78 | |
---|
79 | /* |
---|
80 | * Malloc Plugin to Dirty Memory at Allocation Time |
---|
81 | */ |
---|
82 | typedef void (*rtems_malloc_dirtier_t)(void *, size_t); |
---|
83 | extern rtems_malloc_dirtier_t *rtems_malloc_dirty_helper; |
---|
84 | |
---|
85 | /** @brief Dirty memory function |
---|
86 | * |
---|
87 | * This method fills the specified area with a non-zero pattern |
---|
88 | * to aid in debugging programs which do not initialize their |
---|
89 | * memory allocated from the heap. |
---|
90 | */ |
---|
91 | void rtems_malloc_dirty_memory( |
---|
92 | void *start, |
---|
93 | size_t size |
---|
94 | ); |
---|
95 | |
---|
96 | /** @brief Print Malloc Statistic Usage Report |
---|
97 | * |
---|
98 | * This method fills in the called provided malloc statistics area. |
---|
99 | * |
---|
100 | * @return This method returns 0 if successful and -1 on error. |
---|
101 | */ |
---|
102 | int malloc_get_statistics( |
---|
103 | rtems_malloc_statistics_t *stats |
---|
104 | ); |
---|
105 | |
---|
106 | /** @brief Print Malloc Statistic Usage Report |
---|
107 | * |
---|
108 | * This method prints a malloc statistics report. |
---|
109 | * |
---|
110 | * @note It uses printk to print the report. |
---|
111 | */ |
---|
112 | void malloc_report_statistics(void); |
---|
113 | |
---|
114 | /** @brief Print Malloc Statistic Usage Report |
---|
115 | * |
---|
116 | * This method prints a malloc statistics report. |
---|
117 | * |
---|
118 | * @param[in] context is the context to pass to the print handler |
---|
119 | * @param[in] print is the print handler |
---|
120 | * |
---|
121 | * @note It uses the CALLER's routine to print the report. |
---|
122 | */ |
---|
123 | void malloc_report_statistics_with_plugin( |
---|
124 | void *context, |
---|
125 | rtems_printk_plugin_t print |
---|
126 | ); |
---|
127 | |
---|
128 | /** |
---|
129 | * |
---|
130 | * This method is a help memalign implementation which does all |
---|
131 | * error checking done by posix_memalign() EXCEPT it does NOT |
---|
132 | * place numeric restrictions on the alignment value. |
---|
133 | * |
---|
134 | * @param[in] pointer points to the user pointer |
---|
135 | * @param[in] alignment is the desired alignment |
---|
136 | * @param[in] size is the allocation request size in bytes |
---|
137 | * |
---|
138 | * @return This methods returns zero on success and a POSIX errno |
---|
139 | * value to indicate the failure condition. On success |
---|
140 | * *pointer will contain the address of the allocated memory. |
---|
141 | */ |
---|
142 | int rtems_memalign( |
---|
143 | void **pointer, |
---|
144 | size_t alignment, |
---|
145 | size_t size |
---|
146 | ); |
---|
147 | |
---|
148 | #endif |
---|