#if defined(HAVE_SYS_MMAN_H)
#include <sys/mman.h>
#endif
+#if defined(HAVE_SYS_PRCTL_H)
+#include <sys/prctl.h>
+#endif
#if defined(HAVE_SYS_PTRACE_H)
#include <sys/ptrace.h>
#endif
#if defined(HAVE_NET_IF_H)
#include <net/if.h>
#endif
+
+/* Constants that may only be defined as expressions on some systems,
+ expressions too complex for -fdump-go-spec to handle. These are
+ handled specially below. */
+enum {
+#ifdef TIOCGWINSZ
+ TIOCGWINSZ_val = TIOCGWINSZ,
+#endif
+};
EOF
${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
# The net package requires some const definitions.
-for m in IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP; do
+for m in IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS; do
if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
echo "const $m = 0" >> ${OUT}
fi
# epoll constants.
grep '^const _EPOLL' gen-sysinfo.go |
sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
-# Make sure EPOLLRDHUP is defined.
+# Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
fi
+if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
+ echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
+fi
+
+# Prctl constants.
+grep '^const _PR_' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
# Ptrace constants.
grep '^const _PTRACE' gen-sysinfo.go |
echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
fi
if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
- echo "const _PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
+ echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
fi
if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
fi
+# The size of the ipv6_mreq struct.
+echo 'var SizeofIPv6Mreq = int(unsafe.Sizeof(IPv6Mreq{}))' >> ${OUT}
+
+# The ip_mreqn struct.
+grep '^type _ip_mreqn ' gen-sysinfo.go | \
+ sed -e 's/_ip_mreqn/IPMreqn/' \
+ -e 's/imr_multiaddr/Multiaddr/' \
+ -e 's/imr_address/Address/' \
+ -e 's/imr_ifindex/Ifindex/' \
+ -e 's/_in_addr/[4]byte/g' \
+ >> ${OUT}
+
+# We need IPMreq to compile the net package.
+if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
+ echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
+fi
+
+# The size of the ip_mreqn struct.
+echo 'var SizeofIPMreqn = int(unsafe.Sizeof(IPMreqn{}))' >> ${OUT}
+
# 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"
# The ioctl flags for the controlling TTY.
grep '^const _TIOC' gen-sysinfo.go | \
+ grep -v '_val =' | \
sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+# We need TIOCGWINSZ.
+if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
+ if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
+ echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
+ fi
+fi
# The ioctl flags for terminal control
grep '^const _TC[GS]ET' gen-sysinfo.go | \