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