From 1c14dcadc3ab57365f78d5cec67223a88a720479 Mon Sep 17 00:00:00 2001 From: Nahum Shalman Date: Thu, 2 Jan 2025 18:07:06 +0000 Subject: [PATCH 01/14] unix: add GetPeerUcred and UcredGet for solaris Change-Id: I74ba119fb729ef46899de04c686115f960975bb3 Reviewed-on: https://go-review.googlesource.com/c/sys/+/639755 LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor Reviewed-by: Michael Pratt Reviewed-by: Ian Lance Taylor Reviewed-by: Matt Layher --- unix/syscall_solaris.go | 87 +++++++++++++++++++++++++ unix/syscall_solaris_test.go | 64 ++++++++++++++++++ unix/zsyscall_solaris_amd64.go | 114 +++++++++++++++++++++++++++++++++ 3 files changed, 265 insertions(+) diff --git a/unix/syscall_solaris.go b/unix/syscall_solaris.go index 21974af064..abc3955477 100644 --- a/unix/syscall_solaris.go +++ b/unix/syscall_solaris.go @@ -1102,3 +1102,90 @@ func (s *Strioctl) SetInt(i int) { func IoctlSetStrioctlRetInt(fd int, req int, s *Strioctl) (int, error) { return ioctlPtrRet(fd, req, unsafe.Pointer(s)) } + +// Ucred Helpers +// See ucred(3c) and getpeerucred(3c) + +//sys getpeerucred(fd uintptr, ucred *uintptr) (err error) +//sys ucredFree(ucred uintptr) = ucred_free +//sys ucredGet(pid int) (ucred uintptr, err error) = ucred_get +//sys ucredGeteuid(ucred uintptr) (uid int) = ucred_geteuid +//sys ucredGetegid(ucred uintptr) (gid int) = ucred_getegid +//sys ucredGetruid(ucred uintptr) (uid int) = ucred_getruid +//sys ucredGetrgid(ucred uintptr) (gid int) = ucred_getrgid +//sys ucredGetsuid(ucred uintptr) (uid int) = ucred_getsuid +//sys ucredGetsgid(ucred uintptr) (gid int) = ucred_getsgid +//sys ucredGetpid(ucred uintptr) (pid int) = ucred_getpid + +// Ucred is an opaque struct that holds user credentials. +type Ucred struct { + ucred uintptr +} + +// We need to ensure that ucredFree is called on the underlying ucred +// when the Ucred is garbage collected. +func ucredFinalizer(u *Ucred) { + ucredFree(u.ucred) +} + +func GetPeerUcred(fd uintptr) (*Ucred, error) { + var ucred uintptr + err := getpeerucred(fd, &ucred) + if err != nil { + return nil, err + } + result := &Ucred{ + ucred: ucred, + } + // set the finalizer on the result so that the ucred will be freed + runtime.SetFinalizer(result, ucredFinalizer) + return result, nil +} + +func UcredGet(pid int) (*Ucred, error) { + ucred, err := ucredGet(pid) + if err != nil { + return nil, err + } + result := &Ucred{ + ucred: ucred, + } + // set the finalizer on the result so that the ucred will be freed + runtime.SetFinalizer(result, ucredFinalizer) + return result, nil +} + +func (u *Ucred) Geteuid() int { + defer runtime.KeepAlive(u) + return ucredGeteuid(u.ucred) +} + +func (u *Ucred) Getruid() int { + defer runtime.KeepAlive(u) + return ucredGetruid(u.ucred) +} + +func (u *Ucred) Getsuid() int { + defer runtime.KeepAlive(u) + return ucredGetsuid(u.ucred) +} + +func (u *Ucred) Getegid() int { + defer runtime.KeepAlive(u) + return ucredGetegid(u.ucred) +} + +func (u *Ucred) Getrgid() int { + defer runtime.KeepAlive(u) + return ucredGetrgid(u.ucred) +} + +func (u *Ucred) Getsgid() int { + defer runtime.KeepAlive(u) + return ucredGetsgid(u.ucred) +} + +func (u *Ucred) Getpid() int { + defer runtime.KeepAlive(u) + return ucredGetpid(u.ucred) +} diff --git a/unix/syscall_solaris_test.go b/unix/syscall_solaris_test.go index 738733b21f..a687d85947 100644 --- a/unix/syscall_solaris_test.go +++ b/unix/syscall_solaris_test.go @@ -8,6 +8,7 @@ package unix_test import ( "fmt" + "net" "os" "os/exec" "path/filepath" @@ -420,3 +421,66 @@ func TestLifreqGetMTU(t *testing.T) { } } } + +func TestUcredGet(t *testing.T) { + euid := unix.Geteuid() + creds, err := unix.UcredGet(unix.Getpid()) + if err != nil { + t.Fatalf("unix.UcredGet failed: %v", err) + } + if euid != creds.Geteuid() { + t.Fatalf("mismatched euid") + } +} + +func TestGetPeerUcred(t *testing.T) { + d := t.TempDir() + path := filepath.Join(d, "foo.sock") + sock, err := net.Listen("unix", path) + if err != nil { + t.Fatalf("net.Listen: %v", err) + } + defer sock.Close() + + c1, err := net.Dial("unix", path) + if err != nil { + t.Error(err) + return + } + defer c1.Close() + + c2, err := sock.Accept() + if err != nil { + t.Fatalf("Accept: %v", err) + } + defer c2.Close() + + switch unixconn := c2.(type) { + case *net.UnixConn: + raw, err := unixconn.SyscallConn() + if err != nil { + t.Fatalf("SyscallConn failed: %v", err) + } + + var creds *unix.Ucred + cerr := raw.Control(func(fd uintptr) { + creds, err = unix.GetPeerUcred(fd) + if err != nil { + err = fmt.Errorf("unix.GetPeerUcred: %w", err) + return + } + }) + if cerr != nil { + t.Fatalf("raw.Control failed: %v", err) + } + if creds == nil { + t.Fatalf("Got a nil Ucred response") + } + euid := unix.Geteuid() + if euid != creds.Geteuid() { + t.Fatalf("mismatched euid") + } + default: + t.Fatalf("Somehow didn't get a UnixConn") + } +} diff --git a/unix/zsyscall_solaris_amd64.go b/unix/zsyscall_solaris_amd64.go index 829b87feb8..c6545413c4 100644 --- a/unix/zsyscall_solaris_amd64.go +++ b/unix/zsyscall_solaris_amd64.go @@ -141,6 +141,16 @@ import ( //go:cgo_import_dynamic libc_getpeername getpeername "libsocket.so" //go:cgo_import_dynamic libc_setsockopt setsockopt "libsocket.so" //go:cgo_import_dynamic libc_recvfrom recvfrom "libsocket.so" +//go:cgo_import_dynamic libc_getpeerucred getpeerucred "libc.so" +//go:cgo_import_dynamic libc_ucred_get ucred_get "libc.so" +//go:cgo_import_dynamic libc_ucred_geteuid ucred_geteuid "libc.so" +//go:cgo_import_dynamic libc_ucred_getegid ucred_getegid "libc.so" +//go:cgo_import_dynamic libc_ucred_getruid ucred_getruid "libc.so" +//go:cgo_import_dynamic libc_ucred_getrgid ucred_getrgid "libc.so" +//go:cgo_import_dynamic libc_ucred_getsuid ucred_getsuid "libc.so" +//go:cgo_import_dynamic libc_ucred_getsgid ucred_getsgid "libc.so" +//go:cgo_import_dynamic libc_ucred_getpid ucred_getpid "libc.so" +//go:cgo_import_dynamic libc_ucred_free ucred_free "libc.so" //go:cgo_import_dynamic libc_port_create port_create "libc.so" //go:cgo_import_dynamic libc_port_associate port_associate "libc.so" //go:cgo_import_dynamic libc_port_dissociate port_dissociate "libc.so" @@ -280,6 +290,16 @@ import ( //go:linkname procgetpeername libc_getpeername //go:linkname procsetsockopt libc_setsockopt //go:linkname procrecvfrom libc_recvfrom +//go:linkname procgetpeerucred libc_getpeerucred +//go:linkname procucred_get libc_ucred_get +//go:linkname procucred_geteuid libc_ucred_geteuid +//go:linkname procucred_getegid libc_ucred_getegid +//go:linkname procucred_getruid libc_ucred_getruid +//go:linkname procucred_getrgid libc_ucred_getrgid +//go:linkname procucred_getsuid libc_ucred_getsuid +//go:linkname procucred_getsgid libc_ucred_getsgid +//go:linkname procucred_getpid libc_ucred_getpid +//go:linkname procucred_free libc_ucred_free //go:linkname procport_create libc_port_create //go:linkname procport_associate libc_port_associate //go:linkname procport_dissociate libc_port_dissociate @@ -420,6 +440,16 @@ var ( procgetpeername, procsetsockopt, procrecvfrom, + procgetpeerucred, + procucred_get, + procucred_geteuid, + procucred_getegid, + procucred_getruid, + procucred_getrgid, + procucred_getsuid, + procucred_getsgid, + procucred_getpid, + procucred_free, procport_create, procport_associate, procport_dissociate, @@ -2029,6 +2059,90 @@ func recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Sockl // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func getpeerucred(fd uintptr, ucred *uintptr) (err error) { + _, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procgetpeerucred)), 2, uintptr(fd), uintptr(unsafe.Pointer(ucred)), 0, 0, 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGet(pid int) (ucred uintptr, err error) { + r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procucred_get)), 1, uintptr(pid), 0, 0, 0, 0, 0) + ucred = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGeteuid(ucred uintptr) (uid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_geteuid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetegid(ucred uintptr) (gid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getegid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetruid(ucred uintptr) (uid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getruid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetrgid(ucred uintptr) (gid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getrgid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetsuid(ucred uintptr) (uid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getsuid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + uid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetsgid(ucred uintptr) (gid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getsgid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + gid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredGetpid(ucred uintptr) (pid int) { + r0, _, _ := sysvicall6(uintptr(unsafe.Pointer(&procucred_getpid)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + pid = int(r0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func ucredFree(ucred uintptr) { + sysvicall6(uintptr(unsafe.Pointer(&procucred_free)), 1, uintptr(ucred), 0, 0, 0, 0, 0) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func port_create() (n int, err error) { r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procport_create)), 0, 0, 0, 0, 0, 0, 0) n = int(r0) From c75621413d5e9378521df26cd38206af2f9b9d1a Mon Sep 17 00:00:00 2001 From: Grigorii Khvatskii Date: Wed, 8 Jan 2025 17:40:25 +0000 Subject: [PATCH 02/14] cpu: add support for AVX-VNNI and IFMA detection Added detection for x86 AVX-VNNI (VEX-coded Vector Neural Network Instructions) and AVX-IFMA (VEX-coded Integer Fused Multiply Add), including both the base VNNI set and the Int8 extention. Fixes golang/go#71142 Change-Id: I9e8d18b2e8bf81d5d4313a4a47fdf731fb3d44dd GitHub-Last-Rev: 32ea443fc247f1b6e957d2b27a44909c620d2fb2 GitHub-Pull-Request: golang/sys#242 Reviewed-on: https://go-review.googlesource.com/c/sys/+/641155 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- cpu/cpu.go | 3 +++ cpu/cpu_test.go | 34 ++++++++++++++++++++++++++++++++++ cpu/cpu_x86.go | 21 +++++++++++++++++---- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/cpu/cpu.go b/cpu/cpu.go index 02609d5b21..9c105f23af 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -72,6 +72,9 @@ var X86 struct { HasSSSE3 bool // Supplemental streaming SIMD extension 3 HasSSE41 bool // Streaming SIMD extension 4 and 4.1 HasSSE42 bool // Streaming SIMD extension 4 and 4.2 + HasAVXIFMA bool // Advanced vector extension Integer Fused Multiply Add + HasAVXVNNI bool // Advanced vector extension Vector Neural Network Instructions + HasAVXVNNIInt8 bool // Advanced vector extension Vector Neural Network Int8 instructions _ CacheLinePad } diff --git a/cpu/cpu_test.go b/cpu/cpu_test.go index 7a9bac7e5d..dd493ece8c 100644 --- a/cpu/cpu_test.go +++ b/cpu/cpu_test.go @@ -41,6 +41,40 @@ func TestAVX512HasAVX2AndAVX(t *testing.T) { } } +func TestAVX512BF16HasAVX512(t *testing.T) { + if runtime.GOARCH == "amd64" { + if cpu.X86.HasAVX512BF16 && !cpu.X86.HasAVX512 { + t.Fatal("HasAVX512 expected true, got false") + } + } +} + +func TestAVXVNNIHasAVX(t *testing.T) { + if cpu.X86.HasAVXVNNI && !cpu.X86.HasAVX { + t.Fatal("HasAVX expected true, got false") + } +} + +func TestAVXIFMAHasAVXVNNIAndAVX(t *testing.T) { + if cpu.X86.HasAVXIFMA && !cpu.X86.HasAVX { + t.Fatal("HasAVX expected true, got false") + } + + if cpu.X86.HasAVXIFMA && !cpu.X86.HasAVXVNNI { + t.Fatal("HasAVXVNNI expected true, got false") + } +} + +func TestAVXVNNIInt8HasAVXVNNIAndAVX(t *testing.T) { + if cpu.X86.HasAVXVNNIInt8 && !cpu.X86.HasAVXVNNI { + t.Fatal("HasAVXVNNI expected true, got false") + } + + if cpu.X86.HasAVXVNNIInt8 && !cpu.X86.HasAVX { + t.Fatal("HasAVX expected true, got false") + } +} + func TestARM64minimalFeatures(t *testing.T) { if runtime.GOARCH != "arm64" || runtime.GOOS == "ios" { return diff --git a/cpu/cpu_x86.go b/cpu/cpu_x86.go index 600a680786..1e642f3304 100644 --- a/cpu/cpu_x86.go +++ b/cpu/cpu_x86.go @@ -53,6 +53,9 @@ func initOptions() { {Name: "sse41", Feature: &X86.HasSSE41}, {Name: "sse42", Feature: &X86.HasSSE42}, {Name: "ssse3", Feature: &X86.HasSSSE3}, + {Name: "avxifma", Feature: &X86.HasAVXIFMA}, + {Name: "avxvnni", Feature: &X86.HasAVXVNNI}, + {Name: "avxvnniint8", Feature: &X86.HasAVXVNNIInt8}, // These capabilities should always be enabled on amd64: {Name: "sse2", Feature: &X86.HasSSE2, Required: runtime.GOARCH == "amd64"}, @@ -106,7 +109,7 @@ func archInit() { return } - _, ebx7, ecx7, edx7 := cpuid(7, 0) + eax7, ebx7, ecx7, edx7 := cpuid(7, 0) X86.HasBMI1 = isSet(3, ebx7) X86.HasAVX2 = isSet(5, ebx7) && osSupportsAVX X86.HasBMI2 = isSet(8, ebx7) @@ -134,14 +137,24 @@ func archInit() { X86.HasAVX512VAES = isSet(9, ecx7) X86.HasAVX512VBMI2 = isSet(6, ecx7) X86.HasAVX512BITALG = isSet(12, ecx7) - - eax71, _, _, _ := cpuid(7, 1) - X86.HasAVX512BF16 = isSet(5, eax71) } X86.HasAMXTile = isSet(24, edx7) X86.HasAMXInt8 = isSet(25, edx7) X86.HasAMXBF16 = isSet(22, edx7) + + // These features depend on the second level of extended features. + if eax7 >= 1 { + eax71, _, _, edx71 := cpuid(7, 1) + if X86.HasAVX512 { + X86.HasAVX512BF16 = isSet(5, eax71) + } + if X86.HasAVX { + X86.HasAVXIFMA = isSet(23, eax71) + X86.HasAVXVNNI = isSet(4, eax71) + X86.HasAVXVNNIInt8 = isSet(4, edx71) + } + } } func isSet(bitpos uint, value uint32) bool { From b215a1c6fc7e2f5dc665b5e6f8d8a3424899d6d3 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Mon, 20 Jan 2025 13:10:11 +0000 Subject: [PATCH 03/14] unix: update to Linux kernel 6.13 Change-Id: I4c49a78bd2abf2ac9e4d461680c92ae65be14544 GitHub-Last-Rev: 888e68d533fba83dddd70a8c0d52b082de6d87bc GitHub-Pull-Request: golang/sys#243 Reviewed-on: https://go-review.googlesource.com/c/sys/+/642199 LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- unix/linux/Dockerfile | 4 ++-- unix/linux/types.go | 3 +++ unix/zerrors_linux.go | 13 ++++++++++++- unix/zerrors_linux_386.go | 1 + unix/zerrors_linux_amd64.go | 1 + unix/zerrors_linux_arm.go | 1 + unix/zerrors_linux_arm64.go | 2 ++ unix/zerrors_linux_loong64.go | 1 + unix/zerrors_linux_mips.go | 1 + unix/zerrors_linux_mips64.go | 1 + unix/zerrors_linux_mips64le.go | 1 + unix/zerrors_linux_mipsle.go | 1 + unix/zerrors_linux_ppc.go | 1 + unix/zerrors_linux_ppc64.go | 1 + unix/zerrors_linux_ppc64le.go | 1 + unix/zerrors_linux_riscv64.go | 1 + unix/zerrors_linux_s390x.go | 1 + unix/zerrors_linux_sparc64.go | 1 + unix/zsysnum_linux_386.go | 4 ++++ unix/zsysnum_linux_amd64.go | 4 ++++ unix/zsysnum_linux_arm.go | 4 ++++ unix/zsysnum_linux_arm64.go | 4 ++++ unix/zsysnum_linux_loong64.go | 4 ++++ unix/zsysnum_linux_mips.go | 4 ++++ unix/zsysnum_linux_mips64.go | 4 ++++ unix/zsysnum_linux_mips64le.go | 4 ++++ unix/zsysnum_linux_mipsle.go | 4 ++++ unix/zsysnum_linux_ppc.go | 4 ++++ unix/zsysnum_linux_ppc64.go | 4 ++++ unix/zsysnum_linux_ppc64le.go | 4 ++++ unix/zsysnum_linux_riscv64.go | 4 ++++ unix/zsysnum_linux_s390x.go | 4 ++++ unix/zsysnum_linux_sparc64.go | 4 ++++ unix/ztypes_linux.go | 6 ++++-- 34 files changed, 97 insertions(+), 5 deletions(-) diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile index 96dd602d28..767e423de7 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 17 Nov 2024 -RUN git clone --branch v6.12 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux +# Linux Kernel: Released 20 Jan 2025 +RUN git clone --branch v6.13 --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/types.go b/unix/linux/types.go index 8109005cfe..a125a25edc 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -6100,3 +6100,6 @@ const ( ) type SockDiagReq C.struct_sock_diag_req + +// Removed in Linux 6.13, kept for backwards compatibility. +const RTM_NEWNVLAN = 0x70 diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index 6ebc48b3fe..612f452de6 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -1245,6 +1245,7 @@ const ( FAN_REPORT_DFID_NAME = 0xc00 FAN_REPORT_DFID_NAME_TARGET = 0x1e00 FAN_REPORT_DIR_FID = 0x400 + FAN_REPORT_FD_ERROR = 0x2000 FAN_REPORT_FID = 0x200 FAN_REPORT_NAME = 0x800 FAN_REPORT_PIDFD = 0x80 @@ -2083,6 +2084,7 @@ const ( NFC_ATR_REQ_MAXSIZE = 0x40 NFC_ATR_RES_GB_MAXSIZE = 0x2f NFC_ATR_RES_MAXSIZE = 0x40 + NFC_ATS_MAXSIZE = 0x14 NFC_COMM_ACTIVE = 0x0 NFC_COMM_PASSIVE = 0x1 NFC_DEVICE_NAME_MAXSIZE = 0x8 @@ -2163,6 +2165,7 @@ const ( NFNL_SUBSYS_QUEUE = 0x3 NFNL_SUBSYS_ULOG = 0x4 NFS_SUPER_MAGIC = 0x6969 + NFT_BITWISE_BOOL = 0x0 NFT_CHAIN_FLAGS = 0x7 NFT_CHAIN_MAXNAMELEN = 0x100 NFT_CT_MAX = 0x17 @@ -2491,6 +2494,7 @@ const ( PR_GET_PDEATHSIG = 0x2 PR_GET_SECCOMP = 0x15 PR_GET_SECUREBITS = 0x1b + PR_GET_SHADOW_STACK_STATUS = 0x4a PR_GET_SPECULATION_CTRL = 0x34 PR_GET_TAGGED_ADDR_CTRL = 0x38 PR_GET_THP_DISABLE = 0x2a @@ -2499,6 +2503,7 @@ const ( PR_GET_TIMING = 0xd PR_GET_TSC = 0x19 PR_GET_UNALIGN = 0x5 + PR_LOCK_SHADOW_STACK_STATUS = 0x4c PR_MCE_KILL = 0x21 PR_MCE_KILL_CLEAR = 0x0 PR_MCE_KILL_DEFAULT = 0x2 @@ -2525,6 +2530,8 @@ const ( PR_PAC_GET_ENABLED_KEYS = 0x3d PR_PAC_RESET_KEYS = 0x36 PR_PAC_SET_ENABLED_KEYS = 0x3c + PR_PMLEN_MASK = 0x7f000000 + PR_PMLEN_SHIFT = 0x18 PR_PPC_DEXCR_CTRL_CLEAR = 0x4 PR_PPC_DEXCR_CTRL_CLEAR_ONEXEC = 0x10 PR_PPC_DEXCR_CTRL_EDITABLE = 0x1 @@ -2592,6 +2599,7 @@ const ( PR_SET_PTRACER = 0x59616d61 PR_SET_SECCOMP = 0x16 PR_SET_SECUREBITS = 0x1c + PR_SET_SHADOW_STACK_STATUS = 0x4b PR_SET_SPECULATION_CTRL = 0x35 PR_SET_SYSCALL_USER_DISPATCH = 0x3b PR_SET_TAGGED_ADDR_CTRL = 0x37 @@ -2602,6 +2610,9 @@ const ( PR_SET_UNALIGN = 0x6 PR_SET_VMA = 0x53564d41 PR_SET_VMA_ANON_NAME = 0x0 + PR_SHADOW_STACK_ENABLE = 0x1 + PR_SHADOW_STACK_PUSH = 0x4 + PR_SHADOW_STACK_WRITE = 0x2 PR_SME_GET_VL = 0x40 PR_SME_SET_VL = 0x3f PR_SME_SET_VL_ONEXEC = 0x40000 @@ -2911,7 +2922,6 @@ const ( RTM_NEWNEXTHOP = 0x68 RTM_NEWNEXTHOPBUCKET = 0x74 RTM_NEWNSID = 0x58 - RTM_NEWNVLAN = 0x70 RTM_NEWPREFIX = 0x34 RTM_NEWQDISC = 0x24 RTM_NEWROUTE = 0x18 @@ -2920,6 +2930,7 @@ const ( RTM_NEWTCLASS = 0x28 RTM_NEWTFILTER = 0x2c RTM_NEWTUNNEL = 0x78 + RTM_NEWVLAN = 0x70 RTM_NR_FAMILIES = 0x1b RTM_NR_MSGTYPES = 0x6c RTM_SETDCB = 0x4f diff --git a/unix/zerrors_linux_386.go b/unix/zerrors_linux_386.go index c0d45e3205..fc60616b2f 100644 --- a/unix/zerrors_linux_386.go +++ b/unix/zerrors_linux_386.go @@ -304,6 +304,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 diff --git a/unix/zerrors_linux_amd64.go b/unix/zerrors_linux_amd64.go index c731d24f02..891fbcee37 100644 --- a/unix/zerrors_linux_amd64.go +++ b/unix/zerrors_linux_amd64.go @@ -305,6 +305,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 diff --git a/unix/zerrors_linux_arm.go b/unix/zerrors_linux_arm.go index 680018a4a7..ec28b50a3b 100644 --- a/unix/zerrors_linux_arm.go +++ b/unix/zerrors_linux_arm.go @@ -310,6 +310,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 diff --git a/unix/zerrors_linux_arm64.go b/unix/zerrors_linux_arm64.go index a63909f308..c36d3a9157 100644 --- a/unix/zerrors_linux_arm64.go +++ b/unix/zerrors_linux_arm64.go @@ -109,6 +109,7 @@ const ( F_SETOWN = 0x8 F_UNLCK = 0x2 F_WRLCK = 0x1 + GCS_MAGIC = 0x47435300 HIDIOCGRAWINFO = 0x80084803 HIDIOCGRDESC = 0x90044802 HIDIOCGRDESCSIZE = 0x80044801 @@ -302,6 +303,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 diff --git a/unix/zerrors_linux_loong64.go b/unix/zerrors_linux_loong64.go index 9b0a2573fe..fe4c27275b 100644 --- a/unix/zerrors_linux_loong64.go +++ b/unix/zerrors_linux_loong64.go @@ -297,6 +297,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 diff --git a/unix/zerrors_linux_mips.go b/unix/zerrors_linux_mips.go index 958e6e0645..f3e70b2e32 100644 --- a/unix/zerrors_linux_mips.go +++ b/unix/zerrors_linux_mips.go @@ -303,6 +303,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 diff --git a/unix/zerrors_linux_mips64.go b/unix/zerrors_linux_mips64.go index 50c7f25bd1..06acea1c51 100644 --- a/unix/zerrors_linux_mips64.go +++ b/unix/zerrors_linux_mips64.go @@ -303,6 +303,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 diff --git a/unix/zerrors_linux_mips64le.go b/unix/zerrors_linux_mips64le.go index ced21d66d9..7c144acd4b 100644 --- a/unix/zerrors_linux_mips64le.go +++ b/unix/zerrors_linux_mips64le.go @@ -303,6 +303,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 diff --git a/unix/zerrors_linux_mipsle.go b/unix/zerrors_linux_mipsle.go index 226c044190..52998aff94 100644 --- a/unix/zerrors_linux_mipsle.go +++ b/unix/zerrors_linux_mipsle.go @@ -303,6 +303,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 diff --git a/unix/zerrors_linux_ppc.go b/unix/zerrors_linux_ppc.go index 3122737cd4..4bb35f4ee1 100644 --- a/unix/zerrors_linux_ppc.go +++ b/unix/zerrors_linux_ppc.go @@ -358,6 +358,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 diff --git a/unix/zerrors_linux_ppc64.go b/unix/zerrors_linux_ppc64.go index eb5d3467ed..d02c108653 100644 --- a/unix/zerrors_linux_ppc64.go +++ b/unix/zerrors_linux_ppc64.go @@ -362,6 +362,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 diff --git a/unix/zerrors_linux_ppc64le.go b/unix/zerrors_linux_ppc64le.go index e921ebc60b..4704d53e27 100644 --- a/unix/zerrors_linux_ppc64le.go +++ b/unix/zerrors_linux_ppc64le.go @@ -362,6 +362,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 diff --git a/unix/zerrors_linux_riscv64.go b/unix/zerrors_linux_riscv64.go index 38ba81c55c..1b29f3182c 100644 --- a/unix/zerrors_linux_riscv64.go +++ b/unix/zerrors_linux_riscv64.go @@ -294,6 +294,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 diff --git a/unix/zerrors_linux_s390x.go b/unix/zerrors_linux_s390x.go index 71f0400977..35b34f408d 100644 --- a/unix/zerrors_linux_s390x.go +++ b/unix/zerrors_linux_s390x.go @@ -366,6 +366,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x36 SCM_TIMESTAMPING_PKTINFO = 0x3a SCM_TIMESTAMPNS = 0x23 + SCM_TS_OPT_ID = 0x51 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 diff --git a/unix/zerrors_linux_sparc64.go b/unix/zerrors_linux_sparc64.go index c44a313322..d8aef34863 100644 --- a/unix/zerrors_linux_sparc64.go +++ b/unix/zerrors_linux_sparc64.go @@ -357,6 +357,7 @@ const ( SCM_TIMESTAMPING_OPT_STATS = 0x38 SCM_TIMESTAMPING_PKTINFO = 0x3c SCM_TIMESTAMPNS = 0x21 + SCM_TS_OPT_ID = 0x5a SCM_TXTIME = 0x3f SCM_WIFI_STATUS = 0x25 SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 diff --git a/unix/zsysnum_linux_386.go b/unix/zsysnum_linux_386.go index 524b0820cb..c79aaff306 100644 --- a/unix/zsysnum_linux_386.go +++ b/unix/zsysnum_linux_386.go @@ -458,4 +458,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_amd64.go b/unix/zsysnum_linux_amd64.go index f485dbf456..5eb450695e 100644 --- a/unix/zsysnum_linux_amd64.go +++ b/unix/zsysnum_linux_amd64.go @@ -381,4 +381,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_arm.go b/unix/zsysnum_linux_arm.go index 70b35bf3b0..05e5029744 100644 --- a/unix/zsysnum_linux_arm.go +++ b/unix/zsysnum_linux_arm.go @@ -422,4 +422,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_arm64.go b/unix/zsysnum_linux_arm64.go index 1893e2fe88..38c53ec51b 100644 --- a/unix/zsysnum_linux_arm64.go +++ b/unix/zsysnum_linux_arm64.go @@ -325,4 +325,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_loong64.go b/unix/zsysnum_linux_loong64.go index 16a4017da0..31d2e71a18 100644 --- a/unix/zsysnum_linux_loong64.go +++ b/unix/zsysnum_linux_loong64.go @@ -321,4 +321,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_mips.go b/unix/zsysnum_linux_mips.go index 7e567f1eff..f4184a336b 100644 --- a/unix/zsysnum_linux_mips.go +++ b/unix/zsysnum_linux_mips.go @@ -442,4 +442,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 4460 SYS_LSM_LIST_MODULES = 4461 SYS_MSEAL = 4462 + SYS_SETXATTRAT = 4463 + SYS_GETXATTRAT = 4464 + SYS_LISTXATTRAT = 4465 + SYS_REMOVEXATTRAT = 4466 ) diff --git a/unix/zsysnum_linux_mips64.go b/unix/zsysnum_linux_mips64.go index 38ae55e5ef..05b9962278 100644 --- a/unix/zsysnum_linux_mips64.go +++ b/unix/zsysnum_linux_mips64.go @@ -372,4 +372,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 5460 SYS_LSM_LIST_MODULES = 5461 SYS_MSEAL = 5462 + SYS_SETXATTRAT = 5463 + SYS_GETXATTRAT = 5464 + SYS_LISTXATTRAT = 5465 + SYS_REMOVEXATTRAT = 5466 ) diff --git a/unix/zsysnum_linux_mips64le.go b/unix/zsysnum_linux_mips64le.go index 55e92e60a8..43a256e9e6 100644 --- a/unix/zsysnum_linux_mips64le.go +++ b/unix/zsysnum_linux_mips64le.go @@ -372,4 +372,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 5460 SYS_LSM_LIST_MODULES = 5461 SYS_MSEAL = 5462 + SYS_SETXATTRAT = 5463 + SYS_GETXATTRAT = 5464 + SYS_LISTXATTRAT = 5465 + SYS_REMOVEXATTRAT = 5466 ) diff --git a/unix/zsysnum_linux_mipsle.go b/unix/zsysnum_linux_mipsle.go index 60658d6a02..eea5ddfc22 100644 --- a/unix/zsysnum_linux_mipsle.go +++ b/unix/zsysnum_linux_mipsle.go @@ -442,4 +442,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 4460 SYS_LSM_LIST_MODULES = 4461 SYS_MSEAL = 4462 + SYS_SETXATTRAT = 4463 + SYS_GETXATTRAT = 4464 + SYS_LISTXATTRAT = 4465 + SYS_REMOVEXATTRAT = 4466 ) diff --git a/unix/zsysnum_linux_ppc.go b/unix/zsysnum_linux_ppc.go index e203e8a7ed..0d777bfbb1 100644 --- a/unix/zsysnum_linux_ppc.go +++ b/unix/zsysnum_linux_ppc.go @@ -449,4 +449,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_ppc64.go b/unix/zsysnum_linux_ppc64.go index 5944b97d54..b446365025 100644 --- a/unix/zsysnum_linux_ppc64.go +++ b/unix/zsysnum_linux_ppc64.go @@ -421,4 +421,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_ppc64le.go b/unix/zsysnum_linux_ppc64le.go index c66d416dad..0c7d21c188 100644 --- a/unix/zsysnum_linux_ppc64le.go +++ b/unix/zsysnum_linux_ppc64le.go @@ -421,4 +421,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_riscv64.go b/unix/zsysnum_linux_riscv64.go index a5459e766f..8405391698 100644 --- a/unix/zsysnum_linux_riscv64.go +++ b/unix/zsysnum_linux_riscv64.go @@ -326,4 +326,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_s390x.go b/unix/zsysnum_linux_s390x.go index 01d86825bb..fcf1b790d6 100644 --- a/unix/zsysnum_linux_s390x.go +++ b/unix/zsysnum_linux_s390x.go @@ -387,4 +387,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/zsysnum_linux_sparc64.go b/unix/zsysnum_linux_sparc64.go index 7b703e77cd..52d15b5f9d 100644 --- a/unix/zsysnum_linux_sparc64.go +++ b/unix/zsysnum_linux_sparc64.go @@ -400,4 +400,8 @@ const ( SYS_LSM_SET_SELF_ATTR = 460 SYS_LSM_LIST_MODULES = 461 SYS_MSEAL = 462 + SYS_SETXATTRAT = 463 + SYS_GETXATTRAT = 464 + SYS_LISTXATTRAT = 465 + SYS_REMOVEXATTRAT = 466 ) diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 5537148dcb..a46abe6472 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -4747,7 +4747,7 @@ const ( NL80211_ATTR_MAC_HINT = 0xc8 NL80211_ATTR_MAC_MASK = 0xd7 NL80211_ATTR_MAX_AP_ASSOC_STA = 0xca - NL80211_ATTR_MAX = 0x14c + NL80211_ATTR_MAX = 0x14d NL80211_ATTR_MAX_CRIT_PROT_DURATION = 0xb4 NL80211_ATTR_MAX_CSA_COUNTERS = 0xce NL80211_ATTR_MAX_MATCH_SETS = 0x85 @@ -5519,7 +5519,7 @@ const ( NL80211_MNTR_FLAG_CONTROL = 0x3 NL80211_MNTR_FLAG_COOK_FRAMES = 0x5 NL80211_MNTR_FLAG_FCSFAIL = 0x1 - NL80211_MNTR_FLAG_MAX = 0x6 + NL80211_MNTR_FLAG_MAX = 0x7 NL80211_MNTR_FLAG_OTHER_BSS = 0x4 NL80211_MNTR_FLAG_PLCPFAIL = 0x2 NL80211_MPATH_FLAG_ACTIVE = 0x1 @@ -6174,3 +6174,5 @@ type SockDiagReq struct { Family uint8 Protocol uint8 } + +const RTM_NEWNVLAN = 0x70 From 4d4692e1b078ef608f533de23ece0464d8f9e182 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Sat, 25 Jan 2025 13:08:06 +0100 Subject: [PATCH 04/14] unix: add Auxv Fixes golang/go#67839 Change-Id: I3af38d21159f7cac3786b49ac17657d314fbc178 Reviewed-on: https://go-review.googlesource.com/c/sys/+/644295 Reviewed-by: Tobias Klauser LUCI-TryBot-Result: Go LUCI Reviewed-by: Carlos Amedee Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- unix/auxv.go | 36 ++++++++++++++++++++++++++++++++++++ unix/auxv_linux_test.go | 23 +++++++++++++++++++++++ unix/auxv_unsupported.go | 13 +++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 unix/auxv.go create mode 100644 unix/auxv_linux_test.go create mode 100644 unix/auxv_unsupported.go diff --git a/unix/auxv.go b/unix/auxv.go new file mode 100644 index 0000000000..37a82528f5 --- /dev/null +++ b/unix/auxv.go @@ -0,0 +1,36 @@ +// Copyright 2025 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 go1.21 && (aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos) + +package unix + +import ( + "syscall" + "unsafe" +) + +//go:linkname runtime_getAuxv runtime.getAuxv +func runtime_getAuxv() []uintptr + +// Auxv returns the ELF auxiliary vector as a sequence of key/value pairs. +// The returned slice is always a fresh copy, owned by the caller. +// It returns an error on non-ELF platforms, or if the auxiliary vector cannot be accessed, +// which happens in some locked-down environments and build modes. +func Auxv() ([][2]uintptr, error) { + vec := runtime_getAuxv() + vecLen := len(vec) + + if vecLen == 0 { + return nil, syscall.ENOENT + } + + if vecLen%2 != 0 { + return nil, syscall.EINVAL + } + + result := make([]uintptr, vecLen) + copy(result, vec) + return unsafe.Slice((*[2]uintptr)(unsafe.Pointer(&result[0])), vecLen/2), nil +} diff --git a/unix/auxv_linux_test.go b/unix/auxv_linux_test.go new file mode 100644 index 0000000000..928f3c9724 --- /dev/null +++ b/unix/auxv_linux_test.go @@ -0,0 +1,23 @@ +// Copyright 2025 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 go1.21 && linux + +package unix_test + +import ( + "testing" + + "golang.org/x/sys/unix" +) + +func TestAuxv(t *testing.T) { + vec, err := unix.Auxv() + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if len(vec) == 0 { + t.Errorf("got zero auxv entries on linux, expected > 0") + } +} diff --git a/unix/auxv_unsupported.go b/unix/auxv_unsupported.go new file mode 100644 index 0000000000..1200487f2e --- /dev/null +++ b/unix/auxv_unsupported.go @@ -0,0 +1,13 @@ +// Copyright 2025 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 !go1.21 && (aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos) + +package unix + +import "syscall" + +func Auxv() ([][2]uintptr, error) { + return nil, syscall.ENOTSUP +} From 863b3c4ac4975ff758815fa8d01acb6771f37177 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Thu, 30 Jan 2025 12:04:28 +0000 Subject: [PATCH 05/14] unix: update glibc to 2.41 Change-Id: I1796b552f854a15e8ef5e019e247c4d7e0644086 GitHub-Last-Rev: 3518c6200591380bc4414649afefb16882ab565a GitHub-Pull-Request: golang/sys#244 Reviewed-on: https://go-review.googlesource.com/c/sys/+/645436 LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Carlos Amedee --- unix/linux/Dockerfile | 4 ++-- unix/zerrors_linux.go | 7 +++++++ unix/zerrors_linux_386.go | 2 ++ unix/zerrors_linux_amd64.go | 2 ++ unix/zerrors_linux_arm.go | 2 ++ unix/zerrors_linux_arm64.go | 2 ++ unix/zerrors_linux_loong64.go | 2 ++ unix/zerrors_linux_mips.go | 2 ++ unix/zerrors_linux_mips64.go | 2 ++ unix/zerrors_linux_mips64le.go | 2 ++ unix/zerrors_linux_mipsle.go | 2 ++ unix/zerrors_linux_ppc.go | 2 ++ unix/zerrors_linux_ppc64.go | 2 ++ unix/zerrors_linux_ppc64le.go | 2 ++ unix/zerrors_linux_riscv64.go | 2 ++ unix/zerrors_linux_s390x.go | 2 ++ unix/zerrors_linux_sparc64.go | 2 ++ 17 files changed, 39 insertions(+), 2 deletions(-) diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile index 767e423de7..2bbb21a37a 100644 --- a/unix/linux/Dockerfile +++ b/unix/linux/Dockerfile @@ -17,8 +17,8 @@ WORKDIR /git RUN git config --global advice.detachedHead false # Linux Kernel: Released 20 Jan 2025 RUN git clone --branch v6.13 --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 +# GNU C library: Released 29 Jan 2025 +RUN git clone --branch release/2.41/master --depth 1 https://sourceware.org/git/glibc.git # Get Go ENV GOLANG_VERSION=1.23.0 diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index 612f452de6..4f432bfe8f 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -1331,8 +1331,10 @@ const ( FUSE_SUPER_MAGIC = 0x65735546 FUTEXFS_SUPER_MAGIC = 0xbad1dea F_ADD_SEALS = 0x409 + F_CREATED_QUERY = 0x404 F_DUPFD = 0x0 F_DUPFD_CLOEXEC = 0x406 + F_DUPFD_QUERY = 0x403 F_EXLCK = 0x4 F_GETFD = 0x1 F_GETFL = 0x3 @@ -1552,6 +1554,7 @@ const ( IPPROTO_ROUTING = 0x2b IPPROTO_RSVP = 0x2e IPPROTO_SCTP = 0x84 + IPPROTO_SMC = 0x100 IPPROTO_TCP = 0x6 IPPROTO_TP = 0x1d IPPROTO_UDP = 0x11 @@ -1624,6 +1627,8 @@ const ( IPV6_UNICAST_IF = 0x4c IPV6_USER_FLOW = 0xe IPV6_V6ONLY = 0x1a + IPV6_VERSION = 0x60 + IPV6_VERSION_MASK = 0xf0 IPV6_XFRM_POLICY = 0x23 IP_ADD_MEMBERSHIP = 0x23 IP_ADD_SOURCE_MEMBERSHIP = 0x27 @@ -1868,6 +1873,7 @@ const ( MADV_UNMERGEABLE = 0xd MADV_WILLNEED = 0x3 MADV_WIPEONFORK = 0x12 + MAP_DROPPABLE = 0x8 MAP_FILE = 0x0 MAP_FIXED = 0x10 MAP_FIXED_NOREPLACE = 0x100000 @@ -1968,6 +1974,7 @@ const ( MSG_PEEK = 0x2 MSG_PROXY = 0x10 MSG_RST = 0x1000 + MSG_SOCK_DEVMEM = 0x2000000 MSG_SYN = 0x400 MSG_TRUNC = 0x20 MSG_TRYHARD = 0x4 diff --git a/unix/zerrors_linux_386.go b/unix/zerrors_linux_386.go index fc60616b2f..75207613c7 100644 --- a/unix/zerrors_linux_386.go +++ b/unix/zerrors_linux_386.go @@ -116,6 +116,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_amd64.go b/unix/zerrors_linux_amd64.go index 891fbcee37..c68acda535 100644 --- a/unix/zerrors_linux_amd64.go +++ b/unix/zerrors_linux_amd64.go @@ -116,6 +116,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_arm.go b/unix/zerrors_linux_arm.go index ec28b50a3b..a8c607ab86 100644 --- a/unix/zerrors_linux_arm.go +++ b/unix/zerrors_linux_arm.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_arm64.go b/unix/zerrors_linux_arm64.go index c36d3a9157..18563dd8d3 100644 --- a/unix/zerrors_linux_arm64.go +++ b/unix/zerrors_linux_arm64.go @@ -120,6 +120,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_loong64.go b/unix/zerrors_linux_loong64.go index fe4c27275b..22912cdaa9 100644 --- a/unix/zerrors_linux_loong64.go +++ b/unix/zerrors_linux_loong64.go @@ -116,6 +116,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_mips.go b/unix/zerrors_linux_mips.go index f3e70b2e32..29344eb37a 100644 --- a/unix/zerrors_linux_mips.go +++ b/unix/zerrors_linux_mips.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x80 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_mips64.go b/unix/zerrors_linux_mips64.go index 06acea1c51..20d51fb96a 100644 --- a/unix/zerrors_linux_mips64.go +++ b/unix/zerrors_linux_mips64.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x80 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_mips64le.go b/unix/zerrors_linux_mips64le.go index 7c144acd4b..321b60902a 100644 --- a/unix/zerrors_linux_mips64le.go +++ b/unix/zerrors_linux_mips64le.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x80 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_mipsle.go b/unix/zerrors_linux_mipsle.go index 52998aff94..9bacdf1e27 100644 --- a/unix/zerrors_linux_mipsle.go +++ b/unix/zerrors_linux_mipsle.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x80 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_ppc.go b/unix/zerrors_linux_ppc.go index 4bb35f4ee1..c224272615 100644 --- a/unix/zerrors_linux_ppc.go +++ b/unix/zerrors_linux_ppc.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x80 IUCLC = 0x1000 IXOFF = 0x400 diff --git a/unix/zerrors_linux_ppc64.go b/unix/zerrors_linux_ppc64.go index d02c108653..6270c8ee13 100644 --- a/unix/zerrors_linux_ppc64.go +++ b/unix/zerrors_linux_ppc64.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x80 IUCLC = 0x1000 IXOFF = 0x400 diff --git a/unix/zerrors_linux_ppc64le.go b/unix/zerrors_linux_ppc64le.go index 4704d53e27..9966c1941f 100644 --- a/unix/zerrors_linux_ppc64le.go +++ b/unix/zerrors_linux_ppc64le.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x80 IUCLC = 0x1000 IXOFF = 0x400 diff --git a/unix/zerrors_linux_riscv64.go b/unix/zerrors_linux_riscv64.go index 1b29f3182c..848e5fcc42 100644 --- a/unix/zerrors_linux_riscv64.go +++ b/unix/zerrors_linux_riscv64.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xffffff0f + IPV6_FLOWLABEL_MASK = 0xffff0f00 ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_s390x.go b/unix/zerrors_linux_s390x.go index 35b34f408d..669b2adb80 100644 --- a/unix/zerrors_linux_s390x.go +++ b/unix/zerrors_linux_s390x.go @@ -115,6 +115,8 @@ const ( IN_CLOEXEC = 0x80000 IN_NONBLOCK = 0x800 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 diff --git a/unix/zerrors_linux_sparc64.go b/unix/zerrors_linux_sparc64.go index d8aef34863..4834e57514 100644 --- a/unix/zerrors_linux_sparc64.go +++ b/unix/zerrors_linux_sparc64.go @@ -119,6 +119,8 @@ const ( IN_CLOEXEC = 0x400000 IN_NONBLOCK = 0x4000 IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x200007b9 + IPV6_FLOWINFO_MASK = 0xfffffff + IPV6_FLOWLABEL_MASK = 0xfffff ISIG = 0x1 IUCLC = 0x200 IXOFF = 0x1000 From 74cfc93a99be6ca6f193856132e6799065b071af Mon Sep 17 00:00:00 2001 From: Gopher Robot Date: Fri, 14 Feb 2025 21:16:54 +0000 Subject: [PATCH 06/14] all: upgrade go directive to at least 1.23.0 [generated] By now Go 1.24.0 has been released, and Go 1.22 is no longer supported per the Go Release Policy (https://go.dev/doc/devel/release#policy). For golang/go#69095. [git-generate] (cd . && go get go@1.23.0 && go mod tidy && go fix ./... && go mod edit -toolchain=none) Change-Id: Ibb66e9edd9b097ab8ff838138f8116664bb50158 Reviewed-on: https://go-review.googlesource.com/c/sys/+/649697 Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Auto-Submit: Gopher Robot Reviewed-by: Cherry Mui --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9e1e4d59be..c9e7faab86 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module golang.org/x/sys -go 1.18 +go 1.23.0 From f2ce62c21a0ddb543d412be19f3168b09d76d1b8 Mon Sep 17 00:00:00 2001 From: database64128 Date: Tue, 4 Mar 2025 05:31:52 +0000 Subject: [PATCH 07/14] windows: add constants for PMTUD socket options Related documentation: - https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options - https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-ipv6-socket-options Change-Id: I21b23ca815d1d8135ce5724115b9ca23819ea10a GitHub-Last-Rev: 9054c5c79068da8d2583b23dca9464293c36901a GitHub-Pull-Request: golang/sys#245 Reviewed-on: https://go-review.googlesource.com/c/sys/+/654495 Reviewed-by: Quim Muntal Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Junyang Shao Auto-Submit: Ian Lance Taylor --- windows/types_windows.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/windows/types_windows.go b/windows/types_windows.go index 9d138de5fe..fac0309d08 100644 --- a/windows/types_windows.go +++ b/windows/types_windows.go @@ -1074,6 +1074,7 @@ const ( IP_ADD_MEMBERSHIP = 0xc IP_DROP_MEMBERSHIP = 0xd IP_PKTINFO = 0x13 + IP_MTU_DISCOVER = 0x47 IPV6_V6ONLY = 0x1b IPV6_UNICAST_HOPS = 0x4 @@ -1083,6 +1084,7 @@ const ( IPV6_JOIN_GROUP = 0xc IPV6_LEAVE_GROUP = 0xd IPV6_PKTINFO = 0x13 + IPV6_MTU_DISCOVER = 0x47 MSG_OOB = 0x1 MSG_PEEK = 0x2 @@ -1132,6 +1134,15 @@ const ( WSASYS_STATUS_LEN = 128 ) +// enum PMTUD_STATE from ws2ipdef.h +const ( + IP_PMTUDISC_NOT_SET = 0 + IP_PMTUDISC_DO = 1 + IP_PMTUDISC_DONT = 2 + IP_PMTUDISC_PROBE = 3 + IP_PMTUDISC_MAX = 4 +) + type WSABuf struct { Len uint32 Buf *byte From b8f7da6c5a244c4015da1e739f7f40b21f4c40c8 Mon Sep 17 00:00:00 2001 From: Guoqi Chen Date: Thu, 6 Mar 2025 19:41:06 +0800 Subject: [PATCH 08/14] cpu: add support for detecting cpu features on loong64 Except for lasx, all other features have been implemented in the Go mainline. Change-Id: I61a09396ed23d17991b641a1265e952585cb5636 Reviewed-on: https://go-review.googlesource.com/c/sys/+/655355 Reviewed-by: David Chase Reviewed-by: sophie zhao LUCI-TryBot-Result: Go LUCI Reviewed-by: Junyang Shao Reviewed-by: Meidan Li --- cpu/cpu.go | 12 ++++++++++++ cpu/cpu_linux_loong64.go | 22 ++++++++++++++++++++++ cpu/cpu_linux_noinit.go | 2 +- cpu/cpu_loong64.go | 38 ++++++++++++++++++++++++++++++++++++++ cpu/cpu_loong64.s | 12 ++++++++++++ cpu/cpu_test.go | 8 ++++++++ 6 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 cpu/cpu_linux_loong64.go create mode 100644 cpu/cpu_loong64.s diff --git a/cpu/cpu.go b/cpu/cpu.go index 9c105f23af..2e73ee1975 100644 --- a/cpu/cpu.go +++ b/cpu/cpu.go @@ -149,6 +149,18 @@ var ARM struct { _ CacheLinePad } +// The booleans in Loong64 contain the correspondingly named cpu feature bit. +// The struct is padded to avoid false sharing. +var Loong64 struct { + _ CacheLinePad + HasLSX bool // support 128-bit vector extension + HasLASX bool // support 256-bit vector extension + HasCRC32 bool // support CRC instruction + HasLAM_BH bool // support AM{SWAP/ADD}[_DB].{B/H} instruction + HasLAMCAS bool // support AMCAS[_DB].{B/H/W/D} instruction + _ CacheLinePad +} + // MIPS64X contains the supported CPU features of the current mips64/mips64le // platforms. If the current platform is not mips64/mips64le or the current // operating system is not Linux then all feature flags are false. diff --git a/cpu/cpu_linux_loong64.go b/cpu/cpu_linux_loong64.go new file mode 100644 index 0000000000..4f34114329 --- /dev/null +++ b/cpu/cpu_linux_loong64.go @@ -0,0 +1,22 @@ +// Copyright 2025 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 + +// HWCAP bits. These are exposed by the Linux kernel. +const ( + hwcap_LOONGARCH_LSX = 1 << 4 + hwcap_LOONGARCH_LASX = 1 << 5 +) + +func doinit() { + // TODO: Features that require kernel support like LSX and LASX can + // be detected here once needed in std library or by the compiler. + Loong64.HasLSX = hwcIsSet(hwCap, hwcap_LOONGARCH_LSX) + Loong64.HasLASX = hwcIsSet(hwCap, hwcap_LOONGARCH_LASX) +} + +func hwcIsSet(hwc uint, val uint) bool { + return hwc&val != 0 +} diff --git a/cpu/cpu_linux_noinit.go b/cpu/cpu_linux_noinit.go index 7d902b6847..a428dec9cd 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 && !riscv64 +//go:build linux && !arm && !arm64 && !loong64 && !mips64 && !mips64le && !ppc64 && !ppc64le && !s390x && !riscv64 package cpu diff --git a/cpu/cpu_loong64.go b/cpu/cpu_loong64.go index 558635850c..45ecb29ae7 100644 --- a/cpu/cpu_loong64.go +++ b/cpu/cpu_loong64.go @@ -8,5 +8,43 @@ package cpu const cacheLineSize = 64 +// Bit fields for CPUCFG registers, Related reference documents: +// https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_cpucfg +const ( + // CPUCFG1 bits + cpucfg1_CRC32 = 1 << 25 + + // CPUCFG2 bits + cpucfg2_LAM_BH = 1 << 27 + cpucfg2_LAMCAS = 1 << 28 +) + func initOptions() { + options = []option{ + {Name: "lsx", Feature: &Loong64.HasLSX}, + {Name: "lasx", Feature: &Loong64.HasLASX}, + {Name: "crc32", Feature: &Loong64.HasCRC32}, + {Name: "lam_bh", Feature: &Loong64.HasLAM_BH}, + {Name: "lamcas", Feature: &Loong64.HasLAMCAS}, + } + + // The CPUCFG data on Loong64 only reflects the hardware capabilities, + // not the kernel support status, so features such as LSX and LASX that + // require kernel support cannot be obtained from the CPUCFG data. + // + // These features only require hardware capability support and do not + // require kernel specific support, so they can be obtained directly + // through CPUCFG + cfg1 := get_cpucfg(1) + cfg2 := get_cpucfg(2) + + Loong64.HasCRC32 = cfgIsSet(cfg1, cpucfg1_CRC32) + Loong64.HasLAMCAS = cfgIsSet(cfg2, cpucfg2_LAMCAS) + Loong64.HasLAM_BH = cfgIsSet(cfg2, cpucfg2_LAM_BH) +} + +func get_cpucfg(reg uint32) uint32 + +func cfgIsSet(cfg uint32, val uint32) bool { + return cfg&val != 0 } diff --git a/cpu/cpu_loong64.s b/cpu/cpu_loong64.s new file mode 100644 index 0000000000..30b4c0d10b --- /dev/null +++ b/cpu/cpu_loong64.s @@ -0,0 +1,12 @@ +// Copyright 2025 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. + +#include "textflag.h" + +// func get_cpucfg(reg uint32) uint32 +TEXT ·get_cpucfg(SB), NOSPLIT|NOFRAME, $0 + MOVW reg+0(FP), R5 + CPUCFG R5, R4 + MOVW R4, ret+8(FP) + RET diff --git a/cpu/cpu_test.go b/cpu/cpu_test.go index dd493ece8c..6906786436 100644 --- a/cpu/cpu_test.go +++ b/cpu/cpu_test.go @@ -87,6 +87,14 @@ func TestARM64minimalFeatures(t *testing.T) { } } +func TestLOONG64Initialized(t *testing.T) { + if runtime.GOARCH == "loong64" { + if !cpu.Initialized { + t.Fatal("Initialized expected true, got false") + } + } +} + func TestMIPS64Initialized(t *testing.T) { if runtime.GOARCH == "mips64" || runtime.GOARCH == "mips64le" { if !cpu.Initialized { From 7401cce31392295f531e1d0fcc2f01d782353300 Mon Sep 17 00:00:00 2001 From: Guoqi Chen Date: Wed, 12 Mar 2025 10:18:00 +0800 Subject: [PATCH 09/14] cpu: replace specific instructions with WORD in the function get_cpucfg on loong64 The CPUCFG instruction on loong64 was introduced in Go1.24, which caused compilation errors when using this feature in Go1.23 and earlier versions. Change-Id: I68891bbfc527194ecdafebac3398e700bfb53c2f Reviewed-on: https://go-review.googlesource.com/c/sys/+/656915 Reviewed-by: Meidan Li LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase Reviewed-by: Junyang Shao --- cpu/cpu_loong64.s | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpu/cpu_loong64.s b/cpu/cpu_loong64.s index 30b4c0d10b..71cbaf1ce2 100644 --- a/cpu/cpu_loong64.s +++ b/cpu/cpu_loong64.s @@ -7,6 +7,7 @@ // func get_cpucfg(reg uint32) uint32 TEXT ·get_cpucfg(SB), NOSPLIT|NOFRAME, $0 MOVW reg+0(FP), R5 - CPUCFG R5, R4 + // CPUCFG R5, R4 = 0x00006ca4 + WORD $0x00006ca4 MOVW R4, ret+8(FP) RET From 3330b5e756f9a4ffd9510bc98b4c8b5b6d05b9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Sch=C3=B6nlaub?= Date: Wed, 19 Mar 2025 21:08:22 -0600 Subject: [PATCH 10/14] unix: support Readv, Preadv, Writev and Pwritev for darwin Darwin, starting with Big Sur, supports vectorized IO. Fixes golang/go#64710 Change-Id: Ic3a3c51009eab24f70665d8d3a145b328a7713c6 Reviewed-on: https://go-review.googlesource.com/c/sys/+/548795 LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Cherry Mui --- unix/darwin_amd64_test.go | 4 + unix/darwin_arm64_test.go | 3 + unix/syscall_darwin.go | 149 +++++++++++++++++++++++++++++++++- unix/zsyscall_darwin_amd64.go | 84 +++++++++++++++++++ unix/zsyscall_darwin_amd64.s | 20 +++++ unix/zsyscall_darwin_arm64.go | 84 +++++++++++++++++++ unix/zsyscall_darwin_arm64.s | 20 +++++ 7 files changed, 363 insertions(+), 1 deletion(-) diff --git a/unix/darwin_amd64_test.go b/unix/darwin_amd64_test.go index f89b50e717..a35f64e770 100644 --- a/unix/darwin_amd64_test.go +++ b/unix/darwin_amd64_test.go @@ -102,14 +102,17 @@ var darwinTests = [...]darwinTest{ {"pipe", libc_pipe_trampoline_addr}, {"poll", libc_poll_trampoline_addr}, {"pread", libc_pread_trampoline_addr}, + {"preadv", libc_preadv_trampoline_addr}, {"pthread_chdir_np", libc_pthread_chdir_np_trampoline_addr}, {"pthread_fchdir_np", libc_pthread_fchdir_np_trampoline_addr}, {"ptrace", libc_ptrace_trampoline_addr}, {"pwrite", libc_pwrite_trampoline_addr}, + {"pwritev", libc_pwritev_trampoline_addr}, {"read", libc_read_trampoline_addr}, {"readdir_r", libc_readdir_r_trampoline_addr}, {"readlink", libc_readlink_trampoline_addr}, {"readlinkat", libc_readlinkat_trampoline_addr}, + {"readv", libc_readv_trampoline_addr}, {"recvfrom", libc_recvfrom_trampoline_addr}, {"recvmsg", libc_recvmsg_trampoline_addr}, {"removexattr", libc_removexattr_trampoline_addr}, @@ -162,4 +165,5 @@ var darwinTests = [...]darwinTest{ {"utimes", libc_utimes_trampoline_addr}, {"wait4", libc_wait4_trampoline_addr}, {"write", libc_write_trampoline_addr}, + {"writev", libc_writev_trampoline_addr}, } diff --git a/unix/darwin_arm64_test.go b/unix/darwin_arm64_test.go index 5fc4feb44b..740d6f7d1e 100644 --- a/unix/darwin_arm64_test.go +++ b/unix/darwin_arm64_test.go @@ -102,6 +102,7 @@ var darwinTests = [...]darwinTest{ {"pipe", libc_pipe_trampoline_addr}, {"poll", libc_poll_trampoline_addr}, {"pread", libc_pread_trampoline_addr}, + {"preadv", libc_preadv_trampoline_addr}, {"pthread_chdir_np", libc_pthread_chdir_np_trampoline_addr}, {"pthread_fchdir_np", libc_pthread_fchdir_np_trampoline_addr}, {"ptrace", libc_ptrace_trampoline_addr}, @@ -110,6 +111,7 @@ var darwinTests = [...]darwinTest{ {"readdir_r", libc_readdir_r_trampoline_addr}, {"readlink", libc_readlink_trampoline_addr}, {"readlinkat", libc_readlinkat_trampoline_addr}, + {"readv", libc_readv_trampoline_addr}, {"recvfrom", libc_recvfrom_trampoline_addr}, {"recvmsg", libc_recvmsg_trampoline_addr}, {"removexattr", libc_removexattr_trampoline_addr}, @@ -162,4 +164,5 @@ var darwinTests = [...]darwinTest{ {"utimes", libc_utimes_trampoline_addr}, {"wait4", libc_wait4_trampoline_addr}, {"write", libc_write_trampoline_addr}, + {"writev", libc_writev_trampoline_addr}, } diff --git a/unix/syscall_darwin.go b/unix/syscall_darwin.go index 099867deed..798f61ad3b 100644 --- a/unix/syscall_darwin.go +++ b/unix/syscall_darwin.go @@ -602,7 +602,150 @@ func Connectx(fd int, srcIf uint32, srcAddr, dstAddr Sockaddr, associd SaeAssocI return } -//sys connectx(fd int, endpoints *SaEndpoints, associd SaeAssocID, flags uint32, iov []Iovec, n *uintptr, connid *SaeConnID) (err error) +// sys connectx(fd int, endpoints *SaEndpoints, associd SaeAssocID, flags uint32, iov []Iovec, n *uintptr, connid *SaeConnID) (err error) +const minIovec = 8 + +func Readv(fd int, iovs [][]byte) (n int, err error) { + if !darwinKernelVersionMin(11, 0, 0) { + return 0, ENOSYS + } + + iovecs := make([]Iovec, 0, minIovec) + iovecs = appendBytes(iovecs, iovs) + n, err = readv(fd, iovecs) + readvRacedetect(iovecs, n, err) + return n, err +} + +func Preadv(fd int, iovs [][]byte, offset int64) (n int, err error) { + if !darwinKernelVersionMin(11, 0, 0) { + return 0, ENOSYS + } + iovecs := make([]Iovec, 0, minIovec) + iovecs = appendBytes(iovecs, iovs) + n, err = preadv(fd, iovecs, offset) + readvRacedetect(iovecs, n, err) + return n, err +} + +func Writev(fd int, iovs [][]byte) (n int, err error) { + if !darwinKernelVersionMin(11, 0, 0) { + return 0, ENOSYS + } + + iovecs := make([]Iovec, 0, minIovec) + iovecs = appendBytes(iovecs, iovs) + if raceenabled { + raceReleaseMerge(unsafe.Pointer(&ioSync)) + } + n, err = writev(fd, iovecs) + writevRacedetect(iovecs, n) + return n, err +} + +func Pwritev(fd int, iovs [][]byte, offset int64) (n int, err error) { + if !darwinKernelVersionMin(11, 0, 0) { + return 0, ENOSYS + } + + iovecs := make([]Iovec, 0, minIovec) + iovecs = appendBytes(iovecs, iovs) + if raceenabled { + raceReleaseMerge(unsafe.Pointer(&ioSync)) + } + n, err = pwritev(fd, iovecs, offset) + writevRacedetect(iovecs, n) + return n, err +} + +func appendBytes(vecs []Iovec, bs [][]byte) []Iovec { + for _, b := range bs { + var v Iovec + v.SetLen(len(b)) + if len(b) > 0 { + v.Base = &b[0] + } else { + v.Base = (*byte)(unsafe.Pointer(&_zero)) + } + vecs = append(vecs, v) + } + return vecs +} + +func writevRacedetect(iovecs []Iovec, n int) { + if !raceenabled { + return + } + for i := 0; n > 0 && i < len(iovecs); i++ { + m := int(iovecs[i].Len) + if m > n { + m = n + } + n -= m + if m > 0 { + raceReadRange(unsafe.Pointer(iovecs[i].Base), m) + } + } +} + +func readvRacedetect(iovecs []Iovec, n int, err error) { + if !raceenabled { + return + } + for i := 0; n > 0 && i < len(iovecs); i++ { + m := int(iovecs[i].Len) + if m > n { + m = n + } + n -= m + if m > 0 { + raceWriteRange(unsafe.Pointer(iovecs[i].Base), m) + } + } + if err == nil { + raceAcquire(unsafe.Pointer(&ioSync)) + } +} + +func darwinMajorMinPatch() (maj, min, patch int, err error) { + var un Utsname + err = Uname(&un) + if err != nil { + return + } + + var mmp [3]int + c := 0 +Loop: + for _, b := range un.Release[:] { + switch { + case b >= '0' && b <= '9': + mmp[c] = 10*mmp[c] + int(b-'0') + case b == '.': + c++ + if c > 2 { + return 0, 0, 0, ENOTSUP + } + case b == 0: + break Loop + default: + return 0, 0, 0, ENOTSUP + } + } + if c != 2 { + return 0, 0, 0, ENOTSUP + } + return mmp[0], mmp[1], mmp[2], nil +} + +func darwinKernelVersionMin(maj, min, patch int) bool { + actualMaj, actualMin, actualPatch, err := darwinMajorMinPatch() + if err != nil { + return false + } + return actualMaj > maj || actualMaj == maj && (actualMin > min || actualMin == min && actualPatch >= patch) +} + //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) @@ -705,3 +848,7 @@ func Connectx(fd int, srcIf uint32, srcAddr, dstAddr Sockaddr, associd SaeAssocI //sys write(fd int, p []byte) (n int, err error) //sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) //sys munmap(addr uintptr, length uintptr) (err error) +//sys readv(fd int, iovecs []Iovec) (n int, err error) +//sys preadv(fd int, iovecs []Iovec, offset int64) (n int, err error) +//sys writev(fd int, iovecs []Iovec) (n int, err error) +//sys pwritev(fd int, iovecs []Iovec, offset int64) (n int, err error) diff --git a/unix/zsyscall_darwin_amd64.go b/unix/zsyscall_darwin_amd64.go index 24b346e1a3..813c05b664 100644 --- a/unix/zsyscall_darwin_amd64.go +++ b/unix/zsyscall_darwin_amd64.go @@ -2512,6 +2512,90 @@ var libc_munmap_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func readv(fd int, iovecs []Iovec) (n int, err error) { + var _p0 unsafe.Pointer + if len(iovecs) > 0 { + _p0 = unsafe.Pointer(&iovecs[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall(libc_readv_trampoline_addr, uintptr(fd), uintptr(_p0), uintptr(len(iovecs))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_readv_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_readv readv "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func preadv(fd int, iovecs []Iovec, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(iovecs) > 0 { + _p0 = unsafe.Pointer(&iovecs[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall6(libc_preadv_trampoline_addr, uintptr(fd), uintptr(_p0), uintptr(len(iovecs)), uintptr(offset), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_preadv_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_preadv preadv "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writev(fd int, iovecs []Iovec) (n int, err error) { + var _p0 unsafe.Pointer + if len(iovecs) > 0 { + _p0 = unsafe.Pointer(&iovecs[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall(libc_writev_trampoline_addr, uintptr(fd), uintptr(_p0), uintptr(len(iovecs))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_writev_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_writev writev "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pwritev(fd int, iovecs []Iovec, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(iovecs) > 0 { + _p0 = unsafe.Pointer(&iovecs[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall6(libc_pwritev_trampoline_addr, uintptr(fd), uintptr(_p0), uintptr(len(iovecs)), uintptr(offset), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pwritev_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pwritev pwritev "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Fstat(fd int, stat *Stat_t) (err error) { _, _, e1 := syscall_syscall(libc_fstat64_trampoline_addr, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) if e1 != 0 { diff --git a/unix/zsyscall_darwin_amd64.s b/unix/zsyscall_darwin_amd64.s index ebd213100b..fda328582b 100644 --- a/unix/zsyscall_darwin_amd64.s +++ b/unix/zsyscall_darwin_amd64.s @@ -738,6 +738,26 @@ TEXT libc_munmap_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_munmap_trampoline_addr(SB), RODATA, $8 DATA ·libc_munmap_trampoline_addr(SB)/8, $libc_munmap_trampoline<>(SB) +TEXT libc_readv_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_readv(SB) +GLOBL ·libc_readv_trampoline_addr(SB), RODATA, $8 +DATA ·libc_readv_trampoline_addr(SB)/8, $libc_readv_trampoline<>(SB) + +TEXT libc_preadv_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_preadv(SB) +GLOBL ·libc_preadv_trampoline_addr(SB), RODATA, $8 +DATA ·libc_preadv_trampoline_addr(SB)/8, $libc_preadv_trampoline<>(SB) + +TEXT libc_writev_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_writev(SB) +GLOBL ·libc_writev_trampoline_addr(SB), RODATA, $8 +DATA ·libc_writev_trampoline_addr(SB)/8, $libc_writev_trampoline<>(SB) + +TEXT libc_pwritev_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pwritev(SB) +GLOBL ·libc_pwritev_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pwritev_trampoline_addr(SB)/8, $libc_pwritev_trampoline<>(SB) + TEXT libc_fstat64_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_fstat64(SB) GLOBL ·libc_fstat64_trampoline_addr(SB), RODATA, $8 diff --git a/unix/zsyscall_darwin_arm64.go b/unix/zsyscall_darwin_arm64.go index 824b9c2d5e..e6f58f3c6f 100644 --- a/unix/zsyscall_darwin_arm64.go +++ b/unix/zsyscall_darwin_arm64.go @@ -2512,6 +2512,90 @@ var libc_munmap_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func readv(fd int, iovecs []Iovec) (n int, err error) { + var _p0 unsafe.Pointer + if len(iovecs) > 0 { + _p0 = unsafe.Pointer(&iovecs[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall(libc_readv_trampoline_addr, uintptr(fd), uintptr(_p0), uintptr(len(iovecs))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_readv_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_readv readv "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func preadv(fd int, iovecs []Iovec, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(iovecs) > 0 { + _p0 = unsafe.Pointer(&iovecs[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall6(libc_preadv_trampoline_addr, uintptr(fd), uintptr(_p0), uintptr(len(iovecs)), uintptr(offset), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_preadv_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_preadv preadv "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func writev(fd int, iovecs []Iovec) (n int, err error) { + var _p0 unsafe.Pointer + if len(iovecs) > 0 { + _p0 = unsafe.Pointer(&iovecs[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall(libc_writev_trampoline_addr, uintptr(fd), uintptr(_p0), uintptr(len(iovecs))) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_writev_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_writev writev "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func pwritev(fd int, iovecs []Iovec, offset int64) (n int, err error) { + var _p0 unsafe.Pointer + if len(iovecs) > 0 { + _p0 = unsafe.Pointer(&iovecs[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + r0, _, e1 := syscall_syscall6(libc_pwritev_trampoline_addr, uintptr(fd), uintptr(_p0), uintptr(len(iovecs)), uintptr(offset), 0, 0) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +var libc_pwritev_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_pwritev pwritev "/usr/lib/libSystem.B.dylib" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Fstat(fd int, stat *Stat_t) (err error) { _, _, e1 := syscall_syscall(libc_fstat_trampoline_addr, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) if e1 != 0 { diff --git a/unix/zsyscall_darwin_arm64.s b/unix/zsyscall_darwin_arm64.s index 4f178a2293..7f8998b905 100644 --- a/unix/zsyscall_darwin_arm64.s +++ b/unix/zsyscall_darwin_arm64.s @@ -738,6 +738,26 @@ TEXT libc_munmap_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_munmap_trampoline_addr(SB), RODATA, $8 DATA ·libc_munmap_trampoline_addr(SB)/8, $libc_munmap_trampoline<>(SB) +TEXT libc_readv_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_readv(SB) +GLOBL ·libc_readv_trampoline_addr(SB), RODATA, $8 +DATA ·libc_readv_trampoline_addr(SB)/8, $libc_readv_trampoline<>(SB) + +TEXT libc_preadv_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_preadv(SB) +GLOBL ·libc_preadv_trampoline_addr(SB), RODATA, $8 +DATA ·libc_preadv_trampoline_addr(SB)/8, $libc_preadv_trampoline<>(SB) + +TEXT libc_writev_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_writev(SB) +GLOBL ·libc_writev_trampoline_addr(SB), RODATA, $8 +DATA ·libc_writev_trampoline_addr(SB)/8, $libc_writev_trampoline<>(SB) + +TEXT libc_pwritev_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_pwritev(SB) +GLOBL ·libc_pwritev_trampoline_addr(SB), RODATA, $8 +DATA ·libc_pwritev_trampoline_addr(SB)/8, $libc_pwritev_trampoline<>(SB) + TEXT libc_fstat_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_fstat(SB) GLOBL ·libc_fstat_trampoline_addr(SB), RODATA, $8 From c175b6ba6781614eadf22a0727389d97e25f72ee Mon Sep 17 00:00:00 2001 From: database64128 Date: Mon, 17 Mar 2025 08:42:26 +0000 Subject: [PATCH 11/14] windows: add cmsghdr and pktinfo structures - CMSGHDR from ws2def.h, corresponds to Cmsghdr in unix - IN_PKTINFO from ws2ipdef.h, corresponds to InetPktinfo in unix - IN6_PKTINFO from ws2ipdef.h, corresponds to Inet6Pktinfo in unix Change-Id: I74f6812588859c3a6080e6675df28998fc435965 GitHub-Last-Rev: 7377c793c687a74012e0ff3ce458eb2d8717ea72 GitHub-Pull-Request: golang/sys#246 Reviewed-on: https://go-review.googlesource.com/c/sys/+/658175 Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov Reviewed-by: Alex Brainman --- windows/types_windows.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/windows/types_windows.go b/windows/types_windows.go index fac0309d08..ad67df2fdb 100644 --- a/windows/types_windows.go +++ b/windows/types_windows.go @@ -1157,6 +1157,22 @@ type WSAMsg struct { Flags uint32 } +type WSACMSGHDR struct { + Len uintptr + Level int32 + Type int32 +} + +type IN_PKTINFO struct { + Addr [4]byte + Ifindex uint32 +} + +type IN6_PKTINFO struct { + Addr [16]byte + Ifindex uint32 +} + // Flags for WSASocket const ( WSA_FLAG_OVERLAPPED = 0x01 From 1c3b72f1c1fa7f3a3a355c7a963cd1c958135d01 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Mon, 24 Mar 2025 17:02:11 +0000 Subject: [PATCH 12/14] unix: update Linux kernel to 6.14 No new syscalls or constants in this release, just bumping the version number. Change-Id: I97f7e1092bb78d99342552ba18e1ea3cd40681f4 GitHub-Last-Rev: df5cca1a90e8d69769e164bcdaf165188bf04929 GitHub-Pull-Request: golang/sys#247 Reviewed-on: https://go-review.googlesource.com/c/sys/+/660375 Reviewed-by: Tobias Klauser Reviewed-by: Dmitri Shuralyov Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- unix/linux/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile index 2bbb21a37a..68fb9c3a5e 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 20 Jan 2025 -RUN git clone --branch v6.13 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux +# Linux Kernel: Released 24 Mar 2025 +RUN git clone --branch v6.14 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux # GNU C library: Released 29 Jan 2025 RUN git clone --branch release/2.41/master --depth 1 https://sourceware.org/git/glibc.git From 1b2bd6bb49091efddfc5ca87435bcea9e2090720 Mon Sep 17 00:00:00 2001 From: Douglas Danger Manley Date: Sat, 22 Mar 2025 17:40:25 -0400 Subject: [PATCH 13/14] windows: replace all StringToUTF16 calls with UTF16FromString `StringToUTF16` is deprecated and will panic if given an "invalid" string (in particular, one that has a null byte in it). The replacement function is `UTF16FromString`, and it returns an error if there was a problem. This change replaces all uses of `StringToUTF16` with `UTF16FromString`. The `service` struct now no longer stores a `string` name but rather a `*uint16` pointer to the name. It should not be possible to panic due to UTF16 string conversion at this point. Fixes golang/go#73006 Change-Id: Idce9cdbb4651fef8481f0cad19b5df0314fd4277 Reviewed-on: https://go-review.googlesource.com/c/sys/+/659936 Reviewed-by: Carlos Amedee Auto-Submit: Carlos Amedee LUCI-TryBot-Result: Go LUCI Reviewed-by: Alex Brainman TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov --- windows/registry/key.go | 13 ++++++++-- windows/registry/value.go | 6 ++++- windows/svc/eventlog/log.go | 20 ++++++++++++--- windows/svc/mgr/config.go | 34 +++++++++++++++++++++---- windows/svc/mgr/mgr.go | 49 +++++++++++++++++++++++++++++++------ windows/svc/mgr/recovery.go | 14 +++++++++-- windows/svc/mgr/service.go | 6 ++++- windows/svc/service.go | 20 +++++++++------ 8 files changed, 132 insertions(+), 30 deletions(-) diff --git a/windows/registry/key.go b/windows/registry/key.go index fd8632444e..39aeeb644f 100644 --- a/windows/registry/key.go +++ b/windows/registry/key.go @@ -164,7 +164,12 @@ loopItems: func CreateKey(k Key, path string, access uint32) (newk Key, openedExisting bool, err error) { var h syscall.Handle var d uint32 - err = regCreateKeyEx(syscall.Handle(k), syscall.StringToUTF16Ptr(path), + var pathPointer *uint16 + pathPointer, err = syscall.UTF16PtrFromString(path) + if err != nil { + return 0, false, err + } + err = regCreateKeyEx(syscall.Handle(k), pathPointer, 0, nil, _REG_OPTION_NON_VOLATILE, access, nil, &h, &d) if err != nil { return 0, false, err @@ -174,7 +179,11 @@ func CreateKey(k Key, path string, access uint32) (newk Key, openedExisting bool // DeleteKey deletes the subkey path of key k and its values. func DeleteKey(k Key, path string) error { - return regDeleteKey(syscall.Handle(k), syscall.StringToUTF16Ptr(path)) + pathPointer, err := syscall.UTF16PtrFromString(path) + if err != nil { + return err + } + return regDeleteKey(syscall.Handle(k), pathPointer) } // A KeyInfo describes the statistics of a key. It is returned by Stat. diff --git a/windows/registry/value.go b/windows/registry/value.go index 74db26b94d..a1bcbb2362 100644 --- a/windows/registry/value.go +++ b/windows/registry/value.go @@ -340,7 +340,11 @@ func (k Key) SetBinaryValue(name string, value []byte) error { // DeleteValue removes a named value from the key k. func (k Key) DeleteValue(name string) error { - return regDeleteValue(syscall.Handle(k), syscall.StringToUTF16Ptr(name)) + namePointer, err := syscall.UTF16PtrFromString(name) + if err != nil { + return err + } + return regDeleteValue(syscall.Handle(k), namePointer) } // ReadValueNames returns the value names of key k. diff --git a/windows/svc/eventlog/log.go b/windows/svc/eventlog/log.go index f279444d98..ad40c2f48b 100644 --- a/windows/svc/eventlog/log.go +++ b/windows/svc/eventlog/log.go @@ -29,11 +29,19 @@ func OpenRemote(host, source string) (*Log, error) { if source == "" { return nil, errors.New("Specify event log source") } - var s *uint16 + var hostPointer *uint16 if host != "" { - s = syscall.StringToUTF16Ptr(host) + var err error + hostPointer, err = syscall.UTF16PtrFromString(host) + if err != nil { + return nil, err + } } - h, err := windows.RegisterEventSource(s, syscall.StringToUTF16Ptr(source)) + sourcePointer, err := syscall.UTF16PtrFromString(source) + if err != nil { + return nil, err + } + h, err := windows.RegisterEventSource(hostPointer, sourcePointer) if err != nil { return nil, err } @@ -46,7 +54,11 @@ func (l *Log) Close() error { } func (l *Log) report(etype uint16, eid uint32, msg string) error { - ss := []*uint16{syscall.StringToUTF16Ptr(msg)} + msgPointer, err := syscall.UTF16PtrFromString(msg) + if err != nil { + return err + } + ss := []*uint16{msgPointer} return windows.ReportEvent(l.Handle, etype, 0, eid, 0, 1, 0, &ss[0], nil) } diff --git a/windows/svc/mgr/config.go b/windows/svc/mgr/config.go index 3c7ba08f58..ec01f96eba 100644 --- a/windows/svc/mgr/config.go +++ b/windows/svc/mgr/config.go @@ -121,7 +121,11 @@ func (s *Service) Config() (Config, error) { } func updateDescription(handle windows.Handle, desc string) error { - d := windows.SERVICE_DESCRIPTION{Description: toPtr(desc)} + descPointer, err := toPtr(desc) + if err != nil { + return err + } + d := windows.SERVICE_DESCRIPTION{Description: descPointer} return windows.ChangeServiceConfig2(handle, windows.SERVICE_CONFIG_DESCRIPTION, (*byte)(unsafe.Pointer(&d))) } @@ -141,10 +145,30 @@ func updateStartUp(handle windows.Handle, isDelayed bool) error { // UpdateConfig updates service s configuration parameters. func (s *Service) UpdateConfig(c Config) error { - err := windows.ChangeServiceConfig(s.Handle, c.ServiceType, c.StartType, - c.ErrorControl, toPtr(c.BinaryPathName), toPtr(c.LoadOrderGroup), - nil, toStringBlock(c.Dependencies), toPtr(c.ServiceStartName), - toPtr(c.Password), toPtr(c.DisplayName)) + binaryPathNamePointer, err := toPtr(c.BinaryPathName) + if err != nil { + return err + } + loadOrderGroupPointer, err := toPtr(c.LoadOrderGroup) + if err != nil { + return err + } + serviceStartNamePointer, err := toPtr(c.ServiceStartName) + if err != nil { + return err + } + passwordPointer, err := toPtr(c.Password) + if err != nil { + return err + } + displayNamePointer, err := toPtr(c.DisplayName) + if err != nil { + return err + } + err = windows.ChangeServiceConfig(s.Handle, c.ServiceType, c.StartType, + c.ErrorControl, binaryPathNamePointer, loadOrderGroupPointer, + nil, toStringBlock(c.Dependencies), serviceStartNamePointer, + passwordPointer, displayNamePointer) if err != nil { return err } diff --git a/windows/svc/mgr/mgr.go b/windows/svc/mgr/mgr.go index dbfd729fec..74755940a1 100644 --- a/windows/svc/mgr/mgr.go +++ b/windows/svc/mgr/mgr.go @@ -34,7 +34,11 @@ func Connect() (*Mgr, error) { func ConnectRemote(host string) (*Mgr, error) { var s *uint16 if host != "" { - s = syscall.StringToUTF16Ptr(host) + var err error + s, err = syscall.UTF16PtrFromString(host) + if err != nil { + return nil, err + } } h, err := windows.OpenSCManager(s, nil, windows.SC_MANAGER_ALL_ACCESS) if err != nil { @@ -78,11 +82,11 @@ func (m *Mgr) LockStatus() (*LockStatus, error) { } } -func toPtr(s string) *uint16 { +func toPtr(s string) (*uint16, error) { if len(s) == 0 { - return nil + return nil, nil } - return syscall.StringToUTF16Ptr(s) + return syscall.UTF16PtrFromString(s) } // toStringBlock terminates strings in ss with 0, and then @@ -122,10 +126,34 @@ func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Se for _, v := range args { s += " " + syscall.EscapeArg(v) } - h, err := windows.CreateService(m.Handle, toPtr(name), toPtr(c.DisplayName), + namePointer, err := toPtr(name) + if err != nil { + return nil, err + } + displayNamePointer, err := toPtr(c.DisplayName) + if err != nil { + return nil, err + } + sPointer, err := toPtr(s) + if err != nil { + return nil, err + } + loadOrderGroupPointer, err := toPtr(c.LoadOrderGroup) + if err != nil { + return nil, err + } + serviceStartNamePointer, err := toPtr(c.ServiceStartName) + if err != nil { + return nil, err + } + passwordPointer, err := toPtr(c.Password) + if err != nil { + return nil, err + } + h, err := windows.CreateService(m.Handle, namePointer, displayNamePointer, windows.SERVICE_ALL_ACCESS, c.ServiceType, - c.StartType, c.ErrorControl, toPtr(s), toPtr(c.LoadOrderGroup), - nil, toStringBlock(c.Dependencies), toPtr(c.ServiceStartName), toPtr(c.Password)) + c.StartType, c.ErrorControl, sPointer, loadOrderGroupPointer, + nil, toStringBlock(c.Dependencies), serviceStartNamePointer, passwordPointer) if err != nil { return nil, err } @@ -159,7 +187,12 @@ func (m *Mgr) CreateService(name, exepath string, c Config, args ...string) (*Se // OpenService retrieves access to service name, so it can // be interrogated and controlled. func (m *Mgr) OpenService(name string) (*Service, error) { - h, err := windows.OpenService(m.Handle, syscall.StringToUTF16Ptr(name), windows.SERVICE_ALL_ACCESS) + namePointer, err := syscall.UTF16PtrFromString(name) + if err != nil { + return nil, err + } + + h, err := windows.OpenService(m.Handle, namePointer, windows.SERVICE_ALL_ACCESS) if err != nil { return nil, err } diff --git a/windows/svc/mgr/recovery.go b/windows/svc/mgr/recovery.go index ef2a687840..1a07374838 100644 --- a/windows/svc/mgr/recovery.go +++ b/windows/svc/mgr/recovery.go @@ -99,8 +99,13 @@ func (s *Service) ResetPeriod() (uint32, error) { // SetRebootMessage sets service s reboot message. // If msg is "", the reboot message is deleted and no message is broadcast. func (s *Service) SetRebootMessage(msg string) error { + msgPointer, err := syscall.UTF16PtrFromString(msg) + if err != nil { + return err + } + rActions := windows.SERVICE_FAILURE_ACTIONS{ - RebootMsg: syscall.StringToUTF16Ptr(msg), + RebootMsg: msgPointer, } return windows.ChangeServiceConfig2(s.Handle, windows.SERVICE_CONFIG_FAILURE_ACTIONS, (*byte)(unsafe.Pointer(&rActions))) } @@ -118,8 +123,13 @@ func (s *Service) RebootMessage() (string, error) { // SetRecoveryCommand sets the command line of the process to execute in response to the RunCommand service controller action. // If cmd is "", the command is deleted and no program is run when the service fails. func (s *Service) SetRecoveryCommand(cmd string) error { + cmdPointer, err := syscall.UTF16PtrFromString(cmd) + if err != nil { + return err + } + rActions := windows.SERVICE_FAILURE_ACTIONS{ - Command: syscall.StringToUTF16Ptr(cmd), + Command: cmdPointer, } return windows.ChangeServiceConfig2(s.Handle, windows.SERVICE_CONFIG_FAILURE_ACTIONS, (*byte)(unsafe.Pointer(&rActions))) } diff --git a/windows/svc/mgr/service.go b/windows/svc/mgr/service.go index c9740ef0ce..9f59eab754 100644 --- a/windows/svc/mgr/service.go +++ b/windows/svc/mgr/service.go @@ -37,7 +37,11 @@ func (s *Service) Start(args ...string) error { if len(args) > 0 { vs := make([]*uint16, len(args)) for i := range vs { - vs[i] = syscall.StringToUTF16Ptr(args[i]) + argPointer, err := syscall.UTF16PtrFromString(args[i]) + if err != nil { + return err + } + vs[i] = argPointer } p = &vs[0] } diff --git a/windows/svc/service.go b/windows/svc/service.go index c4f74924dd..a9b1c192d3 100644 --- a/windows/svc/service.go +++ b/windows/svc/service.go @@ -132,10 +132,10 @@ type ctlEvent struct { // service provides access to windows service api. type service struct { - name string - h windows.Handle - c chan ctlEvent - handler Handler + namePointer *uint16 + h windows.Handle + c chan ctlEvent + handler Handler } type exitCode struct { @@ -209,7 +209,7 @@ var theService service // This is, unfortunately, a global, which means only one // serviceMain is the entry point called by the service manager, registered earlier by // the call to StartServiceCtrlDispatcher. func serviceMain(argc uint32, argv **uint16) uintptr { - handle, err := windows.RegisterServiceCtrlHandlerEx(windows.StringToUTF16Ptr(theService.name), ctlHandlerCallback, 0) + handle, err := windows.RegisterServiceCtrlHandlerEx(theService.namePointer, ctlHandlerCallback, 0) if sysErr, ok := err.(windows.Errno); ok { return uintptr(sysErr) } else if err != nil { @@ -280,15 +280,21 @@ loop: // Run executes service name by calling appropriate handler function. func Run(name string, handler Handler) error { + // Check to make sure that the service name is valid. + namePointer, err := windows.UTF16PtrFromString(name) + if err != nil { + return err + } + initCallbacks.Do(func() { ctlHandlerCallback = windows.NewCallback(ctlHandler) serviceMainCallback = windows.NewCallback(serviceMain) }) - theService.name = name + theService.namePointer = namePointer theService.handler = handler theService.c = make(chan ctlEvent) t := []windows.SERVICE_TABLE_ENTRY{ - {ServiceName: windows.StringToUTF16Ptr(theService.name), ServiceProc: serviceMainCallback}, + {ServiceName: namePointer, ServiceProc: serviceMainCallback}, {ServiceName: nil, ServiceProc: 0}, } return windows.StartServiceCtrlDispatcher(&t[0]) From 01aaa8342f9d6e36356d05d0baff28e64ee6367e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 1 Apr 2025 11:05:11 +0200 Subject: [PATCH 14/14] all: simplify code by using modern Go constructs Generated using modernize by running: go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... Change-Id: Ifc7d61cf6735cc53f2bdf890a338961f55075af5 Reviewed-on: https://go-review.googlesource.com/c/sys/+/661975 Auto-Submit: Tobias Klauser Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov --- cpu/parse.go | 4 +-- unix/dirent_test.go | 2 +- unix/fdset_test.go | 10 +++---- unix/internal/mkmerge/mkmerge.go | 4 +-- unix/internal/mkmerge/mkmerge_test.go | 2 +- unix/syscall_linux.go | 42 ++++++++++----------------- unix/syscall_linux_test.go | 6 ++-- unix/xattr_test.go | 17 ++--------- 8 files changed, 33 insertions(+), 54 deletions(-) diff --git a/cpu/parse.go b/cpu/parse.go index 762b63d688..56a7e1a176 100644 --- a/cpu/parse.go +++ b/cpu/parse.go @@ -13,7 +13,7 @@ import "strconv" // https://golang.org/cl/209597. func parseRelease(rel string) (major, minor, patch int, ok bool) { // Strip anything after a dash or plus. - for i := 0; i < len(rel); i++ { + for i := range len(rel) { if rel[i] == '-' || rel[i] == '+' { rel = rel[:i] break @@ -21,7 +21,7 @@ func parseRelease(rel string) (major, minor, patch int, ok bool) { } next := func() (int, bool) { - for i := 0; i < len(rel); i++ { + for i := range len(rel) { if rel[i] == '.' { ver, err := strconv.Atoi(rel[:i]) rel = rel[i+1:] diff --git a/unix/dirent_test.go b/unix/dirent_test.go index e47d091d7f..f209fa1fc7 100644 --- a/unix/dirent_test.go +++ b/unix/dirent_test.go @@ -107,7 +107,7 @@ func TestDirentRepeat(t *testing.T) { d := t.TempDir() var files []string - for i := 0; i < N; i++ { + for i := range N { files = append(files, fmt.Sprintf("file%d", i)) } for _, file := range files { diff --git a/unix/fdset_test.go b/unix/fdset_test.go index 26d05c7a52..7d08f691dc 100644 --- a/unix/fdset_test.go +++ b/unix/fdset_test.go @@ -15,21 +15,21 @@ import ( func TestFdSet(t *testing.T) { var fdSet unix.FdSet fdSet.Zero() - for fd := 0; fd < unix.FD_SETSIZE; fd++ { + for fd := range unix.FD_SETSIZE { if fdSet.IsSet(fd) { t.Fatalf("Zero did not clear fd %d", fd) } fdSet.Set(fd) } - for fd := 0; fd < unix.FD_SETSIZE; fd++ { + for fd := range unix.FD_SETSIZE { if !fdSet.IsSet(fd) { t.Fatalf("IsSet(%d): expected true, got false", fd) } } fdSet.Zero() - for fd := 0; fd < unix.FD_SETSIZE; fd++ { + for fd := range unix.FD_SETSIZE { if fdSet.IsSet(fd) { t.Fatalf("Zero did not clear fd %d", fd) } @@ -39,7 +39,7 @@ func TestFdSet(t *testing.T) { fdSet.Set(fd) } - for fd := 0; fd < unix.FD_SETSIZE; fd++ { + for fd := range unix.FD_SETSIZE { if fd&0x1 == 0x1 { if !fdSet.IsSet(fd) { t.Fatalf("IsSet(%d): expected true, got false", fd) @@ -55,7 +55,7 @@ func TestFdSet(t *testing.T) { fdSet.Clear(fd) } - for fd := 0; fd < unix.FD_SETSIZE; fd++ { + for fd := range unix.FD_SETSIZE { if fdSet.IsSet(fd) { t.Fatalf("Clear(%d) did not clear fd", fd) } diff --git a/unix/internal/mkmerge/mkmerge.go b/unix/internal/mkmerge/mkmerge.go index 52f1d12bb2..06a6900647 100644 --- a/unix/internal/mkmerge/mkmerge.go +++ b/unix/internal/mkmerge/mkmerge.go @@ -137,7 +137,7 @@ type filterFn func(codeElem) bool // filter parses and filters Go source code from src, removing top // level declarations using keep as predicate. // For src parameter, please see docs for parser.ParseFile. -func filter(src interface{}, keep filterFn) ([]byte, error) { +func filter(src any, keep filterFn) ([]byte, error) { // Parse the src into an ast fset := token.NewFileSet() f, err := parser.ParseFile(fset, "", src, parser.ParseComments) @@ -243,7 +243,7 @@ func getCommonSet(files []srcFile) (*codeSet, error) { // getCodeSet returns the set of all top-level consts, types, and funcs from src. // src must be string, []byte, or io.Reader (see go/parser.ParseFile docs) -func getCodeSet(src interface{}) (*codeSet, error) { +func getCodeSet(src any) (*codeSet, error) { set := newCodeSet() fset := token.NewFileSet() diff --git a/unix/internal/mkmerge/mkmerge_test.go b/unix/internal/mkmerge/mkmerge_test.go index 2566dad9e0..29b584dd21 100644 --- a/unix/internal/mkmerge/mkmerge_test.go +++ b/unix/internal/mkmerge/mkmerge_test.go @@ -498,7 +498,7 @@ func diffLines(t *testing.T, got, expected []byte) { func addLineNr(src []byte) []byte { lines := bytes.Split(src, []byte("\n")) for i, line := range lines { - lines[i] = []byte(fmt.Sprintf("%d: %s", i+1, line)) + lines[i] = fmt.Appendf(nil, "%d: %s", i+1, line) } return bytes.Join(lines, []byte("\n")) } diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 230a94549a..4958a65708 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -13,6 +13,7 @@ package unix import ( "encoding/binary" + "slices" "strconv" "syscall" "time" @@ -417,7 +418,7 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) { return nil, 0, EINVAL } sa.raw.Family = AF_UNIX - for i := 0; i < n; i++ { + for i := range n { sa.raw.Path[i] = int8(name[i]) } // length is family (uint16), name, NUL. @@ -507,7 +508,7 @@ func (sa *SockaddrL2) sockaddr() (unsafe.Pointer, _Socklen, error) { psm := (*[2]byte)(unsafe.Pointer(&sa.raw.Psm)) psm[0] = byte(sa.PSM) psm[1] = byte(sa.PSM >> 8) - for i := 0; i < len(sa.Addr); i++ { + for i := range len(sa.Addr) { sa.raw.Bdaddr[i] = sa.Addr[len(sa.Addr)-1-i] } cid := (*[2]byte)(unsafe.Pointer(&sa.raw.Cid)) @@ -589,11 +590,11 @@ func (sa *SockaddrCAN) sockaddr() (unsafe.Pointer, _Socklen, error) { sa.raw.Family = AF_CAN sa.raw.Ifindex = int32(sa.Ifindex) rx := (*[4]byte)(unsafe.Pointer(&sa.RxID)) - for i := 0; i < 4; i++ { + for i := range 4 { sa.raw.Addr[i] = rx[i] } tx := (*[4]byte)(unsafe.Pointer(&sa.TxID)) - for i := 0; i < 4; i++ { + for i := range 4 { sa.raw.Addr[i+4] = tx[i] } return unsafe.Pointer(&sa.raw), SizeofSockaddrCAN, nil @@ -618,11 +619,11 @@ func (sa *SockaddrCANJ1939) sockaddr() (unsafe.Pointer, _Socklen, error) { sa.raw.Family = AF_CAN sa.raw.Ifindex = int32(sa.Ifindex) n := (*[8]byte)(unsafe.Pointer(&sa.Name)) - for i := 0; i < 8; i++ { + for i := range 8 { sa.raw.Addr[i] = n[i] } p := (*[4]byte)(unsafe.Pointer(&sa.PGN)) - for i := 0; i < 4; i++ { + for i := range 4 { sa.raw.Addr[i+8] = p[i] } sa.raw.Addr[12] = sa.Addr @@ -911,7 +912,7 @@ func (sa *SockaddrIUCV) sockaddr() (unsafe.Pointer, _Socklen, error) { // These are EBCDIC encoded by the kernel, but we still need to pad them // with blanks. Initializing with blanks allows the caller to feed in either // a padded or an unpadded string. - for i := 0; i < 8; i++ { + for i := range 8 { sa.raw.Nodeid[i] = ' ' sa.raw.User_id[i] = ' ' sa.raw.Name[i] = ' ' @@ -1148,7 +1149,7 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) { var user [8]byte var name [8]byte - for i := 0; i < 8; i++ { + for i := range 8 { user[i] = byte(pp.User_id[i]) name[i] = byte(pp.Name[i]) } @@ -1173,11 +1174,11 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) { Ifindex: int(pp.Ifindex), } name := (*[8]byte)(unsafe.Pointer(&sa.Name)) - for i := 0; i < 8; i++ { + for i := range 8 { name[i] = pp.Addr[i] } pgn := (*[4]byte)(unsafe.Pointer(&sa.PGN)) - for i := 0; i < 4; i++ { + for i := range 4 { pgn[i] = pp.Addr[i+8] } addr := (*[1]byte)(unsafe.Pointer(&sa.Addr)) @@ -1188,11 +1189,11 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) { Ifindex: int(pp.Ifindex), } rx := (*[4]byte)(unsafe.Pointer(&sa.RxID)) - for i := 0; i < 4; i++ { + for i := range 4 { rx[i] = pp.Addr[i] } tx := (*[4]byte)(unsafe.Pointer(&sa.TxID)) - for i := 0; i < 4; i++ { + for i := range 4 { tx[i] = pp.Addr[i+4] } return sa, nil @@ -2216,10 +2217,7 @@ func readvRacedetect(iovecs []Iovec, n int, err error) { return } for i := 0; n > 0 && i < len(iovecs); i++ { - m := int(iovecs[i].Len) - if m > n { - m = n - } + m := min(int(iovecs[i].Len), n) n -= m if m > 0 { raceWriteRange(unsafe.Pointer(iovecs[i].Base), m) @@ -2270,10 +2268,7 @@ func writevRacedetect(iovecs []Iovec, n int) { return } for i := 0; n > 0 && i < len(iovecs); i++ { - m := int(iovecs[i].Len) - if m > n { - m = n - } + m := min(int(iovecs[i].Len), n) n -= m if m > 0 { raceReadRange(unsafe.Pointer(iovecs[i].Base), m) @@ -2320,12 +2315,7 @@ func isGroupMember(gid int) bool { return false } - for _, g := range groups { - if g == gid { - return true - } - } - return false + return slices.Contains(groups, gid) } func isCapDacOverrideSet() bool { diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index d4ed88726d..d3075ca74c 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -367,7 +367,7 @@ func TestTime(t *testing.T) { var now time.Time - for i := 0; i < 10; i++ { + for range 10 { ut, err = unix.Time(nil) if err != nil { t.Fatalf("Time: %v", err) @@ -555,7 +555,7 @@ func TestSchedSetaffinity(t *testing.T) { cpu = 1 if !oldMask.IsSet(cpu) { newMask.Zero() - for i := 0; i < len(oldMask); i++ { + for i := range len(oldMask) { if oldMask.IsSet(i) { newMask.Set(i) break @@ -878,7 +878,7 @@ func openMountByID(mountID int) (f *os.File, err error) { } defer mi.Close() bs := bufio.NewScanner(mi) - wantPrefix := []byte(fmt.Sprintf("%v ", mountID)) + wantPrefix := fmt.Appendf(nil, "%v ", mountID) for bs.Scan() { if !bytes.HasPrefix(bs.Bytes(), wantPrefix) { continue diff --git a/unix/xattr_test.go b/unix/xattr_test.go index dfa208f160..3b5111497c 100644 --- a/unix/xattr_test.go +++ b/unix/xattr_test.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" "runtime" + "slices" "strings" "testing" @@ -62,13 +63,7 @@ func TestXattr(t *testing.T) { // name and Listxattr doesn't return the namespace prefix. xattrWant = strings.TrimPrefix(xattrWant, "user.") } - found := false - for _, name := range xattrs { - if name == xattrWant { - found = true - break - } - } + found := slices.Contains(xattrs, xattrWant) if !found { t.Errorf("Listxattr did not return previously set attribute %q in attributes %v", xattrName, xattrs) @@ -170,13 +165,7 @@ func TestFdXattr(t *testing.T) { // name and Listxattr doesn't return the namespace prefix. xattrWant = strings.TrimPrefix(xattrWant, "user.") } - found := false - for _, name := range xattrs { - if name == xattrWant { - found = true - break - } - } + found := slices.Contains(xattrs, xattrWant) if !found { t.Errorf("Flistxattr did not return previously set attribute %q in attributes %v", xattrName, xattrs)