gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

mkerrors.sh (19930B)


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