Devon H. O'Dell | 553be84 | 2009-11-14 15:29:09 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 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 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 6 | # Generate Go code listing errors and other #defined constant |
| 7 | # values (ENAMETOOLONG etc.), by asking the preprocessor |
| 8 | # about the definitions. |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 9 | |
Russ Cox | 0b126c1 | 2009-12-01 16:53:43 -0800 | [diff] [blame] | 10 | unset LANG |
| 11 | export LC_ALL=C |
| 12 | export LC_CTYPE=C |
| 13 | |
Mikio Hara | fe330cf | 2014-02-24 16:34:51 +0900 | [diff] [blame] | 14 | CC=${CC:-gcc} |
Kai Backman | e5c884f | 2009-10-01 06:55:01 -0700 | [diff] [blame] | 15 | |
Shawn Walker-Salas | af7c9a4 | 2015-09-04 16:53:19 -0700 | [diff] [blame] | 16 | if [[ "$GOOS" -eq "solaris" ]]; then |
| 17 | # Assumes GNU versions of utilities in PATH. |
| 18 | export PATH=/usr/gnu/bin:$PATH |
| 19 | fi |
| 20 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 21 | uname=$(uname) |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 22 | |
Clément Chigot | 8f9902d | 2018-09-28 15:29:58 +0200 | [diff] [blame] | 23 | includes_AIX=' |
| 24 | #include <net/if.h> |
| 25 | #include <net/netopt.h> |
| 26 | #include <netinet/ip_mroute.h> |
| 27 | #include <sys/mman.h> |
| 28 | #include <sys/protosw.h> |
| 29 | #include <sys/ptrace.h> |
| 30 | #include <sys/stropts.h> |
Clément Chigot | 63cad96 | 2019-04-10 17:16:48 +0200 | [diff] [blame] | 31 | #include <termios.h> |
Clément Chigot | 8f9902d | 2018-09-28 15:29:58 +0200 | [diff] [blame] | 32 | ' |
| 33 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 34 | includes_Darwin=' |
Russ Cox | acd858e | 2011-01-18 14:02:41 -0500 | [diff] [blame] | 35 | #define _DARWIN_C_SOURCE |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 36 | #define KERNEL |
| 37 | #define _DARWIN_USE_64_BIT_INODE |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 38 | #include <sys/types.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 39 | #include <sys/event.h> |
Jeff Hodges | 0ce57a7 | 2011-06-14 12:56:46 -0400 | [diff] [blame] | 40 | #include <sys/ptrace.h> |
Mikio Hara | 5c0aab9 | 2011-01-31 12:50:50 -0500 | [diff] [blame] | 41 | #include <sys/socket.h> |
| 42 | #include <sys/sockio.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 43 | #include <sys/sysctl.h> |
Russ Cox | 48ae1f2 | 2011-04-06 17:52:02 -0400 | [diff] [blame] | 44 | #include <sys/mman.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 45 | #include <sys/wait.h> |
Mikio Hara | 380f4ab | 2011-04-21 16:58:20 -0400 | [diff] [blame] | 46 | #include <net/bpf.h> |
Mikio Hara | 5c0aab9 | 2011-01-31 12:50:50 -0500 | [diff] [blame] | 47 | #include <net/if.h> |
Mikio Hara | 12376c9 | 2011-05-26 20:02:03 -0400 | [diff] [blame] | 48 | #include <net/if_types.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 49 | #include <net/route.h> |
| 50 | #include <netinet/in.h> |
Mikio Hara | 5c0aab9 | 2011-01-31 12:50:50 -0500 | [diff] [blame] | 51 | #include <netinet/ip.h> |
| 52 | #include <netinet/ip_mroute.h> |
Ken Rockot | c8443d7 | 2011-06-22 18:07:20 -0400 | [diff] [blame] | 53 | #include <termios.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 54 | ' |
| 55 | |
Joel Sing | 8f3f4c9 | 2013-08-24 01:51:25 +1000 | [diff] [blame] | 56 | includes_DragonFly=' |
| 57 | #include <sys/types.h> |
| 58 | #include <sys/event.h> |
| 59 | #include <sys/socket.h> |
| 60 | #include <sys/sockio.h> |
| 61 | #include <sys/sysctl.h> |
| 62 | #include <sys/mman.h> |
| 63 | #include <sys/wait.h> |
| 64 | #include <sys/ioctl.h> |
| 65 | #include <net/bpf.h> |
| 66 | #include <net/if.h> |
| 67 | #include <net/if_types.h> |
| 68 | #include <net/route.h> |
| 69 | #include <netinet/in.h> |
| 70 | #include <termios.h> |
| 71 | #include <netinet/ip.h> |
| 72 | #include <net/ip_mroute/ip_mroute.h> |
| 73 | ' |
| 74 | |
Devon H. O'Dell | 553be84 | 2009-11-14 15:29:09 -0800 | [diff] [blame] | 75 | includes_FreeBSD=' |
Mikio Hara | 737efeb | 2014-03-04 09:26:01 +0900 | [diff] [blame] | 76 | #include <sys/param.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 77 | #include <sys/types.h> |
Devon H. O'Dell | 553be84 | 2009-11-14 15:29:09 -0800 | [diff] [blame] | 78 | #include <sys/event.h> |
Mikio Hara | 400ea84 | 2011-02-01 08:46:21 -0500 | [diff] [blame] | 79 | #include <sys/socket.h> |
| 80 | #include <sys/sockio.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 81 | #include <sys/sysctl.h> |
Dave Cheney | 9dd92d5 | 2013-03-09 16:25:30 +1100 | [diff] [blame] | 82 | #include <sys/mman.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 83 | #include <sys/wait.h> |
Ken Rockot | c8443d7 | 2011-06-22 18:07:20 -0400 | [diff] [blame] | 84 | #include <sys/ioctl.h> |
Mikio Hara | 5a59b9e | 2011-04-04 15:40:40 -0400 | [diff] [blame] | 85 | #include <net/bpf.h> |
Mikio Hara | 400ea84 | 2011-02-01 08:46:21 -0500 | [diff] [blame] | 86 | #include <net/if.h> |
Mikio Hara | 12376c9 | 2011-05-26 20:02:03 -0400 | [diff] [blame] | 87 | #include <net/if_types.h> |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 88 | #include <net/route.h> |
Mikio Hara | 400ea84 | 2011-02-01 08:46:21 -0500 | [diff] [blame] | 89 | #include <netinet/in.h> |
Russ Cox | dfacfd6 | 2011-06-27 11:02:32 -0400 | [diff] [blame] | 90 | #include <termios.h> |
Mikio Hara | 400ea84 | 2011-02-01 08:46:21 -0500 | [diff] [blame] | 91 | #include <netinet/ip.h> |
| 92 | #include <netinet/ip_mroute.h> |
Mikio Hara | 737efeb | 2014-03-04 09:26:01 +0900 | [diff] [blame] | 93 | |
| 94 | #if __FreeBSD__ >= 10 |
| 95 | #define IFT_CARP 0xf8 // IFT_CARP is deprecated in FreeBSD 10 |
| 96 | #undef SIOCAIFADDR |
| 97 | #define SIOCAIFADDR _IOW(105, 26, struct oifaliasreq) // ifaliasreq contains if_data |
| 98 | #undef SIOCSIFPHYADDR |
| 99 | #define SIOCSIFPHYADDR _IOW(105, 70, struct oifaliasreq) // ifaliasreq contains if_data |
| 100 | #endif |
Devon H. O'Dell | 553be84 | 2009-11-14 15:29:09 -0800 | [diff] [blame] | 101 | ' |
| 102 | |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 103 | includes_Linux=' |
| 104 | #define _LARGEFILE_SOURCE |
| 105 | #define _LARGEFILE64_SOURCE |
Ian Lance Taylor | 08ba7db | 2015-05-11 20:49:32 -0700 | [diff] [blame] | 106 | #ifndef __LP64__ |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 107 | #define _FILE_OFFSET_BITS 64 |
Ian Lance Taylor | 08ba7db | 2015-05-11 20:49:32 -0700 | [diff] [blame] | 108 | #endif |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 109 | #define _GNU_SOURCE |
| 110 | |
| 111 | #include <bits/sockaddr.h> |
| 112 | #include <sys/epoll.h> |
| 113 | #include <sys/inotify.h> |
| 114 | #include <sys/ioctl.h> |
| 115 | #include <sys/mman.h> |
| 116 | #include <sys/mount.h> |
Albert Strasheim | 2cb6fcf | 2012-01-09 21:37:46 +0900 | [diff] [blame] | 117 | #include <sys/prctl.h> |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 118 | #include <sys/stat.h> |
| 119 | #include <sys/types.h> |
Shenghou Ma | 46e30c7 | 2013-06-11 02:47:04 +0800 | [diff] [blame] | 120 | #include <sys/time.h> |
Mikio Hara | adbe59e | 2013-05-23 16:22:05 +0900 | [diff] [blame] | 121 | #include <sys/socket.h> |
Mikio Hara | be9c514 | 2014-02-15 00:47:28 +0900 | [diff] [blame] | 122 | #include <linux/if.h> |
| 123 | #include <linux/if_arp.h> |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 124 | #include <linux/if_ether.h> |
| 125 | #include <linux/if_tun.h> |
Mikio Hara | be9c514 | 2014-02-15 00:47:28 +0900 | [diff] [blame] | 126 | #include <linux/if_packet.h> |
| 127 | #include <linux/if_addr.h> |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 128 | #include <linux/filter.h> |
| 129 | #include <linux/netlink.h> |
| 130 | #include <linux/reboot.h> |
| 131 | #include <linux/rtnetlink.h> |
| 132 | #include <linux/ptrace.h> |
Rémy Oudompheng | d4f719e | 2013-08-23 22:26:49 +0200 | [diff] [blame] | 133 | #include <linux/sched.h> |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 134 | #include <linux/wait.h> |
Mikio Hara | adbe59e | 2013-05-23 16:22:05 +0900 | [diff] [blame] | 135 | #include <linux/icmpv6.h> |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 136 | #include <net/route.h> |
Dave Cheney | bd9cd6e | 2013-09-13 15:01:22 +1000 | [diff] [blame] | 137 | #include <termios.h> |
Brad Fitzpatrick | abf5700 | 2013-02-27 15:51:51 -0800 | [diff] [blame] | 138 | |
| 139 | #ifndef MSG_FASTOPEN |
| 140 | #define MSG_FASTOPEN 0x20000000 |
| 141 | #endif |
Aram Hăvărneanu | d0d9310 | 2015-03-08 14:21:00 +0100 | [diff] [blame] | 142 | |
| 143 | #ifndef PTRACE_GETREGS |
| 144 | #define PTRACE_GETREGS 0xc |
| 145 | #endif |
| 146 | |
| 147 | #ifndef PTRACE_SETREGS |
| 148 | #define PTRACE_SETREGS 0xd |
| 149 | #endif |
Mikio Hara | 055b4f7 | 2011-12-16 19:51:25 +0900 | [diff] [blame] | 150 | ' |
| 151 | |
Christopher Nielsen | 5425db8 | 2011-12-20 03:57:58 +1100 | [diff] [blame] | 152 | includes_NetBSD=' |
| 153 | #include <sys/types.h> |
| 154 | #include <sys/param.h> |
| 155 | #include <sys/event.h> |
Joel Sing | 8f98443 | 2014-01-07 23:04:17 +1100 | [diff] [blame] | 156 | #include <sys/mman.h> |
Christopher Nielsen | 5425db8 | 2011-12-20 03:57:58 +1100 | [diff] [blame] | 157 | #include <sys/socket.h> |
| 158 | #include <sys/sockio.h> |
| 159 | #include <sys/sysctl.h> |
| 160 | #include <sys/termios.h> |
| 161 | #include <sys/ttycom.h> |
| 162 | #include <sys/wait.h> |
| 163 | #include <net/bpf.h> |
| 164 | #include <net/if.h> |
| 165 | #include <net/if_types.h> |
| 166 | #include <net/route.h> |
| 167 | #include <netinet/in.h> |
| 168 | #include <netinet/in_systm.h> |
| 169 | #include <netinet/ip.h> |
| 170 | #include <netinet/ip_mroute.h> |
| 171 | #include <netinet/if_ether.h> |
Joel Sing | 2a47e04 | 2012-05-14 10:40:13 -0700 | [diff] [blame] | 172 | |
| 173 | // Needed since <sys/param.h> refers to it... |
Joel Sing | 495a9dc | 2012-05-23 01:33:48 +1000 | [diff] [blame] | 174 | #define schedppq 1 |
Christopher Nielsen | 5425db8 | 2011-12-20 03:57:58 +1100 | [diff] [blame] | 175 | ' |
| 176 | |
Joel Sing | bf2d403 | 2011-08-22 23:24:32 -0400 | [diff] [blame] | 177 | includes_OpenBSD=' |
| 178 | #include <sys/types.h> |
| 179 | #include <sys/param.h> |
| 180 | #include <sys/event.h> |
Joel Sing | f40dd8f | 2014-01-13 11:25:48 +1100 | [diff] [blame] | 181 | #include <sys/mman.h> |
Joel Sing | bf2d403 | 2011-08-22 23:24:32 -0400 | [diff] [blame] | 182 | #include <sys/socket.h> |
| 183 | #include <sys/sockio.h> |
| 184 | #include <sys/sysctl.h> |
| 185 | #include <sys/termios.h> |
| 186 | #include <sys/ttycom.h> |
| 187 | #include <sys/wait.h> |
| 188 | #include <net/bpf.h> |
| 189 | #include <net/if.h> |
| 190 | #include <net/if_types.h> |
Mikio Hara | 40e7f64 | 2014-05-16 06:49:15 +0900 | [diff] [blame] | 191 | #include <net/if_var.h> |
Joel Sing | bf2d403 | 2011-08-22 23:24:32 -0400 | [diff] [blame] | 192 | #include <net/route.h> |
| 193 | #include <netinet/in.h> |
| 194 | #include <netinet/in_systm.h> |
| 195 | #include <netinet/ip.h> |
| 196 | #include <netinet/ip_mroute.h> |
| 197 | #include <netinet/if_ether.h> |
| 198 | #include <net/if_bridge.h> |
Mikio Hara | 40e7f64 | 2014-05-16 06:49:15 +0900 | [diff] [blame] | 199 | |
| 200 | // We keep some constants not supported in OpenBSD 5.5 and beyond for |
| 201 | // the promise of compatibility. |
| 202 | #define EMUL_ENABLED 0x1 |
| 203 | #define EMUL_NATIVE 0x2 |
| 204 | #define IPV6_FAITH 0x1d |
| 205 | #define IPV6_OPTIONS 0x1 |
| 206 | #define IPV6_RTHDR_STRICT 0x1 |
| 207 | #define IPV6_SOCKOPT_RESERVED1 0x3 |
| 208 | #define SIOCGIFGENERIC 0xc020693a |
| 209 | #define SIOCSIFGENERIC 0x80206939 |
| 210 | #define WALTSIG 0x4 |
Joel Sing | bf2d403 | 2011-08-22 23:24:32 -0400 | [diff] [blame] | 211 | ' |
| 212 | |
Aram Hăvărneanu | 1c98619 | 2014-02-25 21:12:10 +1100 | [diff] [blame] | 213 | includes_SunOS=' |
Shawn Walker-Salas | af7c9a4 | 2015-09-04 16:53:19 -0700 | [diff] [blame] | 214 | #include <limits.h> |
Aram Hăvărneanu | 1c98619 | 2014-02-25 21:12:10 +1100 | [diff] [blame] | 215 | #include <sys/types.h> |
| 216 | #include <sys/socket.h> |
| 217 | #include <sys/sockio.h> |
| 218 | #include <sys/mman.h> |
| 219 | #include <sys/wait.h> |
| 220 | #include <sys/ioctl.h> |
| 221 | #include <net/bpf.h> |
| 222 | #include <net/if.h> |
| 223 | #include <net/if_arp.h> |
| 224 | #include <net/if_types.h> |
| 225 | #include <net/route.h> |
| 226 | #include <netinet/in.h> |
| 227 | #include <termios.h> |
| 228 | #include <netinet/ip.h> |
| 229 | #include <netinet/ip_mroute.h> |
| 230 | ' |
| 231 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 232 | includes=' |
| 233 | #include <sys/types.h> |
Andrea Spadaccini | 83c30f3 | 2011-12-08 15:12:08 +0900 | [diff] [blame] | 234 | #include <sys/file.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 235 | #include <fcntl.h> |
| 236 | #include <dirent.h> |
| 237 | #include <sys/socket.h> |
| 238 | #include <netinet/in.h> |
Russ Cox | 8fbe8be | 2010-03-30 14:32:59 -0700 | [diff] [blame] | 239 | #include <netinet/ip.h> |
| 240 | #include <netinet/ip6.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 241 | #include <netinet/tcp.h> |
| 242 | #include <errno.h> |
| 243 | #include <sys/signal.h> |
| 244 | #include <signal.h> |
Sébastien Paolacci | e2467f0 | 2011-11-19 15:17:40 +0900 | [diff] [blame] | 245 | #include <sys/resource.h> |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 246 | ' |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 247 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 248 | ccflags="$@" |
Russ Cox | 7906e31 | 2010-04-29 23:34:06 -0700 | [diff] [blame] | 249 | |
Mikio Hara | 44122ed | 2012-02-03 12:22:40 +0900 | [diff] [blame] | 250 | # Write go tool cgo -godefs input. |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 251 | ( |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 252 | echo package syscall |
| 253 | echo |
| 254 | echo '/*' |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 255 | indirect="includes_$(uname)" |
| 256 | echo "${!indirect} $includes" |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 257 | echo '*/' |
| 258 | echo 'import "C"' |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 259 | echo |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 260 | echo 'const (' |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 261 | |
| 262 | # The gcc command line prints all the #defines |
| 263 | # it encounters while processing the input |
Mikio Hara | fe330cf | 2014-02-24 16:34:51 +0900 | [diff] [blame] | 264 | echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 265 | awk ' |
Joel Sing | bf2d403 | 2011-08-22 23:24:32 -0400 | [diff] [blame] | 266 | $1 != "#define" || $2 ~ /\(/ || $3 == "" {next} |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 267 | |
Russ Cox | 23bf408 | 2010-05-03 11:11:01 -0700 | [diff] [blame] | 268 | $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 269 | $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next} |
Albert Strasheim | cf6c212 | 2010-12-07 13:40:14 -0500 | [diff] [blame] | 270 | $2 ~ /^(SCM_SRCRT)$/ {next} |
| 271 | $2 ~ /^(MAP_FAILED)$/ {next} |
Shenghou Ma | c74a4d4 | 2014-08-12 19:49:31 -0400 | [diff] [blame] | 272 | $2 ~ /^ELF_.*$/ {next} # <asm/elf.h> contains ELF_ARCH, etc. |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 273 | |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 274 | $2 !~ /^ETH_/ && |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 275 | $2 !~ /^EPROC_/ && |
| 276 | $2 !~ /^EQUIV_/ && |
| 277 | $2 !~ /^EXPR_/ && |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 278 | $2 ~ /^E[A-Z0-9_]+$/ || |
Francisco Souza | 61060ac | 2012-05-03 17:33:19 -0400 | [diff] [blame] | 279 | $2 ~ /^B[0-9_]+$/ || |
| 280 | $2 ~ /^V[A-Z0-9]+$/ || |
| 281 | $2 ~ /^CS[A-Z0-9]/ || |
| 282 | $2 ~ /^I(SIG|CANON|CRNL|EXTEN|MAXBEL|STRIP|UTF8)$/ || |
| 283 | $2 ~ /^IGN/ || |
| 284 | $2 ~ /^IX(ON|ANY|OFF)$/ || |
| 285 | $2 ~ /^IN(LCR|PCK)$/ || |
| 286 | $2 ~ /(^FLU?SH)|(FLU?SH$)/ || |
| 287 | $2 ~ /^C(LOCAL|READ)$/ || |
| 288 | $2 == "BRKINT" || |
| 289 | $2 == "HUPCL" || |
| 290 | $2 == "PENDIN" || |
| 291 | $2 == "TOSTOP" || |
| 292 | $2 ~ /^PAR/ || |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 293 | $2 ~ /^SIG[^_]/ || |
Francisco Souza | 61060ac | 2012-05-03 17:33:19 -0400 | [diff] [blame] | 294 | $2 ~ /^O[CNPFP][A-Z]+[^_][A-Z]+$/ || |
Balazs Lecz | 4bfcfcf | 2010-09-27 11:44:26 -0400 | [diff] [blame] | 295 | $2 ~ /^IN_/ || |
Andrea Spadaccini | 83c30f3 | 2011-12-08 15:12:08 +0900 | [diff] [blame] | 296 | $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || |
Mikio Hara | 3bf75e6 | 2014-07-30 10:01:32 +0900 | [diff] [blame] | 297 | $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ || |
Mikio Hara | adbe59e | 2013-05-23 16:22:05 +0900 | [diff] [blame] | 298 | $2 == "ICMPV6_FILTER" || |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 299 | $2 == "SOMAXCONN" || |
| 300 | $2 == "NAME_MAX" || |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 301 | $2 == "IFNAMSIZ" || |
Joel Sing | 495a9dc | 2012-05-23 01:33:48 +1000 | [diff] [blame] | 302 | $2 ~ /^CTL_(MAXNAME|NET|QUERY)$/ || |
| 303 | $2 ~ /^SYSCTL_VERS/ || |
David Anderson | ad102e1 | 2011-03-09 05:58:47 -0800 | [diff] [blame] | 304 | $2 ~ /^(MS|MNT)_/ || |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 305 | $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ || |
Jeff Hodges | 0ce57a7 | 2011-06-14 12:56:46 -0400 | [diff] [blame] | 306 | $2 ~ /^(O|F|FD|NAME|S|PTRACE|PT)_/ || |
David Anderson | 05660b7 | 2011-03-09 05:45:08 -0800 | [diff] [blame] | 307 | $2 ~ /^LINUX_REBOOT_CMD_/ || |
| 308 | $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ || |
Mikio Hara | 1d550bd | 2011-05-18 16:33:41 -0700 | [diff] [blame] | 309 | $2 !~ "NLA_TYPE_MASK" && |
Mikio Hara | b1d51c6 | 2013-02-24 12:04:48 +0900 | [diff] [blame] | 310 | $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P)_/ || |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 311 | $2 ~ /^SIOC/ || |
Ken Rockot | c8443d7 | 2011-06-22 18:07:20 -0400 | [diff] [blame] | 312 | $2 ~ /^TIOC/ || |
Mikio Hara | 753bdc0 | 2014-03-28 13:27:14 +0900 | [diff] [blame] | 313 | $2 !~ "RTF_BITS" && |
Mikio Hara | 12376c9 | 2011-05-26 20:02:03 -0400 | [diff] [blame] | 314 | $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ || |
Mikio Hara | 5a59b9e | 2011-04-04 15:40:40 -0400 | [diff] [blame] | 315 | $2 ~ /^BIOC/ || |
Sébastien Paolacci | e2467f0 | 2011-11-19 15:17:40 +0900 | [diff] [blame] | 316 | $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || |
| 317 | $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|NOFILE|STACK)|RLIM_INFINITY/ || |
Shenghou Ma | 46e30c7 | 2013-06-11 02:47:04 +0800 | [diff] [blame] | 318 | $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ || |
Rémy Oudompheng | d4f719e | 2013-08-23 22:26:49 +0200 | [diff] [blame] | 319 | $2 ~ /^CLONE_[A-Z_]+/ || |
Mikio Hara | 380f4ab | 2011-04-21 16:58:20 -0400 | [diff] [blame] | 320 | $2 !~ /^(BPF_TIMEVAL)$/ && |
Mikio Hara | 5a59b9e | 2011-04-04 15:40:40 -0400 | [diff] [blame] | 321 | $2 ~ /^(BPF|DLT)_/ || |
Mikio Hara | 9c97af9 | 2011-02-11 14:34:00 -0500 | [diff] [blame] | 322 | $2 !~ "WMESGLEN" && |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 323 | $2 ~ /^W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", $2, $2)} |
Russ Cox | 23bf408 | 2010-05-03 11:11:01 -0700 | [diff] [blame] | 324 | $2 ~ /^__WCOREFLAG$/ {next} |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 325 | $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} |
Mikio Hara | 6555cfc | 2010-12-09 13:55:59 -0500 | [diff] [blame] | 326 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 327 | {next} |
| 328 | ' | sort |
| 329 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 330 | echo ')' |
| 331 | ) >_const.go |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 332 | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 333 | # Pull out the error names for later. |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 334 | errors=$( |
Mikio Hara | fe330cf | 2014-02-24 16:34:51 +0900 | [diff] [blame] | 335 | echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | |
Russ Cox | 0b126c1 | 2009-12-01 16:53:43 -0800 | [diff] [blame] | 336 | awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' | |
| 337 | sort |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 338 | ) |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 339 | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 340 | # Pull out the signal names for later. |
| 341 | signals=$( |
Mikio Hara | fe330cf | 2014-02-24 16:34:51 +0900 | [diff] [blame] | 342 | echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 343 | awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | |
| 344 | egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' | |
| 345 | sort |
| 346 | ) |
| 347 | |
Russ Cox | c017a82 | 2011-11-13 22:44:52 -0500 | [diff] [blame] | 348 | # Again, writing regexps to a file. |
Mikio Hara | fe330cf | 2014-02-24 16:34:51 +0900 | [diff] [blame] | 349 | echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | |
Russ Cox | c017a82 | 2011-11-13 22:44:52 -0500 | [diff] [blame] | 350 | awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | |
| 351 | sort >_error.grep |
Mikio Hara | fe330cf | 2014-02-24 16:34:51 +0900 | [diff] [blame] | 352 | echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 353 | awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | |
| 354 | egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' | |
| 355 | sort >_signal.grep |
Russ Cox | c017a82 | 2011-11-13 22:44:52 -0500 | [diff] [blame] | 356 | |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 357 | echo '// mkerrors.sh' "$@" |
Tobias Klauser | 1031380 | 2018-06-14 11:49:42 +0200 | [diff] [blame] | 358 | echo '// Code generated by the command above; DO NOT EDIT.' |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 359 | echo |
Mikio Hara | 44122ed | 2012-02-03 12:22:40 +0900 | [diff] [blame] | 360 | go tool cgo -godefs -- "$@" _const.go >_error.out |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 361 | cat _error.out | grep -vf _error.grep | grep -vf _signal.grep |
Russ Cox | c017a82 | 2011-11-13 22:44:52 -0500 | [diff] [blame] | 362 | echo |
| 363 | echo '// Errors' |
| 364 | echo 'const (' |
| 365 | cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= Errno(\1)/' |
| 366 | echo ')' |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 367 | |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 368 | echo |
| 369 | echo '// Signals' |
| 370 | echo 'const (' |
| 371 | cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= Signal(\1)/' |
| 372 | echo ')' |
| 373 | |
| 374 | # Run C program to print error and syscall strings. |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 375 | ( |
Aram Hăvărneanu | 1c98619 | 2014-02-25 21:12:10 +1100 | [diff] [blame] | 376 | echo -E " |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 377 | #include <stdio.h> |
Mikio Hara | 65675a3 | 2014-02-09 17:20:59 +0900 | [diff] [blame] | 378 | #include <stdlib.h> |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 379 | #include <errno.h> |
| 380 | #include <ctype.h> |
| 381 | #include <string.h> |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 382 | #include <signal.h> |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 383 | |
| 384 | #define nelem(x) (sizeof(x)/sizeof((x)[0])) |
| 385 | |
| 386 | enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below |
| 387 | |
| 388 | int errors[] = { |
| 389 | " |
| 390 | for i in $errors |
| 391 | do |
Aram Hăvărneanu | 1c98619 | 2014-02-25 21:12:10 +1100 | [diff] [blame] | 392 | echo -E ' '$i, |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 393 | done |
| 394 | |
Aram Hăvărneanu | 1c98619 | 2014-02-25 21:12:10 +1100 | [diff] [blame] | 395 | echo -E " |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 396 | }; |
| 397 | |
| 398 | int signals[] = { |
| 399 | " |
| 400 | for i in $signals |
| 401 | do |
Aram Hăvărneanu | 1c98619 | 2014-02-25 21:12:10 +1100 | [diff] [blame] | 402 | echo -E ' '$i, |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 403 | done |
| 404 | |
Aram Hăvărneanu | 1c98619 | 2014-02-25 21:12:10 +1100 | [diff] [blame] | 405 | # Use -E because on some systems bash builtin interprets \n itself. |
| 406 | echo -E ' |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 407 | }; |
| 408 | |
Russ Cox | 9a96fb3 | 2010-09-24 13:37:02 -0400 | [diff] [blame] | 409 | static int |
| 410 | intcmp(const void *a, const void *b) |
| 411 | { |
| 412 | return *(int*)a - *(int*)b; |
| 413 | } |
| 414 | |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 415 | int |
| 416 | main(void) |
| 417 | { |
| 418 | int i, j, e; |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 419 | char buf[1024], *p; |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 420 | |
| 421 | printf("\n\n// Error table\n"); |
| 422 | printf("var errors = [...]string {\n"); |
Russ Cox | 9a96fb3 | 2010-09-24 13:37:02 -0400 | [diff] [blame] | 423 | qsort(errors, nelem(errors), sizeof errors[0], intcmp); |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 424 | for(i=0; i<nelem(errors); i++) { |
| 425 | e = errors[i]; |
Russ Cox | 9a96fb3 | 2010-09-24 13:37:02 -0400 | [diff] [blame] | 426 | if(i > 0 && errors[i-1] == e) |
| 427 | continue; |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 428 | strcpy(buf, strerror(e)); |
| 429 | // lowercase first letter: Bad -> bad, but STREAM -> STREAM. |
| 430 | if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) |
| 431 | buf[0] += a - A; |
| 432 | printf("\t%d: \"%s\",\n", e, buf); |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 433 | } |
| 434 | printf("}\n\n"); |
Russ Cox | 35586f7 | 2012-02-13 13:52:37 -0500 | [diff] [blame] | 435 | |
| 436 | printf("\n\n// Signal table\n"); |
| 437 | printf("var signals = [...]string {\n"); |
| 438 | qsort(signals, nelem(signals), sizeof signals[0], intcmp); |
| 439 | for(i=0; i<nelem(signals); i++) { |
| 440 | e = signals[i]; |
| 441 | if(i > 0 && signals[i-1] == e) |
| 442 | continue; |
| 443 | strcpy(buf, strsignal(e)); |
| 444 | // lowercase first letter: Bad -> bad, but STREAM -> STREAM. |
| 445 | if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) |
| 446 | buf[0] += a - A; |
| 447 | // cut trailing : number. |
| 448 | p = strrchr(buf, ":"[0]); |
| 449 | if(p) |
| 450 | *p = '\0'; |
| 451 | printf("\t%d: \"%s\",\n", e, buf); |
| 452 | } |
| 453 | printf("}\n\n"); |
| 454 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame] | 455 | return 0; |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | ' |
| 459 | ) >_errors.c |
| 460 | |
Mikio Hara | fe330cf | 2014-02-24 16:34:51 +0900 | [diff] [blame] | 461 | $CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out |