aboutsummaryrefslogtreecommitdiff
path: root/src/syscall
diff options
context:
space:
mode:
Diffstat (limited to 'src/syscall')
-rw-r--r--src/syscall/badlinkname_unix.go22
-rw-r--r--src/syscall/dir_plan9.go30
-rw-r--r--src/syscall/dirent.go21
-rw-r--r--src/syscall/dirent_test.go8
-rw-r--r--src/syscall/exec_linux.go4
-rw-r--r--src/syscall/exec_linux_test.go4
-rw-r--r--src/syscall/export_linux_test.go1
-rw-r--r--src/syscall/export_rlimit_test.go6
-rw-r--r--src/syscall/fs_wasip1.go21
-rw-r--r--src/syscall/getdirentries_test.go6
-rw-r--r--src/syscall/linkname_bsd.go17
-rw-r--r--src/syscall/linkname_darwin.go23
-rw-r--r--src/syscall/linkname_libc.go12
-rw-r--r--src/syscall/linkname_openbsd.go15
-rw-r--r--src/syscall/linkname_unix.go20
-rwxr-xr-xsrc/syscall/mksyscall.pl8
-rw-r--r--src/syscall/rlimit.go5
-rw-r--r--src/syscall/syscall_aix.go1
-rw-r--r--src/syscall/syscall_darwin.go9
-rw-r--r--src/syscall/syscall_linux.go8
-rw-r--r--src/syscall/syscall_linux_test.go70
-rw-r--r--src/syscall/syscall_openbsd_libc.go28
-rw-r--r--src/syscall/zerrors_solaris_amd64.go1
-rw-r--r--src/syscall/zsyscall_aix_ppc64.go13
-rw-r--r--src/syscall/zsyscall_openbsd_386.go15
-rw-r--r--src/syscall/zsyscall_openbsd_386.s2
-rw-r--r--src/syscall/zsyscall_openbsd_amd64.go15
-rw-r--r--src/syscall/zsyscall_openbsd_amd64.s2
-rw-r--r--src/syscall/zsyscall_openbsd_arm.go15
-rw-r--r--src/syscall/zsyscall_openbsd_arm.s2
-rw-r--r--src/syscall/zsyscall_openbsd_arm64.go15
-rw-r--r--src/syscall/zsyscall_openbsd_arm64.s2
-rw-r--r--src/syscall/zsyscall_openbsd_ppc64.go15
-rw-r--r--src/syscall/zsyscall_openbsd_ppc64.s3
-rw-r--r--src/syscall/zsyscall_openbsd_riscv64.go15
-rw-r--r--src/syscall/zsyscall_openbsd_riscv64.s2
36 files changed, 285 insertions, 171 deletions
diff --git a/src/syscall/badlinkname_unix.go b/src/syscall/badlinkname_unix.go
new file mode 100644
index 0000000000..4964a830b0
--- /dev/null
+++ b/src/syscall/badlinkname_unix.go
@@ -0,0 +1,22 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
+
+package syscall
+
+import _ "unsafe"
+
+// As of Go 1.22, the symbols below are found to be pulled via
+// linkname in the wild. We provide a push linkname here, to
+// keep them accessible with pull linknames.
+// This may change in the future. Please do not depend on them
+// in new code.
+
+// golang.org/x/sys linknames getsockopt.
+// Do not remove or change the type signature.
+//
+//go:linkname getsockopt
+
+//go:linkname setsockopt
diff --git a/src/syscall/dir_plan9.go b/src/syscall/dir_plan9.go
index 464fe748f7..34869b6209 100644
--- a/src/syscall/dir_plan9.go
+++ b/src/syscall/dir_plan9.go
@@ -6,7 +6,10 @@
package syscall
-import "errors"
+import (
+ "errors"
+ "internal/byteorder"
+)
var (
ErrShortStat = errors.New("stat buffer too short")
@@ -143,30 +146,19 @@ func pbit8(b []byte, v uint8) []byte {
// pbit16 copies the 16-bit number v to b in little-endian order and returns the remaining slice of b.
func pbit16(b []byte, v uint16) []byte {
- b[0] = byte(v)
- b[1] = byte(v >> 8)
+ byteorder.LePutUint16(b, v)
return b[2:]
}
// pbit32 copies the 32-bit number v to b in little-endian order and returns the remaining slice of b.
func pbit32(b []byte, v uint32) []byte {
- b[0] = byte(v)
- b[1] = byte(v >> 8)
- b[2] = byte(v >> 16)
- b[3] = byte(v >> 24)
+ byteorder.LePutUint32(b, v)
return b[4:]
}
// pbit64 copies the 64-bit number v to b in little-endian order and returns the remaining slice of b.
func pbit64(b []byte, v uint64) []byte {
- b[0] = byte(v)
- b[1] = byte(v >> 8)
- b[2] = byte(v >> 16)
- b[3] = byte(v >> 24)
- b[4] = byte(v >> 32)
- b[5] = byte(v >> 40)
- b[6] = byte(v >> 48)
- b[7] = byte(v >> 56)
+ byteorder.LePutUint64(b, v)
return b[8:]
}
@@ -187,19 +179,17 @@ func gbit8(b []byte) (uint8, []byte) {
//
//go:nosplit
func gbit16(b []byte) (uint16, []byte) {
- return uint16(b[0]) | uint16(b[1])<<8, b[2:]
+ return byteorder.LeUint16(b), b[2:]
}
// gbit32 reads a 32-bit number in little-endian order from b and returns it with the remaining slice of b.
func gbit32(b []byte) (uint32, []byte) {
- return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24, b[4:]
+ return byteorder.LeUint32(b), b[4:]
}
// gbit64 reads a 64-bit number in little-endian order from b and returns it with the remaining slice of b.
func gbit64(b []byte) (uint64, []byte) {
- lo := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
- hi := uint32(b[4]) | uint32(b[5])<<8 | uint32(b[6])<<16 | uint32(b[7])<<24
- return uint64(lo) | uint64(hi)<<32, b[8:]
+ return byteorder.LeUint64(b), b[8:]
}
// gstring reads a string from b, prefixed with a 16-bit length in little-endian order.
diff --git a/src/syscall/dirent.go b/src/syscall/dirent.go
index a9eab15736..e4f36a191b 100644
--- a/src/syscall/dirent.go
+++ b/src/syscall/dirent.go
@@ -7,6 +7,7 @@
package syscall
import (
+ "internal/byteorder"
"internal/goarch"
"runtime"
"unsafe"
@@ -28,15 +29,11 @@ func readIntBE(b []byte, size uintptr) uint64 {
case 1:
return uint64(b[0])
case 2:
- _ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
- return uint64(b[1]) | uint64(b[0])<<8
+ return uint64(byteorder.BeUint16(b))
case 4:
- _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
- return uint64(b[3]) | uint64(b[2])<<8 | uint64(b[1])<<16 | uint64(b[0])<<24
+ return uint64(byteorder.BeUint32(b))
case 8:
- _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
- return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 |
- uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56
+ return uint64(byteorder.BeUint64(b))
default:
panic("syscall: readInt with unsupported size")
}
@@ -47,15 +44,11 @@ func readIntLE(b []byte, size uintptr) uint64 {
case 1:
return uint64(b[0])
case 2:
- _ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
- return uint64(b[0]) | uint64(b[1])<<8
+ return uint64(byteorder.LeUint16(b))
case 4:
- _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808
- return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24
+ return uint64(byteorder.LeUint32(b))
case 8:
- _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808
- return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 |
- uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
+ return uint64(byteorder.LeUint64(b))
default:
panic("syscall: readInt with unsupported size")
}
diff --git a/src/syscall/dirent_test.go b/src/syscall/dirent_test.go
index befe78f1cf..cfa5478feb 100644
--- a/src/syscall/dirent_test.go
+++ b/src/syscall/dirent_test.go
@@ -12,7 +12,7 @@ import (
"os"
"path/filepath"
"runtime"
- "sort"
+ "slices"
"strconv"
"strings"
"syscall"
@@ -71,7 +71,7 @@ func TestDirent(t *testing.T) {
}
}
- sort.Strings(names)
+ slices.Sort(names)
t.Logf("names: %q", names)
if len(names) != 10 {
@@ -138,8 +138,8 @@ func TestDirentRepeat(t *testing.T) {
}
// Check results
- sort.Strings(files)
- sort.Strings(files2)
+ slices.Sort(files)
+ slices.Sort(files2)
if strings.Join(files, "|") != strings.Join(files2, "|") {
t.Errorf("bad file list: want\n%q\ngot\n%q", files, files2)
}
diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go
index e6d6343ed8..e4b9ce1bf4 100644
--- a/src/syscall/exec_linux.go
+++ b/src/syscall/exec_linux.go
@@ -53,6 +53,10 @@ const (
// SysProcIDMap holds Container ID to Host ID mappings used for User Namespaces in Linux.
// See user_namespaces(7).
+//
+// Note that User Namespaces are not available on a number of popular Linux
+// versions (due to security issues), or are available but subject to AppArmor
+// restrictions like in Ubuntu 24.04.
type SysProcIDMap struct {
ContainerID int // Container ID.
HostID int // Host ID.
diff --git a/src/syscall/exec_linux_test.go b/src/syscall/exec_linux_test.go
index 5ec1a24ba4..079220eab1 100644
--- a/src/syscall/exec_linux_test.go
+++ b/src/syscall/exec_linux_test.go
@@ -642,6 +642,10 @@ func TestAmbientCaps(t *testing.T) {
}
func TestAmbientCapsUserns(t *testing.T) {
+ b, err := os.ReadFile("/proc/sys/kernel/apparmor_restrict_unprivileged_userns")
+ if err == nil && strings.TrimSpace(string(b)) == "1" {
+ t.Skip("AppArmor restriction for unprivileged user namespaces is enabled")
+ }
testAmbientCaps(t, true)
}
diff --git a/src/syscall/export_linux_test.go b/src/syscall/export_linux_test.go
index 9bcf73e771..d9309bf234 100644
--- a/src/syscall/export_linux_test.go
+++ b/src/syscall/export_linux_test.go
@@ -11,6 +11,7 @@ import (
var (
RawSyscallNoError = rawSyscallNoError
ForceClone3 = &forceClone3
+ Prlimit = prlimit
)
const (
diff --git a/src/syscall/export_rlimit_test.go b/src/syscall/export_rlimit_test.go
index 8b1545cb03..f584ac410d 100644
--- a/src/syscall/export_rlimit_test.go
+++ b/src/syscall/export_rlimit_test.go
@@ -6,6 +6,12 @@
package syscall
+import "sync/atomic"
+
func OrigRlimitNofile() *Rlimit {
return origRlimitNofile.Load()
}
+
+func GetInternalOrigRlimitNofile() *atomic.Pointer[Rlimit] {
+ return &origRlimitNofile
+}
diff --git a/src/syscall/fs_wasip1.go b/src/syscall/fs_wasip1.go
index 4d3d7d72c6..fc361ee898 100644
--- a/src/syscall/fs_wasip1.go
+++ b/src/syscall/fs_wasip1.go
@@ -7,6 +7,7 @@
package syscall
import (
+ "internal/stringslite"
"runtime"
"unsafe"
)
@@ -287,12 +288,18 @@ func fd_fdstat_get(fd int32, buf unsafe.Pointer) Errno
//go:noescape
func fd_fdstat_set_flags(fd int32, flags fdflags) Errno
+// fd_fdstat_get_flags is accessed from internal/syscall/unix
+//go:linkname fd_fdstat_get_flags
+
func fd_fdstat_get_flags(fd int) (uint32, error) {
var stat fdstat
errno := fd_fdstat_get(int32(fd), unsafe.Pointer(&stat))
return uint32(stat.fdflags), errnoErr(errno)
}
+// fd_fdstat_get_type is accessed from net
+//go:linkname fd_fdstat_get_type
+
func fd_fdstat_get_type(fd int) (uint8, error) {
var stat fdstat
errno := fd_fdstat_get(int32(fd), unsafe.Pointer(&stat))
@@ -468,19 +475,11 @@ func joinPath(dir, file string) string {
}
func isAbs(path string) bool {
- return hasPrefix(path, "/")
+ return stringslite.HasPrefix(path, "/")
}
func isDir(path string) bool {
- return hasSuffix(path, "/")
-}
-
-func hasPrefix(s, p string) bool {
- return len(s) >= len(p) && s[:len(p)] == p
-}
-
-func hasSuffix(s, x string) bool {
- return len(s) >= len(x) && s[len(s)-len(x):] == x
+ return stringslite.HasSuffix(path, "/")
}
// preparePath returns the preopen file descriptor of the directory to perform
@@ -500,7 +499,7 @@ func preparePath(path string) (int32, unsafe.Pointer, size) {
path = joinPath(dir, path)
for _, p := range preopens {
- if len(p.name) > len(dirName) && hasPrefix(path, p.name) {
+ if len(p.name) > len(dirName) && stringslite.HasPrefix(path, p.name) {
dirFd, dirName = p.fd, p.name
}
}
diff --git a/src/syscall/getdirentries_test.go b/src/syscall/getdirentries_test.go
index ddd8208c15..5d401d8dd6 100644
--- a/src/syscall/getdirentries_test.go
+++ b/src/syscall/getdirentries_test.go
@@ -10,7 +10,7 @@ import (
"fmt"
"os"
"path/filepath"
- "sort"
+ "slices"
"strings"
"syscall"
"testing"
@@ -76,8 +76,8 @@ func testGetdirentries(t *testing.T, count int) {
}
names = append(names, ".", "..") // Getdirentries returns these also
- sort.Strings(names)
- sort.Strings(names2)
+ slices.Sort(names)
+ slices.Sort(names2)
if strings.Join(names, ":") != strings.Join(names2, ":") {
t.Errorf("names don't match\n names: %q\nnames2: %q", names, names2)
}
diff --git a/src/syscall/linkname_bsd.go b/src/syscall/linkname_bsd.go
new file mode 100644
index 0000000000..c3c6a58420
--- /dev/null
+++ b/src/syscall/linkname_bsd.go
@@ -0,0 +1,17 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build darwin || dragonfly || freebsd || netbsd || openbsd
+
+package syscall
+
+import _ "unsafe"
+
+// used by internal/syscall/unix
+//go:linkname ioctlPtr
+
+// golang.org/x/net linknames sysctl.
+// Do not remove or change the type signature.
+//
+//go:linkname sysctl
diff --git a/src/syscall/linkname_darwin.go b/src/syscall/linkname_darwin.go
new file mode 100644
index 0000000000..2ed83a4fad
--- /dev/null
+++ b/src/syscall/linkname_darwin.go
@@ -0,0 +1,23 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package syscall
+
+import _ "unsafe"
+
+// used by os
+//go:linkname closedir
+//go:linkname readdir_r
+
+// used by internal/poll
+//go:linkname fdopendir
+
+// used by internal/syscall/unix
+//go:linkname unlinkat
+//go:linkname openat
+//go:linkname fstatat
+
+// used by cmd/link
+//go:linkname msync
+//go:linkname fcntl
diff --git a/src/syscall/linkname_libc.go b/src/syscall/linkname_libc.go
new file mode 100644
index 0000000000..1e7b4880d6
--- /dev/null
+++ b/src/syscall/linkname_libc.go
@@ -0,0 +1,12 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build aix || darwin || (openbsd && !mips64) || solaris
+
+package syscall
+
+import _ "unsafe"
+
+// used by internal/poll
+//go:linkname writev
diff --git a/src/syscall/linkname_openbsd.go b/src/syscall/linkname_openbsd.go
new file mode 100644
index 0000000000..5f5c517ab5
--- /dev/null
+++ b/src/syscall/linkname_openbsd.go
@@ -0,0 +1,15 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build openbsd && !mips64
+
+package syscall
+
+import _ "unsafe"
+
+// used by internal/syscall/unix
+//go:linkname unlinkat
+//go:linkname openat
+//go:linkname fstatat
+//go:linkname getentropy
diff --git a/src/syscall/linkname_unix.go b/src/syscall/linkname_unix.go
new file mode 100644
index 0000000000..c4d187c01f
--- /dev/null
+++ b/src/syscall/linkname_unix.go
@@ -0,0 +1,20 @@
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build unix
+
+package syscall
+
+import _ "unsafe" // for linkname
+
+// mmap should be an internal detail,
+// but widely used packages access it using linkname.
+// Notable members of the hall of shame include:
+// - modernc.org/memory
+// - github.com/ncruces/go-sqlite3
+//
+// Do not remove or change the type signature.
+// See go.dev/issue/67401.
+//
+//go:linkname mmap
diff --git a/src/syscall/mksyscall.pl b/src/syscall/mksyscall.pl
index 47efbffcbc..b46a3f9438 100755
--- a/src/syscall/mksyscall.pl
+++ b/src/syscall/mksyscall.pl
@@ -33,6 +33,7 @@ my $arm = 0; # 64-bit value should use (even, odd)-pair
my $libc = 0;
my $tags = ""; # build tags
my $newtags = ""; # new style build tags
+my $stdimports = 'import "unsafe"';
my $extraimports = "";
if($ARGV[0] eq "-b32") {
@@ -390,6 +391,10 @@ if($errors) {
exit 1;
}
+if($extraimports ne "") {
+ $stdimports .= "\n$extraimports";
+}
+
# TODO: this assumes tags are just simply comma separated. For now this is all the uses.
$newtags = $tags =~ s/,/ && /r;
@@ -401,8 +406,7 @@ print <<EOF;
package syscall
-import "unsafe"
-$extraimports
+$stdimports
$text
EOF
diff --git a/src/syscall/rlimit.go b/src/syscall/rlimit.go
index d77341bde9..8184f17ab6 100644
--- a/src/syscall/rlimit.go
+++ b/src/syscall/rlimit.go
@@ -39,11 +39,10 @@ func init() {
}
func Setrlimit(resource int, rlim *Rlimit) error {
- err := setrlimit(resource, rlim)
- if err == nil && resource == RLIMIT_NOFILE {
+ if resource == RLIMIT_NOFILE {
// Store nil in origRlimitNofile to tell StartProcess
// to not adjust the rlimit in the child process.
origRlimitNofile.Store(nil)
}
- return err
+ return setrlimit(resource, rlim)
}
diff --git a/src/syscall/syscall_aix.go b/src/syscall/syscall_aix.go
index 18827e9e8b..a9bd7a3733 100644
--- a/src/syscall/syscall_aix.go
+++ b/src/syscall/syscall_aix.go
@@ -629,6 +629,7 @@ func PtraceDetach(pid int) (err error) { return ptrace64(PT_DETACH, int64(pid),
//sysnb Setegid(egid int) (err error)
//sysnb Seteuid(euid int) (err error)
//sysnb Setgid(gid int) (err error)
+//sysnb Setuid(uid int) (err error)
//sysnb Setpgid(pid int, pgid int) (err error)
//sys Setpriority(which int, who int, prio int) (err error)
//sysnb Setregid(rgid int, egid int) (err error)
diff --git a/src/syscall/syscall_darwin.go b/src/syscall/syscall_darwin.go
index 2e13b57cd3..5b38aeae31 100644
--- a/src/syscall/syscall_darwin.go
+++ b/src/syscall/syscall_darwin.go
@@ -113,6 +113,15 @@ func libc_getfsstat_trampoline()
//go:cgo_import_dynamic libc_getfsstat getfsstat "/usr/lib/libSystem.B.dylib"
+// utimensat should be an internal detail,
+// but widely used packages access it using linkname.
+// Notable members of the hall of shame include:
+// - github.com/tetratelabs/wazero
+//
+// See go.dev/issue/67401.
+//
+//go:linkname utimensat
+
//sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
/*
diff --git a/src/syscall/syscall_linux.go b/src/syscall/syscall_linux.go
index 6547c517a7..2706973596 100644
--- a/src/syscall/syscall_linux.go
+++ b/src/syscall/syscall_linux.go
@@ -1286,10 +1286,14 @@ func Munmap(b []byte) (err error) {
// prlimit changes a resource limit. We use a single definition so that
// we can tell StartProcess to not restore the original NOFILE limit.
-// This is unexported but can be called from x/sys/unix.
+//
+// golang.org/x/sys linknames prlimit.
+// Do not remove or change the type signature.
+//
+//go:linkname prlimit
func prlimit(pid int, resource int, newlimit *Rlimit, old *Rlimit) (err error) {
err = prlimit1(pid, resource, newlimit, old)
- if err == nil && newlimit != nil && resource == RLIMIT_NOFILE {
+ if err == nil && newlimit != nil && resource == RLIMIT_NOFILE && (pid == 0 || pid == Getpid()) {
origRlimitNofile.Store(nil)
}
return err
diff --git a/src/syscall/syscall_linux_test.go b/src/syscall/syscall_linux_test.go
index 1300fc046e..d7543ceb4b 100644
--- a/src/syscall/syscall_linux_test.go
+++ b/src/syscall/syscall_linux_test.go
@@ -13,7 +13,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
- "sort"
+ "slices"
"strconv"
"strings"
"sync"
@@ -484,7 +484,7 @@ func compareStatus(filter, expect string) error {
// https://github.com/golang/go/issues/46145
// Containers don't reliably output this line in sorted order so manually sort and compare that.
a := strings.Split(line[8:], " ")
- sort.Strings(a)
+ slices.Sort(a)
got := strings.Join(a, " ")
if got == expected[8:] {
foundAThread = true
@@ -654,3 +654,69 @@ func TestAllThreadsSyscallBlockedSyscall(t *testing.T) {
wr.Close()
wg.Wait()
}
+
+func TestPrlimitSelf(t *testing.T) {
+ origLimit := syscall.OrigRlimitNofile()
+ origRlimitNofile := syscall.GetInternalOrigRlimitNofile()
+
+ if origLimit == nil {
+ defer origRlimitNofile.Store(origLimit)
+ origRlimitNofile.Store(&syscall.Rlimit{
+ Cur: 1024,
+ Max: 65536,
+ })
+ }
+
+ // Get current process's nofile limit
+ var lim syscall.Rlimit
+ if err := syscall.Prlimit(0, syscall.RLIMIT_NOFILE, nil, &lim); err != nil {
+ t.Fatalf("Failed to get the current nofile limit: %v", err)
+ }
+ // Set current process's nofile limit through prlimit
+ if err := syscall.Prlimit(0, syscall.RLIMIT_NOFILE, &lim, nil); err != nil {
+ t.Fatalf("Prlimit self failed: %v", err)
+ }
+
+ rlimLater := origRlimitNofile.Load()
+ if rlimLater != nil {
+ t.Fatalf("origRlimitNofile got=%v, want=nil", rlimLater)
+ }
+}
+
+func TestPrlimitOtherProcess(t *testing.T) {
+ origLimit := syscall.OrigRlimitNofile()
+ origRlimitNofile := syscall.GetInternalOrigRlimitNofile()
+
+ if origLimit == nil {
+ defer origRlimitNofile.Store(origLimit)
+ origRlimitNofile.Store(&syscall.Rlimit{
+ Cur: 1024,
+ Max: 65536,
+ })
+ }
+ rlimOrig := origRlimitNofile.Load()
+
+ // Start a child process firstly,
+ // so we can use Prlimit to set it's nofile limit.
+ cmd := exec.Command("sleep", "infinity")
+ cmd.Start()
+ defer func() {
+ cmd.Process.Kill()
+ cmd.Process.Wait()
+ }()
+
+ // Get child process's current nofile limit
+ var lim syscall.Rlimit
+ if err := syscall.Prlimit(cmd.Process.Pid, syscall.RLIMIT_NOFILE, nil, &lim); err != nil {
+ t.Fatalf("Failed to get the current nofile limit: %v", err)
+ }
+ // Set child process's nofile rlimit through prlimit
+ if err := syscall.Prlimit(cmd.Process.Pid, syscall.RLIMIT_NOFILE, &lim, nil); err != nil {
+ t.Fatalf("Prlimit(%d) failed: %v", cmd.Process.Pid, err)
+ }
+
+ rlimLater := origRlimitNofile.Load()
+ if rlimLater != rlimOrig {
+ t.Fatalf("origRlimitNofile got=%v, want=%v", rlimLater, rlimOrig)
+ }
+}
diff --git a/src/syscall/syscall_openbsd_libc.go b/src/syscall/syscall_openbsd_libc.go
index ddf62f4d3f..5dea268c3e 100644
--- a/src/syscall/syscall_openbsd_libc.go
+++ b/src/syscall/syscall_openbsd_libc.go
@@ -16,26 +16,40 @@ func init() {
execveOpenBSD = execve
}
-//sys directSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr) (ret uintptr, err error) = SYS_syscall
-
func syscallInternal(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
- return syscall6X(abi.FuncPCABI0(libc_syscall_trampoline), trap, a1, a2, a3, 0, 0)
+ // OpenBSD 7.5+ no longer supports indirect syscalls. A number of Go
+ // packages make use of syscall.Syscall with SYS_IOCTL since it is
+ // not well supported by golang.org/x/sys/unix. Reroute this system
+ // call number to the respective libc stub so that it continues to
+ // work for the time being. See #63900 for further details.
+ if trap == SYS_IOCTL {
+ return syscallX(abi.FuncPCABI0(libc_ioctl_trampoline), a1, a2, a3)
+ }
+ return 0, 0, ENOSYS
}
func syscall6Internal(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
- return syscall10X(abi.FuncPCABI0(libc_syscall_trampoline), trap, a1, a2, a3, a4, a5, a6, 0, 0, 0)
+ // OpenBSD 7.5+ no longer supports indirect syscalls. A number of Go
+ // packages make use of syscall.Syscall with SYS___SYSCTL since it is
+ // not well supported by golang.org/x/sys/unix. Reroute this system
+ // call number to the respective libc stub so that it continues to
+ // work for the time being. See #63900 for further details.
+ if trap == SYS___SYSCTL {
+ return syscall6X(abi.FuncPCABI0(libc_sysctl_trampoline), a1, a2, a3, a4, a5, a6)
+ }
+ return 0, 0, ENOSYS
}
func rawSyscallInternal(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
- return rawSyscall6X(abi.FuncPCABI0(libc_syscall_trampoline), trap, a1, a2, a3, 0, 0)
+ return 0, 0, ENOSYS
}
func rawSyscall6Internal(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
- return rawSyscall10X(abi.FuncPCABI0(libc_syscall_trampoline), trap, a1, a2, a3, a4, a5, a6, 0, 0, 0)
+ return 0, 0, ENOSYS
}
func syscall9Internal(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err Errno) {
- return rawSyscall10X(abi.FuncPCABI0(libc_syscall_trampoline), trap, a1, a2, a3, a4, a5, a6, a7, a8, a9)
+ return 0, 0, ENOSYS
}
// Implemented in the runtime package (runtime/sys_openbsd3.go)
diff --git a/src/syscall/zerrors_solaris_amd64.go b/src/syscall/zerrors_solaris_amd64.go
index 4a1d9c3d26..b2c81d9a51 100644
--- a/src/syscall/zerrors_solaris_amd64.go
+++ b/src/syscall/zerrors_solaris_amd64.go
@@ -634,6 +634,7 @@ const (
O_APPEND = 0x8
O_CLOEXEC = 0x800000
O_CREAT = 0x100
+ O_DIRECTORY = 0x1000000
O_DSYNC = 0x40
O_EXCL = 0x400
O_EXEC = 0x400000
diff --git a/src/syscall/zsyscall_aix_ppc64.go b/src/syscall/zsyscall_aix_ppc64.go
index 111e6711d7..27657aa1e9 100644
--- a/src/syscall/zsyscall_aix_ppc64.go
+++ b/src/syscall/zsyscall_aix_ppc64.go
@@ -83,6 +83,7 @@ import "unsafe"
//go:cgo_import_dynamic libc_Setegid setegid "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_Seteuid seteuid "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_Setgid setgid "libc.a/shr_64.o"
+//go:cgo_import_dynamic libc_Setuid setuid "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_Setpgid setpgid "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_Setpriority setpriority "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_Setregid setregid "libc.a/shr_64.o"
@@ -177,6 +178,7 @@ import "unsafe"
//go:linkname libc_Setegid libc_Setegid
//go:linkname libc_Seteuid libc_Seteuid
//go:linkname libc_Setgid libc_Setgid
+//go:linkname libc_Setuid libc_Setuid
//go:linkname libc_Setpgid libc_Setpgid
//go:linkname libc_Setpriority libc_Setpriority
//go:linkname libc_Setregid libc_Setregid
@@ -274,6 +276,7 @@ var (
libc_Setegid,
libc_Seteuid,
libc_Setgid,
+ libc_Setuid,
libc_Setpgid,
libc_Setpriority,
libc_Setregid,
@@ -1231,6 +1234,16 @@ func Setgid(gid int) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func Setuid(uid int) (err error) {
+ _, _, e1 := rawSyscall6(uintptr(unsafe.Pointer(&libc_Setuid)), 1, uintptr(uid), 0, 0, 0, 0, 0)
+ if e1 != 0 {
+ err = errnoErr(e1)
+ }
+ return
+}
+
+// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+
func Setpgid(pid int, pgid int) (err error) {
_, _, e1 := rawSyscall6(uintptr(unsafe.Pointer(&libc_Setpgid)), 2, uintptr(pid), uintptr(pgid), 0, 0, 0, 0)
if e1 != 0 {
diff --git a/src/syscall/zsyscall_openbsd_386.go b/src/syscall/zsyscall_openbsd_386.go
index 084b4b78e5..d2bd3ea012 100644
--- a/src/syscall/zsyscall_openbsd_386.go
+++ b/src/syscall/zsyscall_openbsd_386.go
@@ -1729,21 +1729,6 @@ func libc_utimensat_trampoline()
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func directSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr) (ret uintptr, err error) {
- r0, _, e1 := syscall6(abi.FuncPCABI0(libc_syscall_trampoline), uintptr(trap), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5))
- ret = uintptr(r0)
- if e1 != 0 {
- err = errnoErr(e1)
- }
- return
-}
-
-func libc_syscall_trampoline()
-
-//go:cgo_import_dynamic libc_syscall syscall "libc.so"
-
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
r0, _, e1 := syscall(abi.FuncPCABI0(libc_read_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
n = int(r0)
diff --git a/src/syscall/zsyscall_openbsd_386.s b/src/syscall/zsyscall_openbsd_386.s
index 319ad205c0..9a820e9f3e 100644
--- a/src/syscall/zsyscall_openbsd_386.s
+++ b/src/syscall/zsyscall_openbsd_386.s
@@ -213,8 +213,6 @@ TEXT ·libc_getfsstat_trampoline(SB),NOSPLIT,$0-0
JMP libc_getfsstat(SB)
TEXT ·libc_utimensat_trampoline(SB),NOSPLIT,$0-0
JMP libc_utimensat(SB)
-TEXT ·libc_syscall_trampoline(SB),NOSPLIT,$0-0
- JMP libc_syscall(SB)
TEXT ·libc_lseek_trampoline(SB),NOSPLIT,$0-0
JMP libc_lseek(SB)
TEXT ·libc_getcwd_trampoline(SB),NOSPLIT,$0-0
diff --git a/src/syscall/zsyscall_openbsd_amd64.go b/src/syscall/zsyscall_openbsd_amd64.go
index 5a7b4c1122..170a74b457 100644
--- a/src/syscall/zsyscall_openbsd_amd64.go
+++ b/src/syscall/zsyscall_openbsd_amd64.go
@@ -1729,21 +1729,6 @@ func libc_utimensat_trampoline()
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func directSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr) (ret uintptr, err error) {
- r0, _, e1 := syscall6X(abi.FuncPCABI0(libc_syscall_trampoline), uintptr(trap), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5))
- ret = uintptr(r0)
- if e1 != 0 {
- err = errnoErr(e1)
- }
- return
-}
-
-func libc_syscall_trampoline()
-
-//go:cgo_import_dynamic libc_syscall syscall "libc.so"
-
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
r0, _, e1 := syscall(abi.FuncPCABI0(libc_read_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
n = int(r0)
diff --git a/src/syscall/zsyscall_openbsd_amd64.s b/src/syscall/zsyscall_openbsd_amd64.s
index c0e397728a..9b70dc096e 100644
--- a/src/syscall/zsyscall_openbsd_amd64.s
+++ b/src/syscall/zsyscall_openbsd_amd64.s
@@ -213,8 +213,6 @@ TEXT ·libc_getfsstat_trampoline(SB),NOSPLIT,$0-0
JMP libc_getfsstat(SB)
TEXT ·libc_utimensat_trampoline(SB),NOSPLIT,$0-0
JMP libc_utimensat(SB)
-TEXT ·libc_syscall_trampoline(SB),NOSPLIT,$0-0
- JMP libc_syscall(SB)
TEXT ·libc_lseek_trampoline(SB),NOSPLIT,$0-0
JMP libc_lseek(SB)
TEXT ·libc_getcwd_trampoline(SB),NOSPLIT,$0-0
diff --git a/src/syscall/zsyscall_openbsd_arm.go b/src/syscall/zsyscall_openbsd_arm.go
index 66a3227175..e75bd0b443 100644
--- a/src/syscall/zsyscall_openbsd_arm.go
+++ b/src/syscall/zsyscall_openbsd_arm.go
@@ -1729,21 +1729,6 @@ func libc_utimensat_trampoline()
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func directSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr) (ret uintptr, err error) {
- r0, _, e1 := syscall6(abi.FuncPCABI0(libc_syscall_trampoline), uintptr(trap), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5))
- ret = uintptr(r0)
- if e1 != 0 {
- err = errnoErr(e1)
- }
- return
-}
-
-func libc_syscall_trampoline()
-
-//go:cgo_import_dynamic libc_syscall syscall "libc.so"
-
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
r0, _, e1 := syscall(abi.FuncPCABI0(libc_read_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
n = int(r0)
diff --git a/src/syscall/zsyscall_openbsd_arm.s b/src/syscall/zsyscall_openbsd_arm.s
index 73b6a092ef..0333377b8b 100644
--- a/src/syscall/zsyscall_openbsd_arm.s
+++ b/src/syscall/zsyscall_openbsd_arm.s
@@ -213,8 +213,6 @@ TEXT ·libc_getfsstat_trampoline(SB),NOSPLIT,$0-0
JMP libc_getfsstat(SB)
TEXT ·libc_utimensat_trampoline(SB),NOSPLIT,$0-0
JMP libc_utimensat(SB)
-TEXT ·libc_syscall_trampoline(SB),NOSPLIT,$0-0
- JMP libc_syscall(SB)
TEXT ·libc_lseek_trampoline(SB),NOSPLIT,$0-0
JMP libc_lseek(SB)
TEXT ·libc_getcwd_trampoline(SB),NOSPLIT,$0-0
diff --git a/src/syscall/zsyscall_openbsd_arm64.go b/src/syscall/zsyscall_openbsd_arm64.go
index a90f144369..bc027b4475 100644
--- a/src/syscall/zsyscall_openbsd_arm64.go
+++ b/src/syscall/zsyscall_openbsd_arm64.go
@@ -1729,21 +1729,6 @@ func libc_utimensat_trampoline()
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func directSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr) (ret uintptr, err error) {
- r0, _, e1 := syscall6X(abi.FuncPCABI0(libc_syscall_trampoline), uintptr(trap), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5))
- ret = uintptr(r0)
- if e1 != 0 {
- err = errnoErr(e1)
- }
- return
-}
-
-func libc_syscall_trampoline()
-
-//go:cgo_import_dynamic libc_syscall syscall "libc.so"
-
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
r0, _, e1 := syscall(abi.FuncPCABI0(libc_read_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
n = int(r0)
diff --git a/src/syscall/zsyscall_openbsd_arm64.s b/src/syscall/zsyscall_openbsd_arm64.s
index 66656695d5..654e6c69a3 100644
--- a/src/syscall/zsyscall_openbsd_arm64.s
+++ b/src/syscall/zsyscall_openbsd_arm64.s
@@ -213,8 +213,6 @@ TEXT ·libc_getfsstat_trampoline(SB),NOSPLIT,$0-0
JMP libc_getfsstat(SB)
TEXT ·libc_utimensat_trampoline(SB),NOSPLIT,$0-0
JMP libc_utimensat(SB)
-TEXT ·libc_syscall_trampoline(SB),NOSPLIT,$0-0
- JMP libc_syscall(SB)
TEXT ·libc_lseek_trampoline(SB),NOSPLIT,$0-0
JMP libc_lseek(SB)
TEXT ·libc_getcwd_trampoline(SB),NOSPLIT,$0-0
diff --git a/src/syscall/zsyscall_openbsd_ppc64.go b/src/syscall/zsyscall_openbsd_ppc64.go
index 661c8959a6..6808092a5a 100644
--- a/src/syscall/zsyscall_openbsd_ppc64.go
+++ b/src/syscall/zsyscall_openbsd_ppc64.go
@@ -1729,21 +1729,6 @@ func libc_utimensat_trampoline()
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func directSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr) (ret uintptr, err error) {
- r0, _, e1 := syscall6X(abi.FuncPCABI0(libc_syscall_trampoline), uintptr(trap), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5))
- ret = uintptr(r0)
- if e1 != 0 {
- err = errnoErr(e1)
- }
- return
-}
-
-func libc_syscall_trampoline()
-
-//go:cgo_import_dynamic libc_syscall syscall "libc.so"
-
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
r0, _, e1 := syscall(abi.FuncPCABI0(libc_read_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
n = int(r0)
diff --git a/src/syscall/zsyscall_openbsd_ppc64.s b/src/syscall/zsyscall_openbsd_ppc64.s
index 8f3ff9a28c..86a5745c0a 100644
--- a/src/syscall/zsyscall_openbsd_ppc64.s
+++ b/src/syscall/zsyscall_openbsd_ppc64.s
@@ -319,9 +319,6 @@ TEXT ·libc_getfsstat_trampoline(SB),NOSPLIT,$0-0
TEXT ·libc_utimensat_trampoline(SB),NOSPLIT,$0-0
CALL libc_utimensat(SB)
RET
-TEXT ·libc_syscall_trampoline(SB),NOSPLIT,$0-0
- CALL libc_syscall(SB)
- RET
TEXT ·libc_lseek_trampoline(SB),NOSPLIT,$0-0
CALL libc_lseek(SB)
RET
diff --git a/src/syscall/zsyscall_openbsd_riscv64.go b/src/syscall/zsyscall_openbsd_riscv64.go
index a24fcba113..2979ff78c2 100644
--- a/src/syscall/zsyscall_openbsd_riscv64.go
+++ b/src/syscall/zsyscall_openbsd_riscv64.go
@@ -1729,21 +1729,6 @@ func libc_utimensat_trampoline()
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-func directSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr) (ret uintptr, err error) {
- r0, _, e1 := syscall6X(abi.FuncPCABI0(libc_syscall_trampoline), uintptr(trap), uintptr(a1), uintptr(a2), uintptr(a3), uintptr(a4), uintptr(a5))
- ret = uintptr(r0)
- if e1 != 0 {
- err = errnoErr(e1)
- }
- return
-}
-
-func libc_syscall_trampoline()
-
-//go:cgo_import_dynamic libc_syscall syscall "libc.so"
-
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
func readlen(fd int, buf *byte, nbuf int) (n int, err error) {
r0, _, e1 := syscall(abi.FuncPCABI0(libc_read_trampoline), uintptr(fd), uintptr(unsafe.Pointer(buf)), uintptr(nbuf))
n = int(r0)
diff --git a/src/syscall/zsyscall_openbsd_riscv64.s b/src/syscall/zsyscall_openbsd_riscv64.s
index 4f787ee275..c8728190e5 100644
--- a/src/syscall/zsyscall_openbsd_riscv64.s
+++ b/src/syscall/zsyscall_openbsd_riscv64.s
@@ -213,8 +213,6 @@ TEXT ·libc_getfsstat_trampoline(SB),NOSPLIT,$0-0
JMP libc_getfsstat(SB)
TEXT ·libc_utimensat_trampoline(SB),NOSPLIT,$0-0
JMP libc_utimensat(SB)
-TEXT ·libc_syscall_trampoline(SB),NOSPLIT,$0-0
- JMP libc_syscall(SB)
TEXT ·libc_lseek_trampoline(SB),NOSPLIT,$0-0
JMP libc_lseek(SB)
TEXT ·libc_getcwd_trampoline(SB),NOSPLIT,$0-0