Electroneum
Toggle main menu visibility
Loading...
Searching...
No Matches
alloc.h
Go to the documentation of this file.
1
/*
2
* util/alloc.h - memory allocation service.
3
*
4
* Copyright (c) 2007, NLnet Labs. All rights reserved.
5
*
6
* This software is open source.
7
*
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
10
* are met:
11
*
12
* Redistributions of source code must retain the above copyright notice,
13
* this list of conditions and the following disclaimer.
14
*
15
* Redistributions in binary form must reproduce the above copyright notice,
16
* this list of conditions and the following disclaimer in the documentation
17
* and/or other materials provided with the distribution.
18
*
19
* Neither the name of the NLNET LABS nor the names of its contributors may
20
* be used to endorse or promote products derived from this software without
21
* specific prior written permission.
22
*
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
47
48
#ifndef UTIL_ALLOC_H
49
#define UTIL_ALLOC_H
50
51
#include "
util/locks.h
"
52
struct
ub_packed_rrset_key
;
53
struct
regional
;
54
56
typedef
struct
ub_packed_rrset_key
alloc_special_type
;
58
#define alloc_special_clean(x) (x)->id = 0;
60
#define alloc_special_next(x) ((alloc_special_type*)((x)->entry.overflow_next))
62
#define alloc_set_special_next(x, y) \
63
((x)->entry.overflow_next) = (struct lruhash_entry*)(y);
64
66
#define ALLOC_SPECIAL_MAX 10
67
72
struct
alloc_cache
{
74
lock_quick_type
lock
;
76
struct
alloc_cache
*
super
;
78
alloc_special_type
*
quar
;
80
size_t
num_quar
;
82
int
thread_num
;
84
uint64_t
next_id
;
86
uint64_t
last_id
;
88
void (*
cleanup
)(
void
*);
90
void
*
cleanup_arg
;
91
93
size_t
max_reg_blocks
;
95
size_t
num_reg_blocks
;
97
struct
regional
*
reg_list
;
98
};
99
107
void
alloc_init
(
struct
alloc_cache
* alloc,
struct
alloc_cache
* super,
108
int
thread_num);
109
116
void
alloc_clear
(
struct
alloc_cache
* alloc);
117
124
void
alloc_clear_special
(
struct
alloc_cache
* alloc);
125
132
alloc_special_type
*
alloc_special_obtain
(
struct
alloc_cache
* alloc);
133
140
void
alloc_special_release
(
struct
alloc_cache
* alloc,
alloc_special_type
* mem);
141
148
uint64_t
alloc_get_id
(
struct
alloc_cache
* alloc);
149
155
size_t
alloc_get_mem
(
struct
alloc_cache
* alloc);
156
161
void
alloc_stats
(
struct
alloc_cache
* alloc);
162
168
struct
regional
*
alloc_reg_obtain
(
struct
alloc_cache
* alloc);
169
175
void
alloc_reg_release
(
struct
alloc_cache
* alloc,
struct
regional
* r);
176
184
void
alloc_set_id_cleanup
(
struct
alloc_cache
* alloc,
void
(*cleanup)(
void
*),
185
void
* arg);
186
187
#ifdef UNBOUND_ALLOC_LITE
188
# include <sldns/ldns.h>
189
# include <sldns/packet.h>
190
# ifdef HAVE_OPENSSL_SSL_H
191
# include <openssl/ssl.h>
192
# endif
193
# define malloc(s) unbound_stat_malloc_lite(s, __FILE__, __LINE__, __func__)
194
# define calloc(n,s) unbound_stat_calloc_lite(n, s, __FILE__, __LINE__, __func__)
195
# define free(p) unbound_stat_free_lite(p, __FILE__, __LINE__, __func__)
196
# define realloc(p,s) unbound_stat_realloc_lite(p, s, __FILE__, __LINE__, __func__)
197
void
*unbound_stat_malloc_lite(
size_t
size,
const
char
* file,
int
line,
198
const
char
* func);
199
void
*unbound_stat_calloc_lite(
size_t
nmemb,
size_t
size,
const
char
* file,
200
int
line,
const
char
* func);
201
void
unbound_stat_free_lite(
void
*ptr,
const
char
* file,
int
line,
202
const
char
* func);
203
void
*unbound_stat_realloc_lite(
void
*ptr,
size_t
size,
const
char
* file,
204
int
line,
const
char
* func);
205
# ifdef strdup
206
# undef strdup
207
# endif
208
# define strdup(s) unbound_strdup_lite(s, __FILE__, __LINE__, __func__)
209
char
* unbound_strdup_lite(
const
char
* s,
const
char
* file,
int
line,
210
const
char
* func);
211
char
* unbound_lite_wrapstr(
char
* s);
212
# define sldns_rr2str(rr) unbound_lite_wrapstr(sldns_rr2str(rr))
213
# define sldns_rdf2str(rdf) unbound_lite_wrapstr(sldns_rdf2str(rdf))
214
# define sldns_rr_type2str(t) unbound_lite_wrapstr(sldns_rr_type2str(t))
215
# define sldns_rr_class2str(c) unbound_lite_wrapstr(sldns_rr_class2str(c))
216
# define sldns_rr_list2str(r) unbound_lite_wrapstr(sldns_rr_list2str(r))
217
# define sldns_pkt2str(p) unbound_lite_wrapstr(sldns_pkt2str(p))
218
# define sldns_pkt_rcode2str(r) unbound_lite_wrapstr(sldns_pkt_rcode2str(r))
219
# define sldns_pkt2wire(a, r, s) unbound_lite_pkt2wire(a, r, s)
220
sldns_status unbound_lite_pkt2wire(
uint8_t
**
dest
,
const
sldns_pkt *p,
size_t
*size);
221
# define i2d_DSA_SIG(d, s) unbound_lite_i2d_DSA_SIG(d, s)
222
int
unbound_lite_i2d_DSA_SIG(DSA_SIG* dsasig,
unsigned
char
** sig);
223
#endif
/* UNBOUND_ALLOC_LITE */
224
225
#endif
/* UTIL_ALLOC_H */
alloc_get_mem
size_t alloc_get_mem(struct alloc_cache *alloc)
alloc_reg_obtain
struct regional * alloc_reg_obtain(struct alloc_cache *alloc)
alloc_init
void alloc_init(struct alloc_cache *alloc, struct alloc_cache *super, int thread_num)
alloc_clear
void alloc_clear(struct alloc_cache *alloc)
alloc_stats
void alloc_stats(struct alloc_cache *alloc)
alloc_reg_release
void alloc_reg_release(struct alloc_cache *alloc, struct regional *r)
alloc_special_obtain
alloc_special_type * alloc_special_obtain(struct alloc_cache *alloc)
alloc_special_release
void alloc_special_release(struct alloc_cache *alloc, alloc_special_type *mem)
alloc_clear_special
void alloc_clear_special(struct alloc_cache *alloc)
alloc_set_id_cleanup
void alloc_set_id_cleanup(struct alloc_cache *alloc, void(*cleanup)(void *), void *arg)
alloc_get_id
uint64_t alloc_get_id(struct alloc_cache *alloc)
alloc_special_type
struct ub_packed_rrset_key alloc_special_type
Definition
alloc.h:56
locks.h
lock_quick_type
int lock_quick_type
Definition
locks.h:276
dest
CXA_THROW_INFO_T void(* dest)(void *))
Definition
stack_trace.cpp:91
uint8_t
unsigned char uint8_t
Definition
stdint.h:124
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
alloc_cache
Definition
alloc.h:72
alloc_cache::super
struct alloc_cache * super
Definition
alloc.h:76
alloc_cache::reg_list
struct regional * reg_list
Definition
alloc.h:97
alloc_cache::quar
alloc_special_type * quar
Definition
alloc.h:78
alloc_cache::lock
lock_quick_type lock
Definition
alloc.h:74
alloc_cache::max_reg_blocks
size_t max_reg_blocks
Definition
alloc.h:93
alloc_cache::cleanup
void(* cleanup)(void *)
Definition
alloc.h:88
alloc_cache::next_id
uint64_t next_id
Definition
alloc.h:84
alloc_cache::cleanup_arg
void * cleanup_arg
Definition
alloc.h:90
alloc_cache::num_quar
size_t num_quar
Definition
alloc.h:80
alloc_cache::thread_num
int thread_num
Definition
alloc.h:82
alloc_cache::num_reg_blocks
size_t num_reg_blocks
Definition
alloc.h:95
alloc_cache::last_id
uint64_t last_id
Definition
alloc.h:86
regional
Definition
regional.h:60
ub_packed_rrset_key
Definition
packed_rrset.h:107
external
unbound
util
alloc.h
Generated on
for Electroneum by
1.17.0