1 # 2 # CDDL HEADER START 3 # 4 # The contents of this file are subject to the terms of the 5 # Common Development and Distribution License (the "License"). 6 # You may not use this file except in compliance with the License. 7 # 8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 # or http://www.opensolaris.org/os/licensing. 10 # See the License for the specific language governing permissions 11 # and limitations under the License. 12 # 13 # When distributing Covered Code, include this CDDL HEADER in each 14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 # If applicable, add the following below this CDDL HEADER, with the 16 # fields enclosed by brackets "[]" replaced with your own identifying 17 # information: Portions Copyright [yyyy] [name of copyright owner] 18 # 19 # CDDL HEADER END 20 # 21 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 22 # Use is subject to license terms. 23 # 24 # ident "%Z%%M% %I% %E% SMI" 25 # 26 # Create two files from a list of input strings; 27 # new_list.c contains an array of characters indexed into by perror and 28 # strerror; 29 # errlst.c contains an array of pointers to strings for compatibility 30 # with existing user programs that reference it directly; 31 # errlst.c references the strings in new_list.c indirectly using a library 32 # private symbol, __sys_errs[], in order to get relative relocations. 33 # 34 # Since the 64 bit ABI doesn't define the old symbols, the second file 35 # should be left out 64 bit libraries. 36 # 37 # WARNING! 38 # Do NOT add entries to this list such that it grows the list 39 # beyond the last entry: 40 # 151 Stale NFS file handle 41 # Growing this list may damage programs because this array is 42 # copied into a reserved array at runtime. See bug 4097669. 43 # 44 # If you need to add an entry please use one of the empty 45 # slots. 46 # The arrays _sys_errs[], accessible via perror(3C) and strerror(3C) 47 # interfaces, and sys_errlist[] are created from this list. 48 # It is the direct referencing of sys_errlist[] that is the problem. 49 # Your code should only use perror() or strerror(). 50 51 52 BEGIN { 53 FS = "\t" 54 hi = 0 55 56 newfile = "new_list.c" 57 oldfile = "errlst.c" 58 59 print "#pragma ident\t\"%Z%%M%\t%I%\t%E% SMI\"\n" >oldfile 60 print "#pragma weak _sys_errlist = sys_errlist\n" >oldfile 61 print "#include \"lint.h\"\n" >oldfile 62 # We need to include the errors strings proper in the 63 # C source for gettext; the macro C allows us to embed 64 # them as comment. 65 print "#define\tC(x)\n" >oldfile 66 print "extern const char __sys_errs[];\n" >oldfile 67 print "const char *sys_errlist[] = {" >oldfile 68 69 print "#pragma ident\t\"%Z%%M%\t%I%\t%E% SMI\"\n" >newfile 70 print "#include \"lint.h\"" >newfile 71 print "#include <sys/isa_defs.h>\n" >newfile 72 print "#pragma weak __sys_errs = _sys_errs\n" >newfile 73 } 74 75 /^[0-9]+/ { 76 if ($1 > hi) 77 hi = $1 78 astr[$1] = $2 79 } 80 81 END { 82 print "const int _sys_index[] =\n{" >newfile 83 k = 0 84 mx = 151 # max number of entries for sys_errlist[] 85 if (hi > mx) 86 { 87 printf "awk: ERROR! sys_errlist[] > %d entries\n", mx 88 printf "Please read comments in" 89 printf " usr/src/lib/libc/port/gen/errlist\n" 90 exit 1 91 } 92 for (j = 0; j <= hi; ++j) 93 { 94 if (astr[j] == "") 95 astr[j] = sprintf("Error %d", j) 96 printf "\t%d,\n", k >newfile 97 printf "\t&__sys_errs[%d], C(\"%s\")\n", k, astr[j] \ 98 >oldfile 99 k += length(astr[j]) + 1 100 } 101 print "};\n" >newfile 102 103 print "/* This is one long string */" >newfile 104 printf "const char _sys_errs[%d] =\n", k >newfile 105 for (j = 0; j <= hi; ++j) 106 { 107 printf "\t\"%s\\0\"\n", astr[j] >newfile 108 } 109 print ";\n" >newfile 110 print "};\n" >oldfile 111 112 print "const int _sys_num_err = " hi + 1 ";\n" >newfile 113 print "#undef sys_nerr" >newfile 114 print "#ifndef _LP64" >newfile 115 print "#pragma weak _sys_nerr = _sys_num_err" >newfile 116 print "#pragma weak sys_nerr = _sys_num_err" >newfile 117 print "#endif /* _LP64 */" >newfile 118 } 119