/src/freeradius-server/src/freeradius-devel/util/talloc.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | /* |
3 | | * This program is free software; you can redistribute it and/or modify |
4 | | * it under the terms of the GNU General Public License as published by |
5 | | * the Free Software Foundation; either version 2 of the License, or |
6 | | * (at your option) any later version. |
7 | | * |
8 | | * This program is distributed in the hope that it will be useful, |
9 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | | * GNU General Public License for more details. |
12 | | * |
13 | | * You should have received a copy of the GNU General Public License |
14 | | * along with this program; if not, write to the Free Software |
15 | | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
16 | | */ |
17 | | |
18 | | /** Functions which we wish were included in the standard talloc distribution |
19 | | * |
20 | | * @file src/lib/util/talloc.h |
21 | | * |
22 | | * @copyright 2017 The FreeRADIUS server project |
23 | | * @copyright 2017 Arran Cudbard-Bell (a.cudbardb@freeradius.org) |
24 | | */ |
25 | | RCSIDH(talloc_h, "$Id: 48c4855b305a1f53f6f770b497ba8f18ccfb5dd1 $") |
26 | | |
27 | | #ifdef __cplusplus |
28 | | extern "C" { |
29 | | #endif |
30 | | |
31 | | #include <freeradius-devel/autoconf.h> /* Very easy to miss including in special builds */ |
32 | | #include <freeradius-devel/build.h> |
33 | | #include <freeradius-devel/missing.h> |
34 | | #include <ctype.h> |
35 | | #include <stdbool.h> |
36 | | #include <stdint.h> |
37 | | |
38 | | #ifdef HAVE_WDOCUMENTATION |
39 | | DIAG_OFF(documentation) |
40 | | #endif |
41 | | #include <talloc.h> |
42 | | #ifdef HAVE_WDOCUMENTATION |
43 | | DIAG_ON(documentation) |
44 | | #endif |
45 | | |
46 | | #undef talloc_autofree_context |
47 | | /** The original function is deprecated, so replace it with our version |
48 | | */ |
49 | | #define talloc_autofree_context talloc_autofree_context_global |
50 | | |
51 | | /** Iterate over a talloced array of elements |
52 | | * |
53 | | @verbatim |
54 | | talloc_foreach(vpt_m, vpt) { |
55 | | tmpl_debug(vpt); |
56 | | } |
57 | | @endverbatim |
58 | | * |
59 | | * There seems to be a limitation in for loop initialiser arguments where they all |
60 | | * must be the same type, though we can control the number of layers of pointer |
61 | | * indirection on a per variable basis. |
62 | | * |
63 | | * We declare _p to be a pointer of the specified _type, and initialise it to the |
64 | | * start of the array. We declare _end to be a pointer of the specified type and |
65 | | * initialise it to point to the end of the array using talloc_array_length(). |
66 | | * |
67 | | * _iter is only updated in the condition to avoid de-referencing invalid memory. |
68 | | * |
69 | | * @param[in] _array to iterate over. May contain zero elements. |
70 | | * @param[in] _iter Name of iteration variable. |
71 | | * Will be declared in the scope of the loop. |
72 | | */ |
73 | | #define talloc_foreach(_array, _iter) \ |
74 | | for (__typeof__(_array[0]) _iter, *_p = (void *)(_array), *_end = (void *)((_array) + talloc_array_length(_array)); \ |
75 | | (_p < _end) && (_iter = *((void **)(_p))); \ |
76 | | _p = (__typeof__(_p))((__typeof__(_array))_p) + 1) |
77 | | |
78 | | typedef int(* fr_talloc_free_func_t)(void *fire_ctx, void *uctx); |
79 | | |
80 | | typedef struct fr_talloc_destructor_s fr_talloc_destructor_t; |
81 | | typedef struct fr_talloc_destructor_disarm_s fr_talloc_destructor_disarm_t; |
82 | | |
83 | | /** Structure to record a destructor operation on a specific talloc chunk |
84 | | * |
85 | | * Provided here so that additional memory can be allocated with talloc pool. |
86 | | */ |
87 | | struct fr_talloc_destructor_s { |
88 | | void *fire; //!< Parent chunk. |
89 | | |
90 | | fr_talloc_free_func_t func; //!< Free function. |
91 | | void *uctx; //!< uctx to pass to free function. |
92 | | fr_talloc_destructor_disarm_t *ds; //!< Chunk to free. |
93 | | }; |
94 | | |
95 | | /** Structure to record a destructor to disarm if a child talloc chunk is freed |
96 | | * |
97 | | * Provided here so that additional memory can be allocated with talloc pool. |
98 | | */ |
99 | | struct fr_talloc_destructor_disarm_s { |
100 | | fr_talloc_destructor_t *d; //!< Destructor to disarm. |
101 | | }; |
102 | | |
103 | | /** Allocate a top level chunk with a constant name |
104 | | * |
105 | | * @param[in] name Must be a string literal. |
106 | | * @return |
107 | | * - NULL on allocation error. |
108 | | * - A new talloc chunk on success. |
109 | | */ |
110 | | static inline TALLOC_CTX *talloc_init_const(char const *name) |
111 | 1.39k | { |
112 | 1.39k | TALLOC_CTX *ctx; |
113 | | |
114 | 1.39k | ctx = talloc_new(NULL); |
115 | 1.39k | if (unlikely(!ctx)) return NULL; |
116 | | |
117 | 1.39k | talloc_set_name_const(ctx, name); |
118 | | |
119 | 1.39k | return ctx; |
120 | 1.39k | } fuzzer.c:talloc_init_const Line | Count | Source | 111 | 1.39k | { | 112 | 1.39k | TALLOC_CTX *ctx; | 113 | | | 114 | 1.39k | ctx = talloc_new(NULL); | 115 | 1.39k | if (unlikely(!ctx)) return NULL; | 116 | | | 117 | 1.39k | talloc_set_name_const(ctx, name); | 118 | | | 119 | 1.39k | return ctx; | 120 | 1.39k | } |
Unexecuted instantiation: atexit.c:talloc_init_const Unexecuted instantiation: base16.c:talloc_init_const Unexecuted instantiation: base32.c:talloc_init_const Unexecuted instantiation: base64.c:talloc_init_const Unexecuted instantiation: calc.c:talloc_init_const Unexecuted instantiation: dbuff.c:talloc_init_const Unexecuted instantiation: debug.c:talloc_init_const Unexecuted instantiation: dict_ext.c:talloc_init_const Unexecuted instantiation: dict_fixup.c:talloc_init_const Unexecuted instantiation: dict_print.c:talloc_init_const Unexecuted instantiation: dict_test.c:talloc_init_const Unexecuted instantiation: dict_tokenize.c:talloc_init_const Unexecuted instantiation: dict_unknown.c:talloc_init_const Unexecuted instantiation: dict_util.c:talloc_init_const Unexecuted instantiation: dict_validate.c:talloc_init_const Unexecuted instantiation: dl.c:talloc_init_const Unexecuted instantiation: dns.c:talloc_init_const Unexecuted instantiation: edit.c:talloc_init_const Unexecuted instantiation: event.c:talloc_init_const Unexecuted instantiation: ext.c:talloc_init_const Unexecuted instantiation: fifo.c:talloc_init_const Unexecuted instantiation: file.c:talloc_init_const Unexecuted instantiation: fring.c:talloc_init_const Unexecuted instantiation: hash.c:talloc_init_const Unexecuted instantiation: heap.c:talloc_init_const Unexecuted instantiation: htrie.c:talloc_init_const Unexecuted instantiation: inet.c:talloc_init_const Unexecuted instantiation: log.c:talloc_init_const Unexecuted instantiation: lst.c:talloc_init_const Unexecuted instantiation: machine.c:talloc_init_const Unexecuted instantiation: md4.c:talloc_init_const Unexecuted instantiation: md5.c:talloc_init_const Unexecuted instantiation: minmax_heap.c:talloc_init_const Unexecuted instantiation: misc.c:talloc_init_const Unexecuted instantiation: net.c:talloc_init_const Unexecuted instantiation: packet.c:talloc_init_const Unexecuted instantiation: pair.c:talloc_init_const Unexecuted instantiation: pair_legacy.c:talloc_init_const Unexecuted instantiation: pair_print.c:talloc_init_const Unexecuted instantiation: pair_tokenize.c:talloc_init_const Unexecuted instantiation: perm.c:talloc_init_const Unexecuted instantiation: print.c:talloc_init_const Unexecuted instantiation: proto.c:talloc_init_const Unexecuted instantiation: rand.c:talloc_init_const Unexecuted instantiation: rb.c:talloc_init_const Unexecuted instantiation: regex.c:talloc_init_const Unexecuted instantiation: retry.c:talloc_init_const Unexecuted instantiation: sbuff.c:talloc_init_const Unexecuted instantiation: sem.c:talloc_init_const Unexecuted instantiation: socket.c:talloc_init_const Unexecuted instantiation: strerror.c:talloc_init_const Unexecuted instantiation: struct.c:talloc_init_const Unexecuted instantiation: syserror.c:talloc_init_const Unexecuted instantiation: table.c:talloc_init_const Unexecuted instantiation: talloc.c:talloc_init_const Unexecuted instantiation: time.c:talloc_init_const Unexecuted instantiation: timeval.c:talloc_init_const Unexecuted instantiation: token.c:talloc_init_const Unexecuted instantiation: trie.c:talloc_init_const Unexecuted instantiation: types.c:talloc_init_const Unexecuted instantiation: udp.c:talloc_init_const Unexecuted instantiation: udpfromto.c:talloc_init_const Unexecuted instantiation: udp_queue.c:talloc_init_const Unexecuted instantiation: uri.c:talloc_init_const Unexecuted instantiation: value.c:talloc_init_const Unexecuted instantiation: vmps.c:talloc_init_const Unexecuted instantiation: base.c:talloc_init_const Unexecuted instantiation: base.c:talloc_init_const Unexecuted instantiation: decode.c:talloc_init_const Unexecuted instantiation: encode.c:talloc_init_const Unexecuted instantiation: list.c:talloc_init_const Unexecuted instantiation: tcp.c:talloc_init_const Unexecuted instantiation: abinary.c:talloc_init_const Unexecuted instantiation: raw.c:talloc_init_const |
121 | | |
122 | | void talloc_free_data(void *data); |
123 | | |
124 | | void *talloc_null_ctx(void); |
125 | | |
126 | | fr_talloc_destructor_t *talloc_destructor_add(TALLOC_CTX *fire_ctx, TALLOC_CTX *disarm_ctx, |
127 | | fr_talloc_free_func_t func, void const *uctx); |
128 | | |
129 | | void talloc_destructor_disarm(fr_talloc_destructor_t *d); |
130 | | |
131 | | int talloc_link_ctx(TALLOC_CTX *parent, TALLOC_CTX *child); |
132 | | |
133 | | TALLOC_CTX *talloc_page_aligned_pool(TALLOC_CTX *ctx, void **start, void **end, size_t size); |
134 | | TALLOC_CTX *talloc_aligned_array(TALLOC_CTX *ctx, void **start, size_t alignment, size_t size); |
135 | | |
136 | | /* |
137 | | * Add variant that zeroes out newly allocated memory |
138 | | */ |
139 | | #if defined(HAVE__TALLOC_POOLED_OBJECT) && defined(talloc_pooled_object) |
140 | | # define HAVE_TALLOC_ZERO_POOLED_OBJECT 1 |
141 | | # define HAVE_TALLOC_POOLED_OBJECT 1 |
142 | | |
143 | | # define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \ |
144 | 0 | (_type *)_talloc_zero_pooled_object((_ctx), sizeof(_type), #_type, \ |
145 | 0 | (_num_subobjects), (_total_subobjects_size)) |
146 | | |
147 | | static inline TALLOC_CTX *_talloc_zero_pooled_object(const void *ctx, |
148 | | size_t type_size, |
149 | | const char *type_name, |
150 | | unsigned num_subobjects, |
151 | | size_t total_subobjects_size) |
152 | 0 | { |
153 | 0 | TALLOC_CTX *new; |
154 | 0 | new = _talloc_pooled_object(ctx, type_size, type_name, num_subobjects, total_subobjects_size); |
155 | 0 | if (unlikely(!new)) return NULL; |
156 | 0 | memset(new, 0, type_size); |
157 | 0 | return new; |
158 | 0 | } Unexecuted instantiation: fuzzer.c:_talloc_zero_pooled_object Unexecuted instantiation: atexit.c:_talloc_zero_pooled_object Unexecuted instantiation: base16.c:_talloc_zero_pooled_object Unexecuted instantiation: base32.c:_talloc_zero_pooled_object Unexecuted instantiation: base64.c:_talloc_zero_pooled_object Unexecuted instantiation: calc.c:_talloc_zero_pooled_object Unexecuted instantiation: dbuff.c:_talloc_zero_pooled_object Unexecuted instantiation: debug.c:_talloc_zero_pooled_object Unexecuted instantiation: dict_ext.c:_talloc_zero_pooled_object Unexecuted instantiation: dict_fixup.c:_talloc_zero_pooled_object Unexecuted instantiation: dict_print.c:_talloc_zero_pooled_object Unexecuted instantiation: dict_test.c:_talloc_zero_pooled_object Unexecuted instantiation: dict_tokenize.c:_talloc_zero_pooled_object Unexecuted instantiation: dict_unknown.c:_talloc_zero_pooled_object Unexecuted instantiation: dict_util.c:_talloc_zero_pooled_object Unexecuted instantiation: dict_validate.c:_talloc_zero_pooled_object Unexecuted instantiation: dl.c:_talloc_zero_pooled_object Unexecuted instantiation: dns.c:_talloc_zero_pooled_object Unexecuted instantiation: edit.c:_talloc_zero_pooled_object Unexecuted instantiation: event.c:_talloc_zero_pooled_object Unexecuted instantiation: ext.c:_talloc_zero_pooled_object Unexecuted instantiation: fifo.c:_talloc_zero_pooled_object Unexecuted instantiation: file.c:_talloc_zero_pooled_object Unexecuted instantiation: fring.c:_talloc_zero_pooled_object Unexecuted instantiation: hash.c:_talloc_zero_pooled_object Unexecuted instantiation: heap.c:_talloc_zero_pooled_object Unexecuted instantiation: htrie.c:_talloc_zero_pooled_object Unexecuted instantiation: inet.c:_talloc_zero_pooled_object Unexecuted instantiation: log.c:_talloc_zero_pooled_object Unexecuted instantiation: lst.c:_talloc_zero_pooled_object Unexecuted instantiation: machine.c:_talloc_zero_pooled_object Unexecuted instantiation: md4.c:_talloc_zero_pooled_object Unexecuted instantiation: md5.c:_talloc_zero_pooled_object Unexecuted instantiation: minmax_heap.c:_talloc_zero_pooled_object Unexecuted instantiation: misc.c:_talloc_zero_pooled_object Unexecuted instantiation: net.c:_talloc_zero_pooled_object Unexecuted instantiation: packet.c:_talloc_zero_pooled_object Unexecuted instantiation: pair.c:_talloc_zero_pooled_object Unexecuted instantiation: pair_legacy.c:_talloc_zero_pooled_object Unexecuted instantiation: pair_print.c:_talloc_zero_pooled_object Unexecuted instantiation: pair_tokenize.c:_talloc_zero_pooled_object Unexecuted instantiation: perm.c:_talloc_zero_pooled_object Unexecuted instantiation: print.c:_talloc_zero_pooled_object Unexecuted instantiation: proto.c:_talloc_zero_pooled_object Unexecuted instantiation: rand.c:_talloc_zero_pooled_object Unexecuted instantiation: rb.c:_talloc_zero_pooled_object Unexecuted instantiation: regex.c:_talloc_zero_pooled_object Unexecuted instantiation: retry.c:_talloc_zero_pooled_object Unexecuted instantiation: sbuff.c:_talloc_zero_pooled_object Unexecuted instantiation: sem.c:_talloc_zero_pooled_object Unexecuted instantiation: socket.c:_talloc_zero_pooled_object Unexecuted instantiation: strerror.c:_talloc_zero_pooled_object Unexecuted instantiation: struct.c:_talloc_zero_pooled_object Unexecuted instantiation: syserror.c:_talloc_zero_pooled_object Unexecuted instantiation: table.c:_talloc_zero_pooled_object Unexecuted instantiation: talloc.c:_talloc_zero_pooled_object Unexecuted instantiation: time.c:_talloc_zero_pooled_object Unexecuted instantiation: timeval.c:_talloc_zero_pooled_object Unexecuted instantiation: token.c:_talloc_zero_pooled_object Unexecuted instantiation: trie.c:_talloc_zero_pooled_object Unexecuted instantiation: types.c:_talloc_zero_pooled_object Unexecuted instantiation: udp.c:_talloc_zero_pooled_object Unexecuted instantiation: udpfromto.c:_talloc_zero_pooled_object Unexecuted instantiation: udp_queue.c:_talloc_zero_pooled_object Unexecuted instantiation: uri.c:_talloc_zero_pooled_object Unexecuted instantiation: value.c:_talloc_zero_pooled_object Unexecuted instantiation: vmps.c:_talloc_zero_pooled_object Unexecuted instantiation: base.c:_talloc_zero_pooled_object Unexecuted instantiation: decode.c:_talloc_zero_pooled_object Unexecuted instantiation: encode.c:_talloc_zero_pooled_object Unexecuted instantiation: list.c:_talloc_zero_pooled_object Unexecuted instantiation: tcp.c:_talloc_zero_pooled_object Unexecuted instantiation: abinary.c:_talloc_zero_pooled_object Unexecuted instantiation: raw.c:_talloc_zero_pooled_object |
159 | | /* |
160 | | * Fall back to non-pooled variants |
161 | | */ |
162 | | #else |
163 | | # define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \ |
164 | | talloc_zero(_ctx, _type) |
165 | | #undef talloc_pooled_object |
166 | | # define talloc_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size) \ |
167 | | talloc(_ctx, _type) |
168 | | #endif |
169 | | |
170 | | /** @hidecallergraph */ |
171 | | char *talloc_typed_strdup(TALLOC_CTX *ctx, char const *p); |
172 | | |
173 | | char *talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt, ...) CC_HINT(format (printf, 2, 3)); |
174 | | |
175 | | char *talloc_typed_vasprintf(TALLOC_CTX *ctx, char const *fmt, va_list ap) CC_HINT(format (printf, 2, 0)) CC_HINT(nonnull (2)); |
176 | | |
177 | | uint8_t *talloc_typed_memdup(TALLOC_CTX *ctx, uint8_t const *in, size_t inlen); |
178 | | |
179 | | char *talloc_bstrdup(TALLOC_CTX *ctx, char const *in); |
180 | | |
181 | | char *talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen); |
182 | | |
183 | | char *talloc_bstr_append(TALLOC_CTX *ctx, char *to, char const *from, size_t from_len); |
184 | | |
185 | | char *talloc_bstr_realloc(TALLOC_CTX *ctx, char *in, size_t inlen); |
186 | | |
187 | | char *talloc_buffer_append_buffer(TALLOC_CTX *ctx, char *to, char const *from); |
188 | | |
189 | | char *talloc_buffer_append_variadic_buffer(TALLOC_CTX *ctx, char *to, int argc, ...); |
190 | | |
191 | | int talloc_memcmp_array(uint8_t const *a, uint8_t const *b); |
192 | | |
193 | | int talloc_memcmp_bstr(char const *a, char const *b); |
194 | | |
195 | | int talloc_decrease_ref_count(void const *ptr); |
196 | | |
197 | | void **talloc_array_null_terminate(void **array); |
198 | | |
199 | | void **talloc_array_null_strip(void **array); |
200 | | |
201 | | /** Free const'd memory |
202 | | * |
203 | | * @param[in] ptr to free. |
204 | | */ |
205 | | static inline int talloc_const_free(void const *ptr) |
206 | 0 | { |
207 | 0 | if (!ptr) return 0; |
208 | | |
209 | 0 | return talloc_free(UNCONST(void *, ptr)); |
210 | 0 | } Unexecuted instantiation: fuzzer.c:talloc_const_free Unexecuted instantiation: atexit.c:talloc_const_free Unexecuted instantiation: base16.c:talloc_const_free Unexecuted instantiation: base32.c:talloc_const_free Unexecuted instantiation: base64.c:talloc_const_free Unexecuted instantiation: calc.c:talloc_const_free Unexecuted instantiation: dbuff.c:talloc_const_free Unexecuted instantiation: debug.c:talloc_const_free Unexecuted instantiation: dict_ext.c:talloc_const_free Unexecuted instantiation: dict_fixup.c:talloc_const_free Unexecuted instantiation: dict_print.c:talloc_const_free Unexecuted instantiation: dict_test.c:talloc_const_free Unexecuted instantiation: dict_tokenize.c:talloc_const_free Unexecuted instantiation: dict_unknown.c:talloc_const_free Unexecuted instantiation: dict_util.c:talloc_const_free Unexecuted instantiation: dict_validate.c:talloc_const_free Unexecuted instantiation: dl.c:talloc_const_free Unexecuted instantiation: dns.c:talloc_const_free Unexecuted instantiation: edit.c:talloc_const_free Unexecuted instantiation: event.c:talloc_const_free Unexecuted instantiation: ext.c:talloc_const_free Unexecuted instantiation: fifo.c:talloc_const_free Unexecuted instantiation: file.c:talloc_const_free Unexecuted instantiation: fring.c:talloc_const_free Unexecuted instantiation: hash.c:talloc_const_free Unexecuted instantiation: heap.c:talloc_const_free Unexecuted instantiation: htrie.c:talloc_const_free Unexecuted instantiation: inet.c:talloc_const_free Unexecuted instantiation: log.c:talloc_const_free Unexecuted instantiation: lst.c:talloc_const_free Unexecuted instantiation: machine.c:talloc_const_free Unexecuted instantiation: md4.c:talloc_const_free Unexecuted instantiation: md5.c:talloc_const_free Unexecuted instantiation: minmax_heap.c:talloc_const_free Unexecuted instantiation: misc.c:talloc_const_free Unexecuted instantiation: net.c:talloc_const_free Unexecuted instantiation: packet.c:talloc_const_free Unexecuted instantiation: pair.c:talloc_const_free Unexecuted instantiation: pair_legacy.c:talloc_const_free Unexecuted instantiation: pair_print.c:talloc_const_free Unexecuted instantiation: pair_tokenize.c:talloc_const_free Unexecuted instantiation: perm.c:talloc_const_free Unexecuted instantiation: print.c:talloc_const_free Unexecuted instantiation: proto.c:talloc_const_free Unexecuted instantiation: rand.c:talloc_const_free Unexecuted instantiation: rb.c:talloc_const_free Unexecuted instantiation: regex.c:talloc_const_free Unexecuted instantiation: retry.c:talloc_const_free Unexecuted instantiation: sbuff.c:talloc_const_free Unexecuted instantiation: sem.c:talloc_const_free Unexecuted instantiation: socket.c:talloc_const_free Unexecuted instantiation: strerror.c:talloc_const_free Unexecuted instantiation: struct.c:talloc_const_free Unexecuted instantiation: syserror.c:talloc_const_free Unexecuted instantiation: table.c:talloc_const_free Unexecuted instantiation: talloc.c:talloc_const_free Unexecuted instantiation: time.c:talloc_const_free Unexecuted instantiation: timeval.c:talloc_const_free Unexecuted instantiation: token.c:talloc_const_free Unexecuted instantiation: trie.c:talloc_const_free Unexecuted instantiation: types.c:talloc_const_free Unexecuted instantiation: udp.c:talloc_const_free Unexecuted instantiation: udpfromto.c:talloc_const_free Unexecuted instantiation: udp_queue.c:talloc_const_free Unexecuted instantiation: uri.c:talloc_const_free Unexecuted instantiation: value.c:talloc_const_free Unexecuted instantiation: vmps.c:talloc_const_free Unexecuted instantiation: base.c:talloc_const_free Unexecuted instantiation: decode.c:talloc_const_free Unexecuted instantiation: encode.c:talloc_const_free Unexecuted instantiation: list.c:talloc_const_free Unexecuted instantiation: tcp.c:talloc_const_free Unexecuted instantiation: abinary.c:talloc_const_free Unexecuted instantiation: raw.c:talloc_const_free |
211 | | |
212 | | /** Free a list of talloced structures containing a next field |
213 | | * |
214 | | * @param[in] _head of list to free. Will set memory it points to to be NULL. |
215 | | */ |
216 | | #define talloc_list_free(_head) _talloc_list_free((void **)_head, offsetof(__typeof__(**(_head)), next)) |
217 | | |
218 | | static inline void _talloc_list_free(void **head, size_t offset) |
219 | 0 | { |
220 | 0 | void *v = *head, *n; |
221 | 0 |
|
222 | 0 | while (v) { |
223 | 0 | n = *((void **)(((uint8_t *)(v)) + offset)); |
224 | 0 | talloc_free(v); |
225 | 0 | v = n; |
226 | 0 | } |
227 | 0 | *head = NULL; |
228 | 0 | } Unexecuted instantiation: fuzzer.c:_talloc_list_free Unexecuted instantiation: atexit.c:_talloc_list_free Unexecuted instantiation: base16.c:_talloc_list_free Unexecuted instantiation: base32.c:_talloc_list_free Unexecuted instantiation: base64.c:_talloc_list_free Unexecuted instantiation: calc.c:_talloc_list_free Unexecuted instantiation: dbuff.c:_talloc_list_free Unexecuted instantiation: debug.c:_talloc_list_free Unexecuted instantiation: dict_ext.c:_talloc_list_free Unexecuted instantiation: dict_fixup.c:_talloc_list_free Unexecuted instantiation: dict_print.c:_talloc_list_free Unexecuted instantiation: dict_test.c:_talloc_list_free Unexecuted instantiation: dict_tokenize.c:_talloc_list_free Unexecuted instantiation: dict_unknown.c:_talloc_list_free Unexecuted instantiation: dict_util.c:_talloc_list_free Unexecuted instantiation: dict_validate.c:_talloc_list_free Unexecuted instantiation: dl.c:_talloc_list_free Unexecuted instantiation: dns.c:_talloc_list_free Unexecuted instantiation: edit.c:_talloc_list_free Unexecuted instantiation: event.c:_talloc_list_free Unexecuted instantiation: ext.c:_talloc_list_free Unexecuted instantiation: fifo.c:_talloc_list_free Unexecuted instantiation: file.c:_talloc_list_free Unexecuted instantiation: fring.c:_talloc_list_free Unexecuted instantiation: hash.c:_talloc_list_free Unexecuted instantiation: heap.c:_talloc_list_free Unexecuted instantiation: htrie.c:_talloc_list_free Unexecuted instantiation: inet.c:_talloc_list_free Unexecuted instantiation: log.c:_talloc_list_free Unexecuted instantiation: lst.c:_talloc_list_free Unexecuted instantiation: machine.c:_talloc_list_free Unexecuted instantiation: md4.c:_talloc_list_free Unexecuted instantiation: md5.c:_talloc_list_free Unexecuted instantiation: minmax_heap.c:_talloc_list_free Unexecuted instantiation: misc.c:_talloc_list_free Unexecuted instantiation: net.c:_talloc_list_free Unexecuted instantiation: packet.c:_talloc_list_free Unexecuted instantiation: pair.c:_talloc_list_free Unexecuted instantiation: pair_legacy.c:_talloc_list_free Unexecuted instantiation: pair_print.c:_talloc_list_free Unexecuted instantiation: pair_tokenize.c:_talloc_list_free Unexecuted instantiation: perm.c:_talloc_list_free Unexecuted instantiation: print.c:_talloc_list_free Unexecuted instantiation: proto.c:_talloc_list_free Unexecuted instantiation: rand.c:_talloc_list_free Unexecuted instantiation: rb.c:_talloc_list_free Unexecuted instantiation: regex.c:_talloc_list_free Unexecuted instantiation: retry.c:_talloc_list_free Unexecuted instantiation: sbuff.c:_talloc_list_free Unexecuted instantiation: sem.c:_talloc_list_free Unexecuted instantiation: socket.c:_talloc_list_free Unexecuted instantiation: strerror.c:_talloc_list_free Unexecuted instantiation: struct.c:_talloc_list_free Unexecuted instantiation: syserror.c:_talloc_list_free Unexecuted instantiation: table.c:_talloc_list_free Unexecuted instantiation: talloc.c:_talloc_list_free Unexecuted instantiation: time.c:_talloc_list_free Unexecuted instantiation: timeval.c:_talloc_list_free Unexecuted instantiation: token.c:_talloc_list_free Unexecuted instantiation: trie.c:_talloc_list_free Unexecuted instantiation: types.c:_talloc_list_free Unexecuted instantiation: udp.c:_talloc_list_free Unexecuted instantiation: udpfromto.c:_talloc_list_free Unexecuted instantiation: udp_queue.c:_talloc_list_free Unexecuted instantiation: uri.c:_talloc_list_free Unexecuted instantiation: value.c:_talloc_list_free Unexecuted instantiation: vmps.c:_talloc_list_free Unexecuted instantiation: base.c:_talloc_list_free Unexecuted instantiation: decode.c:_talloc_list_free Unexecuted instantiation: encode.c:_talloc_list_free Unexecuted instantiation: list.c:_talloc_list_free Unexecuted instantiation: tcp.c:_talloc_list_free Unexecuted instantiation: abinary.c:_talloc_list_free Unexecuted instantiation: raw.c:_talloc_list_free |
229 | | |
230 | | /** Verify a list of talloced structures are the correct type and are still valid |
231 | | * |
232 | | * @param[in] _head of list to check. |
233 | | * @param[in] _type of talloced chunk we expect. |
234 | | */ |
235 | | #ifndef TALLOC_GET_TYPE_ABORT_NOOP |
236 | | # define talloc_list_get_type_abort(_head, _type) (_type *)_talloc_list_get_type_abort(_head, offsetof(__typeof__(*(_head)), next), #_type, __location__) |
237 | | static inline void *_talloc_list_get_type_abort(void *head, size_t offset, char const *type, char const *location) |
238 | 0 | { |
239 | 0 | void *v = head, *n; |
240 | 0 |
|
241 | 0 | if (!v) _talloc_get_type_abort(v, type, location); /* Behave like the normal talloc_get_type_abort function */ |
242 | 0 |
|
243 | 0 | while (v) { |
244 | 0 | n = *((void **)(((uint8_t *)(v)) + offset)); |
245 | 0 | _talloc_get_type_abort(v, type, location); |
246 | 0 | v = n; |
247 | 0 | } |
248 | 0 |
|
249 | 0 | return head; |
250 | 0 | } Unexecuted instantiation: fuzzer.c:_talloc_list_get_type_abort Unexecuted instantiation: atexit.c:_talloc_list_get_type_abort Unexecuted instantiation: base16.c:_talloc_list_get_type_abort Unexecuted instantiation: base32.c:_talloc_list_get_type_abort Unexecuted instantiation: base64.c:_talloc_list_get_type_abort Unexecuted instantiation: calc.c:_talloc_list_get_type_abort Unexecuted instantiation: dbuff.c:_talloc_list_get_type_abort Unexecuted instantiation: debug.c:_talloc_list_get_type_abort Unexecuted instantiation: dict_ext.c:_talloc_list_get_type_abort Unexecuted instantiation: dict_fixup.c:_talloc_list_get_type_abort Unexecuted instantiation: dict_print.c:_talloc_list_get_type_abort Unexecuted instantiation: dict_test.c:_talloc_list_get_type_abort Unexecuted instantiation: dict_tokenize.c:_talloc_list_get_type_abort Unexecuted instantiation: dict_unknown.c:_talloc_list_get_type_abort Unexecuted instantiation: dict_util.c:_talloc_list_get_type_abort Unexecuted instantiation: dict_validate.c:_talloc_list_get_type_abort Unexecuted instantiation: dl.c:_talloc_list_get_type_abort Unexecuted instantiation: dns.c:_talloc_list_get_type_abort Unexecuted instantiation: edit.c:_talloc_list_get_type_abort Unexecuted instantiation: event.c:_talloc_list_get_type_abort Unexecuted instantiation: ext.c:_talloc_list_get_type_abort Unexecuted instantiation: fifo.c:_talloc_list_get_type_abort Unexecuted instantiation: file.c:_talloc_list_get_type_abort Unexecuted instantiation: fring.c:_talloc_list_get_type_abort Unexecuted instantiation: hash.c:_talloc_list_get_type_abort Unexecuted instantiation: heap.c:_talloc_list_get_type_abort Unexecuted instantiation: htrie.c:_talloc_list_get_type_abort Unexecuted instantiation: inet.c:_talloc_list_get_type_abort Unexecuted instantiation: log.c:_talloc_list_get_type_abort Unexecuted instantiation: lst.c:_talloc_list_get_type_abort Unexecuted instantiation: machine.c:_talloc_list_get_type_abort Unexecuted instantiation: md4.c:_talloc_list_get_type_abort Unexecuted instantiation: md5.c:_talloc_list_get_type_abort Unexecuted instantiation: minmax_heap.c:_talloc_list_get_type_abort Unexecuted instantiation: misc.c:_talloc_list_get_type_abort Unexecuted instantiation: net.c:_talloc_list_get_type_abort Unexecuted instantiation: packet.c:_talloc_list_get_type_abort Unexecuted instantiation: pair.c:_talloc_list_get_type_abort Unexecuted instantiation: pair_legacy.c:_talloc_list_get_type_abort Unexecuted instantiation: pair_print.c:_talloc_list_get_type_abort Unexecuted instantiation: pair_tokenize.c:_talloc_list_get_type_abort Unexecuted instantiation: perm.c:_talloc_list_get_type_abort Unexecuted instantiation: print.c:_talloc_list_get_type_abort Unexecuted instantiation: proto.c:_talloc_list_get_type_abort Unexecuted instantiation: rand.c:_talloc_list_get_type_abort Unexecuted instantiation: rb.c:_talloc_list_get_type_abort Unexecuted instantiation: regex.c:_talloc_list_get_type_abort Unexecuted instantiation: retry.c:_talloc_list_get_type_abort Unexecuted instantiation: sbuff.c:_talloc_list_get_type_abort Unexecuted instantiation: sem.c:_talloc_list_get_type_abort Unexecuted instantiation: socket.c:_talloc_list_get_type_abort Unexecuted instantiation: strerror.c:_talloc_list_get_type_abort Unexecuted instantiation: struct.c:_talloc_list_get_type_abort Unexecuted instantiation: syserror.c:_talloc_list_get_type_abort Unexecuted instantiation: table.c:_talloc_list_get_type_abort Unexecuted instantiation: talloc.c:_talloc_list_get_type_abort Unexecuted instantiation: time.c:_talloc_list_get_type_abort Unexecuted instantiation: timeval.c:_talloc_list_get_type_abort Unexecuted instantiation: token.c:_talloc_list_get_type_abort Unexecuted instantiation: trie.c:_talloc_list_get_type_abort Unexecuted instantiation: types.c:_talloc_list_get_type_abort Unexecuted instantiation: udp.c:_talloc_list_get_type_abort Unexecuted instantiation: udpfromto.c:_talloc_list_get_type_abort Unexecuted instantiation: udp_queue.c:_talloc_list_get_type_abort Unexecuted instantiation: uri.c:_talloc_list_get_type_abort Unexecuted instantiation: value.c:_talloc_list_get_type_abort Unexecuted instantiation: vmps.c:_talloc_list_get_type_abort Unexecuted instantiation: base.c:_talloc_list_get_type_abort Unexecuted instantiation: decode.c:_talloc_list_get_type_abort Unexecuted instantiation: encode.c:_talloc_list_get_type_abort Unexecuted instantiation: list.c:_talloc_list_get_type_abort Unexecuted instantiation: tcp.c:_talloc_list_get_type_abort Unexecuted instantiation: abinary.c:_talloc_list_get_type_abort Unexecuted instantiation: raw.c:_talloc_list_get_type_abort |
251 | | #else |
252 | | # define talloc_list_get_type_abort(_head, _type) (_type *)(_head) |
253 | | #endif |
254 | | |
255 | | /* |
256 | | * talloc portability issues. 'const' is not part of the talloc |
257 | | * type, but it is part of the pointer type. But only if |
258 | | * talloc_get_type_abort() is just a cast. |
259 | | */ |
260 | | #ifdef TALLOC_GET_TYPE_ABORT_NOOP |
261 | | # define talloc_get_type_abort_const(ptr, type) (const type *)(ptr) |
262 | | #else |
263 | 2.59M | # define talloc_get_type_abort_const talloc_get_type_abort |
264 | | #endif |
265 | | |
266 | | TALLOC_CTX *talloc_autofree_context_global(void); |
267 | | TALLOC_CTX *talloc_autofree_context_thread_local(void); |
268 | | |
269 | | typedef struct talloc_child_ctx_s TALLOC_CHILD_CTX; |
270 | | |
271 | | TALLOC_CHILD_CTX *talloc_child_ctx_init(TALLOC_CTX *ctx); |
272 | | TALLOC_CHILD_CTX *talloc_child_ctx_alloc(TALLOC_CHILD_CTX *parent) CC_HINT(nonnull); |
273 | | |
274 | | #ifdef __cplusplus |
275 | | } |
276 | | #endif |