~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/trace/beauty/arch_errno_names.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0
  3 #
  4 # Generate C file mapping errno codes to errno names.
  5 #
  6 # Copyright IBM Corp. 2018
  7 # Author(s):  Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
  8 
  9 gcc="$1"
 10 toolsdir="$2"
 11 include_path="-I$toolsdir/include/uapi"
 12 
 13 arch_string()
 14 {
 15         echo "$1" |sed -e 'y/- /__/' |tr '[[:upper:]]' '[[:lower:]]'
 16 }
 17 
 18 asm_errno_file()
 19 {
 20         arch="$1"
 21 
 22         header="$toolsdir/arch/$arch/include/uapi/asm/errno.h"
 23         if test -r "$header"; then
 24                 echo "$header"
 25         else
 26                 echo "$toolsdir/include/uapi/asm-generic/errno.h"
 27         fi
 28 }
 29 
 30 create_errno_lookup_func()
 31 {
 32         arch=$(arch_string "$1")
 33 
 34         printf "static const char *errno_to_name__%s(int err)\n{\n\tswitch (err) {\n" $arch
 35 
 36         while read name nr; do
 37                 printf '\tcase %d: return "%s";\n' $nr $name
 38         done
 39 
 40         printf '\tdefault: return "(unknown)";\n\t}\n}\n'
 41 }
 42 
 43 process_arch()
 44 {
 45         arch="$1"
 46         asm_errno=$(asm_errno_file "$arch")
 47 
 48         $gcc $CFLAGS $include_path -E -dM -x c $asm_errno \
 49                 |grep -hE '^#define[[:blank:]]+(E[^[:blank:]]+)[[:blank:]]+([[:digit:]]+).*' \
 50                 |awk '{ print $2","$3; }' \
 51                 |sort -t, -k2 -nu \
 52                 |IFS=, create_errno_lookup_func "$arch"
 53 }
 54 
 55 create_arch_errno_table_func()
 56 {
 57         archlist="$1"
 58         default="$2"
 59 
 60         printf 'arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *arch)\n'
 61         printf '{\n'
 62         for arch in $archlist; do
 63                 arch_str=$(arch_string "$arch")
 64                 printf '\tif (!strcmp(arch, "%s"))\n' "$arch_str"
 65                 printf '\t\treturn errno_to_name__%s;\n' "$arch_str"
 66         done
 67         arch_str=$(arch_string "$default")
 68         printf '\treturn errno_to_name__%s;\n' "$arch_str"
 69         printf '}\n'
 70 }
 71 
 72 cat <<EoHEADER
 73 /* SPDX-License-Identifier: GPL-2.0 */
 74 
 75 #include <string.h>
 76 
 77 EoHEADER
 78 
 79 # Create list of architectures that have a specific errno.h.
 80 archlist=""
 81 for f in $toolsdir/arch/*/include/uapi/asm/errno.h; do
 82         d=${f%/include/uapi/asm/errno.h}
 83         arch="${d##*/}"
 84         test -f $toolsdir/arch/$arch/include/uapi/asm/errno.h && archlist="$archlist $arch"
 85 done
 86 
 87 for arch in generic $archlist; do
 88         process_arch "$arch"
 89 done
 90 create_arch_errno_table_func "$archlist" "generic"

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php