STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
memp_priv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25  * OF SUCH DAMAGE.
26  *
27  * This file is part of the lwIP TCP/IP stack.
28  *
29  * Author: Adam Dunkels <adam@sics.se>
30  *
31  */
32 
33 #ifndef LWIP_HDR_MEMP_PRIV_H
34 #define LWIP_HDR_MEMP_PRIV_H
35 
36 #include "lwip/opt.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include "lwip/mem.h"
43 
44 #if MEMP_OVERFLOW_CHECK
45 /* if MEMP_OVERFLOW_CHECK is turned on, we reserve some bytes at the beginning
46  * and at the end of each element, initialize them as 0xcd and check
47  * them later. */
48 /* If MEMP_OVERFLOW_CHECK is >= 2, on every call to memp_malloc or memp_free,
49  * every single element in each pool is checked!
50  * This is VERY SLOW but also very helpful. */
51 /* MEMP_SANITY_REGION_BEFORE and MEMP_SANITY_REGION_AFTER can be overridden in
52  * lwipopts.h to change the amount reserved for checking. */
53 #ifndef MEMP_SANITY_REGION_BEFORE
54 #define MEMP_SANITY_REGION_BEFORE 16
55 #endif /* MEMP_SANITY_REGION_BEFORE*/
56 #if MEMP_SANITY_REGION_BEFORE > 0
57 #define MEMP_SANITY_REGION_BEFORE_ALIGNED LWIP_MEM_ALIGN_SIZE(MEMP_SANITY_REGION_BEFORE)
58 #else
59 #define MEMP_SANITY_REGION_BEFORE_ALIGNED 0
60 #endif /* MEMP_SANITY_REGION_BEFORE*/
61 #ifndef MEMP_SANITY_REGION_AFTER
62 #define MEMP_SANITY_REGION_AFTER 16
63 #endif /* MEMP_SANITY_REGION_AFTER*/
64 #if MEMP_SANITY_REGION_AFTER > 0
65 #define MEMP_SANITY_REGION_AFTER_ALIGNED LWIP_MEM_ALIGN_SIZE(MEMP_SANITY_REGION_AFTER)
66 #else
67 #define MEMP_SANITY_REGION_AFTER_ALIGNED 0
68 #endif /* MEMP_SANITY_REGION_AFTER*/
69 
70 /* MEMP_SIZE: save space for struct memp and for sanity check */
71 #define MEMP_SIZE (LWIP_MEM_ALIGN_SIZE(sizeof(struct memp)) + MEMP_SANITY_REGION_BEFORE_ALIGNED)
72 #define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x) + MEMP_SANITY_REGION_AFTER_ALIGNED)
73 
74 #else /* MEMP_OVERFLOW_CHECK */
75 
76 /* No sanity checks
77  * We don't need to preserve the struct memp while not allocated, so we
78  * can save a little space and set MEMP_SIZE to 0.
79  */
80 #define MEMP_SIZE 0
81 #define MEMP_ALIGN_SIZE(x) (LWIP_MEM_ALIGN_SIZE(x))
82 
83 #endif /* MEMP_OVERFLOW_CHECK */
84 
85 struct memp {
86  struct memp *next;
87 #if MEMP_OVERFLOW_CHECK
88  const char *file;
89  int line;
90 #endif /* MEMP_OVERFLOW_CHECK */
91 };
92 
93 #if MEM_USE_POOLS
94 /* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */
95 typedef enum {
96  /* Get the first (via:
97  MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/
98  MEMP_POOL_HELPER_FIRST = ((u8_t)
99 #define LWIP_MEMPOOL(name,num,size,desc)
100 #define LWIP_MALLOC_MEMPOOL_START 1
101 #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
102 #define LWIP_MALLOC_MEMPOOL_END
103 #include "lwip/priv/memp_std.h"
104  ) ,
105  /* Get the last (via:
106  MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */
107  MEMP_POOL_HELPER_LAST = ((u8_t)
108 #define LWIP_MEMPOOL(name,num,size,desc)
109 #define LWIP_MALLOC_MEMPOOL_START
110 #define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size *
111 #define LWIP_MALLOC_MEMPOOL_END 1
112 #include "lwip/priv/memp_std.h"
113  )
114 } memp_pool_helper_t;
115 
116 /* The actual start and stop values are here (cast them over)
117  We use this helper type and these defines so we can avoid using const memp_t values */
118 #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST)
119 #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST)
120 #endif /* MEM_USE_POOLS */
121 
122 struct memp_desc {
125 
126 #if !MEMP_MEM_MALLOC
127 
129 
130 #if defined(LWIP_DEBUG) || MEMP_OVERFLOW_CHECK
131 
132  const char *desc;
133 #endif /* LWIP_DEBUG || MEMP_OVERFLOW_CHECK */
134 
137 
139  struct memp **tab;
140 #endif /* MEMP_MEM_MALLOC */
141 };
142 
143 #ifdef LWIP_DEBUG
144 #define DECLARE_LWIP_MEMPOOL_DESC(desc) (desc),
145 #else
146 #define DECLARE_LWIP_MEMPOOL_DESC(desc)
147 #endif
148 
149 void memp_init_pool(const struct memp_desc *desc);
150 
151 #if MEMP_OVERFLOW_CHECK
152 void *memp_malloc_pool_fn(const struct memp_desc* desc, const char* file, const int line);
153 #define memp_malloc_pool(d) memp_malloc_pool_fn((d), __FILE__, __LINE__)
154 #else
155 void *memp_malloc_pool(const struct memp_desc *desc);
156 #endif
157 void memp_free_pool(const struct memp_desc* desc, void *mem);
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif /* LWIP_HDR_MEMP_PRIV_H */
164 
u8_t * base
Definition: memp_priv.h:136
void memp_init_pool(const struct memp_desc *desc)
Definition: memp.c:203
struct memp ** tab
Definition: memp_priv.h:139
u16_t num
Definition: memp_priv.h:128
Definition: memp_priv.h:85
struct memp * next
Definition: memp_priv.h:86
u16_t size
Definition: memp_priv.h:124
unsigned char u8_t
Definition: cc.h:38
Definition: mem.c:179
void memp_free_pool(const struct memp_desc *desc, void *mem)
Definition: memp.c:379
unsigned short u16_t
Definition: cc.h:40
#define LWIP_MEMPOOL(name, num, size, desc)
Definition: memp.c:72
void * memp_malloc_pool(const struct memp_desc *desc)
Definition: memp.c:256