1 #!/usr/local/bin/perl -w
3 my $safestack = "include/openssl/safestack.h";
7 $do_write = 1 if $_ eq "-write";
13 my @source = (<include/openssl/*.h>, <crypto/include/internal/*.h>, <crypto/*.[ch]>, <crypto/*/*.[ch]>, <ssl/*.[ch]>, <apps/*.[ch]>);
14 foreach $file (@source) {
17 # Open the .c/.h file for reading
18 open(IN, "< $file") || die "Can't open $file for reading, $!";
21 next unless /^DECLARE_/;
22 if (/^DECLARE_LHASH_OF\(([^)]+)\)/) {
29 my $new_stackfile = <<'EOF';
30 /* automatically generated by util/mkstack.pl */
31 /* ====================================================================
32 * Copyright (c) 1999-2015 The OpenSSL Project. All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
46 * 3. All advertising materials mentioning features or use of this
47 * software must display the following acknowledgment:
48 * "This product includes software developed by the OpenSSL Project
49 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
51 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
52 * endorse or promote products derived from this software without
53 * prior written permission. For written permission, please contact
54 * openssl-core@openssl.org.
56 * 5. Products derived from this software may not be called "OpenSSL"
57 * nor may "OpenSSL" appear in their names without prior written
58 * permission of the OpenSSL Project.
60 * 6. Redistributions of any form whatsoever must retain the following
62 * "This product includes software developed by the OpenSSL Project
63 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
65 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
66 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
68 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
69 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
70 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
71 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
72 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
73 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
74 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
75 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
76 * OF THE POSSIBILITY OF SUCH DAMAGE.
77 * ====================================================================
79 * This product includes cryptographic software written by Eric Young
80 * (eay@cryptsoft.com). This product includes software written by Tim
81 * Hudson (tjh@cryptsoft.com).
85 #ifndef HEADER_SAFESTACK_H
86 # define HEADER_SAFESTACK_H
88 # include <openssl/stack.h>
89 # include <openssl/e_os2.h>
95 # ifndef CHECKED_PTR_OF
96 # define CHECKED_PTR_OF(type, p) ((void*) (1 ? p : (type*)0))
100 * In C++ we get problems because an explicit cast is needed from (void *) we
101 * use CHECKED_STACK_OF to ensure the correct type is passed in the macros
105 # define CHECKED_STACK_OF(type, p) \
106 ((_STACK*) (1 ? p : (STACK_OF(type)*)0))
108 # define CHECKED_SK_COPY_FUNC(type, p) \
109 ((void *(*)(void *)) ((1 ? p : (type *(*)(const type *))0)))
111 # define CHECKED_SK_FREE_FUNC(type, p) \
112 ((void (*)(void *)) ((1 ? p : (void (*)(type *))0)))
114 # define CHECKED_SK_CMP_FUNC(type, p) \
115 ((int (*)(const void *, const void *)) \
116 ((1 ? p : (int (*)(const type * const *, const type * const *))0)))
118 # define STACK_OF(type) struct stack_st_##type
119 # define PREDECLARE_STACK_OF(type) STACK_OF(type);
121 # define SKM_DECLARE_STACK_OF(t1, t2, t3) \
123 static ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
125 return sk_num((_STACK *)sk); \
127 static ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
129 return sk_value((_STACK *)sk, idx); \
131 static ossl_inline STACK_OF(t1) *sk_##t1##_new(int (*cmpf)(const t3 * const *a, const t3 * const *b)) \
133 return (STACK_OF(t1) *)sk_new((int (*)(const void *a, const void *b))cmpf); \
135 static ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \
137 return (STACK_OF(t1) *)sk_new_null(); \
139 static ossl_inline void sk_##t1##_free(const STACK_OF(t1) *sk) \
141 sk_free((_STACK *)sk); \
143 static ossl_inline void sk_##t1##_zero(const STACK_OF(t1) *sk) \
145 sk_zero((_STACK *)sk); \
147 static ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \
149 return sk_delete((_STACK *)sk, i); \
151 static ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \
153 return sk_delete_ptr((_STACK *)sk, (void *)ptr); \
155 static ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
157 return sk_push((_STACK *)sk, (void *)ptr); \
159 static ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
161 return sk_unshift((_STACK *)sk, (void *)ptr); \
163 static ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
165 return (t2 *)sk_pop((_STACK *)sk); \
167 static ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \
169 return (t2 *)sk_shift((_STACK *)sk); \
171 static ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, void (*func)(t3 *a)) \
173 sk_pop_free((_STACK *)sk, (void (*)(void *))func); \
175 static ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
177 return sk_insert((_STACK *)sk, (void *)ptr, idx); \
179 static ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
181 return sk_set((_STACK *)sk, idx, (void *)ptr); \
183 static ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
185 return sk_find((_STACK *)sk, (void *)ptr); \
187 static ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \
189 return sk_find_ex((_STACK *)sk, (void *)ptr); \
191 static ossl_inline void sk_##t1##_sort(const STACK_OF(t1) *sk) \
193 sk_sort((_STACK *)sk); \
195 static ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \
197 return sk_is_sorted((_STACK *)sk); \
199 static ossl_inline STACK_OF(t1) * sk_##t1##_dup(STACK_OF(t1) *sk) \
201 return (STACK_OF(t1) *)sk_dup((_STACK *)sk); \
203 static ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(STACK_OF(t1) *sk, \
204 t3 *(*copyfn)(const t3 *), \
205 void (*freefn)(t3 *)) \
207 return (STACK_OF(t1) *)sk_deep_copy((_STACK *)sk, \
208 (void * (*)(void *a))copyfn, \
209 (void (*)(void *a))freefn); \
211 static ossl_inline int (*sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, int (*cmpf)(const t3 * const *a, const t3 * const *b)))(const t3 * const *, const t3 * const *) \
213 return (int (*)(const t3 * const *,const t3 * const *))sk_set_cmp_func((_STACK *)sk, (int (*)(const void *a, const void *b))cmpf); \
216 # define DECLARE_SPECIAL_STACK_OF(t1, t2) SKM_DECLARE_STACK_OF(t1, t2, t2)
217 # define DECLARE_STACK_OF(t) SKM_DECLARE_STACK_OF(t, t, t)
218 # define DECLARE_CONST_STACK_OF(t) SKM_DECLARE_STACK_OF(t, const t, t)
221 * Strings are special: normally an lhash entry will point to a single
222 * (somewhat) mutable object. In the case of strings:
224 * a) Instead of a single char, there is an array of chars, NUL-terminated.
225 * b) The string may have be immutable.
227 * So, they need their own declarations. Especially important for
228 * type-checking tools, such as Deputy.
230 * In practice, however, it appears to be hard to have a const
231 * string. For now, I'm settling for dealing with the fact it is a
234 typedef char *OPENSSL_STRING;
235 typedef const char *OPENSSL_CSTRING;
238 * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but
239 * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned
240 * above, instead of a single char each entry is a NUL-terminated array of
241 * chars. So, we have to implement STRING specially for STACK_OF. This is
242 * dealt with in the autogenerated macros below.
244 DECLARE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
247 * Similarly, we sometimes use a block of characters, NOT nul-terminated.
248 * These should also be distinguished from "normal" stacks.
250 typedef void *OPENSSL_BLOCK;
251 DECLARE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
254 * This file is automatically generated by util/mkstack.pl
259 * SKM_sk_... stack macros are internal to safestack.h: never use them
260 * directly, use sk_<type>_... instead
268 open(IN, "$safestack") || die "Can't open $safestack, $!";
269 $old_stackfile = <IN>;
275 foreach $type_thing (sort @lhashlst) {
276 my $lc_tt = lc $type_thing;
277 $new_stackfile .= <<EOF;
279 # define lh_${type_thing}_new() LHM_lh_new(${type_thing},${lc_tt})
280 # define lh_${type_thing}_insert(lh,inst) LHM_lh_insert(${type_thing},lh,inst)
281 # define lh_${type_thing}_retrieve(lh,inst) LHM_lh_retrieve(${type_thing},lh,inst)
282 # define lh_${type_thing}_delete(lh,inst) LHM_lh_delete(${type_thing},lh,inst)
283 # define lh_${type_thing}_doall(lh,fn) LHM_lh_doall(${type_thing},lh,fn)
284 # define lh_${type_thing}_doall_arg(lh,fn,arg_type,arg) \\
285 LHM_lh_doall_arg(${type_thing},lh,fn,arg_type,arg)
286 # define lh_${type_thing}_error(lh) LHM_lh_error(${type_thing},lh)
287 # define lh_${type_thing}_num_items(lh) LHM_lh_num_items(${type_thing},lh)
288 # define lh_${type_thing}_down_load(lh) LHM_lh_down_load(${type_thing},lh)
289 # define lh_${type_thing}_node_stats_bio(lh,out) \\
290 LHM_lh_node_stats_bio(${type_thing},lh,out)
291 # define lh_${type_thing}_node_usage_stats_bio(lh,out) \\
292 LHM_lh_node_usage_stats_bio(${type_thing},lh,out)
293 # define lh_${type_thing}_stats_bio(lh,out) \\
294 LHM_lh_stats_bio(${type_thing},lh,out)
295 # define lh_${type_thing}_free(lh) LHM_lh_free(${type_thing},lh)
299 $new_stackfile .= <<'EOF';
307 if ($new_stackfile eq $old_stackfile) {
308 print "No changes to $safestack.\n";
311 print "Writing new $safestack.\n";
312 open OUT, ">$safestack" || die "Can't open $safestack for writing, $!";
313 print OUT $new_stackfile;