diff --git a/README.md b/README.md index 3b7e728042..d296e2dc02 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,13 @@ This repository holds supplemental Go packages for low-level interactions with the operating system. -## Download/Install - -The easiest way to install is to run `go get -u golang.org/x/sys`. You can -also manually git clone the repository to `$GOPATH/src/golang.org/x/sys`. - ## Report Issues / Send Patches This repository uses Gerrit for code changes. To learn how to submit changes to -this repository, see https://golang.org/doc/contribute.html. +this repository, see https://go.dev/doc/contribute. + +The git repository is https://go.googlesource.com/sys. The main issue tracker for the sys repository is located at -https://github.com/golang/go/issues. Prefix your issue with "x/sys:" in the +https://go.dev/issues. Prefix your issue with "x/sys:" in the subject line, so it is easy to find. diff --git a/cpu/asm_darwin_x86_gc.s b/cpu/asm_darwin_x86_gc.s new file mode 100644 index 0000000000..ec2acfe540 --- /dev/null +++ b/cpu/asm_darwin_x86_gc.s @@ -0,0 +1,17 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build darwin && amd64 && gc + +#include "textflag.h" + +TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_sysctl(SB) +GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8 +DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB) + +TEXT libc_sysctlbyname_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_sysctlbyname(SB) +GLOBL ·libc_sysctlbyname_trampoline_addr(SB), RODATA, $8 +DATA ·libc_sysctlbyname_trampoline_addr(SB)/8, $libc_sysctlbyname_trampoline<>(SB) diff --git a/cpu/cpu_darwin_x86.go b/cpu/cpu_darwin_x86.go new file mode 100644 index 0000000000..b838cb9e95 --- /dev/null +++ b/cpu/cpu_darwin_x86.go @@ -0,0 +1,61 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build darwin && amd64 && gc + +package cpu + +// darwinSupportsAVX512 checks Darwin kernel for AVX512 support via sysctl +// call (see issue 43089). It also restricts AVX512 support for Darwin to +// kernel version 21.3.0 (MacOS 12.2.0) or later (see issue 49233). +// +// Background: +// Darwin implements a special mechanism to economize on thread state when +// AVX512 specific registers are not in use. This scheme minimizes state when +// preempting threads that haven't yet used any AVX512 instructions, but adds +// special requirements to check for AVX512 hardware support at runtime (e.g. +// via sysctl call or commpage inspection). See issue 43089 and link below for +// full background: +// https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.1.10/osfmk/i386/fpu.c#L214-L240 +// +// Additionally, all versions of the Darwin kernel from 19.6.0 through 21.2.0 +// (corresponding to MacOS 10.15.6 - 12.1) have a bug that can cause corruption +// of the AVX512 mask registers (K0-K7) upon signal return. For this reason +// AVX512 is considered unsafe to use on Darwin for kernel versions prior to +// 21.3.0, where a fix has been confirmed. See issue 49233 for full background. +func darwinSupportsAVX512() bool { + return darwinSysctlEnabled([]byte("hw.optional.avx512f\x00")) && darwinKernelVersionCheck(21, 3, 0) +} + +// Ensure Darwin kernel version is at least major.minor.patch, avoiding dependencies +func darwinKernelVersionCheck(major, minor, patch int) bool { + var release [256]byte + err := darwinOSRelease(&release) + if err != nil { + return false + } + + var mmp [3]int + c := 0 +Loop: + for _, b := range release[:] { + switch { + case b >= '0' && b <= '9': + mmp[c] = 10*mmp[c] + int(b-'0') + case b == '.': + c++ + if c > 2 { + return false + } + case b == 0: + break Loop + default: + return false + } + } + if c != 2 { + return false + } + return mmp[0] > major || mmp[0] == major && (mmp[1] > minor || mmp[1] == minor && mmp[2] >= patch) +} diff --git a/cpu/cpu_gc_x86.go b/cpu/cpu_gc_x86.go index 910728fb16..32a44514e2 100644 --- a/cpu/cpu_gc_x86.go +++ b/cpu/cpu_gc_x86.go @@ -6,10 +6,10 @@ package cpu -// cpuid is implemented in cpu_x86.s for gc compiler +// cpuid is implemented in cpu_gc_x86.s for gc compiler // and in cpu_gccgo.c for gccgo. func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) -// xgetbv with ecx = 0 is implemented in cpu_x86.s for gc compiler +// xgetbv with ecx = 0 is implemented in cpu_gc_x86.s for gc compiler // and in cpu_gccgo.c for gccgo. func xgetbv() (eax, edx uint32) diff --git a/cpu/cpu_x86.s b/cpu/cpu_gc_x86.s similarity index 94% rename from cpu/cpu_x86.s rename to cpu/cpu_gc_x86.s index 7d7ba33efb..ce208ce6d6 100644 --- a/cpu/cpu_x86.s +++ b/cpu/cpu_gc_x86.s @@ -18,7 +18,7 @@ TEXT ·cpuid(SB), NOSPLIT, $0-24 RET // func xgetbv() (eax, edx uint32) -TEXT ·xgetbv(SB),NOSPLIT,$0-8 +TEXT ·xgetbv(SB), NOSPLIT, $0-8 MOVL $0, CX XGETBV MOVL AX, eax+0(FP) diff --git a/cpu/cpu_gccgo_x86.go b/cpu/cpu_gccgo_x86.go index 99c60fe9f9..170d21ddfd 100644 --- a/cpu/cpu_gccgo_x86.go +++ b/cpu/cpu_gccgo_x86.go @@ -23,9 +23,3 @@ func xgetbv() (eax, edx uint32) { gccgoXgetbv(&a, &d) return a, d } - -// gccgo doesn't build on Darwin, per: -// https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/gcc.rb#L76 -func darwinSupportsAVX512() bool { - return false -} diff --git a/cpu/cpu_linux_arm64.go b/cpu/cpu_linux_arm64.go index 08f35ea177..f1caf0f78e 100644 --- a/cpu/cpu_linux_arm64.go +++ b/cpu/cpu_linux_arm64.go @@ -110,7 +110,6 @@ func doinit() { ARM64.HasASIMDFHM = isSet(hwCap, hwcap_ASIMDFHM) ARM64.HasDIT = isSet(hwCap, hwcap_DIT) - // HWCAP2 feature bits ARM64.HasSVE2 = isSet(hwCap2, hwcap2_SVE2) ARM64.HasI8MM = isSet(hwCap2, hwcap2_I8MM) diff --git a/cpu/cpu_other_x86.go b/cpu/cpu_other_x86.go new file mode 100644 index 0000000000..a0fd7e2f75 --- /dev/null +++ b/cpu/cpu_other_x86.go @@ -0,0 +1,11 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build 386 || amd64p32 || (amd64 && (!darwin || !gc)) + +package cpu + +func darwinSupportsAVX512() bool { + panic("only implemented for gc && amd64 && darwin") +} diff --git a/cpu/cpu_x86.go b/cpu/cpu_x86.go index c29f5e4c5a..600a680786 100644 --- a/cpu/cpu_x86.go +++ b/cpu/cpu_x86.go @@ -92,10 +92,8 @@ func archInit() { osSupportsAVX = isSet(1, eax) && isSet(2, eax) if runtime.GOOS == "darwin" { - // Darwin doesn't save/restore AVX-512 mask registers correctly across signal handlers. - // Since users can't rely on mask register contents, let's not advertise AVX-512 support. - // See issue 49233. - osSupportsAVX512 = false + // Darwin requires special AVX512 checks, see cpu_darwin_x86.go + osSupportsAVX512 = osSupportsAVX && darwinSupportsAVX512() } else { // Check if OPMASK and ZMM registers have OS support. osSupportsAVX512 = osSupportsAVX && isSet(5, eax) && isSet(6, eax) && isSet(7, eax) diff --git a/cpu/syscall_darwin_x86_gc.go b/cpu/syscall_darwin_x86_gc.go new file mode 100644 index 0000000000..4d0888b0c0 --- /dev/null +++ b/cpu/syscall_darwin_x86_gc.go @@ -0,0 +1,98 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Minimal copy of x/sys/unix so the cpu package can make a +// system call on Darwin without depending on x/sys/unix. + +//go:build darwin && amd64 && gc + +package cpu + +import ( + "syscall" + "unsafe" +) + +type _C_int int32 + +// adapted from unix.Uname() at x/sys/unix/syscall_darwin.go L419 +func darwinOSRelease(release *[256]byte) error { + // from x/sys/unix/zerrors_openbsd_amd64.go + const ( + CTL_KERN = 0x1 + KERN_OSRELEASE = 0x2 + ) + + mib := []_C_int{CTL_KERN, KERN_OSRELEASE} + n := unsafe.Sizeof(*release) + + return sysctl(mib, &release[0], &n, nil, 0) +} + +type Errno = syscall.Errno + +var _zero uintptr // Single-word zero for use when we need a valid pointer to 0 bytes. + +// from x/sys/unix/zsyscall_darwin_amd64.go L791-807 +func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + if _, _, err := syscall_syscall6( + libc_sysctl_trampoline_addr, + uintptr(_p0), + uintptr(len(mib)), + uintptr(unsafe.Pointer(old)), + uintptr(unsafe.Pointer(oldlen)), + uintptr(unsafe.Pointer(new)), + uintptr(newlen), + ); err != 0 { + return err + } + + return nil +} + +var libc_sysctl_trampoline_addr uintptr + +// adapted from internal/cpu/cpu_arm64_darwin.go +func darwinSysctlEnabled(name []byte) bool { + out := int32(0) + nout := unsafe.Sizeof(out) + if ret := sysctlbyname(&name[0], (*byte)(unsafe.Pointer(&out)), &nout, nil, 0); ret != nil { + return false + } + return out > 0 +} + +//go:cgo_import_dynamic libc_sysctl sysctl "/usr/lib/libSystem.B.dylib" + +var libc_sysctlbyname_trampoline_addr uintptr + +// adapted from runtime/sys_darwin.go in the pattern of sysctl() above, as defined in x/sys/unix +func sysctlbyname(name *byte, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error { + if _, _, err := syscall_syscall6( + libc_sysctlbyname_trampoline_addr, + uintptr(unsafe.Pointer(name)), + uintptr(unsafe.Pointer(old)), + uintptr(unsafe.Pointer(oldlen)), + uintptr(unsafe.Pointer(new)), + uintptr(newlen), + 0, + ); err != 0 { + return err + } + + return nil +} + +//go:cgo_import_dynamic libc_sysctlbyname sysctlbyname "/usr/lib/libSystem.B.dylib" + +// Implemented in the runtime package (runtime/sys_darwin.go) +func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) + +//go:linkname syscall_syscall6 syscall.syscall6 diff --git a/unix/ioctl_linux.go b/unix/ioctl_linux.go index dbe680eab8..7ca4fa12aa 100644 --- a/unix/ioctl_linux.go +++ b/unix/ioctl_linux.go @@ -58,6 +58,102 @@ func IoctlGetEthtoolDrvinfo(fd int, ifname string) (*EthtoolDrvinfo, error) { return &value, err } +// IoctlGetEthtoolTsInfo fetches ethtool timestamping and PHC +// association for the network device specified by ifname. +func IoctlGetEthtoolTsInfo(fd int, ifname string) (*EthtoolTsInfo, error) { + ifr, err := NewIfreq(ifname) + if err != nil { + return nil, err + } + + value := EthtoolTsInfo{Cmd: ETHTOOL_GET_TS_INFO} + ifrd := ifr.withData(unsafe.Pointer(&value)) + + err = ioctlIfreqData(fd, SIOCETHTOOL, &ifrd) + return &value, err +} + +// IoctlGetHwTstamp retrieves the hardware timestamping configuration +// for the network device specified by ifname. +func IoctlGetHwTstamp(fd int, ifname string) (*HwTstampConfig, error) { + ifr, err := NewIfreq(ifname) + if err != nil { + return nil, err + } + + value := HwTstampConfig{} + ifrd := ifr.withData(unsafe.Pointer(&value)) + + err = ioctlIfreqData(fd, SIOCGHWTSTAMP, &ifrd) + return &value, err +} + +// IoctlSetHwTstamp updates the hardware timestamping configuration for +// the network device specified by ifname. +func IoctlSetHwTstamp(fd int, ifname string, cfg *HwTstampConfig) error { + ifr, err := NewIfreq(ifname) + if err != nil { + return err + } + ifrd := ifr.withData(unsafe.Pointer(cfg)) + return ioctlIfreqData(fd, SIOCSHWTSTAMP, &ifrd) +} + +// FdToClockID derives the clock ID from the file descriptor number +// - see clock_gettime(3), FD_TO_CLOCKID macros. The resulting ID is +// suitable for system calls like ClockGettime. +func FdToClockID(fd int) int32 { return int32((int(^fd) << 3) | 3) } + +// IoctlPtpClockGetcaps returns the description of a given PTP device. +func IoctlPtpClockGetcaps(fd int) (*PtpClockCaps, error) { + var value PtpClockCaps + err := ioctlPtr(fd, PTP_CLOCK_GETCAPS2, unsafe.Pointer(&value)) + return &value, err +} + +// IoctlPtpSysOffsetPrecise returns a description of the clock +// offset compared to the system clock. +func IoctlPtpSysOffsetPrecise(fd int) (*PtpSysOffsetPrecise, error) { + var value PtpSysOffsetPrecise + err := ioctlPtr(fd, PTP_SYS_OFFSET_PRECISE2, unsafe.Pointer(&value)) + return &value, err +} + +// IoctlPtpSysOffsetExtended returns an extended description of the +// clock offset compared to the system clock. The samples parameter +// specifies the desired number of measurements. +func IoctlPtpSysOffsetExtended(fd int, samples uint) (*PtpSysOffsetExtended, error) { + value := PtpSysOffsetExtended{Samples: uint32(samples)} + err := ioctlPtr(fd, PTP_SYS_OFFSET_EXTENDED2, unsafe.Pointer(&value)) + return &value, err +} + +// IoctlPtpPinGetfunc returns the configuration of the specified +// I/O pin on given PTP device. +func IoctlPtpPinGetfunc(fd int, index uint) (*PtpPinDesc, error) { + value := PtpPinDesc{Index: uint32(index)} + err := ioctlPtr(fd, PTP_PIN_GETFUNC2, unsafe.Pointer(&value)) + return &value, err +} + +// IoctlPtpPinSetfunc updates configuration of the specified PTP +// I/O pin. +func IoctlPtpPinSetfunc(fd int, pd *PtpPinDesc) error { + return ioctlPtr(fd, PTP_PIN_SETFUNC2, unsafe.Pointer(pd)) +} + +// IoctlPtpPeroutRequest configures the periodic output mode of the +// PTP I/O pins. +func IoctlPtpPeroutRequest(fd int, r *PtpPeroutRequest) error { + return ioctlPtr(fd, PTP_PEROUT_REQUEST2, unsafe.Pointer(r)) +} + +// IoctlPtpExttsRequest configures the external timestamping mode +// of the PTP I/O pins. +func IoctlPtpExttsRequest(fd int, r *PtpExttsRequest) error { + return ioctlPtr(fd, PTP_EXTTS_REQUEST2, unsafe.Pointer(r)) +} + // IoctlGetWatchdogInfo fetches information about a watchdog device from the // Linux watchdog API. For more information, see: // https://www.kernel.org/doc/html/latest/watchdog/watchdog-api.html. diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile index 0e533d89a7..5cfd42e170 100644 --- a/unix/linux/Dockerfile +++ b/unix/linux/Dockerfile @@ -1,7 +1,7 @@ -FROM ubuntu:20.04 +FROM ubuntu:24.10 # Disable interactive prompts on package installation -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive # Dependencies to get the git sources and go binaries RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -21,16 +21,16 @@ RUN git clone --branch v6.11 --depth 1 https://kernel.googlesource.com/pub/scm/l RUN git clone --branch release/2.40/master --depth 1 https://sourceware.org/git/glibc.git # Get Go -ENV GOLANG_VERSION 1.23.0 -ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz -ENV GOLANG_DOWNLOAD_SHA256 905a297f19ead44780548933e0ff1a1b86e8327bb459e92f9c0012569f76f5e3 +ENV GOLANG_VERSION=1.23.0 +ENV GOLANG_DOWNLOAD_URL=https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz +ENV GOLANG_DOWNLOAD_SHA256=905a297f19ead44780548933e0ff1a1b86e8327bb459e92f9c0012569f76f5e3 RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ && tar -C /usr/local -xzf golang.tar.gz \ && rm golang.tar.gz -ENV PATH /usr/local/go/bin:$PATH +ENV PATH=/usr/local/go/bin:$PATH # Linux and Glibc build dependencies and emulator RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -48,25 +48,11 @@ RUN apt-get update && apt-get install -y \ gcc-powerpc-linux-gnu gcc-powerpc64-linux-gnu \ gcc-powerpc64le-linux-gnu gcc-riscv64-linux-gnu \ gcc-s390x-linux-gnu gcc-sparc64-linux-gnu \ + gcc-loongarch64-linux-gnu \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -# Only for loong64, getting tools of qemu-user and gcc-cross-compiler -ENV LOONG64_BASE_URL https://github.com/loongson/build-tools/releases/download/2023.08.08 -ENV LOONG64_GCC CLFS-loongarch64-8.1-x86_64-cross-tools-gcc-glibc.tar.xz -ENV LOONG64_QEMU qemu-loongarch64 -ENV LOONG64_GCC_DOWNLOAD_URL $LOONG64_BASE_URL/$LOONG64_GCC -ENV LOONG64_QEMU_DOWNLOAD_URL $LOONG64_BASE_URL/$LOONG64_QEMU - -RUN apt-get update && apt-get install xz-utils -y && mkdir /loong64 && cd /loong64 \ - && curl -fsSL "$LOONG64_QEMU_DOWNLOAD_URL" -o /usr/bin/"$LOONG64_QEMU" \ - && chmod +x /usr/bin/"$LOONG64_QEMU" \ - && curl -fsSL "$LOONG64_GCC_DOWNLOAD_URL" -o "$LOONG64_GCC" \ - && tar xf "$LOONG64_GCC" -C /usr/local/ \ - && ln -s /usr/local/cross-tools/bin/loongarch64-unknown-linux-gnu-gcc /usr/bin/loongarch64-linux-gnu-gcc \ - && rm -rf /loong64 - # Let the scripts know they are in the docker environment -ENV GOLANG_SYS_BUILD docker +ENV GOLANG_SYS_BUILD=docker WORKDIR /build/unix ENTRYPOINT ["go", "run", "linux/mkall.go", "/git/linux", "/git/glibc"] diff --git a/unix/linux/types.go b/unix/linux/types.go index 0ba570fe16..8109005cfe 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -20,6 +20,21 @@ package unix #define _FILE_OFFSET_BITS 64 #define _GNU_SOURCE +// Ref: include/linux/time32.h +// +// On Linux, in order to solve the overflow problem of time_t type variables on +// 32-bit arm, mips, and powerpc in 2038, the definition of time_t is switched +// from a 32-bit field to a 64-bit field. For backward compatibility, we force +// the use of 32-bit fields. +#if defined(__ARM_EABI__) || \ + (defined(__mips__) && (_MIPS_SIM == _ABIO32)) || \ + (defined(__powerpc__) && (!defined(__powerpc64__))) +# ifdef _TIME_BITS +# undef _TIME_BITS +# endif +# define _TIME_BITS 32 +#endif + #include #include #include @@ -129,12 +144,14 @@ struct termios2 { #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -509,6 +526,15 @@ struct cachestat { __u64 nr_evicted; __u64 nr_recently_evicted; }; + +// the one defined in linux/ptp_clock.h has unions +struct my_ptp_perout_request { + struct ptp_clock_time startOrPhase; // start or phase + struct ptp_clock_time period; + unsigned int index; + unsigned int flags; + struct ptp_clock_time on; +}; */ import "C" @@ -1557,7 +1583,7 @@ const ( ) // generated by: -// perl -nlE '/^\s*((IFLA|NETKIT)\w+)/ && say "$1 = C.$1"' /usr/include/linux/if_link.h +// perl -nlE '/^\s*(IFLA\w+)/ && say "$1 = C.$1"' /usr/include/linux/if_link.h const ( IFLA_UNSPEC = C.IFLA_UNSPEC IFLA_ADDRESS = C.IFLA_ADDRESS @@ -1788,12 +1814,6 @@ const ( IFLA_IPVLAN_UNSPEC = C.IFLA_IPVLAN_UNSPEC IFLA_IPVLAN_MODE = C.IFLA_IPVLAN_MODE IFLA_IPVLAN_FLAGS = C.IFLA_IPVLAN_FLAGS - NETKIT_NEXT = C.NETKIT_NEXT - NETKIT_PASS = C.NETKIT_PASS - NETKIT_DROP = C.NETKIT_DROP - NETKIT_REDIRECT = C.NETKIT_REDIRECT - NETKIT_L2 = C.NETKIT_L2 - NETKIT_L3 = C.NETKIT_L3 IFLA_NETKIT_UNSPEC = C.IFLA_NETKIT_UNSPEC IFLA_NETKIT_PEER_INFO = C.IFLA_NETKIT_PEER_INFO IFLA_NETKIT_PRIMARY = C.IFLA_NETKIT_PRIMARY @@ -1832,6 +1852,7 @@ const ( IFLA_VXLAN_DF = C.IFLA_VXLAN_DF IFLA_VXLAN_VNIFILTER = C.IFLA_VXLAN_VNIFILTER IFLA_VXLAN_LOCALBYPASS = C.IFLA_VXLAN_LOCALBYPASS + IFLA_VXLAN_LABEL_POLICY = C.IFLA_VXLAN_LABEL_POLICY IFLA_GENEVE_UNSPEC = C.IFLA_GENEVE_UNSPEC IFLA_GENEVE_ID = C.IFLA_GENEVE_ID IFLA_GENEVE_REMOTE = C.IFLA_GENEVE_REMOTE @@ -1861,6 +1882,8 @@ const ( IFLA_GTP_ROLE = C.IFLA_GTP_ROLE IFLA_GTP_CREATE_SOCKETS = C.IFLA_GTP_CREATE_SOCKETS IFLA_GTP_RESTART_COUNT = C.IFLA_GTP_RESTART_COUNT + IFLA_GTP_LOCAL = C.IFLA_GTP_LOCAL + IFLA_GTP_LOCAL6 = C.IFLA_GTP_LOCAL6 IFLA_BOND_UNSPEC = C.IFLA_BOND_UNSPEC IFLA_BOND_MODE = C.IFLA_BOND_MODE IFLA_BOND_ACTIVE_SLAVE = C.IFLA_BOND_ACTIVE_SLAVE @@ -1893,6 +1916,7 @@ const ( IFLA_BOND_AD_LACP_ACTIVE = C.IFLA_BOND_AD_LACP_ACTIVE IFLA_BOND_MISSED_MAX = C.IFLA_BOND_MISSED_MAX IFLA_BOND_NS_IP6_TARGET = C.IFLA_BOND_NS_IP6_TARGET + IFLA_BOND_COUPLED_CONTROL = C.IFLA_BOND_COUPLED_CONTROL IFLA_BOND_AD_INFO_UNSPEC = C.IFLA_BOND_AD_INFO_UNSPEC IFLA_BOND_AD_INFO_AGGREGATOR = C.IFLA_BOND_AD_INFO_AGGREGATOR IFLA_BOND_AD_INFO_NUM_PORTS = C.IFLA_BOND_AD_INFO_NUM_PORTS @@ -1961,6 +1985,7 @@ const ( IFLA_HSR_SEQ_NR = C.IFLA_HSR_SEQ_NR IFLA_HSR_VERSION = C.IFLA_HSR_VERSION IFLA_HSR_PROTOCOL = C.IFLA_HSR_PROTOCOL + IFLA_HSR_INTERLINK = C.IFLA_HSR_INTERLINK IFLA_STATS_UNSPEC = C.IFLA_STATS_UNSPEC IFLA_STATS_LINK_64 = C.IFLA_STATS_LINK_64 IFLA_STATS_LINK_XSTATS = C.IFLA_STATS_LINK_XSTATS @@ -2013,6 +2038,17 @@ const ( IFLA_DSA_MASTER = C.IFLA_DSA_MASTER ) +// netkit +// perl -nlE '/^\s*(NETKIT\w+)/ && say "$1 = C.$1"' /usr/include/linux/if_link.h +const ( + NETKIT_NEXT = C.NETKIT_NEXT + NETKIT_PASS = C.NETKIT_PASS + NETKIT_DROP = C.NETKIT_DROP + NETKIT_REDIRECT = C.NETKIT_REDIRECT + NETKIT_L2 = C.NETKIT_L2 + NETKIT_L3 = C.NETKIT_L3 +) + // netfilter // generated using: // perl -nlE '/^\s*(NF\w+)/ && say "$1 = C.$1"' /usr/include/linux/netfilter.h @@ -4090,6 +4126,45 @@ const SPEED_UNKNOWN = C.SPEED_UNKNOWN type EthtoolDrvinfo C.struct_ethtool_drvinfo +type EthtoolTsInfo C.struct_ethtool_ts_info + +type HwTstampConfig C.struct_hwtstamp_config + +const ( + HWTSTAMP_FILTER_NONE = C.HWTSTAMP_FILTER_NONE + HWTSTAMP_FILTER_ALL = C.HWTSTAMP_FILTER_ALL + HWTSTAMP_FILTER_SOME = C.HWTSTAMP_FILTER_SOME + HWTSTAMP_FILTER_PTP_V1_L4_EVENT = C.HWTSTAMP_FILTER_PTP_V1_L4_EVENT + HWTSTAMP_FILTER_PTP_V2_L4_EVENT = C.HWTSTAMP_FILTER_PTP_V2_L4_EVENT + HWTSTAMP_FILTER_PTP_V2_L2_EVENT = C.HWTSTAMP_FILTER_PTP_V2_L2_EVENT + HWTSTAMP_FILTER_PTP_V2_EVENT = C.HWTSTAMP_FILTER_PTP_V2_EVENT +) + +const ( + HWTSTAMP_TX_OFF = C.HWTSTAMP_TX_OFF + HWTSTAMP_TX_ON = C.HWTSTAMP_TX_ON + HWTSTAMP_TX_ONESTEP_SYNC = C.HWTSTAMP_TX_ONESTEP_SYNC +) + +type ( + PtpClockCaps C.struct_ptp_clock_caps + PtpClockTime C.struct_ptp_clock_time + PtpExttsEvent C.struct_ptp_extts_event + PtpExttsRequest C.struct_ptp_extts_request + PtpPeroutRequest C.struct_my_ptp_perout_request + PtpPinDesc C.struct_ptp_pin_desc + PtpSysOffset C.struct_ptp_sys_offset + PtpSysOffsetExtended C.struct_ptp_sys_offset_extended + PtpSysOffsetPrecise C.struct_ptp_sys_offset_precise +) + +const ( + PTP_PF_NONE = C.PTP_PF_NONE + PTP_PF_EXTTS = C.PTP_PF_EXTTS + PTP_PF_PEROUT = C.PTP_PF_PEROUT + PTP_PF_PHYSYNC = C.PTP_PF_PHYSYNC +) + type ( HIDRawReportDescriptor C.struct_hidraw_report_descriptor HIDRawDevInfo C.struct_hidraw_devinfo diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index ac54ecaba0..6ab02b6c31 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -158,6 +158,16 @@ includes_Linux=' #endif #define _GNU_SOURCE +// See the description in unix/linux/types.go +#if defined(__ARM_EABI__) || \ + (defined(__mips__) && (_MIPS_SIM == _ABIO32)) || \ + (defined(__powerpc__) && (!defined(__powerpc64__))) +# ifdef _TIME_BITS +# undef _TIME_BITS +# endif +# define _TIME_BITS 32 +#endif + // is broken on powerpc64, as it fails to include definitions of // these structures. We just include them copied from . #if defined(__powerpc__) @@ -256,6 +266,7 @@ struct ltchars { #include #include #include +#include #include #include #include @@ -527,6 +538,7 @@ ccflags="$@" $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MREMAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL|TCPOPT|UDP)_/ || $2 ~ /^NFC_(GENL|PROTO|COMM|RF|SE|DIRECTION|LLCP|SOCKPROTO)_/ || $2 ~ /^NFC_.*_(MAX)?SIZE$/ || + $2 ~ /^PTP_/ || $2 ~ /^RAW_PAYLOAD_/ || $2 ~ /^[US]F_/ || $2 ~ /^TP_STATUS_/ || diff --git a/unix/mkpost.go b/unix/mkpost.go index ecacf010c9..5aa20c6a80 100644 --- a/unix/mkpost.go +++ b/unix/mkpost.go @@ -185,6 +185,15 @@ func main() { b = bytes.Replace(b, s, newNames, 1) } + // Convert []int8 to []byte in PtpPinDesc + ptpBytesRegex := regexp.MustCompile(`(Name)(\s+)\[(\d+)\]u?int8`) + ptpIoctlType := regexp.MustCompile(`PtpPinDesc\s+struct {[^}]*}`) + ptpStructs := ptpIoctlType.FindAll(b, -1) + for _, s := range ptpStructs { + newNames := ptpBytesRegex.ReplaceAll(s, []byte("$1$2[$3]byte")) + b = bytes.Replace(b, s, newNames, 1) + } + // Convert []int8 to []byte in ctl_info ioctl interface convertCtlInfoName := regexp.MustCompile(`(Name)(\s+)\[(\d+)\]int8`) ctlInfoType := regexp.MustCompile(`type CtlInfo struct {[^}]*}`) diff --git a/unix/mmap_zos_test.go b/unix/mmap_zos_test.go index f35d9c1e12..15abcee9c7 100644 --- a/unix/mmap_zos_test.go +++ b/unix/mmap_zos_test.go @@ -72,3 +72,17 @@ func TestMmap(t *testing.T) { t.Fatalf("Munmap: %v", err) } } + +func TestMmapPtr(t *testing.T) { + p, err := unix.MmapPtr(-1, 0, nil, uintptr(2*unix.Getpagesize()), + unix.PROT_READ|unix.PROT_WRITE, unix.MAP_ANON|unix.MAP_PRIVATE) + if err != nil { + t.Fatalf("MmapPtr: %v", err) + } + + *(*byte)(p) = 42 + + if err := unix.MunmapPtr(p, uintptr(2*unix.Getpagesize())); err != nil { + t.Fatalf("MunmapPtr: %v", err) + } +} diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index f08abd434f..230a94549a 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -1860,6 +1860,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e //sys ClockAdjtime(clockid int32, buf *Timex) (state int, err error) //sys ClockGetres(clockid int32, res *Timespec) (err error) //sys ClockGettime(clockid int32, time *Timespec) (err error) +//sys ClockSettime(clockid int32, time *Timespec) (err error) //sys ClockNanosleep(clockid int32, flags int, request *Timespec, remain *Timespec) (err error) //sys Close(fd int) (err error) //sys CloseRange(first uint, last uint, flags uint) (err error) diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index 53e64458c4..eca3b7aad4 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -68,6 +68,44 @@ func TestIoctlGetEthtoolDrvinfo(t *testing.T) { } } +func TestIoctlGetEthtoolTsInfo(t *testing.T) { + if runtime.GOOS == "android" { + t.Skip("ethtool driver info is not available on android, skipping test") + } + + s, err := unix.Socket(unix.AF_INET, unix.SOCK_STREAM, 0) + if err != nil { + t.Fatalf("failed to open socket: %v", err) + } + defer unix.Close(s) + + ifis, err := net.Interfaces() + if err != nil { + t.Fatalf("failed to get network interfaces: %v", err) + } + + // Print the interface name and associated PHC information for each + // network interface supported by ethtool. + for _, ifi := range ifis { + tsi, err := unix.IoctlGetEthtoolTsInfo(s, ifi.Name) + if err != nil { + if err == unix.EOPNOTSUPP { + continue + } + + if err == unix.EBUSY { + // See https://go.dev/issues/67350 + t.Logf("%s: ethtool driver busy, possible kernel bug", ifi.Name) + continue + } + + t.Fatalf("failed to get ethtool PHC info for %q: %v", ifi.Name, err) + } + + t.Logf("%s: ptp%d", ifi.Name, tsi.Phc_index) + } +} + func TestIoctlGetInt(t *testing.T) { f, err := os.Open("/dev/random") if err != nil { diff --git a/unix/syscall_zos_s390x.go b/unix/syscall_zos_s390x.go index 312ae6ac1d..7bf5c04bb0 100644 --- a/unix/syscall_zos_s390x.go +++ b/unix/syscall_zos_s390x.go @@ -768,6 +768,15 @@ func Munmap(b []byte) (err error) { return mapper.Munmap(b) } +func MmapPtr(fd int, offset int64, addr unsafe.Pointer, length uintptr, prot int, flags int) (ret unsafe.Pointer, err error) { + xaddr, err := mapper.mmap(uintptr(addr), length, prot, flags, fd, offset) + return unsafe.Pointer(xaddr), err +} + +func MunmapPtr(addr unsafe.Pointer, length uintptr) (err error) { + return mapper.munmap(uintptr(addr), length) +} + //sys Gethostname(buf []byte) (err error) = SYS___GETHOSTNAME_A //sysnb Getgid() (gid int) //sysnb Getpid() (pid int) @@ -816,10 +825,10 @@ func Lstat(path string, stat *Stat_t) (err error) { // for checking symlinks begins with $VERSION/ $SYSNAME/ $SYSSYMR/ $SYSSYMA/ func isSpecialPath(path []byte) (v bool) { var special = [4][8]byte{ - [8]byte{'V', 'E', 'R', 'S', 'I', 'O', 'N', '/'}, - [8]byte{'S', 'Y', 'S', 'N', 'A', 'M', 'E', '/'}, - [8]byte{'S', 'Y', 'S', 'S', 'Y', 'M', 'R', '/'}, - [8]byte{'S', 'Y', 'S', 'S', 'Y', 'M', 'A', '/'}} + {'V', 'E', 'R', 'S', 'I', 'O', 'N', '/'}, + {'S', 'Y', 'S', 'N', 'A', 'M', 'E', '/'}, + {'S', 'Y', 'S', 'S', 'Y', 'M', 'R', '/'}, + {'S', 'Y', 'S', 'S', 'Y', 'M', 'A', '/'}} var i, j int for i = 0; i < len(special); i++ { @@ -3115,3 +3124,90 @@ func legacy_Mkfifoat(dirfd int, path string, mode uint32) (err error) { //sys Posix_openpt(oflag int) (fd int, err error) = SYS_POSIX_OPENPT //sys Grantpt(fildes int) (rc int, err error) = SYS_GRANTPT //sys Unlockpt(fildes int) (rc int, err error) = SYS_UNLOCKPT + +func fcntlAsIs(fd uintptr, cmd int, arg uintptr) (val int, err error) { + runtime.EnterSyscall() + r0, e2, e1 := CallLeFuncWithErr(GetZosLibVec()+SYS_FCNTL<<4, uintptr(fd), uintptr(cmd), arg) + runtime.ExitSyscall() + val = int(r0) + if int64(r0) == -1 { + err = errnoErr2(e1, e2) + } + return +} + +func Fcntl(fd uintptr, cmd int, op interface{}) (ret int, err error) { + switch op.(type) { + case *Flock_t: + err = FcntlFlock(fd, cmd, op.(*Flock_t)) + if err != nil { + ret = -1 + } + return + case int: + return FcntlInt(fd, cmd, op.(int)) + case *F_cnvrt: + return fcntlAsIs(fd, cmd, uintptr(unsafe.Pointer(op.(*F_cnvrt)))) + case unsafe.Pointer: + return fcntlAsIs(fd, cmd, uintptr(op.(unsafe.Pointer))) + default: + return -1, EINVAL + } + return +} + +func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { + if raceenabled { + raceReleaseMerge(unsafe.Pointer(&ioSync)) + } + return sendfile(outfd, infd, offset, count) +} + +func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { + // TODO: use LE call instead if the call is implemented + originalOffset, err := Seek(infd, 0, SEEK_CUR) + if err != nil { + return -1, err + } + //start reading data from in_fd + if offset != nil { + _, err := Seek(infd, *offset, SEEK_SET) + if err != nil { + return -1, err + } + } + + buf := make([]byte, count) + readBuf := make([]byte, 0) + var n int = 0 + for i := 0; i < count; i += n { + n, err := Read(infd, buf) + if n == 0 { + if err != nil { + return -1, err + } else { // EOF + break + } + } + readBuf = append(readBuf, buf...) + buf = buf[0:0] + } + + n2, err := Write(outfd, readBuf) + if err != nil { + return -1, err + } + + //When sendfile() returns, this variable will be set to the + // offset of the byte following the last byte that was read. + if offset != nil { + *offset = *offset + int64(n) + // If offset is not NULL, then sendfile() does not modify the file + // offset of in_fd + _, err := Seek(infd, originalOffset, SEEK_SET) + if err != nil { + return -1, err + } + } + return n2, nil +} diff --git a/unix/syscall_zos_test.go b/unix/syscall_zos_test.go index c04f5a00f7..fad3744654 100644 --- a/unix/syscall_zos_test.go +++ b/unix/syscall_zos_test.go @@ -7,6 +7,7 @@ package unix_test import ( + "bytes" "errors" "flag" "fmt" @@ -202,7 +203,7 @@ func TestSignalNum(t *testing.T) { func TestFcntlInt(t *testing.T) { t.Parallel() - file, err := os.Create(filepath.Join(t.TempDir(), "TestFnctlInt")) + file, err := os.Create(filepath.Join(t.TempDir(), t.Name())) if err != nil { t.Fatal(err) } @@ -217,10 +218,27 @@ func TestFcntlInt(t *testing.T) { } } +func TestFcntlInt2(t *testing.T) { + t.Parallel() + file, err := os.Create(filepath.Join(t.TempDir(), t.Name())) + if err != nil { + t.Fatal(err) + } + defer file.Close() + f := file.Fd() + flags, err := unix.Fcntl(f, unix.F_GETFD, 0) + if err != nil { + t.Fatal(err) + } + if flags&unix.FD_CLOEXEC == 0 { + t.Errorf("flags %#x do not include FD_CLOEXEC", flags) + } +} + // TestFcntlFlock tests whether the file locking structure matches // the calling convention of each kernel. func TestFcntlFlock(t *testing.T) { - name := filepath.Join(os.TempDir(), "TestFcntlFlock") + name := filepath.Join(t.TempDir(), "TestFcntlFlock") fd, err := unix.Open(name, unix.O_CREAT|unix.O_RDWR|unix.O_CLOEXEC, 0) if err != nil { t.Fatalf("Open failed: %v", err) @@ -236,6 +254,23 @@ func TestFcntlFlock(t *testing.T) { } } +func TestFcntlFlock2(t *testing.T) { + name := filepath.Join(t.TempDir(), "TestFcntlFlock2") + fd, err := unix.Open(name, unix.O_CREAT|unix.O_RDWR|unix.O_CLOEXEC, 0) + if err != nil { + t.Fatalf("Open failed: %v", err) + } + defer unix.Unlink(name) + defer unix.Close(fd) + flock := unix.Flock_t{ + Type: unix.F_RDLCK, + Start: 0, Len: 0, Whence: 1, + } + if v, err := unix.Fcntl(uintptr(fd), unix.F_GETLK, &flock); err != nil { + t.Fatalf("FcntlFlock failed: %d %v", v, err) + } +} + // TestPassFD tests passing a file descriptor over a Unix socket. // // This test involved both a parent and child process. The parent @@ -249,8 +284,6 @@ func TestPassFD(t *testing.T) { return } - tempDir := t.TempDir() - fds, err := unix.Socketpair(unix.AF_LOCAL, unix.SOCK_STREAM, 0) if err != nil { t.Fatalf("Socketpair: %v", err) @@ -262,7 +295,11 @@ func TestPassFD(t *testing.T) { defer writeFile.Close() defer readFile.Close() - cmd := exec.Command(os.Args[0], "-test.run=^TestPassFD$", "--", tempDir) + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } + cmd := exec.Command(exe, "-test.run=^TestPassFD$", "--", t.TempDir()) cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"} if lp := os.Getenv("LD_LIBRARY_PATH"); lp != "" { cmd.Env = append(cmd.Env, "LD_LIBRARY_PATH="+lp) @@ -371,7 +408,7 @@ func passFDChild() { } } -// TestUnixRightsRoundtrip tests that UnixRights, ParseSocketControlMessage, +// TestUnixRightsRoundtrip tests that UnixRights, ParseSocketControlMessage, ParseOneSocketControlMessage, // and ParseUnixRights are able to successfully round-trip lists of file descriptors. func TestUnixRightsRoundtrip(t *testing.T) { testCases := [...][][]int{ @@ -399,6 +436,23 @@ func TestUnixRightsRoundtrip(t *testing.T) { if len(scms) != len(testCase) { t.Fatalf("expected %v SocketControlMessage; got scms = %#v", len(testCase), scms) } + + var c int + for len(b) > 0 { + hdr, data, remainder, err := unix.ParseOneSocketControlMessage(b) + if err != nil { + t.Fatalf("ParseOneSocketControlMessage: %v", err) + } + if scms[c].Header != hdr || !bytes.Equal(scms[c].Data, data) { + t.Fatal("expected SocketControlMessage header and data to match") + } + b = remainder + c++ + } + if c != len(scms) { + t.Fatalf("expected %d SocketControlMessages; got %d", len(scms), c) + } + for i, scm := range scms { gotFds, err := unix.ParseUnixRights(&scm) if err != nil { @@ -474,6 +528,12 @@ func TestRlimit(t *testing.T) { if err != nil { t.Fatalf("Setrlimit: restore failed: %#v %v", rlimit, err) } + + // make sure RLIM_INFINITY can be assigned to Rlimit members + _ = unix.Rlimit{ + Cur: unix.RLIM_INFINITY, + Max: unix.RLIM_INFINITY, + } } func TestSeekFailure(t *testing.T) { @@ -497,9 +557,9 @@ func TestSetsockoptString(t *testing.T) { } func TestDup(t *testing.T) { - file, err := os.Create(filepath.Join(t.TempDir(), "TestDup")) + file, err := os.Create(filepath.Join(t.TempDir(), t.Name())) if err != nil { - t.Fatalf("Tempfile failed: %v", err) + t.Fatal(err) } defer file.Close() f := int(file.Fd()) @@ -654,25 +714,21 @@ func touch(t *testing.T, name string) { } // chtmpdir changes the working directory to a new temporary directory and -// provides a cleanup function. Used when PWD is read-only. -func chtmpdir(t *testing.T) func() { +// sets up a cleanup function. Used when PWD is read-only. +func chtmpdir(t *testing.T) { + t.Helper() oldwd, err := os.Getwd() if err != nil { - t.Fatalf("chtmpdir: %v", err) - } - d, err := os.MkdirTemp("", "test") - if err != nil { - t.Fatalf("chtmpdir: %v", err) + t.Fatal(err) } - if err := os.Chdir(d); err != nil { - t.Fatalf("chtmpdir: %v", err) + if err := os.Chdir(t.TempDir()); err != nil { + t.Fatal(err) } - return func() { + t.Cleanup(func() { if err := os.Chdir(oldwd); err != nil { - t.Fatalf("chtmpdir: %v", err) + t.Fatal(err) } - os.RemoveAll(d) - } + }) } func TestLegacyMountUnmount(t *testing.T) { @@ -888,7 +944,11 @@ func TestFlock(t *testing.T) { p2status := BLOCKED done := make(chan bool) execP2 := func(isBlock bool) { - cmd := exec.Command(os.Args[0], "-test.run=^TestFlock$", strconv.Itoa(c.p2mode), f.Name()) + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } + cmd := exec.Command(exe, "-test.run=^TestFlock$", strconv.Itoa(c.p2mode), f.Name()) cmd.Env = append(os.Environ(), "TEST_FLOCK_HELPER=1") out, _ := cmd.CombinedOutput() if p2status, err = strconv.Atoi(string(out)); err != nil { @@ -955,7 +1015,11 @@ func TestLegacyFlock(t *testing.T) { if err != nil { t.Fatalf("Flock: %s", err.Error()) } - cmd := exec.Command(os.Args[0], "-test.run=TestLegacyFlock", f.Name()) + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } + cmd := exec.Command(exe, "-test.run=TestLegacyFlock", f.Name()) cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1") out, err := cmd.CombinedOutput() if len(out) > 0 || err != nil { @@ -2323,7 +2387,11 @@ func TestWait4(t *testing.T) { for _, c := range testCases { t.Run(c.name, func(t *testing.T) { - cmd := exec.Command(os.Args[0], "-test.run=^TestWait4$", fmt.Sprint(c.exitCode)) + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } + cmd := exec.Command(exe, "-test.run=^TestWait4$", fmt.Sprint(c.exitCode)) cmd.Env = []string{"TEST_WAIT4_HELPER=1"} if err := cmd.Start(); err != nil { t.Fatal(err) @@ -2624,7 +2692,11 @@ func TestMountNamespace(t *testing.T) { defer os.Remove(f.Name()) f.Close() - cmd := exec.Command(os.Args[0], "-test.v", "-test.run=^TestMountNamespace$") + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } + cmd := exec.Command(exe, "-test.v", "-test.run=^TestMountNamespace$") cmd.Env = append(os.Environ(), "SETNS_HELPER_PROCESS=1") cmd.Env = append(cmd.Env, "MNT_NS_FILE="+f.Name()) @@ -2993,7 +3065,7 @@ func TestUnlinkat(t *testing.T) { } func TestRenameat(t *testing.T) { - defer chtmpdir(t)() + chtmpdir(t) from, to := "renamefrom", "renameto" @@ -3016,7 +3088,7 @@ func TestRenameat(t *testing.T) { } func TestRenameat2(t *testing.T) { - defer chtmpdir(t)() + chtmpdir(t) from, to := "renamefrom", "renameto" @@ -3050,7 +3122,7 @@ func TestRenameat2(t *testing.T) { } func TestFchmodat(t *testing.T) { - defer chtmpdir(t)() + chtmpdir(t) touch(t, "file1") err := os.Symlink("file1", "symlink1") @@ -3148,7 +3220,7 @@ func compareStat_t(t *testing.T, otherStat string, st1, st2 *unix.Stat_t) { } func TestFstatat(t *testing.T) { - defer chtmpdir(t)() + chtmpdir(t) touch(t, "file1") @@ -3618,7 +3690,11 @@ func TestSetns(t *testing.T) { } } - cmd := exec.Command(os.Args[0], "-test.run=^TestSetns$") + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } + cmd := exec.Command(exe, "-test.run=^TestSetns$") cmd.Env = append(os.Environ(), "SETNS_HELPER_PROCESS=1") stdin, err := cmd.StdinPipe() if err != nil { @@ -3749,3 +3825,194 @@ func TestConsole2modify(t *testing.T) { t.Logf("Got %s %x\n", unix.ZosEbcdicBytesToString(modstr[:], true), cmsg_cmd) } +func TestTty(t *testing.T) { + ptmxfd, err := unix.Posix_openpt(unix.O_RDWR) + if err != nil { + t.Fatalf("Posix_openpt %+v\n", err) + } + t.Logf("ptmxfd %v\n", ptmxfd) + + // convert to EBCDIC + cvtreq := unix.F_cnvrt{Cvtcmd: unix.SETCVTON, Pccsid: 0, Fccsid: 1047} + if _, err = unix.Fcntl(uintptr(ptmxfd), unix.F_CONTROL_CVT, &cvtreq); err != nil { + t.Fatalf("fcntl F_CONTROL_CVT %+v\n", err) + } + p := os.NewFile(uintptr(ptmxfd), "/dev/ptmx") + if p == nil { + t.Fatalf("NewFile %d /dev/ptmx failed\n", ptmxfd) + } + + // In case of error after this point, make sure we close the ptmx fd. + defer func() { + if err != nil { + _ = p.Close() // Best effort. + } + }() + sname, err := unix.Ptsname(ptmxfd) + if err != nil { + t.Fatalf("Ptsname %+v\n", err) + } + t.Logf("sname %v\n", sname) + + _, err = unix.Grantpt(ptmxfd) + if err != nil { + t.Fatalf("Grantpt %+v\n", err) + } + + if _, err = unix.Unlockpt(ptmxfd); err != nil { + t.Fatalf("Unlockpt %+v\n", err) + } + + ptsfd, err := syscall.Open(sname, os.O_RDWR|syscall.O_NOCTTY, 0) + if err != nil { + t.Fatalf("Open %s %+v\n", sname, err) + } + if _, err = unix.Fcntl(uintptr(ptsfd), unix.F_CONTROL_CVT, &cvtreq); err != nil { + t.Fatalf("fcntl F_CONTROL_CVT ptsfd %+v\n", err) + } + + tt := os.NewFile(uintptr(ptsfd), sname) + if err != nil { + t.Fatalf("NewFile %d %+v %+v\n", ptsfd, sname, err) + } + text := []byte("11111111") + + n, err := tt.Write(text) + if err != nil { + t.Fatalf("ptsfd Write %+v\n", err) + } + t.Logf("bytes %d\n", n) + + var buffer [1024]byte + + n, err = p.Read(buffer[:n]) + if err != nil { + t.Fatalf("ptmx read %+v\n", err) + } + t.Logf("Buffer %+v\n", buffer[:n]) + + if !bytes.Equal(text, buffer[:n]) { + t.Fatalf("Expected %+v, read %+v\n", text, buffer[:n]) + + } + +} + +func TestSendfile(t *testing.T) { + srcContent := "hello, world" + srcFile, err := os.Create(filepath.Join(t.TempDir(), "source")) + if err != nil { + t.Fatal("error: ", err) + } + defer srcFile.Close() + + dstFile, err := os.Create(filepath.Join(t.TempDir(), "dst")) + if err != nil { + t.Fatal("error: ", err) + } + defer dstFile.Close() + + err = os.WriteFile(srcFile.Name(), []byte(srcContent), 0644) + if err != nil { + t.Fatal("error: ", err) + } + + n, err := unix.Sendfile(int(dstFile.Fd()), int(srcFile.Fd()), nil, len(srcContent)) + if n != len(srcContent) { + t.Fatal("error: mismatch content length want ", len(srcContent), " got ", n) + } + if err != nil { + t.Fatal("error: ", err) + } + + b, err := os.ReadFile(dstFile.Name()) + if err != nil { + t.Fatal("error: ", err) + } + + content := string(b) + if content != srcContent { + t.Fatal("content mismatch: ", content, " vs ", srcContent) + } +} + +func TestSendfileSocket(t *testing.T) { + // Set up source data file. + name := filepath.Join(t.TempDir(), "source") + const contents = "contents" + err := os.WriteFile(name, []byte(contents), 0666) + if err != nil { + t.Fatal(err) + } + + done := make(chan bool) + + // Start server listening on a socket. + ln, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Skipf("listen failed: %s\n", err) + } + defer ln.Close() + go func() { + conn, err := ln.Accept() + if err != nil { + t.Errorf("failed to accept: %v", err) + return + } + defer conn.Close() + b, err := io.ReadAll(conn) + if err != nil { + t.Errorf("failed to read: %v", err) + return + } + if string(b) != contents { + t.Errorf("contents not transmitted: got %s (len=%d), want %s", string(b), len(b), contents) + } + done <- true + }() + + // Open source file. + src, err := os.Open(name) + if err != nil { + t.Fatal(err) + } + + // Send source file to server. + conn, err := net.Dial("tcp", ln.Addr().String()) + if err != nil { + t.Fatal(err) + } + file, err := conn.(*net.TCPConn).File() + if err != nil { + t.Fatal(err) + } + var off int64 + n, err := unix.Sendfile(int(file.Fd()), int(src.Fd()), &off, len(contents)) + if err != nil { + t.Errorf("Sendfile failed %s\n", err) + } + if n != len(contents) { + t.Errorf("written count wrong: want %d, got %d", len(contents), n) + } + // Note: off is updated on some systems and not others. Oh well. + // Linux: increments off by the amount sent. + // Darwin: leaves off unchanged. + // It would be nice to fix Darwin if we can. + if off != 0 && off != int64(len(contents)) { + t.Errorf("offset wrong: god %d, want %d or %d", off, 0, len(contents)) + } + // The cursor position should be unchanged. + pos, err := src.Seek(0, 1) + if err != nil { + t.Errorf("can't get cursor position %s\n", err) + } + if pos != 0 { + t.Errorf("cursor position wrong: got %d, want 0", pos) + } + + file.Close() // Note: required to have the close below really send EOF to the server. + conn.Close() + + // Wait for server to close. + <-done +} diff --git a/unix/xattr_zos_test.go b/unix/xattr_zos_test.go index 982037fa4d..b19a8765c6 100644 --- a/unix/xattr_zos_test.go +++ b/unix/xattr_zos_test.go @@ -14,7 +14,7 @@ import ( ) func TestXattr(t *testing.T) { - defer chtmpdir(t)() + chtmpdir(t) f := "xattr1" touch(t, f) diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index de3b462489..ccba391c9f 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -2625,6 +2625,28 @@ const ( PR_UNALIGN_NOPRINT = 0x1 PR_UNALIGN_SIGBUS = 0x2 PSTOREFS_MAGIC = 0x6165676c + PTP_CLK_MAGIC = '=' + PTP_ENABLE_FEATURE = 0x1 + PTP_EXTTS_EDGES = 0x6 + PTP_EXTTS_EVENT_VALID = 0x1 + PTP_EXTTS_V1_VALID_FLAGS = 0x7 + PTP_EXTTS_VALID_FLAGS = 0x1f + PTP_EXT_OFFSET = 0x10 + PTP_FALLING_EDGE = 0x4 + PTP_MAX_SAMPLES = 0x19 + PTP_PEROUT_DUTY_CYCLE = 0x2 + PTP_PEROUT_ONE_SHOT = 0x1 + PTP_PEROUT_PHASE = 0x4 + PTP_PEROUT_V1_VALID_FLAGS = 0x0 + PTP_PEROUT_VALID_FLAGS = 0x7 + PTP_PIN_GETFUNC = 0xc0603d06 + PTP_PIN_GETFUNC2 = 0xc0603d0f + PTP_RISING_EDGE = 0x2 + PTP_STRICT_FLAGS = 0x8 + PTP_SYS_OFFSET_EXTENDED = 0xc4c03d09 + PTP_SYS_OFFSET_EXTENDED2 = 0xc4c03d12 + PTP_SYS_OFFSET_PRECISE = 0xc0403d08 + PTP_SYS_OFFSET_PRECISE2 = 0xc0403d11 PTRACE_ATTACH = 0x10 PTRACE_CONT = 0x7 PTRACE_DETACH = 0x11 diff --git a/unix/zerrors_linux_386.go b/unix/zerrors_linux_386.go index 8aa6d77c01..0c00cb3f3a 100644 --- a/unix/zerrors_linux_386.go +++ b/unix/zerrors_linux_386.go @@ -237,6 +237,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x7434 PPPIOCXFERUNIT = 0x744e PR_SET_PTRACER_ANY = 0xffffffff + PTP_CLOCK_GETCAPS = 0x80503d01 + PTP_CLOCK_GETCAPS2 = 0x80503d0a + PTP_ENABLE_PPS = 0x40043d04 + PTP_ENABLE_PPS2 = 0x40043d0d + PTP_EXTTS_REQUEST = 0x40103d02 + PTP_EXTTS_REQUEST2 = 0x40103d0b + PTP_MASK_CLEAR_ALL = 0x3d13 + PTP_MASK_EN_SINGLE = 0x40043d14 + PTP_PEROUT_REQUEST = 0x40383d03 + PTP_PEROUT_REQUEST2 = 0x40383d0c + PTP_PIN_SETFUNC = 0x40603d07 + PTP_PIN_SETFUNC2 = 0x40603d10 + PTP_SYS_OFFSET = 0x43403d05 + PTP_SYS_OFFSET2 = 0x43403d0e PTRACE_GETFPREGS = 0xe PTRACE_GETFPXREGS = 0x12 PTRACE_GET_THREAD_AREA = 0x19 diff --git a/unix/zerrors_linux_amd64.go b/unix/zerrors_linux_amd64.go index da428f4253..dfb364554d 100644 --- a/unix/zerrors_linux_amd64.go +++ b/unix/zerrors_linux_amd64.go @@ -237,6 +237,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x7434 PPPIOCXFERUNIT = 0x744e PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x80503d01 + PTP_CLOCK_GETCAPS2 = 0x80503d0a + PTP_ENABLE_PPS = 0x40043d04 + PTP_ENABLE_PPS2 = 0x40043d0d + PTP_EXTTS_REQUEST = 0x40103d02 + PTP_EXTTS_REQUEST2 = 0x40103d0b + PTP_MASK_CLEAR_ALL = 0x3d13 + PTP_MASK_EN_SINGLE = 0x40043d14 + PTP_PEROUT_REQUEST = 0x40383d03 + PTP_PEROUT_REQUEST2 = 0x40383d0c + PTP_PIN_SETFUNC = 0x40603d07 + PTP_PIN_SETFUNC2 = 0x40603d10 + PTP_SYS_OFFSET = 0x43403d05 + PTP_SYS_OFFSET2 = 0x43403d0e PTRACE_ARCH_PRCTL = 0x1e PTRACE_GETFPREGS = 0xe PTRACE_GETFPXREGS = 0x12 diff --git a/unix/zerrors_linux_arm.go b/unix/zerrors_linux_arm.go index bf45bfec78..d46dcf78ab 100644 --- a/unix/zerrors_linux_arm.go +++ b/unix/zerrors_linux_arm.go @@ -234,6 +234,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x7434 PPPIOCXFERUNIT = 0x744e PR_SET_PTRACER_ANY = 0xffffffff + PTP_CLOCK_GETCAPS = 0x80503d01 + PTP_CLOCK_GETCAPS2 = 0x80503d0a + PTP_ENABLE_PPS = 0x40043d04 + PTP_ENABLE_PPS2 = 0x40043d0d + PTP_EXTTS_REQUEST = 0x40103d02 + PTP_EXTTS_REQUEST2 = 0x40103d0b + PTP_MASK_CLEAR_ALL = 0x3d13 + PTP_MASK_EN_SINGLE = 0x40043d14 + PTP_PEROUT_REQUEST = 0x40383d03 + PTP_PEROUT_REQUEST2 = 0x40383d0c + PTP_PIN_SETFUNC = 0x40603d07 + PTP_PIN_SETFUNC2 = 0x40603d10 + PTP_SYS_OFFSET = 0x43403d05 + PTP_SYS_OFFSET2 = 0x43403d0e PTRACE_GETCRUNCHREGS = 0x19 PTRACE_GETFDPIC = 0x1f PTRACE_GETFDPIC_EXEC = 0x0 diff --git a/unix/zerrors_linux_arm64.go b/unix/zerrors_linux_arm64.go index 71c67162b7..3af3248a7f 100644 --- a/unix/zerrors_linux_arm64.go +++ b/unix/zerrors_linux_arm64.go @@ -240,6 +240,20 @@ const ( PROT_BTI = 0x10 PROT_MTE = 0x20 PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x80503d01 + PTP_CLOCK_GETCAPS2 = 0x80503d0a + PTP_ENABLE_PPS = 0x40043d04 + PTP_ENABLE_PPS2 = 0x40043d0d + PTP_EXTTS_REQUEST = 0x40103d02 + PTP_EXTTS_REQUEST2 = 0x40103d0b + PTP_MASK_CLEAR_ALL = 0x3d13 + PTP_MASK_EN_SINGLE = 0x40043d14 + PTP_PEROUT_REQUEST = 0x40383d03 + PTP_PEROUT_REQUEST2 = 0x40383d0c + PTP_PIN_SETFUNC = 0x40603d07 + PTP_PIN_SETFUNC2 = 0x40603d10 + PTP_SYS_OFFSET = 0x43403d05 + PTP_SYS_OFFSET2 = 0x43403d0e PTRACE_PEEKMTETAGS = 0x21 PTRACE_POKEMTETAGS = 0x22 PTRACE_SYSEMU = 0x1f diff --git a/unix/zerrors_linux_loong64.go b/unix/zerrors_linux_loong64.go index 9476628fa0..292bcf0283 100644 --- a/unix/zerrors_linux_loong64.go +++ b/unix/zerrors_linux_loong64.go @@ -238,6 +238,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x7434 PPPIOCXFERUNIT = 0x744e PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x80503d01 + PTP_CLOCK_GETCAPS2 = 0x80503d0a + PTP_ENABLE_PPS = 0x40043d04 + PTP_ENABLE_PPS2 = 0x40043d0d + PTP_EXTTS_REQUEST = 0x40103d02 + PTP_EXTTS_REQUEST2 = 0x40103d0b + PTP_MASK_CLEAR_ALL = 0x3d13 + PTP_MASK_EN_SINGLE = 0x40043d14 + PTP_PEROUT_REQUEST = 0x40383d03 + PTP_PEROUT_REQUEST2 = 0x40383d0c + PTP_PIN_SETFUNC = 0x40603d07 + PTP_PIN_SETFUNC2 = 0x40603d10 + PTP_SYS_OFFSET = 0x43403d05 + PTP_SYS_OFFSET2 = 0x43403d0e PTRACE_SYSEMU = 0x1f PTRACE_SYSEMU_SINGLESTEP = 0x20 RLIMIT_AS = 0x9 diff --git a/unix/zerrors_linux_mips.go b/unix/zerrors_linux_mips.go index b9e85f3cf0..782b7110fa 100644 --- a/unix/zerrors_linux_mips.go +++ b/unix/zerrors_linux_mips.go @@ -234,6 +234,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x20007434 PPPIOCXFERUNIT = 0x2000744e PR_SET_PTRACER_ANY = 0xffffffff + PTP_CLOCK_GETCAPS = 0x40503d01 + PTP_CLOCK_GETCAPS2 = 0x40503d0a + PTP_ENABLE_PPS = 0x80043d04 + PTP_ENABLE_PPS2 = 0x80043d0d + PTP_EXTTS_REQUEST = 0x80103d02 + PTP_EXTTS_REQUEST2 = 0x80103d0b + PTP_MASK_CLEAR_ALL = 0x20003d13 + PTP_MASK_EN_SINGLE = 0x80043d14 + PTP_PEROUT_REQUEST = 0x80383d03 + PTP_PEROUT_REQUEST2 = 0x80383d0c + PTP_PIN_SETFUNC = 0x80603d07 + PTP_PIN_SETFUNC2 = 0x80603d10 + PTP_SYS_OFFSET = 0x83403d05 + PTP_SYS_OFFSET2 = 0x83403d0e PTRACE_GETFPREGS = 0xe PTRACE_GET_THREAD_AREA = 0x19 PTRACE_GET_THREAD_AREA_3264 = 0xc4 diff --git a/unix/zerrors_linux_mips64.go b/unix/zerrors_linux_mips64.go index a48b68a764..84973fd927 100644 --- a/unix/zerrors_linux_mips64.go +++ b/unix/zerrors_linux_mips64.go @@ -234,6 +234,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x20007434 PPPIOCXFERUNIT = 0x2000744e PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x40503d01 + PTP_CLOCK_GETCAPS2 = 0x40503d0a + PTP_ENABLE_PPS = 0x80043d04 + PTP_ENABLE_PPS2 = 0x80043d0d + PTP_EXTTS_REQUEST = 0x80103d02 + PTP_EXTTS_REQUEST2 = 0x80103d0b + PTP_MASK_CLEAR_ALL = 0x20003d13 + PTP_MASK_EN_SINGLE = 0x80043d14 + PTP_PEROUT_REQUEST = 0x80383d03 + PTP_PEROUT_REQUEST2 = 0x80383d0c + PTP_PIN_SETFUNC = 0x80603d07 + PTP_PIN_SETFUNC2 = 0x80603d10 + PTP_SYS_OFFSET = 0x83403d05 + PTP_SYS_OFFSET2 = 0x83403d0e PTRACE_GETFPREGS = 0xe PTRACE_GET_THREAD_AREA = 0x19 PTRACE_GET_THREAD_AREA_3264 = 0xc4 diff --git a/unix/zerrors_linux_mips64le.go b/unix/zerrors_linux_mips64le.go index ea00e8522a..6d9cbc3b27 100644 --- a/unix/zerrors_linux_mips64le.go +++ b/unix/zerrors_linux_mips64le.go @@ -234,6 +234,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x20007434 PPPIOCXFERUNIT = 0x2000744e PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x40503d01 + PTP_CLOCK_GETCAPS2 = 0x40503d0a + PTP_ENABLE_PPS = 0x80043d04 + PTP_ENABLE_PPS2 = 0x80043d0d + PTP_EXTTS_REQUEST = 0x80103d02 + PTP_EXTTS_REQUEST2 = 0x80103d0b + PTP_MASK_CLEAR_ALL = 0x20003d13 + PTP_MASK_EN_SINGLE = 0x80043d14 + PTP_PEROUT_REQUEST = 0x80383d03 + PTP_PEROUT_REQUEST2 = 0x80383d0c + PTP_PIN_SETFUNC = 0x80603d07 + PTP_PIN_SETFUNC2 = 0x80603d10 + PTP_SYS_OFFSET = 0x83403d05 + PTP_SYS_OFFSET2 = 0x83403d0e PTRACE_GETFPREGS = 0xe PTRACE_GET_THREAD_AREA = 0x19 PTRACE_GET_THREAD_AREA_3264 = 0xc4 diff --git a/unix/zerrors_linux_mipsle.go b/unix/zerrors_linux_mipsle.go index 91c6468717..5f9fedbce0 100644 --- a/unix/zerrors_linux_mipsle.go +++ b/unix/zerrors_linux_mipsle.go @@ -234,6 +234,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x20007434 PPPIOCXFERUNIT = 0x2000744e PR_SET_PTRACER_ANY = 0xffffffff + PTP_CLOCK_GETCAPS = 0x40503d01 + PTP_CLOCK_GETCAPS2 = 0x40503d0a + PTP_ENABLE_PPS = 0x80043d04 + PTP_ENABLE_PPS2 = 0x80043d0d + PTP_EXTTS_REQUEST = 0x80103d02 + PTP_EXTTS_REQUEST2 = 0x80103d0b + PTP_MASK_CLEAR_ALL = 0x20003d13 + PTP_MASK_EN_SINGLE = 0x80043d14 + PTP_PEROUT_REQUEST = 0x80383d03 + PTP_PEROUT_REQUEST2 = 0x80383d0c + PTP_PIN_SETFUNC = 0x80603d07 + PTP_PIN_SETFUNC2 = 0x80603d10 + PTP_SYS_OFFSET = 0x83403d05 + PTP_SYS_OFFSET2 = 0x83403d0e PTRACE_GETFPREGS = 0xe PTRACE_GET_THREAD_AREA = 0x19 PTRACE_GET_THREAD_AREA_3264 = 0xc4 diff --git a/unix/zerrors_linux_ppc.go b/unix/zerrors_linux_ppc.go index 8cbf38d639..bb0026ee0c 100644 --- a/unix/zerrors_linux_ppc.go +++ b/unix/zerrors_linux_ppc.go @@ -237,6 +237,20 @@ const ( PPPIOCXFERUNIT = 0x2000744e PROT_SAO = 0x10 PR_SET_PTRACER_ANY = 0xffffffff + PTP_CLOCK_GETCAPS = 0x40503d01 + PTP_CLOCK_GETCAPS2 = 0x40503d0a + PTP_ENABLE_PPS = 0x80043d04 + PTP_ENABLE_PPS2 = 0x80043d0d + PTP_EXTTS_REQUEST = 0x80103d02 + PTP_EXTTS_REQUEST2 = 0x80103d0b + PTP_MASK_CLEAR_ALL = 0x20003d13 + PTP_MASK_EN_SINGLE = 0x80043d14 + PTP_PEROUT_REQUEST = 0x80383d03 + PTP_PEROUT_REQUEST2 = 0x80383d0c + PTP_PIN_SETFUNC = 0x80603d07 + PTP_PIN_SETFUNC2 = 0x80603d10 + PTP_SYS_OFFSET = 0x83403d05 + PTP_SYS_OFFSET2 = 0x83403d0e PTRACE_GETEVRREGS = 0x14 PTRACE_GETFPREGS = 0xe PTRACE_GETREGS64 = 0x16 diff --git a/unix/zerrors_linux_ppc64.go b/unix/zerrors_linux_ppc64.go index a2df734191..46120db5c9 100644 --- a/unix/zerrors_linux_ppc64.go +++ b/unix/zerrors_linux_ppc64.go @@ -237,6 +237,20 @@ const ( PPPIOCXFERUNIT = 0x2000744e PROT_SAO = 0x10 PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x40503d01 + PTP_CLOCK_GETCAPS2 = 0x40503d0a + PTP_ENABLE_PPS = 0x80043d04 + PTP_ENABLE_PPS2 = 0x80043d0d + PTP_EXTTS_REQUEST = 0x80103d02 + PTP_EXTTS_REQUEST2 = 0x80103d0b + PTP_MASK_CLEAR_ALL = 0x20003d13 + PTP_MASK_EN_SINGLE = 0x80043d14 + PTP_PEROUT_REQUEST = 0x80383d03 + PTP_PEROUT_REQUEST2 = 0x80383d0c + PTP_PIN_SETFUNC = 0x80603d07 + PTP_PIN_SETFUNC2 = 0x80603d10 + PTP_SYS_OFFSET = 0x83403d05 + PTP_SYS_OFFSET2 = 0x83403d0e PTRACE_GETEVRREGS = 0x14 PTRACE_GETFPREGS = 0xe PTRACE_GETREGS64 = 0x16 diff --git a/unix/zerrors_linux_ppc64le.go b/unix/zerrors_linux_ppc64le.go index 2479137923..5c951634fb 100644 --- a/unix/zerrors_linux_ppc64le.go +++ b/unix/zerrors_linux_ppc64le.go @@ -237,6 +237,20 @@ const ( PPPIOCXFERUNIT = 0x2000744e PROT_SAO = 0x10 PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x40503d01 + PTP_CLOCK_GETCAPS2 = 0x40503d0a + PTP_ENABLE_PPS = 0x80043d04 + PTP_ENABLE_PPS2 = 0x80043d0d + PTP_EXTTS_REQUEST = 0x80103d02 + PTP_EXTTS_REQUEST2 = 0x80103d0b + PTP_MASK_CLEAR_ALL = 0x20003d13 + PTP_MASK_EN_SINGLE = 0x80043d14 + PTP_PEROUT_REQUEST = 0x80383d03 + PTP_PEROUT_REQUEST2 = 0x80383d0c + PTP_PIN_SETFUNC = 0x80603d07 + PTP_PIN_SETFUNC2 = 0x80603d10 + PTP_SYS_OFFSET = 0x83403d05 + PTP_SYS_OFFSET2 = 0x83403d0e PTRACE_GETEVRREGS = 0x14 PTRACE_GETFPREGS = 0xe PTRACE_GETREGS64 = 0x16 diff --git a/unix/zerrors_linux_riscv64.go b/unix/zerrors_linux_riscv64.go index d265f146ee..11a84d5af2 100644 --- a/unix/zerrors_linux_riscv64.go +++ b/unix/zerrors_linux_riscv64.go @@ -234,6 +234,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x7434 PPPIOCXFERUNIT = 0x744e PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x80503d01 + PTP_CLOCK_GETCAPS2 = 0x80503d0a + PTP_ENABLE_PPS = 0x40043d04 + PTP_ENABLE_PPS2 = 0x40043d0d + PTP_EXTTS_REQUEST = 0x40103d02 + PTP_EXTTS_REQUEST2 = 0x40103d0b + PTP_MASK_CLEAR_ALL = 0x3d13 + PTP_MASK_EN_SINGLE = 0x40043d14 + PTP_PEROUT_REQUEST = 0x40383d03 + PTP_PEROUT_REQUEST2 = 0x40383d0c + PTP_PIN_SETFUNC = 0x40603d07 + PTP_PIN_SETFUNC2 = 0x40603d10 + PTP_SYS_OFFSET = 0x43403d05 + PTP_SYS_OFFSET2 = 0x43403d0e PTRACE_GETFDPIC = 0x21 PTRACE_GETFDPIC_EXEC = 0x0 PTRACE_GETFDPIC_INTERP = 0x1 diff --git a/unix/zerrors_linux_s390x.go b/unix/zerrors_linux_s390x.go index 3f2d644396..f78c4617ca 100644 --- a/unix/zerrors_linux_s390x.go +++ b/unix/zerrors_linux_s390x.go @@ -234,6 +234,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x7434 PPPIOCXFERUNIT = 0x744e PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x80503d01 + PTP_CLOCK_GETCAPS2 = 0x80503d0a + PTP_ENABLE_PPS = 0x40043d04 + PTP_ENABLE_PPS2 = 0x40043d0d + PTP_EXTTS_REQUEST = 0x40103d02 + PTP_EXTTS_REQUEST2 = 0x40103d0b + PTP_MASK_CLEAR_ALL = 0x3d13 + PTP_MASK_EN_SINGLE = 0x40043d14 + PTP_PEROUT_REQUEST = 0x40383d03 + PTP_PEROUT_REQUEST2 = 0x40383d0c + PTP_PIN_SETFUNC = 0x40603d07 + PTP_PIN_SETFUNC2 = 0x40603d10 + PTP_SYS_OFFSET = 0x43403d05 + PTP_SYS_OFFSET2 = 0x43403d0e PTRACE_DISABLE_TE = 0x5010 PTRACE_ENABLE_TE = 0x5009 PTRACE_GET_LAST_BREAK = 0x5006 diff --git a/unix/zerrors_linux_sparc64.go b/unix/zerrors_linux_sparc64.go index 5d8b727a1c..aeb777c344 100644 --- a/unix/zerrors_linux_sparc64.go +++ b/unix/zerrors_linux_sparc64.go @@ -239,6 +239,20 @@ const ( PPPIOCUNBRIDGECHAN = 0x20007434 PPPIOCXFERUNIT = 0x2000744e PR_SET_PTRACER_ANY = 0xffffffffffffffff + PTP_CLOCK_GETCAPS = 0x40503d01 + PTP_CLOCK_GETCAPS2 = 0x40503d0a + PTP_ENABLE_PPS = 0x80043d04 + PTP_ENABLE_PPS2 = 0x80043d0d + PTP_EXTTS_REQUEST = 0x80103d02 + PTP_EXTTS_REQUEST2 = 0x80103d0b + PTP_MASK_CLEAR_ALL = 0x20003d13 + PTP_MASK_EN_SINGLE = 0x80043d14 + PTP_PEROUT_REQUEST = 0x80383d03 + PTP_PEROUT_REQUEST2 = 0x80383d0c + PTP_PIN_SETFUNC = 0x80603d07 + PTP_PIN_SETFUNC2 = 0x80603d10 + PTP_SYS_OFFSET = 0x83403d05 + PTP_SYS_OFFSET2 = 0x83403d0e PTRACE_GETFPAREGS = 0x14 PTRACE_GETFPREGS = 0xe PTRACE_GETFPREGS64 = 0x19 diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index af30da5578..5cc1e8eb2f 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -592,6 +592,16 @@ func ClockGettime(clockid int32, time *Timespec) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func ClockSettime(clockid int32, time *Timespec) (err error) { + _, _, e1 := Syscall(SYS_CLOCK_SETTIME, uintptr(clockid), uintptr(unsafe.Pointer(time)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ClockNanosleep(clockid int32, flags int, request *Timespec, remain *Timespec) (err error) { _, _, e1 := Syscall6(SYS_CLOCK_NANOSLEEP, uintptr(clockid), uintptr(flags), uintptr(unsafe.Pointer(request)), uintptr(unsafe.Pointer(remain)), 0, 0) if e1 != 0 { diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 3a69e45496..8daaf3faf4 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -1752,12 +1752,6 @@ const ( IFLA_IPVLAN_UNSPEC = 0x0 IFLA_IPVLAN_MODE = 0x1 IFLA_IPVLAN_FLAGS = 0x2 - NETKIT_NEXT = -0x1 - NETKIT_PASS = 0x0 - NETKIT_DROP = 0x2 - NETKIT_REDIRECT = 0x7 - NETKIT_L2 = 0x0 - NETKIT_L3 = 0x1 IFLA_NETKIT_UNSPEC = 0x0 IFLA_NETKIT_PEER_INFO = 0x1 IFLA_NETKIT_PRIMARY = 0x2 @@ -1796,6 +1790,7 @@ const ( IFLA_VXLAN_DF = 0x1d IFLA_VXLAN_VNIFILTER = 0x1e IFLA_VXLAN_LOCALBYPASS = 0x1f + IFLA_VXLAN_LABEL_POLICY = 0x20 IFLA_GENEVE_UNSPEC = 0x0 IFLA_GENEVE_ID = 0x1 IFLA_GENEVE_REMOTE = 0x2 @@ -1825,6 +1820,8 @@ const ( IFLA_GTP_ROLE = 0x4 IFLA_GTP_CREATE_SOCKETS = 0x5 IFLA_GTP_RESTART_COUNT = 0x6 + IFLA_GTP_LOCAL = 0x7 + IFLA_GTP_LOCAL6 = 0x8 IFLA_BOND_UNSPEC = 0x0 IFLA_BOND_MODE = 0x1 IFLA_BOND_ACTIVE_SLAVE = 0x2 @@ -1857,6 +1854,7 @@ const ( IFLA_BOND_AD_LACP_ACTIVE = 0x1d IFLA_BOND_MISSED_MAX = 0x1e IFLA_BOND_NS_IP6_TARGET = 0x1f + IFLA_BOND_COUPLED_CONTROL = 0x20 IFLA_BOND_AD_INFO_UNSPEC = 0x0 IFLA_BOND_AD_INFO_AGGREGATOR = 0x1 IFLA_BOND_AD_INFO_NUM_PORTS = 0x2 @@ -1925,6 +1923,7 @@ const ( IFLA_HSR_SEQ_NR = 0x5 IFLA_HSR_VERSION = 0x6 IFLA_HSR_PROTOCOL = 0x7 + IFLA_HSR_INTERLINK = 0x8 IFLA_STATS_UNSPEC = 0x0 IFLA_STATS_LINK_64 = 0x1 IFLA_STATS_LINK_XSTATS = 0x2 @@ -1977,6 +1976,15 @@ const ( IFLA_DSA_MASTER = 0x1 ) +const ( + NETKIT_NEXT = -0x1 + NETKIT_PASS = 0x0 + NETKIT_DROP = 0x2 + NETKIT_REDIRECT = 0x7 + NETKIT_L2 = 0x0 + NETKIT_L3 = 0x1 +) + const ( NF_INET_PRE_ROUTING = 0x0 NF_INET_LOCAL_IN = 0x1 @@ -4110,6 +4118,106 @@ type EthtoolDrvinfo struct { Regdump_len uint32 } +type EthtoolTsInfo struct { + Cmd uint32 + So_timestamping uint32 + Phc_index int32 + Tx_types uint32 + Tx_reserved [3]uint32 + Rx_filters uint32 + Rx_reserved [3]uint32 +} + +type HwTstampConfig struct { + Flags int32 + Tx_type int32 + Rx_filter int32 +} + +const ( + HWTSTAMP_FILTER_NONE = 0x0 + HWTSTAMP_FILTER_ALL = 0x1 + HWTSTAMP_FILTER_SOME = 0x2 + HWTSTAMP_FILTER_PTP_V1_L4_EVENT = 0x3 + HWTSTAMP_FILTER_PTP_V2_L4_EVENT = 0x6 + HWTSTAMP_FILTER_PTP_V2_L2_EVENT = 0x9 + HWTSTAMP_FILTER_PTP_V2_EVENT = 0xc +) + +const ( + HWTSTAMP_TX_OFF = 0x0 + HWTSTAMP_TX_ON = 0x1 + HWTSTAMP_TX_ONESTEP_SYNC = 0x2 +) + +type ( + PtpClockCaps struct { + Max_adj int32 + N_alarm int32 + N_ext_ts int32 + N_per_out int32 + Pps int32 + N_pins int32 + Cross_timestamping int32 + Adjust_phase int32 + Max_phase_adj int32 + Rsv [11]int32 + } + PtpClockTime struct { + Sec int64 + Nsec uint32 + Reserved uint32 + } + PtpExttsEvent struct { + T PtpClockTime + Index uint32 + Flags uint32 + Rsv [2]uint32 + } + PtpExttsRequest struct { + Index uint32 + Flags uint32 + Rsv [2]uint32 + } + PtpPeroutRequest struct { + StartOrPhase PtpClockTime + Period PtpClockTime + Index uint32 + Flags uint32 + On PtpClockTime + } + PtpPinDesc struct { + Name [64]byte + Index uint32 + Func uint32 + Chan uint32 + Rsv [5]uint32 + } + PtpSysOffset struct { + Samples uint32 + Rsv [3]uint32 + Ts [51]PtpClockTime + } + PtpSysOffsetExtended struct { + Samples uint32 + Rsv [3]uint32 + Ts [25][3]PtpClockTime + } + PtpSysOffsetPrecise struct { + Device PtpClockTime + Realtime PtpClockTime + Monoraw PtpClockTime + Rsv [4]uint32 + } +) + +const ( + PTP_PF_NONE = 0x0 + PTP_PF_EXTTS = 0x1 + PTP_PF_PEROUT = 0x2 + PTP_PF_PHYSYNC = 0x3 +) + type ( HIDRawReportDescriptor struct { Size uint32 diff --git a/unix/ztypes_zos_s390x.go b/unix/ztypes_zos_s390x.go index d9a13af468..2e5d5a4435 100644 --- a/unix/ztypes_zos_s390x.go +++ b/unix/ztypes_zos_s390x.go @@ -377,6 +377,12 @@ type Flock_t struct { Pid int32 } +type F_cnvrt struct { + Cvtcmd int32 + Pccsid int16 + Fccsid int16 +} + type Termios struct { Cflag uint32 Iflag uint32 diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index 5cee9a3143..4510bfc3f5 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -725,20 +725,12 @@ func DurationSinceBoot() time.Duration { } func Ftruncate(fd Handle, length int64) (err error) { - curoffset, e := Seek(fd, 0, 1) - if e != nil { - return e - } - defer Seek(fd, curoffset, 0) - _, e = Seek(fd, length, 0) - if e != nil { - return e + type _FILE_END_OF_FILE_INFO struct { + EndOfFile int64 } - e = SetEndOfFile(fd) - if e != nil { - return e - } - return nil + var info _FILE_END_OF_FILE_INFO + info.EndOfFile = length + return SetFileInformationByHandle(fd, FileEndOfFileInfo, (*byte)(unsafe.Pointer(&info)), uint32(unsafe.Sizeof(info))) } func Gettimeofday(tv *Timeval) (err error) { @@ -894,6 +886,11 @@ const socket_error = uintptr(^uint32(0)) //sys GetACP() (acp uint32) = kernel32.GetACP //sys MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar //sys getBestInterfaceEx(sockaddr unsafe.Pointer, pdwBestIfIndex *uint32) (errcode error) = iphlpapi.GetBestInterfaceEx +//sys GetIfEntry2Ex(level uint32, row *MibIfRow2) (errcode error) = iphlpapi.GetIfEntry2Ex +//sys GetUnicastIpAddressEntry(row *MibUnicastIpAddressRow) (errcode error) = iphlpapi.GetUnicastIpAddressEntry +//sys NotifyIpInterfaceChange(family uint16, callback uintptr, callerContext unsafe.Pointer, initialNotification bool, notificationHandle *Handle) (errcode error) = iphlpapi.NotifyIpInterfaceChange +//sys NotifyUnicastIpAddressChange(family uint16, callback uintptr, callerContext unsafe.Pointer, initialNotification bool, notificationHandle *Handle) (errcode error) = iphlpapi.NotifyUnicastIpAddressChange +//sys CancelMibChangeNotify2(notificationHandle Handle) (errcode error) = iphlpapi.CancelMibChangeNotify2 // For testing: clients can set this flag to force // creation of IPv6 sockets to return EAFNOSUPPORT. @@ -1685,13 +1682,16 @@ func (s NTStatus) Error() string { // do not use NTUnicodeString, and instead UTF16PtrFromString should be used for // the more common *uint16 string type. func NewNTUnicodeString(s string) (*NTUnicodeString, error) { - var u NTUnicodeString - s16, err := UTF16PtrFromString(s) + s16, err := UTF16FromString(s) if err != nil { return nil, err } - RtlInitUnicodeString(&u, s16) - return &u, nil + n := uint16(len(s16) * 2) + return &NTUnicodeString{ + Length: n - 2, // subtract 2 bytes for the NULL terminator + MaximumLength: n, + Buffer: &s16[0], + }, nil } // Slice returns a uint16 slice that aliases the data in the NTUnicodeString. diff --git a/windows/types_windows.go b/windows/types_windows.go index 7b97a154c9..51311e205f 100644 --- a/windows/types_windows.go +++ b/windows/types_windows.go @@ -2203,6 +2203,132 @@ const ( IfOperStatusLowerLayerDown = 7 ) +const ( + IF_MAX_PHYS_ADDRESS_LENGTH = 32 + IF_MAX_STRING_SIZE = 256 +) + +// MIB_IF_ENTRY_LEVEL enumeration from netioapi.h or +// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/nf-netioapi-getifentry2ex. +const ( + MibIfEntryNormal = 0 + MibIfEntryNormalWithoutStatistics = 2 +) + +// MIB_NOTIFICATION_TYPE enumeration from netioapi.h or +// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ne-netioapi-mib_notification_type. +const ( + MibParameterNotification = 0 + MibAddInstance = 1 + MibDeleteInstance = 2 + MibInitialNotification = 3 +) + +// MibIfRow2 stores information about a particular interface. See +// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_if_row2. +type MibIfRow2 struct { + InterfaceLuid uint64 + InterfaceIndex uint32 + InterfaceGuid GUID + Alias [IF_MAX_STRING_SIZE + 1]uint16 + Description [IF_MAX_STRING_SIZE + 1]uint16 + PhysicalAddressLength uint32 + PhysicalAddress [IF_MAX_PHYS_ADDRESS_LENGTH]uint8 + PermanentPhysicalAddress [IF_MAX_PHYS_ADDRESS_LENGTH]uint8 + Mtu uint32 + Type uint32 + TunnelType uint32 + MediaType uint32 + PhysicalMediumType uint32 + AccessType uint32 + DirectionType uint32 + InterfaceAndOperStatusFlags uint8 + OperStatus uint32 + AdminStatus uint32 + MediaConnectState uint32 + NetworkGuid GUID + ConnectionType uint32 + TransmitLinkSpeed uint64 + ReceiveLinkSpeed uint64 + InOctets uint64 + InUcastPkts uint64 + InNUcastPkts uint64 + InDiscards uint64 + InErrors uint64 + InUnknownProtos uint64 + InUcastOctets uint64 + InMulticastOctets uint64 + InBroadcastOctets uint64 + OutOctets uint64 + OutUcastPkts uint64 + OutNUcastPkts uint64 + OutDiscards uint64 + OutErrors uint64 + OutUcastOctets uint64 + OutMulticastOctets uint64 + OutBroadcastOctets uint64 + OutQLen uint64 +} + +// MIB_UNICASTIPADDRESS_ROW stores information about a unicast IP address. See +// https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_unicastipaddress_row. +type MibUnicastIpAddressRow struct { + Address RawSockaddrInet6 // SOCKADDR_INET union + InterfaceLuid uint64 + InterfaceIndex uint32 + PrefixOrigin uint32 + SuffixOrigin uint32 + ValidLifetime uint32 + PreferredLifetime uint32 + OnLinkPrefixLength uint8 + SkipAsSource uint8 + DadState uint32 + ScopeId uint32 + CreationTimeStamp Filetime +} + +const ScopeLevelCount = 16 + +// MIB_IPINTERFACE_ROW stores interface management information for a particular IP address family on a network interface. +// See https://learn.microsoft.com/en-us/windows/win32/api/netioapi/ns-netioapi-mib_ipinterface_row. +type MibIpInterfaceRow struct { + Family uint16 + InterfaceLuid uint64 + InterfaceIndex uint32 + MaxReassemblySize uint32 + InterfaceIdentifier uint64 + MinRouterAdvertisementInterval uint32 + MaxRouterAdvertisementInterval uint32 + AdvertisingEnabled uint8 + ForwardingEnabled uint8 + WeakHostSend uint8 + WeakHostReceive uint8 + UseAutomaticMetric uint8 + UseNeighborUnreachabilityDetection uint8 + ManagedAddressConfigurationSupported uint8 + OtherStatefulConfigurationSupported uint8 + AdvertiseDefaultRoute uint8 + RouterDiscoveryBehavior uint32 + DadTransmits uint32 + BaseReachableTime uint32 + RetransmitTime uint32 + PathMtuDiscoveryTimeout uint32 + LinkLocalAddressBehavior uint32 + LinkLocalAddressTimeout uint32 + ZoneIndices [ScopeLevelCount]uint32 + SitePrefixLength uint32 + Metric uint32 + NlMtu uint32 + Connected uint8 + SupportsWakeUpPatterns uint8 + SupportsNeighborDiscovery uint8 + SupportsRouterDiscovery uint8 + ReachableTime uint32 + TransmitOffload uint32 + ReceiveOffload uint32 + DisableDefaultRoutes uint8 +} + // Console related constants used for the mode parameter to SetConsoleMode. See // https://docs.microsoft.com/en-us/windows/console/setconsolemode for details. diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 4c2e1bdc01..6f5252880c 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -181,10 +181,15 @@ var ( procDnsRecordListFree = moddnsapi.NewProc("DnsRecordListFree") procDwmGetWindowAttribute = moddwmapi.NewProc("DwmGetWindowAttribute") procDwmSetWindowAttribute = moddwmapi.NewProc("DwmSetWindowAttribute") + procCancelMibChangeNotify2 = modiphlpapi.NewProc("CancelMibChangeNotify2") procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses") procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo") procGetBestInterfaceEx = modiphlpapi.NewProc("GetBestInterfaceEx") procGetIfEntry = modiphlpapi.NewProc("GetIfEntry") + procGetIfEntry2Ex = modiphlpapi.NewProc("GetIfEntry2Ex") + procGetUnicastIpAddressEntry = modiphlpapi.NewProc("GetUnicastIpAddressEntry") + procNotifyIpInterfaceChange = modiphlpapi.NewProc("NotifyIpInterfaceChange") + procNotifyUnicastIpAddressChange = modiphlpapi.NewProc("NotifyUnicastIpAddressChange") procAddDllDirectory = modkernel32.NewProc("AddDllDirectory") procAssignProcessToJobObject = modkernel32.NewProc("AssignProcessToJobObject") procCancelIo = modkernel32.NewProc("CancelIo") @@ -1606,6 +1611,14 @@ func DwmSetWindowAttribute(hwnd HWND, attribute uint32, value unsafe.Pointer, si return } +func CancelMibChangeNotify2(notificationHandle Handle) (errcode error) { + r0, _, _ := syscall.SyscallN(procCancelMibChangeNotify2.Addr(), uintptr(notificationHandle)) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) { r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0) if r0 != 0 { @@ -1638,6 +1651,46 @@ func GetIfEntry(pIfRow *MibIfRow) (errcode error) { return } +func GetIfEntry2Ex(level uint32, row *MibIfRow2) (errcode error) { + r0, _, _ := syscall.SyscallN(procGetIfEntry2Ex.Addr(), uintptr(level), uintptr(unsafe.Pointer(row))) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + +func GetUnicastIpAddressEntry(row *MibUnicastIpAddressRow) (errcode error) { + r0, _, _ := syscall.SyscallN(procGetUnicastIpAddressEntry.Addr(), uintptr(unsafe.Pointer(row))) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + +func NotifyIpInterfaceChange(family uint16, callback uintptr, callerContext unsafe.Pointer, initialNotification bool, notificationHandle *Handle) (errcode error) { + var _p0 uint32 + if initialNotification { + _p0 = 1 + } + r0, _, _ := syscall.SyscallN(procNotifyIpInterfaceChange.Addr(), uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle))) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + +func NotifyUnicastIpAddressChange(family uint16, callback uintptr, callerContext unsafe.Pointer, initialNotification bool, notificationHandle *Handle) (errcode error) { + var _p0 uint32 + if initialNotification { + _p0 = 1 + } + r0, _, _ := syscall.SyscallN(procNotifyUnicastIpAddressChange.Addr(), uintptr(family), uintptr(callback), uintptr(callerContext), uintptr(_p0), uintptr(unsafe.Pointer(notificationHandle))) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + func AddDllDirectory(path *uint16) (cookie uintptr, err error) { r0, _, e1 := syscall.Syscall(procAddDllDirectory.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) cookie = uintptr(r0)