Electroneum
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"
53struct regional;
54
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
99
107void alloc_init(struct alloc_cache* alloc, struct alloc_cache* super,
108 int thread_num);
109
116void alloc_clear(struct alloc_cache* alloc);
117
125
133
141
149
155size_t alloc_get_mem(struct alloc_cache* alloc);
156
161void alloc_stats(struct alloc_cache* alloc);
162
168struct regional* alloc_reg_obtain(struct alloc_cache* alloc);
169
175void alloc_reg_release(struct alloc_cache* alloc, struct regional* r);
176
184void 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__)
197void *unbound_stat_malloc_lite(size_t size, const char* file, int line,
198 const char* func);
199void *unbound_stat_calloc_lite(size_t nmemb, size_t size, const char* file,
200 int line, const char* func);
201void unbound_stat_free_lite(void *ptr, const char* file, int line,
202 const char* func);
203void *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__)
209char* unbound_strdup_lite(const char* s, const char* file, int line,
210 const char* func);
211char* 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)
220sldns_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)
222int unbound_lite_i2d_DSA_SIG(DSA_SIG* dsasig, unsigned char** sig);
223#endif /* UNBOUND_ALLOC_LITE */
224
225#endif /* UTIL_ALLOC_H */
size_t alloc_get_mem(struct alloc_cache *alloc)
struct regional * alloc_reg_obtain(struct alloc_cache *alloc)
void alloc_init(struct alloc_cache *alloc, struct alloc_cache *super, int thread_num)
void alloc_clear(struct alloc_cache *alloc)
void alloc_stats(struct alloc_cache *alloc)
void alloc_reg_release(struct alloc_cache *alloc, struct regional *r)
alloc_special_type * alloc_special_obtain(struct alloc_cache *alloc)
void alloc_special_release(struct alloc_cache *alloc, alloc_special_type *mem)
void alloc_clear_special(struct alloc_cache *alloc)
void alloc_set_id_cleanup(struct alloc_cache *alloc, void(*cleanup)(void *), void *arg)
uint64_t alloc_get_id(struct alloc_cache *alloc)
struct ub_packed_rrset_key alloc_special_type
Definition alloc.h:56
int lock_quick_type
Definition locks.h:276
CXA_THROW_INFO_T void(* dest)(void *))
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
struct alloc_cache * super
Definition alloc.h:76
struct regional * reg_list
Definition alloc.h:97
alloc_special_type * quar
Definition alloc.h:78
lock_quick_type lock
Definition alloc.h:74
size_t max_reg_blocks
Definition alloc.h:93
void(* cleanup)(void *)
Definition alloc.h:88
uint64_t next_id
Definition alloc.h:84
void * cleanup_arg
Definition alloc.h:90
size_t num_quar
Definition alloc.h:80
int thread_num
Definition alloc.h:82
size_t num_reg_blocks
Definition alloc.h:95
uint64_t last_id
Definition alloc.h:86