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.
9 # This shell script creates the sysinfo.go file which holds types and
10 # constants extracted from the system header files. This relies on a
11 # hook in gcc: the -fdump-go-spec option will generate debugging
12 # information in Go syntax.
14 # We currently #include all the files at once, which works, but leads
15 # to exposing some names which ideally should not be exposed, as they
16 # match grep patterns. E.g., WCHAR_MIN gets exposed because it starts
17 # with W, like the wait flags.
28 #include <sys/types.h>
32 #include <netinet/in.h>
33 /* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
34 included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
36 <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
37 <sys/ttold.h> does so unconditionally. */
39 #include <sys/bsd_types.h>
40 #include <sys/ttold.h>
42 #include <netinet/tcp.h>
44 #include <sys/ioctl.h>
46 #if defined(HAVE_SYSCALL_H)
49 #if defined(HAVE_SYS_SYSCALL_H)
50 #include <sys/syscall.h>
52 #if defined(HAVE_SYS_EPOLL_H)
53 #include <sys/epoll.h>
55 #if defined(HAVE_SYS_MMAN_H)
58 #if defined(HAVE_SYS_PRCTL_H)
59 #include <sys/prctl.h>
61 #if defined(HAVE_SYS_PTRACE_H)
62 #include <sys/ptrace.h>
64 #include <sys/resource.h>
66 #include <sys/socket.h>
71 #if defined(HAVE_SYS_USER_H)
74 #if defined(HAVE_SYS_UTSNAME_H)
75 #include <sys/utsname.h>
77 #if defined(HAVE_SYS_SELECT_H)
78 #include <sys/select.h>
83 #if defined(HAVE_LINUX_FILTER_H)
84 #include <linux/filter.h>
86 #if defined(HAVE_LINUX_NETLINK_H)
87 #include <linux/netlink.h>
89 #if defined(HAVE_LINUX_RTNETLINK_H)
90 #include <linux/rtnetlink.h>
92 #if defined(HAVE_NET_IF_H)
96 /* Constants that may only be defined as expressions on some systems,
97 expressions too complex for -fdump-go-spec to handle. These are
98 handled specially below. */
101 TIOCGWINSZ_val = TIOCGWINSZ,
106 ${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
108 echo 'package syscall' > ${OUT}
109 echo 'import "unsafe"' >> ${OUT}
110 echo 'type _ unsafe.Pointer' >> ${OUT}
112 # Get all the consts and types, skipping ones which could not be
113 # represented in Go and ones which we need to rewrite. We also skip
114 # function declarations, as we don't need them here. All the symbols
115 # will all have a leading underscore.
116 grep -v '^// ' gen-sysinfo.go | \
118 grep -v '^type _timeval ' | \
119 grep -v '^type _timespec_t ' | \
120 grep -v '^type _timespec ' | \
121 grep -v '^type _timestruc_t ' | \
122 grep -v '^type _epoll_' | \
123 grep -v 'in6_addr' | \
124 grep -v 'sockaddr_in6' | \
125 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
126 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
127 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
128 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
131 # The errno constants. These get type Errno.
132 echo '#include <errno.h>' | ${CC} -x c - -E -dM | \
133 egrep '#define E[A-Z0-9_]+ ' | \
134 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
137 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
138 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
139 if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
140 echo "const O_ASYNC = 0" >> ${OUT}
142 if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
143 echo "const O_CLOEXEC = 0" >> ${OUT}
146 # The signal numbers.
147 grep '^const _SIG[^_]' gen-sysinfo.go | \
148 grep -v '^const _SIGEV_' | \
149 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
151 # The syscall numbers. We force the names to upper case.
152 grep '^const _SYS_' gen-sysinfo.go | \
153 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
155 sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
156 echo "const $sup = _$sys" >> ${OUT}
160 grep '^const _S_' gen-sysinfo.go | \
161 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
164 grep '^const _PROT_' gen-sysinfo.go | \
165 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
166 grep '^const _MAP_' gen-sysinfo.go | \
167 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
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}
177 echo 'const WSTOPPED = 2' >> ${OUT}
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}
185 # Networking constants.
186 egrep '^const _(AF|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
187 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
188 grep '^const _SOMAXCONN' gen-sysinfo.go |
189 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
191 grep '^const _SHUT_' gen-sysinfo.go |
192 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
194 # The net package requires some const definitions.
195 for m in IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS; do
196 if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
197 echo "const $m = 0" >> ${OUT}
201 # pathconf constants.
202 grep '^const __PC' gen-sysinfo.go |
203 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
206 grep '^const _EPOLL' gen-sysinfo.go |
207 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
208 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
209 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
210 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
212 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
213 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
217 grep '^const _PR_' gen-sysinfo.go |
218 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
221 grep '^const _PTRACE' gen-sysinfo.go |
222 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
223 # We need some ptrace options that are not defined in older versions
225 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
226 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
228 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
229 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
231 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
232 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
234 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
235 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
237 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
238 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
240 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
241 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
243 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
244 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
246 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
247 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
249 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
250 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
252 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
253 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
255 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
256 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
258 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
259 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
261 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
262 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
264 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
265 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
267 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
268 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
270 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
271 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
273 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
274 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
277 # The registers returned by PTRACE_GETREGS. This is probably
278 # GNU/Linux specific; it should do no harm if there is no
280 regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
281 if test "$regs" != ""; then
282 regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
283 regs=`echo $regs | sed -e s'/^ *//'`
285 while test -n "$regs"; do
286 field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
287 regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
288 # Capitalize the first character of the field.
289 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
290 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
291 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
293 nregs="$nregs $field;"
295 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
299 echo 'type Size_t _size_t' >> ${OUT}
300 echo "type Ssize_t _ssize_t" >> ${OUT}
301 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
302 echo "type Offset_t _off64_t" >> ${OUT}
304 echo "type Offset_t _off_t" >> ${OUT}
306 echo "type Mode_t _mode_t" >> ${OUT}
307 echo "type Pid_t _pid_t" >> ${OUT}
308 echo "type Uid_t _uid_t" >> ${OUT}
309 echo "type Gid_t _gid_t" >> ${OUT}
310 echo "type Socklen_t _socklen_t" >> ${OUT}
312 # The long type, needed because that is the type that ptrace returns.
313 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
314 if test "$sizeof_long" = "4"; then
315 echo "type _C_long int32" >> ${OUT}
316 elif test "$sizeof_long" = "8"; then
317 echo "type _C_long int64" >> ${OUT}
319 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
323 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
324 # double is commented by -fdump-go-spec.
325 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
326 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
328 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
329 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
332 # The time structures need special handling: we need to name the
333 # types, so that we can cast integers to the right types when
334 # assigning to the structures.
335 timeval=`grep '^type _timeval ' gen-sysinfo.go`
336 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
337 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
338 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
339 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
341 sed -e 's/type _timeval /type Timeval /' \
342 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
343 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
344 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
345 if test "$timespec" = ""; then
346 # IRIX 6.5 has __timespec instead.
347 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
349 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
350 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
351 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
352 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
354 sed -e 's/^type ___timespec /type Timespec /' \
355 -e 's/^type _timespec /type Timespec /' \
356 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
357 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
359 timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
360 if test "$timestruc" != ""; then
361 timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
362 timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
363 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
364 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
366 sed -e 's/^type _timestruc_t /type Timestruc /' \
367 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
368 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
372 # Prefer largefile variant if available.
373 stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
374 if test "$stat" != ""; then
375 grep '^type _stat64 ' gen-sysinfo.go
377 grep '^type _stat ' gen-sysinfo.go
378 fi | sed -e 's/type _stat64/type Stat_t/' \
379 -e 's/type _stat/type Stat_t/' \
381 -e 's/st_ino/Ino/g' \
382 -e 's/st_nlink/Nlink/' \
383 -e 's/st_mode/Mode/' \
386 -e 's/st_rdev/Rdev/' \
387 -e 's/st_size/Size/' \
388 -e 's/st_blksize/Blksize/' \
389 -e 's/st_blocks/Blocks/' \
390 -e 's/st_atim/Atime/' \
391 -e 's/st_mtim/Mtime/' \
392 -e 's/st_ctim/Ctime/' \
393 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
394 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
395 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
396 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
397 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
400 # The directory searching types.
401 # Prefer largefile variant if available.
402 dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
403 if test "$dirent" != ""; then
404 grep '^type _dirent64 ' gen-sysinfo.go
406 grep '^type _dirent ' gen-sysinfo.go
407 fi | sed -e 's/type _dirent64/type Dirent/' \
408 -e 's/type _dirent/type Dirent/' \
409 -e 's/d_name \[0+1\]/d_name [0+256]/' \
410 -e 's/d_name/Name/' \
411 -e 's/]int8/]byte/' \
414 -e 's/d_reclen/Reclen/' \
415 -e 's/d_type/Type/' \
417 echo "type DIR _DIR" >> ${OUT}
420 rusage=`grep '^type _rusage struct' gen-sysinfo.go`
421 if test "$rusage" != ""; then
422 rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
423 rusage=`echo $rusage | sed -e 's/^ *//'`
425 while test -n "$rusage"; do
426 field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
427 rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
428 # Drop the leading ru_, capitalize the next character.
429 field=`echo $field | sed -e 's/^ru_//'`
430 f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
431 r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
432 f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
433 # Fix _timeval _timespec, and _timestruc_t.
434 r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
435 r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
436 r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
438 nrusage="$nrusage $field;"
440 echo "type Rusage struct {$nrusage }" >> ${OUT}
442 echo "type Rusage struct {}" >> ${OUT}
445 # The RUSAGE constants.
446 grep '^const _RUSAGE_' gen-sysinfo.go | \
447 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
449 # The utsname struct.
450 grep '^type _utsname ' gen-sysinfo.go | \
451 sed -e 's/_utsname/Utsname/' \
452 -e 's/sysname/Sysname/' \
453 -e 's/nodename/Nodename/' \
454 -e 's/release/Release/' \
455 -e 's/version/Version/' \
456 -e 's/machine/Machine/' \
457 -e 's/domainname/Domainname/' \
461 iovec=`grep '^type _iovec ' gen-sysinfo.go`
462 iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
463 echo "type Iovec_len_t $iovec_len" >> ${OUT}
465 sed -e 's/_iovec/Iovec/' \
466 -e 's/iov_base/Base/' \
467 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
471 msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
472 msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
473 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
475 sed -e 's/_msghdr/Msghdr/' \
476 -e 's/msg_name/Name/' \
477 -e 's/msg_namelen/Namelen/' \
478 -e 's/msg_iov/Iov/' \
479 -e 's/msg_iovlen/Iovlen/' \
480 -e 's/_iovec/Iovec/' \
481 -e 's/msg_control/Control/' \
482 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
483 -e 's/msg_flags/Flags/' \
486 # The ip_mreq struct.
487 grep '^type _ip_mreq ' gen-sysinfo.go | \
488 sed -e 's/_ip_mreq/IPMreq/' \
489 -e 's/imr_multiaddr/Multiaddr/' \
490 -e 's/imr_interface/Interface/' \
491 -e 's/_in_addr/[4]byte/g' \
494 # We need IPMreq to compile the net package.
495 if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
496 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
499 # The size of the ip_mreq struct.
500 echo 'var SizeofIPMreq = int(unsafe.Sizeof(IPMreq{}))' >> ${OUT}
502 # The ipv6_mreq struct.
503 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
504 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
505 -e 's/ipv6mr_multiaddr/Multiaddr/' \
506 -e 's/ipv6mr_interface/Interface/' \
507 -e 's/_in6_addr/[16]byte/' \
510 # We need IPv6Mreq to compile the net package.
511 if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
512 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
515 # The size of the ipv6_mreq struct.
516 echo 'var SizeofIPv6Mreq = int(unsafe.Sizeof(IPv6Mreq{}))' >> ${OUT}
518 # The ip_mreqn struct.
519 grep '^type _ip_mreqn ' gen-sysinfo.go | \
520 sed -e 's/_ip_mreqn/IPMreqn/' \
521 -e 's/imr_multiaddr/Multiaddr/' \
522 -e 's/imr_address/Address/' \
523 -e 's/imr_ifindex/Ifindex/' \
524 -e 's/_in_addr/[4]byte/g' \
527 # We need IPMreq to compile the net package.
528 if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
529 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
532 # The size of the ip_mreqn struct.
533 echo 'var SizeofIPMreqn = int(unsafe.Sizeof(IPMreqn{}))' >> ${OUT}
535 # Try to guess the type to use for fd_set.
536 fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
537 fds_bits_type="_C_long"
538 if test "$fd_set" != ""; then
539 fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
541 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
543 # The addrinfo struct.
544 grep '^type _addrinfo ' gen-sysinfo.go | \
545 sed -e 's/_addrinfo/Addrinfo/g' \
549 # The addrinfo flags and errors.
550 grep '^const _AI_' gen-sysinfo.go | \
551 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
552 grep '^const _EAI_' gen-sysinfo.go | \
553 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
556 grep '^type _passwd ' gen-sysinfo.go | \
557 sed -e 's/_passwd/Passwd/' \
561 # The ioctl flags for the controlling TTY.
562 grep '^const _TIOC' gen-sysinfo.go | \
564 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
565 # We need TIOCGWINSZ.
566 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
567 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
568 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
572 # The ioctl flags for terminal control
573 grep '^const _TC[GS]ET' gen-sysinfo.go | \
574 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
576 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
577 # needs handling in syscalls.exec.go.
578 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
579 if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
580 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
584 # The nlmsghdr struct.
585 grep '^type _nlmsghdr ' gen-sysinfo.go | \
586 sed -e 's/_nlmsghdr/NlMsghdr/' \
587 -e 's/nlmsg_len/Len/' \
588 -e 's/nlmsg_type/Type/' \
589 -e 's/nlmsg_flags/Flags/' \
590 -e 's/nlmsg_seq/Seq/' \
591 -e 's/nlmsg_pid/Pid/' \
594 # The nlmsg flags and operators.
595 grep '^const _NLM' gen-sysinfo.go | \
596 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
598 # NLMSG_HDRLEN is defined as an expression using sizeof.
599 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
600 if grep '^type NlMsghdr ' ${OUT} > /dev/null 2>&1; then
601 echo 'var NLMSG_HDRLEN = int((unsafe.Sizeof(NlMsghdr{}) + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1))' >> ${OUT}
606 grep '^type _rtmsg ' gen-sysinfo.go | \
607 sed -e 's/_rtmsg/RtMsg/' \
608 -e 's/rtm_family/Family/' \
609 -e 's/rtm_dst_len/Dst_len/' \
610 -e 's/rtm_src_len/Src_len/' \
611 -e 's/rtm_tos/Tos/' \
612 -e 's/rtm_table/Table/' \
613 -e 's/rtm_protocol/Procotol/' \
614 -e 's/rtm_scope/Scope/' \
615 -e 's/rtm_type/Type/' \
616 -e 's/rtm_flags/Flags/' \
619 # The size of the rtmsg struct.
620 if grep 'type RtMsg ' ${OUT} > /dev/null 2>&1; then
621 echo 'var SizeofRtMsg = int(unsafe.Sizeof(RtMsg{}))' >> ${OUT}
624 # The rtgenmsg struct.
625 grep '^type _rtgenmsg ' gen-sysinfo.go | \
626 sed -e 's/_rtgenmsg/RtGenmsg/' \
627 -e 's/rtgen_family/Family/' \
630 # The routing message flags.
631 grep '^const _RTA' gen-sysinfo.go | \
632 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
633 grep '^const _RTM' gen-sysinfo.go | \
634 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
636 # The size of the rtgenmsg struct.
637 if grep 'type RtGenmsg ' ${OUT} > /dev/null 2>&1; then
638 echo 'var SizeofRtGenmsg = int(unsafe.Sizeof(RtGenmsg{}))' >> ${OUT}
641 # The ifinfomsg struct.
642 grep '^type _ifinfomsg ' gen-sysinfo.go | \
643 sed -e 's/_ifinfomsg/IfInfomsg/' \
644 -e 's/ifi_family/Family/' \
645 -e 's/ifi_type/Type/' \
646 -e 's/ifi_index/Index/' \
647 -e 's/ifi_flags/Flags/' \
648 -e 's/ifi_change/Change/' \
651 # The interface information types and flags.
652 grep '^const _IFA' gen-sysinfo.go | \
653 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
654 grep '^const _IFLA' gen-sysinfo.go | \
655 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
656 grep '^const _IFF' gen-sysinfo.go | \
657 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
659 # The size of the ifinfomsg struct.
660 if grep 'type IfInfomsg ' ${OUT} > /dev/null 2>&1; then
661 echo 'var SizeofIfInfomsg = int(unsafe.Sizeof(IfInfomsg{}))' >> ${OUT}
664 # The ifaddrmsg struct.
665 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
666 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
667 -e 's/ifa_family/Family/' \
668 -e 's/ifa_prefixlen/Prefixlen/' \
669 -e 's/ifa_flags/Flags/' \
670 -e 's/ifa_scope/Scope/' \
671 -e 's/ifa_index/Index/' \
674 # The size of the ifaddrmsg struct.
675 if grep 'type IfAddrmsg ' ${OUT} > /dev/null 2>&1; then
676 echo 'var SizeofIfAddrmsg = int(unsafe.Sizeof(IfAddrmsg{}))' >> ${OUT}
680 grep '^type _rtattr ' gen-sysinfo.go | \
681 sed -e 's/_rtattr/RtAttr/' \
682 -e 's/rta_len/Len/' \
683 -e 's/rta_type/Type/' \
686 # The size of the rtattr struct.
687 if grep 'type RtAttr ' ${OUT} > /dev/null 2>&1; then
688 echo 'var SizeofRtAttr = int(unsafe.Sizeof(RtAttr{}))' >> ${OUT}
691 # The termios struct.
692 grep '^type _termios ' gen-sysinfo.go | \
693 sed -e 's/_termios/Termios/' \
694 -e 's/c_iflag/Iflag/' \
695 -e 's/c_oflag/Oflag/' \
696 -e 's/c_cflag/Cflag/' \
697 -e 's/c_lflag/Lflag/' \
698 -e 's/c_line/Line/' \
700 -e 's/c_ispeed/Ispeed/' \
701 -e 's/c_ospeed/Ospeed/' \
704 # The termios constants.
705 for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
706 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
707 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 TABDLY BSDLY VTDLY \
708 FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL CLOCAL \
709 LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK ECHONL \
710 ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN VINTR \
711 VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP VSUSP \
712 VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
713 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
714 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
715 B38400 B57600 B115200 B230400; do
717 grep "^const _$n " gen-sysinfo.go | \
718 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}