#if defined(HAVE_SYS_INOTIFY_H)
#include <sys/inotify.h>
#endif
+#if defined(HAVE_NETINET_ICMP6_H)
+#include <netinet/icmp6.h>
+#endif
+#if defined(HAVE_SCHED_H)
+#include <sched.h>
+#endif
/* Constants that may only be defined as expressions on some systems,
expressions too complex for -fdump-go-spec to handle. These are
#ifdef TIOCGWINSZ
TIOCGWINSZ_val = TIOCGWINSZ,
#endif
+#ifdef TIOCSWINSZ
+ TIOCSWINSZ_val = TIOCSWINSZ,
+#endif
+#ifdef TIOCNOTTY
+ TIOCNOTTY_val = TIOCNOTTY,
+#endif
+#ifdef TIOCSCTTY
+ TIOCSCTTY_val = TIOCSCTTY,
+#endif
+#ifdef TIOCGPTN
+ TIOCGPTN_val = TIOCGPTN,
+#endif
+#ifdef TIOCSPTLCK
+ TIOCSPTLCK_val = TIOCSPTLCK,
+#endif
+#ifdef TIOCGDEV
+ TIOCGDEV_val = TIOCGDEV,
+#endif
+#ifdef TIOCSIG
+ TIOCSIG_val = TIOCSIG,
+#endif
+#ifdef TCGETS
+ TCGETS_val = TCGETS,
+#endif
+#ifdef TCSETS
+ TCSETS_val = TCSETS,
+#endif
};
EOF
echo "const O_CLOEXEC = 0" >> ${OUT}
fi
+# The os package requires F_DUPFD_CLOEXEC to be defined.
+if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
+ echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
+fi
+
# These flags can be lost on i386 GNU/Linux when using
# -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
# before we see the definition of F_SETLK64.
fi
done
+# The Flock_t struct for fcntl.
+grep '^type _flock ' gen-sysinfo.go | \
+ sed -e 's/type _flock/type Flock_t/' \
+ -e 's/l_type/Type/' \
+ -e 's/l_whence/Whence/' \
+ -e 's/l_start/Start/' \
+ -e 's/l_len/Len/' \
+ -e 's/l_pid/Pid/' \
+ >> ${OUT}
+
# The signal numbers.
grep '^const _SIG[^_]' gen-sysinfo.go | \
grep -v '^const _SIGEV_' | \
echo "const $m = 0" >> ${OUT}
fi
done
+for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
+ if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
+ echo "const $m = -1" >> ${OUT}
+ fi
+done
+
+# The syscall package requires AF_LOCAL.
+if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
+ if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
+ echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
+ fi
+fi
# pathconf constants.
grep '^const __PC' gen-sysinfo.go |
echo "const _PTRACE_TRACEME = 0" >> ${OUT}
fi
+# A helper function that prints a structure from gen-sysinfo.go with the first
+# letter of the field names in upper case. $1 is the name of structure. If $2
+# is not empty, the structure or type is renamed to $2.
+upcase_fields () {
+ name="$1"
+ def=`grep "^type $name" gen-sysinfo.go`
+ fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
+ prefix=`echo $def | sed -e 's/{.*//'`
+ if test "$2" != ""; then
+ prefix=`echo $prefix | sed -e "s/$1/$2/"`
+ fi
+ if test "$fields" != ""; then
+ nfields=
+ while test -n "$fields"; do
+ field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'`
+ fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
+ # capitalize the next character.
+ f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
+ r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
+ f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
+ field="$f$r"
+ nfields="$nfields $field;"
+ done
+ echo "${prefix} {$nfields }"
+ fi
+}
+
# The registers returned by PTRACE_GETREGS. This is probably
# GNU/Linux specific; it should do no harm if there is no
# _user_regs_struct.
regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
+if test "$regs" == ""; then
+ # s390
+ regs=`grep '^type __user_regs_struct struct' gen-sysinfo.go || true`
+ if test "$regs" != ""; then
+ # Substructures of __user_regs_struct on s390
+ upcase_fields "__user_psw_struct" "PtracePsw" >> ${OUT} || true
+ upcase_fields "__user_fpregs_struct" "PtraceFpregs" >> ${OUT} || true
+ upcase_fields "__user_per_struct" "PtracePer" >> ${OUT} || true
+ fi
+fi
if test "$regs" != ""; then
- regs=`echo $regs | sed -e 's/type _user_regs_struct struct //' -e 's/[{}]//g'`
+ regs=`echo $regs |
+ sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
regs=`echo $regs | sed -e s'/^ *//'`
nregs=
while test -n "$regs"; do
r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
field="$f$r"
+ field=`echo "$field" | sed \
+ -e 's/__user_psw_struct/PtracePsw/' \
+ -e 's/__user_fpregs_struct/PtraceFpregs/' \
+ -e 's/__user_per_struct/PtracePer/'`
nregs="$nregs $field;"
done
echo "type PtraceRegs struct {$nregs }" >> ${OUT}
echo "type Gid_t _gid_t" >> ${OUT}
echo "type Socklen_t _socklen_t" >> ${OUT}
-# The long type, needed because that is the type that ptrace returns.
+# The C int type.
+sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
+if test "$sizeof_int" = "4"; then
+ echo "type _C_int int32" >> ${OUT}
+ echo "type _C_uint uint32" >> ${OUT}
+elif test "$sizeof_int" = "8"; then
+ echo "type _C_int int64" >> ${OUT}
+ echo "type _C_uint uint64" >> ${OUT}
+else
+ echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
+ exit 1
+fi
+
+# The C long type, needed because that is the type that ptrace returns.
sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
if test "$sizeof_long" = "4"; then
echo "type _C_long int32" >> ${OUT}
rusage=`grep '^type _rusage struct' gen-sysinfo.go`
if test "$rusage" != ""; then
# Remove anonymous unions from GNU/Linux <bits/resource.h>.
- rusage=`echo $rusage | sed -e 's/Godump_[0-9]* struct {\([^}]*\)};/\1/g'`
+ rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'`
rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
rusage=`echo $rusage | sed -e 's/^ *//'`
nrusage=
sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
# The ucred struct.
-grep '^type _ucred ' gen-sysinfo.go | \
- sed -e 's/_ucred/Ucred/' \
- -e 's/pid/Pid/' \
- -e 's/uid/Uid/' \
- -e 's/gid/Gid/' \
- >> ${OUT}
+upcase_fields "_ucred" "Ucred" >> ${OUT} || true
# The ip_mreq struct.
grep '^type _ip_mreq ' gen-sysinfo.go | \
echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
fi
+# The icmp6_filter struct.
+grep '^type _icmp6_filter ' gen-sysinfo.go | \
+ sed -e 's/_icmp6_filter/ICMPv6Filter/' \
+ -e 's/data/Data/' \
+ -e 's/filt/Filt/' \
+ >> ${OUT}
+
+# We need ICMPv6Filter to compile the syscall package.
+if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
+ echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
+fi
+
# Try to guess the type to use for fd_set.
fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
fds_bits_type="_C_long"
echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
fi
fi
+if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
+ fi
+fi
+if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
+ fi
+fi
+if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
+ fi
+fi
+if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
+ fi
+fi
+if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
+ fi
+fi
+if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
+ fi
+fi
+if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
+ fi
+fi
# The ioctl flags for terminal control
-grep '^const _TC[GS]ET' gen-sysinfo.go | \
+grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TCGETS = _TCGETS_val' >> ${OUT}
+ fi
+fi
+if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TCSETS = _TCSETS_val' >> ${OUT}
+ fi
+fi
# ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
# needs handling in syscalls.exec.go.
grep '^const _LOCK_' gen-sysinfo.go |
sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+# The PRIO constants.
+grep '^const _PRIO_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
# The GNU/Linux LINUX_REBOOT flags.
grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
-e 's/\[0\]byte/[0]int8/' \
>> ${OUT}
-# The Solaris 11 Update 1 _zone_net_addr_t struct.
-grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
- sed -e 's/_in6_addr/[16]byte/' \
- >> ${OUT}
+# The GNU/Linux CLONE flags.
+grep '^const _CLONE_' gen-sysinfo.go | \
+ sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
# Struct sizes.
set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
- sock_filter SockFilter sock_fprog SockFprog ucred Ucred
+ sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
+ icmp6_filter ICMPv6Filter
while test $# != 0; do
nc=$1
ngo=$2
if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
echo 'const SizeofIPMreqn = 12' >> ${OUT}
fi
+if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
+ echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
+fi
+
+# The Solaris 11 Update 1 _zone_net_addr_t struct.
+grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
+ sed -e 's/_in6_addr/[16]byte/' \
+ >> ${OUT}
exit $?