github.com/jgarto/itcv@v0.0.0-20180826224514-4eea09c1aa0d/_vendor/src/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 CC=${CC:-cc} 20 21 if [[ "$GOOS" -eq "solaris" ]]; then 22 # Assumes GNU versions of utilities in PATH. 23 export PATH=/usr/gnu/bin:$PATH 24 fi 25 26 uname=$(uname) 27 28 includes_Darwin=' 29 #define _DARWIN_C_SOURCE 30 #define KERNEL 31 #define _DARWIN_USE_64_BIT_INODE 32 #include <sys/types.h> 33 #include <sys/event.h> 34 #include <sys/ptrace.h> 35 #include <sys/socket.h> 36 #include <sys/sockio.h> 37 #include <sys/sysctl.h> 38 #include <sys/mman.h> 39 #include <sys/wait.h> 40 #include <net/bpf.h> 41 #include <net/if.h> 42 #include <net/if_types.h> 43 #include <net/route.h> 44 #include <netinet/in.h> 45 #include <netinet/ip.h> 46 #include <termios.h> 47 ' 48 49 includes_DragonFly=' 50 #include <sys/types.h> 51 #include <sys/event.h> 52 #include <sys/socket.h> 53 #include <sys/sockio.h> 54 #include <sys/sysctl.h> 55 #include <sys/mman.h> 56 #include <sys/wait.h> 57 #include <sys/ioctl.h> 58 #include <net/bpf.h> 59 #include <net/if.h> 60 #include <net/if_types.h> 61 #include <net/route.h> 62 #include <netinet/in.h> 63 #include <termios.h> 64 #include <netinet/ip.h> 65 #include <net/ip_mroute/ip_mroute.h> 66 ' 67 68 includes_FreeBSD=' 69 #include <sys/param.h> 70 #include <sys/types.h> 71 #include <sys/event.h> 72 #include <sys/socket.h> 73 #include <sys/sockio.h> 74 #include <sys/sysctl.h> 75 #include <sys/mman.h> 76 #include <sys/wait.h> 77 #include <sys/ioctl.h> 78 #include <net/bpf.h> 79 #include <net/if.h> 80 #include <net/if_types.h> 81 #include <net/route.h> 82 #include <netinet/in.h> 83 #include <termios.h> 84 #include <netinet/ip.h> 85 #include <netinet/ip_mroute.h> 86 #include <sys/extattr.h> 87 88 #if __FreeBSD__ >= 10 89 #define IFT_CARP 0xf8 // IFT_CARP is deprecated in FreeBSD 10 90 #undef SIOCAIFADDR 91 #define SIOCAIFADDR _IOW(105, 26, struct oifaliasreq) // ifaliasreq contains if_data 92 #undef SIOCSIFPHYADDR 93 #define SIOCSIFPHYADDR _IOW(105, 70, struct oifaliasreq) // ifaliasreq contains if_data 94 #endif 95 ' 96 97 includes_Linux=' 98 #define _LARGEFILE_SOURCE 99 #define _LARGEFILE64_SOURCE 100 #ifndef __LP64__ 101 #define _FILE_OFFSET_BITS 64 102 #endif 103 #define _GNU_SOURCE 104 105 #include <bits/sockaddr.h> 106 #include <sys/epoll.h> 107 #include <sys/inotify.h> 108 #include <sys/ioctl.h> 109 #include <sys/mman.h> 110 #include <sys/mount.h> 111 #include <sys/prctl.h> 112 #include <sys/stat.h> 113 #include <sys/types.h> 114 #include <sys/time.h> 115 #include <sys/socket.h> 116 #include <linux/if.h> 117 #include <linux/if_alg.h> 118 #include <linux/if_arp.h> 119 #include <linux/if_ether.h> 120 #include <linux/if_tun.h> 121 #include <linux/if_packet.h> 122 #include <linux/if_addr.h> 123 #include <linux/falloc.h> 124 #include <linux/filter.h> 125 #include <linux/netlink.h> 126 #include <linux/random.h> 127 #include <linux/reboot.h> 128 #include <linux/rtnetlink.h> 129 #include <linux/ptrace.h> 130 #include <linux/sched.h> 131 #include <linux/wait.h> 132 #include <linux/icmpv6.h> 133 #include <linux/serial.h> 134 #include <linux/can.h> 135 #include <linux/vm_sockets.h> 136 #include <net/route.h> 137 #include <asm/termbits.h> 138 139 #ifndef MSG_FASTOPEN 140 #define MSG_FASTOPEN 0x20000000 141 #endif 142 143 #ifndef PTRACE_GETREGS 144 #define PTRACE_GETREGS 0xc 145 #endif 146 147 #ifndef PTRACE_SETREGS 148 #define PTRACE_SETREGS 0xd 149 #endif 150 151 #ifndef SOL_NETLINK 152 #define SOL_NETLINK 270 153 #endif 154 155 #ifdef SOL_BLUETOOTH 156 // SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h 157 // but it is already in bluetooth_linux.go 158 #undef SOL_BLUETOOTH 159 #endif 160 ' 161 162 includes_NetBSD=' 163 #include <sys/types.h> 164 #include <sys/param.h> 165 #include <sys/event.h> 166 #include <sys/mman.h> 167 #include <sys/socket.h> 168 #include <sys/sockio.h> 169 #include <sys/sysctl.h> 170 #include <sys/termios.h> 171 #include <sys/ttycom.h> 172 #include <sys/wait.h> 173 #include <net/bpf.h> 174 #include <net/if.h> 175 #include <net/if_types.h> 176 #include <net/route.h> 177 #include <netinet/in.h> 178 #include <netinet/in_systm.h> 179 #include <netinet/ip.h> 180 #include <netinet/ip_mroute.h> 181 #include <netinet/if_ether.h> 182 183 // Needed since <sys/param.h> refers to it... 184 #define schedppq 1 185 ' 186 187 includes_OpenBSD=' 188 #include <sys/types.h> 189 #include <sys/param.h> 190 #include <sys/event.h> 191 #include <sys/mman.h> 192 #include <sys/socket.h> 193 #include <sys/sockio.h> 194 #include <sys/sysctl.h> 195 #include <sys/termios.h> 196 #include <sys/ttycom.h> 197 #include <sys/wait.h> 198 #include <net/bpf.h> 199 #include <net/if.h> 200 #include <net/if_types.h> 201 #include <net/if_var.h> 202 #include <net/route.h> 203 #include <netinet/in.h> 204 #include <netinet/in_systm.h> 205 #include <netinet/ip.h> 206 #include <netinet/ip_mroute.h> 207 #include <netinet/if_ether.h> 208 #include <net/if_bridge.h> 209 210 // We keep some constants not supported in OpenBSD 5.5 and beyond for 211 // the promise of compatibility. 212 #define EMUL_ENABLED 0x1 213 #define EMUL_NATIVE 0x2 214 #define IPV6_FAITH 0x1d 215 #define IPV6_OPTIONS 0x1 216 #define IPV6_RTHDR_STRICT 0x1 217 #define IPV6_SOCKOPT_RESERVED1 0x3 218 #define SIOCGIFGENERIC 0xc020693a 219 #define SIOCSIFGENERIC 0x80206939 220 #define WALTSIG 0x4 221 ' 222 223 includes_SunOS=' 224 #include <limits.h> 225 #include <sys/types.h> 226 #include <sys/socket.h> 227 #include <sys/sockio.h> 228 #include <sys/mman.h> 229 #include <sys/wait.h> 230 #include <sys/ioctl.h> 231 #include <net/bpf.h> 232 #include <net/if.h> 233 #include <net/if_arp.h> 234 #include <net/if_types.h> 235 #include <net/route.h> 236 #include <netinet/in.h> 237 #include <termios.h> 238 #include <netinet/ip.h> 239 #include <netinet/ip_mroute.h> 240 ' 241 242 243 includes=' 244 #include <sys/types.h> 245 #include <sys/file.h> 246 #include <fcntl.h> 247 #include <dirent.h> 248 #include <sys/socket.h> 249 #include <netinet/in.h> 250 #include <netinet/ip.h> 251 #include <netinet/ip6.h> 252 #include <netinet/tcp.h> 253 #include <errno.h> 254 #include <sys/signal.h> 255 #include <signal.h> 256 #include <sys/resource.h> 257 #include <time.h> 258 ' 259 ccflags="$@" 260 261 # Write go tool cgo -godefs input. 262 ( 263 echo package unix 264 echo 265 echo '/*' 266 indirect="includes_$(uname)" 267 echo "${!indirect} $includes" 268 echo '*/' 269 echo 'import "C"' 270 echo 'import "syscall"' 271 echo 272 echo 'const (' 273 274 # The gcc command line prints all the #defines 275 # it encounters while processing the input 276 echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags | 277 awk ' 278 $1 != "#define" || $2 ~ /\(/ || $3 == "" {next} 279 280 $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers 281 $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next} 282 $2 ~ /^(SCM_SRCRT)$/ {next} 283 $2 ~ /^(MAP_FAILED)$/ {next} 284 $2 ~ /^ELF_.*$/ {next}# <asm/elf.h> contains ELF_ARCH, etc. 285 286 $2 ~ /^EXTATTR_NAMESPACE_NAMES/ || 287 $2 ~ /^EXTATTR_NAMESPACE_[A-Z]+_STRING/ {next} 288 289 $2 !~ /^ETH_/ && 290 $2 !~ /^EPROC_/ && 291 $2 !~ /^EQUIV_/ && 292 $2 !~ /^EXPR_/ && 293 $2 ~ /^E[A-Z0-9_]+$/ || 294 $2 ~ /^B[0-9_]+$/ || 295 $2 == "BOTHER" || 296 $2 ~ /^CI?BAUD(EX)?$/ || 297 $2 == "IBSHIFT" || 298 $2 ~ /^V[A-Z0-9]+$/ || 299 $2 ~ /^CS[A-Z0-9]/ || 300 $2 ~ /^I(SIG|CANON|CRNL|UCLC|EXTEN|MAXBEL|STRIP|UTF8)$/ || 301 $2 ~ /^IGN/ || 302 $2 ~ /^IX(ON|ANY|OFF)$/ || 303 $2 ~ /^IN(LCR|PCK)$/ || 304 $2 ~ /(^FLU?SH)|(FLU?SH$)/ || 305 $2 ~ /^C(LOCAL|READ|MSPAR|RTSCTS)$/ || 306 $2 == "BRKINT" || 307 $2 == "HUPCL" || 308 $2 == "PENDIN" || 309 $2 == "TOSTOP" || 310 $2 == "XCASE" || 311 $2 == "ALTWERASE" || 312 $2 == "NOKERNINFO" || 313 $2 ~ /^PAR/ || 314 $2 ~ /^SIG[^_]/ || 315 $2 ~ /^O[CNPFPL][A-Z]+[^_][A-Z]+$/ || 316 $2 ~ /^(NL|CR|TAB|BS|VT|FF)DLY$/ || 317 $2 ~ /^(NL|CR|TAB|BS|VT|FF)[0-9]$/ || 318 $2 ~ /^O?XTABS$/ || 319 $2 ~ /^TC[IO](ON|OFF)$/ || 320 $2 ~ /^IN_/ || 321 $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || 322 $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ || 323 $2 ~ /^FALLOC_/ || 324 $2 == "ICMPV6_FILTER" || 325 $2 == "SOMAXCONN" || 326 $2 == "NAME_MAX" || 327 $2 == "IFNAMSIZ" || 328 $2 ~ /^CTL_(MAXNAME|NET|QUERY)$/ || 329 $2 ~ /^SYSCTL_VERS/ || 330 $2 ~ /^(MS|MNT)_/ || 331 $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ || 332 $2 ~ /^(O|F|FD|NAME|S|PTRACE|PT)_/ || 333 $2 ~ /^LINUX_REBOOT_CMD_/ || 334 $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ || 335 $2 !~ "NLA_TYPE_MASK" && 336 $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P)_/ || 337 $2 ~ /^SIOC/ || 338 $2 ~ /^TIOC/ || 339 $2 ~ /^TCGET/ || 340 $2 ~ /^TCSET/ || 341 $2 ~ /^TC(FLSH|SBRKP?|XONC)$/ || 342 $2 !~ "RTF_BITS" && 343 $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ || 344 $2 ~ /^BIOC/ || 345 $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || 346 $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|NOFILE|STACK)|RLIM_INFINITY/ || 347 $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ || 348 $2 ~ /^CLONE_[A-Z_]+/ || 349 $2 !~ /^(BPF_TIMEVAL)$/ && 350 $2 ~ /^(BPF|DLT)_/ || 351 $2 ~ /^CLOCK_/ || 352 $2 ~ /^CAN_/ || 353 $2 ~ /^ALG_/ || 354 $2 ~ /^GRND_/ || 355 $2 ~ /^SPLICE_/ || 356 $2 ~ /^(VM|VMADDR)_/ || 357 $2 !~ "WMESGLEN" && 358 $2 ~ /^W[A-Z0-9]+$/ || 359 $2 ~ /^BLK/ {printf("\t%s = C.%s\n", $2, $2)} 360 $2 ~ /^__WCOREFLAG$/ {next} 361 $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} 362 363 {next} 364 ' | sort 365 366 echo ')' 367 ) >_const.go 368 369 # Pull out the error names for later. 370 errors=$( 371 echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | 372 awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' | 373 sort 374 ) 375 376 # Pull out the signal names for later. 377 signals=$( 378 echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | 379 awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | 380 egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' | 381 sort 382 ) 383 384 # Again, writing regexps to a file. 385 echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | 386 awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | 387 sort >_error.grep 388 echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | 389 awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | 390 egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' | 391 sort >_signal.grep 392 393 echo '// mkerrors.sh' "$@" 394 echo '// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT' 395 echo 396 echo "// +build ${GOARCH},${GOOS}" 397 echo 398 go tool cgo -godefs -- "$@" _const.go >_error.out 399 cat _error.out | grep -vf _error.grep | grep -vf _signal.grep 400 echo 401 echo '// Errors' 402 echo 'const (' 403 cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/' 404 echo ')' 405 406 echo 407 echo '// Signals' 408 echo 'const (' 409 cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/' 410 echo ')' 411 412 # Run C program to print error and syscall strings. 413 ( 414 echo -E " 415 #include <stdio.h> 416 #include <stdlib.h> 417 #include <errno.h> 418 #include <ctype.h> 419 #include <string.h> 420 #include <signal.h> 421 422 #define nelem(x) (sizeof(x)/sizeof((x)[0])) 423 424 enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below 425 426 int errors[] = { 427 " 428 for i in $errors 429 do 430 echo -E ' '$i, 431 done 432 433 echo -E " 434 }; 435 436 int signals[] = { 437 " 438 for i in $signals 439 do 440 echo -E ' '$i, 441 done 442 443 # Use -E because on some systems bash builtin interprets \n itself. 444 echo -E ' 445 }; 446 447 static int 448 intcmp(const void *a, const void *b) 449 { 450 return *(int*)a - *(int*)b; 451 } 452 453 int 454 main(void) 455 { 456 int i, j, e; 457 char buf[1024], *p; 458 459 printf("\n\n// Error table\n"); 460 printf("var errors = [...]string {\n"); 461 qsort(errors, nelem(errors), sizeof errors[0], intcmp); 462 for(i=0; i<nelem(errors); i++) { 463 e = errors[i]; 464 if(i > 0 && errors[i-1] == e) 465 continue; 466 strcpy(buf, strerror(e)); 467 // lowercase first letter: Bad -> bad, but STREAM -> STREAM. 468 if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) 469 buf[0] += a - A; 470 printf("\t%d: \"%s\",\n", e, buf); 471 } 472 printf("}\n\n"); 473 474 printf("\n\n// Signal table\n"); 475 printf("var signals = [...]string {\n"); 476 qsort(signals, nelem(signals), sizeof signals[0], intcmp); 477 for(i=0; i<nelem(signals); i++) { 478 e = signals[i]; 479 if(i > 0 && signals[i-1] == e) 480 continue; 481 strcpy(buf, strsignal(e)); 482 // lowercase first letter: Bad -> bad, but STREAM -> STREAM. 483 if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) 484 buf[0] += a - A; 485 // cut trailing : number. 486 p = strrchr(buf, ":"[0]); 487 if(p) 488 *p = '\0'; 489 printf("\t%d: \"%s\",\n", e, buf); 490 } 491 printf("}\n\n"); 492 493 return 0; 494 } 495 496 ' 497 ) >_errors.c 498 499 $CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out