From 0d9df52791630c612e0b2feaa34e6856d9ad75bf Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Wed, 3 Jan 2024 21:27:29 +0100 Subject: [PATCH 1/9] unix: add more SECCOMP constants Update the SECCOMP regex to fetch more SECCOMP constants. Change-Id: I192ff7cb11fc38f0b0f08d6cba0a4f8649f9775e Reviewed-on: https://go-review.googlesource.com/c/sys/+/553776 LUCI-TryBot-Result: Go LUCI Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Reviewed-by: Dmitri Shuralyov Auto-Submit: Tobias Klauser Reviewed-by: Matt Layher --- unix/mkerrors.sh | 2 +- unix/zerrors_linux.go | 29 +++++++++++++++++++++++++++++ unix/zerrors_linux_386.go | 3 +++ unix/zerrors_linux_amd64.go | 3 +++ unix/zerrors_linux_arm.go | 3 +++ unix/zerrors_linux_arm64.go | 3 +++ unix/zerrors_linux_loong64.go | 3 +++ unix/zerrors_linux_mips.go | 3 +++ unix/zerrors_linux_mips64.go | 3 +++ unix/zerrors_linux_mips64le.go | 3 +++ unix/zerrors_linux_mipsle.go | 3 +++ unix/zerrors_linux_ppc.go | 3 +++ unix/zerrors_linux_ppc64.go | 3 +++ unix/zerrors_linux_ppc64le.go | 3 +++ unix/zerrors_linux_riscv64.go | 3 +++ unix/zerrors_linux_s390x.go | 3 +++ unix/zerrors_linux_sparc64.go | 3 +++ 17 files changed, 75 insertions(+), 1 deletion(-) diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index c6492020ec..fdcaa974d2 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -584,7 +584,7 @@ ccflags="$@" $2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ || $2 ~ /^KEYCTL_/ || $2 ~ /^PERF_/ || - $2 ~ /^SECCOMP_MODE_/ || + $2 ~ /^SECCOMP_/ || $2 ~ /^SEEK_/ || $2 ~ /^SCHED_/ || $2 ~ /^SPLICE_/ || diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index a5d3ff8df9..f8351ca168 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -2913,9 +2913,38 @@ const ( SCM_RIGHTS = 0x1 SCM_TIMESTAMP = 0x1d SC_LOG_FLUSH = 0x100000 + SECCOMP_ADDFD_FLAG_SEND = 0x2 + SECCOMP_ADDFD_FLAG_SETFD = 0x1 + SECCOMP_FILTER_FLAG_LOG = 0x2 + SECCOMP_FILTER_FLAG_NEW_LISTENER = 0x8 + SECCOMP_FILTER_FLAG_SPEC_ALLOW = 0x4 + SECCOMP_FILTER_FLAG_TSYNC = 0x1 + SECCOMP_FILTER_FLAG_TSYNC_ESRCH = 0x10 + SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV = 0x20 + SECCOMP_GET_ACTION_AVAIL = 0x2 + SECCOMP_GET_NOTIF_SIZES = 0x3 + SECCOMP_IOCTL_NOTIF_RECV = 0xc0502100 + SECCOMP_IOCTL_NOTIF_SEND = 0xc0182101 + SECCOMP_IOC_MAGIC = '!' SECCOMP_MODE_DISABLED = 0x0 SECCOMP_MODE_FILTER = 0x2 SECCOMP_MODE_STRICT = 0x1 + SECCOMP_RET_ACTION = 0x7fff0000 + SECCOMP_RET_ACTION_FULL = 0xffff0000 + SECCOMP_RET_ALLOW = 0x7fff0000 + SECCOMP_RET_DATA = 0xffff + SECCOMP_RET_ERRNO = 0x50000 + SECCOMP_RET_KILL = 0x0 + SECCOMP_RET_KILL_PROCESS = 0x80000000 + SECCOMP_RET_KILL_THREAD = 0x0 + SECCOMP_RET_LOG = 0x7ffc0000 + SECCOMP_RET_TRACE = 0x7ff00000 + SECCOMP_RET_TRAP = 0x30000 + SECCOMP_RET_USER_NOTIF = 0x7fc00000 + SECCOMP_SET_MODE_FILTER = 0x1 + SECCOMP_SET_MODE_STRICT = 0x0 + SECCOMP_USER_NOTIF_FD_SYNC_WAKE_UP = 0x1 + SECCOMP_USER_NOTIF_FLAG_CONTINUE = 0x1 SECRETMEM_MAGIC = 0x5345434d SECURITYFS_MAGIC = 0x73636673 SEEK_CUR = 0x1 diff --git a/unix/zerrors_linux_386.go b/unix/zerrors_linux_386.go index 4920821cf3..42ff8c3c1b 100644 --- a/unix/zerrors_linux_386.go +++ b/unix/zerrors_linux_386.go @@ -281,6 +281,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x40082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x40082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_amd64.go b/unix/zerrors_linux_amd64.go index a0c1e41127..dca436004f 100644 --- a/unix/zerrors_linux_amd64.go +++ b/unix/zerrors_linux_amd64.go @@ -282,6 +282,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x40082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x40082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_arm.go b/unix/zerrors_linux_arm.go index c63985560f..5cca668ac3 100644 --- a/unix/zerrors_linux_arm.go +++ b/unix/zerrors_linux_arm.go @@ -288,6 +288,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x40082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x40082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_arm64.go b/unix/zerrors_linux_arm64.go index 47cc62e25c..d8cae6d153 100644 --- a/unix/zerrors_linux_arm64.go +++ b/unix/zerrors_linux_arm64.go @@ -278,6 +278,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x40082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x40082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_loong64.go b/unix/zerrors_linux_loong64.go index 27ac4a09e2..28e39afdcb 100644 --- a/unix/zerrors_linux_loong64.go +++ b/unix/zerrors_linux_loong64.go @@ -275,6 +275,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x40082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x40082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_mips.go b/unix/zerrors_linux_mips.go index 54694642a5..cd66e92cb4 100644 --- a/unix/zerrors_linux_mips.go +++ b/unix/zerrors_linux_mips.go @@ -281,6 +281,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x80082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x80082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x80 SIOCATMARK = 0x40047307 diff --git a/unix/zerrors_linux_mips64.go b/unix/zerrors_linux_mips64.go index 3adb81d758..c1595eba78 100644 --- a/unix/zerrors_linux_mips64.go +++ b/unix/zerrors_linux_mips64.go @@ -281,6 +281,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x80082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x80082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x80 SIOCATMARK = 0x40047307 diff --git a/unix/zerrors_linux_mips64le.go b/unix/zerrors_linux_mips64le.go index 2dfe98f0d1..ee9456b0da 100644 --- a/unix/zerrors_linux_mips64le.go +++ b/unix/zerrors_linux_mips64le.go @@ -281,6 +281,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x80082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x80082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x80 SIOCATMARK = 0x40047307 diff --git a/unix/zerrors_linux_mipsle.go b/unix/zerrors_linux_mipsle.go index f5398f84f0..8cfca81e1b 100644 --- a/unix/zerrors_linux_mipsle.go +++ b/unix/zerrors_linux_mipsle.go @@ -281,6 +281,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x80082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x80082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x80 SIOCATMARK = 0x40047307 diff --git a/unix/zerrors_linux_ppc.go b/unix/zerrors_linux_ppc.go index c54f152d68..60b0deb3af 100644 --- a/unix/zerrors_linux_ppc.go +++ b/unix/zerrors_linux_ppc.go @@ -336,6 +336,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x80082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x80082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_ppc64.go b/unix/zerrors_linux_ppc64.go index 76057dc72f..f90aa7281b 100644 --- a/unix/zerrors_linux_ppc64.go +++ b/unix/zerrors_linux_ppc64.go @@ -340,6 +340,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x80082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x80082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_ppc64le.go b/unix/zerrors_linux_ppc64le.go index e0c3725e2b..ba9e015033 100644 --- a/unix/zerrors_linux_ppc64le.go +++ b/unix/zerrors_linux_ppc64le.go @@ -340,6 +340,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x80082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x80082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_riscv64.go b/unix/zerrors_linux_riscv64.go index 18f2813ed5..07cdfd6e9f 100644 --- a/unix/zerrors_linux_riscv64.go +++ b/unix/zerrors_linux_riscv64.go @@ -272,6 +272,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x40082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x40082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_s390x.go b/unix/zerrors_linux_s390x.go index 11619d4ec8..2f1dd214a7 100644 --- a/unix/zerrors_linux_s390x.go +++ b/unix/zerrors_linux_s390x.go @@ -344,6 +344,9 @@ const ( SCM_TIMESTAMPNS = 0x23 SCM_TXTIME = 0x3d SCM_WIFI_STATUS = 0x29 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x40182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x40082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x40082104 SFD_CLOEXEC = 0x80000 SFD_NONBLOCK = 0x800 SIOCATMARK = 0x8905 diff --git a/unix/zerrors_linux_sparc64.go b/unix/zerrors_linux_sparc64.go index 396d994da7..f40519d901 100644 --- a/unix/zerrors_linux_sparc64.go +++ b/unix/zerrors_linux_sparc64.go @@ -335,6 +335,9 @@ const ( SCM_TIMESTAMPNS = 0x21 SCM_TXTIME = 0x3f SCM_WIFI_STATUS = 0x25 + SECCOMP_IOCTL_NOTIF_ADDFD = 0x80182103 + SECCOMP_IOCTL_NOTIF_ID_VALID = 0x80082102 + SECCOMP_IOCTL_NOTIF_SET_FLAGS = 0x80082104 SFD_CLOEXEC = 0x400000 SFD_NONBLOCK = 0x4000 SF_FP = 0x38 From f69d32aa924ffc151883ca55d803348ecf5ab540 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Wed, 10 Jan 2024 09:46:14 +0800 Subject: [PATCH 2/9] unix: in TestDirent, make as many ReadDirent calls as are needed This CL just port CL 376334 from main repo with minor modification. Fixes golang/go#65015 Change-Id: I327d33bde39a2fcb818e28bcb7ff524ca19c4a38 Reviewed-on: https://go-review.googlesource.com/c/sys/+/554875 Reviewed-by: Bryan Mills Run-TryBot: M Zhuo Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot --- unix/dirent_test.go | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/unix/dirent_test.go b/unix/dirent_test.go index c4911366d9..e47d091d7f 100644 --- a/unix/dirent_test.go +++ b/unix/dirent_test.go @@ -23,7 +23,7 @@ import ( func TestDirent(t *testing.T) { const ( - direntBufSize = 2048 + direntBufSize = 2048 // arbitrary? See https://go.dev/issue/37323. filenameMinSize = 11 ) @@ -38,26 +38,38 @@ func TestDirent(t *testing.T) { } } - buf := bytes.Repeat([]byte("DEADBEAF"), direntBufSize/8) + names := make([]string, 0, 10) + fd, err := unix.Open(d, unix.O_RDONLY, 0) if err != nil { t.Fatalf("Open: %v", err) } defer unix.Close(fd) - n, err := unix.ReadDirent(fd, buf) - if err != nil { - t.Fatalf("ReadDirent: %v", err) - } - buf = buf[:n] - names := make([]string, 0, 10) - for len(buf) > 0 { - var bc int - bc, _, names = unix.ParseDirent(buf, -1, names) - if bc == 0 && len(buf) > 0 { - t.Fatal("no progress") + buf := bytes.Repeat([]byte{0xCD}, direntBufSize) + for { + n, err := unix.ReadDirent(fd, buf) + if err == unix.EINVAL { + // On linux, 'man getdents64' says that EINVAL indicates result buffer is too small. + // Try a bigger buffer. + t.Logf("ReadDirent: %v; retrying with larger buffer", err) + buf = bytes.Repeat([]byte{0xCD}, len(buf)*2) + continue + } + if err != nil { + t.Fatalf("ReadDirent: %v", err) + } + t.Logf("ReadDirent: read %d bytes", n) + if n == 0 { + break + } + + var consumed, count int + consumed, count, names = unix.ParseDirent(buf[:n], -1, names) + t.Logf("ParseDirent: %d new name(s)", count) + if consumed != n { + t.Fatalf("ParseDirent: consumed %d bytes; expected %d", consumed, n) } - buf = buf[bc:] } sort.Strings(names) From c3fa2b8b4120c7313f31d04a946f0ae173fa9e7c Mon Sep 17 00:00:00 2001 From: Kamyar Mirzavaziri Date: Fri, 19 Jan 2024 04:14:25 +0330 Subject: [PATCH 3/9] windows: fix parsing of non-ASCII entries in token.Environ Fixes golang/go#65055, the unexpected behavior of token.Environ in parsing entries containing runes larger than 2 bytes in size Change-Id: I753d2c605e3a2d7a1d90cd18601d6b918f0d3f7a Reviewed-on: https://go-review.googlesource.com/c/sys/+/556895 Auto-Submit: Bryan Mills LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui Reviewed-by: Bryan Mills Reviewed-by: Quim Muntal --- windows/env_windows.go | 17 +++++++++------- windows/env_windows_test.go | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 windows/env_windows_test.go diff --git a/windows/env_windows.go b/windows/env_windows.go index b8ad192506..d4577a4238 100644 --- a/windows/env_windows.go +++ b/windows/env_windows.go @@ -37,14 +37,17 @@ func (token Token) Environ(inheritExisting bool) (env []string, err error) { return nil, err } defer DestroyEnvironmentBlock(block) - blockp := unsafe.Pointer(block) - for { - entry := UTF16PtrToString((*uint16)(blockp)) - if len(entry) == 0 { - break + size := unsafe.Sizeof(*block) + for *block != 0 { + // find NUL terminator + end := unsafe.Pointer(block) + for *(*uint16)(end) != 0 { + end = unsafe.Add(end, size) } - env = append(env, entry) - blockp = unsafe.Add(blockp, 2*(len(entry)+1)) + + entry := unsafe.Slice(block, (uintptr(end)-uintptr(unsafe.Pointer(block)))/size) + env = append(env, UTF16ToString(entry)) + block = (*uint16)(unsafe.Add(end, size)) } return env, nil } diff --git a/windows/env_windows_test.go b/windows/env_windows_test.go new file mode 100644 index 0000000000..6824e6ed64 --- /dev/null +++ b/windows/env_windows_test.go @@ -0,0 +1,40 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package windows_test + +import ( + "fmt" + "slices" + "testing" + + "golang.org/x/sys/windows" +) + +func TestEnvironUTF8(t *testing.T) { + testEnvVariable1Key := "__GO_X_SYS_WINDOWS_ENV_WINDOWS_TEST_VAR_BEAVER" + testEnvVariable1Val := "🦫" + t.Setenv(testEnvVariable1Key, testEnvVariable1Val) + + testEnvVariable2Key := "__GO_X_SYS_WINDOWS_ENV_WINDOWS_TEST_VAR_WHALE" + testEnvVariable2Val := "🐳" + t.Setenv(testEnvVariable2Key, testEnvVariable2Val) + + var userToken windows.Token + + env, err := userToken.Environ(true) + if err != nil { + t.Error(err) + } + + testEnvVariable1 := fmt.Sprintf("%s=%s", testEnvVariable1Key, testEnvVariable1Val) + if !slices.Contains(env, testEnvVariable1) { + t.Fatalf("expected to find %s in env", testEnvVariable1) + } + + testEnvVariable2 := fmt.Sprintf("%s=%s", testEnvVariable2Key, testEnvVariable2Val) + if !slices.Contains(env, testEnvVariable2) { + t.Fatalf("expected to find %s in env", testEnvVariable2) + } +} From b3ce6a356e5aebf797118325792d0410cca08caa Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 23 Jan 2024 15:34:02 -0500 Subject: [PATCH 4/9] windows: build env_windows_test.go only go Go 1.21 and above This test imports the "slices" package, which did not exist in Go 1.20. The test passes on Go 1.21 and above, and the behavior of the function under test is unlikely to vary by platform, so it doesn't seem worth refactoring the test to work with older releases. Updates golang/go#65055. Fixes golang/go#65223. Change-Id: I5f32106d6057b779579a87750633bc57f97fe152 Cq-Include-Trybots: luci.golang.try:x_sys-go1.20-windows-386,x_sys-go1.20-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/sys/+/557975 Auto-Submit: Bryan Mills Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- windows/env_windows_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/windows/env_windows_test.go b/windows/env_windows_test.go index 6824e6ed64..db1860e78d 100644 --- a/windows/env_windows_test.go +++ b/windows/env_windows_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +//go:build go1.21 + package windows_test import ( From 5710a32031f3498e357d801987a07d9638c4fa11 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Mon, 8 Jan 2024 13:53:30 +0000 Subject: [PATCH 5/9] unix/linux: update Linux kernel to 6.7 Change-Id: Ie0cc6803af5b3ede657ce516e657b0356cd91175 GitHub-Last-Rev: 255f0ebf45999353ac87205ffab11e34ddccb9ca GitHub-Pull-Request: golang/sys#185 Reviewed-on: https://go-review.googlesource.com/c/sys/+/554555 LUCI-TryBot-Result: Go LUCI TryBot-Result: Gopher Robot Run-TryBot: Mauri de Souza Meneguzzo Reviewed-by: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Cherry Mui Reviewed-by: Tobias Klauser --- unix/linux/Dockerfile | 4 +- unix/zerrors_linux.go | 7 +- unix/zsysnum_linux_386.go | 4 ++ unix/zsysnum_linux_amd64.go | 3 + 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 | 125 +++++++++++++++++---------------- 18 files changed, 132 insertions(+), 63 deletions(-) diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile index 312e0f7d16..50d8d8d825 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 30 October 2023 -RUN git clone --branch v6.6 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux +# Linux Kernel: Released 07 January 2024 +RUN git clone --branch v6.7 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux # GNU C library: Released 1 Feb 2023 RUN git clone --branch release/2.37/master --depth 1 https://sourceware.org/git/glibc.git diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index f8351ca168..36bf8399f4 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -1785,6 +1785,8 @@ const ( LANDLOCK_ACCESS_FS_REMOVE_FILE = 0x20 LANDLOCK_ACCESS_FS_TRUNCATE = 0x4000 LANDLOCK_ACCESS_FS_WRITE_FILE = 0x2 + LANDLOCK_ACCESS_NET_BIND_TCP = 0x1 + LANDLOCK_ACCESS_NET_CONNECT_TCP = 0x2 LANDLOCK_CREATE_RULESET_VERSION = 0x1 LINUX_REBOOT_CMD_CAD_OFF = 0x0 LINUX_REBOOT_CMD_CAD_ON = 0x89abcdef @@ -2465,6 +2467,7 @@ const ( PR_MCE_KILL_GET = 0x22 PR_MCE_KILL_LATE = 0x0 PR_MCE_KILL_SET = 0x1 + PR_MDWE_NO_INHERIT = 0x2 PR_MDWE_REFUSE_EXEC_GAIN = 0x1 PR_MPX_DISABLE_MANAGEMENT = 0x2c PR_MPX_ENABLE_MANAGEMENT = 0x2b @@ -2669,8 +2672,9 @@ const ( RTAX_FEATURES = 0xc RTAX_FEATURE_ALLFRAG = 0x8 RTAX_FEATURE_ECN = 0x1 - RTAX_FEATURE_MASK = 0xf + RTAX_FEATURE_MASK = 0x1f RTAX_FEATURE_SACK = 0x2 + RTAX_FEATURE_TCP_USEC_TS = 0x10 RTAX_FEATURE_TIMESTAMP = 0x4 RTAX_HOPLIMIT = 0xa RTAX_INITCWND = 0xb @@ -3104,6 +3108,7 @@ const ( SOL_TIPC = 0x10f SOL_TLS = 0x11a SOL_UDP = 0x11 + SOL_VSOCK = 0x11f SOL_X25 = 0x106 SOL_XDP = 0x11b SOMAXCONN = 0x1000 diff --git a/unix/zsysnum_linux_386.go b/unix/zsysnum_linux_386.go index fcf3ecbdde..0cc3ce496e 100644 --- a/unix/zsysnum_linux_386.go +++ b/unix/zsysnum_linux_386.go @@ -448,4 +448,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_amd64.go b/unix/zsysnum_linux_amd64.go index f56dc2504a..856d92d69e 100644 --- a/unix/zsysnum_linux_amd64.go +++ b/unix/zsysnum_linux_amd64.go @@ -371,4 +371,7 @@ const ( SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_arm.go b/unix/zsysnum_linux_arm.go index 974bf24676..8d467094cf 100644 --- a/unix/zsysnum_linux_arm.go +++ b/unix/zsysnum_linux_arm.go @@ -412,4 +412,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_arm64.go b/unix/zsysnum_linux_arm64.go index 39a2739e23..edc173244d 100644 --- a/unix/zsysnum_linux_arm64.go +++ b/unix/zsysnum_linux_arm64.go @@ -315,4 +315,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_loong64.go b/unix/zsysnum_linux_loong64.go index cf9c9d77e1..445eba2061 100644 --- a/unix/zsysnum_linux_loong64.go +++ b/unix/zsysnum_linux_loong64.go @@ -309,4 +309,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_mips.go b/unix/zsysnum_linux_mips.go index 10b7362ef4..adba01bca7 100644 --- a/unix/zsysnum_linux_mips.go +++ b/unix/zsysnum_linux_mips.go @@ -432,4 +432,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 4450 SYS_CACHESTAT = 4451 SYS_FCHMODAT2 = 4452 + SYS_MAP_SHADOW_STACK = 4453 + SYS_FUTEX_WAKE = 4454 + SYS_FUTEX_WAIT = 4455 + SYS_FUTEX_REQUEUE = 4456 ) diff --git a/unix/zsysnum_linux_mips64.go b/unix/zsysnum_linux_mips64.go index cd4d8b4fd3..014c4e9c7a 100644 --- a/unix/zsysnum_linux_mips64.go +++ b/unix/zsysnum_linux_mips64.go @@ -362,4 +362,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 5450 SYS_CACHESTAT = 5451 SYS_FCHMODAT2 = 5452 + SYS_MAP_SHADOW_STACK = 5453 + SYS_FUTEX_WAKE = 5454 + SYS_FUTEX_WAIT = 5455 + SYS_FUTEX_REQUEUE = 5456 ) diff --git a/unix/zsysnum_linux_mips64le.go b/unix/zsysnum_linux_mips64le.go index 2c0efca818..ccc97d74d0 100644 --- a/unix/zsysnum_linux_mips64le.go +++ b/unix/zsysnum_linux_mips64le.go @@ -362,4 +362,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 5450 SYS_CACHESTAT = 5451 SYS_FCHMODAT2 = 5452 + SYS_MAP_SHADOW_STACK = 5453 + SYS_FUTEX_WAKE = 5454 + SYS_FUTEX_WAIT = 5455 + SYS_FUTEX_REQUEUE = 5456 ) diff --git a/unix/zsysnum_linux_mipsle.go b/unix/zsysnum_linux_mipsle.go index a72e31d391..ec2b64a95d 100644 --- a/unix/zsysnum_linux_mipsle.go +++ b/unix/zsysnum_linux_mipsle.go @@ -432,4 +432,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 4450 SYS_CACHESTAT = 4451 SYS_FCHMODAT2 = 4452 + SYS_MAP_SHADOW_STACK = 4453 + SYS_FUTEX_WAKE = 4454 + SYS_FUTEX_WAIT = 4455 + SYS_FUTEX_REQUEUE = 4456 ) diff --git a/unix/zsysnum_linux_ppc.go b/unix/zsysnum_linux_ppc.go index c7d1e37471..21a839e338 100644 --- a/unix/zsysnum_linux_ppc.go +++ b/unix/zsysnum_linux_ppc.go @@ -439,4 +439,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_ppc64.go b/unix/zsysnum_linux_ppc64.go index f4d4838c87..c11121ec3b 100644 --- a/unix/zsysnum_linux_ppc64.go +++ b/unix/zsysnum_linux_ppc64.go @@ -411,4 +411,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_ppc64le.go b/unix/zsysnum_linux_ppc64le.go index b64f0e5911..909b631fcb 100644 --- a/unix/zsysnum_linux_ppc64le.go +++ b/unix/zsysnum_linux_ppc64le.go @@ -411,4 +411,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_riscv64.go b/unix/zsysnum_linux_riscv64.go index 95711195a0..e49bed16ea 100644 --- a/unix/zsysnum_linux_riscv64.go +++ b/unix/zsysnum_linux_riscv64.go @@ -316,4 +316,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_s390x.go b/unix/zsysnum_linux_s390x.go index f94e943bc4..66017d2d32 100644 --- a/unix/zsysnum_linux_s390x.go +++ b/unix/zsysnum_linux_s390x.go @@ -377,4 +377,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/zsysnum_linux_sparc64.go b/unix/zsysnum_linux_sparc64.go index ba0c2bc515..47bab18dce 100644 --- a/unix/zsysnum_linux_sparc64.go +++ b/unix/zsysnum_linux_sparc64.go @@ -390,4 +390,8 @@ const ( SYS_SET_MEMPOLICY_HOME_NODE = 450 SYS_CACHESTAT = 451 SYS_FCHMODAT2 = 452 + SYS_MAP_SHADOW_STACK = 453 + SYS_FUTEX_WAKE = 454 + SYS_FUTEX_WAIT = 455 + SYS_FUTEX_REQUEUE = 456 ) diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index bbf8399ff5..dc0c955eec 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -174,7 +174,8 @@ type FscryptPolicyV2 struct { Contents_encryption_mode uint8 Filenames_encryption_mode uint8 Flags uint8 - _ [4]uint8 + Log2_data_unit_size uint8 + _ [3]uint8 Master_key_identifier [16]uint8 } @@ -455,60 +456,63 @@ type Ucred struct { } type TCPInfo struct { - State uint8 - Ca_state uint8 - Retransmits uint8 - Probes uint8 - Backoff uint8 - Options uint8 - Rto uint32 - Ato uint32 - Snd_mss uint32 - Rcv_mss uint32 - Unacked uint32 - Sacked uint32 - Lost uint32 - Retrans uint32 - Fackets uint32 - Last_data_sent uint32 - Last_ack_sent uint32 - Last_data_recv uint32 - Last_ack_recv uint32 - Pmtu uint32 - Rcv_ssthresh uint32 - Rtt uint32 - Rttvar uint32 - Snd_ssthresh uint32 - Snd_cwnd uint32 - Advmss uint32 - Reordering uint32 - Rcv_rtt uint32 - Rcv_space uint32 - Total_retrans uint32 - Pacing_rate uint64 - Max_pacing_rate uint64 - Bytes_acked uint64 - Bytes_received uint64 - Segs_out uint32 - Segs_in uint32 - Notsent_bytes uint32 - Min_rtt uint32 - Data_segs_in uint32 - Data_segs_out uint32 - Delivery_rate uint64 - Busy_time uint64 - Rwnd_limited uint64 - Sndbuf_limited uint64 - Delivered uint32 - Delivered_ce uint32 - Bytes_sent uint64 - Bytes_retrans uint64 - Dsack_dups uint32 - Reord_seen uint32 - Rcv_ooopack uint32 - Snd_wnd uint32 - Rcv_wnd uint32 - Rehash uint32 + State uint8 + Ca_state uint8 + Retransmits uint8 + Probes uint8 + Backoff uint8 + Options uint8 + Rto uint32 + Ato uint32 + Snd_mss uint32 + Rcv_mss uint32 + Unacked uint32 + Sacked uint32 + Lost uint32 + Retrans uint32 + Fackets uint32 + Last_data_sent uint32 + Last_ack_sent uint32 + Last_data_recv uint32 + Last_ack_recv uint32 + Pmtu uint32 + Rcv_ssthresh uint32 + Rtt uint32 + Rttvar uint32 + Snd_ssthresh uint32 + Snd_cwnd uint32 + Advmss uint32 + Reordering uint32 + Rcv_rtt uint32 + Rcv_space uint32 + Total_retrans uint32 + Pacing_rate uint64 + Max_pacing_rate uint64 + Bytes_acked uint64 + Bytes_received uint64 + Segs_out uint32 + Segs_in uint32 + Notsent_bytes uint32 + Min_rtt uint32 + Data_segs_in uint32 + Data_segs_out uint32 + Delivery_rate uint64 + Busy_time uint64 + Rwnd_limited uint64 + Sndbuf_limited uint64 + Delivered uint32 + Delivered_ce uint32 + Bytes_sent uint64 + Bytes_retrans uint64 + Dsack_dups uint32 + Reord_seen uint32 + Rcv_ooopack uint32 + Snd_wnd uint32 + Rcv_wnd uint32 + Rehash uint32 + Total_rto uint16 + Total_rto_recoveries uint16 + Total_rto_time uint32 } type CanFilter struct { @@ -551,7 +555,7 @@ const ( SizeofIPv6MTUInfo = 0x20 SizeofICMPv6Filter = 0x20 SizeofUcred = 0xc - SizeofTCPInfo = 0xf0 + SizeofTCPInfo = 0xf8 SizeofCanFilter = 0x8 SizeofTCPRepairOpt = 0x8 ) @@ -3399,7 +3403,7 @@ const ( DEVLINK_PORT_FN_ATTR_STATE = 0x2 DEVLINK_PORT_FN_ATTR_OPSTATE = 0x3 DEVLINK_PORT_FN_ATTR_CAPS = 0x4 - DEVLINK_PORT_FUNCTION_ATTR_MAX = 0x4 + DEVLINK_PORT_FUNCTION_ATTR_MAX = 0x5 ) type FsverityDigest struct { @@ -4183,7 +4187,8 @@ const ( ) type LandlockRulesetAttr struct { - Access_fs uint64 + Access_fs uint64 + Access_net uint64 } type LandlockPathBeneathAttr struct { @@ -5134,7 +5139,7 @@ const ( NL80211_FREQUENCY_ATTR_GO_CONCURRENT = 0xf NL80211_FREQUENCY_ATTR_INDOOR_ONLY = 0xe NL80211_FREQUENCY_ATTR_IR_CONCURRENT = 0xf - NL80211_FREQUENCY_ATTR_MAX = 0x1b + NL80211_FREQUENCY_ATTR_MAX = 0x1c NL80211_FREQUENCY_ATTR_MAX_TX_POWER = 0x6 NL80211_FREQUENCY_ATTR_NO_10MHZ = 0x11 NL80211_FREQUENCY_ATTR_NO_160MHZ = 0xc @@ -5547,7 +5552,7 @@ const ( NL80211_REGDOM_TYPE_CUSTOM_WORLD = 0x2 NL80211_REGDOM_TYPE_INTERSECTION = 0x3 NL80211_REGDOM_TYPE_WORLD = 0x1 - NL80211_REG_RULE_ATTR_MAX = 0x7 + NL80211_REG_RULE_ATTR_MAX = 0x8 NL80211_REKEY_DATA_AKM = 0x4 NL80211_REKEY_DATA_KCK = 0x2 NL80211_REKEY_DATA_KEK = 0x1 From bef1bd89712319e29431eb7de75b229216e79c09 Mon Sep 17 00:00:00 2001 From: Joshua Sing Date: Fri, 17 Nov 2023 01:35:39 +1100 Subject: [PATCH 6/9] unix: move mksyscall regexp to package level variables Avoid compiling regular expressions for each loop iteration, rather declare them as package level variables so they are only compiled once. Change-Id: I5c29a44e986ef8d97326134e8fc8e983671e68d8 Reviewed-on: https://go-review.googlesource.com/c/sys/+/542955 Reviewed-by: Joel Sing Run-TryBot: Joel Sing Reviewed-by: Carlos Amedee Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- unix/mksyscall.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/unix/mksyscall.go b/unix/mksyscall.go index e606c2acea..53d2c66128 100644 --- a/unix/mksyscall.go +++ b/unix/mksyscall.go @@ -47,6 +47,18 @@ var ( libcPath = "libc.so" ) +var ( + regexpComma = regexp.MustCompile(`\s*,\s*`) + regexpParamKV = regexp.MustCompile(`^(\S*) (\S*)$`) + regexpSys = regexp.MustCompile(`^\/\/sys\t`) + regexpSysNonblock = regexp.MustCompile(`^\/\/sysnb\t`) + regexpSysDeclaration = regexp.MustCompile(`^\/\/sys(nb)?\t(\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*((?i)SYS_[A-Z0-9_]+))?$`) + regexpPointer = regexp.MustCompile(`^\*`) + regexpSlice = regexp.MustCompile(`^\[](.*)`) + regexpDragonflyExtp = regexp.MustCompile(`^(?i)extp(read|write)`) + regexpSyscallName = regexp.MustCompile(`([a-z])([A-Z])`) +) + // cmdLine returns this programs's commandline arguments func cmdLine() string { return "go run mksyscall.go " + strings.Join(os.Args[1:], " ") @@ -75,12 +87,12 @@ func parseParamList(list string) []string { if list == "" { return []string{} } - return regexp.MustCompile(`\s*,\s*`).Split(list, -1) + return regexpComma.Split(list, -1) } // parseParam splits a parameter into name and type func parseParam(p string) Param { - ps := regexp.MustCompile(`^(\S*) (\S*)$`).FindStringSubmatch(p) + ps := regexpParamKV.FindStringSubmatch(p) if ps == nil { fmt.Fprintf(os.Stderr, "malformed parameter: %s\n", p) os.Exit(1) @@ -138,15 +150,15 @@ func main() { s := bufio.NewScanner(file) for s.Scan() { t := s.Text() - nonblock := regexp.MustCompile(`^\/\/sysnb\t`).FindStringSubmatch(t) - if regexp.MustCompile(`^\/\/sys\t`).FindStringSubmatch(t) == nil && nonblock == nil { + nonblock := regexpSysNonblock.FindStringSubmatch(t) + if regexpSys.FindStringSubmatch(t) == nil && nonblock == nil { continue } // Line must be of the form // func Open(path string, mode int, perm int) (fd int, errno error) // Split into name, in params, out params. - f := regexp.MustCompile(`^\/\/sys(nb)?\t(\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*((?i)SYS_[A-Z0-9_]+))?$`).FindStringSubmatch(t) + f := regexpSysDeclaration.FindStringSubmatch(t) if f == nil { fmt.Fprintf(os.Stderr, "%s:%s\nmalformed //sys declaration\n", path, t) os.Exit(1) @@ -184,7 +196,7 @@ func main() { n := 0 for _, param := range in { p := parseParam(param) - if regexp.MustCompile(`^\*`).FindStringSubmatch(p.Type) != nil { + if regexpPointer.FindStringSubmatch(p.Type) != nil { args = append(args, "uintptr(unsafe.Pointer("+p.Name+"))") } else if p.Type == "string" && errvar != "" { text += fmt.Sprintf("\tvar _p%d *byte\n", n) @@ -198,7 +210,7 @@ func main() { text += fmt.Sprintf("\t_p%d, _ = BytePtrFromString(%s)\n", n, p.Name) args = append(args, fmt.Sprintf("uintptr(unsafe.Pointer(_p%d))", n)) n++ - } else if regexp.MustCompile(`^\[\](.*)`).FindStringSubmatch(p.Type) != nil { + } else if regexpSlice.FindStringSubmatch(p.Type) != nil { // Convert slice into pointer, length. // Have to be careful not to take address of &a[0] if len == 0: // pass dummy pointer in that case. @@ -218,7 +230,7 @@ func main() { args = append(args, fmt.Sprintf("uintptr(%s)", p.Name)) } } else if p.Type == "int64" && *dragonfly { - if regexp.MustCompile(`^(?i)extp(read|write)`).FindStringSubmatch(funct) == nil { + if regexpDragonflyExtp.FindStringSubmatch(funct) == nil { args = append(args, "0") } if endianness == "big-endian" { @@ -278,7 +290,7 @@ func main() { // System call number. if sysname == "" { sysname = "SYS_" + funct - sysname = regexp.MustCompile(`([a-z])([A-Z])`).ReplaceAllString(sysname, `${1}_$2`) + sysname = regexpSyscallName.ReplaceAllString(sysname, `${1}_$2`) sysname = strings.ToUpper(sysname) } From 628365db92ccfeee25005315a474345652e8d164 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Tue, 30 Jan 2024 10:50:59 +0100 Subject: [PATCH 7/9] windows: support nil done parameter in ReadFile and WriteFile Win32 defines the `done` param as optional for ReadFile and WriteFile functions. We should support this case too. Fixes golang/go#65365. Change-Id: I961ff66a63d3a8ffa5560b6dab21fbd4ac9817ae Reviewed-on: https://go-review.googlesource.com/c/sys/+/559375 Reviewed-by: Mauri de Souza Meneguzzo Reviewed-by: Bryan Mills Reviewed-by: Michael Knyszek LUCI-TryBot-Result: Go LUCI --- windows/syscall_windows.go | 20 ++++++++---- windows/syscall_windows_test.go | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index ffb8708ccf..ea7a119085 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -572,13 +572,17 @@ func Write(fd Handle, p []byte) (n int, err error) { } func ReadFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error { - err := readFile(fd, p, done, overlapped) + var n uint32 + err := readFile(fd, p, &n, overlapped) if raceenabled { - if *done > 0 { - raceWriteRange(unsafe.Pointer(&p[0]), int(*done)) + if n > 0 { + raceWriteRange(unsafe.Pointer(&p[0]), int(n)) } raceAcquire(unsafe.Pointer(&ioSync)) } + if done != nil { + *done = n + } return err } @@ -586,9 +590,13 @@ func WriteFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error if raceenabled { raceReleaseMerge(unsafe.Pointer(&ioSync)) } - err := writeFile(fd, p, done, overlapped) - if raceenabled && *done > 0 { - raceReadRange(unsafe.Pointer(&p[0]), int(*done)) + var n uint32 + err := writeFile(fd, p, &n, overlapped) + if raceenabled && n > 0 { + raceReadRange(unsafe.Pointer(&p[0]), int(n)) + } + if done != nil { + *done = n } return err } diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index 6658379070..a360535e0f 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -1275,3 +1275,58 @@ uintptr_t beep(void) { t.Fatal("LoadLibraryEx unexpectedly found beep.dll") } } + +func TestReadWriteFileOverlapped(t *testing.T) { + name := filepath.Join(t.TempDir(), "test.txt") + fd, err := windows.CreateFile(windows.StringToUTF16Ptr(name), windows.GENERIC_READ|windows.GENERIC_WRITE, 0, nil, windows.CREATE_NEW, windows.FILE_FLAG_OVERLAPPED, 0) + if err != nil { + t.Fatal(err) + } + defer windows.CloseHandle(fd) + + content := []byte("hello") + // Test that we can write to a file using overlapped I/O. + var ow windows.Overlapped + ow.HEvent, err = windows.CreateEvent(nil, 0, 0, nil) + if err != nil { + t.Fatal(err) + } + defer windows.CloseHandle(ow.HEvent) + if err := windows.WriteFile(fd, content, nil, &ow); err != nil && err != windows.ERROR_IO_PENDING { + t.Fatal(err) + } + if _, err := windows.WaitForSingleObject(ow.HEvent, windows.INFINITE); err != nil { + t.Fatal(err) + } + var n uint32 + if err := windows.GetOverlappedResult(fd, &ow, &n, true); err != nil { + t.Fatal(err) + } + if n != uint32(len(content)) { + t.Fatalf("got %d bytes written; want %d", n, len(content)) + } + + // Test that we can read from a file using overlapped I/O. + var or windows.Overlapped + or.HEvent, err = windows.CreateEvent(nil, 0, 0, nil) + if err != nil { + t.Fatal(err) + } + defer windows.CloseHandle(ow.HEvent) + buf := make([]byte, len(content)) + if err := windows.ReadFile(fd, buf, nil, &or); err != nil && err != windows.ERROR_IO_PENDING { + t.Fatal(err) + } + if err != nil { + t.Fatal(err) + } + if _, err := windows.WaitForSingleObject(or.HEvent, windows.INFINITE); err != nil { + t.Fatal(err) + } + if err := windows.GetOverlappedResult(fd, &or, &n, true); err != nil { + t.Fatal(err) + } + if string(buf) != string(content) { + t.Fatalf("got %q; want %q", buf, content) + } +} From 511ec846b66e39447acbd021083b26ca2747a188 Mon Sep 17 00:00:00 2001 From: Bryan Mills Date: Tue, 30 Jan 2024 20:37:30 +0000 Subject: [PATCH 8/9] Revert "windows: support nil done parameter in ReadFile and WriteFile" This reverts CL 559375. Reason for revert: introduced a different regression (golang/go#65378). Fixes golang/go#65378. Updates golang/go#65365. Change-Id: Ie2a602415913b04b9d9b65fee5c6a54c0267b35e Cq-Include-Trybots: luci.golang.try:x_sys-gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/sys/+/559502 Auto-Submit: Bryan Mills LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- windows/syscall_windows.go | 20 ++++-------- windows/syscall_windows_test.go | 55 --------------------------------- 2 files changed, 6 insertions(+), 69 deletions(-) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index ea7a119085..ffb8708ccf 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -572,17 +572,13 @@ func Write(fd Handle, p []byte) (n int, err error) { } func ReadFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error { - var n uint32 - err := readFile(fd, p, &n, overlapped) + err := readFile(fd, p, done, overlapped) if raceenabled { - if n > 0 { - raceWriteRange(unsafe.Pointer(&p[0]), int(n)) + if *done > 0 { + raceWriteRange(unsafe.Pointer(&p[0]), int(*done)) } raceAcquire(unsafe.Pointer(&ioSync)) } - if done != nil { - *done = n - } return err } @@ -590,13 +586,9 @@ func WriteFile(fd Handle, p []byte, done *uint32, overlapped *Overlapped) error if raceenabled { raceReleaseMerge(unsafe.Pointer(&ioSync)) } - var n uint32 - err := writeFile(fd, p, &n, overlapped) - if raceenabled && n > 0 { - raceReadRange(unsafe.Pointer(&p[0]), int(n)) - } - if done != nil { - *done = n + err := writeFile(fd, p, done, overlapped) + if raceenabled && *done > 0 { + raceReadRange(unsafe.Pointer(&p[0]), int(*done)) } return err } diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index a360535e0f..6658379070 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -1275,58 +1275,3 @@ uintptr_t beep(void) { t.Fatal("LoadLibraryEx unexpectedly found beep.dll") } } - -func TestReadWriteFileOverlapped(t *testing.T) { - name := filepath.Join(t.TempDir(), "test.txt") - fd, err := windows.CreateFile(windows.StringToUTF16Ptr(name), windows.GENERIC_READ|windows.GENERIC_WRITE, 0, nil, windows.CREATE_NEW, windows.FILE_FLAG_OVERLAPPED, 0) - if err != nil { - t.Fatal(err) - } - defer windows.CloseHandle(fd) - - content := []byte("hello") - // Test that we can write to a file using overlapped I/O. - var ow windows.Overlapped - ow.HEvent, err = windows.CreateEvent(nil, 0, 0, nil) - if err != nil { - t.Fatal(err) - } - defer windows.CloseHandle(ow.HEvent) - if err := windows.WriteFile(fd, content, nil, &ow); err != nil && err != windows.ERROR_IO_PENDING { - t.Fatal(err) - } - if _, err := windows.WaitForSingleObject(ow.HEvent, windows.INFINITE); err != nil { - t.Fatal(err) - } - var n uint32 - if err := windows.GetOverlappedResult(fd, &ow, &n, true); err != nil { - t.Fatal(err) - } - if n != uint32(len(content)) { - t.Fatalf("got %d bytes written; want %d", n, len(content)) - } - - // Test that we can read from a file using overlapped I/O. - var or windows.Overlapped - or.HEvent, err = windows.CreateEvent(nil, 0, 0, nil) - if err != nil { - t.Fatal(err) - } - defer windows.CloseHandle(ow.HEvent) - buf := make([]byte, len(content)) - if err := windows.ReadFile(fd, buf, nil, &or); err != nil && err != windows.ERROR_IO_PENDING { - t.Fatal(err) - } - if err != nil { - t.Fatal(err) - } - if _, err := windows.WaitForSingleObject(or.HEvent, windows.INFINITE); err != nil { - t.Fatal(err) - } - if err := windows.GetOverlappedResult(fd, &or, &n, true); err != nil { - t.Fatal(err) - } - if string(buf) != string(content) { - t.Fatalf("got %q; want %q", buf, content) - } -} From 914b96c1bddd0738464c043cccbbac14fc94b955 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 1 Feb 2024 15:05:25 +0100 Subject: [PATCH 9/9] windows: support ill-formed UTF-16 in UTF16PtrToString UTF16PtrToString does not support ill-formed UTF-16 because it uses utf16.Decode, which expects well-formed UTF-16. This CL updates the UTF16PtrToString implementation to use UTF16ToString instead of utf16.Decode, which supports ill-formed UTF-16 since go1.21 via syscall.UTF16ToString. Change-Id: Ifb72b6d38a8c08ad90ec6a47eed05fc3739500a1 Reviewed-on: https://go-review.googlesource.com/c/sys/+/560355 LUCI-TryBot-Result: Go LUCI Reviewed-by: Bryan Mills Reviewed-by: Michael Knyszek --- windows/syscall_windows.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index ffb8708ccf..6395a031d4 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -125,8 +125,7 @@ func UTF16PtrToString(p *uint16) string { for ptr := unsafe.Pointer(p); *(*uint16)(ptr) != 0; n++ { ptr = unsafe.Pointer(uintptr(ptr) + unsafe.Sizeof(*p)) } - - return string(utf16.Decode(unsafe.Slice(p, n))) + return UTF16ToString(unsafe.Slice(p, n)) } func Getpagesize() int { return 4096 }