From 1911637744c199cdad74ee1ee74d19ce61e3d9fa Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 31 Mar 2023 12:54:09 -0400 Subject: [PATCH 01/25] windows/svc: use separate (and more descriptive) service names in tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notably, the DisplayName field was set to the same thing in both sys.TestExample and mrg.TestMyService, which may explain the collision reported in golang/go#59298. Moreover, the adjective ”my” conveys no information whatsoever — we shouldn't use it in tests or examples. Also skip the tests that install services if GO_BUILDER_NAME is not set, to reduce the likelihood of 'go test all' in a user's working directory being mistaken for a malicious or compromised program. Fixes golang/go#59298. Change-Id: Ib00bf7400bfaa34e1a1d49125c43b97019b53c82 Reviewed-on: https://go-review.googlesource.com/c/sys/+/481015 Reviewed-by: Carlos Amedee Run-TryBot: Bryan Mills Reviewed-by: Alex Brainman TryBot-Result: Gopher Robot Auto-Submit: Bryan Mills --- windows/svc/example/main.go | 8 ++++++-- windows/svc/example/service.go | 6 +++--- windows/svc/mgr/mgr_test.go | 21 +++++++++++---------- windows/svc/svc_test.go | 16 ++++++++++------ 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/windows/svc/example/main.go b/windows/svc/example/main.go index 2ea733010f..62f947027f 100644 --- a/windows/svc/example/main.go +++ b/windows/svc/example/main.go @@ -15,6 +15,7 @@ package main import ( + "flag" "fmt" "log" "os" @@ -33,8 +34,11 @@ func usage(errmsg string) { os.Exit(2) } +var svcName = "exampleservice" + func main() { - const svcName = "myservice" + flag.StringVar(&svcName, "name", svcName, "name of the service") + flag.Parse() inService, err := svc.IsWindowsService() if err != nil { @@ -55,7 +59,7 @@ func main() { runService(svcName, true) return case "install": - err = installService(svcName, "my service") + err = installService(svcName, "example service") case "remove": err = removeService(svcName) case "start": diff --git a/windows/svc/example/service.go b/windows/svc/example/service.go index c989abff7a..08d54b51a3 100644 --- a/windows/svc/example/service.go +++ b/windows/svc/example/service.go @@ -19,9 +19,9 @@ import ( var elog debug.Log -type myservice struct{} +type exampleService struct{} -func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) { +func (m *exampleService) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) { const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue changes <- svc.Status{State: svc.StartPending} fasttick := time.Tick(500 * time.Millisecond) @@ -79,7 +79,7 @@ func runService(name string, isDebug bool) { if isDebug { run = debug.Run } - err = run(name, &myservice{}) + err = run(name, &exampleService{}) if err != nil { elog.Error(1, fmt.Sprintf("%s service failed: %v", name, err)) return diff --git a/windows/svc/mgr/mgr_test.go b/windows/svc/mgr/mgr_test.go index 6f849f3e30..10d2310790 100644 --- a/windows/svc/mgr/mgr_test.go +++ b/windows/svc/mgr/mgr_test.go @@ -227,25 +227,26 @@ func remove(t *testing.T, s *mgr.Service) { } func TestMyService(t *testing.T) { + if os.Getenv("GO_BUILDER_NAME") == "" { + // Don't install services on arbitrary users' machines. + t.Skip("skipping test that modifies system services: GO_BUILDER_NAME not set") + } if testing.Short() { - t.Skip("skipping test in short mode - it modifies system services") + t.Skip("skipping test in short mode that modifies system services") } - const name = "mymgrservice" + const name = "mgrtestservice" m, err := mgr.Connect() if err != nil { - if errno, ok := err.(syscall.Errno); ok && errno == syscall.ERROR_ACCESS_DENIED { - t.Skip("Skipping test: we don't have rights to manage services.") - } t.Fatalf("SCM connection failed: %s", err) } defer m.Disconnect() c := mgr.Config{ StartType: mgr.StartDisabled, - DisplayName: "my service", - Description: "my service is just a test", + DisplayName: "x-sys mgr test service", + Description: "x-sys mgr test service is just a test", Dependencies: []string{"LanmanServer", "W32Time"}, } @@ -288,14 +289,14 @@ func TestMyService(t *testing.T) { if err != nil { t.Fatalf("ListServices failed: %v", err) } - var myserviceIsInstalled bool + var serviceIsInstalled bool for _, sn := range svcnames { if sn == name { - myserviceIsInstalled = true + serviceIsInstalled = true break } } - if !myserviceIsInstalled { + if !serviceIsInstalled { t.Errorf("ListServices failed to find %q service", name) } diff --git a/windows/svc/svc_test.go b/windows/svc/svc_test.go index f7833adb14..5d794e1966 100644 --- a/windows/svc/svc_test.go +++ b/windows/svc/svc_test.go @@ -77,11 +77,15 @@ func stopAndDeleteIfInstalled(t *testing.T, m *mgr.Mgr, name string) { } func TestExample(t *testing.T) { - if testing.Short() && os.Getenv("GO_BUILDER_NAME") != "" { - t.Skip("skipping test in short mode - it modifies system services") + if os.Getenv("GO_BUILDER_NAME") == "" { + // Don't install services on arbitrary users' machines. + t.Skip("skipping test that modifies system services: GO_BUILDER_NAME not set") + } + if testing.Short() { + t.Skip("skipping test in short mode that modifies system services") } - const name = "myservice" + const name = "svctestservice" m, err := mgr.Connect() if err != nil { @@ -103,7 +107,7 @@ func TestExample(t *testing.T) { stopAndDeleteIfInstalled(t, m, name) - s, err := m.CreateService(name, exepath, mgr.Config{DisplayName: "my service"}, "is", "auto-started") + s, err := m.CreateService(name, exepath, mgr.Config{DisplayName: "x-sys svc test service"}, "-name", name) if err != nil { t.Fatalf("CreateService(%s) failed: %v", name, err) } @@ -141,7 +145,7 @@ func TestExample(t *testing.T) { t.Fatalf("Delete failed: %s", err) } - out, err := exec.Command("wevtutil.exe", "qe", "Application", "/q:*[System[Provider[@Name='myservice']]]", "/rd:true", "/c:10").CombinedOutput() + out, err := exec.Command("wevtutil.exe", "qe", "Application", "/q:*[System[Provider[@Name='"+name+"']]]", "/rd:true", "/c:10").CombinedOutput() if err != nil { t.Fatalf("wevtutil failed: %v\n%v", err, string(out)) } @@ -149,7 +153,7 @@ func TestExample(t *testing.T) { // Test context passing (see servicemain in sys_386.s and sys_amd64.s). want += "-123456" if !strings.Contains(string(out), want) { - t.Errorf("%q string does not contain %q", string(out), want) + t.Errorf("%q string does not contain %q", out, want) } } From c43fe1e1f5e94f8140de42e780509f73c20f34b2 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 15 May 2023 10:38:34 +0200 Subject: [PATCH 02/25] cpu: define IsBigEndian on wasm For golang/go#57237 Change-Id: Ia2aa943e93c8df51cd08003535fa026d2bb8003e Reviewed-on: https://go-review.googlesource.com/c/sys/+/494856 TryBot-Result: Gopher Robot Auto-Submit: Tobias Klauser Reviewed-by: Ian Lance Taylor Run-TryBot: Tobias Klauser Reviewed-by: Heschi Kreinick --- cpu/endian_little.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpu/endian_little.go b/cpu/endian_little.go index fe545966b6..55db853efb 100644 --- a/cpu/endian_little.go +++ b/cpu/endian_little.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build 386 || amd64 || amd64p32 || alpha || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || nios2 || ppc64le || riscv || riscv64 || sh -// +build 386 amd64 amd64p32 alpha arm arm64 loong64 mipsle mips64le mips64p32le nios2 ppc64le riscv riscv64 sh +//go:build 386 || amd64 || amd64p32 || alpha || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || nios2 || ppc64le || riscv || riscv64 || sh || wasm +// +build 386 amd64 amd64p32 alpha arm arm64 loong64 mipsle mips64le mips64p32le nios2 ppc64le riscv riscv64 sh wasm package cpu From 352d8339e8b9a29c57d977f5c64810689466b25b Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 15 May 2023 14:32:57 +0200 Subject: [PATCH 03/25] cpu: add test for IsBigEndian For golang/go#57237 Change-Id: I11d1c954f942ebd836c4deb9c710c40778dc5599 Reviewed-on: https://go-review.googlesource.com/c/sys/+/494858 Auto-Submit: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Ian Lance Taylor Reviewed-by: Heschi Kreinick TryBot-Result: Gopher Robot --- cpu/endian_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cpu/endian_test.go diff --git a/cpu/endian_test.go b/cpu/endian_test.go new file mode 100644 index 0000000000..b066bfb3ff --- /dev/null +++ b/cpu/endian_test.go @@ -0,0 +1,21 @@ +// Copyright 2023 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_test + +import ( + "testing" + "unsafe" + + "golang.org/x/sys/cpu" +) + +func TestIsBigEndian(t *testing.T) { + b := uint16(0xff00) + want := *(*byte)(unsafe.Pointer(&b)) == 0xff + if cpu.IsBigEndian != want { + t.Errorf("IsBigEndian = %t, want %t", + cpu.IsBigEndian, want) + } +} From c8ea6b0cbc9ffb7927e068f279c46cb342d0c956 Mon Sep 17 00:00:00 2001 From: Roman Mazur Date: Wed, 17 May 2023 22:45:36 +0200 Subject: [PATCH 04/25] windows: fix EnumProcesses to pass the correct array size Implementation generated directly with mkwinsyscall has a wrong assumption about the expected value for PIDs buffer size. This change adds some small manual code that converts the input slice length to the number of bytes of the array backing the slice. A test is also added. It fails with the previous implementation. Fixes golang/go#60223 Change-Id: I5e2414acb29c6c949e5e6acd328043f8a8883887 Reviewed-on: https://go-review.googlesource.com/c/sys/+/495995 Commit-Queue: Quim Muntal TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Run-TryBot: Quim Muntal Reviewed-by: Quim Muntal Reviewed-by: Heschi Kreinick --- windows/syscall_windows.go | 13 ++++++++++++- windows/syscall_windows_test.go | 22 ++++++++++++++++++++++ windows/zsyscall_windows.go | 8 ++------ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index 3723b2c224..9645900754 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -405,7 +405,7 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys VerQueryValue(block unsafe.Pointer, subBlock string, pointerToBufferPointer unsafe.Pointer, bufSize *uint32) (err error) = version.VerQueryValueW // Process Status API (PSAPI) -//sys EnumProcesses(processIds []uint32, bytesReturned *uint32) (err error) = psapi.EnumProcesses +//sys enumProcesses(processIds *uint32, nSize uint32, bytesReturned *uint32) (err error) = psapi.EnumProcesses //sys EnumProcessModules(process Handle, module *Handle, cb uint32, cbNeeded *uint32) (err error) = psapi.EnumProcessModules //sys EnumProcessModulesEx(process Handle, module *Handle, cb uint32, cbNeeded *uint32, filterFlag uint32) (err error) = psapi.EnumProcessModulesEx //sys GetModuleInformation(process Handle, module Handle, modinfo *ModuleInfo, cb uint32) (err error) = psapi.GetModuleInformation @@ -1354,6 +1354,17 @@ func SetsockoptIPv6Mreq(fd Handle, level, opt int, mreq *IPv6Mreq) (err error) { return syscall.EWINDOWS } +func EnumProcesses(processIds []uint32, bytesReturned *uint32) error { + // EnumProcesses syscall expects the size parameter to be in bytes, but the code generated with mksyscall uses + // the length of the processIds slice instead. Hence, this wrapper function is added to fix the discrepancy. + var p *uint32 + if len(processIds) > 0 { + p = &processIds[0] + } + size := uint32(len(processIds) * 4) + return enumProcesses(p, size, bytesReturned) +} + func Getpid() (pid int) { return int(GetCurrentProcessId()) } func FindFirstFile(name *uint16, data *Win32finddata) (handle Handle, err error) { diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index 42c01fc968..81050d3370 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -717,6 +717,28 @@ func TestWinVerifyTrust(t *testing.T) { } +func TestEnumProcesses(t *testing.T) { + var ( + pids [2]uint32 + outSize uint32 + ) + err := windows.EnumProcesses(pids[:], &outSize) + if err != nil { + t.Fatalf("unable to enumerate processes: %v", err) + } + + // Regression check for go.dev/issue/60223 + if outSize != 8 { + t.Errorf("unexpected bytes returned: %d", outSize) + } + // Most likely, this should be [0, 4]. + // 0 is the system idle pseudo-process. 4 is the initial system process ID. + // This test expects that at least one of the PIDs is not 0. + if pids[0] == 0 && pids[1] == 0 { + t.Errorf("all PIDs are 0") + } +} + func TestProcessModules(t *testing.T) { process, err := windows.GetCurrentProcess() if err != nil { diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index a81ea2c700..566dd3e315 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -3516,12 +3516,8 @@ func EnumProcessModulesEx(process Handle, module *Handle, cb uint32, cbNeeded *u return } -func EnumProcesses(processIds []uint32, bytesReturned *uint32) (err error) { - var _p0 *uint32 - if len(processIds) > 0 { - _p0 = &processIds[0] - } - r1, _, e1 := syscall.Syscall(procEnumProcesses.Addr(), 3, uintptr(unsafe.Pointer(_p0)), uintptr(len(processIds)), uintptr(unsafe.Pointer(bytesReturned))) +func enumProcesses(processIds *uint32, nSize uint32, bytesReturned *uint32) (err error) { + r1, _, e1 := syscall.Syscall(procEnumProcesses.Addr(), 3, uintptr(unsafe.Pointer(processIds)), uintptr(nSize), uintptr(unsafe.Pointer(bytesReturned))) if r1 == 0 { err = errnoErr(e1) } From b5c7a0975ddc3d04a37152e997b3f70ecb531eb7 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Fri, 19 May 2023 14:59:35 +0200 Subject: [PATCH 05/25] unix: update BPF constants with Linux kernel 6.2 Change-Id: Iaa92ec9e8ff6e337457ea4f57b4c046221128d43 Reviewed-on: https://go-review.googlesource.com/c/sys/+/496675 Run-TryBot: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Tobias Klauser Reviewed-by: Ian Lance Taylor Reviewed-by: Matthew Dempsky TryBot-Result: Gopher Robot Auto-Submit: Ian Lance Taylor --- unix/linux/types.go | 46 +++++++++++++++++++++++++++++++++ unix/zerrors_linux_sparc64.go | 48 +++++++++++++++++++++++++++++++++++ unix/ztypes_linux.go | 46 +++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) diff --git a/unix/linux/types.go b/unix/linux/types.go index 671453331c..fff4ed3001 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -2543,6 +2543,11 @@ const ( BPF_REG_8 = C.BPF_REG_8 BPF_REG_9 = C.BPF_REG_9 BPF_REG_10 = C.BPF_REG_10 + BPF_CGROUP_ITER_ORDER_UNSPEC = C.BPF_CGROUP_ITER_ORDER_UNSPEC + BPF_CGROUP_ITER_SELF_ONLY = C.BPF_CGROUP_ITER_SELF_ONLY + BPF_CGROUP_ITER_DESCENDANTS_PRE = C.BPF_CGROUP_ITER_DESCENDANTS_PRE + BPF_CGROUP_ITER_DESCENDANTS_POST = C.BPF_CGROUP_ITER_DESCENDANTS_POST + BPF_CGROUP_ITER_ANCESTORS_UP = C.BPF_CGROUP_ITER_ANCESTORS_UP BPF_MAP_CREATE = C.BPF_MAP_CREATE BPF_MAP_LOOKUP_ELEM = C.BPF_MAP_LOOKUP_ELEM BPF_MAP_UPDATE_ELEM = C.BPF_MAP_UPDATE_ELEM @@ -2554,6 +2559,7 @@ const ( BPF_PROG_ATTACH = C.BPF_PROG_ATTACH BPF_PROG_DETACH = C.BPF_PROG_DETACH BPF_PROG_TEST_RUN = C.BPF_PROG_TEST_RUN + BPF_PROG_RUN = C.BPF_PROG_RUN BPF_PROG_GET_NEXT_ID = C.BPF_PROG_GET_NEXT_ID BPF_MAP_GET_NEXT_ID = C.BPF_MAP_GET_NEXT_ID BPF_PROG_GET_FD_BY_ID = C.BPF_PROG_GET_FD_BY_ID @@ -2598,6 +2604,7 @@ const ( BPF_MAP_TYPE_CPUMAP = C.BPF_MAP_TYPE_CPUMAP BPF_MAP_TYPE_XSKMAP = C.BPF_MAP_TYPE_XSKMAP BPF_MAP_TYPE_SOCKHASH = C.BPF_MAP_TYPE_SOCKHASH + BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED = C.BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED BPF_MAP_TYPE_CGROUP_STORAGE = C.BPF_MAP_TYPE_CGROUP_STORAGE BPF_MAP_TYPE_REUSEPORT_SOCKARRAY = C.BPF_MAP_TYPE_REUSEPORT_SOCKARRAY BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE = C.BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE @@ -2608,6 +2615,10 @@ const ( BPF_MAP_TYPE_STRUCT_OPS = C.BPF_MAP_TYPE_STRUCT_OPS BPF_MAP_TYPE_RINGBUF = C.BPF_MAP_TYPE_RINGBUF BPF_MAP_TYPE_INODE_STORAGE = C.BPF_MAP_TYPE_INODE_STORAGE + BPF_MAP_TYPE_TASK_STORAGE = C.BPF_MAP_TYPE_TASK_STORAGE + BPF_MAP_TYPE_BLOOM_FILTER = C.BPF_MAP_TYPE_BLOOM_FILTER + BPF_MAP_TYPE_USER_RINGBUF = C.BPF_MAP_TYPE_USER_RINGBUF + BPF_MAP_TYPE_CGRP_STORAGE = C.BPF_MAP_TYPE_CGRP_STORAGE BPF_PROG_TYPE_UNSPEC = C.BPF_PROG_TYPE_UNSPEC BPF_PROG_TYPE_SOCKET_FILTER = C.BPF_PROG_TYPE_SOCKET_FILTER BPF_PROG_TYPE_KPROBE = C.BPF_PROG_TYPE_KPROBE @@ -2639,6 +2650,7 @@ const ( BPF_PROG_TYPE_EXT = C.BPF_PROG_TYPE_EXT BPF_PROG_TYPE_LSM = C.BPF_PROG_TYPE_LSM BPF_PROG_TYPE_SK_LOOKUP = C.BPF_PROG_TYPE_SK_LOOKUP + BPF_PROG_TYPE_SYSCALL = C.BPF_PROG_TYPE_SYSCALL BPF_CGROUP_INET_INGRESS = C.BPF_CGROUP_INET_INGRESS BPF_CGROUP_INET_EGRESS = C.BPF_CGROUP_INET_EGRESS BPF_CGROUP_INET_SOCK_CREATE = C.BPF_CGROUP_INET_SOCK_CREATE @@ -2677,6 +2689,12 @@ const ( BPF_XDP_CPUMAP = C.BPF_XDP_CPUMAP BPF_SK_LOOKUP = C.BPF_SK_LOOKUP BPF_XDP = C.BPF_XDP + BPF_SK_SKB_VERDICT = C.BPF_SK_SKB_VERDICT + BPF_SK_REUSEPORT_SELECT = C.BPF_SK_REUSEPORT_SELECT + BPF_SK_REUSEPORT_SELECT_OR_MIGRATE = C.BPF_SK_REUSEPORT_SELECT_OR_MIGRATE + BPF_PERF_EVENT = C.BPF_PERF_EVENT + BPF_TRACE_KPROBE_MULTI = C.BPF_TRACE_KPROBE_MULTI + BPF_LSM_CGROUP = C.BPF_LSM_CGROUP BPF_LINK_TYPE_UNSPEC = C.BPF_LINK_TYPE_UNSPEC BPF_LINK_TYPE_RAW_TRACEPOINT = C.BPF_LINK_TYPE_RAW_TRACEPOINT BPF_LINK_TYPE_TRACING = C.BPF_LINK_TYPE_TRACING @@ -2684,6 +2702,9 @@ const ( BPF_LINK_TYPE_ITER = C.BPF_LINK_TYPE_ITER BPF_LINK_TYPE_NETNS = C.BPF_LINK_TYPE_NETNS BPF_LINK_TYPE_XDP = C.BPF_LINK_TYPE_XDP + BPF_LINK_TYPE_PERF_EVENT = C.BPF_LINK_TYPE_PERF_EVENT + BPF_LINK_TYPE_KPROBE_MULTI = C.BPF_LINK_TYPE_KPROBE_MULTI + BPF_LINK_TYPE_STRUCT_OPS = C.BPF_LINK_TYPE_STRUCT_OPS BPF_ANY = C.BPF_ANY BPF_NOEXIST = C.BPF_NOEXIST BPF_EXIST = C.BPF_EXIST @@ -2721,6 +2742,7 @@ const ( BPF_F_ZERO_CSUM_TX = C.BPF_F_ZERO_CSUM_TX BPF_F_DONT_FRAGMENT = C.BPF_F_DONT_FRAGMENT BPF_F_SEQ_NUMBER = C.BPF_F_SEQ_NUMBER + BPF_F_TUNINFO_FLAGS = C.BPF_F_TUNINFO_FLAGS BPF_F_INDEX_MASK = C.BPF_F_INDEX_MASK BPF_F_CURRENT_CPU = C.BPF_F_CURRENT_CPU BPF_F_CTXLEN_MASK = C.BPF_F_CTXLEN_MASK @@ -2735,6 +2757,7 @@ const ( BPF_F_ADJ_ROOM_ENCAP_L4_GRE = C.BPF_F_ADJ_ROOM_ENCAP_L4_GRE BPF_F_ADJ_ROOM_ENCAP_L4_UDP = C.BPF_F_ADJ_ROOM_ENCAP_L4_UDP BPF_F_ADJ_ROOM_NO_CSUM_RESET = C.BPF_F_ADJ_ROOM_NO_CSUM_RESET + BPF_F_ADJ_ROOM_ENCAP_L2_ETH = C.BPF_F_ADJ_ROOM_ENCAP_L2_ETH BPF_ADJ_ROOM_ENCAP_L2_MASK = C.BPF_ADJ_ROOM_ENCAP_L2_MASK BPF_ADJ_ROOM_ENCAP_L2_SHIFT = C.BPF_ADJ_ROOM_ENCAP_L2_SHIFT BPF_F_SYSCTL_BASE_NAME = C.BPF_F_SYSCTL_BASE_NAME @@ -2759,10 +2782,16 @@ const ( BPF_LWT_ENCAP_SEG6 = C.BPF_LWT_ENCAP_SEG6 BPF_LWT_ENCAP_SEG6_INLINE = C.BPF_LWT_ENCAP_SEG6_INLINE BPF_LWT_ENCAP_IP = C.BPF_LWT_ENCAP_IP + BPF_F_BPRM_SECUREEXEC = C.BPF_F_BPRM_SECUREEXEC + BPF_F_BROADCAST = C.BPF_F_BROADCAST + BPF_F_EXCLUDE_INGRESS = C.BPF_F_EXCLUDE_INGRESS + BPF_SKB_TSTAMP_UNSPEC = C.BPF_SKB_TSTAMP_UNSPEC + BPF_SKB_TSTAMP_DELIVERY_MONO = C.BPF_SKB_TSTAMP_DELIVERY_MONO BPF_OK = C.BPF_OK BPF_DROP = C.BPF_DROP BPF_REDIRECT = C.BPF_REDIRECT BPF_LWT_REROUTE = C.BPF_LWT_REROUTE + BPF_FLOW_DISSECTOR_CONTINUE = C.BPF_FLOW_DISSECTOR_CONTINUE BPF_SOCK_OPS_RTO_CB_FLAG = C.BPF_SOCK_OPS_RTO_CB_FLAG BPF_SOCK_OPS_RETRANS_CB_FLAG = C.BPF_SOCK_OPS_RETRANS_CB_FLAG BPF_SOCK_OPS_STATE_CB_FLAG = C.BPF_SOCK_OPS_STATE_CB_FLAG @@ -2826,6 +2855,10 @@ const ( BPF_FIB_LKUP_RET_UNSUPP_LWT = C.BPF_FIB_LKUP_RET_UNSUPP_LWT BPF_FIB_LKUP_RET_NO_NEIGH = C.BPF_FIB_LKUP_RET_NO_NEIGH BPF_FIB_LKUP_RET_FRAG_NEEDED = C.BPF_FIB_LKUP_RET_FRAG_NEEDED + BPF_MTU_CHK_SEGS = C.BPF_MTU_CHK_SEGS + BPF_MTU_CHK_RET_SUCCESS = C.BPF_MTU_CHK_RET_SUCCESS + BPF_MTU_CHK_RET_FRAG_NEEDED = C.BPF_MTU_CHK_RET_FRAG_NEEDED + BPF_MTU_CHK_RET_SEGS_TOOBIG = C.BPF_MTU_CHK_RET_SEGS_TOOBIG BPF_FD_TYPE_RAW_TRACEPOINT = C.BPF_FD_TYPE_RAW_TRACEPOINT BPF_FD_TYPE_TRACEPOINT = C.BPF_FD_TYPE_TRACEPOINT BPF_FD_TYPE_KPROBE = C.BPF_FD_TYPE_KPROBE @@ -2835,6 +2868,19 @@ const ( BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG = C.BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL = C.BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP = C.BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP + BPF_CORE_FIELD_BYTE_OFFSET = C.BPF_CORE_FIELD_BYTE_OFFSET + BPF_CORE_FIELD_BYTE_SIZE = C.BPF_CORE_FIELD_BYTE_SIZE + BPF_CORE_FIELD_EXISTS = C.BPF_CORE_FIELD_EXISTS + BPF_CORE_FIELD_SIGNED = C.BPF_CORE_FIELD_SIGNED + BPF_CORE_FIELD_LSHIFT_U64 = C.BPF_CORE_FIELD_LSHIFT_U64 + BPF_CORE_FIELD_RSHIFT_U64 = C.BPF_CORE_FIELD_RSHIFT_U64 + BPF_CORE_TYPE_ID_LOCAL = C.BPF_CORE_TYPE_ID_LOCAL + BPF_CORE_TYPE_ID_TARGET = C.BPF_CORE_TYPE_ID_TARGET + BPF_CORE_TYPE_EXISTS = C.BPF_CORE_TYPE_EXISTS + BPF_CORE_TYPE_SIZE = C.BPF_CORE_TYPE_SIZE + BPF_CORE_ENUMVAL_EXISTS = C.BPF_CORE_ENUMVAL_EXISTS + BPF_CORE_ENUMVAL_VALUE = C.BPF_CORE_ENUMVAL_VALUE + BPF_CORE_TYPE_MATCHES = C.BPF_CORE_TYPE_MATCHES ) // generated by: diff --git a/unix/zerrors_linux_sparc64.go b/unix/zerrors_linux_sparc64.go index f619252691..48984202c6 100644 --- a/unix/zerrors_linux_sparc64.go +++ b/unix/zerrors_linux_sparc64.go @@ -329,6 +329,54 @@ const ( SCM_WIFI_STATUS = 0x25 SFD_CLOEXEC = 0x400000 SFD_NONBLOCK = 0x4000 + SF_FP = 0x38 + SF_I0 = 0x20 + SF_I1 = 0x24 + SF_I2 = 0x28 + SF_I3 = 0x2c + SF_I4 = 0x30 + SF_I5 = 0x34 + SF_L0 = 0x0 + SF_L1 = 0x4 + SF_L2 = 0x8 + SF_L3 = 0xc + SF_L4 = 0x10 + SF_L5 = 0x14 + SF_L6 = 0x18 + SF_L7 = 0x1c + SF_PC = 0x3c + SF_RETP = 0x40 + SF_V9_FP = 0x70 + SF_V9_I0 = 0x40 + SF_V9_I1 = 0x48 + SF_V9_I2 = 0x50 + SF_V9_I3 = 0x58 + SF_V9_I4 = 0x60 + SF_V9_I5 = 0x68 + SF_V9_L0 = 0x0 + SF_V9_L1 = 0x8 + SF_V9_L2 = 0x10 + SF_V9_L3 = 0x18 + SF_V9_L4 = 0x20 + SF_V9_L5 = 0x28 + SF_V9_L6 = 0x30 + SF_V9_L7 = 0x38 + SF_V9_PC = 0x78 + SF_V9_RETP = 0x80 + SF_V9_XARG0 = 0x88 + SF_V9_XARG1 = 0x90 + SF_V9_XARG2 = 0x98 + SF_V9_XARG3 = 0xa0 + SF_V9_XARG4 = 0xa8 + SF_V9_XARG5 = 0xb0 + SF_V9_XXARG = 0xb8 + SF_XARG0 = 0x44 + SF_XARG1 = 0x48 + SF_XARG2 = 0x4c + SF_XARG3 = 0x50 + SF_XARG4 = 0x54 + SF_XARG5 = 0x58 + SF_XXARG = 0x5c SIOCATMARK = 0x8905 SIOCGPGRP = 0x8904 SIOCGSTAMPNS_NEW = 0x40108907 diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index ca84727cfe..00c3b8c20f 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -2555,6 +2555,11 @@ const ( BPF_REG_8 = 0x8 BPF_REG_9 = 0x9 BPF_REG_10 = 0xa + BPF_CGROUP_ITER_ORDER_UNSPEC = 0x0 + BPF_CGROUP_ITER_SELF_ONLY = 0x1 + BPF_CGROUP_ITER_DESCENDANTS_PRE = 0x2 + BPF_CGROUP_ITER_DESCENDANTS_POST = 0x3 + BPF_CGROUP_ITER_ANCESTORS_UP = 0x4 BPF_MAP_CREATE = 0x0 BPF_MAP_LOOKUP_ELEM = 0x1 BPF_MAP_UPDATE_ELEM = 0x2 @@ -2566,6 +2571,7 @@ const ( BPF_PROG_ATTACH = 0x8 BPF_PROG_DETACH = 0x9 BPF_PROG_TEST_RUN = 0xa + BPF_PROG_RUN = 0xa BPF_PROG_GET_NEXT_ID = 0xb BPF_MAP_GET_NEXT_ID = 0xc BPF_PROG_GET_FD_BY_ID = 0xd @@ -2610,6 +2616,7 @@ const ( BPF_MAP_TYPE_CPUMAP = 0x10 BPF_MAP_TYPE_XSKMAP = 0x11 BPF_MAP_TYPE_SOCKHASH = 0x12 + BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED = 0x13 BPF_MAP_TYPE_CGROUP_STORAGE = 0x13 BPF_MAP_TYPE_REUSEPORT_SOCKARRAY = 0x14 BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE = 0x15 @@ -2620,6 +2627,10 @@ const ( BPF_MAP_TYPE_STRUCT_OPS = 0x1a BPF_MAP_TYPE_RINGBUF = 0x1b BPF_MAP_TYPE_INODE_STORAGE = 0x1c + BPF_MAP_TYPE_TASK_STORAGE = 0x1d + BPF_MAP_TYPE_BLOOM_FILTER = 0x1e + BPF_MAP_TYPE_USER_RINGBUF = 0x1f + BPF_MAP_TYPE_CGRP_STORAGE = 0x20 BPF_PROG_TYPE_UNSPEC = 0x0 BPF_PROG_TYPE_SOCKET_FILTER = 0x1 BPF_PROG_TYPE_KPROBE = 0x2 @@ -2651,6 +2662,7 @@ const ( BPF_PROG_TYPE_EXT = 0x1c BPF_PROG_TYPE_LSM = 0x1d BPF_PROG_TYPE_SK_LOOKUP = 0x1e + BPF_PROG_TYPE_SYSCALL = 0x1f BPF_CGROUP_INET_INGRESS = 0x0 BPF_CGROUP_INET_EGRESS = 0x1 BPF_CGROUP_INET_SOCK_CREATE = 0x2 @@ -2689,6 +2701,12 @@ const ( BPF_XDP_CPUMAP = 0x23 BPF_SK_LOOKUP = 0x24 BPF_XDP = 0x25 + BPF_SK_SKB_VERDICT = 0x26 + BPF_SK_REUSEPORT_SELECT = 0x27 + BPF_SK_REUSEPORT_SELECT_OR_MIGRATE = 0x28 + BPF_PERF_EVENT = 0x29 + BPF_TRACE_KPROBE_MULTI = 0x2a + BPF_LSM_CGROUP = 0x2b BPF_LINK_TYPE_UNSPEC = 0x0 BPF_LINK_TYPE_RAW_TRACEPOINT = 0x1 BPF_LINK_TYPE_TRACING = 0x2 @@ -2696,6 +2714,9 @@ const ( BPF_LINK_TYPE_ITER = 0x4 BPF_LINK_TYPE_NETNS = 0x5 BPF_LINK_TYPE_XDP = 0x6 + BPF_LINK_TYPE_PERF_EVENT = 0x7 + BPF_LINK_TYPE_KPROBE_MULTI = 0x8 + BPF_LINK_TYPE_STRUCT_OPS = 0x9 BPF_ANY = 0x0 BPF_NOEXIST = 0x1 BPF_EXIST = 0x2 @@ -2733,6 +2754,7 @@ const ( BPF_F_ZERO_CSUM_TX = 0x2 BPF_F_DONT_FRAGMENT = 0x4 BPF_F_SEQ_NUMBER = 0x8 + BPF_F_TUNINFO_FLAGS = 0x10 BPF_F_INDEX_MASK = 0xffffffff BPF_F_CURRENT_CPU = 0xffffffff BPF_F_CTXLEN_MASK = 0xfffff00000000 @@ -2747,6 +2769,7 @@ const ( BPF_F_ADJ_ROOM_ENCAP_L4_GRE = 0x8 BPF_F_ADJ_ROOM_ENCAP_L4_UDP = 0x10 BPF_F_ADJ_ROOM_NO_CSUM_RESET = 0x20 + BPF_F_ADJ_ROOM_ENCAP_L2_ETH = 0x40 BPF_ADJ_ROOM_ENCAP_L2_MASK = 0xff BPF_ADJ_ROOM_ENCAP_L2_SHIFT = 0x38 BPF_F_SYSCTL_BASE_NAME = 0x1 @@ -2771,10 +2794,16 @@ const ( BPF_LWT_ENCAP_SEG6 = 0x0 BPF_LWT_ENCAP_SEG6_INLINE = 0x1 BPF_LWT_ENCAP_IP = 0x2 + BPF_F_BPRM_SECUREEXEC = 0x1 + BPF_F_BROADCAST = 0x8 + BPF_F_EXCLUDE_INGRESS = 0x10 + BPF_SKB_TSTAMP_UNSPEC = 0x0 + BPF_SKB_TSTAMP_DELIVERY_MONO = 0x1 BPF_OK = 0x0 BPF_DROP = 0x2 BPF_REDIRECT = 0x7 BPF_LWT_REROUTE = 0x80 + BPF_FLOW_DISSECTOR_CONTINUE = 0x81 BPF_SOCK_OPS_RTO_CB_FLAG = 0x1 BPF_SOCK_OPS_RETRANS_CB_FLAG = 0x2 BPF_SOCK_OPS_STATE_CB_FLAG = 0x4 @@ -2838,6 +2867,10 @@ const ( BPF_FIB_LKUP_RET_UNSUPP_LWT = 0x6 BPF_FIB_LKUP_RET_NO_NEIGH = 0x7 BPF_FIB_LKUP_RET_FRAG_NEEDED = 0x8 + BPF_MTU_CHK_SEGS = 0x1 + BPF_MTU_CHK_RET_SUCCESS = 0x0 + BPF_MTU_CHK_RET_FRAG_NEEDED = 0x1 + BPF_MTU_CHK_RET_SEGS_TOOBIG = 0x2 BPF_FD_TYPE_RAW_TRACEPOINT = 0x0 BPF_FD_TYPE_TRACEPOINT = 0x1 BPF_FD_TYPE_KPROBE = 0x2 @@ -2847,6 +2880,19 @@ const ( BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG = 0x1 BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL = 0x2 BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP = 0x4 + BPF_CORE_FIELD_BYTE_OFFSET = 0x0 + BPF_CORE_FIELD_BYTE_SIZE = 0x1 + BPF_CORE_FIELD_EXISTS = 0x2 + BPF_CORE_FIELD_SIGNED = 0x3 + BPF_CORE_FIELD_LSHIFT_U64 = 0x4 + BPF_CORE_FIELD_RSHIFT_U64 = 0x5 + BPF_CORE_TYPE_ID_LOCAL = 0x6 + BPF_CORE_TYPE_ID_TARGET = 0x7 + BPF_CORE_TYPE_EXISTS = 0x8 + BPF_CORE_TYPE_SIZE = 0x9 + BPF_CORE_ENUMVAL_EXISTS = 0xa + BPF_CORE_ENUMVAL_VALUE = 0xb + BPF_CORE_TYPE_MATCHES = 0xc ) const ( From b52f5441ce4ee981d7a9295a5ddad71e196486a7 Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Tue, 30 May 2023 08:16:36 +0000 Subject: [PATCH 06/25] unix: add Getresuid, Getresgid for linux Fixes golang/go#60483 Change-Id: Id4c1bf8367066485a16bedeea337c384a3555942 GitHub-Last-Rev: 61f0fe6f6a5be1cd34ddf99e72a75cfd32355793 GitHub-Pull-Request: golang/sys#159 Reviewed-on: https://go-review.googlesource.com/c/sys/+/499055 Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Tobias Klauser Reviewed-by: Michael Knyszek --- unix/syscall_linux.go | 15 +++++++++++++++ unix/zsyscall_linux.go | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index fbaeb5fff1..aa0c55151a 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -2420,6 +2420,21 @@ func PthreadSigmask(how int, set, oldset *Sigset_t) error { return rtSigprocmask(how, set, oldset, _C__NSIG/8) } +//sysnb getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) +//sysnb getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) + +func Getresuid() (ruid, euid, suid int) { + var r, e, s _C_int + getresuid(&r, &e, &s) + return int(r), int(e), int(s) +} + +func Getresgid() (rgid, egid, sgid int) { + var r, e, s _C_int + getresgid(&r, &e, &s) + return int(r), int(e), int(s) +} + /* * Unimplemented */ diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index da63d9d782..722c29a008 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -2172,3 +2172,17 @@ func rtSigprocmask(how int, set *Sigset_t, oldset *Sigset_t, sigsetsize uintptr) } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) { + RawSyscallNoError(SYS_GETRESUID, uintptr(unsafe.Pointer(ruid)), uintptr(unsafe.Pointer(euid)), uintptr(unsafe.Pointer(suid))) + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) { + RawSyscallNoError(SYS_GETRESGID, uintptr(unsafe.Pointer(rgid)), uintptr(unsafe.Pointer(egid)), uintptr(unsafe.Pointer(sgid))) + return +} From ff98eae2a0cc3ace67e30e3e41908d279a7c13cb Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Sun, 4 Jun 2023 15:20:27 +0000 Subject: [PATCH 07/25] unix: remove absolute path of pwd from mkall.sh The pwd command does not always reside under /bin for all Linux distributions. As a $PATH is otherwise always assumed, here too. Change-Id: I8a9b65fedc0bdd6b963f30e69d5c98b1550326cd GitHub-Last-Rev: ff9227dbe6029506a932d033feea2059c15b4fec GitHub-Pull-Request: golang/sys#161 Reviewed-on: https://go-review.googlesource.com/c/sys/+/500656 Run-TryBot: Ian Lance Taylor Auto-Submit: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot --- unix/mkall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unix/mkall.sh b/unix/mkall.sh index 8e3947c368..e6f31d374d 100755 --- a/unix/mkall.sh +++ b/unix/mkall.sh @@ -50,7 +50,7 @@ if [[ "$GOOS" = "linux" ]]; then # Use the Docker-based build system # Files generated through docker (use $cmd so you can Ctl-C the build or run) $cmd docker build --tag generate:$GOOS $GOOS - $cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")/.." && /bin/pwd):/build generate:$GOOS + $cmd docker run --interactive --tty --volume $(cd -- "$(dirname -- "$0")/.." && pwd):/build generate:$GOOS exit fi From 81c8a6c06d9eb977a4869e7a6b0f9c03f6be9c4e Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Sun, 4 Jun 2023 07:56:06 +0000 Subject: [PATCH 08/25] unix: add Getresuid and Getresgid for OpenBSD Addresses golang/go#60483 for OpenBSD. This change was successfully tested on amd64 and adjusted accordingly for the other architectures. Change-Id: Id63cca342d81d2cc5854eb2923ca7e66bfaa91bf GitHub-Last-Rev: cff11701438edc20bef2961bb73bf9c6ea81b4a1 GitHub-Pull-Request: golang/sys#160 Reviewed-on: https://go-review.googlesource.com/c/sys/+/500655 Reviewed-by: David Chase Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Tobias Klauser TryBot-Result: Gopher Robot --- unix/syscall_openbsd.go | 17 +++++++++++++++-- unix/zsyscall_openbsd_386.go | 22 ++++++++++++++++++++++ unix/zsyscall_openbsd_386.s | 10 ++++++++++ unix/zsyscall_openbsd_amd64.go | 32 ++++++++++++++++++++++++++++---- unix/zsyscall_openbsd_amd64.s | 10 ++++++++++ unix/zsyscall_openbsd_arm.go | 22 ++++++++++++++++++++++ unix/zsyscall_openbsd_arm.s | 10 ++++++++++ unix/zsyscall_openbsd_arm64.go | 22 ++++++++++++++++++++++ unix/zsyscall_openbsd_arm64.s | 10 ++++++++++ unix/zsyscall_openbsd_mips64.go | 22 ++++++++++++++++++++++ unix/zsyscall_openbsd_mips64.s | 10 ++++++++++ unix/zsyscall_openbsd_ppc64.go | 22 ++++++++++++++++++++++ unix/zsyscall_openbsd_ppc64.s | 12 ++++++++++++ unix/zsyscall_openbsd_riscv64.go | 22 ++++++++++++++++++++++ unix/zsyscall_openbsd_riscv64.s | 10 ++++++++++ 15 files changed, 247 insertions(+), 6 deletions(-) diff --git a/unix/syscall_openbsd.go b/unix/syscall_openbsd.go index f9c7a9663c..c5f166a115 100644 --- a/unix/syscall_openbsd.go +++ b/unix/syscall_openbsd.go @@ -151,6 +151,21 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { return } +//sysnb getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) +//sysnb getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) + +func Getresuid() (ruid, euid, suid int) { + var r, e, s _C_int + getresuid(&r, &e, &s) + return int(r), int(e), int(s) +} + +func Getresgid() (rgid, egid, sgid int) { + var r, e, s _C_int + getresgid(&r, &e, &s) + return int(r), int(e), int(s) +} + //sys ioctl(fd int, req uint, arg uintptr) (err error) //sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL @@ -338,8 +353,6 @@ func Uname(uname *Utsname) error { // getgid // getitimer // getlogin -// getresgid -// getresuid // getthrid // ktrace // lfs_bmapv diff --git a/unix/zsyscall_openbsd_386.go b/unix/zsyscall_openbsd_386.go index 6699a783e1..9ab9abf721 100644 --- a/unix/zsyscall_openbsd_386.go +++ b/unix/zsyscall_openbsd_386.go @@ -519,6 +519,28 @@ var libc_getcwd_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) { + syscall_rawSyscall(libc_getresuid_trampoline_addr, uintptr(unsafe.Pointer(ruid)), uintptr(unsafe.Pointer(euid)), uintptr(unsafe.Pointer(suid))) + return +} + +var libc_getresuid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresuid getresuid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) { + syscall_rawSyscall(libc_getresgid_trampoline_addr, uintptr(unsafe.Pointer(rgid)), uintptr(unsafe.Pointer(egid)), uintptr(unsafe.Pointer(sgid))) + return +} + +var libc_getresgid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresgid getresgid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ioctl(fd int, req uint, arg uintptr) (err error) { _, _, e1 := syscall_syscall(libc_ioctl_trampoline_addr, uintptr(fd), uintptr(req), uintptr(arg)) if e1 != 0 { diff --git a/unix/zsyscall_openbsd_386.s b/unix/zsyscall_openbsd_386.s index 04f0de34b2..3dcacd30d7 100644 --- a/unix/zsyscall_openbsd_386.s +++ b/unix/zsyscall_openbsd_386.s @@ -158,6 +158,16 @@ TEXT libc_getcwd_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_getcwd_trampoline_addr(SB), RODATA, $4 DATA ·libc_getcwd_trampoline_addr(SB)/4, $libc_getcwd_trampoline<>(SB) +TEXT libc_getresuid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresuid(SB) +GLOBL ·libc_getresuid_trampoline_addr(SB), RODATA, $4 +DATA ·libc_getresuid_trampoline_addr(SB)/4, $libc_getresuid_trampoline<>(SB) + +TEXT libc_getresgid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresgid(SB) +GLOBL ·libc_getresgid_trampoline_addr(SB), RODATA, $4 +DATA ·libc_getresgid_trampoline_addr(SB)/4, $libc_getresgid_trampoline<>(SB) + TEXT libc_ioctl_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_ioctl(SB) GLOBL ·libc_ioctl_trampoline_addr(SB), RODATA, $4 diff --git a/unix/zsyscall_openbsd_amd64.go b/unix/zsyscall_openbsd_amd64.go index 1e775fe057..915761eab7 100644 --- a/unix/zsyscall_openbsd_amd64.go +++ b/unix/zsyscall_openbsd_amd64.go @@ -519,6 +519,28 @@ var libc_getcwd_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) { + syscall_rawSyscall(libc_getresuid_trampoline_addr, uintptr(unsafe.Pointer(ruid)), uintptr(unsafe.Pointer(euid)), uintptr(unsafe.Pointer(suid))) + return +} + +var libc_getresuid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresuid getresuid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) { + syscall_rawSyscall(libc_getresgid_trampoline_addr, uintptr(unsafe.Pointer(rgid)), uintptr(unsafe.Pointer(egid)), uintptr(unsafe.Pointer(sgid))) + return +} + +var libc_getresgid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresgid getresgid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ioctl(fd int, req uint, arg uintptr) (err error) { _, _, e1 := syscall_syscall(libc_ioctl_trampoline_addr, uintptr(fd), uintptr(req), uintptr(arg)) if e1 != 0 { @@ -527,6 +549,12 @@ func ioctl(fd int, req uint, arg uintptr) (err error) { return } +var libc_ioctl_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_ioctl ioctl "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) { _, _, e1 := syscall_syscall(libc_ioctl_trampoline_addr, uintptr(fd), uintptr(req), uintptr(arg)) if e1 != 0 { @@ -535,10 +563,6 @@ func ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) { return } -var libc_ioctl_trampoline_addr uintptr - -//go:cgo_import_dynamic libc_ioctl ioctl "libc.so" - // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { diff --git a/unix/zsyscall_openbsd_amd64.s b/unix/zsyscall_openbsd_amd64.s index 27b6f4df74..2763620b01 100644 --- a/unix/zsyscall_openbsd_amd64.s +++ b/unix/zsyscall_openbsd_amd64.s @@ -158,6 +158,16 @@ TEXT libc_getcwd_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_getcwd_trampoline_addr(SB), RODATA, $8 DATA ·libc_getcwd_trampoline_addr(SB)/8, $libc_getcwd_trampoline<>(SB) +TEXT libc_getresuid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresuid(SB) +GLOBL ·libc_getresuid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresuid_trampoline_addr(SB)/8, $libc_getresuid_trampoline<>(SB) + +TEXT libc_getresgid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresgid(SB) +GLOBL ·libc_getresgid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresgid_trampoline_addr(SB)/8, $libc_getresgid_trampoline<>(SB) + TEXT libc_ioctl_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_ioctl(SB) GLOBL ·libc_ioctl_trampoline_addr(SB), RODATA, $8 diff --git a/unix/zsyscall_openbsd_arm.go b/unix/zsyscall_openbsd_arm.go index 7f6427899a..8e87fdf153 100644 --- a/unix/zsyscall_openbsd_arm.go +++ b/unix/zsyscall_openbsd_arm.go @@ -519,6 +519,28 @@ var libc_getcwd_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) { + syscall_rawSyscall(libc_getresuid_trampoline_addr, uintptr(unsafe.Pointer(ruid)), uintptr(unsafe.Pointer(euid)), uintptr(unsafe.Pointer(suid))) + return +} + +var libc_getresuid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresuid getresuid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) { + syscall_rawSyscall(libc_getresgid_trampoline_addr, uintptr(unsafe.Pointer(rgid)), uintptr(unsafe.Pointer(egid)), uintptr(unsafe.Pointer(sgid))) + return +} + +var libc_getresgid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresgid getresgid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ioctl(fd int, req uint, arg uintptr) (err error) { _, _, e1 := syscall_syscall(libc_ioctl_trampoline_addr, uintptr(fd), uintptr(req), uintptr(arg)) if e1 != 0 { diff --git a/unix/zsyscall_openbsd_arm.s b/unix/zsyscall_openbsd_arm.s index b797045fd2..c922314048 100644 --- a/unix/zsyscall_openbsd_arm.s +++ b/unix/zsyscall_openbsd_arm.s @@ -158,6 +158,16 @@ TEXT libc_getcwd_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_getcwd_trampoline_addr(SB), RODATA, $4 DATA ·libc_getcwd_trampoline_addr(SB)/4, $libc_getcwd_trampoline<>(SB) +TEXT libc_getresuid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresuid(SB) +GLOBL ·libc_getresuid_trampoline_addr(SB), RODATA, $4 +DATA ·libc_getresuid_trampoline_addr(SB)/4, $libc_getresuid_trampoline<>(SB) + +TEXT libc_getresgid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresgid(SB) +GLOBL ·libc_getresgid_trampoline_addr(SB), RODATA, $4 +DATA ·libc_getresgid_trampoline_addr(SB)/4, $libc_getresgid_trampoline<>(SB) + TEXT libc_ioctl_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_ioctl(SB) GLOBL ·libc_ioctl_trampoline_addr(SB), RODATA, $4 diff --git a/unix/zsyscall_openbsd_arm64.go b/unix/zsyscall_openbsd_arm64.go index 756ef7b173..12a7a2160e 100644 --- a/unix/zsyscall_openbsd_arm64.go +++ b/unix/zsyscall_openbsd_arm64.go @@ -519,6 +519,28 @@ var libc_getcwd_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) { + syscall_rawSyscall(libc_getresuid_trampoline_addr, uintptr(unsafe.Pointer(ruid)), uintptr(unsafe.Pointer(euid)), uintptr(unsafe.Pointer(suid))) + return +} + +var libc_getresuid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresuid getresuid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) { + syscall_rawSyscall(libc_getresgid_trampoline_addr, uintptr(unsafe.Pointer(rgid)), uintptr(unsafe.Pointer(egid)), uintptr(unsafe.Pointer(sgid))) + return +} + +var libc_getresgid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresgid getresgid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ioctl(fd int, req uint, arg uintptr) (err error) { _, _, e1 := syscall_syscall(libc_ioctl_trampoline_addr, uintptr(fd), uintptr(req), uintptr(arg)) if e1 != 0 { diff --git a/unix/zsyscall_openbsd_arm64.s b/unix/zsyscall_openbsd_arm64.s index a871266221..a6bc32c922 100644 --- a/unix/zsyscall_openbsd_arm64.s +++ b/unix/zsyscall_openbsd_arm64.s @@ -158,6 +158,16 @@ TEXT libc_getcwd_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_getcwd_trampoline_addr(SB), RODATA, $8 DATA ·libc_getcwd_trampoline_addr(SB)/8, $libc_getcwd_trampoline<>(SB) +TEXT libc_getresuid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresuid(SB) +GLOBL ·libc_getresuid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresuid_trampoline_addr(SB)/8, $libc_getresuid_trampoline<>(SB) + +TEXT libc_getresgid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresgid(SB) +GLOBL ·libc_getresgid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresgid_trampoline_addr(SB)/8, $libc_getresgid_trampoline<>(SB) + TEXT libc_ioctl_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_ioctl(SB) GLOBL ·libc_ioctl_trampoline_addr(SB), RODATA, $8 diff --git a/unix/zsyscall_openbsd_mips64.go b/unix/zsyscall_openbsd_mips64.go index 7bc2e24eb9..b19e8aa031 100644 --- a/unix/zsyscall_openbsd_mips64.go +++ b/unix/zsyscall_openbsd_mips64.go @@ -519,6 +519,28 @@ var libc_getcwd_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) { + syscall_rawSyscall(libc_getresuid_trampoline_addr, uintptr(unsafe.Pointer(ruid)), uintptr(unsafe.Pointer(euid)), uintptr(unsafe.Pointer(suid))) + return +} + +var libc_getresuid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresuid getresuid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) { + syscall_rawSyscall(libc_getresgid_trampoline_addr, uintptr(unsafe.Pointer(rgid)), uintptr(unsafe.Pointer(egid)), uintptr(unsafe.Pointer(sgid))) + return +} + +var libc_getresgid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresgid getresgid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ioctl(fd int, req uint, arg uintptr) (err error) { _, _, e1 := syscall_syscall(libc_ioctl_trampoline_addr, uintptr(fd), uintptr(req), uintptr(arg)) if e1 != 0 { diff --git a/unix/zsyscall_openbsd_mips64.s b/unix/zsyscall_openbsd_mips64.s index 05d4bffd79..b4e7bceabf 100644 --- a/unix/zsyscall_openbsd_mips64.s +++ b/unix/zsyscall_openbsd_mips64.s @@ -158,6 +158,16 @@ TEXT libc_getcwd_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_getcwd_trampoline_addr(SB), RODATA, $8 DATA ·libc_getcwd_trampoline_addr(SB)/8, $libc_getcwd_trampoline<>(SB) +TEXT libc_getresuid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresuid(SB) +GLOBL ·libc_getresuid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresuid_trampoline_addr(SB)/8, $libc_getresuid_trampoline<>(SB) + +TEXT libc_getresgid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresgid(SB) +GLOBL ·libc_getresgid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresgid_trampoline_addr(SB)/8, $libc_getresgid_trampoline<>(SB) + TEXT libc_ioctl_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_ioctl(SB) GLOBL ·libc_ioctl_trampoline_addr(SB), RODATA, $8 diff --git a/unix/zsyscall_openbsd_ppc64.go b/unix/zsyscall_openbsd_ppc64.go index 739be6217a..fb99594c93 100644 --- a/unix/zsyscall_openbsd_ppc64.go +++ b/unix/zsyscall_openbsd_ppc64.go @@ -519,6 +519,28 @@ var libc_getcwd_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) { + syscall_rawSyscall(libc_getresuid_trampoline_addr, uintptr(unsafe.Pointer(ruid)), uintptr(unsafe.Pointer(euid)), uintptr(unsafe.Pointer(suid))) + return +} + +var libc_getresuid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresuid getresuid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) { + syscall_rawSyscall(libc_getresgid_trampoline_addr, uintptr(unsafe.Pointer(rgid)), uintptr(unsafe.Pointer(egid)), uintptr(unsafe.Pointer(sgid))) + return +} + +var libc_getresgid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresgid getresgid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ioctl(fd int, req uint, arg uintptr) (err error) { _, _, e1 := syscall_syscall(libc_ioctl_trampoline_addr, uintptr(fd), uintptr(req), uintptr(arg)) if e1 != 0 { diff --git a/unix/zsyscall_openbsd_ppc64.s b/unix/zsyscall_openbsd_ppc64.s index 74a25f8d64..ca3f766009 100644 --- a/unix/zsyscall_openbsd_ppc64.s +++ b/unix/zsyscall_openbsd_ppc64.s @@ -189,6 +189,18 @@ TEXT libc_getcwd_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_getcwd_trampoline_addr(SB), RODATA, $8 DATA ·libc_getcwd_trampoline_addr(SB)/8, $libc_getcwd_trampoline<>(SB) +TEXT libc_getresuid_trampoline<>(SB),NOSPLIT,$0-0 + CALL libc_getresuid(SB) + RET +GLOBL ·libc_getresuid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresuid_trampoline_addr(SB)/8, $libc_getresuid_trampoline<>(SB) + +TEXT libc_getresgid_trampoline<>(SB),NOSPLIT,$0-0 + CALL libc_getresgid(SB) + RET +GLOBL ·libc_getresgid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresgid_trampoline_addr(SB)/8, $libc_getresgid_trampoline<>(SB) + TEXT libc_ioctl_trampoline<>(SB),NOSPLIT,$0-0 CALL libc_ioctl(SB) RET diff --git a/unix/zsyscall_openbsd_riscv64.go b/unix/zsyscall_openbsd_riscv64.go index 7d95a19780..32cbbbc52b 100644 --- a/unix/zsyscall_openbsd_riscv64.go +++ b/unix/zsyscall_openbsd_riscv64.go @@ -519,6 +519,28 @@ var libc_getcwd_trampoline_addr uintptr // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func getresuid(ruid *_C_int, euid *_C_int, suid *_C_int) { + syscall_rawSyscall(libc_getresuid_trampoline_addr, uintptr(unsafe.Pointer(ruid)), uintptr(unsafe.Pointer(euid)), uintptr(unsafe.Pointer(suid))) + return +} + +var libc_getresuid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresuid getresuid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func getresgid(rgid *_C_int, egid *_C_int, sgid *_C_int) { + syscall_rawSyscall(libc_getresgid_trampoline_addr, uintptr(unsafe.Pointer(rgid)), uintptr(unsafe.Pointer(egid)), uintptr(unsafe.Pointer(sgid))) + return +} + +var libc_getresgid_trampoline_addr uintptr + +//go:cgo_import_dynamic libc_getresgid getresgid "libc.so" + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func ioctl(fd int, req uint, arg uintptr) (err error) { _, _, e1 := syscall_syscall(libc_ioctl_trampoline_addr, uintptr(fd), uintptr(req), uintptr(arg)) if e1 != 0 { diff --git a/unix/zsyscall_openbsd_riscv64.s b/unix/zsyscall_openbsd_riscv64.s index 990be24574..477a7d5b21 100644 --- a/unix/zsyscall_openbsd_riscv64.s +++ b/unix/zsyscall_openbsd_riscv64.s @@ -158,6 +158,16 @@ TEXT libc_getcwd_trampoline<>(SB),NOSPLIT,$0-0 GLOBL ·libc_getcwd_trampoline_addr(SB), RODATA, $8 DATA ·libc_getcwd_trampoline_addr(SB)/8, $libc_getcwd_trampoline<>(SB) +TEXT libc_getresuid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresuid(SB) +GLOBL ·libc_getresuid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresuid_trampoline_addr(SB)/8, $libc_getresuid_trampoline<>(SB) + +TEXT libc_getresgid_trampoline<>(SB),NOSPLIT,$0-0 + JMP libc_getresgid(SB) +GLOBL ·libc_getresgid_trampoline_addr(SB), RODATA, $8 +DATA ·libc_getresgid_trampoline_addr(SB)/8, $libc_getresgid_trampoline<>(SB) + TEXT libc_ioctl_trampoline<>(SB),NOSPLIT,$0-0 JMP libc_ioctl(SB) GLOBL ·libc_ioctl_trampoline_addr(SB), RODATA, $8 From 304f187cdba97b70a86421a915114c328653f0de Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Tue, 6 Jun 2023 13:44:54 +0000 Subject: [PATCH 09/25] unix: replace use of strcpy in mkerrors.sh On OpenBSD-current, clang emits a warning message to standard output for the use of strcpy, e.g.: _errors.c(/tmp/_errors-673190.o:(main)): warning: strcpy() is almost always misused, please use strlcpy() This message makes it into the Go source being created, causing gofmt to error on the invalid syntax, and leaving the zerrors file empty. Using strlcpy would be preferred here, but strncpy is enough to silence this message, and is more portable. Change-Id: I16404d74c4406dadda87f211fc0ba062de0d11ac GitHub-Last-Rev: a43b6fbc1b3c2bd9ee473d0dac9a73381e196abf GitHub-Pull-Request: golang/sys#147 Reviewed-on: https://go-review.googlesource.com/c/sys/+/468399 TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: David Chase --- unix/mkerrors.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index be0423e685..3156462715 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -741,7 +741,8 @@ main(void) e = errors[i].num; if(i > 0 && errors[i-1].num == e) continue; - strcpy(buf, strerror(e)); + strncpy(buf, strerror(e), sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; // lowercase first letter: Bad -> bad, but STREAM -> STREAM. if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) buf[0] += a - A; @@ -760,7 +761,8 @@ main(void) e = signals[i].num; if(i > 0 && signals[i-1].num == e) continue; - strcpy(buf, strsignal(e)); + strncpy(buf, strsignal(e), sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; // lowercase first letter: Bad -> bad, but STREAM -> STREAM. if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) buf[0] += a - A; From 5059a07aa46a89cb45ca6eabd13f2173baa73bb3 Mon Sep 17 00:00:00 2001 From: Guoqi Chen Date: Wed, 7 Jun 2023 07:25:11 +0800 Subject: [PATCH 10/25] unix: implement Ptrace{Set,Get}Regs using PTRACE_{GET,SET}REGSET for Linux The same change was already done in CL 501756. Fixes #60679. Change-Id: I5d1f4ad89cabb0ac120b3d72876944fb3283ec6f Reviewed-on: https://go-review.googlesource.com/c/sys/+/501795 Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: David Chase Reviewed-by: Ian Lance Taylor --- unix/syscall_linux.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index aa0c55151a..ec24faea59 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -12,6 +12,7 @@ package unix import ( + "debug/elf" "encoding/binary" "strconv" "syscall" @@ -1700,11 +1701,17 @@ func PtracePokeUser(pid int, addr uintptr, data []byte) (count int, err error) { } func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) { - return ptracePtr(PTRACE_GETREGS, pid, 0, unsafe.Pointer(regsout)) + var iov Iovec + iov.Base = (*byte)(unsafe.Pointer(regsout)) + iov.SetLen(int(unsafe.Sizeof(*regsout))) + return ptracePtr(PTRACE_GETREGSET, pid, uintptr(elf.NT_PRSTATUS), unsafe.Pointer(&iov)) } func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) { - return ptracePtr(PTRACE_SETREGS, pid, 0, unsafe.Pointer(regs)) + var iov Iovec + iov.Base = (*byte)(unsafe.Pointer(regs)) + iov.SetLen(int(unsafe.Sizeof(*regs))) + return ptracePtr(PTRACE_SETREGSET, pid, uintptr(elf.NT_PRSTATUS), unsafe.Pointer(&iov)) } func PtraceSetOptions(pid int, options int) (err error) { From 55b11dcdae8194618ad245a452849aa95e461114 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 11 Jun 2023 08:50:10 -0700 Subject: [PATCH 11/25] unix: remove recently introduced debug/elf dependency CL 501795 added a dependency on debug/elf (and thus compress/gzip, debug/dwarf, hash/adler32) Add a copy of the const instead. Change-Id: I2c86094ef7de61b8dd0bdd727f6e547ac7f58527 Reviewed-on: https://go-review.googlesource.com/c/sys/+/502356 Reviewed-by: Tobias Klauser Reviewed-by: David Chase Run-TryBot: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor Auto-Submit: Brad Fitzpatrick TryBot-Result: Gopher Robot --- unix/syscall_linux.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index ec24faea59..6de486befe 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -12,7 +12,6 @@ package unix import ( - "debug/elf" "encoding/binary" "strconv" "syscall" @@ -1700,18 +1699,23 @@ func PtracePokeUser(pid int, addr uintptr, data []byte) (count int, err error) { return ptracePoke(PTRACE_POKEUSR, PTRACE_PEEKUSR, pid, addr, data) } +// elfNT_PRSTATUS is a copy of the debug/elf.NT_PRSTATUS constant so +// x/sys/unix doesn't need to depend on debug/elf and thus +// compress/zlib, debug/dwarf, and other packages. +const elfNT_PRSTATUS = 1 + func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) { var iov Iovec iov.Base = (*byte)(unsafe.Pointer(regsout)) iov.SetLen(int(unsafe.Sizeof(*regsout))) - return ptracePtr(PTRACE_GETREGSET, pid, uintptr(elf.NT_PRSTATUS), unsafe.Pointer(&iov)) + return ptracePtr(PTRACE_GETREGSET, pid, uintptr(elfNT_PRSTATUS), unsafe.Pointer(&iov)) } func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) { var iov Iovec iov.Base = (*byte)(unsafe.Pointer(regs)) iov.SetLen(int(unsafe.Sizeof(*regs))) - return ptracePtr(PTRACE_SETREGSET, pid, uintptr(elf.NT_PRSTATUS), unsafe.Pointer(&iov)) + return ptracePtr(PTRACE_SETREGSET, pid, uintptr(elfNT_PRSTATUS), unsafe.Pointer(&iov)) } func PtraceSetOptions(pid int, options int) (err error) { From df9fef2097f5d2cc202cdebbb32ca0d31fa06ec1 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 14 Jun 2023 14:05:14 +0200 Subject: [PATCH 12/25] unix/linux: update to Linux kernel 6.3 and Go 1.20.5 Change-Id: I347341ae0e45e73477e9a310a3749d37bafa8da7 Reviewed-on: https://go-review.googlesource.com/c/sys/+/503255 Run-TryBot: Tobias Klauser Reviewed-by: Ian Lance Taylor Auto-Submit: Tobias Klauser Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- unix/linux/Dockerfile | 8 ++++---- unix/zerrors_linux.go | 11 +++++++++++ unix/zerrors_linux_arm64.go | 2 ++ unix/ztypes_linux.go | 14 +++++++------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile index 6ae6e464cf..a779033169 100644 --- a/unix/linux/Dockerfile +++ b/unix/linux/Dockerfile @@ -15,15 +15,15 @@ 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 19 Feb 2023 -RUN git clone --branch v6.2 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux +# Linux Kernel: Released 23 Apr 2023 +RUN git clone --branch v6.3 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux # GNU C library: Released 1 Feb 2022 RUN git clone --branch release/2.37/master --depth 1 https://sourceware.org/git/glibc.git # Get Go -ENV GOLANG_VERSION 1.20.1 +ENV GOLANG_VERSION 1.20.5 ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz -ENV GOLANG_DOWNLOAD_SHA256 000a5b1fca4f75895f78befeb2eecf10bfff3c428597f3f1e69133b63b911b02 +ENV GOLANG_DOWNLOAD_SHA256 d7ec48cde0d3d2be2c69203bc3e0a44de8660b9c09a6e85c4732a3f7dc442612 RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index de936b677b..bd4a0fcf12 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -493,6 +493,7 @@ const ( BPF_F_TEST_RUN_ON_CPU = 0x1 BPF_F_TEST_STATE_FREQ = 0x8 BPF_F_TEST_XDP_LIVE_FRAMES = 0x2 + BPF_F_XDP_DEV_BOUND_ONLY = 0x40 BPF_F_XDP_HAS_FRAGS = 0x20 BPF_H = 0x8 BPF_IMM = 0x0 @@ -1197,6 +1198,7 @@ const ( FAN_EVENT_METADATA_LEN = 0x18 FAN_EVENT_ON_CHILD = 0x8000000 FAN_FS_ERROR = 0x8000 + FAN_INFO = 0x20 FAN_MARK_ADD = 0x1 FAN_MARK_DONT_FOLLOW = 0x4 FAN_MARK_EVICTABLE = 0x200 @@ -1233,6 +1235,8 @@ const ( FAN_REPORT_PIDFD = 0x80 FAN_REPORT_TARGET_FID = 0x1000 FAN_REPORT_TID = 0x100 + FAN_RESPONSE_INFO_AUDIT_RULE = 0x1 + FAN_RESPONSE_INFO_NONE = 0x0 FAN_UNLIMITED_MARKS = 0x20 FAN_UNLIMITED_QUEUE = 0x10 FD_CLOEXEC = 0x1 @@ -1860,6 +1864,7 @@ const ( MEMWRITEOOB64 = 0xc0184d15 MFD_ALLOW_SEALING = 0x2 MFD_CLOEXEC = 0x1 + MFD_EXEC = 0x10 MFD_HUGETLB = 0x4 MFD_HUGE_16GB = 0x88000000 MFD_HUGE_16MB = 0x60000000 @@ -1875,6 +1880,7 @@ const ( MFD_HUGE_8MB = 0x5c000000 MFD_HUGE_MASK = 0x3f MFD_HUGE_SHIFT = 0x1a + MFD_NOEXEC_SEAL = 0x8 MINIX2_SUPER_MAGIC = 0x2468 MINIX2_SUPER_MAGIC2 = 0x2478 MINIX3_SUPER_MAGIC = 0x4d5a @@ -2221,6 +2227,7 @@ const ( PERF_ATTR_SIZE_VER5 = 0x70 PERF_ATTR_SIZE_VER6 = 0x78 PERF_ATTR_SIZE_VER7 = 0x80 + PERF_ATTR_SIZE_VER8 = 0x88 PERF_AUX_FLAG_COLLISION = 0x8 PERF_AUX_FLAG_CORESIGHT_FORMAT_CORESIGHT = 0x0 PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW = 0x100 @@ -2369,6 +2376,7 @@ const ( PR_GET_FP_MODE = 0x2e PR_GET_IO_FLUSHER = 0x3a PR_GET_KEEPCAPS = 0x7 + PR_GET_MDWE = 0x42 PR_GET_NAME = 0x10 PR_GET_NO_NEW_PRIVS = 0x27 PR_GET_PDEATHSIG = 0x2 @@ -2389,6 +2397,7 @@ const ( PR_MCE_KILL_GET = 0x22 PR_MCE_KILL_LATE = 0x0 PR_MCE_KILL_SET = 0x1 + PR_MDWE_REFUSE_EXEC_GAIN = 0x1 PR_MPX_DISABLE_MANAGEMENT = 0x2c PR_MPX_ENABLE_MANAGEMENT = 0x2b PR_MTE_TAG_MASK = 0x7fff8 @@ -2423,6 +2432,7 @@ const ( PR_SET_FP_MODE = 0x2d PR_SET_IO_FLUSHER = 0x39 PR_SET_KEEPCAPS = 0x8 + PR_SET_MDWE = 0x41 PR_SET_MM = 0x23 PR_SET_MM_ARG_END = 0x9 PR_SET_MM_ARG_START = 0x8 @@ -3238,6 +3248,7 @@ const ( TP_STATUS_COPY = 0x2 TP_STATUS_CSUMNOTREADY = 0x8 TP_STATUS_CSUM_VALID = 0x80 + TP_STATUS_GSO_TCP = 0x100 TP_STATUS_KERNEL = 0x0 TP_STATUS_LOSING = 0x4 TP_STATUS_SENDING = 0x2 diff --git a/unix/zerrors_linux_arm64.go b/unix/zerrors_linux_arm64.go index 9d5352c3e4..12a9a1389e 100644 --- a/unix/zerrors_linux_arm64.go +++ b/unix/zerrors_linux_arm64.go @@ -443,6 +443,7 @@ const ( TIOCSWINSZ = 0x5414 TIOCVHANGUP = 0x5437 TOSTOP = 0x100 + TPIDR2_MAGIC = 0x54504902 TUNATTACHFILTER = 0x401054d5 TUNDETACHFILTER = 0x401054d6 TUNGETDEVNETNS = 0x54e3 @@ -515,6 +516,7 @@ const ( XCASE = 0x4 XTABS = 0x1800 ZA_MAGIC = 0x54366345 + ZT_MAGIC = 0x5a544e01 _HIDIOCGRAWNAME = 0x80804804 _HIDIOCGRAWPHYS = 0x80404805 _HIDIOCGRAWUNIQ = 0x80404808 diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 00c3b8c20f..56cd76a844 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -1968,7 +1968,7 @@ const ( NFT_MSG_GETFLOWTABLE = 0x17 NFT_MSG_DELFLOWTABLE = 0x18 NFT_MSG_GETRULE_RESET = 0x19 - NFT_MSG_MAX = 0x1a + NFT_MSG_MAX = 0x21 NFTA_LIST_UNSPEC = 0x0 NFTA_LIST_ELEM = 0x1 NFTA_HOOK_UNSPEC = 0x0 @@ -3651,7 +3651,7 @@ const ( ETHTOOL_MSG_PSE_GET = 0x24 ETHTOOL_MSG_PSE_SET = 0x25 ETHTOOL_MSG_RSS_GET = 0x26 - ETHTOOL_MSG_USER_MAX = 0x26 + ETHTOOL_MSG_USER_MAX = 0x2b ETHTOOL_MSG_KERNEL_NONE = 0x0 ETHTOOL_MSG_STRSET_GET_REPLY = 0x1 ETHTOOL_MSG_LINKINFO_GET_REPLY = 0x2 @@ -3691,7 +3691,7 @@ const ( ETHTOOL_MSG_MODULE_NTF = 0x24 ETHTOOL_MSG_PSE_GET_REPLY = 0x25 ETHTOOL_MSG_RSS_GET_REPLY = 0x26 - ETHTOOL_MSG_KERNEL_MAX = 0x26 + ETHTOOL_MSG_KERNEL_MAX = 0x2b ETHTOOL_A_HEADER_UNSPEC = 0x0 ETHTOOL_A_HEADER_DEV_INDEX = 0x1 ETHTOOL_A_HEADER_DEV_NAME = 0x2 @@ -3795,7 +3795,7 @@ const ( ETHTOOL_A_RINGS_TCP_DATA_SPLIT = 0xb ETHTOOL_A_RINGS_CQE_SIZE = 0xc ETHTOOL_A_RINGS_TX_PUSH = 0xd - ETHTOOL_A_RINGS_MAX = 0xd + ETHTOOL_A_RINGS_MAX = 0xe ETHTOOL_A_CHANNELS_UNSPEC = 0x0 ETHTOOL_A_CHANNELS_HEADER = 0x1 ETHTOOL_A_CHANNELS_RX_MAX = 0x2 @@ -3833,14 +3833,14 @@ const ( ETHTOOL_A_COALESCE_RATE_SAMPLE_INTERVAL = 0x17 ETHTOOL_A_COALESCE_USE_CQE_MODE_TX = 0x18 ETHTOOL_A_COALESCE_USE_CQE_MODE_RX = 0x19 - ETHTOOL_A_COALESCE_MAX = 0x19 + ETHTOOL_A_COALESCE_MAX = 0x1c ETHTOOL_A_PAUSE_UNSPEC = 0x0 ETHTOOL_A_PAUSE_HEADER = 0x1 ETHTOOL_A_PAUSE_AUTONEG = 0x2 ETHTOOL_A_PAUSE_RX = 0x3 ETHTOOL_A_PAUSE_TX = 0x4 ETHTOOL_A_PAUSE_STATS = 0x5 - ETHTOOL_A_PAUSE_MAX = 0x5 + ETHTOOL_A_PAUSE_MAX = 0x6 ETHTOOL_A_PAUSE_STAT_UNSPEC = 0x0 ETHTOOL_A_PAUSE_STAT_PAD = 0x1 ETHTOOL_A_PAUSE_STAT_TX_FRAMES = 0x2 @@ -4490,7 +4490,7 @@ const ( NL80211_ATTR_MAC_HINT = 0xc8 NL80211_ATTR_MAC_MASK = 0xd7 NL80211_ATTR_MAX_AP_ASSOC_STA = 0xca - NL80211_ATTR_MAX = 0x141 + NL80211_ATTR_MAX = 0x142 NL80211_ATTR_MAX_CRIT_PROT_DURATION = 0xb4 NL80211_ATTR_MAX_CSA_COUNTERS = 0xce NL80211_ATTR_MAX_MATCH_SETS = 0x85 From ca096e46e860c29133d442ddcdef9c6999385446 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 15 Jun 2023 11:26:01 +0200 Subject: [PATCH 13/25] unix: add missing IFLA_* consts on linux Change-Id: Ib221d98f8d7e5aac7ff2db207cdd92145fe1dc60 Reviewed-on: https://go-review.googlesource.com/c/sys/+/503715 Run-TryBot: Tobias Klauser Reviewed-by: Ian Lance Taylor Auto-Submit: Tobias Klauser TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- unix/linux/types.go | 4 ++++ unix/ztypes_linux.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/unix/linux/types.go b/unix/linux/types.go index fff4ed3001..c19661ffb6 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -1517,6 +1517,10 @@ const ( IFLA_GRO_MAX_SIZE = C.IFLA_GRO_MAX_SIZE IFLA_TSO_MAX_SIZE = C.IFLA_TSO_MAX_SIZE IFLA_TSO_MAX_SEGS = C.IFLA_TSO_MAX_SEGS + IFLA_ALLMULTI = C.IFLA_ALLMULTI + IFLA_DEVLINK_PORT = C.IFLA_DEVLINK_PORT + IFLA_GSO_IPV4_MAX_SIZE = C.IFLA_GSO_IPV4_MAX_SIZE + IFLA_GRO_IPV4_MAX_SIZE = C.IFLA_GRO_IPV4_MAX_SIZE IFLA_PROTO_DOWN_REASON_UNSPEC = C.IFLA_PROTO_DOWN_REASON_UNSPEC IFLA_PROTO_DOWN_REASON_MASK = C.IFLA_PROTO_DOWN_REASON_MASK IFLA_PROTO_DOWN_REASON_VALUE = C.IFLA_PROTO_DOWN_REASON_VALUE diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 56cd76a844..daf91f36d0 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -1538,6 +1538,10 @@ const ( IFLA_GRO_MAX_SIZE = 0x3a IFLA_TSO_MAX_SIZE = 0x3b IFLA_TSO_MAX_SEGS = 0x3c + IFLA_ALLMULTI = 0x3d + IFLA_DEVLINK_PORT = 0x3e + IFLA_GSO_IPV4_MAX_SIZE = 0x3f + IFLA_GRO_IPV4_MAX_SIZE = 0x40 IFLA_PROTO_DOWN_REASON_UNSPEC = 0x0 IFLA_PROTO_DOWN_REASON_MASK = 0x1 IFLA_PROTO_DOWN_REASON_VALUE = 0x2 From e0c3b6e6ae3bf6387b753f5062211beed2e71ded Mon Sep 17 00:00:00 2001 From: Anton Kuklin Date: Fri, 16 Jun 2023 19:17:12 +0000 Subject: [PATCH 14/25] unix: add Mremap for linux For golang/go#60409 Change-Id: I75a9732ee996f0aeb91599d80803f96ada468c27 GitHub-Last-Rev: c348b6194d9fbe92f4f912c66709b0af75810e99 GitHub-Pull-Request: golang/sys#164 Reviewed-on: https://go-review.googlesource.com/c/sys/+/502715 Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor --- unix/mkerrors.sh | 2 +- unix/mremap.go | 40 +++++++++++++++++++++++++++++++++++ unix/mremap_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++ unix/syscall_linux.go | 17 ++++++++++----- unix/zerrors_linux.go | 3 +++ unix/zsyscall_linux.go | 11 ++++++++++ 6 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 unix/mremap.go create mode 100644 unix/mremap_test.go diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index 3156462715..0c4d14929a 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -519,7 +519,7 @@ ccflags="$@" $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || $2 ~ /^LO_(KEY|NAME)_SIZE$/ || $2 ~ /^LOOP_(CLR|CTL|GET|SET)_/ || - $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL|TCPOPT|UDP)_/ || + $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MREMAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL|TCPOPT|UDP)_/ || $2 ~ /^NFC_(GENL|PROTO|COMM|RF|SE|DIRECTION|LLCP|SOCKPROTO)_/ || $2 ~ /^NFC_.*_(MAX)?SIZE$/ || $2 ~ /^RAW_PAYLOAD_/ || diff --git a/unix/mremap.go b/unix/mremap.go new file mode 100644 index 0000000000..86213c05d6 --- /dev/null +++ b/unix/mremap.go @@ -0,0 +1,40 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build linux +// +build linux + +package unix + +import "unsafe" + +type mremapMmapper struct { + mmapper + mremap func(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error) +} + +func (m *mremapMmapper) Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) { + if newLength <= 0 || len(oldData) == 0 || len(oldData) != cap(oldData) || flags&MREMAP_FIXED != 0 { + return nil, EINVAL + } + + pOld := &oldData[cap(oldData)-1] + m.Lock() + defer m.Unlock() + bOld := m.active[pOld] + if bOld == nil || &bOld[0] != &oldData[0] { + return nil, EINVAL + } + newAddr, errno := m.mremap(uintptr(unsafe.Pointer(&bOld[0])), uintptr(len(bOld)), uintptr(newLength), flags, 0) + if errno != nil { + return nil, errno + } + bNew := unsafe.Slice((*byte)(unsafe.Pointer(newAddr)), newLength) + pNew := &bNew[cap(bNew)-1] + if flags&MREMAP_DONTUNMAP == 0 { + delete(m.active, pOld) + } + m.active[pNew] = bNew + return bNew, nil +} diff --git a/unix/mremap_test.go b/unix/mremap_test.go new file mode 100644 index 0000000000..7b1655b817 --- /dev/null +++ b/unix/mremap_test.go @@ -0,0 +1,47 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build linux +// +build linux + +package unix_test + +import ( + "testing" + + "golang.org/x/sys/unix" +) + +func TestMremap(t *testing.T) { + b, err := unix.Mmap(-1, 0, unix.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE) + if err != nil { + t.Fatalf("Mmap: %v", err) + } + if err := unix.Mprotect(b, unix.PROT_READ|unix.PROT_WRITE); err != nil { + t.Fatalf("Mprotect: %v", err) + } + + b[0] = 42 + + bNew, err := unix.Mremap(b, unix.Getpagesize()*2, unix.MREMAP_MAYMOVE) + if err != nil { + t.Fatalf("Mremap2: %v", err) + } + bNew[unix.Getpagesize()+1] = 84 // checks + + if bNew[0] != 42 { + t.Fatal("first element value was changed") + } + if len(bNew) != unix.Getpagesize()*2 { + t.Fatal("new memory len not equal to specified len") + } + if cap(bNew) != unix.Getpagesize()*2 { + t.Fatal("new memory cap not equal to specified len") + } + + _, err = unix.Mremap(b, unix.Getpagesize(), unix.MREMAP_FIXED) + if err != unix.EINVAL { + t.Fatalf("unix.MREMAP_FIXED should be forbidden") + } +} diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 6de486befe..39de5f1430 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -2124,11 +2124,15 @@ func writevRacedetect(iovecs []Iovec, n int) { // mmap varies by architecture; see syscall_linux_*.go. //sys munmap(addr uintptr, length uintptr) (err error) +//sys mremap(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error) -var mapper = &mmapper{ - active: make(map[*byte][]byte), - mmap: mmap, - munmap: munmap, +var mapper = &mremapMmapper{ + mmapper: mmapper{ + active: make(map[*byte][]byte), + mmap: mmap, + munmap: munmap, + }, + mremap: mremap, } func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { @@ -2139,6 +2143,10 @@ func Munmap(b []byte) (err error) { return mapper.Munmap(b) } +func Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) { + return mapper.Mremap(oldData, newLength, flags) +} + //sys Madvise(b []byte, advice int) (err error) //sys Mprotect(b []byte, prot int) (err error) //sys Mlock(b []byte) (err error) @@ -2487,7 +2495,6 @@ func Getresgid() (rgid, egid, sgid int) { // MqTimedreceive // MqTimedsend // MqUnlink -// Mremap // Msgctl // Msgget // Msgrcv diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index bd4a0fcf12..c097b48dad 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -1904,6 +1904,9 @@ const ( MOUNT_ATTR_SIZE_VER0 = 0x20 MOUNT_ATTR_STRICTATIME = 0x20 MOUNT_ATTR__ATIME = 0x70 + MREMAP_DONTUNMAP = 0x4 + MREMAP_FIXED = 0x2 + MREMAP_MAYMOVE = 0x1 MSDOS_SUPER_MAGIC = 0x4d44 MSG_BATCH = 0x40000 MSG_CMSG_CLOEXEC = 0x40000000 diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index 722c29a008..7ceec233fb 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -1868,6 +1868,17 @@ func munmap(addr uintptr, length uintptr) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func mremap(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error) { + r0, _, e1 := Syscall6(SYS_MREMAP, uintptr(oldaddr), uintptr(oldlength), uintptr(newlength), uintptr(flags), uintptr(newaddr), 0) + xaddr = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Madvise(b []byte, advice int) (err error) { var _p0 unsafe.Pointer if len(b) > 0 { From 2b751ddc668a14c2c680cdbf6281c0ec6add8161 Mon Sep 17 00:00:00 2001 From: Craig Davison Date: Wed, 3 May 2023 22:01:01 +0000 Subject: [PATCH 15/25] windows/svc/mgr: add Service.RecoveryActionsOnNonCrashFailures Fixes golang/go#59016 Change-Id: I5e16f61ea2fc384052565342c6517687562260a1 GitHub-Last-Rev: 3626b01fcf35da32b67d11e8439e757de177bbaa GitHub-Pull-Request: golang/sys#157 Reviewed-on: https://go-review.googlesource.com/c/sys/+/484896 Run-TryBot: Bryan Mills Reviewed-by: Alex Brainman Reviewed-by: Bryan Mills Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot --- windows/service.go | 4 +++ windows/svc/mgr/mgr_test.go | 54 +++++++++++++++++++++++++++++++++++++ windows/svc/mgr/recovery.go | 27 +++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/windows/service.go b/windows/service.go index c964b6848d..c44a1b9636 100644 --- a/windows/service.go +++ b/windows/service.go @@ -218,6 +218,10 @@ type SERVICE_FAILURE_ACTIONS struct { Actions *SC_ACTION } +type SERVICE_FAILURE_ACTIONS_FLAG struct { + FailureActionsOnNonCrashFailures int32 +} + type SC_ACTION struct { Type uint32 Delay uint32 diff --git a/windows/svc/mgr/mgr_test.go b/windows/svc/mgr/mgr_test.go index 10d2310790..285dc10ddd 100644 --- a/windows/svc/mgr/mgr_test.go +++ b/windows/svc/mgr/mgr_test.go @@ -209,6 +209,57 @@ func testRecoveryCommand(t *testing.T, s *mgr.Service, should string) { } } +func testRecoveryActionsOnNonCrashFailures(t *testing.T, s *mgr.Service, should bool) { + err := s.SetRecoveryActionsOnNonCrashFailures(should) + if err != nil { + t.Fatalf("SetRecoveryActionsOnNonCrashFailures failed: %v", err) + } + is, err := s.RecoveryActionsOnNonCrashFailures() + if err != nil { + t.Fatalf("RecoveryActionsOnNonCrashFailures failed: %v", err) + } + if should != is { + t.Errorf("RecoveryActionsOnNonCrashFailures mismatch: flag is %v, but should have %v", is, should) + } +} + +func testMultipleRecoverySettings(t *testing.T, s *mgr.Service, rebootMsgShould, recoveryCmdShould string, actionsFlagShould bool) { + err := s.SetRebootMessage(rebootMsgShould) + if err != nil { + t.Fatalf("SetRebootMessage failed: %v", err) + } + err = s.SetRecoveryActionsOnNonCrashFailures(actionsFlagShould) + if err != nil { + t.Fatalf("SetRecoveryActionsOnNonCrashFailures failed: %v", err) + } + err = s.SetRecoveryCommand(recoveryCmdShould) + if err != nil { + t.Fatalf("SetRecoveryCommand failed: %v", err) + } + + rebootMsgIs, err := s.RebootMessage() + if err != nil { + t.Fatalf("RebootMessage failed: %v", err) + } + if rebootMsgShould != rebootMsgIs { + t.Errorf("reboot message mismatch: message is %q, but should have %q", rebootMsgIs, rebootMsgShould) + } + recoveryCommandIs, err := s.RecoveryCommand() + if err != nil { + t.Fatalf("RecoveryCommand failed: %v", err) + } + if recoveryCmdShould != recoveryCommandIs { + t.Errorf("recovery command mismatch: command is %q, but should have %q", recoveryCommandIs, recoveryCmdShould) + } + actionsFlagIs, err := s.RecoveryActionsOnNonCrashFailures() + if err != nil { + t.Fatalf("RecoveryActionsOnNonCrashFailures failed: %v", err) + } + if actionsFlagShould != actionsFlagIs { + t.Errorf("RecoveryActionsOnNonCrashFailures mismatch: flag is %v, but should have %v", actionsFlagIs, actionsFlagShould) + } +} + func testControl(t *testing.T, s *mgr.Service, c svc.Cmd, expectedErr error, expectedStatus svc.Status) { status, err := s.Control(c) if err != expectedErr { @@ -305,6 +356,9 @@ func TestMyService(t *testing.T) { testRebootMessage(t, s, "") // delete reboot message testRecoveryCommand(t, s, fmt.Sprintf("sc query %s", name)) testRecoveryCommand(t, s, "") // delete recovery command + testRecoveryActionsOnNonCrashFailures(t, s, true) + testRecoveryActionsOnNonCrashFailures(t, s, false) + testMultipleRecoverySettings(t, s, fmt.Sprintf("%s failed", name), fmt.Sprintf("sc query %s", name), true) expectedStatus := svc.Status{ State: svc.Stopped, diff --git a/windows/svc/mgr/recovery.go b/windows/svc/mgr/recovery.go index 2e042dd695..321451990b 100644 --- a/windows/svc/mgr/recovery.go +++ b/windows/svc/mgr/recovery.go @@ -140,3 +140,30 @@ func (s *Service) RecoveryCommand() (string, error) { p := (*windows.SERVICE_FAILURE_ACTIONS)(unsafe.Pointer(&b[0])) return windows.UTF16PtrToString(p.Command), nil } + +// SetRecoveryActionsOnNonCrashFailures sets the failure actions flag. If the +// flag is set to false, recovery actions will only be performed if the service +// terminates without reporting a status of SERVICE_STOPPED. If the flag is set +// to true, recovery actions are also perfomed if the service stops with a +// nonzero exit code. +func (s *Service) SetRecoveryActionsOnNonCrashFailures(flag bool) error { + var setting windows.SERVICE_FAILURE_ACTIONS_FLAG + if flag { + setting.FailureActionsOnNonCrashFailures = 1 + } + return windows.ChangeServiceConfig2(s.Handle, windows.SERVICE_CONFIG_FAILURE_ACTIONS_FLAG, (*byte)(unsafe.Pointer(&setting))) +} + +// RecoveryActionsOnNonCrashFailures returns the current value of the failure +// actions flag. If the flag is set to false, recovery actions will only be +// performed if the service terminates without reporting a status of +// SERVICE_STOPPED. If the flag is set to true, recovery actions are also +// perfomed if the service stops with a nonzero exit code. +func (s *Service) RecoveryActionsOnNonCrashFailures() (bool, error) { + b, err := s.queryServiceConfig2(windows.SERVICE_CONFIG_FAILURE_ACTIONS_FLAG) + if err != nil { + return false, err + } + p := (*windows.SERVICE_FAILURE_ACTIONS_FLAG)(unsafe.Pointer(&b[0])) + return p.FailureActionsOnNonCrashFailures != 0, nil +} From d1abdad3a4e261d40157caf02c88c3ec80719ac2 Mon Sep 17 00:00:00 2001 From: Jordan Whited Date: Mon, 26 Jun 2023 22:34:47 +0000 Subject: [PATCH 16/25] unix/linux: update TUN flags and virtio_net_hdr constants TUN_F_USO{4,6} and VIRTIO_NET_HDR_GSO_UDP_L4 are new in Linux v6.2. Change-Id: I7e3dc34118d1c03afeb87fb8699d8167a6e49b7f GitHub-Last-Rev: c658b9bf0f669015f2b4413c0df43102b3875dc3 GitHub-Pull-Request: golang/sys#165 Reviewed-on: https://go-review.googlesource.com/c/sys/+/506455 Reviewed-by: Carlos Amedee Auto-Submit: Carlos Amedee TryBot-Result: Gopher Robot Reviewed-by: Tobias Klauser Run-TryBot: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- unix/linux/types.go | 13 ++++++++----- unix/ztypes_linux.go | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/unix/linux/types.go b/unix/linux/types.go index c19661ffb6..469ff6bcf7 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -5721,6 +5721,8 @@ const ( TUN_F_TSO6 = C.TUN_F_TSO6 TUN_F_TSO_ECN = C.TUN_F_TSO_ECN TUN_F_UFO = C.TUN_F_UFO + TUN_F_USO4 = C.TUN_F_USO4 + TUN_F_USO6 = C.TUN_F_USO6 ) // generated by: @@ -5734,9 +5736,10 @@ const ( // generated by: // perl -nlE '/^#define (VIRTIO_NET_HDR_GSO_\w+)/ && say "$1 = C.$1"' include/uapi/linux/virtio_net.h const ( - VIRTIO_NET_HDR_GSO_NONE = C.VIRTIO_NET_HDR_GSO_NONE - VIRTIO_NET_HDR_GSO_TCPV4 = C.VIRTIO_NET_HDR_GSO_TCPV4 - VIRTIO_NET_HDR_GSO_UDP = C.VIRTIO_NET_HDR_GSO_UDP - VIRTIO_NET_HDR_GSO_TCPV6 = C.VIRTIO_NET_HDR_GSO_TCPV6 - VIRTIO_NET_HDR_GSO_ECN = C.VIRTIO_NET_HDR_GSO_ECN + VIRTIO_NET_HDR_GSO_NONE = C.VIRTIO_NET_HDR_GSO_NONE + VIRTIO_NET_HDR_GSO_TCPV4 = C.VIRTIO_NET_HDR_GSO_TCPV4 + VIRTIO_NET_HDR_GSO_UDP = C.VIRTIO_NET_HDR_GSO_UDP + VIRTIO_NET_HDR_GSO_TCPV6 = C.VIRTIO_NET_HDR_GSO_TCPV6 + VIRTIO_NET_HDR_GSO_UDP_L4 = C.VIRTIO_NET_HDR_GSO_UDP_L4 + VIRTIO_NET_HDR_GSO_ECN = C.VIRTIO_NET_HDR_GSO_ECN ) diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index daf91f36d0..fce104b8fa 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -5845,6 +5845,8 @@ const ( TUN_F_TSO6 = 0x4 TUN_F_TSO_ECN = 0x8 TUN_F_UFO = 0x10 + TUN_F_USO4 = 0x20 + TUN_F_USO6 = 0x40 ) const ( @@ -5854,9 +5856,10 @@ const ( ) const ( - VIRTIO_NET_HDR_GSO_NONE = 0x0 - VIRTIO_NET_HDR_GSO_TCPV4 = 0x1 - VIRTIO_NET_HDR_GSO_UDP = 0x3 - VIRTIO_NET_HDR_GSO_TCPV6 = 0x4 - VIRTIO_NET_HDR_GSO_ECN = 0x80 + VIRTIO_NET_HDR_GSO_NONE = 0x0 + VIRTIO_NET_HDR_GSO_TCPV4 = 0x1 + VIRTIO_NET_HDR_GSO_UDP = 0x3 + VIRTIO_NET_HDR_GSO_TCPV6 = 0x4 + VIRTIO_NET_HDR_GSO_UDP_L4 = 0x5 + VIRTIO_NET_HDR_GSO_ECN = 0x80 ) From 0a92922092b21ff6097f5e152130b634b35a4674 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Mon, 26 Jun 2023 12:46:44 -0400 Subject: [PATCH 17/25] windows: make TestSystemModuleVersions more tolerant One file can't be read on LUCI's Windows image: syscall_windows_test.go:892: CimFS.SYS: The specified resource type cannot be found in the image file. That doesn't seem like a good enough reason to fail the test. Skip the file if this error is encountered. Change-Id: Id9a65b3ff748bbf7ef7fac37d3741c16e001a4b0 Reviewed-on: https://go-review.googlesource.com/c/sys/+/505220 TryBot-Result: Gopher Robot Reviewed-by: Carlos Amedee Run-TryBot: Heschi Kreinick Auto-Submit: Heschi Kreinick Reviewed-by: Quim Muntal --- windows/syscall_windows_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index 81050d3370..0129441531 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -888,22 +888,21 @@ func TestSystemModuleVersions(t *testing.T) { var zero windows.Handle infoSize, err := windows.GetFileVersionInfoSize(driverPath, &zero) if err != nil { - if err != windows.ERROR_FILE_NOT_FOUND { - t.Error(err) + if err != windows.ERROR_FILE_NOT_FOUND && err != windows.ERROR_RESOURCE_TYPE_NOT_FOUND { + t.Errorf("%v: %v", moduleName, err) } continue } versionInfo := make([]byte, infoSize) - err = windows.GetFileVersionInfo(driverPath, 0, infoSize, unsafe.Pointer(&versionInfo[0])) - if err != nil && err != windows.ERROR_FILE_NOT_FOUND { - t.Error(err) + if err = windows.GetFileVersionInfo(driverPath, 0, infoSize, unsafe.Pointer(&versionInfo[0])); err != nil { + t.Errorf("%v: %v", moduleName, err) continue } var fixedInfo *windows.VS_FIXEDFILEINFO fixedInfoLen := uint32(unsafe.Sizeof(*fixedInfo)) err = windows.VerQueryValue(unsafe.Pointer(&versionInfo[0]), `\`, (unsafe.Pointer)(&fixedInfo), &fixedInfoLen) if err != nil { - t.Error(err) + t.Errorf("%v: %v", moduleName, err) continue } t.Logf("%s: v%d.%d.%d.%d", moduleName, From a1a9c4b846b3a485ba94fede5b50579c7f432759 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 26 Jun 2023 15:37:18 +0200 Subject: [PATCH 18/25] unix/linux: update to Linux kernel 6.4 and Go 1.21rc2 Also fix the glibc 2.37 release date in a comment. Change-Id: Ibd972a2846f0085bacf67c847ce4726bf130d5ba Reviewed-on: https://go-review.googlesource.com/c/sys/+/506017 TryBot-Result: Gopher Robot Auto-Submit: Carlos Amedee Reviewed-by: Ian Lance Taylor Run-TryBot: Tobias Klauser Reviewed-by: Carlos Amedee --- unix/linux/Dockerfile | 10 +++++----- unix/zerrors_linux.go | 12 +++++++++--- unix/zsysnum_linux_s390x.go | 1 + unix/ztypes_linux.go | 8 ++++---- unix/ztypes_linux_386.go | 2 ++ unix/ztypes_linux_amd64.go | 2 ++ unix/ztypes_linux_arm.go | 2 ++ unix/ztypes_linux_arm64.go | 2 ++ unix/ztypes_linux_loong64.go | 2 ++ unix/ztypes_linux_mips.go | 2 ++ unix/ztypes_linux_mips64.go | 2 ++ unix/ztypes_linux_mips64le.go | 2 ++ unix/ztypes_linux_mipsle.go | 2 ++ unix/ztypes_linux_ppc.go | 2 ++ unix/ztypes_linux_ppc64.go | 2 ++ unix/ztypes_linux_ppc64le.go | 2 ++ unix/ztypes_linux_riscv64.go | 2 ++ unix/ztypes_linux_s390x.go | 2 ++ unix/ztypes_linux_sparc64.go | 2 ++ 19 files changed, 49 insertions(+), 12 deletions(-) diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile index a779033169..18d3acd3aa 100644 --- a/unix/linux/Dockerfile +++ b/unix/linux/Dockerfile @@ -15,15 +15,15 @@ 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 23 Apr 2023 -RUN git clone --branch v6.3 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux -# GNU C library: Released 1 Feb 2022 +# Linux Kernel: Released 25 June 2023 +RUN git clone --branch v6.4 --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 # Get Go -ENV GOLANG_VERSION 1.20.5 +ENV GOLANG_VERSION 1.21rc2 ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz -ENV GOLANG_DOWNLOAD_SHA256 d7ec48cde0d3d2be2c69203bc3e0a44de8660b9c09a6e85c4732a3f7dc442612 +ENV GOLANG_DOWNLOAD_SHA256 8fe90332727c606019e80a7368e23f5e65ad59520e45ee4010692f15572e45c6 RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go index c097b48dad..3784f402e5 100644 --- a/unix/zerrors_linux.go +++ b/unix/zerrors_linux.go @@ -827,9 +827,9 @@ const ( DM_UUID_FLAG = 0x4000 DM_UUID_LEN = 0x81 DM_VERSION = 0xc138fd00 - DM_VERSION_EXTRA = "-ioctl (2022-07-28)" + DM_VERSION_EXTRA = "-ioctl (2023-03-01)" DM_VERSION_MAJOR = 0x4 - DM_VERSION_MINOR = 0x2f + DM_VERSION_MINOR = 0x30 DM_VERSION_PATCHLEVEL = 0x0 DT_BLK = 0x6 DT_CHR = 0x2 @@ -2213,6 +2213,7 @@ const ( PACKET_USER = 0x6 PACKET_VERSION = 0xa PACKET_VNET_HDR = 0xf + PACKET_VNET_HDR_SZ = 0x18 PARITY_CRC16_PR0 = 0x2 PARITY_CRC16_PR0_CCITT = 0x4 PARITY_CRC16_PR1 = 0x3 @@ -2371,6 +2372,7 @@ const ( PR_FP_EXC_UND = 0x40000 PR_FP_MODE_FR = 0x1 PR_FP_MODE_FRE = 0x2 + PR_GET_AUXV = 0x41555856 PR_GET_CHILD_SUBREAPER = 0x25 PR_GET_DUMPABLE = 0x3 PR_GET_ENDIAN = 0x13 @@ -2380,6 +2382,7 @@ const ( PR_GET_IO_FLUSHER = 0x3a PR_GET_KEEPCAPS = 0x7 PR_GET_MDWE = 0x42 + PR_GET_MEMORY_MERGE = 0x44 PR_GET_NAME = 0x10 PR_GET_NO_NEW_PRIVS = 0x27 PR_GET_PDEATHSIG = 0x2 @@ -2436,6 +2439,7 @@ const ( PR_SET_IO_FLUSHER = 0x39 PR_SET_KEEPCAPS = 0x8 PR_SET_MDWE = 0x41 + PR_SET_MEMORY_MERGE = 0x43 PR_SET_MM = 0x23 PR_SET_MM_ARG_END = 0x9 PR_SET_MM_ARG_START = 0x8 @@ -2519,6 +2523,7 @@ const ( PTRACE_GETSIGMASK = 0x420a PTRACE_GET_RSEQ_CONFIGURATION = 0x420f PTRACE_GET_SYSCALL_INFO = 0x420e + PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG = 0x4211 PTRACE_INTERRUPT = 0x4207 PTRACE_KILL = 0x8 PTRACE_LISTEN = 0x4208 @@ -2549,6 +2554,7 @@ const ( PTRACE_SETREGSET = 0x4205 PTRACE_SETSIGINFO = 0x4203 PTRACE_SETSIGMASK = 0x420b + PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG = 0x4210 PTRACE_SINGLESTEP = 0x9 PTRACE_SYSCALL = 0x18 PTRACE_SYSCALL_INFO_ENTRY = 0x1 @@ -3085,7 +3091,7 @@ const ( TASKSTATS_GENL_NAME = "TASKSTATS" TASKSTATS_GENL_VERSION = 0x1 TASKSTATS_TYPE_MAX = 0x6 - TASKSTATS_VERSION = 0xd + TASKSTATS_VERSION = 0xe TCIFLUSH = 0x0 TCIOFF = 0x2 TCIOFLUSH = 0x2 diff --git a/unix/zsysnum_linux_s390x.go b/unix/zsysnum_linux_s390x.go index 7ea465204b..e6ed7d637d 100644 --- a/unix/zsysnum_linux_s390x.go +++ b/unix/zsysnum_linux_s390x.go @@ -372,6 +372,7 @@ const ( SYS_LANDLOCK_CREATE_RULESET = 444 SYS_LANDLOCK_ADD_RULE = 445 SYS_LANDLOCK_RESTRICT_SELF = 446 + SYS_MEMFD_SECRET = 447 SYS_PROCESS_MRELEASE = 448 SYS_FUTEX_WAITV = 449 SYS_SET_MEMPOLICY_HOME_NODE = 450 diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index fce104b8fa..02e2462c8f 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -3799,7 +3799,7 @@ const ( ETHTOOL_A_RINGS_TCP_DATA_SPLIT = 0xb ETHTOOL_A_RINGS_CQE_SIZE = 0xc ETHTOOL_A_RINGS_TX_PUSH = 0xd - ETHTOOL_A_RINGS_MAX = 0xe + ETHTOOL_A_RINGS_MAX = 0x10 ETHTOOL_A_CHANNELS_UNSPEC = 0x0 ETHTOOL_A_CHANNELS_HEADER = 0x1 ETHTOOL_A_CHANNELS_RX_MAX = 0x2 @@ -4494,7 +4494,7 @@ const ( NL80211_ATTR_MAC_HINT = 0xc8 NL80211_ATTR_MAC_MASK = 0xd7 NL80211_ATTR_MAX_AP_ASSOC_STA = 0xca - NL80211_ATTR_MAX = 0x142 + NL80211_ATTR_MAX = 0x145 NL80211_ATTR_MAX_CRIT_PROT_DURATION = 0xb4 NL80211_ATTR_MAX_CSA_COUNTERS = 0xce NL80211_ATTR_MAX_MATCH_SETS = 0x85 @@ -4723,7 +4723,7 @@ const ( NL80211_BAND_ATTR_HT_CAPA = 0x4 NL80211_BAND_ATTR_HT_MCS_SET = 0x3 NL80211_BAND_ATTR_IFTYPE_DATA = 0x9 - NL80211_BAND_ATTR_MAX = 0xb + NL80211_BAND_ATTR_MAX = 0xd NL80211_BAND_ATTR_RATES = 0x2 NL80211_BAND_ATTR_VHT_CAPA = 0x8 NL80211_BAND_ATTR_VHT_MCS_SET = 0x7 @@ -4864,7 +4864,7 @@ const ( NL80211_CMD_LEAVE_IBSS = 0x2c NL80211_CMD_LEAVE_MESH = 0x45 NL80211_CMD_LEAVE_OCB = 0x6d - NL80211_CMD_MAX = 0x98 + NL80211_CMD_MAX = 0x99 NL80211_CMD_MICHAEL_MIC_FAILURE = 0x29 NL80211_CMD_MODIFY_LINK_STA = 0x97 NL80211_CMD_NAN_MATCH = 0x78 diff --git a/unix/ztypes_linux_386.go b/unix/ztypes_linux_386.go index 4ecc1495cd..6d8acbcc57 100644 --- a/unix/ztypes_linux_386.go +++ b/unix/ztypes_linux_386.go @@ -337,6 +337,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint32 diff --git a/unix/ztypes_linux_amd64.go b/unix/ztypes_linux_amd64.go index 34fddff964..59293c6884 100644 --- a/unix/ztypes_linux_amd64.go +++ b/unix/ztypes_linux_amd64.go @@ -350,6 +350,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 diff --git a/unix/ztypes_linux_arm.go b/unix/ztypes_linux_arm.go index 3b14a6031f..40cfa38c29 100644 --- a/unix/ztypes_linux_arm.go +++ b/unix/ztypes_linux_arm.go @@ -328,6 +328,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint32 diff --git a/unix/ztypes_linux_arm64.go b/unix/ztypes_linux_arm64.go index 0517651ab3..055bc4216d 100644 --- a/unix/ztypes_linux_arm64.go +++ b/unix/ztypes_linux_arm64.go @@ -329,6 +329,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 diff --git a/unix/ztypes_linux_loong64.go b/unix/ztypes_linux_loong64.go index 3b0c518134..f28affbc60 100644 --- a/unix/ztypes_linux_loong64.go +++ b/unix/ztypes_linux_loong64.go @@ -330,6 +330,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 diff --git a/unix/ztypes_linux_mips.go b/unix/ztypes_linux_mips.go index fccdf4dd0f..9d71e7ccd8 100644 --- a/unix/ztypes_linux_mips.go +++ b/unix/ztypes_linux_mips.go @@ -333,6 +333,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint32 diff --git a/unix/ztypes_linux_mips64.go b/unix/ztypes_linux_mips64.go index 500de8fc07..fd5ccd332a 100644 --- a/unix/ztypes_linux_mips64.go +++ b/unix/ztypes_linux_mips64.go @@ -332,6 +332,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 diff --git a/unix/ztypes_linux_mips64le.go b/unix/ztypes_linux_mips64le.go index d0434cd2c6..7704de77a2 100644 --- a/unix/ztypes_linux_mips64le.go +++ b/unix/ztypes_linux_mips64le.go @@ -332,6 +332,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 diff --git a/unix/ztypes_linux_mipsle.go b/unix/ztypes_linux_mipsle.go index 84206ba534..df00b87571 100644 --- a/unix/ztypes_linux_mipsle.go +++ b/unix/ztypes_linux_mipsle.go @@ -333,6 +333,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint32 diff --git a/unix/ztypes_linux_ppc.go b/unix/ztypes_linux_ppc.go index ab078cf1f5..0942840db6 100644 --- a/unix/ztypes_linux_ppc.go +++ b/unix/ztypes_linux_ppc.go @@ -340,6 +340,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint32 diff --git a/unix/ztypes_linux_ppc64.go b/unix/ztypes_linux_ppc64.go index 42eb2c4cef..0348743950 100644 --- a/unix/ztypes_linux_ppc64.go +++ b/unix/ztypes_linux_ppc64.go @@ -339,6 +339,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 diff --git a/unix/ztypes_linux_ppc64le.go b/unix/ztypes_linux_ppc64le.go index 31304a4e8b..bad0670475 100644 --- a/unix/ztypes_linux_ppc64le.go +++ b/unix/ztypes_linux_ppc64le.go @@ -339,6 +339,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 diff --git a/unix/ztypes_linux_riscv64.go b/unix/ztypes_linux_riscv64.go index c311f9612d..9ea54b7b86 100644 --- a/unix/ztypes_linux_riscv64.go +++ b/unix/ztypes_linux_riscv64.go @@ -357,6 +357,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 diff --git a/unix/ztypes_linux_s390x.go b/unix/ztypes_linux_s390x.go index bba3cefac1..aa268d025c 100644 --- a/unix/ztypes_linux_s390x.go +++ b/unix/ztypes_linux_s390x.go @@ -352,6 +352,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 diff --git a/unix/ztypes_linux_sparc64.go b/unix/ztypes_linux_sparc64.go index ad8a013804..444045b6c5 100644 --- a/unix/ztypes_linux_sparc64.go +++ b/unix/ztypes_linux_sparc64.go @@ -334,6 +334,8 @@ type Taskstats struct { Ac_exe_inode uint64 Wpcopy_count uint64 Wpcopy_delay_total uint64 + Irq_count uint64 + Irq_delay_total uint64 } type cpuMask uint64 From 3fead03e7d12219855aa7d4961d58d6b65fe24af Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 7 Jul 2023 15:28:59 +0200 Subject: [PATCH 19/25] unix: add Mremap for netbsd Fixes golang/go#60409 Change-Id: I2d872a1a6fb63c27ab3753deff370e1c2f752bdd Reviewed-on: https://go-review.googlesource.com/c/sys/+/508397 Auto-Submit: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Benny Siegert TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- unix/export_mremap_test.go | 13 +++++++++++++ unix/mmap_nomremap.go | 14 ++++++++++++++ unix/mremap.go | 21 +++++++++++++++++---- unix/mremap_test.go | 10 +++++----- unix/syscall_aix.go | 15 --------------- unix/syscall_bsd.go | 14 -------------- unix/syscall_linux.go | 28 ++++++---------------------- unix/syscall_netbsd.go | 13 ++++++++++++- unix/syscall_solaris.go | 14 -------------- unix/syscall_unix.go | 8 ++++++++ unix/syscall_zos_s390x.go | 14 -------------- unix/zsyscall_netbsd_386.go | 11 +++++++++++ unix/zsyscall_netbsd_amd64.go | 11 +++++++++++ unix/zsyscall_netbsd_arm.go | 11 +++++++++++ unix/zsyscall_netbsd_arm64.go | 11 +++++++++++ 15 files changed, 119 insertions(+), 89 deletions(-) create mode 100644 unix/export_mremap_test.go create mode 100644 unix/mmap_nomremap.go diff --git a/unix/export_mremap_test.go b/unix/export_mremap_test.go new file mode 100644 index 0000000000..1c235c2c3b --- /dev/null +++ b/unix/export_mremap_test.go @@ -0,0 +1,13 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build linux || netbsd +// +build linux netbsd + +package unix + +const ( + MremapFixed = mremapFixed + MremapMaymove = mremapMaymove +) diff --git a/unix/mmap_nomremap.go b/unix/mmap_nomremap.go new file mode 100644 index 0000000000..ca0513632e --- /dev/null +++ b/unix/mmap_nomremap.go @@ -0,0 +1,14 @@ +// Copyright 2023 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 aix || darwin || dragonfly || freebsd || openbsd || solaris +// +build aix darwin dragonfly freebsd openbsd solaris + +package unix + +var mapper = &mmapper{ + active: make(map[*byte][]byte), + mmap: mmap, + munmap: munmap, +} diff --git a/unix/mremap.go b/unix/mremap.go index 86213c05d6..fa93d0aa90 100644 --- a/unix/mremap.go +++ b/unix/mremap.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build linux -// +build linux +//go:build linux || netbsd +// +build linux netbsd package unix @@ -14,8 +14,17 @@ type mremapMmapper struct { mremap func(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error) } +var mapper = &mremapMmapper{ + mmapper: mmapper{ + active: make(map[*byte][]byte), + mmap: mmap, + munmap: munmap, + }, + mremap: mremap, +} + func (m *mremapMmapper) Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) { - if newLength <= 0 || len(oldData) == 0 || len(oldData) != cap(oldData) || flags&MREMAP_FIXED != 0 { + if newLength <= 0 || len(oldData) == 0 || len(oldData) != cap(oldData) || flags&mremapFixed != 0 { return nil, EINVAL } @@ -32,9 +41,13 @@ func (m *mremapMmapper) Mremap(oldData []byte, newLength int, flags int) (data [ } bNew := unsafe.Slice((*byte)(unsafe.Pointer(newAddr)), newLength) pNew := &bNew[cap(bNew)-1] - if flags&MREMAP_DONTUNMAP == 0 { + if flags&mremapDontunmap == 0 { delete(m.active, pOld) } m.active[pNew] = bNew return bNew, nil } + +func Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) { + return mapper.Mremap(oldData, newLength, flags) +} diff --git a/unix/mremap_test.go b/unix/mremap_test.go index 7b1655b817..40d4f60dcf 100644 --- a/unix/mremap_test.go +++ b/unix/mremap_test.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build linux -// +build linux +//go:build linux || netbsd +// +build linux netbsd package unix_test @@ -24,7 +24,7 @@ func TestMremap(t *testing.T) { b[0] = 42 - bNew, err := unix.Mremap(b, unix.Getpagesize()*2, unix.MREMAP_MAYMOVE) + bNew, err := unix.Mremap(b, unix.Getpagesize()*2, unix.MremapMaymove) if err != nil { t.Fatalf("Mremap2: %v", err) } @@ -40,8 +40,8 @@ func TestMremap(t *testing.T) { t.Fatal("new memory cap not equal to specified len") } - _, err = unix.Mremap(b, unix.Getpagesize(), unix.MREMAP_FIXED) + _, err = unix.Mremap(b, unix.Getpagesize(), unix.MremapFixed) if err != unix.EINVAL { - t.Fatalf("unix.MREMAP_FIXED should be forbidden") + t.Fatalf("remapping to a fixed address; got %v, want %v", err, unix.EINVAL) } } diff --git a/unix/syscall_aix.go b/unix/syscall_aix.go index c406ae00f4..9a6e5acacb 100644 --- a/unix/syscall_aix.go +++ b/unix/syscall_aix.go @@ -535,21 +535,6 @@ func Fsync(fd int) error { //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) = nsendmsg //sys munmap(addr uintptr, length uintptr) (err error) - -var mapper = &mmapper{ - active: make(map[*byte][]byte), - mmap: mmap, - munmap: munmap, -} - -func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { - return mapper.Mmap(fd, offset, length, prot, flags) -} - -func Munmap(b []byte) (err error) { - return mapper.Munmap(b) -} - //sys Madvise(b []byte, advice int) (err error) //sys Mprotect(b []byte, prot int) (err error) //sys Mlock(b []byte) (err error) diff --git a/unix/syscall_bsd.go b/unix/syscall_bsd.go index 7705c3270b..4217de518b 100644 --- a/unix/syscall_bsd.go +++ b/unix/syscall_bsd.go @@ -601,20 +601,6 @@ func Poll(fds []PollFd, timeout int) (n int, err error) { // Gethostuuid(uuid *byte, timeout *Timespec) (err error) // Ptrace(req int, pid int, addr uintptr, data int) (ret uintptr, err error) -var mapper = &mmapper{ - active: make(map[*byte][]byte), - mmap: mmap, - munmap: munmap, -} - -func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { - return mapper.Mmap(fd, offset, length, prot, flags) -} - -func Munmap(b []byte) (err error) { - return mapper.Munmap(b) -} - //sys Madvise(b []byte, behav int) (err error) //sys Mlock(b []byte) (err error) //sys Mlockall(flags int) (err error) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 39de5f1430..332a74b8ee 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -2125,28 +2125,6 @@ func writevRacedetect(iovecs []Iovec, n int) { // mmap varies by architecture; see syscall_linux_*.go. //sys munmap(addr uintptr, length uintptr) (err error) //sys mremap(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (xaddr uintptr, err error) - -var mapper = &mremapMmapper{ - mmapper: mmapper{ - active: make(map[*byte][]byte), - mmap: mmap, - munmap: munmap, - }, - mremap: mremap, -} - -func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { - return mapper.Mmap(fd, offset, length, prot, flags) -} - -func Munmap(b []byte) (err error) { - return mapper.Munmap(b) -} - -func Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) { - return mapper.Mremap(oldData, newLength, flags) -} - //sys Madvise(b []byte, advice int) (err error) //sys Mprotect(b []byte, prot int) (err error) //sys Mlock(b []byte) (err error) @@ -2155,6 +2133,12 @@ func Mremap(oldData []byte, newLength int, flags int) (data []byte, err error) { //sys Munlock(b []byte) (err error) //sys Munlockall() (err error) +const ( + mremapFixed = MREMAP_FIXED + mremapDontunmap = MREMAP_DONTUNMAP + mremapMaymove = MREMAP_MAYMOVE +) + // Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd, // using the specified flags. func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) { diff --git a/unix/syscall_netbsd.go b/unix/syscall_netbsd.go index 018d7d4782..ddd1ac8534 100644 --- a/unix/syscall_netbsd.go +++ b/unix/syscall_netbsd.go @@ -360,6 +360,18 @@ func Statvfs(path string, buf *Statvfs_t) (err error) { //sys writelen(fd int, buf *byte, nbuf int) (n int, err error) = SYS_WRITE //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error) +const ( + mremapFixed = MAP_FIXED + mremapDontunmap = 0 + mremapMaymove = 0 +) + +//sys mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) = SYS_MREMAP + +func mremap(oldaddr uintptr, oldlength uintptr, newlength uintptr, flags int, newaddr uintptr) (uintptr, error) { + return mremapNetBSD(oldaddr, oldlength, newaddr, newlength, flags) +} + /* * Unimplemented */ @@ -564,7 +576,6 @@ func Statvfs(path string, buf *Statvfs_t) (err error) { // mq_timedreceive // mq_timedsend // mq_unlink -// mremap // msgget // msgrcv // msgsnd diff --git a/unix/syscall_solaris.go b/unix/syscall_solaris.go index b600a289d3..72d23575fa 100644 --- a/unix/syscall_solaris.go +++ b/unix/syscall_solaris.go @@ -716,20 +716,6 @@ func writelen(fd int, buf *byte, nbuf int) (n int, err error) { return } -var mapper = &mmapper{ - active: make(map[*byte][]byte), - mmap: mmap, - munmap: munmap, -} - -func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { - return mapper.Mmap(fd, offset, length, prot, flags) -} - -func Munmap(b []byte) (err error) { - return mapper.Munmap(b) -} - // Event Ports type fileObjCookie struct { diff --git a/unix/syscall_unix.go b/unix/syscall_unix.go index 8e48c29ec3..8bb30e7ce3 100644 --- a/unix/syscall_unix.go +++ b/unix/syscall_unix.go @@ -147,6 +147,14 @@ func (m *mmapper) Munmap(data []byte) (err error) { return nil } +func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { + return mapper.Mmap(fd, offset, length, prot, flags) +} + +func Munmap(b []byte) (err error) { + return mapper.Munmap(b) +} + func Read(fd int, p []byte) (n int, err error) { n, err = read(fd, p) if raceenabled { diff --git a/unix/syscall_zos_s390x.go b/unix/syscall_zos_s390x.go index d3d49ec3ed..44e72edb42 100644 --- a/unix/syscall_zos_s390x.go +++ b/unix/syscall_zos_s390x.go @@ -285,25 +285,11 @@ func Close(fd int) (err error) { return } -var mapper = &mmapper{ - active: make(map[*byte][]byte), - mmap: mmap, - munmap: munmap, -} - // Dummy function: there are no semantics for Madvise on z/OS func Madvise(b []byte, advice int) (err error) { return } -func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) { - return mapper.Mmap(fd, offset, length, prot, flags) -} - -func Munmap(b []byte) (err error) { - return mapper.Munmap(b) -} - //sys Gethostname(buf []byte) (err error) = SYS___GETHOSTNAME_A //sysnb Getegid() (egid int) //sysnb Geteuid() (uid int) diff --git a/unix/zsyscall_netbsd_386.go b/unix/zsyscall_netbsd_386.go index cdb2af5ae0..35f499b32a 100644 --- a/unix/zsyscall_netbsd_386.go +++ b/unix/zsyscall_netbsd_386.go @@ -1858,3 +1858,14 @@ func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) { + r0, _, e1 := Syscall6(SYS_MREMAP, uintptr(oldp), uintptr(oldsize), uintptr(newp), uintptr(newsize), uintptr(flags), 0) + xaddr = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/unix/zsyscall_netbsd_amd64.go b/unix/zsyscall_netbsd_amd64.go index 9d25f76b0b..3cda65b0da 100644 --- a/unix/zsyscall_netbsd_amd64.go +++ b/unix/zsyscall_netbsd_amd64.go @@ -1858,3 +1858,14 @@ func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) { + r0, _, e1 := Syscall6(SYS_MREMAP, uintptr(oldp), uintptr(oldsize), uintptr(newp), uintptr(newsize), uintptr(flags), 0) + xaddr = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/unix/zsyscall_netbsd_arm.go b/unix/zsyscall_netbsd_arm.go index d3f8035169..1e1fea902b 100644 --- a/unix/zsyscall_netbsd_arm.go +++ b/unix/zsyscall_netbsd_arm.go @@ -1858,3 +1858,14 @@ func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) { + r0, _, e1 := Syscall6(SYS_MREMAP, uintptr(oldp), uintptr(oldsize), uintptr(newp), uintptr(newsize), uintptr(flags), 0) + xaddr = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/unix/zsyscall_netbsd_arm64.go b/unix/zsyscall_netbsd_arm64.go index 887188a529..3b77da1107 100644 --- a/unix/zsyscall_netbsd_arm64.go +++ b/unix/zsyscall_netbsd_arm64.go @@ -1858,3 +1858,14 @@ func utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func mremapNetBSD(oldp uintptr, oldsize uintptr, newp uintptr, newsize uintptr, flags int) (xaddr uintptr, err error) { + r0, _, e1 := Syscall6(SYS_MREMAP, uintptr(oldp), uintptr(oldsize), uintptr(newp), uintptr(newsize), uintptr(flags), 0) + xaddr = uintptr(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} From 706fa9866a6caa202cb91ad9bf910e4fa9faca0d Mon Sep 17 00:00:00 2001 From: cui fliter Date: Sat, 15 Jul 2023 00:25:39 +0800 Subject: [PATCH 20/25] windows: remove repetitive words Change-Id: I9c944eca6117b1039f0c5287706cb447b75c8cbd Reviewed-on: https://go-review.googlesource.com/c/sys/+/509835 Reviewed-by: Ian Lance Taylor Reviewed-by: Heschi Kreinick TryBot-Result: Gopher Robot Auto-Submit: Ian Lance Taylor Reviewed-by: Alex Brainman Run-TryBot: Ian Lance Taylor --- windows/syscall_windows.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index 9645900754..373d16388a 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -135,14 +135,14 @@ func Getpagesize() int { return 4096 } // NewCallback converts a Go function to a function pointer conforming to the stdcall calling convention. // This is useful when interoperating with Windows code requiring callbacks. -// The argument is expected to be a function with with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr. +// The argument is expected to be a function with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr. func NewCallback(fn interface{}) uintptr { return syscall.NewCallback(fn) } // NewCallbackCDecl converts a Go function to a function pointer conforming to the cdecl calling convention. // This is useful when interoperating with Windows code requiring callbacks. -// The argument is expected to be a function with with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr. +// The argument is expected to be a function with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr. func NewCallbackCDecl(fn interface{}) uintptr { return syscall.NewCallbackCDecl(fn) } From 25d0004552bee01a3ba08d943dadc39e3c361f77 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Tue, 18 Jul 2023 21:23:29 +0000 Subject: [PATCH 21/25] unix: fix last argument of pselect6 on linux On Linux, the last argument of pselect6 system call is **not** a sigseg_t * pointer, but instead it is a structure of the form: struct { const sigset_t *ss; /* Pointer to signal set */ size_t ss_len; /* Size (in bytes) of object pointed }; See man 2 pselect6. Fixes #61251 Change-Id: Id0aa122a77796713bc6d624dc395d396fbc0c5e2 GitHub-Last-Rev: cb3c6d7da9b846843a4a81898ebfdcf2e449942a GitHub-Pull-Request: golang/sys#167 Reviewed-on: https://go-review.googlesource.com/c/sys/+/510195 Reviewed-by: Bryan Mills Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- unix/linux/types.go | 4 ++++ unix/syscall_linux.go | 35 ++++++++++++++++++++++++++++++++++- unix/syscall_linux_amd64.go | 2 +- unix/syscall_linux_arm64.go | 2 +- unix/syscall_linux_loong64.go | 2 +- unix/syscall_linux_mips64x.go | 2 +- unix/syscall_linux_riscv64.go | 2 +- unix/syscall_linux_test.go | 18 ++++++++++++++++++ unix/zsyscall_linux.go | 2 +- unix/ztypes_linux.go | 5 +++++ 10 files changed, 67 insertions(+), 7 deletions(-) diff --git a/unix/linux/types.go b/unix/linux/types.go index 469ff6bcf7..f2cbd2d458 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -968,6 +968,10 @@ const ( ) type Sigset_t C.sigset_t +type sigset_argpack struct { + ss *Sigset_t + ssLen uintptr // Size (in bytes) of object pointed to by ss. +} const _C__NSIG = C._NSIG diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 332a74b8ee..a730878e49 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -1885,7 +1885,7 @@ func Getpgrp() (pid int) { //sys PerfEventOpen(attr *PerfEventAttr, pid int, cpu int, groupFd int, flags int) (fd int, err error) //sys PivotRoot(newroot string, putold string) (err error) = SYS_PIVOT_ROOT //sys Prctl(option int, arg2 uintptr, arg3 uintptr, arg4 uintptr, arg5 uintptr) (err error) -//sys Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) = SYS_PSELECT6 +//sys pselect6(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *sigset_argpack) (n int, err error) //sys read(fd int, p []byte) (n int, err error) //sys Removexattr(path string, attr string) (err error) //sys Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error) @@ -2438,6 +2438,39 @@ func Getresgid() (rgid, egid, sgid int) { return int(r), int(e), int(s) } +// Pselect is a wrapper around the Linux pselect6 system call. +// This version does not modify the timeout argument. +func Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { + // Per https://man7.org/linux/man-pages/man2/select.2.html#NOTES, + // The Linux pselect6() system call modifies its timeout argument. + // [Not modifying the argument] is the behavior required by POSIX.1-2001. + var mutableTimeout *Timespec + if timeout != nil { + mutableTimeout = new(Timespec) + *mutableTimeout = *timeout + } + + // The final argument of the pselect6() system call is not a + // sigset_t * pointer, but is instead a structure + var kernelMask *sigset_argpack + if sigmask != nil { + wordBits := 32 << (^uintptr(0) >> 63) // see math.intSize + + // A sigset stores one bit per signal, + // offset by 1 (because signal 0 does not exist). + // So the number of words needed is ⌈__C_NSIG - 1 / wordBits⌉. + sigsetWords := (_C__NSIG - 1 + wordBits - 1) / (wordBits) + + sigsetBytes := uintptr(sigsetWords * (wordBits / 8)) + kernelMask = &sigset_argpack{ + ss: sigmask, + ssLen: sigsetBytes, + } + } + + return pselect6(nfd, r, w, e, mutableTimeout, kernelMask) +} + /* * Unimplemented */ diff --git a/unix/syscall_linux_amd64.go b/unix/syscall_linux_amd64.go index 5b21fcfd75..70601ce369 100644 --- a/unix/syscall_linux_amd64.go +++ b/unix/syscall_linux_amd64.go @@ -40,7 +40,7 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err if timeout != nil { ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000} } - return Pselect(nfd, r, w, e, ts, nil) + return pselect6(nfd, r, w, e, ts, nil) } //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) diff --git a/unix/syscall_linux_arm64.go b/unix/syscall_linux_arm64.go index a81f5742b8..f5266689af 100644 --- a/unix/syscall_linux_arm64.go +++ b/unix/syscall_linux_arm64.go @@ -33,7 +33,7 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err if timeout != nil { ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000} } - return Pselect(nfd, r, w, e, ts, nil) + return pselect6(nfd, r, w, e, ts, nil) } //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) diff --git a/unix/syscall_linux_loong64.go b/unix/syscall_linux_loong64.go index 69d2d7c3db..f6ab02ec15 100644 --- a/unix/syscall_linux_loong64.go +++ b/unix/syscall_linux_loong64.go @@ -28,7 +28,7 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err if timeout != nil { ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000} } - return Pselect(nfd, r, w, e, ts, nil) + return pselect6(nfd, r, w, e, ts, nil) } //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) diff --git a/unix/syscall_linux_mips64x.go b/unix/syscall_linux_mips64x.go index 76d564095e..93fe59d25d 100644 --- a/unix/syscall_linux_mips64x.go +++ b/unix/syscall_linux_mips64x.go @@ -31,7 +31,7 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err if timeout != nil { ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000} } - return Pselect(nfd, r, w, e, ts, nil) + return pselect6(nfd, r, w, e, ts, nil) } //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) diff --git a/unix/syscall_linux_riscv64.go b/unix/syscall_linux_riscv64.go index 35851ef70b..b1de100ac0 100644 --- a/unix/syscall_linux_riscv64.go +++ b/unix/syscall_linux_riscv64.go @@ -32,7 +32,7 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err if timeout != nil { ts = &Timespec{Sec: timeout.Sec, Nsec: timeout.Usec * 1000} } - return Pselect(nfd, r, w, e, ts, nil) + return pselect6(nfd, r, w, e, ts, nil) } //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index 2787fe57a3..dee874598d 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -444,6 +444,24 @@ func TestPselect(t *testing.T) { } } +func TestPselectWithSigmask(t *testing.T) { + var sigmask unix.Sigset_t + sigmask.Val[0] |= 1 << (uint(unix.SIGUSR1) - 1) + for { + n, err := unix.Pselect(0, nil, nil, nil, &unix.Timespec{Sec: 0, Nsec: 0}, &sigmask) + if err == unix.EINTR { + t.Logf("Pselect interrupted") + continue + } else if err != nil { + t.Fatalf("Pselect: %v", err) + } + if n != 0 { + t.Fatalf("Pselect: got %v ready file descriptors, expected 0", n) + } + break + } +} + func TestSchedSetaffinity(t *testing.T) { var newMask unix.CPUSet newMask.Zero() diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index 7ceec233fb..a07321bed9 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -1356,7 +1356,7 @@ func Prctl(option int, arg2 uintptr, arg3 uintptr, arg4 uintptr, arg5 uintptr) ( // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) { +func pselect6(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *sigset_argpack) (n int, err error) { r0, _, e1 := Syscall6(SYS_PSELECT6, uintptr(nfd), uintptr(unsafe.Pointer(r)), uintptr(unsafe.Pointer(w)), uintptr(unsafe.Pointer(e)), uintptr(unsafe.Pointer(timeout)), uintptr(unsafe.Pointer(sigmask))) n = int(r0) if e1 != 0 { diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 02e2462c8f..26ef52aafc 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -866,6 +866,11 @@ const ( POLLNVAL = 0x20 ) +type sigset_argpack struct { + ss *Sigset_t + ssLen uintptr +} + type SignalfdSiginfo struct { Signo uint32 Errno int32 From c406141231ada89c399c39dd52dd1e279c509f5c Mon Sep 17 00:00:00 2001 From: cui fliter Date: Tue, 18 Jul 2023 11:10:42 +0800 Subject: [PATCH 22/25] all: fix some typos Change-Id: Id4bf4ce8aee8b98baa2f1a9c62a72a9554f7d557 Reviewed-on: https://go-review.googlesource.com/c/sys/+/510595 TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Run-TryBot: shuang cui Reviewed-by: Ian Lance Taylor Reviewed-by: Heschi Kreinick --- unix/syscall_internal_darwin_test.go | 4 ++-- unix/syscall_internal_linux_test.go | 2 +- windows/svc/svc_test.go | 10 +++++----- windows/syscall_windows_test.go | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/unix/syscall_internal_darwin_test.go b/unix/syscall_internal_darwin_test.go index 1ac0896254..f7de072805 100644 --- a/unix/syscall_internal_darwin_test.go +++ b/unix/syscall_internal_darwin_test.go @@ -18,7 +18,7 @@ func Test_anyToSockaddr_darwin(t *testing.T) { err error }{ { - name: "AF_SYSTEM emtpy", + name: "AF_SYSTEM empty", rsa: sockaddrCtlToAny(RawSockaddrCtl{}), err: EAFNOSUPPORT, }, @@ -51,7 +51,7 @@ func Test_anyToSockaddr_darwin(t *testing.T) { }, }, { - name: "AF_VSOCK emtpy", + name: "AF_VSOCK empty", rsa: sockaddrVMToAny(RawSockaddrVM{}), err: EAFNOSUPPORT, }, diff --git a/unix/syscall_internal_linux_test.go b/unix/syscall_internal_linux_test.go index fd6d21915e..d2aebe373d 100644 --- a/unix/syscall_internal_linux_test.go +++ b/unix/syscall_internal_linux_test.go @@ -254,7 +254,7 @@ func Test_anyToSockaddr(t *testing.T) { proto: makeProto(^0), }, { - name: "AF_VSOCK emtpy", + name: "AF_VSOCK empty", rsa: sockaddrVMToAny(RawSockaddrVM{}), err: EAFNOSUPPORT, }, diff --git a/windows/svc/svc_test.go b/windows/svc/svc_test.go index 5d794e1966..6439a06b26 100644 --- a/windows/svc/svc_test.go +++ b/windows/svc/svc_test.go @@ -163,7 +163,7 @@ func TestIsAnInteractiveSession(t *testing.T) { t.Fatal(err) } if !isInteractive { - t.Error("IsAnInteractiveSession retuns false when running interactively.") + t.Error("IsAnInteractiveSession returns false when running interactively.") } } @@ -173,7 +173,7 @@ func TestIsWindowsService(t *testing.T) { t.Fatal(err) } if isSvc { - t.Error("IsWindowsService retuns true when not running in a service.") + t.Error("IsWindowsService returns true when not running in a service.") } } @@ -206,7 +206,7 @@ func TestIsWindowsServiceWhenParentExits(t *testing.T) { msg = err.Error() } if isSvc { - msg = "IsWindowsService retuns true when not running in a service." + msg = "IsWindowsService returns true when not running in a service." } err = ioutil.WriteFile(dumpPath, []byte(msg), 0644) if err != nil { @@ -235,12 +235,12 @@ func TestIsWindowsServiceWhenParentExits(t *testing.T) { } time.Sleep(100 * time.Millisecond) if i > 10 { - t.Fatal("timed out waiting for child ouput file to be created.") + t.Fatal("timed out waiting for child output file to be created.") } } childOutput, err := ioutil.ReadFile(childDumpPath) if err != nil { - t.Fatalf("reading child ouput failed: %v", err) + t.Fatalf("reading child output failed: %v", err) } if got, want := string(childOutput), ""; got != want { t.Fatalf("child output: want %q, got %q", want, got) diff --git a/windows/syscall_windows_test.go b/windows/syscall_windows_test.go index 0129441531..25f47ea533 100644 --- a/windows/syscall_windows_test.go +++ b/windows/syscall_windows_test.go @@ -226,7 +226,7 @@ func TestKnownFolderPath(t *testing.T) { func TestRtlGetVersion(t *testing.T) { version := windows.RtlGetVersion() major, minor, build := windows.RtlGetNtVersionNumbers() - // Go is not explictly added to the application compatibility database, so + // Go is not explicitly added to the application compatibility database, so // these two functions should return the same thing. if version.MajorVersion != major || version.MinorVersion != minor || version.BuildNumber != build { t.Fatalf("%d.%d.%d != %d.%d.%d", version.MajorVersion, version.MinorVersion, version.BuildNumber, major, minor, build) From ad7130c58d2235b6332aedb42030b3f3fb02ee1a Mon Sep 17 00:00:00 2001 From: Lorenz Brun Date: Thu, 20 Jul 2023 16:36:09 +0200 Subject: [PATCH 23/25] unix: add more block device ioctl numbers This adds a few additional ioctl numbers for performing various block device operations. Change-Id: I1dc836f4017bbc175b2dee759fece728f1caa010 Reviewed-on: https://go-review.googlesource.com/c/sys/+/511597 Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Bryan Mills Run-TryBot: Bryan Mills Run-TryBot: Ian Lance Taylor TryBot-Result: Gopher Robot --- unix/mkerrors.sh | 2 +- unix/zerrors_linux_386.go | 9 +++++++++ unix/zerrors_linux_amd64.go | 9 +++++++++ unix/zerrors_linux_arm.go | 9 +++++++++ unix/zerrors_linux_arm64.go | 9 +++++++++ unix/zerrors_linux_loong64.go | 9 +++++++++ unix/zerrors_linux_mips.go | 9 +++++++++ unix/zerrors_linux_mips64.go | 9 +++++++++ unix/zerrors_linux_mips64le.go | 9 +++++++++ unix/zerrors_linux_mipsle.go | 9 +++++++++ unix/zerrors_linux_ppc.go | 9 +++++++++ unix/zerrors_linux_ppc64.go | 9 +++++++++ unix/zerrors_linux_ppc64le.go | 9 +++++++++ unix/zerrors_linux_riscv64.go | 9 +++++++++ unix/zerrors_linux_s390x.go | 9 +++++++++ unix/zerrors_linux_sparc64.go | 9 +++++++++ 16 files changed, 136 insertions(+), 1 deletion(-) diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh index 0c4d14929a..8f775fafa6 100755 --- a/unix/mkerrors.sh +++ b/unix/mkerrors.sh @@ -624,7 +624,7 @@ ccflags="$@" $2 ~ /^MEM/ || $2 ~ /^WG/ || $2 ~ /^FIB_RULE_/ || - $2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE)/ {printf("\t%s = C.%s\n", $2, $2)} + $2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE|IOMIN$|IOOPT$|ALIGNOFF$|DISCARD|ROTATIONAL$|ZEROOUT$|GETDISKSEQ$)/ {printf("\t%s = C.%s\n", $2, $2)} $2 ~ /^__WCOREFLAG$/ {next} $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} diff --git a/unix/zerrors_linux_386.go b/unix/zerrors_linux_386.go index a46df0f1e5..cfb1430018 100644 --- a/unix/zerrors_linux_386.go +++ b/unix/zerrors_linux_386.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x127a BLKBSZGET = 0x80041270 BLKBSZSET = 0x40041271 + BLKDISCARD = 0x1277 + BLKDISCARDZEROES = 0x127c BLKFLSBUF = 0x1261 BLKFRAGET = 0x1265 BLKFRASET = 0x1264 + BLKGETDISKSEQ = 0x80081280 BLKGETSIZE = 0x1260 BLKGETSIZE64 = 0x80041272 + BLKIOMIN = 0x1278 + BLKIOOPT = 0x1279 BLKPBSZGET = 0x127b BLKRAGET = 0x1263 BLKRASET = 0x1262 BLKROGET = 0x125e BLKROSET = 0x125d + BLKROTATIONAL = 0x127e BLKRRPART = 0x125f + BLKSECDISCARD = 0x127d BLKSECTGET = 0x1267 BLKSECTSET = 0x1266 BLKSSZGET = 0x1268 + BLKZEROOUT = 0x127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_amd64.go b/unix/zerrors_linux_amd64.go index 6cd4a3ea9d..df64f2d590 100644 --- a/unix/zerrors_linux_amd64.go +++ b/unix/zerrors_linux_amd64.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x127a BLKBSZGET = 0x80081270 BLKBSZSET = 0x40081271 + BLKDISCARD = 0x1277 + BLKDISCARDZEROES = 0x127c BLKFLSBUF = 0x1261 BLKFRAGET = 0x1265 BLKFRASET = 0x1264 + BLKGETDISKSEQ = 0x80081280 BLKGETSIZE = 0x1260 BLKGETSIZE64 = 0x80081272 + BLKIOMIN = 0x1278 + BLKIOOPT = 0x1279 BLKPBSZGET = 0x127b BLKRAGET = 0x1263 BLKRASET = 0x1262 BLKROGET = 0x125e BLKROSET = 0x125d + BLKROTATIONAL = 0x127e BLKRRPART = 0x125f + BLKSECDISCARD = 0x127d BLKSECTGET = 0x1267 BLKSECTSET = 0x1266 BLKSSZGET = 0x1268 + BLKZEROOUT = 0x127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_arm.go b/unix/zerrors_linux_arm.go index c7ebee24df..3025cd5b2d 100644 --- a/unix/zerrors_linux_arm.go +++ b/unix/zerrors_linux_arm.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x127a BLKBSZGET = 0x80041270 BLKBSZSET = 0x40041271 + BLKDISCARD = 0x1277 + BLKDISCARDZEROES = 0x127c BLKFLSBUF = 0x1261 BLKFRAGET = 0x1265 BLKFRASET = 0x1264 + BLKGETDISKSEQ = 0x80081280 BLKGETSIZE = 0x1260 BLKGETSIZE64 = 0x80041272 + BLKIOMIN = 0x1278 + BLKIOOPT = 0x1279 BLKPBSZGET = 0x127b BLKRAGET = 0x1263 BLKRASET = 0x1262 BLKROGET = 0x125e BLKROSET = 0x125d + BLKROTATIONAL = 0x127e BLKRRPART = 0x125f + BLKSECDISCARD = 0x127d BLKSECTGET = 0x1267 BLKSECTSET = 0x1266 BLKSSZGET = 0x1268 + BLKZEROOUT = 0x127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_arm64.go b/unix/zerrors_linux_arm64.go index 12a9a1389e..09e1ffbef9 100644 --- a/unix/zerrors_linux_arm64.go +++ b/unix/zerrors_linux_arm64.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x127a BLKBSZGET = 0x80081270 BLKBSZSET = 0x40081271 + BLKDISCARD = 0x1277 + BLKDISCARDZEROES = 0x127c BLKFLSBUF = 0x1261 BLKFRAGET = 0x1265 BLKFRASET = 0x1264 + BLKGETDISKSEQ = 0x80081280 BLKGETSIZE = 0x1260 BLKGETSIZE64 = 0x80081272 + BLKIOMIN = 0x1278 + BLKIOOPT = 0x1279 BLKPBSZGET = 0x127b BLKRAGET = 0x1263 BLKRASET = 0x1262 BLKROGET = 0x125e BLKROSET = 0x125d + BLKROTATIONAL = 0x127e BLKRRPART = 0x125f + BLKSECDISCARD = 0x127d BLKSECTGET = 0x1267 BLKSECTSET = 0x1266 BLKSSZGET = 0x1268 + BLKZEROOUT = 0x127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_loong64.go b/unix/zerrors_linux_loong64.go index f26a164f4a..a457235407 100644 --- a/unix/zerrors_linux_loong64.go +++ b/unix/zerrors_linux_loong64.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x127a BLKBSZGET = 0x80081270 BLKBSZSET = 0x40081271 + BLKDISCARD = 0x1277 + BLKDISCARDZEROES = 0x127c BLKFLSBUF = 0x1261 BLKFRAGET = 0x1265 BLKFRASET = 0x1264 + BLKGETDISKSEQ = 0x80081280 BLKGETSIZE = 0x1260 BLKGETSIZE64 = 0x80081272 + BLKIOMIN = 0x1278 + BLKIOOPT = 0x1279 BLKPBSZGET = 0x127b BLKRAGET = 0x1263 BLKRASET = 0x1262 BLKROGET = 0x125e BLKROSET = 0x125d + BLKROTATIONAL = 0x127e BLKRRPART = 0x125f + BLKSECDISCARD = 0x127d BLKSECTGET = 0x1267 BLKSECTSET = 0x1266 BLKSSZGET = 0x1268 + BLKZEROOUT = 0x127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_mips.go b/unix/zerrors_linux_mips.go index 890bc3c9b7..fee7dfb819 100644 --- a/unix/zerrors_linux_mips.go +++ b/unix/zerrors_linux_mips.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x2000127a BLKBSZGET = 0x40041270 BLKBSZSET = 0x80041271 + BLKDISCARD = 0x20001277 + BLKDISCARDZEROES = 0x2000127c BLKFLSBUF = 0x20001261 BLKFRAGET = 0x20001265 BLKFRASET = 0x20001264 + BLKGETDISKSEQ = 0x40081280 BLKGETSIZE = 0x20001260 BLKGETSIZE64 = 0x40041272 + BLKIOMIN = 0x20001278 + BLKIOOPT = 0x20001279 BLKPBSZGET = 0x2000127b BLKRAGET = 0x20001263 BLKRASET = 0x20001262 BLKROGET = 0x2000125e BLKROSET = 0x2000125d + BLKROTATIONAL = 0x2000127e BLKRRPART = 0x2000125f + BLKSECDISCARD = 0x2000127d BLKSECTGET = 0x20001267 BLKSECTSET = 0x20001266 BLKSSZGET = 0x20001268 + BLKZEROOUT = 0x2000127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_mips64.go b/unix/zerrors_linux_mips64.go index 549f26ac64..a5b2373aea 100644 --- a/unix/zerrors_linux_mips64.go +++ b/unix/zerrors_linux_mips64.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x2000127a BLKBSZGET = 0x40081270 BLKBSZSET = 0x80081271 + BLKDISCARD = 0x20001277 + BLKDISCARDZEROES = 0x2000127c BLKFLSBUF = 0x20001261 BLKFRAGET = 0x20001265 BLKFRASET = 0x20001264 + BLKGETDISKSEQ = 0x40081280 BLKGETSIZE = 0x20001260 BLKGETSIZE64 = 0x40081272 + BLKIOMIN = 0x20001278 + BLKIOOPT = 0x20001279 BLKPBSZGET = 0x2000127b BLKRAGET = 0x20001263 BLKRASET = 0x20001262 BLKROGET = 0x2000125e BLKROSET = 0x2000125d + BLKROTATIONAL = 0x2000127e BLKRRPART = 0x2000125f + BLKSECDISCARD = 0x2000127d BLKSECTGET = 0x20001267 BLKSECTSET = 0x20001266 BLKSSZGET = 0x20001268 + BLKZEROOUT = 0x2000127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_mips64le.go b/unix/zerrors_linux_mips64le.go index e0365e32c1..5dde82c98a 100644 --- a/unix/zerrors_linux_mips64le.go +++ b/unix/zerrors_linux_mips64le.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x2000127a BLKBSZGET = 0x40081270 BLKBSZSET = 0x80081271 + BLKDISCARD = 0x20001277 + BLKDISCARDZEROES = 0x2000127c BLKFLSBUF = 0x20001261 BLKFRAGET = 0x20001265 BLKFRASET = 0x20001264 + BLKGETDISKSEQ = 0x40081280 BLKGETSIZE = 0x20001260 BLKGETSIZE64 = 0x40081272 + BLKIOMIN = 0x20001278 + BLKIOOPT = 0x20001279 BLKPBSZGET = 0x2000127b BLKRAGET = 0x20001263 BLKRASET = 0x20001262 BLKROGET = 0x2000125e BLKROSET = 0x2000125d + BLKROTATIONAL = 0x2000127e BLKRRPART = 0x2000125f + BLKSECDISCARD = 0x2000127d BLKSECTGET = 0x20001267 BLKSECTSET = 0x20001266 BLKSSZGET = 0x20001268 + BLKZEROOUT = 0x2000127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_mipsle.go b/unix/zerrors_linux_mipsle.go index fdccce15ca..2e80ea6b33 100644 --- a/unix/zerrors_linux_mipsle.go +++ b/unix/zerrors_linux_mipsle.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x2000127a BLKBSZGET = 0x40041270 BLKBSZSET = 0x80041271 + BLKDISCARD = 0x20001277 + BLKDISCARDZEROES = 0x2000127c BLKFLSBUF = 0x20001261 BLKFRAGET = 0x20001265 BLKFRASET = 0x20001264 + BLKGETDISKSEQ = 0x40081280 BLKGETSIZE = 0x20001260 BLKGETSIZE64 = 0x40041272 + BLKIOMIN = 0x20001278 + BLKIOOPT = 0x20001279 BLKPBSZGET = 0x2000127b BLKRAGET = 0x20001263 BLKRASET = 0x20001262 BLKROGET = 0x2000125e BLKROSET = 0x2000125d + BLKROTATIONAL = 0x2000127e BLKRRPART = 0x2000125f + BLKSECDISCARD = 0x2000127d BLKSECTGET = 0x20001267 BLKSECTSET = 0x20001266 BLKSSZGET = 0x20001268 + BLKZEROOUT = 0x2000127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_ppc.go b/unix/zerrors_linux_ppc.go index b2205c83fa..a65dcd7cbe 100644 --- a/unix/zerrors_linux_ppc.go +++ b/unix/zerrors_linux_ppc.go @@ -27,22 +27,31 @@ const ( B57600 = 0x10 B576000 = 0x15 B921600 = 0x16 + BLKALIGNOFF = 0x2000127a BLKBSZGET = 0x40041270 BLKBSZSET = 0x80041271 + BLKDISCARD = 0x20001277 + BLKDISCARDZEROES = 0x2000127c BLKFLSBUF = 0x20001261 BLKFRAGET = 0x20001265 BLKFRASET = 0x20001264 + BLKGETDISKSEQ = 0x40081280 BLKGETSIZE = 0x20001260 BLKGETSIZE64 = 0x40041272 + BLKIOMIN = 0x20001278 + BLKIOOPT = 0x20001279 BLKPBSZGET = 0x2000127b BLKRAGET = 0x20001263 BLKRASET = 0x20001262 BLKROGET = 0x2000125e BLKROSET = 0x2000125d + BLKROTATIONAL = 0x2000127e BLKRRPART = 0x2000125f + BLKSECDISCARD = 0x2000127d BLKSECTGET = 0x20001267 BLKSECTSET = 0x20001266 BLKSSZGET = 0x20001268 + BLKZEROOUT = 0x2000127f BOTHER = 0x1f BS1 = 0x8000 BSDLY = 0x8000 diff --git a/unix/zerrors_linux_ppc64.go b/unix/zerrors_linux_ppc64.go index 81aa5ad0f6..cbd34e3d89 100644 --- a/unix/zerrors_linux_ppc64.go +++ b/unix/zerrors_linux_ppc64.go @@ -27,22 +27,31 @@ const ( B57600 = 0x10 B576000 = 0x15 B921600 = 0x16 + BLKALIGNOFF = 0x2000127a BLKBSZGET = 0x40081270 BLKBSZSET = 0x80081271 + BLKDISCARD = 0x20001277 + BLKDISCARDZEROES = 0x2000127c BLKFLSBUF = 0x20001261 BLKFRAGET = 0x20001265 BLKFRASET = 0x20001264 + BLKGETDISKSEQ = 0x40081280 BLKGETSIZE = 0x20001260 BLKGETSIZE64 = 0x40081272 + BLKIOMIN = 0x20001278 + BLKIOOPT = 0x20001279 BLKPBSZGET = 0x2000127b BLKRAGET = 0x20001263 BLKRASET = 0x20001262 BLKROGET = 0x2000125e BLKROSET = 0x2000125d + BLKROTATIONAL = 0x2000127e BLKRRPART = 0x2000125f + BLKSECDISCARD = 0x2000127d BLKSECTGET = 0x20001267 BLKSECTSET = 0x20001266 BLKSSZGET = 0x20001268 + BLKZEROOUT = 0x2000127f BOTHER = 0x1f BS1 = 0x8000 BSDLY = 0x8000 diff --git a/unix/zerrors_linux_ppc64le.go b/unix/zerrors_linux_ppc64le.go index 76807a1fd4..e4afa7a317 100644 --- a/unix/zerrors_linux_ppc64le.go +++ b/unix/zerrors_linux_ppc64le.go @@ -27,22 +27,31 @@ const ( B57600 = 0x10 B576000 = 0x15 B921600 = 0x16 + BLKALIGNOFF = 0x2000127a BLKBSZGET = 0x40081270 BLKBSZSET = 0x80081271 + BLKDISCARD = 0x20001277 + BLKDISCARDZEROES = 0x2000127c BLKFLSBUF = 0x20001261 BLKFRAGET = 0x20001265 BLKFRASET = 0x20001264 + BLKGETDISKSEQ = 0x40081280 BLKGETSIZE = 0x20001260 BLKGETSIZE64 = 0x40081272 + BLKIOMIN = 0x20001278 + BLKIOOPT = 0x20001279 BLKPBSZGET = 0x2000127b BLKRAGET = 0x20001263 BLKRASET = 0x20001262 BLKROGET = 0x2000125e BLKROSET = 0x2000125d + BLKROTATIONAL = 0x2000127e BLKRRPART = 0x2000125f + BLKSECDISCARD = 0x2000127d BLKSECTGET = 0x20001267 BLKSECTSET = 0x20001266 BLKSSZGET = 0x20001268 + BLKZEROOUT = 0x2000127f BOTHER = 0x1f BS1 = 0x8000 BSDLY = 0x8000 diff --git a/unix/zerrors_linux_riscv64.go b/unix/zerrors_linux_riscv64.go index d4a5ab9e4e..44f45a039d 100644 --- a/unix/zerrors_linux_riscv64.go +++ b/unix/zerrors_linux_riscv64.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x127a BLKBSZGET = 0x80081270 BLKBSZSET = 0x40081271 + BLKDISCARD = 0x1277 + BLKDISCARDZEROES = 0x127c BLKFLSBUF = 0x1261 BLKFRAGET = 0x1265 BLKFRASET = 0x1264 + BLKGETDISKSEQ = 0x80081280 BLKGETSIZE = 0x1260 BLKGETSIZE64 = 0x80081272 + BLKIOMIN = 0x1278 + BLKIOOPT = 0x1279 BLKPBSZGET = 0x127b BLKRAGET = 0x1263 BLKRASET = 0x1262 BLKROGET = 0x125e BLKROSET = 0x125d + BLKROTATIONAL = 0x127e BLKRRPART = 0x125f + BLKSECDISCARD = 0x127d BLKSECTGET = 0x1267 BLKSECTSET = 0x1266 BLKSSZGET = 0x1268 + BLKZEROOUT = 0x127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_s390x.go b/unix/zerrors_linux_s390x.go index 66e65db951..74733e260f 100644 --- a/unix/zerrors_linux_s390x.go +++ b/unix/zerrors_linux_s390x.go @@ -27,22 +27,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x127a BLKBSZGET = 0x80081270 BLKBSZSET = 0x40081271 + BLKDISCARD = 0x1277 + BLKDISCARDZEROES = 0x127c BLKFLSBUF = 0x1261 BLKFRAGET = 0x1265 BLKFRASET = 0x1264 + BLKGETDISKSEQ = 0x80081280 BLKGETSIZE = 0x1260 BLKGETSIZE64 = 0x80081272 + BLKIOMIN = 0x1278 + BLKIOOPT = 0x1279 BLKPBSZGET = 0x127b BLKRAGET = 0x1263 BLKRASET = 0x1262 BLKROGET = 0x125e BLKROSET = 0x125d + BLKROTATIONAL = 0x127e BLKRRPART = 0x125f + BLKSECDISCARD = 0x127d BLKSECTGET = 0x1267 BLKSECTSET = 0x1266 BLKSSZGET = 0x1268 + BLKZEROOUT = 0x127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 diff --git a/unix/zerrors_linux_sparc64.go b/unix/zerrors_linux_sparc64.go index 48984202c6..f5f3934b1a 100644 --- a/unix/zerrors_linux_sparc64.go +++ b/unix/zerrors_linux_sparc64.go @@ -30,22 +30,31 @@ const ( B57600 = 0x1001 B576000 = 0x1006 B921600 = 0x1007 + BLKALIGNOFF = 0x2000127a BLKBSZGET = 0x40081270 BLKBSZSET = 0x80081271 + BLKDISCARD = 0x20001277 + BLKDISCARDZEROES = 0x2000127c BLKFLSBUF = 0x20001261 BLKFRAGET = 0x20001265 BLKFRASET = 0x20001264 + BLKGETDISKSEQ = 0x40081280 BLKGETSIZE = 0x20001260 BLKGETSIZE64 = 0x40081272 + BLKIOMIN = 0x20001278 + BLKIOOPT = 0x20001279 BLKPBSZGET = 0x2000127b BLKRAGET = 0x20001263 BLKRASET = 0x20001262 BLKROGET = 0x2000125e BLKROSET = 0x2000125d + BLKROTATIONAL = 0x2000127e BLKRRPART = 0x2000125f + BLKSECDISCARD = 0x2000127d BLKSECTGET = 0x20001267 BLKSECTSET = 0x20001266 BLKSSZGET = 0x20001268 + BLKZEROOUT = 0x2000127f BOTHER = 0x1000 BS1 = 0x2000 BSDLY = 0x2000 From 70f4e408de566fcb64f1c8649fe05a22958255be Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Tue, 25 Jul 2023 19:17:12 +0000 Subject: [PATCH 24/25] unix: retry fetching of lists through sysctl if the size changes On macOS, the SysctlKinfoProcSlice() function may be used to fetch the contents of the process table. As the process table may grow between the first and second call to sysctl(), the second call may fail with ENOMEM. In that case we simply need to retry. Change-Id: I40229653ed383603c33762f37b0dc2e7de47bcb6 GitHub-Last-Rev: b63b6b847122e058977934c5af7841f47485177d GitHub-Pull-Request: golang/sys#169 Reviewed-on: https://go-review.googlesource.com/c/sys/+/513036 Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- unix/syscall_darwin.go | 50 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/unix/syscall_darwin.go b/unix/syscall_darwin.go index 206921504c..135cc3cd75 100644 --- a/unix/syscall_darwin.go +++ b/unix/syscall_darwin.go @@ -510,30 +510,36 @@ func SysctlKinfoProcSlice(name string, args ...int) ([]KinfoProc, error) { return nil, err } - // Find size. - n := uintptr(0) - if err := sysctl(mib, nil, &n, nil, 0); err != nil { - return nil, err - } - if n == 0 { - return nil, nil - } - if n%SizeofKinfoProc != 0 { - return nil, fmt.Errorf("sysctl() returned a size of %d, which is not a multiple of %d", n, SizeofKinfoProc) - } + for { + // Find size. + n := uintptr(0) + if err := sysctl(mib, nil, &n, nil, 0); err != nil { + return nil, err + } + if n == 0 { + return nil, nil + } + if n%SizeofKinfoProc != 0 { + return nil, fmt.Errorf("sysctl() returned a size of %d, which is not a multiple of %d", n, SizeofKinfoProc) + } - // Read into buffer of that size. - buf := make([]KinfoProc, n/SizeofKinfoProc) - if err := sysctl(mib, (*byte)(unsafe.Pointer(&buf[0])), &n, nil, 0); err != nil { - return nil, err - } - if n%SizeofKinfoProc != 0 { - return nil, fmt.Errorf("sysctl() returned a size of %d, which is not a multiple of %d", n, SizeofKinfoProc) - } + // Read into buffer of that size. + buf := make([]KinfoProc, n/SizeofKinfoProc) + if err := sysctl(mib, (*byte)(unsafe.Pointer(&buf[0])), &n, nil, 0); err != nil { + if err == ENOMEM { + // Process table grew. Try again. + continue + } + return nil, err + } + if n%SizeofKinfoProc != 0 { + return nil, fmt.Errorf("sysctl() returned a size of %d, which is not a multiple of %d", n, SizeofKinfoProc) + } - // The actual call may return less than the original reported required - // size so ensure we deal with that. - return buf[:n/SizeofKinfoProc], nil + // The actual call may return less than the original reported required + // size so ensure we deal with that. + return buf[:n/SizeofKinfoProc], nil + } } //sys sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error) From 104d4017fa052d31a480218d213787543bc352d4 Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Tue, 18 Jul 2023 12:41:15 +0000 Subject: [PATCH 25/25] unix: add riscv_hwprobe for riscv64 The riscv_hwprobe system call was introduced in Linux 6.4 and allows the caller to determine a number of interesting pieces of information about the underlying RISC-V CPUs, e.g., which extensions they support and whether they allow fast unaligned memory accesses. For more information please see: https://docs.kernel.org/riscv/hwprobe.html We also update linux/mksysnum.go to ensure that the generated syscall constants written to the zsysnum_linux_*.go files are always sorted by their syscall numbers in ascending order. Updates golang/go#61416 Change-Id: Iedb0a86adb65faac9061b9a5969ffa09eb5b303a Reviewed-on: https://go-review.googlesource.com/c/sys/+/510795 TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor --- unix/linux/mksysnum.go | 71 +++++++++++++++++++++++++++++----- unix/linux/types.go | 49 +++++++++++++++++++++++ unix/mkpost.go | 11 ++++++ unix/syscall_linux_riscv64.go | 11 ++++++ unix/zsyscall_linux_riscv64.go | 16 ++++++++ unix/zsysnum_linux_riscv64.go | 2 + unix/ztypes_linux_riscv64.go | 23 +++++++++++ 7 files changed, 173 insertions(+), 10 deletions(-) diff --git a/unix/linux/mksysnum.go b/unix/linux/mksysnum.go index ed41ce9a29..e1712cbe0a 100644 --- a/unix/linux/mksysnum.go +++ b/unix/linux/mksysnum.go @@ -13,6 +13,7 @@ import ( "os" "os/exec" "regexp" + "sort" "strconv" "strings" ) @@ -36,15 +37,15 @@ func plusBuildTags() string { return fmt.Sprintf("%s,%s", goarch, goos) } -func format(name string, num int, offset int) string { +func format(name string, num int, offset int) (int, string) { if num > 999 { // ignore deprecated syscalls that are no longer implemented // https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h?id=refs/heads/master#n716 - return "" + return 0, "" } name = strings.ToUpper(name) num = num + offset - return fmt.Sprintf(" SYS_%s = %d;\n", name, num) + return num, fmt.Sprintf(" SYS_%s = %d;\n", name, num) } func checkErr(err error) { @@ -69,6 +70,36 @@ func (r *re) Match(exp string) bool { return false } +// syscallNum holds the syscall number and the string +// we will write to the generated file. +type syscallNum struct { + num int + declaration string +} + +// syscallNums is a slice of syscallNum sorted by the syscall number in ascending order. +type syscallNums []syscallNum + +// addSyscallNum adds the syscall declaration to syscallNums. +func (nums *syscallNums) addSyscallNum(num int, declaration string) { + if declaration == "" { + return + } + if len(*nums) == 0 || (*nums)[len(*nums)-1].num <= num { + // This is the most common case as the syscall declarations output by the preprocessor + // are almost always sorted. + *nums = append(*nums, syscallNum{num, declaration}) + return + } + i := sort.Search(len(*nums), func(i int) bool { return (*nums)[i].num >= num }) + + // Maintain the ordering in the preprocessor output when we have multiple definitions with + // the same value. i cannot be > len(nums) - 1 as nums[len(nums)-1].num > num. + for ; (*nums)[i].num == num; i++ { + } + *nums = append((*nums)[:i], append([]syscallNum{{num, declaration}}, (*nums)[i:]...)...) +} + func main() { // Get the OS and architecture (using GOARCH_TARGET if it exists) goos = os.Getenv("GOOS") @@ -100,11 +131,23 @@ func main() { fmt.Fprintf(os.Stderr, "can't run %s", cc) os.Exit(1) } - text := "" s := bufio.NewScanner(strings.NewReader(string(cmd))) - var offset, prev int + var offset, prev, asOffset int + var nums syscallNums for s.Scan() { t := re{str: s.Text()} + + // The generated zsysnum_linux_*.go files for some platforms (arm64, loong64, riscv64) + // treat SYS_ARCH_SPECIFIC_SYSCALL as if it's a syscall which it isn't. It's an offset. + // However, as this constant is already part of the public API we leave it in place. + // Lines of type SYS_ARCH_SPECIFIC_SYSCALL = 244 are thus processed twice, once to extract + // the offset and once to add the constant. + + if t.Match(`^#define __NR_arch_specific_syscall\s+([0-9]+)`) { + // riscv: extract arch specific offset + asOffset, _ = strconv.Atoi(t.sub[1]) // Make asOffset=0 if empty or non-numeric + } + if t.Match(`^#define __NR_Linux\s+([0-9]+)`) { // mips/mips64: extract offset offset, _ = strconv.Atoi(t.sub[1]) // Make offset=0 if empty or non-numeric @@ -118,24 +161,32 @@ func main() { } else if t.Match(`^#define __NR_(\w+)\s+([0-9]+)`) { prev, err = strconv.Atoi(t.sub[2]) checkErr(err) - text += format(t.sub[1], prev, offset) + nums.addSyscallNum(format(t.sub[1], prev, offset)) } else if t.Match(`^#define __NR3264_(\w+)\s+([0-9]+)`) { prev, err = strconv.Atoi(t.sub[2]) checkErr(err) - text += format(t.sub[1], prev, offset) + nums.addSyscallNum(format(t.sub[1], prev, offset)) } else if t.Match(`^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)`) { r2, err := strconv.Atoi(t.sub[2]) checkErr(err) - text += format(t.sub[1], prev+r2, offset) + nums.addSyscallNum(format(t.sub[1], prev+r2, offset)) } else if t.Match(`^#define __NR_(\w+)\s+\(__NR_(?:SYSCALL_BASE|Linux) \+ ([0-9]+)`) { r2, err := strconv.Atoi(t.sub[2]) checkErr(err) - text += format(t.sub[1], r2, offset) + nums.addSyscallNum(format(t.sub[1], r2, offset)) + } else if asOffset != 0 && t.Match(`^#define __NR_(\w+)\s+\(__NR_arch_specific_syscall \+ ([0-9]+)`) { + r2, err := strconv.Atoi(t.sub[2]) + checkErr(err) + nums.addSyscallNum(format(t.sub[1], r2, asOffset)) } } err = s.Err() checkErr(err) - fmt.Printf(template, cmdLine(), goBuildTags(), plusBuildTags(), text) + var text strings.Builder + for _, num := range nums { + text.WriteString(num.declaration) + } + fmt.Printf(template, cmdLine(), goBuildTags(), plusBuildTags(), text.String()) } const template = `// %s diff --git a/unix/linux/types.go b/unix/linux/types.go index f2cbd2d458..bf2df60b2a 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -426,6 +426,32 @@ struct my_can_bittiming_const { __u32 brp_max; __u32 brp_inc; }; + +#if defined(__riscv) +#include +#else + +// copied from /usr/include/asm/hwprobe.h +// values are not used but they need to be defined. + +#define RISCV_HWPROBE_KEY_MVENDORID 0 +#define RISCV_HWPROBE_KEY_MARCHID 1 +#define RISCV_HWPROBE_KEY_MIMPID 2 +#define RISCV_HWPROBE_KEY_BASE_BEHAVIOR 3 +#define RISCV_HWPROBE_BASE_BEHAVIOR_IMA (1 << 0) +#define RISCV_HWPROBE_KEY_IMA_EXT_0 4 +#define RISCV_HWPROBE_IMA_FD (1 << 0) +#define RISCV_HWPROBE_IMA_C (1 << 1) +#define RISCV_HWPROBE_KEY_CPUPERF_0 5 +#define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) +#define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) +#define RISCV_HWPROBE_MISALIGNED_SLOW (2 << 0) +#define RISCV_HWPROBE_MISALIGNED_FAST (3 << 0) +#define RISCV_HWPROBE_MISALIGNED_UNSUPPORTED (4 << 0) +#define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0) + +struct riscv_hwprobe {}; +#endif */ import "C" @@ -5747,3 +5773,26 @@ const ( VIRTIO_NET_HDR_GSO_UDP_L4 = C.VIRTIO_NET_HDR_GSO_UDP_L4 VIRTIO_NET_HDR_GSO_ECN = C.VIRTIO_NET_HDR_GSO_ECN ) + +type RISCVHWProbePairs C.struct_riscv_hwprobe + +// Filtered out for non RISC-V architectures in mkpost.go +// generated by: +// perl -nlE '/^#define\s+(RISCV_HWPROBE_\w+)/ && say "$1 = C.$1"' /tmp/riscv64/include/asm/hwprobe.h +const ( + RISCV_HWPROBE_KEY_MVENDORID = C.RISCV_HWPROBE_KEY_MVENDORID + RISCV_HWPROBE_KEY_MARCHID = C.RISCV_HWPROBE_KEY_MARCHID + RISCV_HWPROBE_KEY_MIMPID = C.RISCV_HWPROBE_KEY_MIMPID + RISCV_HWPROBE_KEY_BASE_BEHAVIOR = C.RISCV_HWPROBE_KEY_BASE_BEHAVIOR + RISCV_HWPROBE_BASE_BEHAVIOR_IMA = C.RISCV_HWPROBE_BASE_BEHAVIOR_IMA + RISCV_HWPROBE_KEY_IMA_EXT_0 = C.RISCV_HWPROBE_KEY_IMA_EXT_0 + RISCV_HWPROBE_IMA_FD = C.RISCV_HWPROBE_IMA_FD + RISCV_HWPROBE_IMA_C = C.RISCV_HWPROBE_IMA_C + RISCV_HWPROBE_KEY_CPUPERF_0 = C.RISCV_HWPROBE_KEY_CPUPERF_0 + RISCV_HWPROBE_MISALIGNED_UNKNOWN = C.RISCV_HWPROBE_MISALIGNED_UNKNOWN + RISCV_HWPROBE_MISALIGNED_EMULATED = C.RISCV_HWPROBE_MISALIGNED_EMULATED + RISCV_HWPROBE_MISALIGNED_SLOW = C.RISCV_HWPROBE_MISALIGNED_SLOW + RISCV_HWPROBE_MISALIGNED_FAST = C.RISCV_HWPROBE_MISALIGNED_FAST + RISCV_HWPROBE_MISALIGNED_UNSUPPORTED = C.RISCV_HWPROBE_MISALIGNED_UNSUPPORTED + RISCV_HWPROBE_MISALIGNED_MASK = C.RISCV_HWPROBE_MISALIGNED_MASK +) diff --git a/unix/mkpost.go b/unix/mkpost.go index 3d19d3fa75..7de7179e0b 100644 --- a/unix/mkpost.go +++ b/unix/mkpost.go @@ -112,6 +112,12 @@ func main() { } } + if goos == "linux" && goarch != "riscv64" { + // The RISCV_HWPROBE_ constants are only defined on Linux for riscv64 + hwprobeConstRexexp := regexp.MustCompile(`const\s+\(\s+RISCV_HWPROBE_[^\)]+\)`) + b = hwprobeConstRexexp.ReplaceAll(b, nil) + } + // Intentionally export __val fields in Fsid and Sigset_t valRegex := regexp.MustCompile(`type (Fsid|Sigset_t) struct {(\s+)X__(bits|val)(\s+\S+\s+)}`) b = valRegex.ReplaceAll(b, []byte("type $1 struct {${2}Val$4}")) @@ -138,6 +144,11 @@ func main() { ptraceRexexp := regexp.MustCompile(`type Ptrace((Psw|Fpregs|Per) struct {\s*})`) b = ptraceRexexp.ReplaceAll(b, nil) + // If we have an empty RISCVHWProbePairs struct, we should delete it. Only riscv64 emits + // nonempty RISCVHWProbePairs structs. + hwprobeRexexp := regexp.MustCompile(`type RISCVHWProbePairs struct {\s*}`) + b = hwprobeRexexp.ReplaceAll(b, nil) + // Replace the control_regs union with a blank identifier for now. controlRegsRegex := regexp.MustCompile(`(Control_regs)\s+\[0\]uint64`) b = controlRegsRegex.ReplaceAll(b, []byte("_ [0]uint64")) diff --git a/unix/syscall_linux_riscv64.go b/unix/syscall_linux_riscv64.go index b1de100ac0..5e6ceee129 100644 --- a/unix/syscall_linux_riscv64.go +++ b/unix/syscall_linux_riscv64.go @@ -177,3 +177,14 @@ func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error } return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags) } + +//sys riscvHWProbe(pairs []RISCVHWProbePairs, cpuCount uintptr, cpus *CPUSet, flags uint) (err error) + +func RISCVHWProbe(pairs []RISCVHWProbePairs, set *CPUSet, flags uint) (err error) { + var setSize uintptr + + if set != nil { + setSize = uintptr(unsafe.Sizeof(*set)) + } + return riscvHWProbe(pairs, setSize, set, flags) +} diff --git a/unix/zsyscall_linux_riscv64.go b/unix/zsyscall_linux_riscv64.go index 0b29239583..0ab4f2ed72 100644 --- a/unix/zsyscall_linux_riscv64.go +++ b/unix/zsyscall_linux_riscv64.go @@ -531,3 +531,19 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func riscvHWProbe(pairs []RISCVHWProbePairs, cpuCount uintptr, cpus *CPUSet, flags uint) (err error) { + var _p0 unsafe.Pointer + if len(pairs) > 0 { + _p0 = unsafe.Pointer(&pairs[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := Syscall6(SYS_RISCV_HWPROBE, uintptr(_p0), uintptr(len(pairs)), uintptr(cpuCount), uintptr(unsafe.Pointer(cpus)), uintptr(flags), 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/unix/zsysnum_linux_riscv64.go b/unix/zsysnum_linux_riscv64.go index 3e594a8c09..ef285c567b 100644 --- a/unix/zsysnum_linux_riscv64.go +++ b/unix/zsysnum_linux_riscv64.go @@ -251,6 +251,8 @@ const ( SYS_ACCEPT4 = 242 SYS_RECVMMSG = 243 SYS_ARCH_SPECIFIC_SYSCALL = 244 + SYS_RISCV_HWPROBE = 258 + SYS_RISCV_FLUSH_ICACHE = 259 SYS_WAIT4 = 260 SYS_PRLIMIT64 = 261 SYS_FANOTIFY_INIT = 262 diff --git a/unix/ztypes_linux_riscv64.go b/unix/ztypes_linux_riscv64.go index 9ea54b7b86..83c69c119f 100644 --- a/unix/ztypes_linux_riscv64.go +++ b/unix/ztypes_linux_riscv64.go @@ -718,3 +718,26 @@ type SysvShmDesc struct { _ uint64 _ uint64 } + +type RISCVHWProbePairs struct { + Key int64 + Value uint64 +} + +const ( + RISCV_HWPROBE_KEY_MVENDORID = 0x0 + RISCV_HWPROBE_KEY_MARCHID = 0x1 + RISCV_HWPROBE_KEY_MIMPID = 0x2 + RISCV_HWPROBE_KEY_BASE_BEHAVIOR = 0x3 + RISCV_HWPROBE_BASE_BEHAVIOR_IMA = 0x1 + RISCV_HWPROBE_KEY_IMA_EXT_0 = 0x4 + RISCV_HWPROBE_IMA_FD = 0x1 + RISCV_HWPROBE_IMA_C = 0x2 + RISCV_HWPROBE_KEY_CPUPERF_0 = 0x5 + RISCV_HWPROBE_MISALIGNED_UNKNOWN = 0x0 + RISCV_HWPROBE_MISALIGNED_EMULATED = 0x1 + RISCV_HWPROBE_MISALIGNED_SLOW = 0x2 + RISCV_HWPROBE_MISALIGNED_FAST = 0x3 + RISCV_HWPROBE_MISALIGNED_UNSUPPORTED = 0x4 + RISCV_HWPROBE_MISALIGNED_MASK = 0x7 +)