libcoap
4.3.5
Toggle main menu visibility
Loading...
Searching...
No Matches
coap_mem.h
Go to the documentation of this file.
1
/*
2
* coap_mem.h -- CoAP memory handling
3
*
4
* Copyright (C) 2010-2011,2014-2015 Olaf Bergmann <bergmann@tzi.org>
5
*
6
* SPDX-License-Identifier: BSD-2-Clause
7
*
8
* This file is part of the CoAP library libcoap. Please see README for terms
9
* of use.
10
*/
11
16
17
#ifndef COAP_MEM_H_
18
#define COAP_MEM_H_
19
20
#include "
coap3/coap_oscore.h
"
21
#include "
coap3/coap_proxy.h
"
22
#include <stdlib.h>
23
24
#ifndef WITH_LWIP
30
void
coap_memory_init
(
void
);
31
#endif
/* WITH_LWIP */
32
38
typedef
enum
{
39
COAP_STRING
,
40
COAP_ATTRIBUTE_NAME
,
41
COAP_ATTRIBUTE_VALUE
,
42
COAP_PACKET
,
43
COAP_NODE
,
44
COAP_CONTEXT
,
45
COAP_ENDPOINT
,
46
COAP_PDU
,
47
COAP_PDU_BUF
,
48
COAP_RESOURCE
,
49
COAP_RESOURCEATTR
,
50
COAP_DTLS_SESSION
,
51
COAP_SESSION
,
52
COAP_OPTLIST
,
53
COAP_CACHE_KEY
,
54
COAP_CACHE_ENTRY
,
55
COAP_LG_XMIT
,
56
COAP_LG_CRCV
,
57
COAP_LG_SRCV
,
58
COAP_DIGEST_CTX
,
59
COAP_SUBSCRIPTION
,
60
COAP_DTLS_CONTEXT
,
61
COAP_OSCORE_COM
,
62
COAP_OSCORE_SEN
,
63
COAP_OSCORE_REC
,
64
COAP_OSCORE_EX
,
65
COAP_OSCORE_EP
,
66
COAP_OSCORE_BUF
,
67
COAP_COSE
,
68
COAP_MEM_TAG_LAST
69
}
coap_memory_tag_t
;
70
71
#ifndef WITH_LWIP
72
83
void
*
coap_malloc_type
(
coap_memory_tag_t
type,
size_t
size);
84
99
void
*
coap_realloc_type
(
coap_memory_tag_t
type,
void
*p,
size_t
size);
100
109
void
coap_free_type
(
coap_memory_tag_t
type,
void
*p);
110
118
void
coap_dump_memory_type_counts
(
coap_log_t
log_level);
119
123
COAP_STATIC_INLINE
void
*
124
coap_malloc
(
size_t
size) {
125
return
coap_malloc_type
(
COAP_STRING
, size);
126
}
127
131
COAP_STATIC_INLINE
void
132
coap_free
(
void
*
object
) {
133
coap_free_type
(
COAP_STRING
,
object
);
134
}
135
136
#endif
/* not WITH_LWIP */
137
138
#ifdef WITH_LWIP
139
140
#include <lwip/memp.h>
141
142
/* no initialization needed with lwip (or, more precisely: lwip must be
143
* completely initialized anyway by the time coap gets active) */
144
COAP_STATIC_INLINE
void
145
coap_memory_init
(
void
) {}
146
147
#if MEMP_STATS
148
COAP_STATIC_INLINE
void
*
149
coap_malloc_error(uint16_t *err) {
150
(*err)++;
151
return
NULL;
152
}
153
#endif
/* MEMP_STATS */
154
/* It would be nice to check that size equals the size given at the memp
155
* declaration, but i currently don't see a standard way to check that without
156
* sourcing the custom memp pools and becoming dependent of its syntax
157
*/
158
#if MEMP_STATS
159
#define coap_malloc_type(type, asize) \
160
(((asize) <= memp_pools[MEMP_ ## type]->size) ? \
161
memp_malloc(MEMP_ ## type) : coap_malloc_error(&memp_pools[MEMP_ ## type]->stats->err))
162
#else
/* ! MEMP_STATS */
163
#define coap_malloc_type(type, asize) \
164
(((asize) <= memp_pools[MEMP_ ## type]->size) ? \
165
memp_malloc(MEMP_ ## type) : NULL)
166
#endif
/* ! MEMP_STATS */
167
#define coap_free_type(type, p) memp_free(MEMP_ ## type, p)
168
169
/* As these are fixed size, return value if already defined */
170
#define coap_realloc_type(type, p, asize) \
171
((p) ? ((asize) <= memp_pools[MEMP_ ## type]->size) ? (p) : NULL : coap_malloc_type(type, asize))
172
173
/* Those are just here to make uri.c happy where string allocation has not been
174
* made conditional.
175
*/
176
COAP_STATIC_INLINE
void
*
177
coap_malloc
(
size_t
size) {
178
(void)size;
179
LWIP_ASSERT(
"coap_malloc must not be used in lwIP"
, 0);
180
}
181
182
COAP_STATIC_INLINE
void
183
coap_free
(
void
*pointer) {
184
(void)pointer;
185
LWIP_ASSERT(
"coap_free must not be used in lwIP"
, 0);
186
}
187
188
#define coap_dump_memory_type_counts(l) coap_lwip_dump_memory_pools(l)
189
190
#endif
/* WITH_LWIP */
191
192
#endif
/* COAP_MEM_H_ */
coap_free
COAP_STATIC_INLINE void coap_free(void *object)
Wrapper function to coap_free_type() for backwards compatibility.
Definition
coap_mem.h:132
coap_malloc
COAP_STATIC_INLINE void * coap_malloc(size_t size)
Wrapper function to coap_malloc_type() for backwards compatibility.
Definition
coap_mem.h:124
coap_dump_memory_type_counts
void coap_dump_memory_type_counts(coap_log_t log_level)
Dumps the current usage of malloc'd memory types.
Definition
coap_mem.c:669
coap_memory_init
void coap_memory_init(void)
Initializes libcoap's memory management.
coap_memory_tag_t
coap_memory_tag_t
Type specifiers for coap_malloc_type().
Definition
coap_mem.h:38
COAP_DTLS_SESSION
@ COAP_DTLS_SESSION
Definition
coap_mem.h:50
COAP_SESSION
@ COAP_SESSION
Definition
coap_mem.h:51
COAP_CACHE_KEY
@ COAP_CACHE_KEY
Definition
coap_mem.h:53
COAP_DIGEST_CTX
@ COAP_DIGEST_CTX
Definition
coap_mem.h:58
COAP_NODE
@ COAP_NODE
Definition
coap_mem.h:43
COAP_OSCORE_COM
@ COAP_OSCORE_COM
Definition
coap_mem.h:61
COAP_DTLS_CONTEXT
@ COAP_DTLS_CONTEXT
Definition
coap_mem.h:60
COAP_OSCORE_EX
@ COAP_OSCORE_EX
Definition
coap_mem.h:64
COAP_CACHE_ENTRY
@ COAP_CACHE_ENTRY
Definition
coap_mem.h:54
COAP_RESOURCE
@ COAP_RESOURCE
Definition
coap_mem.h:48
COAP_RESOURCEATTR
@ COAP_RESOURCEATTR
Definition
coap_mem.h:49
COAP_COSE
@ COAP_COSE
Definition
coap_mem.h:67
COAP_LG_XMIT
@ COAP_LG_XMIT
Definition
coap_mem.h:55
COAP_ATTRIBUTE_VALUE
@ COAP_ATTRIBUTE_VALUE
Definition
coap_mem.h:41
COAP_ENDPOINT
@ COAP_ENDPOINT
Definition
coap_mem.h:45
COAP_CONTEXT
@ COAP_CONTEXT
Definition
coap_mem.h:44
COAP_OPTLIST
@ COAP_OPTLIST
Definition
coap_mem.h:52
COAP_PDU
@ COAP_PDU
Definition
coap_mem.h:46
COAP_LG_CRCV
@ COAP_LG_CRCV
Definition
coap_mem.h:56
COAP_OSCORE_BUF
@ COAP_OSCORE_BUF
Definition
coap_mem.h:66
COAP_MEM_TAG_LAST
@ COAP_MEM_TAG_LAST
Definition
coap_mem.h:68
COAP_OSCORE_SEN
@ COAP_OSCORE_SEN
Definition
coap_mem.h:62
COAP_OSCORE_REC
@ COAP_OSCORE_REC
Definition
coap_mem.h:63
COAP_ATTRIBUTE_NAME
@ COAP_ATTRIBUTE_NAME
Definition
coap_mem.h:40
COAP_OSCORE_EP
@ COAP_OSCORE_EP
Definition
coap_mem.h:65
COAP_LG_SRCV
@ COAP_LG_SRCV
Definition
coap_mem.h:57
COAP_PACKET
@ COAP_PACKET
Definition
coap_mem.h:42
COAP_SUBSCRIPTION
@ COAP_SUBSCRIPTION
Definition
coap_mem.h:59
COAP_STRING
@ COAP_STRING
Definition
coap_mem.h:39
COAP_PDU_BUF
@ COAP_PDU_BUF
Definition
coap_mem.h:47
coap_realloc_type
void * coap_realloc_type(coap_memory_tag_t type, void *p, size_t size)
Reallocates a chunk p of bytes created by coap_malloc_type() or coap_realloc_type() and returns a poi...
coap_malloc_type
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
coap_free_type
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
coap_oscore.h
CoAP OSCORE support.
coap_proxy.h
Helper functions for proxy handling.
coap_log_t
coap_log_t
Logging type.
Definition
coap_debug.h:50
COAP_STATIC_INLINE
#define COAP_STATIC_INLINE
Definition
libcoap.h:53
include
coap3
coap_mem.h
Generated on
for libcoap by
1.17.0