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