usb-ks

USB Killswitch
git clone git://git.laack.co/usb-ks.git
Log | Files | Refs | README | LICENSE

mkerrors.sh (19676B)


      1 #!/usr/bin/env bash
      2 # Copyright 2009 The Go Authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style
      4 # license that can be found in the LICENSE file.
      5 
      6 # Generate Go code listing errors and other #defined constant
      7 # values (ENAMETOOLONG etc.), by asking the preprocessor
      8 # about the definitions.
      9 
     10 unset LANG
     11 export LC_ALL=C
     12 export LC_CTYPE=C
     13 
     14 if test -z "$GOARCH" -o -z "$GOOS"; then
     15 	echo 1>&2 "GOARCH or GOOS not defined in environment"
     16 	exit 1
     17 fi
     18 
     19 # Check that we are using the new build system if we should
     20 if [[ "$GOOS" = "linux" ]] && [[ "$GOLANG_SYS_BUILD" != "docker" ]]; then
     21 	echo 1>&2 "In the Docker based build system, mkerrors should not be called directly."
     22 	echo 1>&2 "See README.md"
     23 	exit 1
     24 fi
     25 
     26 if [[ "$GOOS" = "aix" ]]; then
     27 	CC=${CC:-gcc}
     28 else
     29 	CC=${CC:-cc}
     30 fi
     31 
     32 if [[ "$GOOS" = "solaris" ]]; then
     33 	# Assumes GNU versions of utilities in PATH.
     34 	export PATH=/usr/gnu/bin:$PATH
     35 fi
     36 
     37 uname=$(uname)
     38 
     39 includes_AIX='
     40 #include <net/if.h>
     41 #include <net/netopt.h>
     42 #include <netinet/ip_mroute.h>
     43 #include <sys/protosw.h>
     44 #include <sys/stropts.h>
     45 #include <sys/mman.h>
     46 #include <sys/poll.h>
     47 #include <sys/select.h>
     48 #include <sys/termio.h>
     49 #include <termios.h>
     50 #include <fcntl.h>
     51 
     52 #define AF_LOCAL AF_UNIX
     53 '
     54 
     55 includes_Darwin='
     56 #define _DARWIN_C_SOURCE
     57 #define KERNEL 1
     58 #define _DARWIN_USE_64_BIT_INODE
     59 #define __APPLE_USE_RFC_3542
     60 #include <stdint.h>
     61 #include <sys/attr.h>
     62 #include <sys/clonefile.h>
     63 #include <sys/kern_control.h>
     64 #include <sys/types.h>
     65 #include <sys/event.h>
     66 #include <sys/ptrace.h>
     67 #include <sys/select.h>
     68 #include <sys/socket.h>
     69 #include <sys/un.h>
     70 #include <sys/sockio.h>
     71 #include <sys/sys_domain.h>
     72 #include <sys/sysctl.h>
     73 #include <sys/mman.h>
     74 #include <sys/mount.h>
     75 #include <sys/utsname.h>
     76 #include <sys/wait.h>
     77 #include <sys/xattr.h>
     78 #include <sys/vsock.h>
     79 #include <net/bpf.h>
     80 #include <net/if.h>
     81 #include <net/if_types.h>
     82 #include <net/route.h>
     83 #include <netinet/in.h>
     84 #include <netinet/ip.h>
     85 #include <termios.h>
     86 
     87 // for backwards compatibility because moved TIOCREMOTE to Kernel.framework after MacOSX12.0.sdk.
     88 #define TIOCREMOTE 0x80047469
     89 '
     90 
     91 includes_DragonFly='
     92 #include <sys/types.h>
     93 #include <sys/event.h>
     94 #include <sys/select.h>
     95 #include <sys/socket.h>
     96 #include <sys/sockio.h>
     97 #include <sys/stat.h>
     98 #include <sys/sysctl.h>
     99 #include <sys/mman.h>
    100 #include <sys/mount.h>
    101 #include <sys/wait.h>
    102 #include <sys/ioctl.h>
    103 #include <net/bpf.h>
    104 #include <net/if.h>
    105 #include <net/if_clone.h>
    106 #include <net/if_types.h>
    107 #include <net/route.h>
    108 #include <netinet/in.h>
    109 #include <termios.h>
    110 #include <netinet/ip.h>
    111 #include <net/ip_mroute/ip_mroute.h>
    112 '
    113 
    114 includes_FreeBSD='
    115 #include <sys/capsicum.h>
    116 #include <sys/param.h>
    117 #include <sys/types.h>
    118 #include <sys/disk.h>
    119 #include <sys/event.h>
    120 #include <sys/sched.h>
    121 #include <sys/select.h>
    122 #include <sys/socket.h>
    123 #include <sys/un.h>
    124 #include <sys/sockio.h>
    125 #include <sys/stat.h>
    126 #include <sys/sysctl.h>
    127 #include <sys/mman.h>
    128 #include <sys/mount.h>
    129 #include <sys/wait.h>
    130 #include <sys/ioctl.h>
    131 #include <net/bpf.h>
    132 #include <net/if.h>
    133 #include <net/if_types.h>
    134 #include <net/route.h>
    135 #include <netinet/in.h>
    136 #include <termios.h>
    137 #include <netinet/ip.h>
    138 #include <netinet/ip_mroute.h>
    139 #include <sys/extattr.h>
    140 
    141 #if __FreeBSD__ >= 10
    142 #define IFT_CARP	0xf8	// IFT_CARP is deprecated in FreeBSD 10
    143 #undef SIOCAIFADDR
    144 #define SIOCAIFADDR	_IOW(105, 26, struct oifaliasreq)	// ifaliasreq contains if_data
    145 #undef SIOCSIFPHYADDR
    146 #define SIOCSIFPHYADDR	_IOW(105, 70, struct oifaliasreq)	// ifaliasreq contains if_data
    147 #endif
    148 '
    149 
    150 includes_Linux='
    151 #define _LARGEFILE_SOURCE
    152 #define _LARGEFILE64_SOURCE
    153 #ifndef __LP64__
    154 #define _FILE_OFFSET_BITS 64
    155 #endif
    156 #define _GNU_SOURCE
    157 
    158 // <sys/ioctl.h> is broken on powerpc64, as it fails to include definitions of
    159 // these structures. We just include them copied from <bits/termios.h>.
    160 #if defined(__powerpc__)
    161 struct sgttyb {
    162         char    sg_ispeed;
    163         char    sg_ospeed;
    164         char    sg_erase;
    165         char    sg_kill;
    166         short   sg_flags;
    167 };
    168 
    169 struct tchars {
    170         char    t_intrc;
    171         char    t_quitc;
    172         char    t_startc;
    173         char    t_stopc;
    174         char    t_eofc;
    175         char    t_brkc;
    176 };
    177 
    178 struct ltchars {
    179         char    t_suspc;
    180         char    t_dsuspc;
    181         char    t_rprntc;
    182         char    t_flushc;
    183         char    t_werasc;
    184         char    t_lnextc;
    185 };
    186 #endif
    187 
    188 #include <bits/sockaddr.h>
    189 #include <sys/epoll.h>
    190 #include <sys/eventfd.h>
    191 #include <sys/inotify.h>
    192 #include <sys/ioctl.h>
    193 #include <sys/mman.h>
    194 #include <sys/mount.h>
    195 #include <sys/prctl.h>
    196 #include <sys/stat.h>
    197 #include <sys/types.h>
    198 #include <sys/time.h>
    199 #include <sys/select.h>
    200 #include <sys/signalfd.h>
    201 #include <sys/socket.h>
    202 #include <sys/timerfd.h>
    203 #include <sys/uio.h>
    204 #include <sys/xattr.h>
    205 #include <linux/bpf.h>
    206 #include <linux/can.h>
    207 #include <linux/can/error.h>
    208 #include <linux/can/netlink.h>
    209 #include <linux/can/raw.h>
    210 #include <linux/capability.h>
    211 #include <linux/cryptouser.h>
    212 #include <linux/devlink.h>
    213 #include <linux/dm-ioctl.h>
    214 #include <linux/errqueue.h>
    215 #include <linux/ethtool_netlink.h>
    216 #include <linux/falloc.h>
    217 #include <linux/fanotify.h>
    218 #include <linux/fib_rules.h>
    219 #include <linux/filter.h>
    220 #include <linux/fs.h>
    221 #include <linux/fscrypt.h>
    222 #include <linux/fsverity.h>
    223 #include <linux/genetlink.h>
    224 #include <linux/hdreg.h>
    225 #include <linux/hidraw.h>
    226 #include <linux/if.h>
    227 #include <linux/if_addr.h>
    228 #include <linux/if_alg.h>
    229 #include <linux/if_arp.h>
    230 #include <linux/if_ether.h>
    231 #include <linux/if_ppp.h>
    232 #include <linux/if_tun.h>
    233 #include <linux/if_packet.h>
    234 #include <linux/if_xdp.h>
    235 #include <linux/input.h>
    236 #include <linux/kcm.h>
    237 #include <linux/kexec.h>
    238 #include <linux/keyctl.h>
    239 #include <linux/landlock.h>
    240 #include <linux/loop.h>
    241 #include <linux/lwtunnel.h>
    242 #include <linux/magic.h>
    243 #include <linux/memfd.h>
    244 #include <linux/module.h>
    245 #include <linux/mount.h>
    246 #include <linux/netfilter/nfnetlink.h>
    247 #include <linux/netlink.h>
    248 #include <linux/net_namespace.h>
    249 #include <linux/nfc.h>
    250 #include <linux/nsfs.h>
    251 #include <linux/perf_event.h>
    252 #include <linux/pps.h>
    253 #include <linux/ptrace.h>
    254 #include <linux/random.h>
    255 #include <linux/reboot.h>
    256 #include <linux/rtc.h>
    257 #include <linux/rtnetlink.h>
    258 #include <linux/sched.h>
    259 #include <linux/seccomp.h>
    260 #include <linux/serial.h>
    261 #include <linux/sockios.h>
    262 #include <linux/taskstats.h>
    263 #include <linux/tipc.h>
    264 #include <linux/vm_sockets.h>
    265 #include <linux/wait.h>
    266 #include <linux/watchdog.h>
    267 #include <linux/wireguard.h>
    268 
    269 #include <mtd/ubi-user.h>
    270 #include <mtd/mtd-user.h>
    271 #include <net/route.h>
    272 
    273 #if defined(__sparc__)
    274 // On sparc{,64}, the kernel defines struct termios2 itself which clashes with the
    275 // definition in glibc. As only the error constants are needed here, include the
    276 // generic termibits.h (which is included by termbits.h on sparc).
    277 #include <asm-generic/termbits.h>
    278 #else
    279 #include <asm/termbits.h>
    280 #endif
    281 
    282 #ifndef MSG_FASTOPEN
    283 #define MSG_FASTOPEN    0x20000000
    284 #endif
    285 
    286 #ifndef PTRACE_GETREGS
    287 #define PTRACE_GETREGS	0xc
    288 #endif
    289 
    290 #ifndef PTRACE_SETREGS
    291 #define PTRACE_SETREGS	0xd
    292 #endif
    293 
    294 #ifndef SOL_NETLINK
    295 #define SOL_NETLINK	270
    296 #endif
    297 
    298 #ifdef SOL_BLUETOOTH
    299 // SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h
    300 // but it is already in bluetooth_linux.go
    301 #undef SOL_BLUETOOTH
    302 #endif
    303 
    304 // Certain constants are missing from the fs/crypto UAPI
    305 #define FS_KEY_DESC_PREFIX              "fscrypt:"
    306 #define FS_KEY_DESC_PREFIX_SIZE         8
    307 #define FS_MAX_KEY_SIZE                 64
    308 
    309 // The code generator produces -0x1 for (~0), but an unsigned value is necessary
    310 // for the tipc_subscr timeout __u32 field.
    311 #undef TIPC_WAIT_FOREVER
    312 #define TIPC_WAIT_FOREVER 0xffffffff
    313 
    314 // Copied from linux/l2tp.h
    315 // Including linux/l2tp.h here causes conflicts between linux/in.h
    316 // and netinet/in.h included via net/route.h above.
    317 #define IPPROTO_L2TP		115
    318 
    319 // Copied from linux/hid.h.
    320 // Keep in sync with the size of the referenced fields.
    321 #define _HIDIOCGRAWNAME_LEN	128 // sizeof_field(struct hid_device, name)
    322 #define _HIDIOCGRAWPHYS_LEN	64  // sizeof_field(struct hid_device, phys)
    323 #define _HIDIOCGRAWUNIQ_LEN	64  // sizeof_field(struct hid_device, uniq)
    324 
    325 #define _HIDIOCGRAWNAME		HIDIOCGRAWNAME(_HIDIOCGRAWNAME_LEN)
    326 #define _HIDIOCGRAWPHYS		HIDIOCGRAWPHYS(_HIDIOCGRAWPHYS_LEN)
    327 #define _HIDIOCGRAWUNIQ		HIDIOCGRAWUNIQ(_HIDIOCGRAWUNIQ_LEN)
    328 
    329 '
    330 
    331 includes_NetBSD='
    332 #include <sys/types.h>
    333 #include <sys/param.h>
    334 #include <sys/event.h>
    335 #include <sys/extattr.h>
    336 #include <sys/mman.h>
    337 #include <sys/mount.h>
    338 #include <sys/sched.h>
    339 #include <sys/select.h>
    340 #include <sys/socket.h>
    341 #include <sys/sockio.h>
    342 #include <sys/sysctl.h>
    343 #include <sys/termios.h>
    344 #include <sys/ttycom.h>
    345 #include <sys/wait.h>
    346 #include <net/bpf.h>
    347 #include <net/if.h>
    348 #include <net/if_types.h>
    349 #include <net/route.h>
    350 #include <netinet/in.h>
    351 #include <netinet/in_systm.h>
    352 #include <netinet/ip.h>
    353 #include <netinet/ip_mroute.h>
    354 #include <netinet/if_ether.h>
    355 
    356 // Needed since <sys/param.h> refers to it...
    357 #define schedppq 1
    358 '
    359 
    360 includes_OpenBSD='
    361 #include <sys/types.h>
    362 #include <sys/param.h>
    363 #include <sys/event.h>
    364 #include <sys/mman.h>
    365 #include <sys/mount.h>
    366 #include <sys/select.h>
    367 #include <sys/sched.h>
    368 #include <sys/socket.h>
    369 #include <sys/sockio.h>
    370 #include <sys/stat.h>
    371 #include <sys/sysctl.h>
    372 #include <sys/termios.h>
    373 #include <sys/ttycom.h>
    374 #include <sys/unistd.h>
    375 #include <sys/wait.h>
    376 #include <net/bpf.h>
    377 #include <net/if.h>
    378 #include <net/if_types.h>
    379 #include <net/if_var.h>
    380 #include <net/route.h>
    381 #include <netinet/in.h>
    382 #include <netinet/in_systm.h>
    383 #include <netinet/ip.h>
    384 #include <netinet/ip_mroute.h>
    385 #include <netinet/if_ether.h>
    386 #include <net/if_bridge.h>
    387 
    388 // We keep some constants not supported in OpenBSD 5.5 and beyond for
    389 // the promise of compatibility.
    390 #define EMUL_ENABLED		0x1
    391 #define EMUL_NATIVE		0x2
    392 #define IPV6_FAITH		0x1d
    393 #define IPV6_OPTIONS		0x1
    394 #define IPV6_RTHDR_STRICT	0x1
    395 #define IPV6_SOCKOPT_RESERVED1	0x3
    396 #define SIOCGIFGENERIC		0xc020693a
    397 #define SIOCSIFGENERIC		0x80206939
    398 #define WALTSIG			0x4
    399 '
    400 
    401 includes_SunOS='
    402 #include <limits.h>
    403 #include <sys/types.h>
    404 #include <sys/select.h>
    405 #include <sys/socket.h>
    406 #include <sys/sockio.h>
    407 #include <sys/stat.h>
    408 #include <sys/stream.h>
    409 #include <sys/mman.h>
    410 #include <sys/wait.h>
    411 #include <sys/ioctl.h>
    412 #include <sys/mkdev.h>
    413 #include <net/bpf.h>
    414 #include <net/if.h>
    415 #include <net/if_arp.h>
    416 #include <net/if_types.h>
    417 #include <net/route.h>
    418 #include <netinet/icmp6.h>
    419 #include <netinet/in.h>
    420 #include <netinet/ip.h>
    421 #include <netinet/ip_mroute.h>
    422 #include <termios.h>
    423 '
    424 
    425 
    426 includes='
    427 #include <sys/types.h>
    428 #include <sys/file.h>
    429 #include <fcntl.h>
    430 #include <dirent.h>
    431 #include <sys/socket.h>
    432 #include <netinet/in.h>
    433 #include <netinet/ip.h>
    434 #include <netinet/ip6.h>
    435 #include <netinet/tcp.h>
    436 #include <errno.h>
    437 #include <sys/signal.h>
    438 #include <signal.h>
    439 #include <sys/resource.h>
    440 #include <time.h>
    441 '
    442 ccflags="$@"
    443 
    444 # Write go tool cgo -godefs input.
    445 (
    446 	echo package unix
    447 	echo
    448 	echo '/*'
    449 	indirect="includes_$(uname)"
    450 	echo "${!indirect} $includes"
    451 	echo '*/'
    452 	echo 'import "C"'
    453 	echo 'import "syscall"'
    454 	echo
    455 	echo 'const ('
    456 
    457 	# The gcc command line prints all the #defines
    458 	# it encounters while processing the input
    459 	echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags |
    460 	awk '
    461 		$1 != "#define" || $2 ~ /\(/ || $3 == "" {next}
    462 
    463 		$2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next}  # 386 registers
    464 		$2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next}
    465 		$2 ~ /^(SCM_SRCRT)$/ {next}
    466 		$2 ~ /^(MAP_FAILED)$/ {next}
    467 		$2 ~ /^ELF_.*$/ {next}# <asm/elf.h> contains ELF_ARCH, etc.
    468 
    469 		$2 ~ /^EXTATTR_NAMESPACE_NAMES/ ||
    470 		$2 ~ /^EXTATTR_NAMESPACE_[A-Z]+_STRING/ {next}
    471 
    472 		$2 !~ /^ECCAPBITS/ &&
    473 		$2 !~ /^ETH_/ &&
    474 		$2 !~ /^EPROC_/ &&
    475 		$2 !~ /^EQUIV_/ &&
    476 		$2 !~ /^EXPR_/ &&
    477 		$2 !~ /^EVIOC/ &&
    478 		$2 ~ /^E[A-Z0-9_]+$/ ||
    479 		$2 ~ /^B[0-9_]+$/ ||
    480 		$2 ~ /^(OLD|NEW)DEV$/ ||
    481 		$2 == "BOTHER" ||
    482 		$2 ~ /^CI?BAUD(EX)?$/ ||
    483 		$2 == "IBSHIFT" ||
    484 		$2 ~ /^V[A-Z0-9]+$/ ||
    485 		$2 ~ /^CS[A-Z0-9]/ ||
    486 		$2 ~ /^I(SIG|CANON|CRNL|UCLC|EXTEN|MAXBEL|STRIP|UTF8)$/ ||
    487 		$2 ~ /^IGN/ ||
    488 		$2 ~ /^IX(ON|ANY|OFF)$/ ||
    489 		$2 ~ /^IN(LCR|PCK)$/ ||
    490 		$2 !~ "X86_CR3_PCID_NOFLUSH" &&
    491 		$2 ~ /(^FLU?SH)|(FLU?SH$)/ ||
    492 		$2 ~ /^C(LOCAL|READ|MSPAR|RTSCTS)$/ ||
    493 		$2 == "BRKINT" ||
    494 		$2 == "HUPCL" ||
    495 		$2 == "PENDIN" ||
    496 		$2 == "TOSTOP" ||
    497 		$2 == "XCASE" ||
    498 		$2 == "ALTWERASE" ||
    499 		$2 == "NOKERNINFO" ||
    500 		$2 == "NFDBITS" ||
    501 		$2 ~ /^PAR/ ||
    502 		$2 ~ /^SIG[^_]/ ||
    503 		$2 ~ /^O[CNPFPL][A-Z]+[^_][A-Z]+$/ ||
    504 		$2 ~ /^(NL|CR|TAB|BS|VT|FF)DLY$/ ||
    505 		$2 ~ /^(NL|CR|TAB|BS|VT|FF)[0-9]$/ ||
    506 		$2 ~ /^O?XTABS$/ ||
    507 		$2 ~ /^TC[IO](ON|OFF)$/ ||
    508 		$2 ~ /^IN_/ ||
    509 		$2 ~ /^KCM/ ||
    510 		$2 ~ /^LANDLOCK_/ ||
    511 		$2 ~ /^LOCK_(SH|EX|NB|UN)$/ ||
    512 		$2 ~ /^LO_(KEY|NAME)_SIZE$/ ||
    513 		$2 ~ /^LOOP_(CLR|CTL|GET|SET)_/ ||
    514 		$2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL|TCPOPT)_/ ||
    515 		$2 ~ /^NFC_(GENL|PROTO|COMM|RF|SE|DIRECTION|LLCP|SOCKPROTO)_/ ||
    516 		$2 ~ /^NFC_.*_(MAX)?SIZE$/ ||
    517 		$2 ~ /^RAW_PAYLOAD_/ ||
    518 		$2 ~ /^TP_STATUS_/ ||
    519 		$2 ~ /^FALLOC_/ ||
    520 		$2 ~ /^ICMPV?6?_(FILTER|SEC)/ ||
    521 		$2 == "SOMAXCONN" ||
    522 		$2 == "NAME_MAX" ||
    523 		$2 == "IFNAMSIZ" ||
    524 		$2 ~ /^CTL_(HW|KERN|MAXNAME|NET|QUERY)$/ ||
    525 		$2 ~ /^KERN_(HOSTNAME|OS(RELEASE|TYPE)|VERSION)$/ ||
    526 		$2 ~ /^HW_MACHINE$/ ||
    527 		$2 ~ /^SYSCTL_VERS/ ||
    528 		$2 !~ "MNT_BITS" &&
    529 		$2 ~ /^(MS|MNT|MOUNT|UMOUNT)_/ ||
    530 		$2 ~ /^NS_GET_/ ||
    531 		$2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ ||
    532 		$2 ~ /^(O|F|[ES]?FD|NAME|S|PTRACE|PT|TFD)_/ ||
    533 		$2 ~ /^KEXEC_/ ||
    534 		$2 ~ /^LINUX_REBOOT_CMD_/ ||
    535 		$2 ~ /^LINUX_REBOOT_MAGIC[12]$/ ||
    536 		$2 ~ /^MODULE_INIT_/ ||
    537 		$2 !~ "NLA_TYPE_MASK" &&
    538 		$2 !~ /^RTC_VL_(ACCURACY|BACKUP|DATA)/ &&
    539 		$2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ ||
    540 		$2 ~ /^FIORDCHK$/ ||
    541 		$2 ~ /^SIOC/ ||
    542 		$2 ~ /^TIOC/ ||
    543 		$2 ~ /^TCGET/ ||
    544 		$2 ~ /^TCSET/ ||
    545 		$2 ~ /^TC(FLSH|SBRKP?|XONC)$/ ||
    546 		$2 !~ "RTF_BITS" &&
    547 		$2 ~ /^(IFF|IFT|NET_RT|RTM(GRP)?|RTF|RTV|RTA|RTAX)_/ ||
    548 		$2 ~ /^BIOC/ ||
    549 		$2 ~ /^DIOC/ ||
    550 		$2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ ||
    551 		$2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|LOCKS|MEMLOCK|MSGQUEUE|NICE|NOFILE|NPROC|RSS|RTPRIO|RTTIME|SIGPENDING|STACK)|RLIM_INFINITY/ ||
    552 		$2 ~ /^PRIO_(PROCESS|PGRP|USER)/ ||
    553 		$2 ~ /^CLONE_[A-Z_]+/ ||
    554 		$2 !~ /^(BPF_TIMEVAL|BPF_FIB_LOOKUP_[A-Z]+)$/ &&
    555 		$2 ~ /^(BPF|DLT)_/ ||
    556 		$2 ~ /^(CLOCK|TIMER)_/ ||
    557 		$2 ~ /^CAN_/ ||
    558 		$2 ~ /^CAP_/ ||
    559 		$2 ~ /^CP_/ ||
    560 		$2 ~ /^CPUSTATES$/ ||
    561 		$2 ~ /^CTLIOCGINFO$/ ||
    562 		$2 ~ /^ALG_/ ||
    563 		$2 ~ /^FI(CLONE|DEDUPERANGE)/ ||
    564 		$2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE)/ ||
    565 		$2 ~ /^FS_IOC_.*(ENCRYPTION|VERITY|[GS]ETFLAGS)/ ||
    566 		$2 ~ /^FS_VERITY_/ ||
    567 		$2 ~ /^FSCRYPT_/ ||
    568 		$2 ~ /^DM_/ ||
    569 		$2 ~ /^GRND_/ ||
    570 		$2 ~ /^RND/ ||
    571 		$2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ ||
    572 		$2 ~ /^KEYCTL_/ ||
    573 		$2 ~ /^PERF_/ ||
    574 		$2 ~ /^SECCOMP_MODE_/ ||
    575 		$2 ~ /^SEEK_/ ||
    576 		$2 ~ /^SPLICE_/ ||
    577 		$2 ~ /^SYNC_FILE_RANGE_/ ||
    578 		$2 !~ /^AUDIT_RECORD_MAGIC/ &&
    579 		$2 !~ /IOC_MAGIC/ &&
    580 		$2 ~ /^[A-Z][A-Z0-9_]+_MAGIC2?$/ ||
    581 		$2 ~ /^(VM|VMADDR)_/ ||
    582 		$2 ~ /^IOCTL_VM_SOCKETS_/ ||
    583 		$2 ~ /^(TASKSTATS|TS)_/ ||
    584 		$2 ~ /^CGROUPSTATS_/ ||
    585 		$2 ~ /^GENL_/ ||
    586 		$2 ~ /^STATX_/ ||
    587 		$2 ~ /^RENAME/ ||
    588 		$2 ~ /^UBI_IOC[A-Z]/ ||
    589 		$2 ~ /^UTIME_/ ||
    590 		$2 ~ /^XATTR_(CREATE|REPLACE|NO(DEFAULT|FOLLOW|SECURITY)|SHOWCOMPRESSION)/ ||
    591 		$2 ~ /^ATTR_(BIT_MAP_COUNT|(CMN|VOL|FILE)_)/ ||
    592 		$2 ~ /^FSOPT_/ ||
    593 		$2 ~ /^WDIO[CFS]_/ ||
    594 		$2 ~ /^NFN/ ||
    595 		$2 ~ /^XDP_/ ||
    596 		$2 ~ /^RWF_/ ||
    597 		$2 ~ /^(HDIO|WIN|SMART)_/ ||
    598 		$2 ~ /^CRYPTO_/ ||
    599 		$2 ~ /^TIPC_/ ||
    600 		$2 !~  "DEVLINK_RELOAD_LIMITS_VALID_MASK" &&
    601 		$2 ~ /^DEVLINK_/ ||
    602 		$2 ~ /^ETHTOOL_/ ||
    603 		$2 ~ /^LWTUNNEL_IP/ ||
    604 		$2 ~ /^ITIMER_/ ||
    605 		$2 !~ "WMESGLEN" &&
    606 		$2 ~ /^W[A-Z0-9]+$/ ||
    607 		$2 ~ /^P_/ ||
    608 		$2 ~/^PPPIOC/ ||
    609 		$2 ~ /^FAN_|FANOTIFY_/ ||
    610 		$2 == "HID_MAX_DESCRIPTOR_SIZE" ||
    611 		$2 ~ /^_?HIDIOC/ ||
    612 		$2 ~ /^BUS_(USB|HIL|BLUETOOTH|VIRTUAL)$/ ||
    613 		$2 ~ /^MTD/ ||
    614 		$2 ~ /^OTP/ ||
    615 		$2 ~ /^MEM/ ||
    616 		$2 ~ /^WG/ ||
    617 		$2 ~ /^FIB_RULE_/ ||
    618 		$2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE)/ {printf("\t%s = C.%s\n", $2, $2)}
    619 		$2 ~ /^__WCOREFLAG$/ {next}
    620 		$2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)}
    621 
    622 		{next}
    623 	' | sort
    624 
    625 	echo ')'
    626 ) >_const.go
    627 
    628 # Pull out the error names for later.
    629 errors=$(
    630 	echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
    631 	awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' |
    632 	sort
    633 )
    634 
    635 # Pull out the signal names for later.
    636 signals=$(
    637 	echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
    638 	awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' |
    639 	egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' |
    640 	sort
    641 )
    642 
    643 # Again, writing regexps to a file.
    644 echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
    645 	awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' |
    646 	sort >_error.grep
    647 echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
    648 	awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' |
    649 	egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' |
    650 	sort >_signal.grep
    651 
    652 echo '// mkerrors.sh' "$@"
    653 echo '// Code generated by the command above; see README.md. DO NOT EDIT.'
    654 echo
    655 echo "//go:build ${GOARCH} && ${GOOS}"
    656 echo "// +build ${GOARCH},${GOOS}"
    657 echo
    658 go tool cgo -godefs -- "$@" _const.go >_error.out
    659 cat _error.out | grep -vf _error.grep | grep -vf _signal.grep
    660 echo
    661 echo '// Errors'
    662 echo 'const ('
    663 cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/'
    664 echo ')'
    665 
    666 echo
    667 echo '// Signals'
    668 echo 'const ('
    669 cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/'
    670 echo ')'
    671 
    672 # Run C program to print error and syscall strings.
    673 (
    674 	echo -E "
    675 #include <stdio.h>
    676 #include <stdlib.h>
    677 #include <errno.h>
    678 #include <ctype.h>
    679 #include <string.h>
    680 #include <signal.h>
    681 
    682 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
    683 
    684 enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below
    685 
    686 struct tuple {
    687 	int num;
    688 	const char *name;
    689 };
    690 
    691 struct tuple errors[] = {
    692 "
    693 	for i in $errors
    694 	do
    695 		echo -E '	{'$i', "'$i'" },'
    696 	done
    697 
    698 	echo -E "
    699 };
    700 
    701 struct tuple signals[] = {
    702 "
    703 	for i in $signals
    704 	do
    705 		echo -E '	{'$i', "'$i'" },'
    706 	done
    707 
    708 	# Use -E because on some systems bash builtin interprets \n itself.
    709 	echo -E '
    710 };
    711 
    712 static int
    713 tuplecmp(const void *a, const void *b)
    714 {
    715 	return ((struct tuple *)a)->num - ((struct tuple *)b)->num;
    716 }
    717 
    718 int
    719 main(void)
    720 {
    721 	int i, e;
    722 	char buf[1024], *p;
    723 
    724 	printf("\n\n// Error table\n");
    725 	printf("var errorList = [...]struct {\n");
    726 	printf("\tnum  syscall.Errno\n");
    727 	printf("\tname string\n");
    728 	printf("\tdesc string\n");
    729 	printf("} {\n");
    730 	qsort(errors, nelem(errors), sizeof errors[0], tuplecmp);
    731 	for(i=0; i<nelem(errors); i++) {
    732 		e = errors[i].num;
    733 		if(i > 0 && errors[i-1].num == e)
    734 			continue;
    735 		strcpy(buf, strerror(e));
    736 		// lowercase first letter: Bad -> bad, but STREAM -> STREAM.
    737 		if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
    738 			buf[0] += a - A;
    739 		printf("\t{ %d, \"%s\", \"%s\" },\n", e, errors[i].name, buf);
    740 	}
    741 	printf("}\n\n");
    742 
    743 	printf("\n\n// Signal table\n");
    744 	printf("var signalList = [...]struct {\n");
    745 	printf("\tnum  syscall.Signal\n");
    746 	printf("\tname string\n");
    747 	printf("\tdesc string\n");
    748 	printf("} {\n");
    749 	qsort(signals, nelem(signals), sizeof signals[0], tuplecmp);
    750 	for(i=0; i<nelem(signals); i++) {
    751 		e = signals[i].num;
    752 		if(i > 0 && signals[i-1].num == e)
    753 			continue;
    754 		strcpy(buf, strsignal(e));
    755 		// lowercase first letter: Bad -> bad, but STREAM -> STREAM.
    756 		if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
    757 			buf[0] += a - A;
    758 		// cut trailing : number.
    759 		p = strrchr(buf, ":"[0]);
    760 		if(p)
    761 			*p = '\0';
    762 		printf("\t{ %d, \"%s\", \"%s\" },\n", e, signals[i].name, buf);
    763 	}
    764 	printf("}\n\n");
    765 
    766 	return 0;
    767 }
    768 
    769 '
    770 ) >_errors.c
    771 
    772 $CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out