PageRenderTime 1265ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/golang.org/x/sys/unix/mkerrors.sh

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