17c478bd9Sstevel@tonic-gate# 27c478bd9Sstevel@tonic-gate# CDDL HEADER START 37c478bd9Sstevel@tonic-gate# 47c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 57257d1b4Sraf# Common Development and Distribution License (the "License"). 67257d1b4Sraf# You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate# 87c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate# and limitations under the License. 127c478bd9Sstevel@tonic-gate# 137c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate# 197c478bd9Sstevel@tonic-gate# CDDL HEADER END 207c478bd9Sstevel@tonic-gate# 217257d1b4Sraf# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 227257d1b4Sraf# Use is subject to license terms. 237257d1b4Sraf# 24*faadcf7eSRobert Mustacchi# Copyright 2024 Oxide Computer Company 25*faadcf7eSRobert Mustacchi# 267c478bd9Sstevel@tonic-gate# Create two files from a list of input strings; 277c478bd9Sstevel@tonic-gate# new_list.c contains an array of characters indexed into by perror and 28*faadcf7eSRobert Mustacchi# strerror and an array of strings for strerrorname_np; 297c478bd9Sstevel@tonic-gate# errlst.c contains an array of pointers to strings for compatibility 307c478bd9Sstevel@tonic-gate# with existing user programs that reference it directly; 317c478bd9Sstevel@tonic-gate# errlst.c references the strings in new_list.c indirectly using a library 327c478bd9Sstevel@tonic-gate# private symbol, __sys_errs[], in order to get relative relocations. 337c478bd9Sstevel@tonic-gate# 347c478bd9Sstevel@tonic-gate# Since the 64 bit ABI doesn't define the old symbols, the second file 357c478bd9Sstevel@tonic-gate# should be left out 64 bit libraries. 367c478bd9Sstevel@tonic-gate# 377c478bd9Sstevel@tonic-gate# WARNING! 387c478bd9Sstevel@tonic-gate# Do NOT add entries to this list such that it grows the list 397c478bd9Sstevel@tonic-gate# beyond the last entry: 407c478bd9Sstevel@tonic-gate# 151 Stale NFS file handle 417c478bd9Sstevel@tonic-gate# Growing this list may damage programs because this array is 427c478bd9Sstevel@tonic-gate# copied into a reserved array at runtime. See bug 4097669. 437c478bd9Sstevel@tonic-gate# 447c478bd9Sstevel@tonic-gate# If you need to add an entry please use one of the empty 457c478bd9Sstevel@tonic-gate# slots. 467c478bd9Sstevel@tonic-gate# The arrays _sys_errs[], accessible via perror(3C) and strerror(3C) 477c478bd9Sstevel@tonic-gate# interfaces, and sys_errlist[] are created from this list. 487c478bd9Sstevel@tonic-gate# It is the direct referencing of sys_errlist[] that is the problem. 497c478bd9Sstevel@tonic-gate# Your code should only use perror() or strerror(). 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gateBEGIN { 537c478bd9Sstevel@tonic-gate FS = "\t" 547c478bd9Sstevel@tonic-gate hi = 0 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate newfile = "new_list.c" 577c478bd9Sstevel@tonic-gate oldfile = "errlst.c" 587c478bd9Sstevel@tonic-gate 597257d1b4Sraf print "#pragma weak _sys_errlist = sys_errlist\n" >oldfile 607257d1b4Sraf print "#include \"lint.h\"\n" >oldfile 617c478bd9Sstevel@tonic-gate # We need to include the errors strings proper in the 627c478bd9Sstevel@tonic-gate # C source for gettext; the macro C allows us to embed 637c478bd9Sstevel@tonic-gate # them as comment. 647c478bd9Sstevel@tonic-gate print "#define\tC(x)\n" >oldfile 657c478bd9Sstevel@tonic-gate print "extern const char __sys_errs[];\n" >oldfile 667c478bd9Sstevel@tonic-gate print "const char *sys_errlist[] = {" >oldfile 677c478bd9Sstevel@tonic-gate 687257d1b4Sraf print "#include \"lint.h\"" >newfile 697c478bd9Sstevel@tonic-gate print "#include <sys/isa_defs.h>\n" >newfile 70*faadcf7eSRobert Mustacchi print "#include <errno.h>\n" >newfile 717c478bd9Sstevel@tonic-gate print "#pragma weak __sys_errs = _sys_errs\n" >newfile 727c478bd9Sstevel@tonic-gate } 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate/^[0-9]+/ { 757c478bd9Sstevel@tonic-gate if ($1 > hi) 767c478bd9Sstevel@tonic-gate hi = $1 77*faadcf7eSRobert Mustacchi aname[$1] = $2 78*faadcf7eSRobert Mustacchi astr[$1] = $3 797c478bd9Sstevel@tonic-gate } 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gateEND { 827c478bd9Sstevel@tonic-gate print "const int _sys_index[] =\n{" >newfile 837c478bd9Sstevel@tonic-gate k = 0 847c478bd9Sstevel@tonic-gate mx = 151 # max number of entries for sys_errlist[] 857c478bd9Sstevel@tonic-gate if (hi > mx) 867c478bd9Sstevel@tonic-gate { 877c478bd9Sstevel@tonic-gate printf "awk: ERROR! sys_errlist[] > %d entries\n", mx 887c478bd9Sstevel@tonic-gate printf "Please read comments in" 897c478bd9Sstevel@tonic-gate printf " usr/src/lib/libc/port/gen/errlist\n" 907c478bd9Sstevel@tonic-gate exit 1 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate for (j = 0; j <= hi; ++j) 937c478bd9Sstevel@tonic-gate { 947c478bd9Sstevel@tonic-gate if (astr[j] == "") 957c478bd9Sstevel@tonic-gate astr[j] = sprintf("Error %d", j) 967c478bd9Sstevel@tonic-gate printf "\t%d,\n", k >newfile 977c478bd9Sstevel@tonic-gate printf "\t&__sys_errs[%d], C(\"%s\")\n", k, astr[j] \ 987c478bd9Sstevel@tonic-gate >oldfile 997c478bd9Sstevel@tonic-gate k += length(astr[j]) + 1 1007c478bd9Sstevel@tonic-gate } 1017c478bd9Sstevel@tonic-gate print "};\n" >newfile 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate print "/* This is one long string */" >newfile 1047c478bd9Sstevel@tonic-gate printf "const char _sys_errs[%d] =\n", k >newfile 1057c478bd9Sstevel@tonic-gate for (j = 0; j <= hi; ++j) 1067c478bd9Sstevel@tonic-gate { 1077c478bd9Sstevel@tonic-gate printf "\t\"%s\\0\"\n", astr[j] >newfile 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate print ";\n" >newfile 1107c478bd9Sstevel@tonic-gate print "};\n" >oldfile 1117c478bd9Sstevel@tonic-gate 112*faadcf7eSRobert Mustacchi # 113*faadcf7eSRobert Mustacchi # This stanza is used to generate the array of names for mapping 114*faadcf7eSRobert Mustacchi # an errno to its constant (e.g. "ENOENT"). 115*faadcf7eSRobert Mustacchi # 116*faadcf7eSRobert Mustacchi printf "const char *_sys_err_names[%d] = {\n", hi + 1 >newfile 117*faadcf7eSRobert Mustacchi printf "\t[0] = \"0\",\n" >newfile 118*faadcf7eSRobert Mustacchi for (j = 1; j <= hi; ++j) 119*faadcf7eSRobert Mustacchi { 120*faadcf7eSRobert Mustacchi if (aname[j] != "" && aname[j] != "SKIP") 121*faadcf7eSRobert Mustacchi printf "\t[%s] = \"%s\",\n", aname[j], aname[j] \ 122*faadcf7eSRobert Mustacchi >newfile 123*faadcf7eSRobert Mustacchi } 124*faadcf7eSRobert Mustacchi print "};\n" > newfile 125*faadcf7eSRobert Mustacchi 1267c478bd9Sstevel@tonic-gate print "const int _sys_num_err = " hi + 1 ";\n" >newfile 1277c478bd9Sstevel@tonic-gate print "#undef sys_nerr" >newfile 1287c478bd9Sstevel@tonic-gate print "#ifndef _LP64" >newfile 1297c478bd9Sstevel@tonic-gate print "#pragma weak _sys_nerr = _sys_num_err" >newfile 1307c478bd9Sstevel@tonic-gate print "#pragma weak sys_nerr = _sys_num_err" >newfile 1317c478bd9Sstevel@tonic-gate print "#endif /* _LP64 */" >newfile 1327c478bd9Sstevel@tonic-gate } 133