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