source: rtems/cpukit/libcsupport/include/rtems/malloc.h @ dda372da

4.9
Last change on this file since dda372da was dda372da, checked in by Ralf Corsepius <ralf.corsepius@…>, on 06/03/09 at 03:39:59

Add extern "C" {} guards.

  • Property mode set to 100644
File size: 3.9 KB
Line 
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
27extern "C" {
28#endif
29
30/*
31 *  Malloc Statistics Structure
32 */
33typedef 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 */
48typedef struct {
49  void (*initialize)(void);
50  void (*at_malloc)(void *);
51  void (*at_free)(void *);
52} rtems_malloc_statistics_functions_t;
53
54extern rtems_malloc_statistics_functions_t
55  rtems_malloc_statistics_helpers_table;
56extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
57
58/*
59 *  Malloc boundary support plugin
60 */
61typedef 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
69extern rtems_malloc_boundary_functions_t rtems_malloc_boundary_helpers_table;
70extern rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers;
71
72/*
73 *  Malloc Heap Extension (sbrk) plugin
74 */
75typedef struct {
76  void *(*initialize)(void *, size_t);
77  void *(*extend)(size_t);
78} rtems_malloc_sbrk_functions_t;
79
80extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table;
81extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers;
82
83/*
84 * Malloc Plugin to Dirty Memory at Allocation Time
85 */
86typedef void (*rtems_malloc_dirtier_t)(void *, size_t);
87extern 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 */
95void 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 */
106int 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 */
116void 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 */
127void 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 */
146int rtems_memalign(
147  void   **pointer,
148  size_t   alignment,
149  size_t   size
150);
151
152#ifdef __cplusplus
153}
154#endif
155
156#endif
Note: See TracBrowser for help on using the repository browser.