From 29298aaa6a49af9eb63e0c3e6932893034b93051 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Thu, 1 Aug 2024 18:02:11 +1000 Subject: [PATCH 01/23] windows: delete TestGetKeyboardLayout According to https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getforegroundwindow GetForegroundWindow can return nil in some circumstances. So GetForegroundWindow cannot be used in the TestGetKeyboardLayout. Just delete the test for now. Fixes golang/go#68671 Change-Id: I7e05ac2f19b1a6310a3f7f690c6d02b0d1f5571e Reviewed-on: https://go-review.googlesource.com/c/sys/+/602335 Reviewed-by: Cherry Mui Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI Reviewed-by: Ayman Bagabas --- windows/syscall_windows_test.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index ca8a70d2a4..b7703dfe15 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -1438,17 +1438,6 @@ uintptr_t beep(void) { } } -func TestGetKeyboardLayout(t *testing.T) { - fg := windows.GetForegroundWindow() - tid, err := windows.GetWindowThreadProcessId(fg, nil) - if err != nil { - t.Fatalf("GetWindowThreadProcessId failed: %v", err) - } - - // We don't care about the result, just that it doesn't crash. - _ = windows.GetKeyboardLayout(tid) -} - func TestToUnicodeEx(t *testing.T) { var utf16Buf [16]uint16 From 4c7077ec60eeb233fdff4640ef2286500c7689a7 Mon Sep 17 00:00:00 2001 From: database64128 Date: Mon, 29 Jul 2024 06:53:55 +0000 Subject: [PATCH 02/23] windows: add enums for IpAdapterUnicastAddress These are for the enum fields in IpAdapterUnicastAddress. Change-Id: Ibcb6ce674ab41a94dbe46d394f035208a94b6dae GitHub-Last-Rev: 1837ff9c32357fe7eb64257001b9bf42485b1c8c GitHub-Pull-Request: golang/sys#204 Reviewed-on: https://go-review.googlesource.com/c/sys/+/598895 LUCI-TryBot-Result: Go LUCI Reviewed-by: Alex Brainman Reviewed-by: Michael Knyszek Reviewed-by: David Chase --- windows/types_windows.go | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/windows/types_windows.go b/windows/types_windows.go index 4d0c15745f..3f03b3d57c 100644 --- a/windows/types_windows.go +++ b/windows/types_windows.go @@ -2031,6 +2031,50 @@ const ( IF_TYPE_IEEE1394 = 144 ) +// Enum NL_PREFIX_ORIGIN for [IpAdapterUnicastAddress], see +// https://learn.microsoft.com/en-us/windows/win32/api/nldef/ne-nldef-nl_prefix_origin +const ( + IpPrefixOriginOther = 0 + IpPrefixOriginManual = 1 + IpPrefixOriginWellKnown = 2 + IpPrefixOriginDhcp = 3 + IpPrefixOriginRouterAdvertisement = 4 + IpPrefixOriginUnchanged = 1 << 4 +) + +// Enum NL_SUFFIX_ORIGIN for [IpAdapterUnicastAddress], see +// https://learn.microsoft.com/en-us/windows/win32/api/nldef/ne-nldef-nl_suffix_origin +const ( + NlsoOther = 0 + NlsoManual = 1 + NlsoWellKnown = 2 + NlsoDhcp = 3 + NlsoLinkLayerAddress = 4 + NlsoRandom = 5 + IpSuffixOriginOther = 0 + IpSuffixOriginManual = 1 + IpSuffixOriginWellKnown = 2 + IpSuffixOriginDhcp = 3 + IpSuffixOriginLinkLayerAddress = 4 + IpSuffixOriginRandom = 5 + IpSuffixOriginUnchanged = 1 << 4 +) + +// Enum NL_DAD_STATE for [IpAdapterUnicastAddress], see +// https://learn.microsoft.com/en-us/windows/win32/api/nldef/ne-nldef-nl_dad_state +const ( + NldsInvalid = 0 + NldsTentative = 1 + NldsDuplicate = 2 + NldsDeprecated = 3 + NldsPreferred = 4 + IpDadStateInvalid = 0 + IpDadStateTentative = 1 + IpDadStateDuplicate = 2 + IpDadStateDeprecated = 3 + IpDadStatePreferred = 4 +) + type SocketAddress struct { Sockaddr *syscall.RawSockaddrAny SockaddrLength int32 From 914deed708990c429d263121ee1ef42388e94ba4 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Wed, 7 Aug 2024 20:55:24 +0000 Subject: [PATCH 03/23] unix: add missing ETHTOOL_FLAG_ constants Some constants were removed in CL 600516 that included changes for the Linux kernel 6.10. This kernel version moved C defines to an enum ethtool_header_flags that was not picked up by the mkall.sh script. For enums, there is a perl script that needs to be run manually, and the output must be added by hand to the list of constants in unix/linux/types.go. See https://elixir.bootlin.com/linux/v6.10.3/source/include/uapi/linux/ethtool_netlink.h#L120 Fixes golang/go#68761 Change-Id: Idb189886d257d0fe66a4e832757a469e17f86c34 GitHub-Last-Rev: 08b8ef571ddeed14640c0b84a846e9fe280aaddb GitHub-Pull-Request: golang/sys#212 Reviewed-on: https://go-review.googlesource.com/c/sys/+/604098 Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI --- unix/linux/types.go | 7 +++++-- unix/ztypes_linux.go | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/unix/linux/types.go b/unix/linux/types.go index a6f44f4bb1..27b56486c4 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -3551,8 +3551,8 @@ const ( // ethtool and its netlink interface, generated using: // -// perl -nlE '/^\s*(ETHTOOL_\w+)/ && say "$1 = C.$1"' ethtool.h -// perl -nlE '/^\s*(ETHTOOL_\w+)/ && say "$1 = C.$1"' ethtool_netlink.h +// perl -nlE '/^\s*(ETHTOOL_\w+)/ && say "$1 = C.$1"' /usr/include/linux/ethtool.h +// perl -nlE '/^\s*(ETHTOOL_\w+)/ && say "$1 = C.$1"' /usr/include/linux/ethtool_netlink.h // // Note that a couple of constants produced by this command will be duplicated // by mkerrors.sh, so some manual pruning was necessary. @@ -3787,6 +3787,9 @@ const ( ETHTOOL_MSG_PSE_GET_REPLY = C.ETHTOOL_MSG_PSE_GET_REPLY ETHTOOL_MSG_RSS_GET_REPLY = C.ETHTOOL_MSG_RSS_GET_REPLY ETHTOOL_MSG_KERNEL_MAX = C.ETHTOOL_MSG_KERNEL_MAX + ETHTOOL_FLAG_COMPACT_BITSETS = C.ETHTOOL_FLAG_COMPACT_BITSETS + ETHTOOL_FLAG_OMIT_REPLY = C.ETHTOOL_FLAG_OMIT_REPLY + ETHTOOL_FLAG_STATS = C.ETHTOOL_FLAG_STATS ETHTOOL_A_HEADER_UNSPEC = C.ETHTOOL_A_HEADER_UNSPEC ETHTOOL_A_HEADER_DEV_INDEX = C.ETHTOOL_A_HEADER_DEV_INDEX ETHTOOL_A_HEADER_DEV_NAME = C.ETHTOOL_A_HEADER_DEV_NAME diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index b102b95a0a..7f1961b907 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -3807,6 +3807,9 @@ const ( ETHTOOL_MSG_PSE_GET_REPLY = 0x25 ETHTOOL_MSG_RSS_GET_REPLY = 0x26 ETHTOOL_MSG_KERNEL_MAX = 0x2b + ETHTOOL_FLAG_COMPACT_BITSETS = 0x1 + ETHTOOL_FLAG_OMIT_REPLY = 0x2 + ETHTOOL_FLAG_STATS = 0x4 ETHTOOL_A_HEADER_UNSPEC = 0x0 ETHTOOL_A_HEADER_DEV_INDEX = 0x1 ETHTOOL_A_HEADER_DEV_NAME = 0x2 From da77c6b1d14d14ebebd1688dca8b1c0172a8ca2d Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Sat, 10 Aug 2024 11:19:58 +0000 Subject: [PATCH 04/23] unix: sync minimum Linux Kernel version with requirements page Change-Id: I306728f5bf19955177365fd9afcc4c8678b6f81f GitHub-Last-Rev: cf6f9c7b19c5af00bf94812eb002b9c6798daa30 GitHub-Pull-Request: golang/sys#213 Reviewed-on: https://go-review.googlesource.com/c/sys/+/604136 Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Carlos Amedee Auto-Submit: Ian Lance Taylor --- unix/linux/mkall.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unix/linux/mkall.go b/unix/linux/mkall.go index ae159148b2..d78109261c 100644 --- a/unix/linux/mkall.go +++ b/unix/linux/mkall.go @@ -40,7 +40,7 @@ const TempDir = "/tmp" const GOOS = "linux" // Only for Linux targets const BuildArch = "amd64" // Must be built on this architecture -const MinKernel = "2.6.23" // https://golang.org/doc/install#requirements +const MinKernel = "2.6.32" // https://go.dev/wiki/MinimumRequirements#linuxlinux type target struct { GoArch string // Architecture name according to Go From c64c51db65cebfa1dc4825a1c7a077a5859796a3 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Fri, 9 Aug 2024 20:46:59 +0800 Subject: [PATCH 05/23] unix: update riscv64 hwprobe to Linux kernel 6.10 Change-Id: Ic74816df459b17302a3ba746060b49e987e5da5c Reviewed-on: https://go-review.googlesource.com/c/sys/+/604435 Reviewed-by: Mark Ryan Reviewed-by: Carlos Amedee Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- unix/linux/types.go | 66 ++++++++++++++++++++++++++++++++++++ unix/ztypes_linux_riscv64.go | 33 ++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/unix/linux/types.go b/unix/linux/types.go index 27b56486c4..75acaec896 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -451,6 +451,37 @@ struct my_can_bittiming_const { #define RISCV_HWPROBE_EXT_ZBA (1 << 3) #define RISCV_HWPROBE_EXT_ZBB (1 << 4) #define RISCV_HWPROBE_EXT_ZBS (1 << 5) +#define RISCV_HWPROBE_EXT_ZICBOZ (1 << 6) +#define RISCV_HWPROBE_EXT_ZBC (1 << 7) +#define RISCV_HWPROBE_EXT_ZBKB (1 << 8) +#define RISCV_HWPROBE_EXT_ZBKC (1 << 9) +#define RISCV_HWPROBE_EXT_ZBKX (1 << 10) +#define RISCV_HWPROBE_EXT_ZKND (1 << 11) +#define RISCV_HWPROBE_EXT_ZKNE (1 << 12) +#define RISCV_HWPROBE_EXT_ZKNH (1 << 13) +#define RISCV_HWPROBE_EXT_ZKSED (1 << 14) +#define RISCV_HWPROBE_EXT_ZKSH (1 << 15) +#define RISCV_HWPROBE_EXT_ZKT (1 << 16) +#define RISCV_HWPROBE_EXT_ZVBB (1 << 17) +#define RISCV_HWPROBE_EXT_ZVBC (1 << 18) +#define RISCV_HWPROBE_EXT_ZVKB (1 << 19) +#define RISCV_HWPROBE_EXT_ZVKG (1 << 20) +#define RISCV_HWPROBE_EXT_ZVKNED (1 << 21) +#define RISCV_HWPROBE_EXT_ZVKNHA (1 << 22) +#define RISCV_HWPROBE_EXT_ZVKNHB (1 << 23) +#define RISCV_HWPROBE_EXT_ZVKSED (1 << 24) +#define RISCV_HWPROBE_EXT_ZVKSH (1 << 25) +#define RISCV_HWPROBE_EXT_ZVKT (1 << 26) +#define RISCV_HWPROBE_EXT_ZFH (1 << 27) +#define RISCV_HWPROBE_EXT_ZFHMIN (1 << 28) +#define RISCV_HWPROBE_EXT_ZIHINTNTL (1 << 29) +#define RISCV_HWPROBE_EXT_ZVFH (1 << 30) +#define RISCV_HWPROBE_EXT_ZVFHMIN (1ULL << 31) +#define RISCV_HWPROBE_EXT_ZFA (1ULL << 32) +#define RISCV_HWPROBE_EXT_ZTSO (1ULL << 33) +#define RISCV_HWPROBE_EXT_ZACAS (1ULL << 34) +#define RISCV_HWPROBE_EXT_ZICOND (1ULL << 35) +#define RISCV_HWPROBE_EXT_ZIHINTPAUSE (1ULL << 36) #define RISCV_HWPROBE_KEY_CPUPERF_0 5 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) @@ -458,6 +489,8 @@ struct my_can_bittiming_const { #define RISCV_HWPROBE_MISALIGNED_FAST (3 << 0) #define RISCV_HWPROBE_MISALIGNED_UNSUPPORTED (4 << 0) #define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0) +#define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6 +#define RISCV_HWPROBE_WHICH_CPUS (1 << 0) struct riscv_hwprobe {}; #endif @@ -5906,6 +5939,37 @@ const ( RISCV_HWPROBE_EXT_ZBA = C.RISCV_HWPROBE_EXT_ZBA RISCV_HWPROBE_EXT_ZBB = C.RISCV_HWPROBE_EXT_ZBB RISCV_HWPROBE_EXT_ZBS = C.RISCV_HWPROBE_EXT_ZBS + RISCV_HWPROBE_EXT_ZICBOZ = C.RISCV_HWPROBE_EXT_ZICBOZ + RISCV_HWPROBE_EXT_ZBC = C.RISCV_HWPROBE_EXT_ZBC + RISCV_HWPROBE_EXT_ZBKB = C.RISCV_HWPROBE_EXT_ZBKB + RISCV_HWPROBE_EXT_ZBKC = C.RISCV_HWPROBE_EXT_ZBKC + RISCV_HWPROBE_EXT_ZBKX = C.RISCV_HWPROBE_EXT_ZBKX + RISCV_HWPROBE_EXT_ZKND = C.RISCV_HWPROBE_EXT_ZKND + RISCV_HWPROBE_EXT_ZKNE = C.RISCV_HWPROBE_EXT_ZKNE + RISCV_HWPROBE_EXT_ZKNH = C.RISCV_HWPROBE_EXT_ZKNH + RISCV_HWPROBE_EXT_ZKSED = C.RISCV_HWPROBE_EXT_ZKSED + RISCV_HWPROBE_EXT_ZKSH = C.RISCV_HWPROBE_EXT_ZKSH + RISCV_HWPROBE_EXT_ZKT = C.RISCV_HWPROBE_EXT_ZKT + RISCV_HWPROBE_EXT_ZVBB = C.RISCV_HWPROBE_EXT_ZVBB + RISCV_HWPROBE_EXT_ZVBC = C.RISCV_HWPROBE_EXT_ZVBC + RISCV_HWPROBE_EXT_ZVKB = C.RISCV_HWPROBE_EXT_ZVKB + RISCV_HWPROBE_EXT_ZVKG = C.RISCV_HWPROBE_EXT_ZVKG + RISCV_HWPROBE_EXT_ZVKNED = C.RISCV_HWPROBE_EXT_ZVKNED + RISCV_HWPROBE_EXT_ZVKNHA = C.RISCV_HWPROBE_EXT_ZVKNHA + RISCV_HWPROBE_EXT_ZVKNHB = C.RISCV_HWPROBE_EXT_ZVKNHB + RISCV_HWPROBE_EXT_ZVKSED = C.RISCV_HWPROBE_EXT_ZVKSED + RISCV_HWPROBE_EXT_ZVKSH = C.RISCV_HWPROBE_EXT_ZVKSH + RISCV_HWPROBE_EXT_ZVKT = C.RISCV_HWPROBE_EXT_ZVKT + RISCV_HWPROBE_EXT_ZFH = C.RISCV_HWPROBE_EXT_ZFH + RISCV_HWPROBE_EXT_ZFHMIN = C.RISCV_HWPROBE_EXT_ZFHMIN + RISCV_HWPROBE_EXT_ZIHINTNTL = C.RISCV_HWPROBE_EXT_ZIHINTNTL + RISCV_HWPROBE_EXT_ZVFH = C.RISCV_HWPROBE_EXT_ZVFH + RISCV_HWPROBE_EXT_ZVFHMIN = C.RISCV_HWPROBE_EXT_ZVFHMIN + RISCV_HWPROBE_EXT_ZFA = C.RISCV_HWPROBE_EXT_ZFA + RISCV_HWPROBE_EXT_ZTSO = C.RISCV_HWPROBE_EXT_ZTSO + RISCV_HWPROBE_EXT_ZACAS = C.RISCV_HWPROBE_EXT_ZACAS + RISCV_HWPROBE_EXT_ZICOND = C.RISCV_HWPROBE_EXT_ZICOND + RISCV_HWPROBE_EXT_ZIHINTPAUSE = C.RISCV_HWPROBE_EXT_ZIHINTPAUSE RISCV_HWPROBE_KEY_CPUPERF_0 = C.RISCV_HWPROBE_KEY_CPUPERF_0 RISCV_HWPROBE_MISALIGNED_UNKNOWN = C.RISCV_HWPROBE_MISALIGNED_UNKNOWN RISCV_HWPROBE_MISALIGNED_EMULATED = C.RISCV_HWPROBE_MISALIGNED_EMULATED @@ -5913,6 +5977,8 @@ const ( RISCV_HWPROBE_MISALIGNED_FAST = C.RISCV_HWPROBE_MISALIGNED_FAST RISCV_HWPROBE_MISALIGNED_UNSUPPORTED = C.RISCV_HWPROBE_MISALIGNED_UNSUPPORTED RISCV_HWPROBE_MISALIGNED_MASK = C.RISCV_HWPROBE_MISALIGNED_MASK + RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE = C.RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE + RISCV_HWPROBE_WHICH_CPUS = C.RISCV_HWPROBE_WHICH_CPUS ) type SchedAttr C.struct_sched_attr diff --git a/unix/ztypes_linux_riscv64.go b/unix/ztypes_linux_riscv64.go index 15adc04142..ad05b51a60 100644 --- a/unix/ztypes_linux_riscv64.go +++ b/unix/ztypes_linux_riscv64.go @@ -727,6 +727,37 @@ const ( RISCV_HWPROBE_EXT_ZBA = 0x8 RISCV_HWPROBE_EXT_ZBB = 0x10 RISCV_HWPROBE_EXT_ZBS = 0x20 + RISCV_HWPROBE_EXT_ZICBOZ = 0x40 + RISCV_HWPROBE_EXT_ZBC = 0x80 + RISCV_HWPROBE_EXT_ZBKB = 0x100 + RISCV_HWPROBE_EXT_ZBKC = 0x200 + RISCV_HWPROBE_EXT_ZBKX = 0x400 + RISCV_HWPROBE_EXT_ZKND = 0x800 + RISCV_HWPROBE_EXT_ZKNE = 0x1000 + RISCV_HWPROBE_EXT_ZKNH = 0x2000 + RISCV_HWPROBE_EXT_ZKSED = 0x4000 + RISCV_HWPROBE_EXT_ZKSH = 0x8000 + RISCV_HWPROBE_EXT_ZKT = 0x10000 + RISCV_HWPROBE_EXT_ZVBB = 0x20000 + RISCV_HWPROBE_EXT_ZVBC = 0x40000 + RISCV_HWPROBE_EXT_ZVKB = 0x80000 + RISCV_HWPROBE_EXT_ZVKG = 0x100000 + RISCV_HWPROBE_EXT_ZVKNED = 0x200000 + RISCV_HWPROBE_EXT_ZVKNHA = 0x400000 + RISCV_HWPROBE_EXT_ZVKNHB = 0x800000 + RISCV_HWPROBE_EXT_ZVKSED = 0x1000000 + RISCV_HWPROBE_EXT_ZVKSH = 0x2000000 + RISCV_HWPROBE_EXT_ZVKT = 0x4000000 + RISCV_HWPROBE_EXT_ZFH = 0x8000000 + RISCV_HWPROBE_EXT_ZFHMIN = 0x10000000 + RISCV_HWPROBE_EXT_ZIHINTNTL = 0x20000000 + RISCV_HWPROBE_EXT_ZVFH = 0x40000000 + RISCV_HWPROBE_EXT_ZVFHMIN = 0x80000000 + RISCV_HWPROBE_EXT_ZFA = 0x100000000 + RISCV_HWPROBE_EXT_ZTSO = 0x200000000 + RISCV_HWPROBE_EXT_ZACAS = 0x400000000 + RISCV_HWPROBE_EXT_ZICOND = 0x800000000 + RISCV_HWPROBE_EXT_ZIHINTPAUSE = 0x1000000000 RISCV_HWPROBE_KEY_CPUPERF_0 = 0x5 RISCV_HWPROBE_MISALIGNED_UNKNOWN = 0x0 RISCV_HWPROBE_MISALIGNED_EMULATED = 0x1 @@ -734,4 +765,6 @@ const ( RISCV_HWPROBE_MISALIGNED_FAST = 0x3 RISCV_HWPROBE_MISALIGNED_UNSUPPORTED = 0x4 RISCV_HWPROBE_MISALIGNED_MASK = 0x7 + RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE = 0x6 + RISCV_HWPROBE_WHICH_CPUS = 0x1 ) From a0c72efe2d1704645e6627b27e9b7e13c50e68f4 Mon Sep 17 00:00:00 2001 From: Joon Lee Date: Mon, 19 Aug 2024 20:37:18 +0000 Subject: [PATCH 06/23] unix: add f_flag member flags on z/OS This change adds the constants `ST_RDONLY` and `ST_NOSUID` to a z/OS-specific file. Change-Id: Ifb78124d93b60a10f10b8169d1bb73dce074e760 GitHub-Last-Rev: 952cf1bc7f3944210ed92fc356f2158261953ddf GitHub-Pull-Request: golang/sys#214 Reviewed-on: https://go-review.googlesource.com/c/sys/+/606877 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- unix/zerrors_zos_s390x.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unix/zerrors_zos_s390x.go b/unix/zerrors_zos_s390x.go index da08b2ab3d..1ec2b1407b 100644 --- a/unix/zerrors_zos_s390x.go +++ b/unix/zerrors_zos_s390x.go @@ -581,6 +581,8 @@ const ( AT_EMPTY_PATH = 0x1000 AT_REMOVEDIR = 0x200 RENAME_NOREPLACE = 1 << 0 + ST_RDONLY = 1 + ST_NOSUID = 2 ) const ( From 59665e5b431b8aea43003a9fba126c1d2f36a5d9 Mon Sep 17 00:00:00 2001 From: database64128 Date: Sun, 18 Aug 2024 02:42:01 +0000 Subject: [PATCH 07/23] unix: add Connectx for darwin connectx(2) can be used to initiate a connection with TCP Fast Open. Change-Id: I113ee4dede7df1c01e16a0c07fec2b384b266cb0 GitHub-Last-Rev: 31665b9ad3b7ce01ac881d4df9d94957d37da67b GitHub-Pull-Request: golang/sys#215 Reviewed-on: https://go-review.googlesource.com/c/sys/+/606155 Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui Reviewed-by: Ian Lance Taylor --- unix/darwin_amd64_test.go | 1 + unix/darwin_arm64_test.go | 1 + unix/mkerrors.sh | 1 + unix/syscall_darwin.go | 37 +++++++++++++++++++++++++++++++++++ unix/types_darwin.go | 6 ++++++ unix/zerrors_darwin_amd64.go | 7 +++++++ unix/zerrors_darwin_arm64.go | 7 +++++++ unix/zsyscall_darwin_amd64.go | 20 +++++++++++++++++++ unix/zsyscall_darwin_amd64.s | 5 +++++ unix/zsyscall_darwin_arm64.go | 20 +++++++++++++++++++ unix/zsyscall_darwin_arm64.s | 5 +++++ unix/ztypes_darwin_amd64.go | 13 ++++++++++++ unix/ztypes_darwin_arm64.go | 13 ++++++++++++ 13 files changed, 136 insertions(+) diff --git a/unix/darwin_amd64_test.go b/unix/darwin_amd64_test.go index b6dac524c4..f89b50e717 100644 --- a/unix/darwin_amd64_test.go +++ b/unix/darwin_amd64_test.go @@ -22,6 +22,7 @@ var darwinTests = [...]darwinTest{ {"close", libc_close_trampoline_addr}, {"closedir", libc_closedir_trampoline_addr}, {"connect", libc_connect_trampoline_addr}, + {"connectx", libc_connectx_trampoline_addr}, {"dup", libc_dup_trampoline_addr}, {"dup2", libc_dup2_trampoline_addr}, {"exchangedata", libc_exchangedata_trampoline_addr}, diff --git a/unix/darwin_arm64_test.go b/unix/darwin_arm64_test.go index 5a310de020..5fc4feb44b 100644 --- a/unix/darwin_arm64_test.go +++ b/unix/darwin_arm64_test.go @@ -22,6 +22,7 @@ var darwinTests = [...]darwinTest{ {"close", libc_close_trampoline_addr}, {"closedir", libc_closedir_trampoline_addr}, {"connect", libc_connect_trampoline_addr}, + {"connectx", libc_connectx_trampoline_addr}, {"dup", libc_dup_trampoline_addr}, {"dup2", libc_dup2_trampoline_addr}, {"exchangedata", libc_exchangedata_trampoline_addr}, diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index d07dd09eb5..e14b766a32 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -552,6 +552,7 @@ ccflags="$@" $2 !~ /^RTC_VL_(ACCURACY|BACKUP|DATA)/ && $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ || $2 ~ /^SOCK_|SK_DIAG_|SKNLGRP_$/ || + $2 ~ /^(CONNECT|SAE)_/ || $2 ~ /^FIORDCHK$/ || $2 ~ /^SIOC/ || $2 ~ /^TIOC/ || diff --git a/unix/syscall_darwin.go b/unix/syscall_darwin.go index 2d15200adb..099867deed 100644 --- a/unix/syscall_darwin.go +++ b/unix/syscall_darwin.go @@ -566,6 +566,43 @@ func PthreadFchdir(fd int) (err error) { return pthread_fchdir_np(fd) } +// Connectx calls connectx(2) to initiate a connection on a socket. +// +// srcIf, srcAddr, and dstAddr are filled into a [SaEndpoints] struct and passed as the endpoints argument. +// +// - srcIf is the optional source interface index. 0 means unspecified. +// - srcAddr is the optional source address. nil means unspecified. +// - dstAddr is the destination address. +// +// On success, Connectx returns the number of bytes enqueued for transmission. +func Connectx(fd int, srcIf uint32, srcAddr, dstAddr Sockaddr, associd SaeAssocID, flags uint32, iov []Iovec, connid *SaeConnID) (n uintptr, err error) { + endpoints := SaEndpoints{ + Srcif: srcIf, + } + + if srcAddr != nil { + addrp, addrlen, err := srcAddr.sockaddr() + if err != nil { + return 0, err + } + endpoints.Srcaddr = (*RawSockaddr)(addrp) + endpoints.Srcaddrlen = uint32(addrlen) + } + + if dstAddr != nil { + addrp, addrlen, err := dstAddr.sockaddr() + if err != nil { + return 0, err + } + endpoints.Dstaddr = (*RawSockaddr)(addrp) + endpoints.Dstaddrlen = uint32(addrlen) + } + + err = connectx(fd, &endpoints, associd, flags, iov, &n, connid) + return +} + +//sys connectx(fd int, endpoints *SaEndpoints, associd SaeAssocID, flags uint32, iov []Iovec, n *uintptr, connid *SaeConnID) (err error) //sys sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) //sys shmat(id int, addr uintptr, flag int) (ret uintptr, err error) diff --git a/unix/types_darwin.go b/unix/types_darwin.go index 7ed32a1a5f..36e2f045da 100644 --- a/unix/types_darwin.go +++ b/unix/types_darwin.go @@ -177,6 +177,12 @@ type XVSockPgen C.struct_xvsockpgen type _Socklen C.socklen_t +type SaeAssocID C.sae_associd_t + +type SaeConnID C.sae_connid_t + +type SaEndpoints C.struct_sa_endpoints + type Xucred C.struct_xucred type Linger C.struct_linger diff --git a/unix/zerrors_darwin_amd64.go b/unix/zerrors_darwin_amd64.go index 4308ac1772..d73c4652e6 100644 --- a/unix/zerrors_darwin_amd64.go +++ b/unix/zerrors_darwin_amd64.go @@ -237,6 +237,9 @@ const ( CLOCK_UPTIME_RAW_APPROX = 0x9 CLONE_NOFOLLOW = 0x1 CLONE_NOOWNERCOPY = 0x2 + CONNECT_DATA_AUTHENTICATED = 0x4 + CONNECT_DATA_IDEMPOTENT = 0x2 + CONNECT_RESUME_ON_READ_WRITE = 0x1 CR0 = 0x0 CR1 = 0x1000 CR2 = 0x2000 @@ -1265,6 +1268,10 @@ const ( RTV_SSTHRESH = 0x20 RUSAGE_CHILDREN = -0x1 RUSAGE_SELF = 0x0 + SAE_ASSOCID_ALL = 0xffffffff + SAE_ASSOCID_ANY = 0x0 + SAE_CONNID_ALL = 0xffffffff + SAE_CONNID_ANY = 0x0 SCM_CREDS = 0x3 SCM_RIGHTS = 0x1 SCM_TIMESTAMP = 0x2 diff --git a/unix/zerrors_darwin_arm64.go b/unix/zerrors_darwin_arm64.go index c8068a7a16..4a55a40058 100644 --- a/unix/zerrors_darwin_arm64.go +++ b/unix/zerrors_darwin_arm64.go @@ -237,6 +237,9 @@ const ( CLOCK_UPTIME_RAW_APPROX = 0x9 CLONE_NOFOLLOW = 0x1 CLONE_NOOWNERCOPY = 0x2 + CONNECT_DATA_AUTHENTICATED = 0x4 + CONNECT_DATA_IDEMPOTENT = 0x2 + CONNECT_RESUME_ON_READ_WRITE = 0x1 CR0 = 0x0 CR1 = 0x1000 CR2 = 0x2000 @@ -1265,6 +1268,10 @@ const ( RTV_SSTHRESH = 0x20 RUSAGE_CHILDREN = -0x1 RUSAGE_SELF = 0x0 + SAE_ASSOCID_ALL = 0xffffffff + SAE_ASSOCID_ANY = 0x0 + SAE_CONNID_ALL = 0xffffffff + SAE_CONNID_ANY = 0x0 SCM_CREDS = 0x3 SCM_RIGHTS = 0x1 SCM_TIMESTAMP = 0x2 diff --git a/unix/zsyscall_darwin_amd64.go b/unix/zsyscall_darwin_amd64.go index b622533ef2..24b346e1a3 100644 --- a/unix/zsyscall_darwin_amd64.go +++ b/unix/zsyscall_darwin_amd64.go @@ -841,6 +841,26 @@ var libc_pthread_fchdir_np_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func connectx(fd int, endpoints *SaEndpoints, associd SaeAssocID, flags uint32, iov []Iovec, n *uintptr, connid *SaeConnID) (err error) { + var _p0 unsafe.Pointer + if len(iov) > 0 { + _p0 = unsafe.Pointer(&iov[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := syscall_syscall9(libc_connectx_trampoline_addr, uintptr(fd), uintptr(unsafe.Pointer(endpoints)), uintptr(associd), uintptr(flags), uintptr(_p0), uintptr(len(iov)), uintptr(unsafe.Pointer(n)), uintptr(unsafe.Pointer(connid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_connectx_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_connectx connectx "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) { _, _, e1 := syscall_syscall6(libc_sendfile_trampoline_addr, uintptr(infd), uintptr(outfd), uintptr(offset), uintptr(unsafe.Pointer(len)), uintptr(hdtr), uintptr(flags)) if e1 != 0 { diff --git a/unix/zsyscall_darwin_amd64.s b/unix/zsyscall_darwin_amd64.s index cfe6646baf..ebd213100b 100644 --- a/unix/zsyscall_darwin_amd64.s +++ b/unix/zsyscall_darwin_amd64.s @@ -248,6 +248,11 @@ TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8 DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB) +TEXT libc_connectx_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_connectx(SB) +GLOBL ·libc_connectx_trampoline_addr(SB), RODATA, $8 +DATA ·libc_connectx_trampoline_addr(SB)/8, $libc_connectx_trampoline<>(SB) + TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_sendfile(SB) GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8 diff --git a/unix/zsyscall_darwin_arm64.go b/unix/zsyscall_darwin_arm64.go index 13f624f69f..824b9c2d5e 100644 --- a/unix/zsyscall_darwin_arm64.go +++ b/unix/zsyscall_darwin_arm64.go @@ -841,6 +841,26 @@ var libc_pthread_fchdir_np_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func connectx(fd int, endpoints *SaEndpoints, associd SaeAssocID, flags uint32, iov []Iovec, n *uintptr, connid *SaeConnID) (err error) { + var _p0 unsafe.Pointer + if len(iov) > 0 { + _p0 = unsafe.Pointer(&iov[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := syscall_syscall9(libc_connectx_trampoline_addr, uintptr(fd), uintptr(unsafe.Pointer(endpoints)), uintptr(associd), uintptr(flags), uintptr(_p0), uintptr(len(iov)), uintptr(unsafe.Pointer(n)), uintptr(unsafe.Pointer(connid)), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_connectx_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_connectx connectx "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) { _, _, e1 := syscall_syscall6(libc_sendfile_trampoline_addr, uintptr(infd), uintptr(outfd), uintptr(offset), uintptr(unsafe.Pointer(len)), uintptr(hdtr), uintptr(flags)) if e1 != 0 { diff --git a/unix/zsyscall_darwin_arm64.s b/unix/zsyscall_darwin_arm64.s index fe222b75df..4f178a2293 100644 --- a/unix/zsyscall_darwin_arm64.s +++ b/unix/zsyscall_darwin_arm64.s @@ -248,6 +248,11 @@ TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8 DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB) +TEXT libc_connectx_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_connectx(SB) +GLOBL ·libc_connectx_trampoline_addr(SB), RODATA, $8 +DATA ·libc_connectx_trampoline_addr(SB)/8, $libc_connectx_trampoline<>(SB) + TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_sendfile(SB) GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8 diff --git a/unix/ztypes_darwin_amd64.go b/unix/ztypes_darwin_amd64.go index 091d107f3a..d003c3d437 100644 --- a/unix/ztypes_darwin_amd64.go +++ b/unix/ztypes_darwin_amd64.go @@ -306,6 +306,19 @@ type XVSockPgen struct { type _Socklen uint32 +type SaeAssocID uint32 + +type SaeConnID uint32 + +type SaEndpoints struct { + Srcif uint32 + Srcaddr *RawSockaddr + Srcaddrlen uint32 + Dstaddr *RawSockaddr + Dstaddrlen uint32 + _ [4]byte +} + type Xucred struct { Version uint32 Uid uint32 diff --git a/unix/ztypes_darwin_arm64.go b/unix/ztypes_darwin_arm64.go index 28ff4ef74d..0d45a941aa 100644 --- a/unix/ztypes_darwin_arm64.go +++ b/unix/ztypes_darwin_arm64.go @@ -306,6 +306,19 @@ type XVSockPgen struct { type _Socklen uint32 +type SaeAssocID uint32 + +type SaeConnID uint32 + +type SaEndpoints struct { + Srcif uint32 + Srcaddr *RawSockaddr + Srcaddrlen uint32 + Dstaddr *RawSockaddr + Dstaddrlen uint32 + _ [4]byte +} + type Xucred struct { Version uint32 Uid uint32 From a8c5219b5e9b860186192d821723785bd48e9100 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 22 Aug 2024 09:39:55 -0700 Subject: [PATCH 08/23] unix: rename XDPUmemReg field back to Size When the Linux-specific XDPUmemReg struct was originally added (CL 136695) the only field with a prefix was chunk_size, so cgo rewrote the field to Size. Later Linux added a tx_metadata_len field, which caused cgo to to leave the chunk_size field as Chunk_size (CL 577975). However, existing code, specifically gvisor, refers to the field as Size. So go back to Size so that existing code will continue to work. This does unfortunately mean that people who used the struct since CL 577975 in April, 2024 will have to adapt. There doesn't seem to be a perfect solution here. But we've had Size since September, 2018, so let's stick with that. Change-Id: Ib11edfbf98ce3a9e1a909194f200a39ddfe6f8e0 Reviewed-on: https://go-review.googlesource.com/c/sys/+/607876 Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- unix/mkpost.go | 14 ++++++++++++++ unix/ztypes_linux.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/unix/mkpost.go b/unix/mkpost.go index 5dc2a2b92c..c98a77d7f6 100644 --- a/unix/mkpost.go +++ b/unix/mkpost.go @@ -202,6 +202,20 @@ func main() { spareFieldsRegex := regexp.MustCompile(`X__spare\S*`) b = spareFieldsRegex.ReplaceAll(b, []byte("_")) + // Rename chunk_size field in XDPUmemReg. + // When the struct was originally added (CL 136695) the only + // field with a prefix was chunk_size, so cgo rewrote the + // field to Size. Later Linux added a tx_metadata_len field, + // so cgo left chunk_size as Chunk_size (CL 577975). + // Go back to Size so that packages like gvisor don't have + // to adjust. + xdpUmemRegType := regexp.MustCompile(`type XDPUmemReg struct {[^}]*}`) + xdpUmemRegStructs := xdpUmemRegType.FindAll(b, -1) + for _, s := range xdpUmemRegStructs { + newName := bytes.Replace(s, []byte("Chunk_size"), []byte("Size"), 1) + b = bytes.Replace(b, s, newName, 1) + } + // Remove cgo padding fields removePaddingFieldsRegex := regexp.MustCompile(`Pad_cgo_\d+`) b = removePaddingFieldsRegex.ReplaceAll(b, []byte("_")) diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 7f1961b907..9f2550dc31 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -2486,7 +2486,7 @@ type XDPMmapOffsets struct { type XDPUmemReg struct { Addr uint64 Len uint64 - Chunk_size uint32 + Size uint32 Headroom uint32 Flags uint32 Tx_metadata_len uint32 From 29e55b2fd3f55c5c24c36d1995a5242f1ee34014 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 22 Aug 2024 09:09:15 -0700 Subject: [PATCH 09/23] unix: use os.Executable rather than os.Args[0] in tests Change-Id: I67a063d747c6e34dcd0292fdb3a9a0d965a6e133 Reviewed-on: https://go-review.googlesource.com/c/sys/+/607875 Commit-Queue: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Reviewed-by: Michael Knyszek Auto-Submit: Ian Lance Taylor --- unix/darwin_test.go | 6 +++++- unix/openbsd_test.go | 2 +- unix/syscall_freebsd_test.go | 2 +- unix/syscall_unix_test.go | 6 +++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/unix/darwin_test.go b/unix/darwin_test.go index 8edde104b1..f8fea55f1e 100644 --- a/unix/darwin_test.go +++ b/unix/darwin_test.go @@ -35,10 +35,14 @@ func TestDarwinLoader(t *testing.T) { // // In an ideal world each syscall would have its own test, so this test // would be unnecessary. Unfortunately, we do not live in that world. + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } for _, test := range darwinTests { // Call the test binary recursively, giving it a magic argument // (see init below) and the name of the test to run. - cmd := exec.Command(os.Args[0], "testDarwinLoader", test.name) + cmd := exec.Command(exe, "testDarwinLoader", test.name) // Run subprocess, collect results. Note that we expect the subprocess // to fail somehow, so the error is irrelevant. diff --git a/unix/openbsd_test.go b/unix/openbsd_test.go index 8ca05245d7..cd36c43755 100644 --- a/unix/openbsd_test.go +++ b/unix/openbsd_test.go @@ -43,7 +43,7 @@ func init() { // testCmd generates a proper command that, when executed, runs the test // corresponding to the given key. func testCmd(procName string) (*exec.Cmd, error) { - exe, err := filepath.Abs(os.Args[0]) + exe, err := os.Executable() if err != nil { return nil, err } diff --git a/unix/syscall_freebsd_test.go b/unix/syscall_freebsd_test.go index cbe3d36696..46b48d6f37 100644 --- a/unix/syscall_freebsd_test.go +++ b/unix/syscall_freebsd_test.go @@ -53,7 +53,7 @@ func init() { } func testCmd(procName string, procArg string) (*exec.Cmd, error) { - exe, err := filepath.Abs(os.Args[0]) + exe, err := os.Executable() if err != nil { return nil, err } diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index 29c158fbab..3bb5c7a10a 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -205,7 +205,11 @@ func TestPassFD(t *testing.T) { defer writeFile.Close() defer readFile.Close() - cmd := exec.Command(os.Args[0], "-test.run=^TestPassFD$", "--", t.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) From 3283fc3f6160baf63bec24fbaa24e094e9ff6daf Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Wed, 14 Aug 2024 15:24:42 +0200 Subject: [PATCH 10/23] cpu: add support for detecting RISC-V extensions Add a RISCV64 variable to cpu that indicates both the presence of RISC-V extensions and performance information about the underlying RISC-V cores. The variable is only populated with non false values on Linux. The detection code first attempts to use the riscv_hwprobe syscall introduced in Linux 6.4, falling back to HWCAP if riscv_hwprobe is not supported. The patch can detect the C, V, Zba, Zbb and Zbs extensions. V, Zba, Zbb and Zbs can only be detected on a 6.5 kernel or later (without backports). Updates golang/go#61416 Change-Id: I40f92724ee3d337c06bdc559ff0b18a8f6bfda9f Reviewed-on: https://go-review.googlesource.com/c/sys/+/605815 Reviewed-by: Cherry Mui Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Reviewed-by: Joel Sing Reviewed-by: Meng Zhuo --- cpu/cpu.go | 19 ++++++ cpu/cpu_linux_noinit.go | 2 +- cpu/cpu_linux_riscv64.go | 137 +++++++++++++++++++++++++++++++++++++++ cpu/cpu_riscv64.go | 11 +++- cpu/cpu_test.go | 8 +++ 5 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 cpu/cpu_linux_riscv64.go diff --git a/cpu/cpu.go b/cpu/cpu.go index ec07aab057..02609d5b21 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -201,6 +201,25 @@ var S390X struct { _ CacheLinePad } +// RISCV64 contains the supported CPU features and performance characteristics for riscv64 +// platforms. The booleans in RISCV64, with the exception of HasFastMisaligned, indicate +// the presence of RISC-V extensions. +// +// It is safe to assume that all the RV64G extensions are supported and so they are omitted from +// this structure. As riscv64 Go programs require at least RV64G, the code that populates +// this structure cannot run successfully if some of the RV64G extensions are missing. +// The struct is padded to avoid false sharing. +var RISCV64 struct { + _ CacheLinePad + HasFastMisaligned bool // Fast misaligned accesses + HasC bool // Compressed instruction-set extension + HasV bool // Vector extension compatible with RVV 1.0 + HasZba bool // Address generation instructions extension + HasZbb bool // Basic bit-manipulation extension + HasZbs bool // Single-bit instructions extension + _ CacheLinePad +} + func init() { archInit() initOptions() diff --git a/cpu/cpu_linux_noinit.go b/cpu/cpu_linux_noinit.go index cd63e73355..7d902b6847 100644 --- a/cpu/cpu_linux_noinit.go +++ b/cpu/cpu_linux_noinit.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build linux && !arm && !arm64 && !mips64 && !mips64le && !ppc64 && !ppc64le && !s390x +//go:build linux && !arm && !arm64 && !mips64 && !mips64le && !ppc64 && !ppc64le && !s390x && !riscv64 package cpu diff --git a/cpu/cpu_linux_riscv64.go b/cpu/cpu_linux_riscv64.go new file mode 100644 index 0000000000..cb4a0c5728 --- /dev/null +++ b/cpu/cpu_linux_riscv64.go @@ -0,0 +1,137 @@ +// 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. + +package cpu + +import ( + "syscall" + "unsafe" +) + +// RISC-V extension discovery code for Linux. The approach here is to first try the riscv_hwprobe +// syscall falling back to HWCAP to check for the C extension if riscv_hwprobe is not available. +// +// A note on detection of the Vector extension using HWCAP. +// +// Support for the Vector extension version 1.0 was added to the Linux kernel in release 6.5. +// Support for the riscv_hwprobe syscall was added in 6.4. It follows that if the riscv_hwprobe +// syscall is not available then neither is the Vector extension (which needs kernel support). +// The riscv_hwprobe syscall should then be all we need to detect the Vector extension. +// However, some RISC-V board manufacturers ship boards with an older kernel on top of which +// they have back-ported various versions of the Vector extension patches but not the riscv_hwprobe +// patches. These kernels advertise support for the Vector extension using HWCAP. Falling +// back to HWCAP to detect the Vector extension, if riscv_hwprobe is not available, or simply not +// bothering with riscv_hwprobe at all and just using HWCAP may then seem like an attractive option. +// +// Unfortunately, simply checking the 'V' bit in AT_HWCAP will not work as this bit is used by +// RISC-V board and cloud instance providers to mean different things. The Lichee Pi 4A board +// and the Scaleway RV1 cloud instances use the 'V' bit to advertise their support for the unratified +// 0.7.1 version of the Vector Specification. The Banana Pi BPI-F3 and the CanMV-K230 board use +// it to advertise support for 1.0 of the Vector extension. Versions 0.7.1 and 1.0 of the Vector +// extension are binary incompatible. HWCAP can then not be used in isolation to populate the +// HasV field as this field indicates that the underlying CPU is compatible with RVV 1.0. +// +// There is a way at runtime to distinguish between versions 0.7.1 and 1.0 of the Vector +// specification by issuing a RVV 1.0 vsetvli instruction and checking the vill bit of the vtype +// register. This check would allow us to safely detect version 1.0 of the Vector extension +// with HWCAP, if riscv_hwprobe were not available. However, the check cannot +// be added until the assembler supports the Vector instructions. +// +// Note the riscv_hwprobe syscall does not suffer from these ambiguities by design as all of the +// extensions it advertises support for are explicitly versioned. It's also worth noting that +// the riscv_hwprobe syscall is the only way to detect multi-letter RISC-V extensions, e.g., Zba. +// These cannot be detected using HWCAP and so riscv_hwprobe must be used to detect the majority +// of RISC-V extensions. +// +// Please see https://docs.kernel.org/arch/riscv/hwprobe.html for more information. + +// golang.org/x/sys/cpu is not allowed to depend on golang.org/x/sys/unix so we must +// reproduce the constants, types and functions needed to make the riscv_hwprobe syscall +// here. + +const ( + // Copied from golang.org/x/sys/unix/ztypes_linux_riscv64.go. + riscv_HWPROBE_KEY_IMA_EXT_0 = 0x4 + riscv_HWPROBE_IMA_C = 0x2 + riscv_HWPROBE_IMA_V = 0x4 + riscv_HWPROBE_EXT_ZBA = 0x8 + riscv_HWPROBE_EXT_ZBB = 0x10 + riscv_HWPROBE_EXT_ZBS = 0x20 + riscv_HWPROBE_KEY_CPUPERF_0 = 0x5 + riscv_HWPROBE_MISALIGNED_FAST = 0x3 + riscv_HWPROBE_MISALIGNED_MASK = 0x7 +) + +const ( + // sys_RISCV_HWPROBE is copied from golang.org/x/sys/unix/zsysnum_linux_riscv64.go. + sys_RISCV_HWPROBE = 258 +) + +// riscvHWProbePairs is copied from golang.org/x/sys/unix/ztypes_linux_riscv64.go. +type riscvHWProbePairs struct { + key int64 + value uint64 +} + +const ( + // CPU features + hwcap_RISCV_ISA_C = 1 << ('C' - 'A') +) + +func doinit() { + // A slice of key/value pair structures is passed to the RISCVHWProbe syscall. The key + // field should be initialised with one of the key constants defined above, e.g., + // RISCV_HWPROBE_KEY_IMA_EXT_0. The syscall will set the value field to the appropriate value. + // If the kernel does not recognise a key it will set the key field to -1 and the value field to 0. + + pairs := []riscvHWProbePairs{ + {riscv_HWPROBE_KEY_IMA_EXT_0, 0}, + {riscv_HWPROBE_KEY_CPUPERF_0, 0}, + } + + // This call only indicates that extensions are supported if they are implemented on all cores. + if riscvHWProbe(pairs, 0) { + if pairs[0].key != -1 { + v := uint(pairs[0].value) + RISCV64.HasC = isSet(v, riscv_HWPROBE_IMA_C) + RISCV64.HasV = isSet(v, riscv_HWPROBE_IMA_V) + RISCV64.HasZba = isSet(v, riscv_HWPROBE_EXT_ZBA) + RISCV64.HasZbb = isSet(v, riscv_HWPROBE_EXT_ZBB) + RISCV64.HasZbs = isSet(v, riscv_HWPROBE_EXT_ZBS) + } + if pairs[1].key != -1 { + v := pairs[1].value & riscv_HWPROBE_MISALIGNED_MASK + RISCV64.HasFastMisaligned = v == riscv_HWPROBE_MISALIGNED_FAST + } + } + + // Let's double check with HWCAP if the C extension does not appear to be supported. + // This may happen if we're running on a kernel older than 6.4. + + if !RISCV64.HasC { + RISCV64.HasC = isSet(hwCap, hwcap_RISCV_ISA_C) + } +} + +func isSet(hwc uint, value uint) bool { + return hwc&value != 0 +} + +// riscvHWProbe is a simplified version of the generated wrapper function found in +// golang.org/x/sys/unix/zsyscall_linux_riscv64.go. We simplify it by removing the +// cpuCount and cpus parameters which we do not need. We always want to pass 0 for +// these parameters here so the kernel only reports the extensions that are present +// on all cores. +func riscvHWProbe(pairs []riscvHWProbePairs, flags uint) bool { + var _zero uintptr + var p0 unsafe.Pointer + if len(pairs) > 0 { + p0 = unsafe.Pointer(&pairs[0]) + } else { + p0 = unsafe.Pointer(&_zero) + } + + _, _, e1 := syscall.Syscall6(sys_RISCV_HWPROBE, uintptr(p0), uintptr(len(pairs)), uintptr(0), uintptr(0), uintptr(flags), 0) + return e1 == 0 +} diff --git a/cpu/cpu_riscv64.go b/cpu/cpu_riscv64.go index 7f0c79c004..aca3199c91 100644 --- a/cpu/cpu_riscv64.go +++ b/cpu/cpu_riscv64.go @@ -8,4 +8,13 @@ package cpu const cacheLineSize = 64 -func initOptions() {} +func initOptions() { + options = []option{ + {Name: "fastmisaligned", Feature: &RISCV64.HasFastMisaligned}, + {Name: "c", Feature: &RISCV64.HasC}, + {Name: "v", Feature: &RISCV64.HasV}, + {Name: "zba", Feature: &RISCV64.HasZba}, + {Name: "zbb", Feature: &RISCV64.HasZbb}, + {Name: "zbs", Feature: &RISCV64.HasZbs}, + } +} diff --git a/cpu/cpu_test.go b/cpu/cpu_test.go index ba25551509..7a9bac7e5d 100644 --- a/cpu/cpu_test.go +++ b/cpu/cpu_test.go @@ -61,6 +61,14 @@ func TestMIPS64Initialized(t *testing.T) { } } +func TestRISCV64Initialized(t *testing.T) { + if runtime.GOARCH == "riscv64" { + if !cpu.Initialized { + t.Fatal("Initialized expected true, got false") + } + } +} + // On ppc64x, the ISA bit for POWER8 should always be set on POWER8 and beyond. func TestPPC64minimalFeatures(t *testing.T) { // Do not run this with gccgo on ppc64, as it doesn't have POWER8 as a minimum From 71132f5fbd80ad7e1b3940bc6689c31a6e0f195b Mon Sep 17 00:00:00 2001 From: Eli Lindsey Date: Thu, 22 Aug 2024 20:42:27 -0400 Subject: [PATCH 11/23] unix: add POLLRDHUP to FreeBSD POLLRDHUP is a poll(2) event applicable to stream sockets that notifies when a remote peer closes a connection. Change-Id: I03a192426f89bbd08fb27dda2716ffb888043c92 Reviewed-on: https://go-review.googlesource.com/c/sys/+/607797 Auto-Submit: Ian Lance Taylor Reviewed-by: Cherry Mui Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- unix/types_freebsd.go | 1 + unix/ztypes_freebsd_386.go | 1 + unix/ztypes_freebsd_amd64.go | 1 + unix/ztypes_freebsd_arm.go | 1 + unix/ztypes_freebsd_arm64.go | 1 + unix/ztypes_freebsd_riscv64.go | 1 + 6 files changed, 6 insertions(+) diff --git a/unix/types_freebsd.go b/unix/types_freebsd.go index 23e3a026af..601096ee5f 100644 --- a/unix/types_freebsd.go +++ b/unix/types_freebsd.go @@ -356,6 +356,7 @@ const ( POLLRDNORM = C.POLLRDNORM POLLWRBAND = C.POLLWRBAND POLLWRNORM = C.POLLWRNORM + POLLRDHUP = C.POLLRDHUP ) // Capabilities diff --git a/unix/ztypes_freebsd_386.go b/unix/ztypes_freebsd_386.go index 6cbd094a3a..51e13eb055 100644 --- a/unix/ztypes_freebsd_386.go +++ b/unix/ztypes_freebsd_386.go @@ -625,6 +625,7 @@ const ( POLLRDNORM = 0x40 POLLWRBAND = 0x100 POLLWRNORM = 0x4 + POLLRDHUP = 0x4000 ) type CapRights struct { diff --git a/unix/ztypes_freebsd_amd64.go b/unix/ztypes_freebsd_amd64.go index 7c03b6ee77..d002d8ef3c 100644 --- a/unix/ztypes_freebsd_amd64.go +++ b/unix/ztypes_freebsd_amd64.go @@ -630,6 +630,7 @@ const ( POLLRDNORM = 0x40 POLLWRBAND = 0x100 POLLWRNORM = 0x4 + POLLRDHUP = 0x4000 ) type CapRights struct { diff --git a/unix/ztypes_freebsd_arm.go b/unix/ztypes_freebsd_arm.go index 422107ee8b..3f863d898d 100644 --- a/unix/ztypes_freebsd_arm.go +++ b/unix/ztypes_freebsd_arm.go @@ -616,6 +616,7 @@ const ( POLLRDNORM = 0x40 POLLWRBAND = 0x100 POLLWRNORM = 0x4 + POLLRDHUP = 0x4000 ) type CapRights struct { diff --git a/unix/ztypes_freebsd_arm64.go b/unix/ztypes_freebsd_arm64.go index 505a12acfd..61c7293106 100644 --- a/unix/ztypes_freebsd_arm64.go +++ b/unix/ztypes_freebsd_arm64.go @@ -610,6 +610,7 @@ const ( POLLRDNORM = 0x40 POLLWRBAND = 0x100 POLLWRNORM = 0x4 + POLLRDHUP = 0x4000 ) type CapRights struct { diff --git a/unix/ztypes_freebsd_riscv64.go b/unix/ztypes_freebsd_riscv64.go index cc986c7900..b5d17414f0 100644 --- a/unix/ztypes_freebsd_riscv64.go +++ b/unix/ztypes_freebsd_riscv64.go @@ -612,6 +612,7 @@ const ( POLLRDNORM = 0x40 POLLWRBAND = 0x100 POLLWRNORM = 0x4 + POLLRDHUP = 0x4000 ) type CapRights struct { From 9cb830b23eaf26f5db69302da2b1ba1d89c9548e Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 22 Aug 2024 15:07:11 -0700 Subject: [PATCH 12/23] unix: add missing import to syscall_hurd.go CL 471119 added a reference to the unsafe package, but didn't add the import. Change-Id: Ibb8097df0444d8e83ba08e4ca2b5df98844fccf4 Reviewed-on: https://go-review.googlesource.com/c/sys/+/607976 Reviewed-by: Tobias Klauser Auto-Submit: Ian Lance Taylor Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Commit-Queue: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- unix/syscall_hurd.go | 1 + 1 file changed, 1 insertion(+) diff --git a/unix/syscall_hurd.go b/unix/syscall_hurd.go index ba46651f8e..a6a2d2fc2b 100644 --- a/unix/syscall_hurd.go +++ b/unix/syscall_hurd.go @@ -11,6 +11,7 @@ package unix int ioctl(int, unsigned long int, uintptr_t); */ import "C" +import "unsafe" func ioctl(fd int, req uint, arg uintptr) (err error) { r0, er := C.ioctl(C.int(fd), C.ulong(req), C.uintptr_t(arg)) From ed67b1566aaf07fe80ee32c1efd254f99dbcf514 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Mon, 26 Aug 2024 22:22:01 +0000 Subject: [PATCH 13/23] windows: add console codepage api Add setter/getter for console input/output codepages. This is useful to set the console expected codepage instead of converting it to UTF-16 before writing. Change-Id: Ie0465708e7cf68d776e23dbbeeca7bcb4db7d2bf GitHub-Last-Rev: 93c06e27a0ac885d9da288985fc1df87921626c0 GitHub-Pull-Request: golang/sys#206 Reviewed-on: https://go-review.googlesource.com/c/sys/+/599395 LUCI-TryBot-Result: Go LUCI Reviewed-by: Alex Brainman Reviewed-by: Cherry Mui Reviewed-by: Michael Pratt --- windows/syscall_windows.go | 4 ++++ windows/zsyscall_windows.go | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index 1fa34fd17c..5cee9a3143 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -313,6 +313,10 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys SetConsoleMode(console Handle, mode uint32) (err error) = kernel32.SetConsoleMode //sys GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) = kernel32.GetConsoleScreenBufferInfo //sys setConsoleCursorPosition(console Handle, position uint32) (err error) = kernel32.SetConsoleCursorPosition +//sys GetConsoleCP() (cp uint32, err error) = kernel32.GetConsoleCP +//sys GetConsoleOutputCP() (cp uint32, err error) = kernel32.GetConsoleOutputCP +//sys SetConsoleCP(cp uint32) (err error) = kernel32.SetConsoleCP +//sys SetConsoleOutputCP(cp uint32) (err error) = kernel32.SetConsoleOutputCP //sys WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) = kernel32.WriteConsoleW //sys ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) = kernel32.ReadConsoleW //sys resizePseudoConsole(pconsole Handle, size uint32) (hr error) = kernel32.ResizePseudoConsole diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 9bb979a3e4..4c2e1bdc01 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -247,7 +247,9 @@ var ( procGetCommandLineW = modkernel32.NewProc("GetCommandLineW") procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW") procGetComputerNameW = modkernel32.NewProc("GetComputerNameW") + procGetConsoleCP = modkernel32.NewProc("GetConsoleCP") procGetConsoleMode = modkernel32.NewProc("GetConsoleMode") + procGetConsoleOutputCP = modkernel32.NewProc("GetConsoleOutputCP") procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo") procGetCurrentDirectoryW = modkernel32.NewProc("GetCurrentDirectoryW") procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId") @@ -347,8 +349,10 @@ var ( procSetCommMask = modkernel32.NewProc("SetCommMask") procSetCommState = modkernel32.NewProc("SetCommState") procSetCommTimeouts = modkernel32.NewProc("SetCommTimeouts") + procSetConsoleCP = modkernel32.NewProc("SetConsoleCP") procSetConsoleCursorPosition = modkernel32.NewProc("SetConsoleCursorPosition") procSetConsoleMode = modkernel32.NewProc("SetConsoleMode") + procSetConsoleOutputCP = modkernel32.NewProc("SetConsoleOutputCP") procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW") procSetDefaultDllDirectories = modkernel32.NewProc("SetDefaultDllDirectories") procSetDllDirectoryW = modkernel32.NewProc("SetDllDirectoryW") @@ -2162,6 +2166,15 @@ func GetComputerName(buf *uint16, n *uint32) (err error) { return } +func GetConsoleCP() (cp uint32, err error) { + r0, _, e1 := syscall.Syscall(procGetConsoleCP.Addr(), 0, 0, 0, 0) + cp = uint32(r0) + if cp == 0 { + err = errnoErr(e1) + } + return +} + func GetConsoleMode(console Handle, mode *uint32) (err error) { r1, _, e1 := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0) if r1 == 0 { @@ -2170,6 +2183,15 @@ func GetConsoleMode(console Handle, mode *uint32) (err error) { return } +func GetConsoleOutputCP() (cp uint32, err error) { + r0, _, e1 := syscall.Syscall(procGetConsoleOutputCP.Addr(), 0, 0, 0, 0) + cp = uint32(r0) + if cp == 0 { + err = errnoErr(e1) + } + return +} + func GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) { r1, _, e1 := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(info)), 0) if r1 == 0 { @@ -3038,6 +3060,14 @@ func SetCommTimeouts(handle Handle, timeouts *CommTimeouts) (err error) { return } +func SetConsoleCP(cp uint32) (err error) { + r1, _, e1 := syscall.Syscall(procSetConsoleCP.Addr(), 1, uintptr(cp), 0, 0) + if r1 == 0 { + err = errnoErr(e1) + } + return +} + func setConsoleCursorPosition(console Handle, position uint32) (err error) { r1, _, e1 := syscall.Syscall(procSetConsoleCursorPosition.Addr(), 2, uintptr(console), uintptr(position), 0) if r1 == 0 { @@ -3054,6 +3084,14 @@ func SetConsoleMode(console Handle, mode uint32) (err error) { return } +func SetConsoleOutputCP(cp uint32) (err error) { + r1, _, e1 := syscall.Syscall(procSetConsoleOutputCP.Addr(), 1, uintptr(cp), 0, 0) + if r1 == 0 { + err = errnoErr(e1) + } + return +} + func SetCurrentDirectory(path *uint16) (err error) { r1, _, e1 := syscall.Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) if r1 == 0 { From a43b625d3c32b5cd2726d132c8478884ae6cb0dc Mon Sep 17 00:00:00 2001 From: James Tucker Date: Fri, 26 Jul 2024 13:58:09 -0700 Subject: [PATCH 14/23] windows: add SIO_UDP_NETRESET constant In order to get BSD like behavior with regard to ICMP, it is necessary to set SIO_UDP_NETRESET as well as SIO_UDP_CONNRESET. Updates golang/go#68614 Change-Id: Ibdf5b6ea6bc08a9d3a0aeac9037864670cf765c0 Reviewed-on: https://go-review.googlesource.com/c/sys/+/609295 LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov Reviewed-by: Funda Secgin Reviewed-by: Ian Lance Taylor Reviewed-by: Alex Brainman Auto-Submit: Ian Lance Taylor --- windows/types_windows.go | 1 + 1 file changed, 1 insertion(+) diff --git a/windows/types_windows.go b/windows/types_windows.go index 3f03b3d57c..7b97a154c9 100644 --- a/windows/types_windows.go +++ b/windows/types_windows.go @@ -1060,6 +1060,7 @@ const ( SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6 SIO_KEEPALIVE_VALS = IOC_IN | IOC_VENDOR | 4 SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12 + SIO_UDP_NETRESET = IOC_IN | IOC_VENDOR | 15 // cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460 From c08bc6e187fc8d4d07c5eae96ac4a8ba6a326abb Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 4 Sep 2024 12:30:33 +0200 Subject: [PATCH 15/23] unix: update Go to 1.23.0 Change-Id: Ifd0f3aefd3699871fc875c8628aa4105b2c85f13 Reviewed-on: https://go-review.googlesource.com/c/sys/+/610016 LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Auto-Submit: Tobias Klauser Reviewed-by: Dmitri Shuralyov --- unix/linux/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile index 51b66ccba9..3f36a1be34 100644 --- a/unix/linux/Dockerfile +++ b/unix/linux/Dockerfile @@ -21,9 +21,9 @@ RUN git clone --branch v6.10 --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.21.0 +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 d0398903a16ba2232b389fb31032ddf57cac34efda306a0eebac34f0965a0742 +ENV GOLANG_DOWNLOAD_SHA256 905a297f19ead44780548933e0ff1a1b86e8327bb459e92f9c0012569f76f5e3 RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ From 68ed59b20bf0e0fefc232c3eb288c90c95732b3d Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Fri, 6 Sep 2024 06:22:10 -0400 Subject: [PATCH 16/23] windows/svc: fix printf(var) mistake detected by latest printf checker For golang/go#69267. Change-Id: Ie240b5c826bb96c0e2021a7e99a3c0f973f0a0e1 Reviewed-on: https://go-review.googlesource.com/c/sys/+/610940 Reviewed-by: Tim King Reviewed-by: Dmitri Shuralyov Auto-Submit: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI --- windows/svc/svc_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/svc/svc_test.go b/windows/svc/svc_test.go index be369ea211..cd2cd467c6 100644 --- a/windows/svc/svc_test.go +++ b/windows/svc/svc_test.go @@ -178,7 +178,7 @@ func TestIsWindowsServiceWhenParentExits(t *testing.T) { child.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=child") err := child.Start() if err != nil { - fmt.Fprintf(os.Stderr, fmt.Sprintf("child start failed: %v", err)) + fmt.Fprintf(os.Stderr, "child start failed: %v", err) os.Exit(1) } os.Exit(0) From 30de3524c2229f51e499858e9201cbcd8b9c2b80 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 8 Sep 2024 18:48:53 +0200 Subject: [PATCH 17/23] unix: fix Test{Fd,}Xattr failure on NetBSD On NetBSD the namespace of an xattr is stored separately from the name and isn't returned by Listxattr and Flistxattr. Like on FreeBSD, strip the namespace before checking the returned xattrs. Fixes golang/go#69313 Fixes golang/go#69314 Change-Id: I7f2393cc63f9860332c0e07a51f3b9d32911e892 Cq-Include-Trybots: luci.golang.try:x_sys-gotip-netbsd-arm64 Reviewed-on: https://go-review.googlesource.com/c/sys/+/611695 Auto-Submit: Tobias Klauser LUCI-TryBot-Result: Go LUCI Reviewed-by: Benny Siegert Reviewed-by: Ian Lance Taylor Commit-Queue: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- unix/xattr_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/unix/xattr_test.go b/unix/xattr_test.go index a8e4fb86d1..a8be3ec5be 100644 --- a/unix/xattr_test.go +++ b/unix/xattr_test.go @@ -56,8 +56,9 @@ func TestXattr(t *testing.T) { xattrs := stringsFromByteSlice(buf[:read]) xattrWant := xattrName - if runtime.GOOS == "freebsd" { - // On FreeBSD, the namespace is stored separately from the xattr + switch runtime.GOOS { + case "freebsd", "netbsd": + // On FreeBSD and NetBSD, the namespace is stored separately from the xattr // name and Listxattr doesn't return the namespace prefix. xattrWant = strings.TrimPrefix(xattrWant, "user.") } @@ -65,11 +66,12 @@ func TestXattr(t *testing.T) { for _, name := range xattrs { if name == xattrWant { found = true + break } } if !found { - t.Errorf("Listxattr did not return previously set attribute '%s'", xattrName) + t.Errorf("Listxattr did not return previously set attribute %q in attributes %v", xattrName, xattrs) } // find size @@ -162,8 +164,9 @@ func TestFdXattr(t *testing.T) { xattrs := stringsFromByteSlice(buf[:read]) xattrWant := xattrName - if runtime.GOOS == "freebsd" { - // On FreeBSD, the namespace is stored separately from the xattr + switch runtime.GOOS { + case "freebsd", "netbsd": + // On FreeBSD and NetBSD, the namespace is stored separately from the xattr // name and Listxattr doesn't return the namespace prefix. xattrWant = strings.TrimPrefix(xattrWant, "user.") } @@ -171,11 +174,12 @@ func TestFdXattr(t *testing.T) { for _, name := range xattrs { if name == xattrWant { found = true + break } } if !found { - t.Errorf("Flistxattr did not return previously set attribute '%s'", xattrName) + t.Errorf("Flistxattr did not return previously set attribute %q in attributes %v", xattrName, xattrs) } // find size From d58f986c8984f0fb072181b6c10da9a2d4f9287f Mon Sep 17 00:00:00 2001 From: cuishuang Date: Mon, 9 Sep 2024 15:02:35 +0800 Subject: [PATCH 18/23] all: fix some typos in comment Change-Id: I40f9866661bad30ee2f4be2e9d0beee54db860b3 Reviewed-on: https://go-review.googlesource.com/c/sys/+/611775 Reviewed-by: Dmitri Shuralyov Commit-Queue: Ian Lance Taylor Auto-Submit: Dmitri Shuralyov Auto-Submit: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- unix/README.md | 2 +- unix/internal/mkmerge/mkmerge.go | 2 +- unix/mkpost.go | 2 +- unix/mksyscall_zos_s390x.go | 2 +- unix/syscall_aix.go | 2 +- unix/syscall_solaris_test.go | 2 +- unix/syscall_zos_test.go | 4 ++-- unix/sysvshm_unix_test.go | 2 +- unix/xattr_test.go | 2 +- windows/dll_windows.go | 2 +- windows/registry/registry_test.go | 2 +- windows/svc/mgr/config.go | 2 +- windows/svc/mgr/recovery.go | 4 ++-- windows/syscall_windows_test.go | 4 ++-- 14 files changed, 17 insertions(+), 17 deletions(-) diff --git a/unix/README.md b/unix/README.md index 7d3c060e12..6e08a76a71 100644 --- a/unix/README.md +++ b/unix/README.md @@ -156,7 +156,7 @@ from the generated architecture-specific files listed below, and merge these into a common file for each OS. The merge is performed in the following steps: -1. Construct the set of common code that is idential in all architecture-specific files. +1. Construct the set of common code that is identical in all architecture-specific files. 2. Write this common code to the merged file. 3. Remove the common code from all architecture-specific files. diff --git a/unix/internal/mkmerge/mkmerge.go b/unix/internal/mkmerge/mkmerge.go index db8098c7f0..52f1d12bb2 100644 --- a/unix/internal/mkmerge/mkmerge.go +++ b/unix/internal/mkmerge/mkmerge.go @@ -427,7 +427,7 @@ func filterImports(fileSrc []byte) ([]byte, error) { } // merge extracts duplicate code from archFiles and merges it to mergeFile. -// 1. Construct commonSet: the set of code that is idential in all archFiles. +// 1. Construct commonSet: the set of code that is identical in all archFiles. // 2. Write the code in commonSet to mergedFile. // 3. Remove the commonSet code from all archFiles. func merge(mergedFile string, archFiles ...string) error { diff --git a/unix/mkpost.go b/unix/mkpost.go index c98a77d7f6..ecacf010c9 100644 --- a/unix/mkpost.go +++ b/unix/mkpost.go @@ -153,7 +153,7 @@ func main() { b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64")) // Remove fields that are added by glibc - // Note that this is unstable as the identifers are private. + // Note that this is unstable as the identifiers are private. removeFieldsRegex := regexp.MustCompile(`X__glibc\S*`) b = removeFieldsRegex.ReplaceAll(b, []byte("_")) diff --git a/unix/mksyscall_zos_s390x.go b/unix/mksyscall_zos_s390x.go index f4fd945b39..12db6378af 100644 --- a/unix/mksyscall_zos_s390x.go +++ b/unix/mksyscall_zos_s390x.go @@ -374,7 +374,7 @@ func processStream(s *bufio.Scanner, asm, go1 *bufio.Writer, m *map[string]int64 } // Prepare arguments to Syscall. var args []string - var fargs []string // for call fowarding + var fargs []string // for call forwarding n := 0 for _, param := range in { p := parseParam(param) diff --git a/unix/syscall_aix.go b/unix/syscall_aix.go index 67ce6cef2d..6f15ba1eaf 100644 --- a/unix/syscall_aix.go +++ b/unix/syscall_aix.go @@ -360,7 +360,7 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, var status _C_int var r Pid_t err = ERESTART - // AIX wait4 may return with ERESTART errno, while the processus is still + // AIX wait4 may return with ERESTART errno, while the process is still // active. for err == ERESTART { r, err = wait4(Pid_t(pid), &status, options, rusage) diff --git a/unix/syscall_solaris_test.go b/unix/syscall_solaris_test.go index a9d486a10f..738733b21f 100644 --- a/unix/syscall_solaris_test.go +++ b/unix/syscall_solaris_test.go @@ -207,7 +207,7 @@ func TestEventPortErrors(t *testing.T) { defer port.Close() err = port.AssociatePath(path, stat, unix.FILE_MODIFIED, nil) if err == nil { - t.Errorf("unexpected success associating nonexistant file") + t.Errorf("unexpected success associating nonexistent file") } err = port.DissociatePath(path) if err == nil { diff --git a/unix/syscall_zos_test.go b/unix/syscall_zos_test.go index 2589e9ccd0..c04f5a00f7 100644 --- a/unix/syscall_zos_test.go +++ b/unix/syscall_zos_test.go @@ -3350,7 +3350,7 @@ func TestCreat(t *testing.T) { t.Fatal("Creat error: Cannot truncate file") } if string(b) != string(writeContent) { - t.Fatal("data missmatch: expect ", string(writeContent), " actual: ", string(b)) + t.Fatal("data mismatch: expect ", string(writeContent), " actual: ", string(b)) } // testing file create function @@ -3375,7 +3375,7 @@ func TestCreat(t *testing.T) { t.Fatal("Creat error: Cannot truncate file") } if string(b) != string(writeContent) { - t.Fatal("data missmatch: expect ", string(writeContent), " actual: ", string(b)) + t.Fatal("data mismatch: expect ", string(writeContent), " actual: ", string(b)) } } diff --git a/unix/sysvshm_unix_test.go b/unix/sysvshm_unix_test.go index cf234b83e3..af90637c2c 100644 --- a/unix/sysvshm_unix_test.go +++ b/unix/sysvshm_unix_test.go @@ -66,7 +66,7 @@ func TestSysvSharedMemory(t *testing.T) { } if runtime.GOOS == "zos" { - // The returned shared memory alligns with the pagesize. + // The returned shared memory aligns with the pagesize. // If pagesize is not 1024 bytes, the shared memory could be larger if len(b2) < 1024 { t.Fatalf("b1 len = %v, less than 1024", len(b2)) diff --git a/unix/xattr_test.go b/unix/xattr_test.go index a8be3ec5be..dfa208f160 100644 --- a/unix/xattr_test.go +++ b/unix/xattr_test.go @@ -119,7 +119,7 @@ func TestXattr(t *testing.T) { err = unix.Lsetxattr(s, xattrName, []byte(xattrDataSet), 0) if err != nil { - // Linux and Android doen't support xattrs on symlinks according + // Linux and Android doesn't support xattrs on symlinks according // to xattr(7), so just test that we get the proper error. if (runtime.GOOS != "linux" && runtime.GOOS != "android") || err != unix.EPERM { t.Fatalf("Lsetxattr: %v", err) diff --git a/windows/dll_windows.go b/windows/dll_windows.go index 115341fba6..4e613cf633 100644 --- a/windows/dll_windows.go +++ b/windows/dll_windows.go @@ -65,7 +65,7 @@ func LoadDLL(name string) (dll *DLL, err error) { return d, nil } -// MustLoadDLL is like LoadDLL but panics if load operation failes. +// MustLoadDLL is like LoadDLL but panics if load operation fails. func MustLoadDLL(name string) *DLL { d, e := LoadDLL(name) if e != nil { diff --git a/windows/registry/registry_test.go b/windows/registry/registry_test.go index c227a5db62..6e7bec505e 100644 --- a/windows/registry/registry_test.go +++ b/windows/registry/registry_test.go @@ -214,7 +214,7 @@ func enumerateValues(t *testing.T, k registry.Key) { } } for n, v := range haveNames { - t.Errorf("value %s (%v) is found while enumerating, but has not been cretaed", n, v) + t.Errorf("value %s (%v) is found while enumerating, but has not been created", n, v) } } diff --git a/windows/svc/mgr/config.go b/windows/svc/mgr/config.go index a6d3e8a88a..3c7ba08f58 100644 --- a/windows/svc/mgr/config.go +++ b/windows/svc/mgr/config.go @@ -63,7 +63,7 @@ func toStringSlice(ps *uint16) []string { return r } -// Config retrieves service s configuration paramteres. +// Config retrieves service s configuration parameters. func (s *Service) Config() (Config, error) { var p *windows.QUERY_SERVICE_CONFIG n := uint32(1024) diff --git a/windows/svc/mgr/recovery.go b/windows/svc/mgr/recovery.go index cdf880e13a..ef2a687840 100644 --- a/windows/svc/mgr/recovery.go +++ b/windows/svc/mgr/recovery.go @@ -137,7 +137,7 @@ func (s *Service) RecoveryCommand() (string, error) { // SetRecoveryActionsOnNonCrashFailures sets the failure actions flag. If the // flag is set to false, recovery actions will only be performed if the service // terminates without reporting a status of SERVICE_STOPPED. If the flag is set -// to true, recovery actions are also perfomed if the service stops with a +// to true, recovery actions are also performed if the service stops with a // nonzero exit code. func (s *Service) SetRecoveryActionsOnNonCrashFailures(flag bool) error { var setting windows.SERVICE_FAILURE_ACTIONS_FLAG @@ -151,7 +151,7 @@ func (s *Service) SetRecoveryActionsOnNonCrashFailures(flag bool) error { // actions flag. If the flag is set to false, recovery actions will only be // performed if the service terminates without reporting a status of // SERVICE_STOPPED. If the flag is set to true, recovery actions are also -// perfomed if the service stops with a nonzero exit code. +// performed if the service stops with a nonzero exit code. func (s *Service) RecoveryActionsOnNonCrashFailures() (bool, error) { b, err := s.queryServiceConfig2(windows.SERVICE_CONFIG_FAILURE_ACTIONS_FLAG) if err != nil { diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index b7703dfe15..1e686a4fd3 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -830,9 +830,9 @@ func FuzzComposeCommandLine(f *testing.F) { // If args[0] contains a space or control character, we must quote it // to avoid it being split into multiple arguments. // If args[0] already starts with a quote character, we have no way - // to indicate that that character is part of the literal argument. + // to indicate that character is part of the literal argument. // In either case, if the string already contains a quote character - // we must avoid misinterpriting that character as the end of the + // we must avoid misinterpreting that character as the end of the // quoted argument string. // // Unfortunately, ComposeCommandLine does not return an error, so we From 48aad76ed3ac439edae50adb78dbdbc46080878a Mon Sep 17 00:00:00 2001 From: Leo Antunes Date: Mon, 16 Sep 2024 08:39:39 +0000 Subject: [PATCH 19/23] linux: add tcp_cc_info and its related types Add the ability to retrieve congestion control information from a socket via TCP_CC_INFO. Fixes golang/go#68232 Change-Id: I2ea15928ec0e3192b670759bab4b659e62be553b GitHub-Last-Rev: b8b8c44f1f047fe6c60fae8adc695f2633dadd7c GitHub-Pull-Request: golang/sys#200 Reviewed-on: https://go-review.googlesource.com/c/sys/+/595676 LUCI-TryBot-Result: Go LUCI Reviewed-by: Carlos Amedee Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- unix/linux/types.go | 8 ++++++++ unix/syscall_linux.go | 42 ++++++++++++++++++++++++++++++++++++++++++ unix/ztypes_linux.go | 24 ++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/unix/linux/types.go b/unix/linux/types.go index 75acaec896..0ba570fe16 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -112,6 +112,7 @@ struct termios2 { #include #include #include +#include #include #include #include @@ -757,6 +758,12 @@ type Ucred C.struct_ucred type TCPInfo C.struct_tcp_info +type TCPVegasInfo C.struct_tcpvegas_info + +type TCPDCTCPInfo C.struct_tcp_dctcp_info + +type TCPBBRInfo C.struct_tcp_bbr_info + type CanFilter C.struct_can_filter type ifreq C.struct_ifreq @@ -798,6 +805,7 @@ const ( SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter SizeofUcred = C.sizeof_struct_ucred SizeofTCPInfo = C.sizeof_struct_tcp_info + SizeofTCPCCInfo = C.sizeof_union_tcp_cc_info SizeofCanFilter = C.sizeof_struct_can_filter SizeofTCPRepairOpt = C.sizeof_struct_tcp_repair_opt ) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 3f1d3d4cb2..c5bb17ae5e 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -1295,6 +1295,48 @@ func GetsockoptTCPInfo(fd, level, opt int) (*TCPInfo, error) { return &value, err } +// GetsockoptTCPCCVegasInfo returns algorithm specific congestion control information for a socket using the "vegas" +// algorithm. +// +// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option: +// +// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION) +func GetsockoptTCPCCVegasInfo(fd, level, opt int) (*TCPVegasInfo, error) { + var value [SizeofTCPCCInfo / 4]uint32 // ensure proper alignment + vallen := _Socklen(SizeofTCPCCInfo) + err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen) + out := (*TCPVegasInfo)(unsafe.Pointer(&value[0])) + return out, err +} + +// GetsockoptTCPCCDCTCPInfo returns algorithm specific congestion control information for a socket using the "dctp" +// algorithm. +// +// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option: +// +// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION) +func GetsockoptTCPCCDCTCPInfo(fd, level, opt int) (*TCPDCTCPInfo, error) { + var value [SizeofTCPCCInfo / 4]uint32 // ensure proper alignment + vallen := _Socklen(SizeofTCPCCInfo) + err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen) + out := (*TCPDCTCPInfo)(unsafe.Pointer(&value[0])) + return out, err +} + +// GetsockoptTCPCCBBRInfo returns algorithm specific congestion control information for a socket using the "bbr" +// algorithm. +// +// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option: +// +// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION) +func GetsockoptTCPCCBBRInfo(fd, level, opt int) (*TCPBBRInfo, error) { + var value [SizeofTCPCCInfo / 4]uint32 // ensure proper alignment + vallen := _Socklen(SizeofTCPCCInfo) + err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen) + out := (*TCPBBRInfo)(unsafe.Pointer(&value[0])) + return out, err +} + // GetsockoptString returns the string value of the socket option opt for the // socket associated with fd at the given socket level. func GetsockoptString(fd, level, opt int) (string, error) { diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 9f2550dc31..cabdee2407 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -516,6 +516,29 @@ type TCPInfo struct { Total_rto_time uint32 } +type TCPVegasInfo struct { + Enabled uint32 + Rttcnt uint32 + Rtt uint32 + Minrtt uint32 +} + +type TCPDCTCPInfo struct { + Enabled uint16 + Ce_state uint16 + Alpha uint32 + Ab_ecn uint32 + Ab_tot uint32 +} + +type TCPBBRInfo struct { + Bw_lo uint32 + Bw_hi uint32 + Min_rtt uint32 + Pacing_gain uint32 + Cwnd_gain uint32 +} + type CanFilter struct { Id uint32 Mask uint32 @@ -557,6 +580,7 @@ const ( SizeofICMPv6Filter = 0x20 SizeofUcred = 0xc SizeofTCPInfo = 0xf8 + SizeofTCPCCInfo = 0x14 SizeofCanFilter = 0x8 SizeofTCPRepairOpt = 0x8 ) From 981de40f5c9d8dc49087c2d351624288ee17b34c Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 24 Sep 2024 03:29:28 +0200 Subject: [PATCH 20/23] unix: use vDSO for getrandom() on linux With CL 614835 adding support in the runtime for calling into the getrandom() vDSO function, wire up x/sys/unix's Getrandom() function to it, so that callers can benefit from the increased speed and shared vDSO state with the runtime. Updates golang/go#69577. Change-Id: I17734409982c51bb984a6337f4ffa8f60414ebee Reviewed-on: https://go-review.googlesource.com/c/sys/+/615335 Reviewed-by: Michael Pratt Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI --- unix/syscall_linux.go | 21 ++++++++++++++++++++- unix/vgetrandom_linux.go | 12 ++++++++++++ unix/vgetrandom_unsupported.go | 11 +++++++++++ unix/zsyscall_linux.go | 17 ----------------- 4 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 unix/vgetrandom_linux.go create mode 100644 unix/vgetrandom_unsupported.go diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index c5bb17ae5e..f08abd434f 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -2001,7 +2001,26 @@ func Getpgrp() (pid int) { //sysnb Getpid() (pid int) //sysnb Getppid() (ppid int) //sys Getpriority(which int, who int) (prio int, err error) -//sys Getrandom(buf []byte, flags int) (n int, err error) + +func Getrandom(buf []byte, flags int) (n int, err error) { + vdsoRet, supported := vgetrandom(buf, uint32(flags)) + if supported { + if vdsoRet < 0 { + return 0, errnoErr(syscall.Errno(-vdsoRet)) + } + return vdsoRet, nil + } + var p *byte + if len(buf) > 0 { + p = &buf[0] + } + r, _, e := Syscall(SYS_GETRANDOM, uintptr(unsafe.Pointer(p)), uintptr(len(buf)), uintptr(flags)) + if e != 0 { + return 0, errnoErr(e) + } + return int(r), nil +} + //sysnb Getrusage(who int, rusage *Rusage) (err error) //sysnb Getsid(pid int) (sid int, err error) //sysnb Gettid() (tid int) diff --git a/unix/vgetrandom_linux.go b/unix/vgetrandom_linux.go new file mode 100644 index 0000000000..47cce9bbdc --- /dev/null +++ b/unix/vgetrandom_linux.go @@ -0,0 +1,12 @@ +// 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 linux && go1.24 + +package unix + +import _ "unsafe" + +//go:linkname vgetrandom runtime.vgetrandom +func vgetrandom(p []byte, flags uint32) (ret int, supported bool) diff --git a/unix/vgetrandom_unsupported.go b/unix/vgetrandom_unsupported.go new file mode 100644 index 0000000000..297e97bce9 --- /dev/null +++ b/unix/vgetrandom_unsupported.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 !linux || !go1.24 + +package unix + +func vgetrandom(p []byte, flags uint32) (ret int, supported bool) { + return -1, false +} diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index 1bc1a5adb2..af30da5578 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -971,23 +971,6 @@ func Getpriority(which int, who int) (prio int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Getrandom(buf []byte, flags int) (n int, err error) { - var _p0 unsafe.Pointer - if len(buf) > 0 { - _p0 = unsafe.Pointer(&buf[0]) - } else { - _p0 = unsafe.Pointer(&_zero) - } - r0, _, e1 := Syscall(SYS_GETRANDOM, uintptr(_p0), uintptr(len(buf)), uintptr(flags)) - n = int(r0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Getrusage(who int, rusage *Rusage) (err error) { _, _, e1 := RawSyscall(SYS_GETRUSAGE, uintptr(who), uintptr(unsafe.Pointer(rusage)), 0) if e1 != 0 { From e7397b9a65e3b9b49ff8a63a5156bbfe90df8786 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Fri, 27 Sep 2024 20:20:15 +0000 Subject: [PATCH 21/23] unix: update to Linux 6.11 Change-Id: I1cc777822da1b557e69634faade8e24d06c00ce8 GitHub-Last-Rev: d09238ecd0989901b5d92e7a0ae2556c6e441d27 GitHub-Pull-Request: golang/sys#218 Reviewed-on: https://go-review.googlesource.com/c/sys/+/613855 LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Tobias Klauser Reviewed-by: Michael Knyszek --- unix/linux/Dockerfile | 4 +-- unix/linux/mksysnum.go | 14 ++++++++ unix/syscall_linux_arm64.go | 2 ++ unix/syscall_linux_loong64.go | 2 ++ unix/syscall_linux_riscv64.go | 2 ++ unix/zerrors_linux.go | 13 +++++-- unix/zerrors_linux_386.go | 5 +++ unix/zerrors_linux_amd64.go | 5 +++ unix/zerrors_linux_arm.go | 5 +++ unix/zerrors_linux_arm64.go | 5 +++ unix/zerrors_linux_loong64.go | 5 +++ unix/zerrors_linux_mips.go | 5 +++ unix/zerrors_linux_mips64.go | 5 +++ unix/zerrors_linux_mips64le.go | 5 +++ unix/zerrors_linux_mipsle.go | 5 +++ unix/zerrors_linux_ppc.go | 5 +++ unix/zerrors_linux_ppc64.go | 5 +++ unix/zerrors_linux_ppc64le.go | 5 +++ unix/zerrors_linux_riscv64.go | 5 +++ unix/zerrors_linux_s390x.go | 5 +++ unix/zerrors_linux_sparc64.go | 5 +++ unix/zsysnum_linux_amd64.go | 1 + unix/zsysnum_linux_arm64.go | 2 +- unix/zsysnum_linux_loong64.go | 2 ++ unix/zsysnum_linux_riscv64.go | 2 +- unix/ztypes_linux.go | 64 ++++++++++++++++++---------------- 26 files changed, 147 insertions(+), 36 deletions(-) diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile index 3f36a1be34..0e533d89a7 100644 --- a/unix/linux/Dockerfile +++ b/unix/linux/Dockerfile @@ -15,8 +15,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ # Get the git sources. If not cached, this takes O(5 minutes). WORKDIR /git RUN git config --global advice.detachedHead false -# Linux Kernel: Released 14 July 2024 -RUN git clone --branch v6.10 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux +# Linux Kernel: Released 15 Sep 2024 +RUN git clone --branch v6.11 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux # GNU C library: Released 21 July 2024 RUN git clone --branch release/2.40/master --depth 1 https://sourceware.org/git/glibc.git diff --git a/unix/linux/mksysnum.go b/unix/linux/mksysnum.go index be425325f9..612b60e9b5 100644 --- a/unix/linux/mksysnum.go +++ b/unix/linux/mksysnum.go @@ -8,6 +8,7 @@ package main import ( "bufio" + "bytes" "fmt" "os" "os/exec" @@ -125,6 +126,19 @@ func main() { fmt.Fprintf(os.Stderr, "can't run %s", cc) os.Exit(1) } + + switch goarch { + case "riscv64", "loong64", "arm64": + // Kernel linux v6.11 removed some __NR_* macros that only + // existed on some architectures as an implementation detail. In + // order to keep backwards compatibility we add them back. + // + // See https://lkml.org/lkml/2024/8/5/1283. + if !bytes.Contains(cmd, []byte("#define __NR_arch_specific_syscall")) { + cmd = append(cmd, []byte("#define __NR_arch_specific_syscall 244\n")...) + } + } + s := bufio.NewScanner(strings.NewReader(string(cmd))) var offset, prev, asOffset int var nums syscallNums diff --git a/unix/syscall_linux_arm64.go b/unix/syscall_linux_arm64.go index cf2ee6c75e..745e5c7e6c 100644 --- a/unix/syscall_linux_arm64.go +++ b/unix/syscall_linux_arm64.go @@ -182,3 +182,5 @@ func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error } return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags) } + +const SYS_FSTATAT = SYS_NEWFSTATAT diff --git a/unix/syscall_linux_loong64.go b/unix/syscall_linux_loong64.go index 3d0e98451f..dd2262a407 100644 --- a/unix/syscall_linux_loong64.go +++ b/unix/syscall_linux_loong64.go @@ -214,3 +214,5 @@ func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error } return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags) } + +const SYS_FSTATAT = SYS_NEWFSTATAT diff --git a/unix/syscall_linux_riscv64.go b/unix/syscall_linux_riscv64.go index 6f5a288944..8cf3670bda 100644 --- a/unix/syscall_linux_riscv64.go +++ b/unix/syscall_linux_riscv64.go @@ -187,3 +187,5 @@ func RISCVHWProbe(pairs []RISCVHWProbePairs, set *CPUSet, flags uint) (err error } return riscvHWProbe(pairs, setSize, set, flags) } + +const SYS_FSTATAT = SYS_NEWFSTATAT diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index 01a70b2463..de3b462489 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -495,6 +495,7 @@ const ( BPF_F_TEST_REG_INVARIANTS = 0x80 BPF_F_TEST_RND_HI32 = 0x4 BPF_F_TEST_RUN_ON_CPU = 0x1 + BPF_F_TEST_SKB_CHECKSUM_COMPLETE = 0x4 BPF_F_TEST_STATE_FREQ = 0x8 BPF_F_TEST_XDP_LIVE_FRAMES = 0x2 BPF_F_XDP_DEV_BOUND_ONLY = 0x40 @@ -1922,6 +1923,7 @@ const ( MNT_EXPIRE = 0x4 MNT_FORCE = 0x1 MNT_ID_REQ_SIZE_VER0 = 0x18 + MNT_ID_REQ_SIZE_VER1 = 0x20 MODULE_INIT_COMPRESSED_FILE = 0x4 MODULE_INIT_IGNORE_MODVERSIONS = 0x1 MODULE_INIT_IGNORE_VERMAGIC = 0x2 @@ -2187,7 +2189,7 @@ const ( NFT_REG_SIZE = 0x10 NFT_REJECT_ICMPX_MAX = 0x3 NFT_RT_MAX = 0x4 - NFT_SECMARK_CTX_MAXLEN = 0x100 + NFT_SECMARK_CTX_MAXLEN = 0x1000 NFT_SET_MAXNAMELEN = 0x100 NFT_SOCKET_MAX = 0x3 NFT_TABLE_F_MASK = 0x7 @@ -2356,9 +2358,11 @@ const ( PERF_MEM_LVLNUM_IO = 0xa PERF_MEM_LVLNUM_L1 = 0x1 PERF_MEM_LVLNUM_L2 = 0x2 + PERF_MEM_LVLNUM_L2_MHB = 0x5 PERF_MEM_LVLNUM_L3 = 0x3 PERF_MEM_LVLNUM_L4 = 0x4 PERF_MEM_LVLNUM_LFB = 0xc + PERF_MEM_LVLNUM_MSC = 0x6 PERF_MEM_LVLNUM_NA = 0xf PERF_MEM_LVLNUM_PMEM = 0xe PERF_MEM_LVLNUM_RAM = 0xd @@ -2431,6 +2435,7 @@ const ( PRIO_PGRP = 0x1 PRIO_PROCESS = 0x0 PRIO_USER = 0x2 + PROCFS_IOCTL_MAGIC = 'f' PROC_SUPER_MAGIC = 0x9fa0 PROT_EXEC = 0x4 PROT_GROWSDOWN = 0x1000000 @@ -2933,11 +2938,12 @@ const ( RUSAGE_SELF = 0x0 RUSAGE_THREAD = 0x1 RWF_APPEND = 0x10 + RWF_ATOMIC = 0x40 RWF_DSYNC = 0x2 RWF_HIPRI = 0x1 RWF_NOAPPEND = 0x20 RWF_NOWAIT = 0x8 - RWF_SUPPORTED = 0x3f + RWF_SUPPORTED = 0x7f RWF_SYNC = 0x4 RWF_WRITE_LIFE_NOT_SET = 0x0 SCHED_BATCH = 0x3 @@ -3210,6 +3216,7 @@ const ( STATX_ATTR_MOUNT_ROOT = 0x2000 STATX_ATTR_NODUMP = 0x40 STATX_ATTR_VERITY = 0x100000 + STATX_ATTR_WRITE_ATOMIC = 0x400000 STATX_BASIC_STATS = 0x7ff STATX_BLOCKS = 0x400 STATX_BTIME = 0x800 @@ -3226,6 +3233,7 @@ const ( STATX_SUBVOL = 0x8000 STATX_TYPE = 0x1 STATX_UID = 0x8 + STATX_WRITE_ATOMIC = 0x10000 STATX__RESERVED = 0x80000000 SYNC_FILE_RANGE_WAIT_AFTER = 0x4 SYNC_FILE_RANGE_WAIT_BEFORE = 0x1 @@ -3624,6 +3632,7 @@ const ( XDP_UMEM_PGOFF_COMPLETION_RING = 0x180000000 XDP_UMEM_PGOFF_FILL_RING = 0x100000000 XDP_UMEM_REG = 0x4 + XDP_UMEM_TX_METADATA_LEN = 0x4 XDP_UMEM_TX_SW_CSUM = 0x2 XDP_UMEM_UNALIGNED_CHUNK_FLAG = 0x1 XDP_USE_NEED_WAKEUP = 0x8 diff --git a/unix/zerrors_linux_386.go b/unix/zerrors_linux_386.go index 684a5168da..8aa6d77c01 100644 --- a/unix/zerrors_linux_386.go +++ b/unix/zerrors_linux_386.go @@ -153,9 +153,14 @@ const ( NFDBITS = 0x20 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x8008b705 NS_GET_NSTYPE = 0xb703 NS_GET_OWNER_UID = 0xb704 NS_GET_PARENT = 0xb702 + NS_GET_PID_FROM_PIDNS = 0x8004b706 + NS_GET_PID_IN_PIDNS = 0x8004b708 + NS_GET_TGID_FROM_PIDNS = 0x8004b707 + NS_GET_TGID_IN_PIDNS = 0x8004b709 NS_GET_USERNS = 0xb701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_amd64.go b/unix/zerrors_linux_amd64.go index 61d74b592d..da428f4253 100644 --- a/unix/zerrors_linux_amd64.go +++ b/unix/zerrors_linux_amd64.go @@ -153,9 +153,14 @@ const ( NFDBITS = 0x40 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x8008b705 NS_GET_NSTYPE = 0xb703 NS_GET_OWNER_UID = 0xb704 NS_GET_PARENT = 0xb702 + NS_GET_PID_FROM_PIDNS = 0x8004b706 + NS_GET_PID_IN_PIDNS = 0x8004b708 + NS_GET_TGID_FROM_PIDNS = 0x8004b707 + NS_GET_TGID_IN_PIDNS = 0x8004b709 NS_GET_USERNS = 0xb701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_arm.go b/unix/zerrors_linux_arm.go index a28c9e3e89..bf45bfec78 100644 --- a/unix/zerrors_linux_arm.go +++ b/unix/zerrors_linux_arm.go @@ -150,9 +150,14 @@ const ( NFDBITS = 0x20 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x8008b705 NS_GET_NSTYPE = 0xb703 NS_GET_OWNER_UID = 0xb704 NS_GET_PARENT = 0xb702 + NS_GET_PID_FROM_PIDNS = 0x8004b706 + NS_GET_PID_IN_PIDNS = 0x8004b708 + NS_GET_TGID_FROM_PIDNS = 0x8004b707 + NS_GET_TGID_IN_PIDNS = 0x8004b709 NS_GET_USERNS = 0xb701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_arm64.go b/unix/zerrors_linux_arm64.go index ab5d1fe8ea..71c67162b7 100644 --- a/unix/zerrors_linux_arm64.go +++ b/unix/zerrors_linux_arm64.go @@ -154,9 +154,14 @@ const ( NFDBITS = 0x40 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x8008b705 NS_GET_NSTYPE = 0xb703 NS_GET_OWNER_UID = 0xb704 NS_GET_PARENT = 0xb702 + NS_GET_PID_FROM_PIDNS = 0x8004b706 + NS_GET_PID_IN_PIDNS = 0x8004b708 + NS_GET_TGID_FROM_PIDNS = 0x8004b707 + NS_GET_TGID_IN_PIDNS = 0x8004b709 NS_GET_USERNS = 0xb701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_loong64.go b/unix/zerrors_linux_loong64.go index c523090e7c..9476628fa0 100644 --- a/unix/zerrors_linux_loong64.go +++ b/unix/zerrors_linux_loong64.go @@ -154,9 +154,14 @@ const ( NFDBITS = 0x40 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x8008b705 NS_GET_NSTYPE = 0xb703 NS_GET_OWNER_UID = 0xb704 NS_GET_PARENT = 0xb702 + NS_GET_PID_FROM_PIDNS = 0x8004b706 + NS_GET_PID_IN_PIDNS = 0x8004b708 + NS_GET_TGID_FROM_PIDNS = 0x8004b707 + NS_GET_TGID_IN_PIDNS = 0x8004b709 NS_GET_USERNS = 0xb701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_mips.go b/unix/zerrors_linux_mips.go index 01e6ea7804..b9e85f3cf0 100644 --- a/unix/zerrors_linux_mips.go +++ b/unix/zerrors_linux_mips.go @@ -150,9 +150,14 @@ const ( NFDBITS = 0x20 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x4008b705 NS_GET_NSTYPE = 0x2000b703 NS_GET_OWNER_UID = 0x2000b704 NS_GET_PARENT = 0x2000b702 + NS_GET_PID_FROM_PIDNS = 0x4004b706 + NS_GET_PID_IN_PIDNS = 0x4004b708 + NS_GET_TGID_FROM_PIDNS = 0x4004b707 + NS_GET_TGID_IN_PIDNS = 0x4004b709 NS_GET_USERNS = 0x2000b701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_mips64.go b/unix/zerrors_linux_mips64.go index 7aa610b1e7..a48b68a764 100644 --- a/unix/zerrors_linux_mips64.go +++ b/unix/zerrors_linux_mips64.go @@ -150,9 +150,14 @@ const ( NFDBITS = 0x40 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x4008b705 NS_GET_NSTYPE = 0x2000b703 NS_GET_OWNER_UID = 0x2000b704 NS_GET_PARENT = 0x2000b702 + NS_GET_PID_FROM_PIDNS = 0x4004b706 + NS_GET_PID_IN_PIDNS = 0x4004b708 + NS_GET_TGID_FROM_PIDNS = 0x4004b707 + NS_GET_TGID_IN_PIDNS = 0x4004b709 NS_GET_USERNS = 0x2000b701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_mips64le.go b/unix/zerrors_linux_mips64le.go index 92af771b44..ea00e8522a 100644 --- a/unix/zerrors_linux_mips64le.go +++ b/unix/zerrors_linux_mips64le.go @@ -150,9 +150,14 @@ const ( NFDBITS = 0x40 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x4008b705 NS_GET_NSTYPE = 0x2000b703 NS_GET_OWNER_UID = 0x2000b704 NS_GET_PARENT = 0x2000b702 + NS_GET_PID_FROM_PIDNS = 0x4004b706 + NS_GET_PID_IN_PIDNS = 0x4004b708 + NS_GET_TGID_FROM_PIDNS = 0x4004b707 + NS_GET_TGID_IN_PIDNS = 0x4004b709 NS_GET_USERNS = 0x2000b701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_mipsle.go b/unix/zerrors_linux_mipsle.go index b27ef5e6f1..91c6468717 100644 --- a/unix/zerrors_linux_mipsle.go +++ b/unix/zerrors_linux_mipsle.go @@ -150,9 +150,14 @@ const ( NFDBITS = 0x20 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x4008b705 NS_GET_NSTYPE = 0x2000b703 NS_GET_OWNER_UID = 0x2000b704 NS_GET_PARENT = 0x2000b702 + NS_GET_PID_FROM_PIDNS = 0x4004b706 + NS_GET_PID_IN_PIDNS = 0x4004b708 + NS_GET_TGID_FROM_PIDNS = 0x4004b707 + NS_GET_TGID_IN_PIDNS = 0x4004b709 NS_GET_USERNS = 0x2000b701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_ppc.go b/unix/zerrors_linux_ppc.go index 237a2cefb3..8cbf38d639 100644 --- a/unix/zerrors_linux_ppc.go +++ b/unix/zerrors_linux_ppc.go @@ -152,9 +152,14 @@ const ( NL3 = 0x300 NLDLY = 0x300 NOFLSH = 0x80000000 + NS_GET_MNTNS_ID = 0x4008b705 NS_GET_NSTYPE = 0x2000b703 NS_GET_OWNER_UID = 0x2000b704 NS_GET_PARENT = 0x2000b702 + NS_GET_PID_FROM_PIDNS = 0x4004b706 + NS_GET_PID_IN_PIDNS = 0x4004b708 + NS_GET_TGID_FROM_PIDNS = 0x4004b707 + NS_GET_TGID_IN_PIDNS = 0x4004b709 NS_GET_USERNS = 0x2000b701 OLCUC = 0x4 ONLCR = 0x2 diff --git a/unix/zerrors_linux_ppc64.go b/unix/zerrors_linux_ppc64.go index 4a5c555a36..a2df734191 100644 --- a/unix/zerrors_linux_ppc64.go +++ b/unix/zerrors_linux_ppc64.go @@ -152,9 +152,14 @@ const ( NL3 = 0x300 NLDLY = 0x300 NOFLSH = 0x80000000 + NS_GET_MNTNS_ID = 0x4008b705 NS_GET_NSTYPE = 0x2000b703 NS_GET_OWNER_UID = 0x2000b704 NS_GET_PARENT = 0x2000b702 + NS_GET_PID_FROM_PIDNS = 0x4004b706 + NS_GET_PID_IN_PIDNS = 0x4004b708 + NS_GET_TGID_FROM_PIDNS = 0x4004b707 + NS_GET_TGID_IN_PIDNS = 0x4004b709 NS_GET_USERNS = 0x2000b701 OLCUC = 0x4 ONLCR = 0x2 diff --git a/unix/zerrors_linux_ppc64le.go b/unix/zerrors_linux_ppc64le.go index a02fb49a5f..2479137923 100644 --- a/unix/zerrors_linux_ppc64le.go +++ b/unix/zerrors_linux_ppc64le.go @@ -152,9 +152,14 @@ const ( NL3 = 0x300 NLDLY = 0x300 NOFLSH = 0x80000000 + NS_GET_MNTNS_ID = 0x4008b705 NS_GET_NSTYPE = 0x2000b703 NS_GET_OWNER_UID = 0x2000b704 NS_GET_PARENT = 0x2000b702 + NS_GET_PID_FROM_PIDNS = 0x4004b706 + NS_GET_PID_IN_PIDNS = 0x4004b708 + NS_GET_TGID_FROM_PIDNS = 0x4004b707 + NS_GET_TGID_IN_PIDNS = 0x4004b709 NS_GET_USERNS = 0x2000b701 OLCUC = 0x4 ONLCR = 0x2 diff --git a/unix/zerrors_linux_riscv64.go b/unix/zerrors_linux_riscv64.go index e26a7c61b2..d265f146ee 100644 --- a/unix/zerrors_linux_riscv64.go +++ b/unix/zerrors_linux_riscv64.go @@ -150,9 +150,14 @@ const ( NFDBITS = 0x40 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x8008b705 NS_GET_NSTYPE = 0xb703 NS_GET_OWNER_UID = 0xb704 NS_GET_PARENT = 0xb702 + NS_GET_PID_FROM_PIDNS = 0x8004b706 + NS_GET_PID_IN_PIDNS = 0x8004b708 + NS_GET_TGID_FROM_PIDNS = 0x8004b707 + NS_GET_TGID_IN_PIDNS = 0x8004b709 NS_GET_USERNS = 0xb701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_s390x.go b/unix/zerrors_linux_s390x.go index c48f7c2103..3f2d644396 100644 --- a/unix/zerrors_linux_s390x.go +++ b/unix/zerrors_linux_s390x.go @@ -150,9 +150,14 @@ const ( NFDBITS = 0x40 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x8008b705 NS_GET_NSTYPE = 0xb703 NS_GET_OWNER_UID = 0xb704 NS_GET_PARENT = 0xb702 + NS_GET_PID_FROM_PIDNS = 0x8004b706 + NS_GET_PID_IN_PIDNS = 0x8004b708 + NS_GET_TGID_FROM_PIDNS = 0x8004b707 + NS_GET_TGID_IN_PIDNS = 0x8004b709 NS_GET_USERNS = 0xb701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zerrors_linux_sparc64.go b/unix/zerrors_linux_sparc64.go index ad4b9aace7..5d8b727a1c 100644 --- a/unix/zerrors_linux_sparc64.go +++ b/unix/zerrors_linux_sparc64.go @@ -155,9 +155,14 @@ const ( NFDBITS = 0x40 NLDLY = 0x100 NOFLSH = 0x80 + NS_GET_MNTNS_ID = 0x4008b705 NS_GET_NSTYPE = 0x2000b703 NS_GET_OWNER_UID = 0x2000b704 NS_GET_PARENT = 0x2000b702 + NS_GET_PID_FROM_PIDNS = 0x4004b706 + NS_GET_PID_IN_PIDNS = 0x4004b708 + NS_GET_TGID_FROM_PIDNS = 0x4004b707 + NS_GET_TGID_IN_PIDNS = 0x4004b709 NS_GET_USERNS = 0x2000b701 OLCUC = 0x2 ONLCR = 0x4 diff --git a/unix/zsysnum_linux_amd64.go b/unix/zsysnum_linux_amd64.go index d3e38f681a..f485dbf456 100644 --- a/unix/zsysnum_linux_amd64.go +++ b/unix/zsysnum_linux_amd64.go @@ -341,6 +341,7 @@ const ( SYS_STATX = 332 SYS_IO_PGETEVENTS = 333 SYS_RSEQ = 334 + SYS_URETPROBE = 335 SYS_PIDFD_SEND_SIGNAL = 424 SYS_IO_URING_SETUP = 425 SYS_IO_URING_ENTER = 426 diff --git a/unix/zsysnum_linux_arm64.go b/unix/zsysnum_linux_arm64.go index 6c778c2327..1893e2fe88 100644 --- a/unix/zsysnum_linux_arm64.go +++ b/unix/zsysnum_linux_arm64.go @@ -85,7 +85,7 @@ const ( SYS_SPLICE = 76 SYS_TEE = 77 SYS_READLINKAT = 78 - SYS_FSTATAT = 79 + SYS_NEWFSTATAT = 79 SYS_FSTAT = 80 SYS_SYNC = 81 SYS_FSYNC = 82 diff --git a/unix/zsysnum_linux_loong64.go b/unix/zsysnum_linux_loong64.go index 37281cf51a..16a4017da0 100644 --- a/unix/zsysnum_linux_loong64.go +++ b/unix/zsysnum_linux_loong64.go @@ -84,6 +84,8 @@ const ( SYS_SPLICE = 76 SYS_TEE = 77 SYS_READLINKAT = 78 + SYS_NEWFSTATAT = 79 + SYS_FSTAT = 80 SYS_SYNC = 81 SYS_FSYNC = 82 SYS_FDATASYNC = 83 diff --git a/unix/zsysnum_linux_riscv64.go b/unix/zsysnum_linux_riscv64.go index 9889f6a559..a5459e766f 100644 --- a/unix/zsysnum_linux_riscv64.go +++ b/unix/zsysnum_linux_riscv64.go @@ -84,7 +84,7 @@ const ( SYS_SPLICE = 76 SYS_TEE = 77 SYS_READLINKAT = 78 - SYS_FSTATAT = 79 + SYS_NEWFSTATAT = 79 SYS_FSTAT = 80 SYS_SYNC = 81 SYS_FSYNC = 82 diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index cabdee2407..3a69e45496 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -87,31 +87,35 @@ type StatxTimestamp struct { } type Statx_t struct { - Mask uint32 - Blksize uint32 - Attributes uint64 - Nlink uint32 - Uid uint32 - Gid uint32 - Mode uint16 - _ [1]uint16 - Ino uint64 - Size uint64 - Blocks uint64 - Attributes_mask uint64 - Atime StatxTimestamp - Btime StatxTimestamp - Ctime StatxTimestamp - Mtime StatxTimestamp - Rdev_major uint32 - Rdev_minor uint32 - Dev_major uint32 - Dev_minor uint32 - Mnt_id uint64 - Dio_mem_align uint32 - Dio_offset_align uint32 - Subvol uint64 - _ [11]uint64 + Mask uint32 + Blksize uint32 + Attributes uint64 + Nlink uint32 + Uid uint32 + Gid uint32 + Mode uint16 + _ [1]uint16 + Ino uint64 + Size uint64 + Blocks uint64 + Attributes_mask uint64 + Atime StatxTimestamp + Btime StatxTimestamp + Ctime StatxTimestamp + Mtime StatxTimestamp + Rdev_major uint32 + Rdev_minor uint32 + Dev_major uint32 + Dev_minor uint32 + Mnt_id uint64 + Dio_mem_align uint32 + Dio_offset_align uint32 + Subvol uint64 + Atomic_write_unit_min uint32 + Atomic_write_unit_max uint32 + Atomic_write_segments_max uint32 + _ [1]uint32 + _ [9]uint64 } type Fsid struct { @@ -3790,7 +3794,7 @@ const ( ETHTOOL_MSG_PSE_GET = 0x24 ETHTOOL_MSG_PSE_SET = 0x25 ETHTOOL_MSG_RSS_GET = 0x26 - ETHTOOL_MSG_USER_MAX = 0x2b + ETHTOOL_MSG_USER_MAX = 0x2c ETHTOOL_MSG_KERNEL_NONE = 0x0 ETHTOOL_MSG_STRSET_GET_REPLY = 0x1 ETHTOOL_MSG_LINKINFO_GET_REPLY = 0x2 @@ -3830,7 +3834,7 @@ const ( ETHTOOL_MSG_MODULE_NTF = 0x24 ETHTOOL_MSG_PSE_GET_REPLY = 0x25 ETHTOOL_MSG_RSS_GET_REPLY = 0x26 - ETHTOOL_MSG_KERNEL_MAX = 0x2b + ETHTOOL_MSG_KERNEL_MAX = 0x2c ETHTOOL_FLAG_COMPACT_BITSETS = 0x1 ETHTOOL_FLAG_OMIT_REPLY = 0x2 ETHTOOL_FLAG_STATS = 0x4 @@ -3975,7 +3979,7 @@ const ( ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL = 0x17 ETHTOOL_A_COALESCE_USE_CQE_MODE_TX = 0x18 ETHTOOL_A_COALESCE_USE_CQE_MODE_RX = 0x19 - ETHTOOL_A_COALESCE_MAX = 0x1c + ETHTOOL_A_COALESCE_MAX = 0x1e ETHTOOL_A_PAUSE_UNSPEC = 0x0 ETHTOOL_A_PAUSE_HEADER = 0x1 ETHTOOL_A_PAUSE_AUTONEG = 0x2 @@ -4633,7 +4637,7 @@ const ( NL80211_ATTR_MAC_HINT = 0xc8 NL80211_ATTR_MAC_MASK = 0xd7 NL80211_ATTR_MAX_AP_ASSOC_STA = 0xca - NL80211_ATTR_MAX = 0x14a + NL80211_ATTR_MAX = 0x14c NL80211_ATTR_MAX_CRIT_PROT_DURATION = 0xb4 NL80211_ATTR_MAX_CSA_COUNTERS = 0xce NL80211_ATTR_MAX_MATCH_SETS = 0x85 @@ -5237,7 +5241,7 @@ const ( NL80211_FREQUENCY_ATTR_GO_CONCURRENT = 0xf NL80211_FREQUENCY_ATTR_INDOOR_ONLY = 0xe NL80211_FREQUENCY_ATTR_IR_CONCURRENT = 0xf - NL80211_FREQUENCY_ATTR_MAX = 0x20 + NL80211_FREQUENCY_ATTR_MAX = 0x21 NL80211_FREQUENCY_ATTR_MAX_TX_POWER = 0x6 NL80211_FREQUENCY_ATTR_NO_10MHZ = 0x11 NL80211_FREQUENCY_ATTR_NO_160MHZ = 0xc From cbf0eb65e7bacca61a408b25429879f49c878a0b Mon Sep 17 00:00:00 2001 From: John Troy Date: Fri, 27 Sep 2024 19:29:44 +0000 Subject: [PATCH 22/23] unix: fix grep syntax to work on non-GNU greps CL 432835 changed two grep commands in unix/mkerrors.sh in such a way that is incompatible with AIX's grep, which, unlike GNU grep, does not support extended regular expressions without the -E flag. The intent of this PR is to restore the egrep behavior by invoking grep as grep -E. My assumption is that GNU grep is not meant to be a requirement to run mkerrors.sh, and given that, grep -E looks like the most cross-platform approach. Example of current (incorrect) behavior on AIX: bash-5.2$ printf 'SIGHUP\nSIGMAX64\nSIGTERM' | grep -v 'SIGSTKSIZE\|SIGSTKSZ\|SIGRT\|SIGMAX64' SIGHUP SIGMAX64 SIGTERM Behavior before CL 432835: bash-5.2$ printf 'SIGHUP\nSIGMAX64\nSIGTERM' | egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' SIGHUP SIGTERM Behavior of proposed change: bash-5.2$ printf 'SIGHUP\nSIGMAX64\nSIGTERM' | grep -E -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' SIGHUP SIGTERM OpenBSD's grep behaves the same as AIX for the above commands, which is why I cast this as GNU vs. non-GNU. I haven't tested any other implementations. Fixes golang/go#69365 Change-Id: I009353ee630463475a5c131d019f59c5e69efd34 GitHub-Last-Rev: e1166046e1f6d97d0efe28f96e692f2df790be6f GitHub-Pull-Request: golang/sys#217 Reviewed-on: https://go-review.googlesource.com/c/sys/+/615755 Reviewed-by: Michael Knyszek Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- unix/mkerrors.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index e14b766a32..ac54ecaba0 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -656,7 +656,7 @@ errors=$( signals=$( echo '#include ' | $CC -x c - -E -dM $ccflags | awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | - grep -v 'SIGSTKSIZE\|SIGSTKSZ\|SIGRT\|SIGMAX64' | + grep -E -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | sort ) @@ -666,7 +666,7 @@ echo '#include ' | $CC -x c - -E -dM $ccflags | sort >_error.grep echo '#include ' | $CC -x c - -E -dM $ccflags | awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | - grep -v 'SIGSTKSIZE\|SIGSTKSZ\|SIGRT\|SIGMAX64' | + grep -E -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | sort >_signal.grep echo '// mkerrors.sh' "$@" From 23b0dabe630b463b28ffc2871505befb3c5d3b4b Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Mon, 30 Sep 2024 17:01:15 +0000 Subject: [PATCH 23/23] unix: mark vgetrandom as non-escaping For golang/go#69577 Change-Id: Id1942d252c813126aa2f110e3f426714db73b9c7 GitHub-Last-Rev: 10e6a30b78d5945a8a0bdb2aa732d653eb08c1ee GitHub-Pull-Request: golang/sys#220 Reviewed-on: https://go-review.googlesource.com/c/sys/+/616795 Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek Reviewed-by: Jason Donenfeld --- unix/vgetrandom_linux.go | 1 + 1 file changed, 1 insertion(+) diff --git a/unix/vgetrandom_linux.go b/unix/vgetrandom_linux.go index 47cce9bbdc..07ac8e09d1 100644 --- a/unix/vgetrandom_linux.go +++ b/unix/vgetrandom_linux.go @@ -9,4 +9,5 @@ package unix import _ "unsafe" //go:linkname vgetrandom runtime.vgetrandom +//go:noescape func vgetrandom(p []byte, flags uint32) (ret int, supported bool)