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>
69 #include <sys/times.h>
72 #if defined(HAVE_SYS_USER_H)
75 #if defined(HAVE_SYS_UTSNAME_H)
76 #include <sys/utsname.h>
78 #if defined(HAVE_SYS_SELECT_H)
79 #include <sys/select.h>
85 #if defined(HAVE_LINUX_FILTER_H)
86 #include <linux/filter.h>
88 #if defined(HAVE_LINUX_NETLINK_H)
89 #include <linux/netlink.h>
91 #if defined(HAVE_LINUX_RTNETLINK_H)
92 #include <linux/rtnetlink.h>
94 #if defined(HAVE_NET_IF_H)
97 #if defined(HAVE_SYS_MOUNT_H)
98 #include <sys/mount.h>
100 #if defined(HAVE_SYS_VFS_H)
103 #if defined(HAVE_STATFS_H)
104 #include <sys/statfs.h>
106 #if defined(HAVE_SYS_TIMEX_H)
107 #include <sys/timex.h>
109 #if defined(HAVE_SYS_SYSINFO_H)
110 #include <sys/sysinfo.h>
112 #if defined(HAVE_USTAT_H)
115 #if defined(HAVE_UTIME_H)
118 #if defined(HAVE_LINUX_REBOOT_H)
119 #include <linux/reboot.h>
122 /* Constants that may only be defined as expressions on some systems,
123 expressions too complex for -fdump-go-spec to handle. These are
124 handled specially below. */
127 TIOCGWINSZ_val = TIOCGWINSZ,
132 ${CC} -fdump-go-spec=gen-sysinfo.go
-std=gnu99
-S -o sysinfo.s sysinfo.c
134 echo 'package syscall' > ${OUT}
135 echo 'import "unsafe"' >> ${OUT}
136 echo 'type _ unsafe.Pointer' >> ${OUT}
138 # Get all the consts and types, skipping ones which could not be
139 # represented in Go and ones which we need to rewrite. We also skip
140 # function declarations, as we don't need them here. All the symbols
141 # will all have a leading underscore.
142 grep -v '^// ' gen-sysinfo.go | \
144 grep -v '^type _timeval ' | \
145 grep -v '^type _timespec_t ' | \
146 grep -v '^type _timespec ' | \
147 grep -v '^type _timestruc_t ' | \
148 grep -v '^type _epoll_' | \
149 grep -v 'in6_addr' | \
150 grep -v 'sockaddr_in6' | \
151 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
152 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
153 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
154 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
157 # The errno constants. These get type Errno.
158 echo '#include <errno.h>' |
${CC} -x c
- -E -dM | \
159 egrep '#define E[A-Z0-9_]+ ' | \
160 sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
163 egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
164 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
165 if ! grep '^const O_ASYNC' ${OUT} >/dev
/null
2>&1; then
166 echo "const O_ASYNC = 0" >> ${OUT}
168 if ! grep '^const O_CLOEXEC' ${OUT} >/dev
/null
2>&1; then
169 echo "const O_CLOEXEC = 0" >> ${OUT}
172 # The signal numbers.
173 grep '^const _SIG[^_]' gen-sysinfo.go | \
174 grep -v '^const _SIGEV_' | \
175 sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
177 # The syscall numbers. We force the names to upper case.
178 grep '^const _SYS_' gen-sysinfo.go | \
179 sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
181 sup
=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
182 echo "const $sup = _$sys" >> ${OUT}
186 grep '^const _S_' gen-sysinfo.go | \
187 sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
190 grep '^const _PROT_' gen-sysinfo.go | \
191 sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
192 grep '^const _MAP_' gen-sysinfo.go | \
193 sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
194 grep '^const _MADV_' gen-sysinfo.go | \
195 sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
197 # Process status constants.
198 grep '^const _W' gen-sysinfo.go |
199 sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
200 # WSTOPPED was introduced in glibc 2.3.4.
201 if ! grep '^const _WSTOPPED = ' gen-sysinfo.go
>/dev
/null
2>&1; then
202 if grep '^const _WUNTRACED = ' gen-sysinfo.go
> /dev
/null
2>&1; then
203 echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
205 echo 'const WSTOPPED = 2' >> ${OUT}
208 if grep '^const ___WALL = ' gen-sysinfo.go
>/dev
/null
2>&1 \
209 && ! grep '^const _WALL = ' gen-sysinfo.go
>/dev
/null
2>&1; then
210 echo 'const WALL = ___WALL' >> ${OUT}
213 # Networking constants.
214 egrep '^const _(AF|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
215 sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
216 grep '^const _SOMAXCONN' gen-sysinfo.go |
217 sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
219 grep '^const _SHUT_' gen-sysinfo.go |
220 sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
222 # The net package requires some const definitions.
223 for m
in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS
; do
224 if ! grep "^const $m " ${OUT} >/dev
/null
2>&1; then
225 echo "const $m = 0" >> ${OUT}
229 # pathconf constants.
230 grep '^const __PC' gen-sysinfo.go |
231 sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
234 grep '^const _EPOLL' gen-sysinfo.go |
235 sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
236 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
237 if ! grep '^const EPOLLRDHUP' ${OUT} >/dev
/null
2>&1; then
238 echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
240 if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev
/null
2>&1; then
241 echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
245 grep '^const _PR_' gen-sysinfo.go |
246 sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
249 grep '^const _PTRACE' gen-sysinfo.go |
250 sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
251 # We need some ptrace options that are not defined in older versions
253 if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev
/null
2>&1; then
254 echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
256 if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev
/null
2>&1; then
257 echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
259 if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev
/null
2>&1; then
260 echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
262 if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev
/null
2>&1; then
263 echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
265 if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev
/null
2>&1; then
266 echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
268 if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev
/null
2>&1; then
269 echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
271 if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev
/null
2>&1; then
272 echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
274 if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev
/null
2>&1; then
275 echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
277 if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev
/null
2>&1; then
278 echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
280 if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev
/null
2>&1; then
281 echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
283 if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev
/null
2>&1; then
284 echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
286 if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev
/null
2>&1; then
287 echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
289 if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev
/null
2>&1; then
290 echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
292 if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev
/null
2>&1; then
293 echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
295 if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev
/null
2>&1; then
296 echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
298 if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev
/null
2>&1; then
299 echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
301 if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev
/null
2>&1; then
302 echo "const _PTRACE_TRACEME = 0" >> ${OUT}
305 # The registers returned by PTRACE_GETREGS. This is probably
306 # GNU/Linux specific; it should do no harm if there is no
308 regs
=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
309 if test "$regs" != ""; then
310 regs
=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
311 regs
=`echo $regs | sed -e s'/^ *//'`
313 while test -n "$regs"; do
314 field
=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
315 regs
=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
316 # Capitalize the first character of the field.
317 f
=`echo $field | sed -e 's/^\(.\).*$/\1/'`
318 r
=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
319 f
=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
321 nregs
="$nregs $field;"
323 echo "type PtraceRegs struct {$nregs }" >> ${OUT}
327 echo 'type Size_t _size_t' >> ${OUT}
328 echo "type Ssize_t _ssize_t" >> ${OUT}
329 if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go
> /dev
/null
2>&1; then
330 echo "type Offset_t _off64_t" >> ${OUT}
332 echo "type Offset_t _off_t" >> ${OUT}
334 echo "type Mode_t _mode_t" >> ${OUT}
335 echo "type Pid_t _pid_t" >> ${OUT}
336 echo "type Uid_t _uid_t" >> ${OUT}
337 echo "type Gid_t _gid_t" >> ${OUT}
338 echo "type Socklen_t _socklen_t" >> ${OUT}
340 # The long type, needed because that is the type that ptrace returns.
341 sizeof_long
=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
342 if test "$sizeof_long" = "4"; then
343 echo "type _C_long int32" >> ${OUT}
344 elif test "$sizeof_long" = "8"; then
345 echo "type _C_long int64" >> ${OUT}
347 echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
351 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
352 # double is commented by -fdump-go-spec.
353 if grep "^// type _pad128_t" gen-sysinfo.go
> /dev
/null
2>&1; then
354 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
356 if grep "^// type _upad128_t" gen-sysinfo.go
> /dev
/null
2>&1; then
357 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
361 if grep '^type _time_t ' gen-sysinfo.go
> /dev
/null
2>&1; then
362 echo 'type Time_t _time_t' >> ${OUT}
365 # The time structures need special handling: we need to name the
366 # types, so that we can cast integers to the right types when
367 # assigning to the structures.
368 timeval
=`grep '^type _timeval ' gen-sysinfo.go`
369 timeval_sec
=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
370 timeval_usec
=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
371 echo "type Timeval_sec_t $timeval_sec" >> ${OUT}
372 echo "type Timeval_usec_t $timeval_usec" >> ${OUT}
374 sed -e 's/type _timeval /type Timeval /' \
375 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
376 -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
377 timespec
=`grep '^type _timespec ' gen-sysinfo.go || true`
378 if test "$timespec" = ""; then
379 # IRIX 6.5 has __timespec instead.
380 timespec
=`grep '^type ___timespec ' gen-sysinfo.go || true`
382 timespec_sec
=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
383 timespec_nsec
=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
384 echo "type Timespec_sec_t $timespec_sec" >> ${OUT}
385 echo "type Timespec_nsec_t $timespec_nsec" >> ${OUT}
387 sed -e 's/^type ___timespec /type Timespec /' \
388 -e 's/^type _timespec /type Timespec /' \
389 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
390 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
392 timestruc
=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
393 if test "$timestruc" != ""; then
394 timestruc_sec
=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
395 timestruc_nsec
=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
396 echo "type Timestruc_sec_t $timestruc_sec" >> ${OUT}
397 echo "type Timestruc_nsec_t $timestruc_nsec" >> ${OUT}
399 sed -e 's/^type _timestruc_t /type Timestruc /' \
400 -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
401 -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
405 grep '^type _tms ' gen-sysinfo.go | \
406 sed -e 's/type _tms/type Tms/' \
407 -e 's/tms_utime/Utime/' \
408 -e 's/tms_stime/Stime/' \
409 -e 's/tms_cutime/Cutime/' \
410 -e 's/tms_cstime/Cstime/' \
414 # Prefer largefile variant if available.
415 stat
=`grep '^type _stat64 ' gen-sysinfo.go || true`
416 if test "$stat" != ""; then
417 grep '^type _stat64 ' gen-sysinfo.go
419 grep '^type _stat ' gen-sysinfo.go
420 fi |
sed -e 's/type _stat64/type Stat_t/' \
421 -e 's/type _stat/type Stat_t/' \
423 -e 's/st_ino/Ino/g' \
424 -e 's/st_nlink/Nlink/' \
425 -e 's/st_mode/Mode/' \
428 -e 's/st_rdev/Rdev/' \
429 -e 's/st_size/Size/' \
430 -e 's/st_blksize/Blksize/' \
431 -e 's/st_blocks/Blocks/' \
432 -e 's/st_atim/Atime/' \
433 -e 's/st_mtim/Mtime/' \
434 -e 's/st_ctim/Ctime/' \
435 -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
436 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
437 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
438 -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
439 -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
442 # The directory searching types.
443 # Prefer largefile variant if available.
444 dirent
=`grep '^type _dirent64 ' gen-sysinfo.go || true`
445 if test "$dirent" != ""; then
446 grep '^type _dirent64 ' gen-sysinfo.go
448 grep '^type _dirent ' gen-sysinfo.go
449 fi |
sed -e 's/type _dirent64/type Dirent/' \
450 -e 's/type _dirent/type Dirent/' \
451 -e 's/d_name \[0+1\]/d_name [0+256]/' \
452 -e 's/d_name/Name/' \
453 -e 's/]int8/]byte/' \
456 -e 's/d_reclen/Reclen/' \
457 -e 's/d_type/Type/' \
459 echo "type DIR _DIR" >> ${OUT}
462 rusage
=`grep '^type _rusage struct' gen-sysinfo.go`
463 if test "$rusage" != ""; then
464 rusage
=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
465 rusage
=`echo $rusage | sed -e 's/^ *//'`
467 while test -n "$rusage"; do
468 field
=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
469 rusage
=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
470 # Drop the leading ru_, capitalize the next character.
471 field
=`echo $field | sed -e 's/^ru_//'`
472 f
=`echo $field | sed -e 's/^\(.\).*$/\1/'`
473 r
=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
474 f
=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
475 # Fix _timeval _timespec, and _timestruc_t.
476 r
=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
477 r
=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
478 r
=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
480 nrusage
="$nrusage $field;"
482 echo "type Rusage struct {$nrusage }" >> ${OUT}
484 echo "type Rusage struct {}" >> ${OUT}
487 # The RUSAGE constants.
488 grep '^const _RUSAGE_' gen-sysinfo.go | \
489 sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
491 # The utsname struct.
492 grep '^type _utsname ' gen-sysinfo.go | \
493 sed -e 's/_utsname/Utsname/' \
494 -e 's/sysname/Sysname/' \
495 -e 's/nodename/Nodename/' \
496 -e 's/release/Release/' \
497 -e 's/version/Version/' \
498 -e 's/machine/Machine/' \
499 -e 's/domainname/Domainname/' \
503 iovec
=`grep '^type _iovec ' gen-sysinfo.go`
504 iovec_len
=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
505 echo "type Iovec_len_t $iovec_len" >> ${OUT}
507 sed -e 's/_iovec/Iovec/' \
508 -e 's/iov_base/Base/' \
509 -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
513 msghdr
=`grep '^type _msghdr ' gen-sysinfo.go`
514 msghdr_controllen
=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
515 echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
517 sed -e 's/_msghdr/Msghdr/' \
518 -e 's/msg_name/Name/' \
519 -e 's/msg_namelen/Namelen/' \
520 -e 's/msg_iov/Iov/' \
521 -e 's/msg_iovlen/Iovlen/' \
522 -e 's/_iovec/Iovec/' \
523 -e 's/msg_control/Control/' \
524 -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
525 -e 's/msg_flags/Flags/' \
528 # The MSG_ flags for Msghdr.
529 grep '^const _MSG_' gen-sysinfo.go | \
530 sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
532 # The cmsghdr struct.
533 cmsghdr
=`grep '^type _cmsghdr ' gen-sysinfo.go`
534 if test -n "$cmsghdr"; then
535 cmsghdr_len
=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
536 echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
538 sed -e 's/_cmsghdr/Cmsghdr/' \
539 -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
540 -e 's/cmsg_level/Level/' \
541 -e 's/cmsg_type/Type/' \
545 # The size of the cmsghdr struct.
546 echo 'var SizeofCmsghdr = int(unsafe.Sizeof(Cmsghdr{}))' >> ${OUT}
549 # The SCM_ flags for Cmsghdr.
550 grep '^const _SCM_' gen-sysinfo.go | \
551 sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
554 grep '^type _ucred ' gen-sysinfo.go | \
555 sed -e 's/_ucred/Ucred/' \
561 # The size of the ucred struct.
562 if grep 'type Ucred ' ${OUT} >/dev
/null
2>&1; then
563 echo 'var SizeofUcred = int(unsafe.Sizeof(Ucred{}))' >> ${OUT}
566 # The ip_mreq struct.
567 grep '^type _ip_mreq ' gen-sysinfo.go | \
568 sed -e 's/_ip_mreq/IPMreq/' \
569 -e 's/imr_multiaddr/Multiaddr/' \
570 -e 's/imr_interface/Interface/' \
571 -e 's/_in_addr/[4]byte/g' \
574 # We need IPMreq to compile the net package.
575 if ! grep 'type IPMreq ' ${OUT} >/dev
/null
2>&1; then
576 echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
579 # The size of the ip_mreq struct.
580 echo 'var SizeofIPMreq = int(unsafe.Sizeof(IPMreq{}))' >> ${OUT}
582 # The ipv6_mreq struct.
583 grep '^type _ipv6_mreq ' gen-sysinfo.go | \
584 sed -e 's/_ipv6_mreq/IPv6Mreq/' \
585 -e 's/ipv6mr_multiaddr/Multiaddr/' \
586 -e 's/ipv6mr_interface/Interface/' \
587 -e 's/_in6_addr/[16]byte/' \
590 # We need IPv6Mreq to compile the net package.
591 if ! grep 'type IPv6Mreq ' ${OUT} >/dev
/null
2>&1; then
592 echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
595 # The size of the ipv6_mreq struct.
596 echo 'var SizeofIPv6Mreq = int(unsafe.Sizeof(IPv6Mreq{}))' >> ${OUT}
598 # The ip_mreqn struct.
599 grep '^type _ip_mreqn ' gen-sysinfo.go | \
600 sed -e 's/_ip_mreqn/IPMreqn/' \
601 -e 's/imr_multiaddr/Multiaddr/' \
602 -e 's/imr_address/Address/' \
603 -e 's/imr_ifindex/Ifindex/' \
604 -e 's/_in_addr/[4]byte/g' \
607 # We need IPMreq to compile the net package.
608 if ! grep 'type IPMreqn ' ${OUT} >/dev
/null
2>&1; then
609 echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
612 # The size of the ip_mreqn struct.
613 echo 'var SizeofIPMreqn = int(unsafe.Sizeof(IPMreqn{}))' >> ${OUT}
615 # Try to guess the type to use for fd_set.
616 fd_set
=`grep '^type _fd_set ' gen-sysinfo.go || true`
617 fds_bits_type
="_C_long"
618 if test "$fd_set" != ""; then
619 fds_bits_type
=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
621 echo "type fds_bits_type $fds_bits_type" >> ${OUT}
623 # The addrinfo struct.
624 grep '^type _addrinfo ' gen-sysinfo.go | \
625 sed -e 's/_addrinfo/Addrinfo/g' \
629 # The addrinfo flags and errors.
630 grep '^const _AI_' gen-sysinfo.go | \
631 sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
632 grep '^const _EAI_' gen-sysinfo.go | \
633 sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
636 grep '^type _passwd ' gen-sysinfo.go | \
637 sed -e 's/_passwd/Passwd/' \
641 # The ioctl flags for the controlling TTY.
642 grep '^const _TIOC' gen-sysinfo.go | \
644 sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
645 # We need TIOCGWINSZ.
646 if ! grep '^const TIOCGWINSZ' ${OUT} >/dev
/null
2>&1; then
647 if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev
/null
2>&1; then
648 echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
652 # The ioctl flags for terminal control
653 grep '^const _TC[GS]ET' gen-sysinfo.go | \
654 sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
656 # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
657 # needs handling in syscalls.exec.go.
658 if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go
>/dev
/null
2>&1; then
659 if grep '^const _TIOCNXCL ' gen-sysinfo.go
>/dev
/null
2>&1; then
660 echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
664 # The nlmsghdr struct.
665 grep '^type _nlmsghdr ' gen-sysinfo.go | \
666 sed -e 's/_nlmsghdr/NlMsghdr/' \
667 -e 's/nlmsg_len/Len/' \
668 -e 's/nlmsg_type/Type/' \
669 -e 's/nlmsg_flags/Flags/' \
670 -e 's/nlmsg_seq/Seq/' \
671 -e 's/nlmsg_pid/Pid/' \
674 # The nlmsg flags and operators.
675 grep '^const _NLM' gen-sysinfo.go | \
676 sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
678 # NLMSG_HDRLEN is defined as an expression using sizeof.
679 if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev
/null
2>&1; then
680 if grep '^type NlMsghdr ' ${OUT} > /dev
/null
2>&1; then
681 echo 'var NLMSG_HDRLEN = int((unsafe.Sizeof(NlMsghdr{}) + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1))' >> ${OUT}
686 grep '^type _rtmsg ' gen-sysinfo.go | \
687 sed -e 's/_rtmsg/RtMsg/' \
688 -e 's/rtm_family/Family/' \
689 -e 's/rtm_dst_len/Dst_len/' \
690 -e 's/rtm_src_len/Src_len/' \
691 -e 's/rtm_tos/Tos/' \
692 -e 's/rtm_table/Table/' \
693 -e 's/rtm_protocol/Procotol/' \
694 -e 's/rtm_scope/Scope/' \
695 -e 's/rtm_type/Type/' \
696 -e 's/rtm_flags/Flags/' \
699 # The size of the rtmsg struct.
700 if grep 'type RtMsg ' ${OUT} > /dev
/null
2>&1; then
701 echo 'var SizeofRtMsg = int(unsafe.Sizeof(RtMsg{}))' >> ${OUT}
704 # The rtgenmsg struct.
705 grep '^type _rtgenmsg ' gen-sysinfo.go | \
706 sed -e 's/_rtgenmsg/RtGenmsg/' \
707 -e 's/rtgen_family/Family/' \
710 # The routing message flags.
711 grep '^const _RTA' gen-sysinfo.go | \
712 sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
713 grep '^const _RTM' gen-sysinfo.go | \
714 sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
716 # The size of the rtgenmsg struct.
717 if grep 'type RtGenmsg ' ${OUT} > /dev
/null
2>&1; then
718 echo 'var SizeofRtGenmsg = int(unsafe.Sizeof(RtGenmsg{}))' >> ${OUT}
721 # The ifinfomsg struct.
722 grep '^type _ifinfomsg ' gen-sysinfo.go | \
723 sed -e 's/_ifinfomsg/IfInfomsg/' \
724 -e 's/ifi_family/Family/' \
725 -e 's/ifi_type/Type/' \
726 -e 's/ifi_index/Index/' \
727 -e 's/ifi_flags/Flags/' \
728 -e 's/ifi_change/Change/' \
731 # The interface information types and flags.
732 grep '^const _IFA' gen-sysinfo.go | \
733 sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
734 grep '^const _IFLA' gen-sysinfo.go | \
735 sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
736 grep '^const _IFF' gen-sysinfo.go | \
737 sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
738 grep '^const _IFNAMSIZ' gen-sysinfo.go | \
739 sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
740 grep '^const _SIOC' gen-sysinfo.go |
741 sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
743 # The size of the ifinfomsg struct.
744 if grep 'type IfInfomsg ' ${OUT} > /dev
/null
2>&1; then
745 echo 'var SizeofIfInfomsg = int(unsafe.Sizeof(IfInfomsg{}))' >> ${OUT}
748 # The ifaddrmsg struct.
749 grep '^type _ifaddrmsg ' gen-sysinfo.go | \
750 sed -e 's/_ifaddrmsg/IfAddrmsg/' \
751 -e 's/ifa_family/Family/' \
752 -e 's/ifa_prefixlen/Prefixlen/' \
753 -e 's/ifa_flags/Flags/' \
754 -e 's/ifa_scope/Scope/' \
755 -e 's/ifa_index/Index/' \
758 # The size of the ifaddrmsg struct.
759 if grep 'type IfAddrmsg ' ${OUT} > /dev
/null
2>&1; then
760 echo 'var SizeofIfAddrmsg = int(unsafe.Sizeof(IfAddrmsg{}))' >> ${OUT}
764 grep '^type _rtattr ' gen-sysinfo.go | \
765 sed -e 's/_rtattr/RtAttr/' \
766 -e 's/rta_len/Len/' \
767 -e 's/rta_type/Type/' \
770 # The size of the rtattr struct.
771 if grep 'type RtAttr ' ${OUT} > /dev
/null
2>&1; then
772 echo 'var SizeofRtAttr = int(unsafe.Sizeof(RtAttr{}))' >> ${OUT}
775 # The termios struct.
776 grep '^type _termios ' gen-sysinfo.go | \
777 sed -e 's/_termios/Termios/' \
778 -e 's/c_iflag/Iflag/' \
779 -e 's/c_oflag/Oflag/' \
780 -e 's/c_cflag/Cflag/' \
781 -e 's/c_lflag/Lflag/' \
782 -e 's/c_line/Line/' \
784 -e 's/c_ispeed/Ispeed/' \
785 -e 's/c_ospeed/Ospeed/' \
788 # The termios constants.
789 for n
in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
790 IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
791 OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 TABDLY BSDLY VTDLY \
792 FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL CLOCAL \
793 LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK ECHONL \
794 ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN VINTR \
795 VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP VSUSP \
796 VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
797 TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
798 B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
799 B38400 B57600 B115200 B230400
; do
801 grep "^const _$n " gen-sysinfo.go | \
802 sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
806 grep '^const _MS_' gen-sysinfo.go |
807 sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
809 # The fallocate flags.
810 grep '^const _FALLOC_' gen-sysinfo.go |
811 sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
814 # Prefer largefile variant if available.
815 statfs
=`grep '^type _statfs64 ' gen-sysinfo.go || true`
816 if test "$statfs" != ""; then
817 grep '^type _statfs64 ' gen-sysinfo.go
819 grep '^type _statfs ' gen-sysinfo.go
820 fi |
sed -e 's/type _statfs64/type Statfs_t/' \
821 -e 's/type _statfs/type Statfs_t/' \
822 -e 's/f_type/Type/' \
823 -e 's/f_bsize/Bsize/' \
824 -e 's/f_blocks/Blocks/' \
825 -e 's/f_bfree/Bfree/' \
826 -e 's/f_bavail/Bavail/' \
827 -e 's/f_files/Files/' \
828 -e 's/f_ffree/Ffree/' \
829 -e 's/f_fsid/Fsid/' \
830 -e 's/f_namelen/Namelen/' \
831 -e 's/f_frsize/Frsize/' \
832 -e 's/f_flags/Flags/' \
833 -e 's/f_spare/Spare/' \
837 timex
=`grep '^type _timex ' gen-sysinfo.go || true`
838 if test "$timex" = ""; then
839 timex
=`grep '^// type _timex ' gen-sysinfo.go || true`
840 if test "$timex" != ""; then
841 timex
=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
844 if test "$timex" != ""; then
846 sed -e 's/_timex/Timex/' \
847 -e 's/modes/Modes/' \
848 -e 's/offset/Offset/' \
850 -e 's/maxerror/Maxerror/' \
851 -e 's/esterror/Esterror/' \
852 -e 's/status/Status/' \
853 -e 's/constant/Constant/' \
854 -e 's/precision/Precision/' \
855 -e 's/tolerance/Tolerance/' \
856 -e 's/ time / Time /' \
858 -e 's/ppsfreq/Ppsfreq/' \
859 -e 's/jitter/Jitter/' \
860 -e 's/shift/Shift/' \
861 -e 's/stabil/Stabil/' \
862 -e 's/jitcnt/Jitcnt/' \
863 -e 's/calcnt/Calcnt/' \
864 -e 's/errcnt/Errcnt/' \
865 -e 's/stbcnt/Stbcnt/' \
867 -e 's/_timeval/Timeval/' \
872 grep '^type _rlimit ' gen-sysinfo.go | \
873 sed -e 's/_rlimit/Rlimit/' \
874 -e 's/rlim_cur/Cur/' \
875 -e 's/rlim_max/Max/' \
878 # The RLIMIT constants.
879 grep '^const _RLIMIT_' gen-sysinfo.go |
880 sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
882 # The sysinfo struct.
883 grep '^type _sysinfo ' gen-sysinfo.go | \
884 sed -e 's/_sysinfo/Sysinfo_t/' \
885 -e 's/uptime/Uptime/' \
886 -e 's/loads/Loads/' \
887 -e 's/totalram/Totalram/' \
888 -e 's/freeram/Freeram/' \
889 -e 's/sharedram/Sharedram/' \
890 -e 's/bufferram/Bufferram/' \
891 -e 's/totalswap/Totalswap/' \
892 -e 's/freeswap/Freeswap/' \
893 -e 's/procs/Procs/' \
894 -e 's/totalhigh/Totalhigh/' \
895 -e 's/freehigh/Freehigh/' \
896 -e 's/mem_unit/Unit/' \
900 grep '^type _ustat ' gen-sysinfo.go | \
901 sed -e 's/_ustat/Ustat_t/' \
902 -e 's/f_tfree/Tfree/' \
903 -e 's/f_tinode/Tinoe/' \
904 -e 's/f_fname/Fname/' \
905 -e 's/f_fpack/Fpack/' \
907 # Force it to be defined, as on some older GNU/Linux systems the
908 # header file fails when using with <linux/filter.h>.
909 if ! grep 'type _ustat ' gen-sysinfo.go
>/dev
/null
2>&1; then
910 echo 'type Ustat_t struct { Tfree int32; Tinoe uint64; Fname [5+1]int8; Fpack [5+1]int8; }' >> ${OUT}
913 # The utimbuf struct.
914 grep '^type _utimbuf ' gen-sysinfo.go | \
915 sed -e 's/_utimbuf/Utimbuf/' \
916 -e 's/actime/Actime/' \
917 -e 's/modtime/Modtime/' \
920 # The GNU/Linux LINUX_REBOOT flags.
921 grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
922 sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
924 # The GNU/Linux sock_filter struct.
925 grep '^type _sock_filter ' gen-sysinfo.go | \
926 sed -e 's/_sock_filter/SockFilter/' \
933 # The GNU/Linux sock_fprog struct.
934 grep '^type _sock_fprog ' gen-sysinfo.go | \
935 sed -e 's/_sock_fprog/SockFprog/' \
937 -e 's/filter/Filter/' \
938 -e 's/_sock_filter/SockFilter/' \