runtime: complete defer handling in CgocallBackDone
[official-gcc.git] / libgo / mksysinfo.sh
blob8fd8eadefc626241c1813002588283e52bca956c
1 #!/bin/sh
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.
7 # Create sysinfo.go from gen-sysinfo.go and errno.i.
9 # This shell script creates the sysinfo.go file which holds types and
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.
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.
18 OUT=tmp-sysinfo.go
20 set -e
22 echo 'package syscall' > ${OUT}
23 echo 'import "unsafe"' >> ${OUT}
24 echo 'type _ unsafe.Pointer' >> ${OUT}
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' | \
32 grep -v '^type _timeval ' | \
33 grep -v '^type _timespec_t ' | \
34 grep -v '^type _timespec ' | \
35 grep -v '^type _timestruc_t ' | \
36 grep -v '^type _epoll_' | \
37 grep -v 'in6_addr' | \
38 grep -v 'sockaddr_in6' | \
39 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
40 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
41 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
42 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
43 >> ${OUT}
45 # On AIX, the _arpcom struct, is filtered by the above grep sequence, as it as
46 # a field of type _in6_addr, but other types depend on _arpcom, so we need to
47 # put it back.
48 grep '^type _arpcom ' gen-sysinfo.go | \
49 sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
51 # The errno constants. These get type Errno.
52 egrep '#define E[A-Z0-9_]+ ' errno.i | \
53 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
55 # The O_xxx flags.
56 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
57 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
58 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
59 echo "const O_ASYNC = 0" >> ${OUT}
61 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
62 echo "const O_CLOEXEC = 0" >> ${OUT}
65 # The os package requires F_DUPFD_CLOEXEC to be defined.
66 if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
67 echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
70 # AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
71 # which leads to a constant overflow when using O_CLOEXEC in some
72 # go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
73 # more present in 7.2 (_FCLOEXEC is a 32 bit value).
74 if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
75 sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
76 mv ${OUT}-2 ${OUT}
79 # These flags can be lost on i386 GNU/Linux when using
80 # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
81 # before we see the definition of F_SETLK64.
82 for flag in F_GETLK F_SETLK F_SETLKW; do
83 if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
84 && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
85 echo "const ${flag} = ${flag}64" >> ${OUT}
87 done
89 # The Flock_t struct for fcntl.
90 grep '^type _flock ' gen-sysinfo.go | \
91 sed -e 's/type _flock/type Flock_t/' \
92 -e 's/l_type/Type/' \
93 -e 's/l_whence/Whence/' \
94 -e 's/l_start/Start/' \
95 -e 's/l_len/Len/' \
96 -e 's/l_pid/Pid/' \
97 >> ${OUT}
99 # The signal numbers.
100 grep '^const _SIG[^_]' gen-sysinfo.go | \
101 grep -v '^const _SIGEV_' | \
102 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
103 if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
104 if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
105 echo "const SIGPOLL = SIGIO" >> ${OUT}
108 if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
109 if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
110 echo "const SIGCLD = SIGCHLD" >> ${OUT}
114 # The syscall numbers. We force the names to upper case.
115 grep '^const _SYS_' gen-sysinfo.go | \
116 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
117 while read sys; do
118 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
119 echo "const $sup = _$sys" >> ${OUT}
120 done
122 # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
123 if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
124 echo "const SYS_GETDENTS = 0" >> ${OUT}
126 if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
127 echo "const SYS_GETDENTS64 = 0" >> ${OUT}
130 # Stat constants.
131 grep '^const _S_' gen-sysinfo.go | \
132 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
134 # Mmap constants.
135 grep '^const _PROT_' gen-sysinfo.go | \
136 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
137 grep '^const _MAP_' gen-sysinfo.go | \
138 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
139 grep '^const _MADV_' gen-sysinfo.go | \
140 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
141 grep '^const _MCL_' gen-sysinfo.go | \
142 sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
144 # Process status constants.
145 grep '^const _W' gen-sysinfo.go |
146 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
147 # WSTOPPED was introduced in glibc 2.3.4.
148 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
149 if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
150 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
151 else
152 echo 'const WSTOPPED = 2' >> ${OUT}
155 if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
156 && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
157 echo 'const WALL = ___WALL' >> ${OUT}
160 # Networking constants.
161 egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
162 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
163 grep '^const _SOMAXCONN' gen-sysinfo.go |
164 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
165 >> ${OUT}
166 grep '^const _SHUT_' gen-sysinfo.go |
167 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
169 # The net package requires some const definitions.
170 for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
171 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
172 echo "const $m = 0" >> ${OUT}
174 done
175 for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
176 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
177 echo "const $m = -1" >> ${OUT}
179 done
181 # The syscall package requires AF_LOCAL.
182 if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
183 if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
184 echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
188 # sysconf constants.
189 grep '^const __SC' gen-sysinfo.go |
190 sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
192 # pathconf constants.
193 grep '^const __PC' gen-sysinfo.go |
194 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
196 # The PATH_MAX constant.
197 if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
198 echo 'const PathMax = _PATH_MAX' >> ${OUT}
201 # epoll constants.
202 grep '^const _EPOLL' gen-sysinfo.go |
203 grep -v EPOLLET |
204 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
205 # Make sure EPOLLET is positive.
206 if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go >/dev/null 2>&1; then
207 grep '^const _EPOLLET ' gen-sysinfo.go |
208 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
209 else
210 echo "const EPOLLET = 0x80000000" >> ${OUT}
212 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
213 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
214 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
216 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
217 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
220 # Prctl constants.
221 grep '^const _PR_' gen-sysinfo.go |
222 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
224 # Ptrace constants.
225 grep '^const _PTRACE' gen-sysinfo.go |
226 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
227 # We need some ptrace options that are not defined in older versions
228 # of glibc.
229 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
230 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
232 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
233 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
235 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
236 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
238 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
239 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
241 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
242 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
244 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
245 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
247 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
248 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
250 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
251 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
253 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
254 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
256 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
257 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
259 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
260 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
262 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
263 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
265 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
266 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
268 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
269 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
271 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
272 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
274 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
275 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
277 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
278 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
281 # A helper function that prints a structure from gen-sysinfo.go with the first
282 # letter of the field names in upper case. $1 is the name of structure. If $2
283 # is not empty, the structure or type is renamed to $2.
284 upcase_fields () {
285 name="$1"
286 def=`grep "^type $name " gen-sysinfo.go`
287 fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
288 prefix=`echo $def | sed -e 's/{.*//'`
289 if test "$2" != ""; then
290 prefix=`echo $prefix | sed -e "s/$1/$2/"`
292 if test "$fields" != ""; then
293 nfields=
294 while test -n "$fields"; do
295 field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'`
296 fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
297 # capitalize the next character.
298 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
299 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
300 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
301 field="$f$r"
302 nfields="$nfields $field;"
303 done
304 echo "${prefix} {$nfields }"
308 # The registers returned by PTRACE_GETREGS. This is probably
309 # GNU/Linux specific; it should do no harm if there is no
310 # _user_regs_struct.
311 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
312 if test "$regs" = ""; then
313 # s390
314 regs=`grep '^type __user_regs_struct struct' gen-sysinfo.go || true`
315 if test "$regs" != ""; then
316 # Substructures of __user_regs_struct on s390
317 upcase_fields "__user_psw_struct" "PtracePsw" >> ${OUT} || true
318 upcase_fields "__user_fpregs_struct" "PtraceFpregs" >> ${OUT} || true
319 upcase_fields "__user_per_struct" "PtracePer" >> ${OUT} || true
320 else
321 # mips*
322 regs=`grep '^type _pt_regs struct' gen-sysinfo.go || true`
325 if test "$regs" != ""; then
326 regs=`echo $regs | sed -e 's/type _pt_regs struct//'`
327 regs=`echo $regs |
328 sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
329 regs=`echo $regs | sed -e s'/^ *//'`
330 nregs=
331 while test -n "$regs"; do
332 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
333 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
334 # Capitalize the first character of the field.
335 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
336 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
337 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
338 field="$f$r"
339 field=`echo "$field" | sed \
340 -e 's/__user_psw_struct/PtracePsw/' \
341 -e 's/__user_fpregs_struct/PtraceFpregs/' \
342 -e 's/__user_per_struct/PtracePer/'`
343 nregs="$nregs $field;"
344 done
345 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
348 # Some basic types.
349 echo 'type Size_t _size_t' >> ${OUT}
350 echo "type Ssize_t _ssize_t" >> ${OUT}
351 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
352 echo "type Offset_t _off64_t" >> ${OUT}
353 else
354 echo "type Offset_t _off_t" >> ${OUT}
356 echo "type Mode_t _mode_t" >> ${OUT}
357 echo "type Pid_t _pid_t" >> ${OUT}
358 echo "type Uid_t _uid_t" >> ${OUT}
359 echo "type Gid_t _gid_t" >> ${OUT}
360 echo "type Socklen_t _socklen_t" >> ${OUT}
362 # The C int type.
363 sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
364 if test "$sizeof_int" = "4"; then
365 echo "type _C_int int32" >> ${OUT}
366 echo "type _C_uint uint32" >> ${OUT}
367 elif test "$sizeof_int" = "8"; then
368 echo "type _C_int int64" >> ${OUT}
369 echo "type _C_uint uint64" >> ${OUT}
370 else
371 echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
372 exit 1
375 # The C long type, needed because that is the type that ptrace returns.
376 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
377 if test "$sizeof_long" = "4"; then
378 echo "type _C_long int32" >> ${OUT}
379 echo "type _C_ulong uint32" >> ${OUT}
380 elif test "$sizeof_long" = "8"; then
381 echo "type _C_long int64" >> ${OUT}
382 echo "type _C_ulong uint64" >> ${OUT}
383 else
384 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
385 exit 1
388 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
389 # double is commented by -fdump-go-spec.
390 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
391 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
393 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
394 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
397 # The time_t type.
398 if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
399 echo 'type Time_t _time_t' >> ${OUT}
402 # The time structures need special handling: we need to name the
403 # types, so that we can cast integers to the right types when
404 # assigning to the structures.
405 timeval=`grep '^type _timeval ' gen-sysinfo.go`
406 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
407 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
408 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
409 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
410 echo $timeval | \
411 sed -e 's/type _timeval /type Timeval /' \
412 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
413 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
414 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
415 if test "$timespec" = ""; then
416 # IRIX 6.5 has __timespec instead.
417 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
419 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
420 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
421 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
422 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
423 echo $timespec | \
424 sed -e 's/^type ___timespec /type Timespec /' \
425 -e 's/^type _timespec /type Timespec /' \
426 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
427 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
429 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
430 if test "$timestruc" != ""; then
431 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
432 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
433 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
434 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
435 echo $timestruc | \
436 sed -e 's/^type _timestruc_t /type Timestruc /' \
437 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
438 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
441 # The tms struct.
442 grep '^type _tms ' gen-sysinfo.go | \
443 sed -e 's/type _tms/type Tms/' \
444 -e 's/tms_utime/Utime/' \
445 -e 's/tms_stime/Stime/' \
446 -e 's/tms_cutime/Cutime/' \
447 -e 's/tms_cstime/Cstime/' \
448 >> ${OUT}
450 # The stat type.
451 # Prefer largefile variant if available.
452 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
453 if test "$stat" != ""; then
454 grep '^type _stat64 ' gen-sysinfo.go
455 else
456 grep '^type _stat ' gen-sysinfo.go
457 fi | sed -e 's/type _stat64/type Stat_t/' \
458 -e 's/type _stat/type Stat_t/' \
459 -e 's/st_dev/Dev/' \
460 -e 's/st_ino/Ino/g' \
461 -e 's/st_nlink/Nlink/' \
462 -e 's/st_mode/Mode/' \
463 -e 's/st_uid/Uid/' \
464 -e 's/st_gid/Gid/' \
465 -e 's/st_rdev/Rdev/' \
466 -e 's/st_size/Size/' \
467 -e 's/st_blksize/Blksize/' \
468 -e 's/st_blocks/Blocks/' \
469 -e 's/st_atim/Atim/' \
470 -e 's/st_mtim/Mtim/' \
471 -e 's/st_ctim/Ctim/' \
472 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
473 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
474 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
475 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
476 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
477 >> ${OUT}
479 # The directory searching types.
480 # Prefer largefile variant if available.
481 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
482 if test "$dirent" != ""; then
483 grep '^type _dirent64 ' gen-sysinfo.go
484 else
485 grep '^type _dirent ' gen-sysinfo.go
486 fi | sed -e 's/type _dirent64/type Dirent/' \
487 -e 's/type _dirent/type Dirent/' \
488 -e 's/d_name \[0+1\]/d_name [0+256]/' \
489 -e 's/d_name/Name/' \
490 -e 's/]int8/]byte/' \
491 -e 's/d_ino/Ino/' \
492 -e 's/d_off/Off/' \
493 -e 's/d_reclen/Reclen/' \
494 -e 's/d_type/Type/' \
495 >> ${OUT}
496 echo "type DIR _DIR" >> ${OUT}
498 # Values for d_type field in dirent.
499 grep '^const _DT_' gen-sysinfo.go |
500 sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
502 # The rusage struct.
503 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
504 if test "$rusage" != ""; then
505 # Remove anonymous unions from GNU/Linux <bits/resource.h>.
506 rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'`
507 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
508 rusage=`echo $rusage | sed -e 's/^ *//'`
509 nrusage=
510 while test -n "$rusage"; do
511 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
512 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
513 # Drop the leading ru_, capitalize the next character.
514 field=`echo $field | sed -e 's/^ru_//'`
515 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
516 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
517 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
518 # Fix _timeval _timespec, and _timestruc_t.
519 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
520 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
521 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
522 field="$f$r"
523 nrusage="$nrusage $field;"
524 done
525 echo "type Rusage struct {$nrusage }" >> ${OUT}
526 else
527 echo "type Rusage struct {}" >> ${OUT}
530 # The RUSAGE constants.
531 grep '^const _RUSAGE_' gen-sysinfo.go | \
532 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
534 # The utsname struct.
535 grep '^type _utsname ' gen-sysinfo.go | \
536 sed -e 's/_utsname/Utsname/' \
537 -e 's/sysname/Sysname/' \
538 -e 's/nodename/Nodename/' \
539 -e 's/release/Release/' \
540 -e 's/version/Version/' \
541 -e 's/machine/Machine/' \
542 -e 's/domainname/Domainname/' \
543 >> ${OUT}
545 # The iovec struct.
546 iovec=`grep '^type _iovec ' gen-sysinfo.go`
547 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
548 echo "type Iovec_len_t $iovec_len" >> ${OUT}
549 echo $iovec | \
550 sed -e 's/_iovec/Iovec/' \
551 -e 's/iov_base/Base/' \
552 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
553 >> ${OUT}
555 # The msghdr struct.
556 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
557 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
558 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
559 echo $msghdr | \
560 sed -e 's/_msghdr/Msghdr/' \
561 -e 's/msg_name/Name/' \
562 -e 's/msg_namelen/Namelen/' \
563 -e 's/msg_iov/Iov/' \
564 -e 's/msg_iovlen/Iovlen/' \
565 -e 's/_iovec/Iovec/' \
566 -e 's/msg_control/Control/' \
567 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
568 -e 's/msg_flags/Flags/' \
569 >> ${OUT}
571 # The MSG_ flags for Msghdr.
572 grep '^const _MSG_' gen-sysinfo.go | \
573 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
575 # The cmsghdr struct.
576 cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
577 if test -n "$cmsghdr"; then
578 cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
579 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
580 echo "$cmsghdr" | \
581 sed -e 's/_cmsghdr/Cmsghdr/' \
582 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
583 -e 's/cmsg_level/Level/' \
584 -e 's/cmsg_type/Type/' \
585 -e 's/\[\]/[0]/' \
586 >> ${OUT}
589 # The SCM_ flags for Cmsghdr.
590 grep '^const _SCM_' gen-sysinfo.go | \
591 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
593 # The ucred struct.
594 upcase_fields "_ucred" "Ucred" >> ${OUT} || true
596 # The ip_mreq struct.
597 grep '^type _ip_mreq ' gen-sysinfo.go | \
598 sed -e 's/_ip_mreq/IPMreq/' \
599 -e 's/imr_multiaddr/Multiaddr/' \
600 -e 's/imr_interface/Interface/' \
601 -e 's/_in_addr/[4]byte/g' \
602 >> ${OUT}
604 # We need IPMreq to compile the net package.
605 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
606 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
609 # The ipv6_mreq struct.
610 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
611 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
612 -e 's/ipv6mr_multiaddr/Multiaddr/' \
613 -e 's/ipv6mr_interface/Interface/' \
614 -e 's/_in6_addr/[16]byte/' \
615 >> ${OUT}
617 # We need IPv6Mreq to compile the net package.
618 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
619 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
622 # The ip_mreqn struct.
623 grep '^type _ip_mreqn ' gen-sysinfo.go | \
624 sed -e 's/_ip_mreqn/IPMreqn/' \
625 -e 's/imr_multiaddr/Multiaddr/' \
626 -e 's/imr_address/Address/' \
627 -e 's/imr_ifindex/Ifindex/' \
628 -e 's/_in_addr/[4]byte/g' \
629 >> ${OUT}
631 # We need IPMreq to compile the net package.
632 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
633 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
636 # The icmp6_filter struct.
637 grep '^type _icmp6_filter ' gen-sysinfo.go | \
638 sed -e 's/_icmp6_filter/ICMPv6Filter/' \
639 -e 's/data/Data/' \
640 -e 's/filt/Filt/' \
641 >> ${OUT}
643 # We need ICMPv6Filter to compile the syscall package.
644 if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
645 echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
648 # The ip6_mtuinfo struct.
649 grep '^type _ip6_mtuinfo ' gen-sysinfo.go | \
650 sed -e 's/_ip6_mtuinfo/IPv6MTUInfo/' \
651 -e 's/ip6m_addr/Addr/' \
652 -e 's/_sockaddr_in6/RawSockaddrInet6/' \
653 -e 's/ip6m_mtu/Mtu/' \
654 >> ${OUT}
656 # Try to guess the type to use for fd_set.
657 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
658 fds_bits_type="_C_long"
659 if test "$fd_set" != ""; then
660 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
662 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
664 # The addrinfo struct.
665 grep '^type _addrinfo ' gen-sysinfo.go | \
666 sed -e 's/_addrinfo/Addrinfo/g' \
667 -e 's/ ai_/ Ai_/g' \
668 >> ${OUT}
670 # The addrinfo and nameinfo flags and errors.
671 grep '^const _AI_' gen-sysinfo.go | \
672 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
673 grep '^const _EAI_' gen-sysinfo.go | \
674 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
675 grep '^const _NI_' gen-sysinfo.go | \
676 sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
678 # If nothing else defined EAI_OVERFLOW, make sure it has a value.
679 if ! grep "const EAI_OVERFLOW " ${OUT} >/dev/null 2>&1; then
680 echo "const EAI_OVERFLOW = 0" >> ${OUT}
683 # The passwd struct.
684 grep '^type _passwd ' gen-sysinfo.go | \
685 sed -e 's/_passwd/Passwd/' \
686 -e 's/ pw_/ Pw_/g' \
687 >> ${OUT}
689 # The group struct.
690 grep '^type _group ' gen-sysinfo.go | \
691 sed -e 's/_group/Group/' \
692 -e 's/ gr_/ Gr_/g' \
693 >> ${OUT}
695 # The ioctl flags for the controlling TTY.
696 grep '^const _TIOC' gen-sysinfo.go | \
697 grep -v '_val =' | \
698 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
699 grep '^const _TUNSET' gen-sysinfo.go | \
700 grep -v '_val =' | \
701 sed -e 's/^\(const \)_\(TUNSET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
702 # We need TIOCGWINSZ.
703 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
704 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
705 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
708 if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
709 if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
710 echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
713 if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
714 if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
715 echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
718 if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
719 if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
720 echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
723 if ! grep '^const TIOCGPGRP' ${OUT} >/dev/null 2>&1; then
724 if grep '^const _TIOCGPGRP_val' ${OUT} >/dev/null 2>&1; then
725 echo 'const TIOCGPGRP = _TIOCGPGRP_val' >> ${OUT}
728 if ! grep '^const TIOCSPGRP' ${OUT} >/dev/null 2>&1; then
729 if grep '^const _TIOCSPGRP_val' ${OUT} >/dev/null 2>&1; then
730 echo 'const TIOCSPGRP = _TIOCSPGRP_val' >> ${OUT}
733 if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
734 if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
735 echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
738 if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
739 if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
740 echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
743 if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
744 if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
745 echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
748 if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
749 if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
750 echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
754 if ! grep '^const TUNSETNOCSUM' ${OUT} >/dev/null 2>&1; then
755 if grep '^const _TUNSETNOCSUM_val' ${OUT} >/dev/null 2>&1; then
756 echo 'const TUNSETNOCSUM = _TUNSETNOCSUM_val' >> ${OUT}
760 if ! grep '^const TUNSETDEBUG' ${OUT} >/dev/null 2>&1; then
761 if grep '^const _TUNSETDEBUG_val' ${OUT} >/dev/null 2>&1; then
762 echo 'const TUNSETDEBUG = _TUNSETDEBUG_val' >> ${OUT}
766 if ! grep '^const TUNSETIFF' ${OUT} >/dev/null 2>&1; then
767 if grep '^const _TUNSETIFF_val' ${OUT} >/dev/null 2>&1; then
768 echo 'const TUNSETIFF = _TUNSETIFF_val' >> ${OUT}
772 if ! grep '^const TUNSETPERSIST' ${OUT} >/dev/null 2>&1; then
773 if grep '^const _TUNSETPERSIST_val' ${OUT} >/dev/null 2>&1; then
774 echo 'const TUNSETPERSIST = _TUNSETPERSIST_val' >> ${OUT}
778 if ! grep '^const TUNSETOWNER' ${OUT} >/dev/null 2>&1; then
779 if grep '^const _TUNSETOWNER_val' ${OUT} >/dev/null 2>&1; then
780 echo 'const TUNSETOWNER = _TUNSETOWNER_val' >> ${OUT}
784 if ! grep '^const TUNSETLINK' ${OUT} >/dev/null 2>&1; then
785 if grep '^const _TUNSETLINK_val' ${OUT} >/dev/null 2>&1; then
786 echo 'const TUNSETLINK = _TUNSETLINK_val' >> ${OUT}
790 if ! grep '^const TUNSETGROUP' ${OUT} >/dev/null 2>&1; then
791 if grep '^const _TUNSETGROUP_val' ${OUT} >/dev/null 2>&1; then
792 echo 'const TUNSETGROUP = _TUNSETGROUP_val' >> ${OUT}
796 if ! grep '^const TUNGETFEATURES' ${OUT} >/dev/null 2>&1; then
797 if grep '^const _TUNGETFEATURES_val' ${OUT} >/dev/null 2>&1; then
798 echo 'const TUNGETFEATURES = _TUNGETFEATURES_val' >> ${OUT}
802 if ! grep '^const TUNSETOFFLOAD' ${OUT} >/dev/null 2>&1; then
803 if grep '^const _TUNSETOFFLOAD_val' ${OUT} >/dev/null 2>&1; then
804 echo 'const TUNSETOFFLOAD = _TUNSETOFFLOAD_val' >> ${OUT}
808 if ! grep '^const TUNSETTXFILTER' ${OUT} >/dev/null 2>&1; then
809 if grep '^const _TUNSETTXFILTER_val' ${OUT} >/dev/null 2>&1; then
810 echo 'const TUNSETTXFILTER = _TUNSETTXFILTER_val' >> ${OUT}
814 if ! grep '^const TUNGETIFF' ${OUT} >/dev/null 2>&1; then
815 if grep '^const _TUNGETIFF_val' ${OUT} >/dev/null 2>&1; then
816 echo 'const TUNGETIFF = _TUNGETIFF_val' >> ${OUT}
820 if ! grep '^const TUNGETSNDBUF' ${OUT} >/dev/null 2>&1; then
821 if grep '^const _TUNGETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
822 echo 'const TUNGETSNDBUF = _TUNGETSNDBUF_val' >> ${OUT}
826 if ! grep '^const TUNSETSNDBUF' ${OUT} >/dev/null 2>&1; then
827 if grep '^const _TUNSETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
828 echo 'const TUNSETSNDBUF = _TUNSETSNDBUF_val' >> ${OUT}
832 if ! grep '^const TUNATTACHFILTER' ${OUT} >/dev/null 2>&1; then
833 if grep '^const _TUNATTACHFILTER_val' ${OUT} >/dev/null 2>&1; then
834 echo 'const TUNATTACHFILTER = _TUNATTACHFILTER_val' >> ${OUT}
838 if ! grep '^const TUNDETACHFILTER' ${OUT} >/dev/null 2>&1; then
839 if grep '^const _TUNDETACHFILTER_val' ${OUT} >/dev/null 2>&1; then
840 echo 'const TUNDETACHFILTER = _TUNDETACHFILTER_val' >> ${OUT}
844 if ! grep '^const TUNGETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
845 if grep '^const _TUNGETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
846 echo 'const TUNGETVNETHDRSZ = _TUNGETVNETHDRSZ_val' >> ${OUT}
850 if ! grep '^const TUNSETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
851 if grep '^const _TUNSETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
852 echo 'const TUNSETVNETHDRSZ = _TUNSETVNETHDRSZ_val' >> ${OUT}
856 if ! grep '^const TUNSETQUEUE' ${OUT} >/dev/null 2>&1; then
857 if grep '^const _TUNSETQUEUE_val' ${OUT} >/dev/null 2>&1; then
858 echo 'const TUNSETQUEUE = _TUNSETQUEUE_val' >> ${OUT}
863 if ! grep '^const TUNSETIFINDEX' ${OUT} >/dev/null 2>&1; then
864 if grep '^const _TUNSETIFINDEX_val' ${OUT} >/dev/null 2>&1; then
865 echo 'const TUNSETIFINDEX = _TUNSETIFINDEX_val' >> ${OUT}
869 if ! grep '^const TUNGETFILTER' ${OUT} >/dev/null 2>&1; then
870 if grep '^const _TUNGETFILTER_val' ${OUT} >/dev/null 2>&1; then
871 echo 'const TUNGETFILTER = _TUNGETFILTER_val' >> ${OUT}
875 # The ioctl flags for terminal control
876 grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
877 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
878 if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
879 if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
880 echo 'const TCGETS = _TCGETS_val' >> ${OUT}
883 if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
884 if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
885 echo 'const TCSETS = _TCSETS_val' >> ${OUT}
889 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
890 # needs handling in syscalls.exec.go.
891 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
892 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
893 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
897 # If nothing else defined TIOCSCTTY, make sure it has a value.
898 if ! grep "const TIOCSCTTY " ${OUT} >/dev/null 2>&1; then
899 echo "const TIOCSCTTY = 0" >> ${OUT}
902 # The nlmsghdr struct.
903 grep '^type _nlmsghdr ' gen-sysinfo.go | \
904 sed -e 's/_nlmsghdr/NlMsghdr/' \
905 -e 's/nlmsg_len/Len/' \
906 -e 's/nlmsg_type/Type/' \
907 -e 's/nlmsg_flags/Flags/' \
908 -e 's/nlmsg_seq/Seq/' \
909 -e 's/nlmsg_pid/Pid/' \
910 >> ${OUT}
912 # The nlmsg flags and operators.
913 grep '^const _NLM' gen-sysinfo.go | \
914 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
916 # NLMSG_HDRLEN is defined as an expression using sizeof.
917 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
918 if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
919 echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
923 # The rtmsg struct.
924 grep '^type _rtmsg ' gen-sysinfo.go | \
925 sed -e 's/_rtmsg/RtMsg/' \
926 -e 's/rtm_family/Family/' \
927 -e 's/rtm_dst_len/Dst_len/' \
928 -e 's/rtm_src_len/Src_len/' \
929 -e 's/rtm_tos/Tos/' \
930 -e 's/rtm_table/Table/' \
931 -e 's/rtm_protocol/Protocol/' \
932 -e 's/rtm_scope/Scope/' \
933 -e 's/rtm_type/Type/' \
934 -e 's/rtm_flags/Flags/' \
935 >> ${OUT}
937 # The rtgenmsg struct.
938 grep '^type _rtgenmsg ' gen-sysinfo.go | \
939 sed -e 's/_rtgenmsg/RtGenmsg/' \
940 -e 's/rtgen_family/Family/' \
941 >> ${OUT}
943 # The routing message flags.
944 grep '^const _RT_' gen-sysinfo.go | \
945 sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
946 grep '^const _RTA' gen-sysinfo.go | \
947 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
948 grep '^const _RTF' gen-sysinfo.go | \
949 sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
950 grep '^const _RTCF' gen-sysinfo.go | \
951 sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
952 grep '^const _RTM' gen-sysinfo.go | \
953 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
954 grep '^const _RTN' gen-sysinfo.go | \
955 sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
956 grep '^const _RTPROT' gen-sysinfo.go | \
957 sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
959 # The ifinfomsg struct.
960 grep '^type _ifinfomsg ' gen-sysinfo.go | \
961 sed -e 's/_ifinfomsg/IfInfomsg/' \
962 -e 's/ifi_family/Family/' \
963 -e 's/ifi_type/Type/' \
964 -e 's/ifi_index/Index/' \
965 -e 's/ifi_flags/Flags/' \
966 -e 's/ifi_change/Change/' \
967 >> ${OUT}
969 # The interface information types and flags.
970 grep '^const _IFA' gen-sysinfo.go | \
971 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
972 grep '^const _IFLA' gen-sysinfo.go | \
973 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
974 grep '^const _IFF' gen-sysinfo.go | \
975 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
976 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
977 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
978 grep '^const _SIOC' gen-sysinfo.go |
979 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
981 # The ifaddrmsg struct.
982 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
983 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
984 -e 's/ifa_family/Family/' \
985 -e 's/ifa_prefixlen/Prefixlen/' \
986 -e 's/ifa_flags/Flags/' \
987 -e 's/ifa_scope/Scope/' \
988 -e 's/ifa_index/Index/' \
989 >> ${OUT}
991 # The rtattr struct.
992 grep '^type _rtattr ' gen-sysinfo.go | \
993 sed -e 's/_rtattr/RtAttr/' \
994 -e 's/rta_len/Len/' \
995 -e 's/rta_type/Type/' \
996 >> ${OUT}
998 # The in_pktinfo struct.
999 grep '^type _in_pktinfo ' gen-sysinfo.go | \
1000 sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
1001 -e 's/ipi_ifindex/Ifindex/' \
1002 -e 's/ipi_spec_dst/Spec_dst/' \
1003 -e 's/ipi_addr/Addr/' \
1004 -e 's/_in_addr/[4]byte/g' \
1005 >> ${OUT}
1007 # The in6_pktinfo struct.
1008 grep '^type _in6_pktinfo ' gen-sysinfo.go | \
1009 sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
1010 -e 's/ipi6_addr/Addr/' \
1011 -e 's/ipi6_ifindex/Ifindex/' \
1012 -e 's/_in6_addr/[16]byte/' \
1013 >> ${OUT}
1015 # The termios struct.
1016 grep '^type _termios ' gen-sysinfo.go | \
1017 sed -e 's/_termios/Termios/' \
1018 -e 's/c_iflag/Iflag/' \
1019 -e 's/c_oflag/Oflag/' \
1020 -e 's/c_cflag/Cflag/' \
1021 -e 's/c_lflag/Lflag/' \
1022 -e 's/c_line/Line/' \
1023 -e 's/c_cc/Cc/' \
1024 -e 's/c_ispeed/Ispeed/' \
1025 -e 's/c_ospeed/Ospeed/' \
1026 >> ${OUT}
1028 # The termios constants.
1029 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
1030 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
1031 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
1032 BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
1033 CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
1034 ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
1035 VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
1036 VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
1037 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
1038 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
1039 B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
1040 B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
1042 grep "^const _$n " gen-sysinfo.go | \
1043 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1044 done
1046 # The mount flags
1047 grep '^const _MNT_' gen-sysinfo.go |
1048 sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1049 grep '^const _MS_' gen-sysinfo.go |
1050 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1052 # The fallocate flags.
1053 grep '^const _FALLOC_' gen-sysinfo.go |
1054 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1056 # The statfs struct.
1057 # Prefer largefile variant if available.
1058 statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
1059 if test "$statfs" != ""; then
1060 grep '^type _statfs64 ' gen-sysinfo.go
1061 else
1062 grep '^type _statfs ' gen-sysinfo.go
1063 fi | sed -e 's/type _statfs64/type Statfs_t/' \
1064 -e 's/type _statfs/type Statfs_t/' \
1065 -e 's/f_type/Type/' \
1066 -e 's/f_bsize/Bsize/' \
1067 -e 's/f_blocks/Blocks/' \
1068 -e 's/f_bfree/Bfree/' \
1069 -e 's/f_bavail/Bavail/' \
1070 -e 's/f_files/Files/' \
1071 -e 's/f_ffree/Ffree/' \
1072 -e 's/f_fsid/Fsid/' \
1073 -e 's/f_namelen/Namelen/' \
1074 -e 's/f_frsize/Frsize/' \
1075 -e 's/f_flags/Flags/' \
1076 -e 's/f_spare/Spare/' \
1077 >> ${OUT}
1079 # The timex struct.
1080 timex=`grep '^type _timex ' gen-sysinfo.go || true`
1081 if test "$timex" = ""; then
1082 timex=`grep '^// type _timex ' gen-sysinfo.go || true`
1083 if test "$timex" != ""; then
1084 timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
1087 if test "$timex" != ""; then
1088 echo "$timex" | \
1089 sed -e 's/_timex/Timex/' \
1090 -e 's/modes/Modes/' \
1091 -e 's/offset/Offset/' \
1092 -e 's/freq/Freq/' \
1093 -e 's/maxerror/Maxerror/' \
1094 -e 's/esterror/Esterror/' \
1095 -e 's/status/Status/' \
1096 -e 's/constant/Constant/' \
1097 -e 's/precision/Precision/' \
1098 -e 's/tolerance/Tolerance/' \
1099 -e 's/ time / Time /' \
1100 -e 's/tick/Tick/' \
1101 -e 's/ppsfreq/Ppsfreq/' \
1102 -e 's/jitter/Jitter/' \
1103 -e 's/shift/Shift/' \
1104 -e 's/stabil/Stabil/' \
1105 -e 's/jitcnt/Jitcnt/' \
1106 -e 's/calcnt/Calcnt/' \
1107 -e 's/errcnt/Errcnt/' \
1108 -e 's/stbcnt/Stbcnt/' \
1109 -e 's/tai/Tai/' \
1110 -e 's/_timeval/Timeval/' \
1111 >> ${OUT}
1114 # The rlimit struct.
1115 grep '^type _rlimit ' gen-sysinfo.go | \
1116 sed -e 's/_rlimit/Rlimit/' \
1117 -e 's/rlim_cur/Cur/' \
1118 -e 's/rlim_max/Max/' \
1119 >> ${OUT}
1121 # The RLIMIT constants.
1122 grep '^const _RLIMIT_' gen-sysinfo.go |
1123 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1124 grep '^const _RLIM_' gen-sysinfo.go |
1125 sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1127 # The sysinfo struct.
1128 grep '^type _sysinfo ' gen-sysinfo.go | \
1129 sed -e 's/_sysinfo/Sysinfo_t/' \
1130 -e 's/uptime/Uptime/' \
1131 -e 's/loads/Loads/' \
1132 -e 's/totalram/Totalram/' \
1133 -e 's/freeram/Freeram/' \
1134 -e 's/sharedram/Sharedram/' \
1135 -e 's/bufferram/Bufferram/' \
1136 -e 's/totalswap/Totalswap/' \
1137 -e 's/freeswap/Freeswap/' \
1138 -e 's/procs/Procs/' \
1139 -e 's/totalhigh/Totalhigh/' \
1140 -e 's/freehigh/Freehigh/' \
1141 -e 's/mem_unit/Unit/' \
1142 >> ${OUT}
1144 # The ustat struct.
1145 grep '^type _ustat ' gen-sysinfo.go | \
1146 sed -e 's/_ustat/Ustat_t/' \
1147 -e 's/f_tfree/Tfree/' \
1148 -e 's/f_tinode/Tinoe/' \
1149 -e 's/f_fname/Fname/' \
1150 -e 's/f_fpack/Fpack/' \
1151 >> ${OUT}
1152 # Force it to be defined, as on some older GNU/Linux systems the
1153 # header file fails when using with <linux/filter.h>.
1154 if ! grep 'type _ustat ' gen-sysinfo.go >/dev/null 2>&1; then
1155 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
1158 # The utimbuf struct.
1159 grep '^type _utimbuf ' gen-sysinfo.go | \
1160 sed -e 's/_utimbuf/Utimbuf/' \
1161 -e 's/actime/Actime/' \
1162 -e 's/modtime/Modtime/' \
1163 >> ${OUT}
1165 # The LOCK flags for flock.
1166 grep '^const _LOCK_' gen-sysinfo.go |
1167 sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1169 # The PRIO constants.
1170 grep '^const _PRIO_' gen-sysinfo.go | \
1171 sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1173 # The GNU/Linux LINUX_REBOOT flags.
1174 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
1175 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1177 # The GNU/Linux sock_filter struct.
1178 grep '^type _sock_filter ' gen-sysinfo.go | \
1179 sed -e 's/_sock_filter/SockFilter/' \
1180 -e 's/code/Code/' \
1181 -e 's/jt/Jt/' \
1182 -e 's/jf/Jf/' \
1183 -e 's/k /K /' \
1184 >> ${OUT}
1186 # The GNU/Linux sock_fprog struct.
1187 grep '^type _sock_fprog ' gen-sysinfo.go | \
1188 sed -e 's/_sock_fprog/SockFprog/' \
1189 -e 's/len/Len/' \
1190 -e 's/filter/Filter/' \
1191 -e 's/_sock_filter/SockFilter/' \
1192 >> ${OUT}
1194 # The GNU/Linux filter flags.
1195 grep '^const _BPF_' gen-sysinfo.go | \
1196 sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1198 # The GNU/Linux nlattr struct.
1199 grep '^type _nlattr ' gen-sysinfo.go | \
1200 sed -e 's/_nlattr/NlAttr/' \
1201 -e 's/nla_len/Len/' \
1202 -e 's/nla_type/Type/' \
1203 >> ${OUT}
1205 # The GNU/Linux nlmsgerr struct.
1206 grep '^type _nlmsgerr ' gen-sysinfo.go | \
1207 sed -e 's/_nlmsgerr/NlMsgerr/' \
1208 -e 's/error/Error/' \
1209 -e 's/msg/Msg/' \
1210 -e 's/_nlmsghdr/NlMsghdr/' \
1211 >> ${OUT}
1213 # The GNU/Linux rtnexthop struct.
1214 grep '^type _rtnexthop ' gen-sysinfo.go | \
1215 sed -e 's/_rtnexthop/RtNexthop/' \
1216 -e 's/rtnh_len/Len/' \
1217 -e 's/rtnh_flags/Flags/' \
1218 -e 's/rtnh_hops/Hops/' \
1219 -e 's/rtnh_ifindex/Ifindex/' \
1220 >> ${OUT}
1222 # The GNU/Linux netlink flags.
1223 grep '^const _NETLINK_' gen-sysinfo.go | \
1224 sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1225 grep '^const _NLA_' gen-sysinfo.go | grep -v '_val =' | \
1226 sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1228 if ! grep '^const NLA_HDRLEN' ${OUT} >/dev/null 2>&1; then
1229 if grep '^const _NLA_HDRLEN_val' ${OUT} >/dev/null 2>&1; then
1230 echo 'const NLA_HDRLEN = _NLA_HDRLEN_val' >> ${OUT}
1234 # The GNU/Linux packet socket flags.
1235 grep '^const _PACKET_' gen-sysinfo.go | \
1236 sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1238 # The GNU/Linux inotify_event struct.
1239 grep '^type _inotify_event ' gen-sysinfo.go | \
1240 sed -e 's/_inotify_event/InotifyEvent/' \
1241 -e 's/wd/Wd/' \
1242 -e 's/mask/Mask/' \
1243 -e 's/cookie/Cookie/' \
1244 -e 's/len/Len/' \
1245 -e 's/name/Name/' \
1246 -e 's/\[\]/[0]/' \
1247 -e 's/\[0\]byte/[0]int8/' \
1248 >> ${OUT}
1250 # The GNU/Linux CLONE flags.
1251 grep '^const _CLONE_' gen-sysinfo.go | \
1252 sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
1253 # We need some CLONE constants that are not defined in older versions
1254 # of glibc.
1255 if ! grep '^const CLONE_NEWUSER ' ${OUT} > /dev/null 2>&1; then
1256 echo "const CLONE_NEWUSER = 0x10000000" >> ${OUT}
1258 if ! grep '^const CLONE_NEWNET ' ${OUT} > /dev/null 2>&1; then
1259 echo "const CLONE_NEWNET = 0x40000000" >> ${OUT}
1262 # Struct sizes.
1263 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
1264 ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
1265 in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
1266 msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
1267 rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
1268 sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
1269 icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo
1270 while test $# != 0; do
1271 nc=$1
1272 ngo=$2
1273 shift
1274 shift
1275 if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
1276 echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
1278 done
1280 # In order to compile the net package, we need some sizes to exist
1281 # even if the types do not.
1282 if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
1283 echo 'const SizeofIPMreq = 8' >> ${OUT}
1285 if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
1286 echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
1288 if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
1289 echo 'const SizeofIPMreqn = 12' >> ${OUT}
1291 if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
1292 echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
1295 # The Solaris 11 Update 1 _zone_net_addr_t struct.
1296 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
1297 sed -e 's/_in6_addr/[16]byte/' \
1298 >> ${OUT}
1300 # The Solaris 12 _flow_arp_desc_t struct.
1301 grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
1302 sed -e 's/_in6_addr_t/[16]byte/g' \
1303 >> ${OUT}
1305 # The Solaris 12 _flow_l3_desc_t struct.
1306 grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
1307 sed -e 's/_in6_addr_t/[16]byte/g' \
1308 >> ${OUT}
1310 # The Solaris 12 _mac_ipaddr_t struct.
1311 grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
1312 sed -e 's/_in6_addr_t/[16]byte/g' \
1313 >> ${OUT}
1315 # The Solaris 12 _mactun_info_t struct.
1316 grep '^type _mactun_info_t ' gen-sysinfo.go | \
1317 sed -e 's/_in6_addr_t/[16]byte/g' \
1318 >> ${OUT}
1320 exit $?