]>
Commit | Line | Data |
---|---|---|
7a938933 ILT |
1 | #!/bin/sh |
2 | ||
3 | # Copyright 2009 The Go Authors. All rights reserved. | |
4 | # Use of this source code is governed by a BSD-style | |
5 | # license that can be found in the LICENSE file. | |
6 | ||
14cda8a1 | 7 | # Create sysinfo.go from gen-sysinfo.go and errno.i. |
7a938933 ILT |
8 | |
9 | # This shell script creates the sysinfo.go file which holds types and | |
14cda8a1 ILT |
10 | # constants extracted from the system header files. This reads the |
11 | # raw data from gen-sysinfo.go which is generated using the | |
12 | # -fdump-go-spec option. | |
7a938933 | 13 | |
14cda8a1 ILT |
14 | # This currently exposes some names that ideally should not be |
15 | # exposed, as they match grep patterns. E.g., WCHAR_MIN gets exposed | |
16 | # because it starts with W, like the wait flags. | |
7a938933 | 17 | |
7a938933 ILT |
18 | OUT=tmp-sysinfo.go |
19 | ||
20 | set -e | |
21 | ||
7a938933 | 22 | echo 'package syscall' > ${OUT} |
adb0401d | 23 | echo 'import "unsafe"' >> ${OUT} |
f0f91207 | 24 | echo 'type _ unsafe.Pointer' >> ${OUT} |
7a938933 ILT |
25 | |
26 | # Get all the consts and types, skipping ones which could not be | |
27 | # represented in Go and ones which we need to rewrite. We also skip | |
28 | # function declarations, as we don't need them here. All the symbols | |
29 | # will all have a leading underscore. | |
30 | grep -v '^// ' gen-sysinfo.go | \ | |
31 | grep -v '^func' | \ | |
fbf2f198 | 32 | grep -v '^var' | \ |
7a938933 | 33 | grep -v '^type _timeval ' | \ |
9f3b1e6c ILT |
34 | grep -v '^type _timespec_t ' | \ |
35 | grep -v '^type _timespec ' | \ | |
5fd58e56 | 36 | grep -v '^type _timestruc_t ' | \ |
7a938933 | 37 | grep -v '^type _epoll_' | \ |
03907394 | 38 | grep -v '^type _*locale[_ ]' | \ |
9bac6639 | 39 | grep -v '^type _in6_addr' | \ |
7a938933 | 40 | grep -v 'sockaddr_in6' | \ |
5128f8d0 | 41 | egrep -v '^const _*FLT(64|128)_(NORM_)?MAX' | \ |
7a938933 | 42 | sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \ |
9bac6639 | 43 | -e 's/\([^a-zA-Z0-9_]\)_timeval$/\1Timeval/g' \ |
9f3b1e6c | 44 | -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \ |
9bac6639 | 45 | -e 's/\([^a-zA-Z0-9_]\)_timespec_t$/\1Timespec/g' \ |
9f3b1e6c | 46 | -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \ |
9bac6639 | 47 | -e 's/\([^a-zA-Z0-9_]\)_timespec$/\1Timespec/g' \ |
5fd58e56 | 48 | -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \ |
9bac6639 NB |
49 | -e 's/\([^a-zA-Z0-9_]\)_timestruc_t$/\1Timestruc/g' \ |
50 | -e 's/\([^a-zA-Z0-9_]\)_in6_addr\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \ | |
51 | -e 's/\([^a-zA-Z0-9_]\)_in6_addr$/\1[16]byte/g' \ | |
52 | -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \ | |
53 | -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t$/\1[16]byte/g' \ | |
7a938933 ILT |
54 | >> ${OUT} |
55 | ||
ab61e9c4 | 56 | # The errno constants. These get type Errno. |
d9f0237f | 57 | egrep '#define E[A-Z0-9_]+ [0-9E]' errno.i | \ |
ab61e9c4 | 58 | sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT} |
7a938933 | 59 | |
d9f0237f ILT |
60 | # Workaround for GNU/Hurd _EMIG_* errors having negative values |
61 | egrep '#define E[A-Z0-9_]+ -[0-9]' errno.i | \ | |
62 | sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(-_\1)/' >> ${OUT} | |
63 | ||
7a938933 | 64 | # The O_xxx flags. |
90630d19 | 65 | egrep '^const _(O|F|FD)_' gen-sysinfo.go | \ |
7a938933 | 66 | sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} |
5fd58e56 ILT |
67 | if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then |
68 | echo "const O_ASYNC = 0" >> ${OUT} | |
69 | fi | |
7a938933 ILT |
70 | if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then |
71 | echo "const O_CLOEXEC = 0" >> ${OUT} | |
72 | fi | |
73 | ||
3c450181 ILT |
74 | # The os package requires F_DUPFD_CLOEXEC to be defined. |
75 | if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then | |
76 | echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT} | |
77 | fi | |
78 | ||
f5ec13f1 ILT |
79 | # The internal/poll package requires F_GETPIPE_SZ to be defined. |
80 | if ! grep '^const F_GETPIPE_SZ' ${OUT} >/dev/null 2>&1; then | |
81 | echo "const F_GETPIPE_SZ = 0" >> ${OUT} | |
82 | fi | |
83 | ||
f163907e ILT |
84 | # AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC) |
85 | # which leads to a constant overflow when using O_CLOEXEC in some | |
86 | # go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no | |
87 | # more present in 7.2 (_FCLOEXEC is a 32 bit value). | |
88 | if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then | |
89 | sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2 | |
90 | mv ${OUT}-2 ${OUT} | |
91 | fi | |
92 | ||
e162e288 ILT |
93 | # These flags can be lost on i386 GNU/Linux when using |
94 | # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64" | |
95 | # before we see the definition of F_SETLK64. | |
96 | for flag in F_GETLK F_SETLK F_SETLKW; do | |
97 | if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \ | |
98 | && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then | |
99 | echo "const ${flag} = ${flag}64" >> ${OUT} | |
100 | fi | |
101 | done | |
102 | ||
6736ef96 ILT |
103 | # The Flock_t struct for fcntl. |
104 | grep '^type _flock ' gen-sysinfo.go | \ | |
105 | sed -e 's/type _flock/type Flock_t/' \ | |
106 | -e 's/l_type/Type/' \ | |
107 | -e 's/l_whence/Whence/' \ | |
108 | -e 's/l_start/Start/' \ | |
109 | -e 's/l_len/Len/' \ | |
110 | -e 's/l_pid/Pid/' \ | |
111 | >> ${OUT} | |
112 | ||
7a938933 ILT |
113 | # The signal numbers. |
114 | grep '^const _SIG[^_]' gen-sysinfo.go | \ | |
115 | grep -v '^const _SIGEV_' | \ | |
cbb6491d | 116 | sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT} |
1a6c552d ILT |
117 | if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then |
118 | if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then | |
119 | echo "const SIGPOLL = SIGIO" >> ${OUT} | |
120 | fi | |
121 | fi | |
122 | if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then | |
123 | if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then | |
124 | echo "const SIGCLD = SIGCHLD" >> ${OUT} | |
125 | fi | |
126 | fi | |
7a938933 ILT |
127 | |
128 | # The syscall numbers. We force the names to upper case. | |
129 | grep '^const _SYS_' gen-sysinfo.go | \ | |
130 | sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \ | |
131 | while read sys; do | |
132 | sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` | |
133 | echo "const $sup = _$sys" >> ${OUT} | |
134 | done | |
135 | ||
d9f0237f ILT |
136 | # Special treatment of SYS_IOCTL for GNU/Hurd. |
137 | if ! grep '^const SYS_IOCTL' ${OUT} > /dev/null 2>&1; then | |
138 | echo "const SYS_IOCTL = 0" >> ${OUT} | |
139 | fi | |
140 | ||
81b95894 ILT |
141 | # The GNU/Linux support wants to use SYS_GETDENTS64 if available. |
142 | if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then | |
143 | echo "const SYS_GETDENTS = 0" >> ${OUT} | |
144 | fi | |
145 | if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then | |
146 | echo "const SYS_GETDENTS64 = 0" >> ${OUT} | |
147 | fi | |
148 | ||
dd554b78 ILT |
149 | # The syscall package wants the geteuid system call number. It isn't |
150 | # defined on Alpha, which only provides the getresuid system call. | |
151 | if ! grep '^const SYS_GETEUID ' ${OUT} >/dev/null 2>&1; then | |
152 | echo "const SYS_GETEUID = 0" >> ${OUT} | |
153 | fi | |
154 | ||
7a938933 ILT |
155 | # Stat constants. |
156 | grep '^const _S_' gen-sysinfo.go | \ | |
157 | sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
405ca104 ILT |
158 | |
159 | # Mmap constants. | |
160 | grep '^const _PROT_' gen-sysinfo.go | \ | |
161 | sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
162 | grep '^const _MAP_' gen-sysinfo.go | \ | |
163 | sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
116b061e ILT |
164 | grep '^const _MADV_' gen-sysinfo.go | \ |
165 | sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1410c222 ILT |
166 | grep '^const _MCL_' gen-sysinfo.go | \ |
167 | sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
7a938933 ILT |
168 | |
169 | # Process status constants. | |
170 | grep '^const _W' gen-sysinfo.go | | |
171 | sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
172 | # WSTOPPED was introduced in glibc 2.3.4. | |
173 | if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then | |
174 | if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then | |
175 | echo 'const WSTOPPED = _WUNTRACED' >> ${OUT} | |
176 | else | |
177 | echo 'const WSTOPPED = 2' >> ${OUT} | |
178 | fi | |
179 | fi | |
180 | if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \ | |
181 | && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then | |
182 | echo 'const WALL = ___WALL' >> ${OUT} | |
183 | fi | |
0abbc8f1 ILT |
184 | # On GNU/Linux the os package requires WEXITED and WNOWAIT. |
185 | if test "${GOOS}" = "linux"; then | |
186 | if ! grep '^const WEXITED = ' ${OUT} >/dev/null 2>&1; then | |
187 | echo 'const WEXITED = 4' >> ${OUT} | |
188 | fi | |
189 | if ! grep '^const WNOWAIT = ' ${OUT} >/dev/null 2>&1; then | |
190 | echo 'const WNOWAIT = 0x01000000' >> ${OUT} | |
191 | fi | |
192 | fi | |
7a938933 ILT |
193 | |
194 | # Networking constants. | |
b059fba4 | 195 | egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go | |
e848a83f | 196 | grep -v '_val =' | |
7a938933 ILT |
197 | sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} |
198 | grep '^const _SOMAXCONN' gen-sysinfo.go | | |
199 | sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \ | |
200 | >> ${OUT} | |
201 | grep '^const _SHUT_' gen-sysinfo.go | | |
202 | sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
203 | ||
c915f63f | 204 | # The net package requires some const definitions. |
181c7267 | 205 | for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do |
c915f63f ILT |
206 | if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then |
207 | echo "const $m = 0" >> ${OUT} | |
208 | fi | |
209 | done | |
d6f2922e ILT |
210 | for m in SOCK_CLOEXEC SOCK_NONBLOCK; do |
211 | if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then | |
212 | echo "const $m = -1" >> ${OUT} | |
213 | fi | |
214 | done | |
75d0b398 | 215 | |
e848a83f ILT |
216 | # On 32-bit GNU/Linux the expression for SO_RCVTIMEO is too complicated |
217 | # for -fdump-go-spec. | |
218 | if ! grep '^const SO_RCVTIMEO ' ${OUT} >/dev/null 2>&1; then | |
219 | if grep '^const _SO_RCVTIMEO_val' ${OUT} >/dev/null 2>&1; then | |
220 | echo 'const SO_RCVTIMEO = _SO_RCVTIMEO_val' >> ${OUT} | |
221 | fi | |
222 | fi | |
223 | ||
ae135907 ILT |
224 | # The syscall package requires AF_LOCAL. |
225 | if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then | |
226 | if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then | |
227 | echo "const AF_LOCAL = AF_UNIX" >> ${OUT} | |
228 | fi | |
229 | fi | |
230 | ||
d3d684c6 ILT |
231 | # The syscall package requires _AT_FDCWD, but doesn't export it. |
232 | if ! grep '^const _AT_FDCWD = ' ${OUT} >/dev/null 2>&1; then | |
233 | echo "const _AT_FDCWD = -100" >> ${OUT} | |
234 | fi | |
235 | ||
dc570700 NB |
236 | # sysctl constants. |
237 | grep '^const _CTL' gen-sysinfo.go | | |
238 | sed -e 's/^\(const \)_\(CTL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
239 | grep '^const _SYSCTL' gen-sysinfo.go | | |
240 | sed -e 's/^\(const \)_\(SYSCTL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
241 | grep '^const _NET_RT' gen-sysinfo.go | | |
242 | sed -e 's/^\(const \)_\(NET_RT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
243 | ||
244 | # The sysctlnode struct. | |
245 | grep '^type _sysctlnode ' gen-sysinfo.go | \ | |
246 | sed -e 's/_sysctlnode/Sysctlnode/' \ | |
247 | -e 's/sysctl_flags/Flags/' \ | |
248 | -e 's/sysctl_name/Name/' \ | |
249 | -e 's/sysctl_num/Num/' \ | |
250 | >> ${OUT} | |
251 | ||
22b955cc ILT |
252 | # sysconf constants. |
253 | grep '^const __SC' gen-sysinfo.go | | |
254 | sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT} | |
255 | ||
7a938933 ILT |
256 | # pathconf constants. |
257 | grep '^const __PC' gen-sysinfo.go | | |
258 | sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT} | |
259 | ||
f04e40af | 260 | # The PATH_MAX constant. |
1a985a56 | 261 | if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then |
f04e40af | 262 | echo 'const PathMax = _PATH_MAX' >> ${OUT} |
1a985a56 | 263 | fi |
f04e40af | 264 | |
ab61e9c4 ILT |
265 | # epoll constants. |
266 | grep '^const _EPOLL' gen-sysinfo.go | | |
29849c91 | 267 | grep -v EPOLLET | |
ab61e9c4 | 268 | sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} |
29849c91 | 269 | # Make sure EPOLLET is positive. |
655a8355 | 270 | if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go >/dev/null 2>&1; then |
29849c91 ILT |
271 | grep '^const _EPOLLET ' gen-sysinfo.go | |
272 | sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
273 | else | |
274 | echo "const EPOLLET = 0x80000000" >> ${OUT} | |
275 | fi | |
daeae9f1 | 276 | # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined. |
7a938933 ILT |
277 | if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then |
278 | echo "const EPOLLRDHUP = 0x2000" >> ${OUT} | |
279 | fi | |
daeae9f1 ILT |
280 | if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then |
281 | echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT} | |
282 | fi | |
7a938933 | 283 | |
df1304ee ILT |
284 | # Prctl constants. |
285 | grep '^const _PR_' gen-sysinfo.go | | |
286 | sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
287 | ||
de27caac ILT |
288 | # Ptrace constants. |
289 | grep '^const _PTRACE' gen-sysinfo.go | | |
290 | sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
291 | # We need some ptrace options that are not defined in older versions | |
292 | # of glibc. | |
293 | if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then | |
294 | echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT} | |
7a938933 ILT |
295 | fi |
296 | if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then | |
297 | echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT} | |
298 | fi | |
299 | if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then | |
300 | echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT} | |
301 | fi | |
302 | if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then | |
303 | echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT} | |
304 | fi | |
305 | if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then | |
306 | echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT} | |
307 | fi | |
308 | if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then | |
309 | echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT} | |
310 | fi | |
311 | if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then | |
312 | echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT} | |
313 | fi | |
314 | if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then | |
315 | echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT} | |
316 | fi | |
317 | if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then | |
318 | echo "const PTRACE_O_MASK = 0x7f" >> ${OUT} | |
319 | fi | |
320 | if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then | |
70a3ffe8 | 321 | echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT} |
7a938933 ILT |
322 | fi |
323 | if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then | |
324 | echo "const PTRACE_EVENT_FORK = 1" >> ${OUT} | |
325 | fi | |
326 | if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then | |
327 | echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT} | |
328 | fi | |
329 | if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then | |
330 | echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT} | |
331 | fi | |
332 | if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then | |
333 | echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT} | |
334 | fi | |
335 | if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then | |
336 | echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT} | |
337 | fi | |
338 | if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then | |
339 | echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT} | |
340 | fi | |
5fd58e56 | 341 | if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then |
f9367b7c | 342 | echo "const _PTRACE_TRACEME = 0" >> ${OUT} |
5fd58e56 | 343 | fi |
7a938933 | 344 | |
1fec5f52 ILT |
345 | # A helper function that prints a structure from gen-sysinfo.go with the first |
346 | # letter of the field names in upper case. $1 is the name of structure. If $2 | |
347 | # is not empty, the structure or type is renamed to $2. | |
348 | upcase_fields () { | |
349 | name="$1" | |
655a8355 | 350 | def=`grep "^type $name " gen-sysinfo.go` |
1fec5f52 ILT |
351 | fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'` |
352 | prefix=`echo $def | sed -e 's/{.*//'` | |
353 | if test "$2" != ""; then | |
354 | prefix=`echo $prefix | sed -e "s/$1/$2/"` | |
355 | fi | |
356 | if test "$fields" != ""; then | |
357 | nfields= | |
358 | while test -n "$fields"; do | |
359 | field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'` | |
360 | fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'` | |
361 | # capitalize the next character. | |
362 | f=`echo $field | sed -e 's/^\(.\).*$/\1/'` | |
363 | r=`echo $field | sed -e 's/^.\(.*\)$/\1/'` | |
364 | f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` | |
365 | field="$f$r" | |
366 | nfields="$nfields $field;" | |
367 | done | |
368 | echo "${prefix} {$nfields }" | |
369 | fi | |
370 | } | |
371 | ||
7a938933 | 372 | # The registers returned by PTRACE_GETREGS. This is probably |
5fd58e56 ILT |
373 | # GNU/Linux specific; it should do no harm if there is no |
374 | # _user_regs_struct. | |
389295b7 | 375 | regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true` |
9f59bddf | 376 | if test "$regs" = ""; then |
f9dedc3f ILT |
377 | # mips* |
378 | regs=`grep '^type _pt_regs struct' gen-sysinfo.go || true` | |
1fec5f52 | 379 | fi |
7a938933 | 380 | if test "$regs" != ""; then |
8d4b68a7 | 381 | regs=`echo $regs | sed -e 's/type _pt_regs struct//'` |
1fec5f52 ILT |
382 | regs=`echo $regs | |
383 | sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'` | |
7a938933 ILT |
384 | regs=`echo $regs | sed -e s'/^ *//'` |
385 | nregs= | |
386 | while test -n "$regs"; do | |
387 | field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'` | |
388 | regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'` | |
389 | # Capitalize the first character of the field. | |
390 | f=`echo $field | sed -e 's/^\(.\).*$/\1/'` | |
391 | r=`echo $field | sed -e 's/^.\(.*\)$/\1/'` | |
392 | f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` | |
393 | field="$f$r" | |
1fec5f52 ILT |
394 | field=`echo "$field" | sed \ |
395 | -e 's/__user_psw_struct/PtracePsw/' \ | |
396 | -e 's/__user_fpregs_struct/PtraceFpregs/' \ | |
397 | -e 's/__user_per_struct/PtracePer/'` | |
7a938933 ILT |
398 | nregs="$nregs $field;" |
399 | done | |
400 | echo "type PtraceRegs struct {$nregs }" >> ${OUT} | |
401 | fi | |
402 | ||
403 | # Some basic types. | |
404 | echo 'type Size_t _size_t' >> ${OUT} | |
405 | echo "type Ssize_t _ssize_t" >> ${OUT} | |
406 | if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then | |
407 | echo "type Offset_t _off64_t" >> ${OUT} | |
408 | else | |
409 | echo "type Offset_t _off_t" >> ${OUT} | |
410 | fi | |
411 | echo "type Mode_t _mode_t" >> ${OUT} | |
412 | echo "type Pid_t _pid_t" >> ${OUT} | |
413 | echo "type Uid_t _uid_t" >> ${OUT} | |
414 | echo "type Gid_t _gid_t" >> ${OUT} | |
415 | echo "type Socklen_t _socklen_t" >> ${OUT} | |
416 | ||
ff95e2ab ILT |
417 | # The C int type. |
418 | sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'` | |
419 | if test "$sizeof_int" = "4"; then | |
420 | echo "type _C_int int32" >> ${OUT} | |
540817f4 | 421 | echo "type _C_uint uint32" >> ${OUT} |
ff95e2ab ILT |
422 | elif test "$sizeof_int" = "8"; then |
423 | echo "type _C_int int64" >> ${OUT} | |
540817f4 | 424 | echo "type _C_uint uint64" >> ${OUT} |
ff95e2ab ILT |
425 | else |
426 | echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)" | |
427 | exit 1 | |
428 | fi | |
429 | ||
430 | # The C long type, needed because that is the type that ptrace returns. | |
7a938933 ILT |
431 | sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'` |
432 | if test "$sizeof_long" = "4"; then | |
433 | echo "type _C_long int32" >> ${OUT} | |
c8dc49fb | 434 | echo "type _C_ulong uint32" >> ${OUT} |
7a938933 ILT |
435 | elif test "$sizeof_long" = "8"; then |
436 | echo "type _C_long int64" >> ${OUT} | |
c8dc49fb | 437 | echo "type _C_ulong uint64" >> ${OUT} |
7a938933 ILT |
438 | else |
439 | echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)" | |
440 | exit 1 | |
441 | fi | |
442 | ||
b65734ac ILT |
443 | # The time_t type. |
444 | if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then | |
445 | echo 'type Time_t _time_t' >> ${OUT} | |
446 | fi | |
447 | ||
7a938933 ILT |
448 | # The time structures need special handling: we need to name the |
449 | # types, so that we can cast integers to the right types when | |
450 | # assigning to the structures. | |
451 | timeval=`grep '^type _timeval ' gen-sysinfo.go` | |
452 | timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'` | |
453 | timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'` | |
025f56b7 ILT |
454 | echo "type Timeval_sec_t = $timeval_sec" >> ${OUT} |
455 | echo "type Timeval_usec_t = $timeval_usec" >> ${OUT} | |
7a938933 ILT |
456 | echo $timeval | \ |
457 | sed -e 's/type _timeval /type Timeval /' \ | |
458 | -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \ | |
459 | -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT} | |
654d2ec0 ILT |
460 | timespec=`grep '^type _timespec ' gen-sysinfo.go || true` |
461 | if test "$timespec" = ""; then | |
462 | # IRIX 6.5 has __timespec instead. | |
463 | timespec=`grep '^type ___timespec ' gen-sysinfo.go || true` | |
464 | fi | |
7a938933 ILT |
465 | timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'` |
466 | timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'` | |
025f56b7 ILT |
467 | echo "type Timespec_sec_t = $timespec_sec" >> ${OUT} |
468 | echo "type Timespec_nsec_t = $timespec_nsec" >> ${OUT} | |
7a938933 | 469 | echo $timespec | \ |
9f3b1e6c ILT |
470 | sed -e 's/^type ___timespec /type Timespec /' \ |
471 | -e 's/^type _timespec /type Timespec /' \ | |
7a938933 ILT |
472 | -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \ |
473 | -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT} | |
474 | ||
5fd58e56 | 475 | timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true` |
9bac6639 NB |
476 | if test "$timestruc" = "type _timestruc_t _timespec"; then |
477 | echo "type Timestruc Timespec" >> ${OUT} | |
478 | elif test "$timestruc" != ""; then | |
5fd58e56 ILT |
479 | timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'` |
480 | timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'` | |
025f56b7 ILT |
481 | echo "type Timestruc_sec_t = $timestruc_sec" >> ${OUT} |
482 | echo "type Timestruc_nsec_t = $timestruc_nsec" >> ${OUT} | |
5fd58e56 ILT |
483 | echo $timestruc | \ |
484 | sed -e 's/^type _timestruc_t /type Timestruc /' \ | |
485 | -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \ | |
486 | -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT} | |
487 | fi | |
488 | ||
10f5ffa4 ILT |
489 | # The tms struct. |
490 | grep '^type _tms ' gen-sysinfo.go | \ | |
491 | sed -e 's/type _tms/type Tms/' \ | |
492 | -e 's/tms_utime/Utime/' \ | |
493 | -e 's/tms_stime/Stime/' \ | |
494 | -e 's/tms_cutime/Cutime/' \ | |
495 | -e 's/tms_cstime/Cstime/' \ | |
496 | >> ${OUT} | |
497 | ||
bbb31a1d ILT |
498 | # AIX uses st_timespec struct for stat. |
499 | grep '^type _st_timespec ' gen-sysinfo.go | \ | |
500 | sed -e 's/type _st_timespec /type StTimespec /' \ | |
501 | -e 's/tv_sec/Sec/' \ | |
502 | -e 's/tv_nsec/Nsec/' >> ${OUT} | |
503 | ||
d9f0237f ILT |
504 | # Special treatment of struct stat st_dev for GNU/Hurd |
505 | # /usr/include/i386-gnu/bits/stat.h: #define st_dev st_fsid | |
42ee8204 | 506 | st_dev='-e s/st_dev/Dev/' |
d9f0237f | 507 | if grep 'define st_dev st_fsid' gen-sysinfo.go > /dev/null 2>&1; then |
42ee8204 | 508 | st_dev='-e s/st_fsid/Dev/' |
d9f0237f ILT |
509 | fi |
510 | ||
7cf256c3 NB |
511 | # For historical reasons Go uses the suffix "timespec" instead of "tim" for |
512 | # stat_t's time fields on NetBSD. | |
513 | st_times='-e s/st_atim/Atim/ -e s/st_mtim/Mtim/ -e s/st_ctim/Ctim/' | |
514 | if test "${GOOS}" = "netbsd"; then | |
515 | st_times='-e s/st_atim/Atimespec/ -e s/st_mtim/Mtimespec/ -e s/st_ctim/Ctimespec/' | |
516 | fi | |
517 | ||
7a938933 | 518 | # The stat type. |
a3dbf764 ILT |
519 | # Prefer largefile variant if available. |
520 | stat=`grep '^type _stat64 ' gen-sysinfo.go || true` | |
521 | if test "$stat" != ""; then | |
522 | grep '^type _stat64 ' gen-sysinfo.go | |
523 | else | |
524 | grep '^type _stat ' gen-sysinfo.go | |
90630d19 ILT |
525 | fi | sed -e 's/type _stat64/type Stat_t/' \ |
526 | -e 's/type _stat/type Stat_t/' \ | |
42ee8204 | 527 | ${st_dev} \ |
7cf256c3 | 528 | ${st_times} \ |
a3dbf764 ILT |
529 | -e 's/st_ino/Ino/g' \ |
530 | -e 's/st_nlink/Nlink/' \ | |
531 | -e 's/st_mode/Mode/' \ | |
532 | -e 's/st_uid/Uid/' \ | |
533 | -e 's/st_gid/Gid/' \ | |
534 | -e 's/st_rdev/Rdev/' \ | |
535 | -e 's/st_size/Size/' \ | |
536 | -e 's/st_blksize/Blksize/' \ | |
537 | -e 's/st_blocks/Blocks/' \ | |
a3dbf764 | 538 | -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \ |
9f3b1e6c | 539 | -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \ |
bbb31a1d | 540 | -e 's/\([^a-zA-Z0-9_]\)_st_timespec_t\([^a-zA-Z0-9_]\)/\1StTimespec\2/g' \ |
9f3b1e6c | 541 | -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \ |
a3dbf764 | 542 | -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \ |
f718d442 | 543 | -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \ |
a3dbf764 | 544 | >> ${OUT} |
7a938933 ILT |
545 | |
546 | # The directory searching types. | |
a3dbf764 ILT |
547 | # Prefer largefile variant if available. |
548 | dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true` | |
549 | if test "$dirent" != ""; then | |
550 | grep '^type _dirent64 ' gen-sysinfo.go | |
551 | else | |
552 | grep '^type _dirent ' gen-sysinfo.go | |
90630d19 ILT |
553 | fi | sed -e 's/type _dirent64/type Dirent/' \ |
554 | -e 's/type _dirent/type Dirent/' \ | |
a3dbf764 ILT |
555 | -e 's/d_name \[0+1\]/d_name [0+256]/' \ |
556 | -e 's/d_name/Name/' \ | |
557 | -e 's/]int8/]byte/' \ | |
dc570700 | 558 | -e 's/d_fileno/Fileno/' \ |
a3dbf764 | 559 | -e 's/d_ino/Ino/' \ |
836cccc7 | 560 | -e 's/d_namlen/Namlen/' \ |
a3dbf764 ILT |
561 | -e 's/d_off/Off/' \ |
562 | -e 's/d_reclen/Reclen/' \ | |
563 | -e 's/d_type/Type/' \ | |
564 | >> ${OUT} | |
7a938933 ILT |
565 | echo "type DIR _DIR" >> ${OUT} |
566 | ||
b059fba4 ILT |
567 | # Values for d_type field in dirent. |
568 | grep '^const _DT_' gen-sysinfo.go | | |
569 | sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
570 | ||
7a938933 ILT |
571 | # The rusage struct. |
572 | rusage=`grep '^type _rusage struct' gen-sysinfo.go` | |
573 | if test "$rusage" != ""; then | |
70b9f516 | 574 | # Remove anonymous unions from GNU/Linux <bits/resource.h>. |
1fec5f52 | 575 | rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'` |
5ede5aa5 ILT |
576 | rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'` |
577 | rusage=`echo $rusage | sed -e 's/^ *//'` | |
7a938933 ILT |
578 | nrusage= |
579 | while test -n "$rusage"; do | |
580 | field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'` | |
581 | rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'` | |
582 | # Drop the leading ru_, capitalize the next character. | |
583 | field=`echo $field | sed -e 's/^ru_//'` | |
584 | f=`echo $field | sed -e 's/^\(.\).*$/\1/'` | |
585 | r=`echo $field | sed -e 's/^.\(.*\)$/\1/'` | |
586 | f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` | |
5fd58e56 | 587 | # Fix _timeval _timespec, and _timestruc_t. |
7a938933 ILT |
588 | r=`echo $r | sed -e s'/ _timeval$/ Timeval/'` |
589 | r=`echo $r | sed -e s'/ _timespec$/ Timespec/'` | |
5fd58e56 | 590 | r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'` |
7a938933 ILT |
591 | field="$f$r" |
592 | nrusage="$nrusage $field;" | |
593 | done | |
594 | echo "type Rusage struct {$nrusage }" >> ${OUT} | |
0b3189e7 ILT |
595 | else |
596 | echo "type Rusage struct {}" >> ${OUT} | |
7a938933 ILT |
597 | fi |
598 | ||
9ff56c95 ILT |
599 | # The RUSAGE constants. |
600 | grep '^const _RUSAGE_' gen-sysinfo.go | \ | |
601 | sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
602 | ||
7a938933 ILT |
603 | # The utsname struct. |
604 | grep '^type _utsname ' gen-sysinfo.go | \ | |
605 | sed -e 's/_utsname/Utsname/' \ | |
606 | -e 's/sysname/Sysname/' \ | |
607 | -e 's/nodename/Nodename/' \ | |
608 | -e 's/release/Release/' \ | |
609 | -e 's/version/Version/' \ | |
610 | -e 's/machine/Machine/' \ | |
611 | -e 's/domainname/Domainname/' \ | |
612 | >> ${OUT} | |
613 | ||
ff5f50c5 ILT |
614 | # The iovec struct. |
615 | iovec=`grep '^type _iovec ' gen-sysinfo.go` | |
616 | iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'` | |
617 | echo "type Iovec_len_t $iovec_len" >> ${OUT} | |
618 | echo $iovec | \ | |
619 | sed -e 's/_iovec/Iovec/' \ | |
620 | -e 's/iov_base/Base/' \ | |
621 | -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \ | |
622 | >> ${OUT} | |
623 | ||
624 | # The msghdr struct. | |
625 | msghdr=`grep '^type _msghdr ' gen-sysinfo.go` | |
626 | msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'` | |
627 | echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT} | |
628 | echo $msghdr | \ | |
629 | sed -e 's/_msghdr/Msghdr/' \ | |
630 | -e 's/msg_name/Name/' \ | |
631 | -e 's/msg_namelen/Namelen/' \ | |
632 | -e 's/msg_iov/Iov/' \ | |
633 | -e 's/msg_iovlen/Iovlen/' \ | |
634 | -e 's/_iovec/Iovec/' \ | |
635 | -e 's/msg_control/Control/' \ | |
636 | -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \ | |
637 | -e 's/msg_flags/Flags/' \ | |
638 | >> ${OUT} | |
639 | ||
4a1a8596 ILT |
640 | # The MSG_ flags for Msghdr. |
641 | grep '^const _MSG_' gen-sysinfo.go | \ | |
642 | sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
643 | ||
644 | # The cmsghdr struct. | |
645 | cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go` | |
646 | if test -n "$cmsghdr"; then | |
647 | cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'` | |
648 | echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT} | |
649 | echo "$cmsghdr" | \ | |
650 | sed -e 's/_cmsghdr/Cmsghdr/' \ | |
651 | -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \ | |
652 | -e 's/cmsg_level/Level/' \ | |
653 | -e 's/cmsg_type/Type/' \ | |
cf54a93c | 654 | -e 's/\[\]/[0]/' \ |
4a1a8596 | 655 | >> ${OUT} |
4a1a8596 ILT |
656 | fi |
657 | ||
658 | # The SCM_ flags for Cmsghdr. | |
659 | grep '^const _SCM_' gen-sysinfo.go | \ | |
660 | sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
661 | ||
662 | # The ucred struct. | |
5c2648fb | 663 | upcase_fields "_ucred" "Ucred" >> ${OUT} || true |
4a1a8596 | 664 | |
d8f41257 | 665 | # The ip_mreq struct. |
5133f00e | 666 | grep '^type _ip_mreq ' gen-sysinfo.go | \ |
adb0401d | 667 | sed -e 's/_ip_mreq/IPMreq/' \ |
5133f00e ILT |
668 | -e 's/imr_multiaddr/Multiaddr/' \ |
669 | -e 's/imr_interface/Interface/' \ | |
670 | -e 's/_in_addr/[4]byte/g' \ | |
671 | >> ${OUT} | |
672 | ||
c915f63f ILT |
673 | # We need IPMreq to compile the net package. |
674 | if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then | |
675 | echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT} | |
de27caac ILT |
676 | fi |
677 | ||
d8f41257 ILT |
678 | # The ipv6_mreq struct. |
679 | grep '^type _ipv6_mreq ' gen-sysinfo.go | \ | |
680 | sed -e 's/_ipv6_mreq/IPv6Mreq/' \ | |
681 | -e 's/ipv6mr_multiaddr/Multiaddr/' \ | |
682 | -e 's/ipv6mr_interface/Interface/' \ | |
683 | -e 's/_in6_addr/[16]byte/' \ | |
684 | >> ${OUT} | |
685 | ||
c915f63f ILT |
686 | # We need IPv6Mreq to compile the net package. |
687 | if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then | |
688 | echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT} | |
689 | fi | |
690 | ||
df1304ee ILT |
691 | # The ip_mreqn struct. |
692 | grep '^type _ip_mreqn ' gen-sysinfo.go | \ | |
693 | sed -e 's/_ip_mreqn/IPMreqn/' \ | |
694 | -e 's/imr_multiaddr/Multiaddr/' \ | |
695 | -e 's/imr_address/Address/' \ | |
696 | -e 's/imr_ifindex/Ifindex/' \ | |
697 | -e 's/_in_addr/[4]byte/g' \ | |
698 | >> ${OUT} | |
699 | ||
700 | # We need IPMreq to compile the net package. | |
701 | if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then | |
702 | echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT} | |
703 | fi | |
704 | ||
f038dae6 ILT |
705 | # The icmp6_filter struct. |
706 | grep '^type _icmp6_filter ' gen-sysinfo.go | \ | |
707 | sed -e 's/_icmp6_filter/ICMPv6Filter/' \ | |
708 | -e 's/data/Data/' \ | |
709 | -e 's/filt/Filt/' \ | |
710 | >> ${OUT} | |
711 | ||
712 | # We need ICMPv6Filter to compile the syscall package. | |
713 | if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then | |
714 | echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT} | |
715 | fi | |
716 | ||
6b2cd37b ILT |
717 | # The ip6_mtuinfo struct. |
718 | grep '^type _ip6_mtuinfo ' gen-sysinfo.go | \ | |
719 | sed -e 's/_ip6_mtuinfo/IPv6MTUInfo/' \ | |
720 | -e 's/ip6m_addr/Addr/' \ | |
721 | -e 's/_sockaddr_in6/RawSockaddrInet6/' \ | |
722 | -e 's/ip6m_mtu/Mtu/' \ | |
723 | >> ${OUT} | |
724 | ||
d3d684c6 ILT |
725 | # We need IPv6MTUInfo to compile the syscall package. |
726 | if ! grep 'type IPv6MTUInfo ' ${OUT} >/dev/null 2>&1; then | |
727 | echo 'type IPv6MTUInfo struct { Addr RawSockaddrInet6; Mtu uint32; }' >> ${OUT} | |
728 | fi | |
729 | if ! grep 'const _sizeof_ip6_mtuinfo = ' ${OUT} >/dev/null 2>&1; then | |
730 | echo 'const SizeofIPv6MTUInfo = 32' >> ${OUT} | |
731 | fi | |
732 | ||
4ac7fcaa ILT |
733 | # Try to guess the type to use for fd_set. |
734 | fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true` | |
735 | fds_bits_type="_C_long" | |
736 | if test "$fd_set" != ""; then | |
737 | fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'` | |
738 | fi | |
739 | echo "type fds_bits_type $fds_bits_type" >> ${OUT} | |
740 | ||
9ff56c95 ILT |
741 | # The addrinfo struct. |
742 | grep '^type _addrinfo ' gen-sysinfo.go | \ | |
743 | sed -e 's/_addrinfo/Addrinfo/g' \ | |
744 | -e 's/ ai_/ Ai_/g' \ | |
745 | >> ${OUT} | |
746 | ||
af146490 | 747 | # The addrinfo and nameinfo flags and errors. |
9ff56c95 ILT |
748 | grep '^const _AI_' gen-sysinfo.go | \ |
749 | sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
ab61e9c4 ILT |
750 | grep '^const _EAI_' gen-sysinfo.go | \ |
751 | sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
af146490 ILT |
752 | grep '^const _NI_' gen-sysinfo.go | \ |
753 | sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
9ff56c95 | 754 | |
f163907e ILT |
755 | # If nothing else defined EAI_OVERFLOW, make sure it has a value. |
756 | if ! grep "const EAI_OVERFLOW " ${OUT} >/dev/null 2>&1; then | |
757 | echo "const EAI_OVERFLOW = 0" >> ${OUT} | |
758 | fi | |
759 | ||
9ff56c95 ILT |
760 | # The passwd struct. |
761 | grep '^type _passwd ' gen-sysinfo.go | \ | |
762 | sed -e 's/_passwd/Passwd/' \ | |
763 | -e 's/ pw_/ Pw_/g' \ | |
764 | >> ${OUT} | |
765 | ||
22b955cc ILT |
766 | # The group struct. |
767 | grep '^type _group ' gen-sysinfo.go | \ | |
768 | sed -e 's/_group/Group/' \ | |
769 | -e 's/ gr_/ Gr_/g' \ | |
770 | >> ${OUT} | |
771 | ||
adb0401d ILT |
772 | # The ioctl flags for the controlling TTY. |
773 | grep '^const _TIOC' gen-sysinfo.go | \ | |
dd162880 | 774 | grep -v '_val =' | \ |
adb0401d | 775 | sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} |
2850beb9 ILT |
776 | grep '^const _TUNSET' gen-sysinfo.go | \ |
777 | grep -v '_val =' | \ | |
778 | sed -e 's/^\(const \)_\(TUNSET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
dd162880 ILT |
779 | # We need TIOCGWINSZ. |
780 | if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then | |
781 | if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then | |
eec3e72c | 782 | echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT} |
dd162880 ILT |
783 | fi |
784 | fi | |
3a21b777 ILT |
785 | if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then |
786 | if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then | |
787 | echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT} | |
788 | fi | |
789 | fi | |
98fd70c2 ILT |
790 | if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then |
791 | if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then | |
792 | echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT} | |
793 | fi | |
794 | fi | |
795 | if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then | |
796 | if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then | |
797 | echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT} | |
798 | fi | |
799 | fi | |
c5f6dbf6 ILT |
800 | if ! grep '^const TIOCGPGRP' ${OUT} >/dev/null 2>&1; then |
801 | if grep '^const _TIOCGPGRP_val' ${OUT} >/dev/null 2>&1; then | |
802 | echo 'const TIOCGPGRP = _TIOCGPGRP_val' >> ${OUT} | |
803 | fi | |
804 | fi | |
1c47a3bf ILT |
805 | if ! grep '^const TIOCSPGRP' ${OUT} >/dev/null 2>&1; then |
806 | if grep '^const _TIOCSPGRP_val' ${OUT} >/dev/null 2>&1; then | |
807 | echo 'const TIOCSPGRP = _TIOCSPGRP_val' >> ${OUT} | |
808 | fi | |
809 | fi | |
44d5790f ILT |
810 | if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then |
811 | if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then | |
812 | echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT} | |
813 | fi | |
814 | fi | |
815 | if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then | |
816 | if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then | |
817 | echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT} | |
818 | fi | |
819 | fi | |
820 | if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then | |
821 | if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then | |
822 | echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT} | |
823 | fi | |
824 | fi | |
825 | if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then | |
826 | if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then | |
827 | echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT} | |
828 | fi | |
829 | fi | |
adb0401d | 830 | |
2850beb9 ILT |
831 | if ! grep '^const TUNSETNOCSUM' ${OUT} >/dev/null 2>&1; then |
832 | if grep '^const _TUNSETNOCSUM_val' ${OUT} >/dev/null 2>&1; then | |
833 | echo 'const TUNSETNOCSUM = _TUNSETNOCSUM_val' >> ${OUT} | |
834 | fi | |
835 | fi | |
836 | ||
837 | if ! grep '^const TUNSETDEBUG' ${OUT} >/dev/null 2>&1; then | |
838 | if grep '^const _TUNSETDEBUG_val' ${OUT} >/dev/null 2>&1; then | |
839 | echo 'const TUNSETDEBUG = _TUNSETDEBUG_val' >> ${OUT} | |
840 | fi | |
841 | fi | |
842 | ||
843 | if ! grep '^const TUNSETIFF' ${OUT} >/dev/null 2>&1; then | |
844 | if grep '^const _TUNSETIFF_val' ${OUT} >/dev/null 2>&1; then | |
845 | echo 'const TUNSETIFF = _TUNSETIFF_val' >> ${OUT} | |
846 | fi | |
847 | fi | |
848 | ||
849 | if ! grep '^const TUNSETPERSIST' ${OUT} >/dev/null 2>&1; then | |
850 | if grep '^const _TUNSETPERSIST_val' ${OUT} >/dev/null 2>&1; then | |
851 | echo 'const TUNSETPERSIST = _TUNSETPERSIST_val' >> ${OUT} | |
852 | fi | |
853 | fi | |
854 | ||
855 | if ! grep '^const TUNSETOWNER' ${OUT} >/dev/null 2>&1; then | |
856 | if grep '^const _TUNSETOWNER_val' ${OUT} >/dev/null 2>&1; then | |
857 | echo 'const TUNSETOWNER = _TUNSETOWNER_val' >> ${OUT} | |
858 | fi | |
859 | fi | |
860 | ||
861 | if ! grep '^const TUNSETLINK' ${OUT} >/dev/null 2>&1; then | |
862 | if grep '^const _TUNSETLINK_val' ${OUT} >/dev/null 2>&1; then | |
863 | echo 'const TUNSETLINK = _TUNSETLINK_val' >> ${OUT} | |
864 | fi | |
865 | fi | |
866 | ||
867 | if ! grep '^const TUNSETGROUP' ${OUT} >/dev/null 2>&1; then | |
868 | if grep '^const _TUNSETGROUP_val' ${OUT} >/dev/null 2>&1; then | |
869 | echo 'const TUNSETGROUP = _TUNSETGROUP_val' >> ${OUT} | |
870 | fi | |
871 | fi | |
872 | ||
873 | if ! grep '^const TUNGETFEATURES' ${OUT} >/dev/null 2>&1; then | |
874 | if grep '^const _TUNGETFEATURES_val' ${OUT} >/dev/null 2>&1; then | |
875 | echo 'const TUNGETFEATURES = _TUNGETFEATURES_val' >> ${OUT} | |
876 | fi | |
877 | fi | |
878 | ||
879 | if ! grep '^const TUNSETOFFLOAD' ${OUT} >/dev/null 2>&1; then | |
880 | if grep '^const _TUNSETOFFLOAD_val' ${OUT} >/dev/null 2>&1; then | |
881 | echo 'const TUNSETOFFLOAD = _TUNSETOFFLOAD_val' >> ${OUT} | |
882 | fi | |
883 | fi | |
884 | ||
885 | if ! grep '^const TUNSETTXFILTER' ${OUT} >/dev/null 2>&1; then | |
886 | if grep '^const _TUNSETTXFILTER_val' ${OUT} >/dev/null 2>&1; then | |
887 | echo 'const TUNSETTXFILTER = _TUNSETTXFILTER_val' >> ${OUT} | |
888 | fi | |
889 | fi | |
890 | ||
891 | if ! grep '^const TUNGETIFF' ${OUT} >/dev/null 2>&1; then | |
892 | if grep '^const _TUNGETIFF_val' ${OUT} >/dev/null 2>&1; then | |
893 | echo 'const TUNGETIFF = _TUNGETIFF_val' >> ${OUT} | |
894 | fi | |
895 | fi | |
896 | ||
897 | if ! grep '^const TUNGETSNDBUF' ${OUT} >/dev/null 2>&1; then | |
898 | if grep '^const _TUNGETSNDBUF_val' ${OUT} >/dev/null 2>&1; then | |
899 | echo 'const TUNGETSNDBUF = _TUNGETSNDBUF_val' >> ${OUT} | |
900 | fi | |
901 | fi | |
902 | ||
903 | if ! grep '^const TUNSETSNDBUF' ${OUT} >/dev/null 2>&1; then | |
904 | if grep '^const _TUNSETSNDBUF_val' ${OUT} >/dev/null 2>&1; then | |
905 | echo 'const TUNSETSNDBUF = _TUNSETSNDBUF_val' >> ${OUT} | |
906 | fi | |
907 | fi | |
908 | ||
909 | if ! grep '^const TUNATTACHFILTER' ${OUT} >/dev/null 2>&1; then | |
910 | if grep '^const _TUNATTACHFILTER_val' ${OUT} >/dev/null 2>&1; then | |
911 | echo 'const TUNATTACHFILTER = _TUNATTACHFILTER_val' >> ${OUT} | |
912 | fi | |
913 | fi | |
914 | ||
915 | if ! grep '^const TUNDETACHFILTER' ${OUT} >/dev/null 2>&1; then | |
916 | if grep '^const _TUNDETACHFILTER_val' ${OUT} >/dev/null 2>&1; then | |
917 | echo 'const TUNDETACHFILTER = _TUNDETACHFILTER_val' >> ${OUT} | |
918 | fi | |
919 | fi | |
920 | ||
d266c7e9 | 921 | if ! grep '^const TUNGETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then |
2850beb9 ILT |
922 | if grep '^const _TUNGETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then |
923 | echo 'const TUNGETVNETHDRSZ = _TUNGETVNETHDRSZ_val' >> ${OUT} | |
924 | fi | |
925 | fi | |
926 | ||
d266c7e9 | 927 | if ! grep '^const TUNSETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then |
2850beb9 ILT |
928 | if grep '^const _TUNSETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then |
929 | echo 'const TUNSETVNETHDRSZ = _TUNSETVNETHDRSZ_val' >> ${OUT} | |
930 | fi | |
931 | fi | |
932 | ||
d266c7e9 | 933 | if ! grep '^const TUNSETQUEUE' ${OUT} >/dev/null 2>&1; then |
2850beb9 ILT |
934 | if grep '^const _TUNSETQUEUE_val' ${OUT} >/dev/null 2>&1; then |
935 | echo 'const TUNSETQUEUE = _TUNSETQUEUE_val' >> ${OUT} | |
936 | fi | |
937 | fi | |
938 | ||
939 | ||
940 | if ! grep '^const TUNSETIFINDEX' ${OUT} >/dev/null 2>&1; then | |
941 | if grep '^const _TUNSETIFINDEX_val' ${OUT} >/dev/null 2>&1; then | |
942 | echo 'const TUNSETIFINDEX = _TUNSETIFINDEX_val' >> ${OUT} | |
943 | fi | |
944 | fi | |
945 | ||
946 | if ! grep '^const TUNGETFILTER' ${OUT} >/dev/null 2>&1; then | |
947 | if grep '^const _TUNGETFILTER_val' ${OUT} >/dev/null 2>&1; then | |
948 | echo 'const TUNGETFILTER = _TUNGETFILTER_val' >> ${OUT} | |
949 | fi | |
950 | fi | |
951 | ||
d8f41257 | 952 | # The ioctl flags for terminal control |
3a21b777 | 953 | grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \ |
d8f41257 | 954 | sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} |
3a21b777 ILT |
955 | if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then |
956 | if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then | |
957 | echo 'const TCGETS = _TCGETS_val' >> ${OUT} | |
958 | fi | |
959 | fi | |
960 | if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then | |
961 | if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then | |
962 | echo 'const TCSETS = _TCSETS_val' >> ${OUT} | |
963 | fi | |
964 | fi | |
d8f41257 | 965 | |
3019bbae ILT |
966 | # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but |
967 | # needs handling in syscalls.exec.go. | |
968 | if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then | |
969 | if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then | |
970 | echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT} | |
971 | fi | |
972 | fi | |
973 | ||
f163907e ILT |
974 | # If nothing else defined TIOCSCTTY, make sure it has a value. |
975 | if ! grep "const TIOCSCTTY " ${OUT} >/dev/null 2>&1; then | |
976 | echo "const TIOCSCTTY = 0" >> ${OUT} | |
977 | fi | |
978 | ||
adb0401d ILT |
979 | # The nlmsghdr struct. |
980 | grep '^type _nlmsghdr ' gen-sysinfo.go | \ | |
981 | sed -e 's/_nlmsghdr/NlMsghdr/' \ | |
982 | -e 's/nlmsg_len/Len/' \ | |
983 | -e 's/nlmsg_type/Type/' \ | |
984 | -e 's/nlmsg_flags/Flags/' \ | |
985 | -e 's/nlmsg_seq/Seq/' \ | |
986 | -e 's/nlmsg_pid/Pid/' \ | |
987 | >> ${OUT} | |
988 | ||
989 | # The nlmsg flags and operators. | |
990 | grep '^const _NLM' gen-sysinfo.go | \ | |
991 | sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
992 | ||
993 | # NLMSG_HDRLEN is defined as an expression using sizeof. | |
994 | if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then | |
f12e8bd5 ILT |
995 | if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then |
996 | echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT} | |
adb0401d ILT |
997 | fi |
998 | fi | |
999 | ||
de27caac ILT |
1000 | # The rtmsg struct. |
1001 | grep '^type _rtmsg ' gen-sysinfo.go | \ | |
1002 | sed -e 's/_rtmsg/RtMsg/' \ | |
1003 | -e 's/rtm_family/Family/' \ | |
1004 | -e 's/rtm_dst_len/Dst_len/' \ | |
1005 | -e 's/rtm_src_len/Src_len/' \ | |
1006 | -e 's/rtm_tos/Tos/' \ | |
1007 | -e 's/rtm_table/Table/' \ | |
1410c222 | 1008 | -e 's/rtm_protocol/Protocol/' \ |
de27caac ILT |
1009 | -e 's/rtm_scope/Scope/' \ |
1010 | -e 's/rtm_type/Type/' \ | |
1011 | -e 's/rtm_flags/Flags/' \ | |
1012 | >> ${OUT} | |
1013 | ||
adb0401d ILT |
1014 | # The rtgenmsg struct. |
1015 | grep '^type _rtgenmsg ' gen-sysinfo.go | \ | |
1016 | sed -e 's/_rtgenmsg/RtGenmsg/' \ | |
1017 | -e 's/rtgen_family/Family/' \ | |
1018 | >> ${OUT} | |
1019 | ||
dc570700 NB |
1020 | # The rt_msghdr struct. |
1021 | grep '^type _rt_msghdr ' gen-sysinfo.go | \ | |
1022 | sed -e 's/_rt_msghdr/RtMsghdr/g' \ | |
1023 | -e 's/rtm_msglen/Msglen/' \ | |
1024 | -e 's/rtm_version/Version/' \ | |
1025 | -e 's/rtm_type/Type/' \ | |
1026 | -e 's/rtm_index/Index/' \ | |
1027 | -e 's/rtm_flags/Flags/' \ | |
1028 | -e 's/rtm_addrs/Addrs/' \ | |
1029 | -e 's/rtm_pid/Pid/' \ | |
1030 | -e 's/rtm_seq/Seq/' \ | |
1031 | -e 's/rtm_errno/Errno/' \ | |
1032 | -e 's/rtm_use/Use/' \ | |
1033 | -e 's/rtm_inits/Inits/' \ | |
1034 | -e 's/rtm_rmx/Rmx/' \ | |
1035 | -e 's/_rt_metrics/RtMetrics/' \ | |
1036 | >> ${OUT} | |
1037 | ||
1038 | # The rt_metrics struct. | |
1039 | grep '^type _rt_metrics ' gen-sysinfo.go | \ | |
1040 | sed -e 's/_rt_metrics/RtMetrics/g' \ | |
1041 | -e 's/rmx_locks/Locks/' \ | |
1042 | -e 's/rmx_mtu/Mtu/' \ | |
1043 | -e 's/rmx_hopcount/Hopcount/' \ | |
1044 | -e 's/rmx_recvpipe/Recvpipe/' \ | |
1045 | -e 's/rmx_sendpipe/Sendpipe/' \ | |
1046 | -e 's/rmx_ssthresh/Ssthresh/' \ | |
1047 | -e 's/rmx_rtt/Rtt/' \ | |
1048 | -e 's/rmx_rttvar/Rttvar/' \ | |
1049 | -e 's/rmx_expire/Expire/' \ | |
1050 | -e 's/rmx_pksent/Pksent/' \ | |
1051 | >> ${OUT} | |
1052 | ||
adb0401d | 1053 | # The routing message flags. |
1410c222 ILT |
1054 | grep '^const _RT_' gen-sysinfo.go | \ |
1055 | sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
adb0401d ILT |
1056 | grep '^const _RTA' gen-sysinfo.go | \ |
1057 | sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
8db6380a ILT |
1058 | grep '^const _RTF' gen-sysinfo.go | \ |
1059 | sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1060 | grep '^const _RTCF' gen-sysinfo.go | \ | |
1061 | sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
adb0401d ILT |
1062 | grep '^const _RTM' gen-sysinfo.go | \ |
1063 | sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
7cf256c3 NB |
1064 | if test "${GOOS}" = "netbsd"; then |
1065 | if ! grep "RTM_RESOLVE" ${OUT} >/dev/null 2>&1; then | |
1066 | # NetBSD 8.0 removed RTM_RESOLVE, but it is part of the syscall package's | |
1067 | # stable API, so add it manually. | |
1068 | echo "const RTM_RESOLVE = 0xb" >> ${OUT} | |
1069 | fi | |
1070 | fi | |
1410c222 ILT |
1071 | grep '^const _RTN' gen-sysinfo.go | \ |
1072 | sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1073 | grep '^const _RTPROT' gen-sysinfo.go | \ | |
1074 | sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
adb0401d | 1075 | |
adb0401d ILT |
1076 | # The ifinfomsg struct. |
1077 | grep '^type _ifinfomsg ' gen-sysinfo.go | \ | |
1078 | sed -e 's/_ifinfomsg/IfInfomsg/' \ | |
1079 | -e 's/ifi_family/Family/' \ | |
1080 | -e 's/ifi_type/Type/' \ | |
1081 | -e 's/ifi_index/Index/' \ | |
1082 | -e 's/ifi_flags/Flags/' \ | |
1083 | -e 's/ifi_change/Change/' \ | |
1084 | >> ${OUT} | |
1085 | ||
dc570700 NB |
1086 | # The if_msghdr struct. Upstream uses inconsistent capitalization for this type |
1087 | # on AIX, so we do too. | |
1088 | ifmsghdr_name=IfMsghdr | |
1089 | if test "${GOOS}" = "aix"; then | |
1090 | ifmsghdr_name=IfMsgHdr | |
1091 | fi | |
9195aa17 | 1092 | grep '^type _if_msghdr ' gen-sysinfo.go | \ |
dc570700 | 1093 | sed -e "s/_if_msghdr/${ifmsghdr_name}/" \ |
9195aa17 ILT |
1094 | -e 's/ifm_msglen/Msglen/' \ |
1095 | -e 's/ifm_version/Version/' \ | |
1096 | -e 's/ifm_type/Type/' \ | |
1097 | -e 's/ifm_addrs/Addrs/' \ | |
1098 | -e 's/ifm_flags/Flags/' \ | |
1099 | -e 's/ifm_index/Index/' \ | |
1100 | -e 's/ifm_addrlen/Addrlen/' \ | |
1101 | >> ${OUT} | |
1102 | ||
dc570700 NB |
1103 | # The if_announcemsghdr struct. |
1104 | grep '^type _if_announcemsghdr ' gen-sysinfo.go | \ | |
1105 | sed -e 's/_if_announcemsghdr/IfAnnounceMsghdr/g' \ | |
1106 | -e 's/ifan_msglen/Msglen/' \ | |
1107 | -e 's/ifan_version/Version/' \ | |
1108 | -e 's/ifan_type/Type/' \ | |
1109 | -e 's/ifan_index/Index/' \ | |
1110 | -e 's/ifan_name/Name/' \ | |
1111 | -e 's/ifan_what/What/' \ | |
1112 | >> ${OUT} | |
1113 | ||
adb0401d ILT |
1114 | # The interface information types and flags. |
1115 | grep '^const _IFA' gen-sysinfo.go | \ | |
1116 | sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1117 | grep '^const _IFLA' gen-sysinfo.go | \ | |
1118 | sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1119 | grep '^const _IFF' gen-sysinfo.go | \ | |
1120 | sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
b65734ac ILT |
1121 | grep '^const _IFNAMSIZ' gen-sysinfo.go | \ |
1122 | sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
63cd53d2 CC |
1123 | grep '^const _SIOC' gen-sysinfo.go | \ |
1124 | grep -v '_val =' | \ | |
b65734ac | 1125 | sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} |
adb0401d | 1126 | |
63cd53d2 CC |
1127 | if ! grep '^const SIOCGIFMTU' ${OUT} >/dev/null 2>&1; then |
1128 | if grep '^const _SIOCGIFMTU_val' ${OUT} >/dev/null 2>&1; then | |
1129 | echo 'const SIOCGIFMTU = _SIOCGIFMTU_val' >> ${OUT} | |
1130 | fi | |
1131 | fi | |
1132 | ||
adb0401d ILT |
1133 | # The ifaddrmsg struct. |
1134 | grep '^type _ifaddrmsg ' gen-sysinfo.go | \ | |
1135 | sed -e 's/_ifaddrmsg/IfAddrmsg/' \ | |
1136 | -e 's/ifa_family/Family/' \ | |
1137 | -e 's/ifa_prefixlen/Prefixlen/' \ | |
1138 | -e 's/ifa_flags/Flags/' \ | |
1139 | -e 's/ifa_scope/Scope/' \ | |
1140 | -e 's/ifa_index/Index/' \ | |
1141 | >> ${OUT} | |
1142 | ||
dc570700 NB |
1143 | # The ifa_msghdr struct. |
1144 | grep '^type _ifa_msghdr ' gen-sysinfo.go | \ | |
1145 | sed -e 's/_ifa_msghdr/IfaMsghdr/g' \ | |
1146 | -e 's/ifam_msglen/Msglen/' \ | |
1147 | -e 's/ifam_version/Version/' \ | |
1148 | -e 's/ifam_type/Type/' \ | |
1149 | -e 's/ifam_addrs/Addrs/' \ | |
1150 | -e 's/ifam_flags/Flags/' \ | |
1151 | -e 's/ifam_metric/Metric/' \ | |
1152 | -e 's/ifam_index/Index/' \ | |
1153 | >> ${OUT} | |
1154 | ||
adb0401d ILT |
1155 | # The rtattr struct. |
1156 | grep '^type _rtattr ' gen-sysinfo.go | \ | |
1157 | sed -e 's/_rtattr/RtAttr/' \ | |
1158 | -e 's/rta_len/Len/' \ | |
1159 | -e 's/rta_type/Type/' \ | |
1160 | >> ${OUT} | |
1161 | ||
dc570700 NB |
1162 | # The bpf_version struct. |
1163 | grep '^type _bpf_version ' gen-sysinfo.go | \ | |
1164 | sed -e 's/_bpf_version/BpfVersion/g' \ | |
1165 | -e 's/bv_major/Major/' \ | |
1166 | -e 's/bv_minor/Minor/' \ | |
1167 | >> ${OUT} | |
1168 | ||
1169 | # The bpf_stat struct. | |
1170 | grep '^type _bpf_stat ' gen-sysinfo.go | \ | |
1171 | sed -e 's/_bpf_stat/BpfStat/g' \ | |
1172 | -e 's/bs_recv/Recv/' \ | |
1173 | -e 's/bs_drop/Drop/' \ | |
1174 | -e 's/bs_capt/Capt/' \ | |
1175 | -e 's/bs_padding/Padding/' \ | |
1176 | >> ${OUT} | |
1177 | ||
1178 | # The bpf_insn struct. | |
1179 | grep '^type _bpf_insn ' gen-sysinfo.go | \ | |
1180 | sed -e 's/_bpf_insn/BpfInsn/g' \ | |
1181 | -e 's/code/Code/' \ | |
1182 | -e 's/jt/Jt/' \ | |
1183 | -e 's/jf/Jf/' \ | |
1184 | -e 's/k/K/' \ | |
1185 | >> ${OUT} | |
1186 | ||
1187 | # The bpf_program struct. | |
1188 | grep '^type _bpf_program ' gen-sysinfo.go | \ | |
1189 | sed -e 's/_bpf_program/BpfProgram/g' \ | |
1190 | -e 's/bf_len/Len/' \ | |
1191 | -e 's/bf_insns/Insns/' \ | |
1192 | -e 's/_bpf_insn/BpfInsn/' \ | |
1193 | >> ${OUT} | |
1194 | ||
1195 | # The BPF ioctl constants. | |
1196 | grep '^const _BIOC' gen-sysinfo.go | \ | |
1197 | grep -v '_val =' | \ | |
1198 | sed -e 's/^\(const \)_\(BIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1199 | for c in BIOCFLUSH BIOCGBLEN BIOCGDLT BIOCGETIF BIOCGHDRCMPLT BIOCGRTIMEOUT \ | |
1200 | BIOCGSTATS BIOCIMMEDIATE BIOCPROMISC BIOCSBLEN BIOCSDLT BIOCSETF \ | |
1201 | BIOCSETIF BIOCSHDRCMPLT BIOCSRTIMEOUT BIOCVERSION | |
1202 | do | |
1203 | if ! grep "^const ${c}" ${OUT} >/dev/null 2>&1; then | |
1204 | if grep "^const _${c}_val" ${OUT} >/dev/null 2>&1; then | |
1205 | echo "const ${c} = _${c}_val" >> ${OUT} | |
1206 | fi | |
1207 | fi | |
1208 | done | |
1209 | ||
df32732f ILT |
1210 | # The in_pktinfo struct. |
1211 | grep '^type _in_pktinfo ' gen-sysinfo.go | \ | |
1212 | sed -e 's/_in_pktinfo/Inet4Pktinfo/' \ | |
1213 | -e 's/ipi_ifindex/Ifindex/' \ | |
1214 | -e 's/ipi_spec_dst/Spec_dst/' \ | |
1215 | -e 's/ipi_addr/Addr/' \ | |
f04e40af | 1216 | -e 's/_in_addr/[4]byte/g' \ |
df32732f ILT |
1217 | >> ${OUT} |
1218 | ||
1219 | # The in6_pktinfo struct. | |
1220 | grep '^type _in6_pktinfo ' gen-sysinfo.go | \ | |
1221 | sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \ | |
1222 | -e 's/ipi6_addr/Addr/' \ | |
1223 | -e 's/ipi6_ifindex/Ifindex/' \ | |
1224 | -e 's/_in6_addr/[16]byte/' \ | |
1225 | >> ${OUT} | |
1226 | ||
d8f41257 ILT |
1227 | # The termios struct. |
1228 | grep '^type _termios ' gen-sysinfo.go | \ | |
1229 | sed -e 's/_termios/Termios/' \ | |
1230 | -e 's/c_iflag/Iflag/' \ | |
1231 | -e 's/c_oflag/Oflag/' \ | |
1232 | -e 's/c_cflag/Cflag/' \ | |
1233 | -e 's/c_lflag/Lflag/' \ | |
1234 | -e 's/c_line/Line/' \ | |
1235 | -e 's/c_cc/Cc/' \ | |
1236 | -e 's/c_ispeed/Ispeed/' \ | |
1237 | -e 's/c_ospeed/Ospeed/' \ | |
1238 | >> ${OUT} | |
1239 | ||
ab61e9c4 | 1240 | # The termios constants. |
d8f41257 ILT |
1241 | for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \ |
1242 | IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \ | |
b059fba4 ILT |
1243 | OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \ |
1244 | BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \ | |
1245 | CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \ | |
1246 | ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \ | |
1247 | VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \ | |
1248 | VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \ | |
ab61e9c4 ILT |
1249 | TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \ |
1250 | B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \ | |
b059fba4 | 1251 | B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \ |
f04e40af | 1252 | B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do |
d8f41257 ILT |
1253 | |
1254 | grep "^const _$n " gen-sysinfo.go | \ | |
1255 | sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1256 | done | |
1257 | ||
5d46bf05 | 1258 | # The mount flags |
1410c222 ILT |
1259 | grep '^const _MNT_' gen-sysinfo.go | |
1260 | sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
5d46bf05 ILT |
1261 | grep '^const _MS_' gen-sysinfo.go | |
1262 | sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1263 | ||
1264 | # The fallocate flags. | |
1265 | grep '^const _FALLOC_' gen-sysinfo.go | | |
1266 | sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1267 | ||
1268 | # The statfs struct. | |
1269 | # Prefer largefile variant if available. | |
9bf54c93 | 1270 | # CentOS 5 does not have f_flags, so pull from f_spare. |
5d46bf05 | 1271 | statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true` |
4d7bfeec | 1272 | if test "$statfs" = ""; then |
0e1a6d27 ILT |
1273 | statfs=`grep '^type _statfs ' gen-sysinfo.go || true` |
1274 | fi | |
025f56b7 | 1275 | if ! echo "$statfs" | grep f_flags >/dev/null 2>&1; then |
9bf54c93 ILT |
1276 | statfs=`echo "$statfs" | sed -e 's/f_spare \[4+1\]\([^ ;]*\)/f_flags \1; f_spare [3+1]\1/'` |
1277 | fi | |
0e1a6d27 | 1278 | echo "$statfs" | sed -e 's/type _statfs64/type Statfs_t/' \ |
5d46bf05 ILT |
1279 | -e 's/type _statfs/type Statfs_t/' \ |
1280 | -e 's/f_type/Type/' \ | |
1281 | -e 's/f_bsize/Bsize/' \ | |
1282 | -e 's/f_blocks/Blocks/' \ | |
1283 | -e 's/f_bfree/Bfree/' \ | |
1284 | -e 's/f_bavail/Bavail/' \ | |
1285 | -e 's/f_files/Files/' \ | |
1286 | -e 's/f_ffree/Ffree/' \ | |
1287 | -e 's/f_fsid/Fsid/' \ | |
1288 | -e 's/f_namelen/Namelen/' \ | |
1289 | -e 's/f_frsize/Frsize/' \ | |
1290 | -e 's/f_flags/Flags/' \ | |
1291 | -e 's/f_spare/Spare/' \ | |
1292 | >> ${OUT} | |
1293 | ||
b65734ac | 1294 | # The timex struct. |
42cd8749 ILT |
1295 | timex=`grep '^type _timex ' gen-sysinfo.go || true` |
1296 | if test "$timex" = ""; then | |
1297 | timex=`grep '^// type _timex ' gen-sysinfo.go || true` | |
1298 | if test "$timex" != ""; then | |
1299 | timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'` | |
1300 | fi | |
1301 | fi | |
1302 | if test "$timex" != ""; then | |
1303 | echo "$timex" | \ | |
b65734ac ILT |
1304 | sed -e 's/_timex/Timex/' \ |
1305 | -e 's/modes/Modes/' \ | |
1306 | -e 's/offset/Offset/' \ | |
1307 | -e 's/freq/Freq/' \ | |
1308 | -e 's/maxerror/Maxerror/' \ | |
1309 | -e 's/esterror/Esterror/' \ | |
1310 | -e 's/status/Status/' \ | |
1311 | -e 's/constant/Constant/' \ | |
1312 | -e 's/precision/Precision/' \ | |
1313 | -e 's/tolerance/Tolerance/' \ | |
1314 | -e 's/ time / Time /' \ | |
1315 | -e 's/tick/Tick/' \ | |
1316 | -e 's/ppsfreq/Ppsfreq/' \ | |
1317 | -e 's/jitter/Jitter/' \ | |
1318 | -e 's/shift/Shift/' \ | |
1319 | -e 's/stabil/Stabil/' \ | |
1320 | -e 's/jitcnt/Jitcnt/' \ | |
1321 | -e 's/calcnt/Calcnt/' \ | |
1322 | -e 's/errcnt/Errcnt/' \ | |
1323 | -e 's/stbcnt/Stbcnt/' \ | |
1324 | -e 's/tai/Tai/' \ | |
1325 | -e 's/_timeval/Timeval/' \ | |
1326 | >> ${OUT} | |
42cd8749 | 1327 | fi |
b65734ac ILT |
1328 | |
1329 | # The rlimit struct. | |
2a3abc86 ILT |
1330 | # On systems that use syscall/libcall_posix_largefile.go, use rlimit64 |
1331 | # if it exists. | |
1332 | rlimit="_rlimit" | |
1333 | if test "${GOOS}" = "aix" || test "${GOOS}" = "linux" || (test "${GOOS}" = "solaris" && (test "${GOARCH}" = "386" || test "${GOARCH}" = "sparc")); then | |
1334 | if grep '^type _rlimit64 ' gen-sysinfo.go > /dev/null 2>&1; then | |
1335 | rlimit="_rlimit64" | |
1336 | fi | |
1337 | fi | |
1338 | grep "^type ${rlimit} " gen-sysinfo.go | \ | |
1339 | sed -e "s/${rlimit}/Rlimit/" \ | |
b65734ac ILT |
1340 | -e 's/rlim_cur/Cur/' \ |
1341 | -e 's/rlim_max/Max/' \ | |
1342 | >> ${OUT} | |
1343 | ||
1344 | # The RLIMIT constants. | |
1345 | grep '^const _RLIMIT_' gen-sysinfo.go | | |
1346 | sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
f04e40af | 1347 | grep '^const _RLIM_' gen-sysinfo.go | |
2a3abc86 | 1348 | grep -v '^const _RLIM_INFINITY ' | |
f04e40af | 1349 | sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} |
71caffb7 | 1350 | rliminf="" |
2a3abc86 | 1351 | if test "${rlimit}" = "_rlimit64" && grep '^const _RLIM64_INFINITY ' gen-sysinfo.go > /dev/null 2>&1; then |
71caffb7 ILT |
1352 | rliminf=`grep '^const _RLIM64_INFINITY ' gen-sysinfo.go | sed -e 's/.* //'` |
1353 | else | |
1354 | rliminf=`grep '^const _RLIM_INFINITY ' gen-sysinfo.go | sed -e 's/.* //'` | |
1355 | fi | |
1356 | # For compatibility with the gc syscall package, treat 0xffffffffffffffff as -1. | |
1357 | if test "$rliminf" = "0xffffffffffffffff"; then | |
1358 | echo "const RLIM_INFINITY = -1" >> ${OUT} | |
1359 | elif test -n "$rliminf"; then | |
1360 | echo "const RLIM_INFINITY = $rliminf" >> ${OUT} | |
2a3abc86 | 1361 | fi |
b65734ac ILT |
1362 | |
1363 | # The sysinfo struct. | |
1364 | grep '^type _sysinfo ' gen-sysinfo.go | \ | |
1365 | sed -e 's/_sysinfo/Sysinfo_t/' \ | |
1366 | -e 's/uptime/Uptime/' \ | |
1367 | -e 's/loads/Loads/' \ | |
1368 | -e 's/totalram/Totalram/' \ | |
1369 | -e 's/freeram/Freeram/' \ | |
1370 | -e 's/sharedram/Sharedram/' \ | |
1371 | -e 's/bufferram/Bufferram/' \ | |
1372 | -e 's/totalswap/Totalswap/' \ | |
1373 | -e 's/freeswap/Freeswap/' \ | |
1374 | -e 's/procs/Procs/' \ | |
1375 | -e 's/totalhigh/Totalhigh/' \ | |
1376 | -e 's/freehigh/Freehigh/' \ | |
1377 | -e 's/mem_unit/Unit/' \ | |
1378 | >> ${OUT} | |
1379 | ||
b65734ac ILT |
1380 | # The utimbuf struct. |
1381 | grep '^type _utimbuf ' gen-sysinfo.go | \ | |
1382 | sed -e 's/_utimbuf/Utimbuf/' \ | |
1383 | -e 's/actime/Actime/' \ | |
1384 | -e 's/modtime/Modtime/' \ | |
1385 | >> ${OUT} | |
1386 | ||
1410c222 ILT |
1387 | # The LOCK flags for flock. |
1388 | grep '^const _LOCK_' gen-sysinfo.go | | |
1389 | sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1390 | ||
d5b18b0b ILT |
1391 | # The PRIO constants. |
1392 | grep '^const _PRIO_' gen-sysinfo.go | \ | |
1393 | sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1394 | ||
b65734ac ILT |
1395 | # The GNU/Linux LINUX_REBOOT flags. |
1396 | grep '^const _LINUX_REBOOT_' gen-sysinfo.go | | |
1397 | sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1398 | ||
1399 | # The GNU/Linux sock_filter struct. | |
1400 | grep '^type _sock_filter ' gen-sysinfo.go | \ | |
1401 | sed -e 's/_sock_filter/SockFilter/' \ | |
1402 | -e 's/code/Code/' \ | |
1403 | -e 's/jt/Jt/' \ | |
1404 | -e 's/jf/Jf/' \ | |
1405 | -e 's/k /K /' \ | |
1406 | >> ${OUT} | |
1407 | ||
1408 | # The GNU/Linux sock_fprog struct. | |
1409 | grep '^type _sock_fprog ' gen-sysinfo.go | \ | |
1410 | sed -e 's/_sock_fprog/SockFprog/' \ | |
1411 | -e 's/len/Len/' \ | |
1412 | -e 's/filter/Filter/' \ | |
1413 | -e 's/_sock_filter/SockFilter/' \ | |
1414 | >> ${OUT} | |
1415 | ||
8db6380a ILT |
1416 | # The GNU/Linux filter flags. |
1417 | grep '^const _BPF_' gen-sysinfo.go | \ | |
1418 | sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1419 | ||
df32732f ILT |
1420 | # The GNU/Linux nlattr struct. |
1421 | grep '^type _nlattr ' gen-sysinfo.go | \ | |
1422 | sed -e 's/_nlattr/NlAttr/' \ | |
1423 | -e 's/nla_len/Len/' \ | |
1424 | -e 's/nla_type/Type/' \ | |
1425 | >> ${OUT} | |
1426 | ||
1427 | # The GNU/Linux nlmsgerr struct. | |
1428 | grep '^type _nlmsgerr ' gen-sysinfo.go | \ | |
1429 | sed -e 's/_nlmsgerr/NlMsgerr/' \ | |
1430 | -e 's/error/Error/' \ | |
1431 | -e 's/msg/Msg/' \ | |
f04e40af | 1432 | -e 's/_nlmsghdr/NlMsghdr/' \ |
df32732f ILT |
1433 | >> ${OUT} |
1434 | ||
1435 | # The GNU/Linux rtnexthop struct. | |
1436 | grep '^type _rtnexthop ' gen-sysinfo.go | \ | |
1437 | sed -e 's/_rtnexthop/RtNexthop/' \ | |
1438 | -e 's/rtnh_len/Len/' \ | |
1439 | -e 's/rtnh_flags/Flags/' \ | |
1440 | -e 's/rtnh_hops/Hops/' \ | |
1441 | -e 's/rtnh_ifindex/Ifindex/' \ | |
1442 | >> ${OUT} | |
1443 | ||
1410c222 ILT |
1444 | # The GNU/Linux netlink flags. |
1445 | grep '^const _NETLINK_' gen-sysinfo.go | \ | |
1446 | sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
474c8a07 | 1447 | grep '^const _NLA_' gen-sysinfo.go | grep -v '_val =' | \ |
f04e40af | 1448 | sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} |
1410c222 | 1449 | |
474c8a07 ILT |
1450 | if ! grep '^const NLA_HDRLEN' ${OUT} >/dev/null 2>&1; then |
1451 | if grep '^const _NLA_HDRLEN_val' ${OUT} >/dev/null 2>&1; then | |
1452 | echo 'const NLA_HDRLEN = _NLA_HDRLEN_val' >> ${OUT} | |
1453 | fi | |
1454 | fi | |
1455 | ||
1410c222 ILT |
1456 | # The GNU/Linux packet socket flags. |
1457 | grep '^const _PACKET_' gen-sysinfo.go | \ | |
1458 | sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
1459 | ||
df32732f ILT |
1460 | # The GNU/Linux inotify_event struct. |
1461 | grep '^type _inotify_event ' gen-sysinfo.go | \ | |
1462 | sed -e 's/_inotify_event/InotifyEvent/' \ | |
1463 | -e 's/wd/Wd/' \ | |
1464 | -e 's/mask/Mask/' \ | |
1465 | -e 's/cookie/Cookie/' \ | |
1466 | -e 's/len/Len/' \ | |
1467 | -e 's/name/Name/' \ | |
1468 | -e 's/\[\]/[0]/' \ | |
f04e40af | 1469 | -e 's/\[0\]byte/[0]int8/' \ |
df32732f ILT |
1470 | >> ${OUT} |
1471 | ||
d3b4df0b ILT |
1472 | # The GNU/Linux CLONE flags. |
1473 | grep '^const _CLONE_' gen-sysinfo.go | \ | |
1474 | sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT} | |
7372dfe4 ILT |
1475 | # We need some CLONE constants that are not defined in older versions |
1476 | # of glibc. | |
1477 | if ! grep '^const CLONE_NEWUSER ' ${OUT} > /dev/null 2>&1; then | |
1478 | echo "const CLONE_NEWUSER = 0x10000000" >> ${OUT} | |
1479 | fi | |
bbc824cd ILT |
1480 | if ! grep '^const CLONE_NEWNET ' ${OUT} > /dev/null 2>&1; then |
1481 | echo "const CLONE_NEWNET = 0x40000000" >> ${OUT} | |
1482 | fi | |
d3b4df0b | 1483 | |
f12e8bd5 ILT |
1484 | # Struct sizes. |
1485 | set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \ | |
dc570700 NB |
1486 | ifaddrmsg IfAddrmsg ifa_msghdr IfaMsghdr ifinfomsg IfInfomsg \ |
1487 | if_msghdr IfMsghdr in_pktinfo Inet4Pktinfo in6_pktinfo Inet6Pktinfo \ | |
1488 | inotify_event InotifyEvent linger Linger msghdr Msghdr nlattr NlAttr \ | |
1489 | nlmsgerr NlMsgerr nlmsghdr NlMsghdr rtattr RtAttr rt_msghdr RtMsghdr \ | |
1490 | rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \ | |
f038dae6 | 1491 | sock_filter SockFilter sock_fprog SockFprog ucred Ucred \ |
6b2cd37b | 1492 | icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo |
f12e8bd5 ILT |
1493 | while test $# != 0; do |
1494 | nc=$1 | |
1495 | ngo=$2 | |
1496 | shift | |
1497 | shift | |
1498 | if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then | |
1499 | echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT} | |
1500 | fi | |
1501 | done | |
1502 | ||
1503 | # In order to compile the net package, we need some sizes to exist | |
1504 | # even if the types do not. | |
1505 | if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then | |
1506 | echo 'const SizeofIPMreq = 8' >> ${OUT} | |
1507 | fi | |
1508 | if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then | |
1509 | echo 'const SizeofIPv6Mreq = 20' >> ${OUT} | |
1510 | fi | |
1511 | if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then | |
1512 | echo 'const SizeofIPMreqn = 12' >> ${OUT} | |
1513 | fi | |
f038dae6 ILT |
1514 | if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then |
1515 | echo 'const SizeofICMPv6Filter = 32' >> ${OUT} | |
1516 | fi | |
f12e8bd5 | 1517 | |
ab2d47a8 ILT |
1518 | # Type 'uint128' is needed in a couple of type definitions on arm64,such |
1519 | # as _user_fpsimd_struct, _elf_fpregset_t, etc. | |
1520 | if ! grep '^type uint128' ${OUT} > /dev/null 2>&1; then | |
1521 | echo "type uint128 [16]byte" >> ${OUT} | |
1522 | fi | |
1523 | ||
7a938933 | 1524 | exit $? |