# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-# Create sysinfo.go.
+# Create sysinfo.go from gen-sysinfo.go and errno.i.
# This shell script creates the sysinfo.go file which holds types and
-# constants extracted from the system header files. This relies on a
-# hook in gcc: the -fdump-go-spec option will generate debugging
-# information in Go syntax.
+# constants extracted from the system header files. This reads the
+# raw data from gen-sysinfo.go which is generated using the
+# -fdump-go-spec option.
-# We currently #include all the files at once, which works, but leads
-# to exposing some names which ideally should not be exposed, as they
-# match grep patterns. E.g., WCHAR_MIN gets exposed because it starts
-# with W, like the wait flags.
+# This currently exposes some names that ideally should not be
+# exposed, as they match grep patterns. E.g., WCHAR_MIN gets exposed
+# because it starts with W, like the wait flags.
-CC=${CC:-gcc}
OUT=tmp-sysinfo.go
set -e
-rm -f sysinfo.c
-cat > sysinfo.c <<EOF
-#include "config.h"
-
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <ucontext.h>
-#include <netinet/in.h>
-/* <netinet/tcp.h> needs u_char/u_short, but <sys/bsd_types> is only
- included by <netinet/in.h> if _SGIAPI (i.e. _SGI_SOURCE
- && !_XOPEN_SOURCE.
- <sys/termios.h> only defines TIOCNOTTY if !_XOPEN_SOURCE, while
- <sys/ttold.h> does so unconditionally. */
-#ifdef __sgi__
-#include <sys/bsd_types.h>
-#include <sys/ttold.h>
-#endif
-#include <netinet/tcp.h>
-#if defined(HAVE_NETINET_IN_SYSTM_H)
-#include <netinet/in_systm.h>
-#endif
-#if defined(HAVE_NETINET_IP_H)
-#include <netinet/ip.h>
-#endif
-#if defined(HAVE_NETINET_IP_MROUTE_H)
-#include <netinet/ip_mroute.h>
-#endif
-#if defined(HAVE_NETINET_IF_ETHER_H)
-#include <netinet/if_ether.h>
-#endif
-#include <signal.h>
-#include <sys/ioctl.h>
-#include <termios.h>
-#if defined(HAVE_SYSCALL_H)
-#include <syscall.h>
-#endif
-#if defined(HAVE_SYS_SYSCALL_H)
-#include <sys/syscall.h>
-#endif
-#if defined(HAVE_SYS_EPOLL_H)
-#include <sys/epoll.h>
-#endif
-#if defined(HAVE_SYS_FILE_H)
-#include <sys/file.h>
-#endif
-#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
-#include <sys/resource.h>
-#include <sys/uio.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <sys/wait.h>
-#include <sys/un.h>
-#if defined(HAVE_SYS_USER_H)
-#include <sys/user.h>
-#endif
-#if defined(HAVE_SYS_UTSNAME_H)
-#include <sys/utsname.h>
-#endif
-#if defined(HAVE_SYS_SELECT_H)
-#include <sys/select.h>
-#endif
-#include <time.h>
-#include <unistd.h>
-#include <netdb.h>
-#include <pwd.h>
-#include <grp.h>
-#if defined(HAVE_LINUX_FILTER_H)
-#include <linux/filter.h>
-#endif
-#if defined(HAVE_LINUX_IF_ADDR_H)
-#include <linux/if_addr.h>
-#endif
-#if defined(HAVE_LINUX_IF_ETHER_H)
-#include <linux/if_ether.h>
-#endif
-#if defined(HAVE_LINUX_IF_TUN_H)
-#include <linux/if_tun.h>
-#endif
-#if defined(HAVE_LINUX_NETLINK_H)
-#include <linux/netlink.h>
-#endif
-#if defined(HAVE_LINUX_RTNETLINK_H)
-#include <linux/rtnetlink.h>
-#endif
-#if defined(HAVE_NET_IF_H)
-#include <net/if.h>
-#endif
-#if defined(HAVE_NET_IF_ARP_H)
-#include <net/if_arp.h>
-#endif
-#if defined(HAVE_NET_ROUTE_H)
-#include <net/route.h>
-#endif
-#if defined (HAVE_NETPACKET_PACKET_H)
-#include <netpacket/packet.h>
-#endif
-#if defined(HAVE_SYS_MOUNT_H)
-#include <sys/mount.h>
-#endif
-#if defined(HAVE_SYS_VFS_H)
-#include <sys/vfs.h>
-#endif
-#if defined(HAVE_STATFS_H)
-#include <sys/statfs.h>
-#endif
-#if defined(HAVE_SYS_TIMEX_H)
-#include <sys/timex.h>
-#endif
-#if defined(HAVE_SYS_SYSINFO_H)
-#include <sys/sysinfo.h>
-#endif
-#if defined(HAVE_USTAT_H)
-#include <ustat.h>
-#endif
-#if defined(HAVE_UTIME_H)
-#include <utime.h>
-#endif
-#if defined(HAVE_LINUX_ETHER_H)
-#include <linux/ether.h>
-#endif
-#if defined(HAVE_LINUX_FS_H)
-#include <linux/fs.h>
-#endif
-#if defined(HAVE_LINUX_REBOOT_H)
-#include <linux/reboot.h>
-#endif
-#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
- handled specially below. */
-enum {
-#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 TIOCGPGRP
- TIOCGPGRP_val = TIOCGPGRP,
-#endif
-#ifdef TIOCSPGRP
- TIOCSPGRP_val = TIOCSPGRP,
-#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
-#ifdef TUNSETIFF
- TUNSETIFF_val = TUNSETIFF,
-#endif
-#ifdef TUNSETNOCSUM
- TUNSETNOCSUM_val = TUNSETNOCSUM,
-#endif
-#ifdef TUNSETDEBUG
- TUNSETDEBUG_val = TUNSETDEBUG,
-#endif
-#ifdef TUNSETPERSIST
- TUNSETPERSIST_val = TUNSETPERSIST,
-#endif
-#ifdef TUNSETOWNER
- TUNSETOWNER_val = TUNSETOWNER,
-#endif
-#ifdef TUNSETLINK
- TUNSETLINK_val = TUNSETLINK,
-#endif
-#ifdef TUNSETGROUP
- TUNSETGROUP_val = TUNSETGROUP,
-#endif
-#ifdef TUNGETFEATURES
- TUNGETFEATURES_val = TUNGETFEATURES,
-#endif
-#ifdef TUNSETOFFLOAD
- TUNSETOFFLOAD_val = TUNSETOFFLOAD,
-#endif
-#ifdef TUNSETTXFILTER
- TUNSETTXFILTER_val = TUNSETTXFILTER,
-#endif
-#ifdef TUNGETIFF
- TUNGETIFF_val = TUNGETIFF,
-#endif
-#ifdef TUNGETSNDBUF
- TUNGETSNDBUF_val = TUNGETSNDBUF,
-#endif
-#ifdef TUNSETSNDBUF
- TUNSETSNDBUF_val = TUNSETSNDBUF,
-#endif
-#ifdef TUNATTACHFILTER
- TUNATTACHFILTER_val = TUNATTACHFILTER,
-#endif
-#ifdef TUNDETACHFILTER
- TUNDETACHFILTER_val = TUNDETACHFILTER,
-#endif
-#ifdef TUNGETVNETHDRSZ
- TUNGETVNETHDRSZ_val = TUNGETVNETHDRSZ,
-#endif
-#ifdef TUNSETVNETHDRSZ
- TUNSETVNETHDRSZ_val = TUNSETVNETHDRSZ,
-#endif
-#ifdef TUNSETQUEUE
- TUNSETQUEUE_val = TUNSETQUEUE,
-#endif
-#ifdef TUNSETIFINDEX
- TUNSETIFINDEX_val = TUNSETIFINDEX,
-#endif
-#ifdef TUNGETFILTER
- TUNGETFILTER_val = TUNGETFILTER,
-#endif
-#ifdef NLA_HDRLEN
- NLA_HDRLEN_val = NLA_HDRLEN,
-#endif
-
-};
-EOF
-
-${CC} -fdump-go-spec=gen-sysinfo.go -std=gnu99 -S -o sysinfo.s sysinfo.c
-
echo 'package syscall' > ${OUT}
echo 'import "unsafe"' >> ${OUT}
echo 'type _ unsafe.Pointer' >> ${OUT}
grep -v '^type _timespec ' | \
grep -v '^type _timestruc_t ' | \
grep -v '^type _epoll_' | \
+ grep -v '^type _*locale[_ ]' | \
grep -v 'in6_addr' | \
grep -v 'sockaddr_in6' | \
sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
-e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
>> ${OUT}
+# On AIX, the _arpcom struct, is filtered by the above grep sequence, as it as
+# a field of type _in6_addr, but other types depend on _arpcom, so we need to
+# put it back.
+grep '^type _arpcom ' gen-sysinfo.go | \
+ sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
+
+# Same on Solaris for _mld_hdr_t.
+grep '^type _mld_hdr_t ' gen-sysinfo.go | \
+ sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
+
# The errno constants. These get type Errno.
-echo '#include <errno.h>' | ${CC} -x c - -E -dM | \
- egrep '#define E[A-Z0-9_]+ ' | \
+ egrep '#define E[A-Z0-9_]+ ' errno.i | \
sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
# The O_xxx flags.
echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
fi
+# AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
+# which leads to a constant overflow when using O_CLOEXEC in some
+# go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
+# more present in 7.2 (_FCLOEXEC is a 32 bit value).
+if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
+ sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
+ mv ${OUT}-2 ${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.
# epoll constants.
grep '^const _EPOLL' gen-sysinfo.go |
+ grep -v EPOLLET |
sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+# Make sure EPOLLET is positive.
+if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go >/dev/null 2>&1; then
+ grep '^const _EPOLLET ' gen-sysinfo.go |
+ sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+else
+ echo "const EPOLLET = 0x80000000" >> ${OUT}
+fi
# Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
# is not empty, the structure or type is renamed to $2.
upcase_fields () {
name="$1"
- def=`grep "^type $name" gen-sysinfo.go`
+ def=`grep "^type $name " gen-sysinfo.go`
fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
prefix=`echo $def | sed -e 's/{.*//'`
if test "$2" != ""; then
# _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
+ # mips*
+ regs=`grep '^type _pt_regs struct' gen-sysinfo.go || true`
fi
if test "$regs" != ""; then
+ regs=`echo $regs | sed -e 's/type _pt_regs struct//'`
regs=`echo $regs |
sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
regs=`echo $regs | sed -e s'/^ *//'`
sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
if test "$sizeof_long" = "4"; then
echo "type _C_long int32" >> ${OUT}
+ echo "type _C_ulong uint32" >> ${OUT}
elif test "$sizeof_long" = "8"; then
echo "type _C_long int64" >> ${OUT}
+ echo "type _C_ulong uint64" >> ${OUT}
else
echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
exit 1
-e 's/st_ctim/Ctim/' \
-e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
-e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
+ -e 's/\([^a-zA-Z0-9_]\)_st_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
-e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
-e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
-e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
-e 's/d_name/Name/' \
-e 's/]int8/]byte/' \
-e 's/d_ino/Ino/' \
+ -e 's/d_namlen/Namlen/' \
-e 's/d_off/Off/' \
-e 's/d_reclen/Reclen/' \
-e 's/d_type/Type/' \
grep '^const _NI_' gen-sysinfo.go | \
sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+# If nothing else defined EAI_OVERFLOW, make sure it has a value.
+if ! grep "const EAI_OVERFLOW " ${OUT} >/dev/null 2>&1; then
+ echo "const EAI_OVERFLOW = 0" >> ${OUT}
+fi
+
# The passwd struct.
grep '^type _passwd ' gen-sysinfo.go | \
sed -e 's/_passwd/Passwd/' \
fi
fi
+# If nothing else defined TIOCSCTTY, make sure it has a value.
+if ! grep "const TIOCSCTTY " ${OUT} >/dev/null 2>&1; then
+ echo "const TIOCSCTTY = 0" >> ${OUT}
+fi
+
# The nlmsghdr struct.
grep '^type _nlmsghdr ' gen-sysinfo.go | \
sed -e 's/_nlmsghdr/NlMsghdr/' \
sed -e 's/_in6_addr/[16]byte/' \
>> ${OUT}
-# The Solaris 12 _flow_arp_desc_t struct.
+# The Solaris 11.4 _flow_arp_desc_t struct.
grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
sed -e 's/_in6_addr_t/[16]byte/g' \
>> ${OUT}
-# The Solaris 12 _flow_l3_desc_t struct.
+# The Solaris 11.4 _flow_l3_desc_t struct.
grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
sed -e 's/_in6_addr_t/[16]byte/g' \
>> ${OUT}
-# The Solaris 12 _mac_ipaddr_t struct.
+# The Solaris 11.3 _mac_ipaddr_t struct.
grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
sed -e 's/_in6_addr_t/[16]byte/g' \
>> ${OUT}
-# The Solaris 12 _mactun_info_t struct.
+# The Solaris 11.3 _mactun_info_t struct.
grep '^type _mactun_info_t ' gen-sysinfo.go | \
sed -e 's/_in6_addr_t/[16]byte/g' \
>> ${OUT}