summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/util')
-rw-r--r--src/lib/libcrypto/util/mkerr.pl234
-rw-r--r--src/lib/libcrypto/util/mkstack.pl2
2 files changed, 181 insertions, 55 deletions
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl
index 4b3bccb13e..4105047b21 100644
--- a/src/lib/libcrypto/util/mkerr.pl
+++ b/src/lib/libcrypto/util/mkerr.pl
@@ -7,7 +7,7 @@ my $static = 1;
7my $recurse = 0; 7my $recurse = 0;
8my $reindex = 0; 8my $reindex = 0;
9my $dowrite = 0; 9my $dowrite = 0;
10 10my $staticloader = "";
11 11
12while (@ARGV) { 12while (@ARGV) {
13 my $arg = $ARGV[0]; 13 my $arg = $ARGV[0];
@@ -29,6 +29,9 @@ while (@ARGV) {
29 } elsif($arg eq "-nostatic") { 29 } elsif($arg eq "-nostatic") {
30 $static = 0; 30 $static = 0;
31 shift @ARGV; 31 shift @ARGV;
32 } elsif($arg eq "-staticloader") {
33 $staticloader = "static ";
34 shift @ARGV;
32 } elsif($arg eq "-write") { 35 } elsif($arg eq "-write") {
33 $dowrite = 1; 36 $dowrite = 1;
34 shift @ARGV; 37 shift @ARGV;
@@ -38,7 +41,7 @@ while (@ARGV) {
38} 41}
39 42
40if($recurse) { 43if($recurse) {
41 @source = (<crypto/*.c>, <crypto/*/*.c>, ,<rsaref/*.c>, <ssl/*.c>); 44 @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>);
42} else { 45} else {
43 @source = @ARGV; 46 @source = @ARGV;
44} 47}
@@ -53,6 +56,7 @@ while(<IN>)
53{ 56{
54 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) { 57 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
55 $hinc{$1} = $2; 58 $hinc{$1} = $2;
59 $libinc{$2} = $1;
56 $cskip{$3} = $1; 60 $cskip{$3} = $1;
57 if($3 ne "NONE") { 61 if($3 ne "NONE") {
58 $csrc{$1} = $3; 62 $csrc{$1} = $3;
@@ -74,43 +78,53 @@ close IN;
74# Scan each header file in turn and make a list of error codes 78# Scan each header file in turn and make a list of error codes
75# and function names 79# and function names
76 80
77while (($lib, $hdr) = each %hinc) 81while (($hdr, $lib) = each %libinc)
78{ 82{
79 next if($hdr eq "NONE"); 83 next if($hdr eq "NONE");
80 print STDERR "Scanning header file $hdr\n" if $debug; 84 print STDERR "Scanning header file $hdr\n" if $debug;
81 open(IN, "<$hdr") || die "Can't open Header file $hdr\n"; 85 my $line = "", $def= "", $linenr = 0, $gotfile = 0;
82 my $line = "", $def= ""; 86 if (open(IN, "<$hdr")) {
83 while(<IN>) { 87 $gotfile = 1;
84 last if(/BEGIN\s+ERROR\s+CODES/); 88 while(<IN>) {
85 if ($line ne '') { 89 $linenr++;
86 $_ = $line . $_; 90 print STDERR "line: $linenr\r" if $debug;
87 $line = ''; 91
88 } 92 last if(/BEGIN\s+ERROR\s+CODES/);
93 if ($line ne '') {
94 $_ = $line . $_;
95 $line = '';
96 }
89 97
90 if (/\\$/) { 98 if (/\\$/) {
91 $line = $_; 99 $line = $_;
92 next; 100 next;
93 } 101 }
94 102
95 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration 103 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
96 if ($cpp) { 104 if ($cpp) {
97 $cpp = 0 if /^#.*endif/; 105 $cpp = 0 if /^#.*endif/;
98 next; 106 next;
99 } 107 }
100 108
101 next if (/^#/); # skip preprocessor directives 109 next if (/^\#/); # skip preprocessor directives
102 110
103 s/\/\*.*?\*\///gs; # ignore comments 111 s/\/\*.*?\*\///gs; # ignore comments
104 s/{[^{}]*}//gs; # ignore {} blocks 112 s/{[^{}]*}//gs; # ignore {} blocks
105 113
106 if (/{|\/\*/) { # Add a } so editor works... 114 if (/\{|\/\*/) { # Add a } so editor works...
107 $line = $_; 115 $line = $_;
108 } else { 116 } else {
109 $def .= $_; 117 $def .= $_;
118 }
110 } 119 }
111 } 120 }
112 121
122 print STDERR " \r" if $debug;
123 $defnr = 0;
113 foreach (split /;/, $def) { 124 foreach (split /;/, $def) {
125 $defnr++;
126 print STDERR "def: $defnr\r" if $debug;
127
114 s/^[\n\s]*//g; 128 s/^[\n\s]*//g;
115 s/[\n\s]*$//g; 129 s/[\n\s]*$//g;
116 next if(/typedef\W/); 130 next if(/typedef\W/);
@@ -136,15 +150,19 @@ while (($lib, $hdr) = each %hinc)
136 } 150 }
137 } 151 }
138 152
153 print STDERR " \r" if $debug;
154
139 next if $reindex; 155 next if $reindex;
140 156
141 # Scan function and reason codes and store them: keep a note of the 157 # Scan function and reason codes and store them: keep a note of the
142 # maximum code used. 158 # maximum code used.
143 159
144 while(<IN>) { 160 if ($gotfile) {
145 if(/^#define\s+(\S+)\s+(\S+)/) { 161 while(<IN>) {
162 if(/^\#define\s+(\S+)\s+(\S+)/) {
146 $name = $1; 163 $name = $1;
147 $code = $2; 164 $code = $2;
165 next if $name =~ /^${lib}err/;
148 unless($name =~ /^${lib}_([RF])_(\w+)$/) { 166 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
149 print STDERR "Invalid error code $name\n"; 167 print STDERR "Invalid error code $name\n";
150 next; 168 next;
@@ -162,6 +180,7 @@ while (($lib, $hdr) = each %hinc)
162 $fcodes{$name} = $code; 180 $fcodes{$name} = $code;
163 } 181 }
164 } 182 }
183 }
165 } 184 }
166 close IN; 185 close IN;
167} 186}
@@ -178,9 +197,11 @@ while (($lib, $hdr) = each %hinc)
178# so all those unreferenced can be printed out. 197# so all those unreferenced can be printed out.
179 198
180 199
200print STDERR "Files loaded: " if $debug;
181foreach $file (@source) { 201foreach $file (@source) {
182 # Don't parse the error source file. 202 # Don't parse the error source file.
183 next if exists $cskip{$file}; 203 next if exists $cskip{$file};
204 print STDERR $file if $debug;
184 open(IN, "<$file") || die "Can't open source file $file\n"; 205 open(IN, "<$file") || die "Can't open source file $file\n";
185 while(<IN>) { 206 while(<IN>) {
186 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { 207 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
@@ -204,6 +225,7 @@ foreach $file (@source) {
204 } 225 }
205 close IN; 226 close IN;
206} 227}
228print STDERR "\n" if $debug;
207 229
208# Now process each library in turn. 230# Now process each library in turn.
209 231
@@ -230,15 +252,74 @@ foreach $lib (keys %csrc)
230 252
231 # Rewrite the header file 253 # Rewrite the header file
232 254
233 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n"; 255 if (open(IN, "<$hfile")) {
234 256 # Copy across the old file
235 # Copy across the old file 257 while(<IN>) {
236 while(<IN>) {
237 push @out, $_; 258 push @out, $_;
238 last if (/BEGIN ERROR CODES/); 259 last if (/BEGIN ERROR CODES/);
260 }
261 close IN;
262 } else {
263 push @out,
264"/* ====================================================================\n",
265" * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.\n",
266" *\n",
267" * Redistribution and use in source and binary forms, with or without\n",
268" * modification, are permitted provided that the following conditions\n",
269" * are met:\n",
270" *\n",
271" * 1. Redistributions of source code must retain the above copyright\n",
272" * notice, this list of conditions and the following disclaimer. \n",
273" *\n",
274" * 2. Redistributions in binary form must reproduce the above copyright\n",
275" * notice, this list of conditions and the following disclaimer in\n",
276" * the documentation and/or other materials provided with the\n",
277" * distribution.\n",
278" *\n",
279" * 3. All advertising materials mentioning features or use of this\n",
280" * software must display the following acknowledgment:\n",
281" * \"This product includes software developed by the OpenSSL Project\n",
282" * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n",
283" *\n",
284" * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n",
285" * endorse or promote products derived from this software without\n",
286" * prior written permission. For written permission, please contact\n",
287" * openssl-core\@openssl.org.\n",
288" *\n",
289" * 5. Products derived from this software may not be called \"OpenSSL\"\n",
290" * nor may \"OpenSSL\" appear in their names without prior written\n",
291" * permission of the OpenSSL Project.\n",
292" *\n",
293" * 6. Redistributions of any form whatsoever must retain the following\n",
294" * acknowledgment:\n",
295" * \"This product includes software developed by the OpenSSL Project\n",
296" * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n",
297" *\n",
298" * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n",
299" * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n",
300" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n",
301" * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n",
302" * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n",
303" * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n",
304" * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n",
305" * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n",
306" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n",
307" * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n",
308" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n",
309" * OF THE POSSIBILITY OF SUCH DAMAGE.\n",
310" * ====================================================================\n",
311" *\n",
312" * This product includes cryptographic software written by Eric Young\n",
313" * (eay\@cryptsoft.com). This product includes software written by Tim\n",
314" * Hudson (tjh\@cryptsoft.com).\n",
315" *\n",
316" */\n",
317"\n",
318"#ifndef HEADER_${lib}_ERR_H\n",
319"#define HEADER_${lib}_ERR_H\n",
320"\n",
321"/* BEGIN ERROR CODES */\n";
239 } 322 }
240 close IN;
241
242 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n"; 323 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
243 324
244 print OUT @out; 325 print OUT @out;
@@ -247,7 +328,22 @@ foreach $lib (keys %csrc)
247/* The following lines are auto generated by the script mkerr.pl. Any changes 328/* The following lines are auto generated by the script mkerr.pl. Any changes
248 * made after this point may be overwritten when the script is next run. 329 * made after this point may be overwritten when the script is next run.
249 */ 330 */
331EOF
332 if($static) {
333 print OUT <<"EOF";
334${staticloader}void ERR_load_${lib}_strings(void);
335
336EOF
337 } else {
338 print OUT <<"EOF";
339${staticloader}void ERR_load_${lib}_strings(void);
340${staticloader}void ERR_unload_${lib}_strings(void);
341${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line);
342#define ${lib}err(f,r) ERR_${lib}_error((f),(r),__FILE__,__LINE__)
250 343
344EOF
345 }
346 print OUT <<"EOF";
251/* Error codes for the $lib functions. */ 347/* Error codes for the $lib functions. */
252 348
253/* Function codes. */ 349/* Function codes. */
@@ -278,12 +374,22 @@ EOF
278} 374}
279#endif 375#endif
280#endif 376#endif
281
282EOF 377EOF
283 close OUT; 378 close OUT;
284 379
285 # Rewrite the C source file containing the error details. 380 # Rewrite the C source file containing the error details.
286 381
382 # First, read any existing reason string definitions:
383 my %err_reason_strings;
384 if (open(IN,"<$cfile")) {
385 while (<IN>) {
386 if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) {
387 $err_reason_strings{$1} = $2;
388 }
389 }
390 close(IN);
391 }
392
287 my $hincf; 393 my $hincf;
288 if($static) { 394 if($static) {
289 $hfile =~ /([^\/]+)$/; 395 $hfile =~ /([^\/]+)$/;
@@ -298,7 +404,7 @@ EOF
298 print OUT <<"EOF"; 404 print OUT <<"EOF";
299/* $cfile */ 405/* $cfile */
300/* ==================================================================== 406/* ====================================================================
301 * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 407 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
302 * 408 *
303 * Redistribution and use in source and binary forms, with or without 409 * Redistribution and use in source and binary forms, with or without
304 * modification, are permitted provided that the following conditions 410 * modification, are permitted provided that the following conditions
@@ -352,7 +458,8 @@ EOF
352 */ 458 */
353 459
354/* NOTE: this file was auto generated by the mkerr.pl script: any changes 460/* NOTE: this file was auto generated by the mkerr.pl script: any changes
355 * made to it will be overwritten when the script next updates this file. 461 * made to it will be overwritten when the script next updates this file,
462 * only reason strings will be preserved.
356 */ 463 */
357 464
358#include <stdio.h> 465#include <stdio.h>
@@ -360,7 +467,7 @@ EOF
360#include $hincf 467#include $hincf
361 468
362/* BEGIN ERROR CODES */ 469/* BEGIN ERROR CODES */
363#ifndef NO_ERR 470#ifndef OPENSSL_NO_ERR
364static ERR_STRING_DATA ${lib}_str_functs[]= 471static ERR_STRING_DATA ${lib}_str_functs[]=
365 { 472 {
366EOF 473EOF
@@ -385,9 +492,13 @@ EOF
385 foreach $i (@reasons) { 492 foreach $i (@reasons) {
386 my $rn; 493 my $rn;
387 my $nspc = 0; 494 my $nspc = 0;
388 $i =~ /^${lib}_R_(\S+)$/; 495 if (exists $err_reason_strings{$i}) {
389 $rn = $1; 496 $rn = $err_reason_strings{$i};
390 $rn =~ tr/_[A-Z]/ [a-z]/; 497 } else {
498 $i =~ /^${lib}_R_(\S+)$/;
499 $rn = $1;
500 $rn =~ tr/_[A-Z]/ [a-z]/;
501 }
391 $nspc = 40 - length($i) unless length($i) > 40; 502 $nspc = 40 - length($i) unless length($i) > 40;
392 $nspc = " " x $nspc; 503 $nspc = " " x $nspc;
393 print OUT "{${i}${nspc},\"$rn\"},\n"; 504 print OUT "{${i}${nspc},\"$rn\"},\n";
@@ -399,14 +510,14 @@ if($static) {
399 510
400#endif 511#endif
401 512
402void ERR_load_${lib}_strings(void) 513${staticloader}void ERR_load_${lib}_strings(void)
403 { 514 {
404 static int init=1; 515 static int init=1;
405 516
406 if (init) 517 if (init)
407 { 518 {
408 init=0; 519 init=0;
409#ifndef NO_ERR 520#ifndef OPENSSL_NO_ERR
410 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs); 521 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
411 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons); 522 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
412#endif 523#endif
@@ -430,19 +541,18 @@ static ERR_STRING_DATA ${lib}_lib_name[]=
430#endif 541#endif
431 542
432 543
433int ${lib}_lib_error_code=0; 544static int ${lib}_lib_error_code=0;
545static int ${lib}_error_init=1;
434 546
435void ERR_load_${lib}_strings(void) 547${staticloader}void ERR_load_${lib}_strings(void)
436 { 548 {
437 static int init=1;
438
439 if (${lib}_lib_error_code == 0) 549 if (${lib}_lib_error_code == 0)
440 ${lib}_lib_error_code=ERR_get_next_error_library(); 550 ${lib}_lib_error_code=ERR_get_next_error_library();
441 551
442 if (init) 552 if (${lib}_error_init)
443 { 553 {
444 init=0; 554 ${lib}_error_init=0;
445#ifndef NO_ERR 555#ifndef OPENSSL_NO_ERR
446 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs); 556 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
447 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons); 557 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
448#endif 558#endif
@@ -450,11 +560,27 @@ void ERR_load_${lib}_strings(void)
450#ifdef ${lib}_LIB_NAME 560#ifdef ${lib}_LIB_NAME
451 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0); 561 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
452 ERR_load_strings(0,${lib}_lib_name); 562 ERR_load_strings(0,${lib}_lib_name);
453#endif; 563#endif
564 }
565 }
566
567${staticloader}void ERR_unload_${lib}_strings(void)
568 {
569 if (${lib}_error_init == 0)
570 {
571#ifndef OPENSSL_NO_ERR
572 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_functs);
573 ERR_unload_strings(${lib}_lib_error_code,${lib}_str_reasons);
574#endif
575
576#ifdef ${lib}_LIB_NAME
577 ERR_unload_strings(0,${lib}_lib_name);
578#endif
579 ${lib}_error_init=1;
454 } 580 }
455 } 581 }
456 582
457void ERR_${lib}_error(int function, int reason, char *file, int line) 583${staticloader}void ERR_${lib}_error(int function, int reason, char *file, int line)
458 { 584 {
459 if (${lib}_lib_error_code == 0) 585 if (${lib}_lib_error_code == 0)
460 ${lib}_lib_error_code=ERR_get_next_error_library(); 586 ${lib}_lib_error_code=ERR_get_next_error_library();
@@ -465,7 +591,7 @@ EOF
465} 591}
466 592
467 close OUT; 593 close OUT;
468 594 undef %err_reason_strings;
469} 595}
470 596
471if($debug && defined(%notrans)) { 597if($debug && defined(%notrans)) {
diff --git a/src/lib/libcrypto/util/mkstack.pl b/src/lib/libcrypto/util/mkstack.pl
index 3ee13fe7c9..085c50f790 100644
--- a/src/lib/libcrypto/util/mkstack.pl
+++ b/src/lib/libcrypto/util/mkstack.pl
@@ -21,7 +21,7 @@ while (@ARGV) {
21} 21}
22 22
23 23
24@source = (<crypto/*.[ch]>, <crypto/*/*.[ch]>, <rsaref/*.[ch]>, <ssl/*.[ch]>); 24@source = (<crypto/*.[ch]>, <crypto/*/*.[ch]>, <ssl/*.[ch]>);
25foreach $file (@source) { 25foreach $file (@source) {
26 next if -l $file; 26 next if -l $file;
27 27