diff options
Diffstat (limited to 'src/lib/libcrypto/util/mkerr.pl')
-rw-r--r-- | src/lib/libcrypto/util/mkerr.pl | 113 |
1 files changed, 104 insertions, 9 deletions
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl index 554bebb159..15b774f277 100644 --- a/src/lib/libcrypto/util/mkerr.pl +++ b/src/lib/libcrypto/util/mkerr.pl | |||
@@ -1,6 +1,7 @@ | |||
1 | #!/usr/local/bin/perl -w | 1 | #!/usr/local/bin/perl -w |
2 | 2 | ||
3 | my $config = "crypto/err/openssl.ec"; | 3 | my $config = "crypto/err/openssl.ec"; |
4 | my $hprefix = "openssl/"; | ||
4 | my $debug = 0; | 5 | my $debug = 0; |
5 | my $rebuild = 0; | 6 | my $rebuild = 0; |
6 | my $static = 1; | 7 | my $static = 1; |
@@ -12,11 +13,16 @@ my $staticloader = ""; | |||
12 | my $pack_errcode; | 13 | my $pack_errcode; |
13 | my $load_errcode; | 14 | my $load_errcode; |
14 | 15 | ||
16 | my $errcount; | ||
17 | |||
15 | while (@ARGV) { | 18 | while (@ARGV) { |
16 | my $arg = $ARGV[0]; | 19 | my $arg = $ARGV[0]; |
17 | if($arg eq "-conf") { | 20 | if($arg eq "-conf") { |
18 | shift @ARGV; | 21 | shift @ARGV; |
19 | $config = shift @ARGV; | 22 | $config = shift @ARGV; |
23 | } elsif($arg eq "-hprefix") { | ||
24 | shift @ARGV; | ||
25 | $hprefix = shift @ARGV; | ||
20 | } elsif($arg eq "-debug") { | 26 | } elsif($arg eq "-debug") { |
21 | $debug = 1; | 27 | $debug = 1; |
22 | shift @ARGV; | 28 | shift @ARGV; |
@@ -38,14 +44,78 @@ while (@ARGV) { | |||
38 | } elsif($arg eq "-write") { | 44 | } elsif($arg eq "-write") { |
39 | $dowrite = 1; | 45 | $dowrite = 1; |
40 | shift @ARGV; | 46 | shift @ARGV; |
47 | } elsif($arg eq "-help" || $arg eq "-h" || $arg eq "-?" || $arg eq "--help") { | ||
48 | print STDERR <<"EOF"; | ||
49 | mkerr.pl [options] ... | ||
50 | |||
51 | Options: | ||
52 | |||
53 | -conf F Use the config file F instead of the default one: | ||
54 | crypto/err/openssl.ec | ||
55 | |||
56 | -hprefix P Prepend the filenames in generated #include <header> | ||
57 | statements with prefix P. Default: 'openssl/' (without | ||
58 | the quotes, naturally) | ||
59 | |||
60 | -debug Turn on debugging verbose output on stderr. | ||
61 | |||
62 | -rebuild Rebuild all header and C source files, irrespective of the | ||
63 | fact if any error or function codes have been added/removed. | ||
64 | Default: only update files for libraries which saw change | ||
65 | (of course, this requires '-write' as well, or no | ||
66 | files will be touched!) | ||
67 | |||
68 | -recurse scan a preconfigured set of directories / files for error and | ||
69 | function codes: | ||
70 | (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <apps/*.c>) | ||
71 | When this option is NOT specified, the filelist is taken from | ||
72 | the commandline instead. Here, wildcards may be embedded. (Be | ||
73 | sure to escape those to prevent the shell from expanding them | ||
74 | for you when you wish mkerr.pl to do so instead.) | ||
75 | Default: take file list to scan from the command line. | ||
76 | |||
77 | -reindex Discard the numeric values previously assigned to the error | ||
78 | and function codes as extracted from the scanned header files; | ||
79 | instead renumber all of them starting from 100. (Note that | ||
80 | the numbers assigned through 'R' records in the config file | ||
81 | remain intact.) | ||
82 | Default: keep previously assigned numbers. (You are warned | ||
83 | when collisions are detected.) | ||
84 | |||
85 | -nostatic Generates a different source code, where these additional | ||
86 | functions are generated for each library specified in the | ||
87 | config file: | ||
88 | void ERR_load_<LIB>_strings(void); | ||
89 | void ERR_unload_<LIB>_strings(void); | ||
90 | void ERR_<LIB>_error(int f, int r, char *fn, int ln); | ||
91 | #define <LIB>err(f,r) ERR_<LIB>_error(f,r,__FILE__,__LINE__) | ||
92 | while the code facilitates the use of these in an environment | ||
93 | where the error support routines are dynamically loaded at | ||
94 | runtime. | ||
95 | Default: 'static' code generation. | ||
96 | |||
97 | -staticloader Prefix generated functions with the 'static' scope modifier. | ||
98 | Default: don't write any scope modifier prefix. | ||
99 | |||
100 | -write Actually (over)write the generated code to the header and C | ||
101 | source files as assigned to each library through the config | ||
102 | file. | ||
103 | Default: don't write. | ||
104 | |||
105 | -help / -h / -? / --help Show this help text. | ||
106 | |||
107 | ... Additional arguments are added to the file list to scan, | ||
108 | assuming '-recurse' was NOT specified on the command line. | ||
109 | |||
110 | EOF | ||
111 | exit 1; | ||
41 | } else { | 112 | } else { |
42 | last; | 113 | last; |
43 | } | 114 | } |
44 | } | 115 | } |
45 | 116 | ||
46 | if($recurse) { | 117 | if($recurse) { |
47 | @source = ( <crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, | 118 | @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>); |
48 | <fips/*.c>, <fips/*/*.c>); | ||
49 | } else { | 119 | } else { |
50 | @source = @ARGV; | 120 | @source = @ARGV; |
51 | } | 121 | } |
@@ -64,8 +134,8 @@ while(<IN>) | |||
64 | $cskip{$3} = $1; | 134 | $cskip{$3} = $1; |
65 | if($3 ne "NONE") { | 135 | if($3 ne "NONE") { |
66 | $csrc{$1} = $3; | 136 | $csrc{$1} = $3; |
67 | $fmax{$1} = 99; | 137 | $fmax{$1} = 100; |
68 | $rmax{$1} = 99; | 138 | $rmax{$1} = 100; |
69 | $fassigned{$1} = ":"; | 139 | $fassigned{$1} = ":"; |
70 | $rassigned{$1} = ":"; | 140 | $rassigned{$1} = ":"; |
71 | $fnew{$1} = 0; | 141 | $fnew{$1} = 0; |
@@ -191,7 +261,8 @@ while (($hdr, $lib) = each %libinc) | |||
191 | if($1 eq "R") { | 261 | if($1 eq "R") { |
192 | $rcodes{$name} = $code; | 262 | $rcodes{$name} = $code; |
193 | if ($rassigned{$lib} =~ /:$code:/) { | 263 | if ($rassigned{$lib} =~ /:$code:/) { |
194 | print STDERR "!! ERROR: $lib reason code $code assigned twice\n"; | 264 | print STDERR "!! ERROR: $lib reason code $code assigned twice (collision at $name)\n"; |
265 | ++$errcount; | ||
195 | } | 266 | } |
196 | $rassigned{$lib} .= "$code:"; | 267 | $rassigned{$lib} .= "$code:"; |
197 | if(!(exists $rextra{$name}) && | 268 | if(!(exists $rextra{$name}) && |
@@ -200,7 +271,8 @@ while (($hdr, $lib) = each %libinc) | |||
200 | } | 271 | } |
201 | } else { | 272 | } else { |
202 | if ($fassigned{$lib} =~ /:$code:/) { | 273 | if ($fassigned{$lib} =~ /:$code:/) { |
203 | print STDERR "!! ERROR: $lib function code $code assigned twice\n"; | 274 | print STDERR "!! ERROR: $lib function code $code assigned twice (collision at $name)\n"; |
275 | ++$errcount; | ||
204 | } | 276 | } |
205 | $fassigned{$lib} .= "$code:"; | 277 | $fassigned{$lib} .= "$code:"; |
206 | if($code > $fmax{$lib}) { | 278 | if($code > $fmax{$lib}) { |
@@ -231,6 +303,7 @@ while (($hdr, $lib) = each %libinc) | |||
231 | if ($rmax{$lib} >= 1000) { | 303 | if ($rmax{$lib} >= 1000) { |
232 | print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n"; | 304 | print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n"; |
233 | print STDERR "!! Any new alerts must be added to $config.\n"; | 305 | print STDERR "!! Any new alerts must be added to $config.\n"; |
306 | ++$errcount; | ||
234 | print STDERR "\n"; | 307 | print STDERR "\n"; |
235 | } | 308 | } |
236 | } | 309 | } |
@@ -255,6 +328,9 @@ foreach $file (@source) { | |||
255 | print STDERR "File loaded: ".$file."\r" if $debug; | 328 | print STDERR "File loaded: ".$file."\r" if $debug; |
256 | open(IN, "<$file") || die "Can't open source file $file\n"; | 329 | open(IN, "<$file") || die "Can't open source file $file\n"; |
257 | while(<IN>) { | 330 | while(<IN>) { |
331 | # skip obsoleted source files entirely! | ||
332 | last if(/^#error\s+obsolete/); | ||
333 | |||
258 | if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { | 334 | if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { |
259 | next unless exists $csrc{$2}; | 335 | next unless exists $csrc{$2}; |
260 | next if($1 eq "BIO_F_BUFFER_CTX"); | 336 | next if($1 eq "BIO_F_BUFFER_CTX"); |
@@ -264,6 +340,7 @@ foreach $file (@source) { | |||
264 | $fnew{$2}++; | 340 | $fnew{$2}++; |
265 | } | 341 | } |
266 | $notrans{$1} = 1 unless exists $ftrans{$3}; | 342 | $notrans{$1} = 1 unless exists $ftrans{$3}; |
343 | print STDERR "Function: $1\t= $fcodes{$1} (lib: $2, name: $3)\n" if $debug; | ||
267 | } | 344 | } |
268 | if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) { | 345 | if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) { |
269 | next unless exists $csrc{$2}; | 346 | next unless exists $csrc{$2}; |
@@ -272,6 +349,7 @@ foreach $file (@source) { | |||
272 | $rcodes{$1} = "X"; | 349 | $rcodes{$1} = "X"; |
273 | $rnew{$2}++; | 350 | $rnew{$2}++; |
274 | } | 351 | } |
352 | print STDERR "Reason: $1\t= $rcodes{$1} (lib: $2)\n" if $debug; | ||
275 | } | 353 | } |
276 | } | 354 | } |
277 | close IN; | 355 | close IN; |
@@ -313,7 +391,7 @@ foreach $lib (keys %csrc) | |||
313 | } else { | 391 | } else { |
314 | push @out, | 392 | push @out, |
315 | "/* ====================================================================\n", | 393 | "/* ====================================================================\n", |
316 | " * Copyright (c) 2001-2008 The OpenSSL Project. All rights reserved.\n", | 394 | " * Copyright (c) 2001-2010 The OpenSSL Project. All rights reserved.\n", |
317 | " *\n", | 395 | " *\n", |
318 | " * Redistribution and use in source and binary forms, with or without\n", | 396 | " * Redistribution and use in source and binary forms, with or without\n", |
319 | " * modification, are permitted provided that the following conditions\n", | 397 | " * modification, are permitted provided that the following conditions\n", |
@@ -369,6 +447,10 @@ foreach $lib (keys %csrc) | |||
369 | "#ifndef HEADER_${lib}_ERR_H\n", | 447 | "#ifndef HEADER_${lib}_ERR_H\n", |
370 | "#define HEADER_${lib}_ERR_H\n", | 448 | "#define HEADER_${lib}_ERR_H\n", |
371 | "\n", | 449 | "\n", |
450 | "#ifdef __cplusplus\n", | ||
451 | "extern \"C\" {\n", | ||
452 | "#endif\n", | ||
453 | "\n", | ||
372 | "/* BEGIN ERROR CODES */\n"; | 454 | "/* BEGIN ERROR CODES */\n"; |
373 | } | 455 | } |
374 | open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n"; | 456 | open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n"; |
@@ -455,14 +537,21 @@ EOF | |||
455 | if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) { | 537 | if (/\b(${lib}_R_\w*)\b.*\"(.*)\"/) { |
456 | $err_reason_strings{$1} = $2; | 538 | $err_reason_strings{$1} = $2; |
457 | } | 539 | } |
540 | if (/\b${lib}_F_(\w*)\b.*\"(.*)\"/) { | ||
541 | if (!exists $ftrans{$1} && ($1 ne $2)) { | ||
542 | print STDERR "WARNING: Mismatched function string $2\n"; | ||
543 | $ftrans{$1} = $2; | ||
544 | } | ||
545 | } | ||
458 | } | 546 | } |
459 | close(IN); | 547 | close(IN); |
460 | } | 548 | } |
461 | 549 | ||
550 | |||
462 | my $hincf; | 551 | my $hincf; |
463 | if($static) { | 552 | if($static) { |
464 | $hfile =~ /([^\/]+)$/; | 553 | $hfile =~ /([^\/]+)$/; |
465 | $hincf = "<openssl/$1>"; | 554 | $hincf = "<${hprefix}$1>"; |
466 | } else { | 555 | } else { |
467 | $hincf = "\"$hfile\""; | 556 | $hincf = "\"$hfile\""; |
468 | } | 557 | } |
@@ -487,7 +576,7 @@ EOF | |||
487 | print OUT <<"EOF"; | 576 | print OUT <<"EOF"; |
488 | /* $cfile */ | 577 | /* $cfile */ |
489 | /* ==================================================================== | 578 | /* ==================================================================== |
490 | * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. | 579 | * Copyright (c) 1999-2010 The OpenSSL Project. All rights reserved. |
491 | * | 580 | * |
492 | * Redistribution and use in source and binary forms, with or without | 581 | * Redistribution and use in source and binary forms, with or without |
493 | * modification, are permitted provided that the following conditions | 582 | * modification, are permitted provided that the following conditions |
@@ -713,3 +802,9 @@ if($debug && defined(@runref) ) { | |||
713 | print STDERR "$_\n"; | 802 | print STDERR "$_\n"; |
714 | } | 803 | } |
715 | } | 804 | } |
805 | |||
806 | if($errcount) { | ||
807 | print STDERR "There were errors, failing...\n\n"; | ||
808 | exit $errcount; | ||
809 | } | ||
810 | |||