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