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

4.104.114.95
Last change on this file since e0a66c15 was e0a66c15, checked in by Joel Sherrill <joel.sherrill@…>, on 01/29/08 at 17:28:27

2008-01-29 Joel Sherrill <joel.sherrill@…>

  • libcsupport/Makefile.am, libcsupport/include/rtems/malloc.h, libcsupport/src/malloc_walk.c, libcsupport/src/posix_memalign.c, libcsupport/src/realloc.c, score/src/heapwalk.c: Add rtems_memalign as helper and as exposed nmemalign variant with few restrictions. Also turn on compilation of _Heap_Walk but make forced calls to it conditionally compiled. This should allow more flexibility to the user as to run-time checking of the heap.
  • libcsupport/src/rtems_memalign.c: New file.
  • 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/*
27 *  Malloc Statistics Structure
28 */
29typedef 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 */
44typedef struct {
45  void (*initialize)(void);
46  void (*at_malloc)(void *);
47  void (*at_free)(void *);
48} rtems_malloc_statistics_functions_t;
49
50extern rtems_malloc_statistics_functions_t
51  rtems_malloc_statistics_helpers_table;
52extern rtems_malloc_statistics_functions_t *rtems_malloc_statistics_helpers;
53
54/*
55 *  Malloc boundary support plugin
56 */
57typedef 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
65extern rtems_malloc_boundary_functions_t rtems_malloc_boundary_helpers_table;
66extern rtems_malloc_boundary_functions_t *rtems_malloc_boundary_helpers;
67
68/*
69 *  Malloc Heap Extension (sbrk) plugin
70 */
71typedef struct {
72  void *(*initialize)(void *, size_t);
73  void *(*extend)(size_t);
74} rtems_malloc_sbrk_functions_t;
75
76extern rtems_malloc_sbrk_functions_t rtems_malloc_sbrk_helpers_table;
77extern rtems_malloc_sbrk_functions_t *rtems_malloc_sbrk_helpers;
78
79/*
80 * Malloc Plugin to Dirty Memory at Allocation Time
81 */
82typedef void (*rtems_malloc_dirtier_t)(void *, size_t);
83extern 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 */
91void 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 */
102int 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 */
112void 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 */
123void 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 */
142int rtems_memalign(
143  void   **pointer,
144  size_t   alignment,
145  size_t   size
146);
147
148#endif
Note: See TracBrowser for help on using the repository browser.