211 Commits

Author SHA1 Message Date
Kir Kolyshkin
28c5bda5d4 unix: add SetMemPolicy and its mode/flag values
This reuses CPUSet type as it fits perfectly.

No GetMemPolicy support yet.

Change-Id: I549361bc1ed95ee73fd38d00277ec0f9f348a9ba
Reviewed-on: https://go-review.googlesource.com/c/sys/+/706917
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Antti Kervinen <antti.kervinen@gmail.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-10-08 14:29:03 -07:00
Kir Kolyshkin
32e203842b unix: use Go 1.21+ clear built-in
Inspired by CL 698495.

Change-Id: Ic6ff68a60d41b6ffb6a28f523597c5d36c1e4d2f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/704915
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-09-18 13:57:09 -07:00
Tobias Klauser
01aaa8342f all: simplify code by using modern Go constructs
Generated using modernize by running:

    go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...

Change-Id: Ifc7d61cf6735cc53f2bdf890a338961f55075af5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/661975
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-04-03 13:04:48 -07:00
Yaroslav Kolomiiets
fe162bad74 unix: add ClockSettime on Linux
The syscall clock_settime(3) is used to set the time on the specified
clock. It is a counterpart to clock_gettime(3) which is already
exposed as ClockGettime here.

Fixes golang/go#69830

Change-Id: I6145c915754f31e3c50f6a11568eb9d5ba12a778
GitHub-Last-Rev: 5b15f129cc
GitHub-Pull-Request: golang/sys#221
Reviewed-on: https://go-review.googlesource.com/c/sys/+/619255
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-10 19:53:43 +00:00
Jason A. Donenfeld
981de40f5c unix: use vDSO for getrandom() on linux
With CL 614835 adding support in the runtime for calling into the
getrandom() vDSO function, wire up x/sys/unix's Getrandom() function to
it, so that callers can benefit from the increased speed and shared
vDSO state with the runtime.

Updates golang/go#69577.

Change-Id: I17734409982c51bb984a6337f4ffa8f60414ebee
Reviewed-on: https://go-review.googlesource.com/c/sys/+/615335
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-28 01:26:00 +00:00
Leo Antunes
48aad76ed3 linux: add tcp_cc_info and its related types
Add the ability to retrieve congestion control information from a socket via TCP_CC_INFO.

Fixes golang/go#68232

Change-Id: I2ea15928ec0e3192b670759bab4b659e62be553b
GitHub-Last-Rev: b8b8c44f1f
GitHub-Pull-Request: golang/sys#200
Reviewed-on: https://go-review.googlesource.com/c/sys/+/595676
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-09-17 15:50:50 +00:00
Mauri de Souza Meneguzzo
cde4660eb9 unix: add linux mseal system call
The mseal system call was added in Linux 6.10.

See https://lwn.net/Articles/954936.

Change-Id: Ic812a5d784effbc1f362045ffeb6f7e50ee5f8bb
GitHub-Last-Rev: de3924e954
GitHub-Pull-Request: golang/sys#209
Reviewed-on: https://go-review.googlesource.com/c/sys/+/600518
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-07-29 14:24:59 +00:00
Ilya Hanov
360f961f89 unix: add API for fsconfig system call
Fixes golang/go#59537

Change-Id: I8d806ace3adad423c633813455d8f758706cee1d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/484995
Reviewed-by: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-02-16 13:31:09 +00:00
Konstantin Burkalev
e4099bfacb unix: fix trimmed socket opt string in GetsockoptString
Fixes golang/go#63217

Change-Id: Ia1b0ae88b7e7a7c611067a0b30e454b66f45ce51
Reviewed-on: https://go-review.googlesource.com/c/sys/+/530897
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2023-11-08 17:59:55 +00:00
Tobias Klauser
2d0c73638b unix: use fchmodat2 in Fchmodat
The fchmodat2 syscall was added in Linux kernel 6.6. Use it in Fchmodat
if flags are given. It will return ENOSYS on older kernels (or EINVAL or
any other bogus error in some container implementations).

Fixes golang/go#61636

Change-Id: Ibbc9a08733b7186907b2fe5837cb997446c38357
Reviewed-on: https://go-review.googlesource.com/c/sys/+/539635
Reviewed-by: Heschi Kreinick <heschi@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
2023-11-06 18:22:10 +00:00
F Y
1e638101df unix: stop counting trailing NUL for abstract addresses starting with NUL
Changes trailing-NUL-counting behavior for abstract addresses
starting with the NUL character to be the same as abstract
addresses starting with the @ character.

For golang/go#63579.

Change-Id: I2f26de4bcf614c4635ad188b1afa3d14ebd9a95f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/535955
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-23 09:05:11 +00:00
Mauri de Souza Meneguzzo
1d9f0b6d88 unix: add linux cachestat system call
The cachestat system call is an alternative to mincore that offers more
extensive page cache statistics, aiming to enhance scalability. It was added
on Linux 6.5.

Fixes golang/go#61917

Change-Id: If1b6b96f859dd6bf09f1a0c048abfa743a42c540
GitHub-Last-Rev: d18fbb9c48
GitHub-Pull-Request: golang/sys#176
Reviewed-on: https://go-review.googlesource.com/c/sys/+/533242
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-10 00:36:02 +00:00
Tobias Klauser
2964e1e4b1 unix: remove unused readlen and writelen
These were originally added when copying over files from package
syscall. However, their use was removed in CL 129500043. New ports kept
adding these wrappers without using them. They are still unused, so
remove them.

Change-Id: I2ffffe98a5c999d23b63d1f04ee4ad8f807ee736
Reviewed-on: https://go-review.googlesource.com/c/sys/+/531356
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-28 17:55:56 +00:00
Tobias Klauser
807530fc6d unix: remove lists of unimplemented syscalls
These lists are incomplete and out of date, so there's not much point
in keeping them around.

Change-Id: I0a45905c774b751f0a744f1df88bccb0554a6ab1
Reviewed-on: https://go-review.googlesource.com/c/sys/+/530896
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-09-27 13:17:34 +00:00
Kir Kolyshkin
c7ff727a8c unix: fix double copy in (*SockaddrALG).sockaddr
The code uses ByteSliceFromString first, which
 - checks that the string does not contain \0;
 - copies the string to a byte slice which ends with \0.

Next, it does one more copy, to sa.raw fields.

Double copying is not needed because:
 - the code already checks that there's an extra byte for \0 in the
   sa.raw field;
 - there is no need to check for \0 byte in the middle of the fields
   (those are hash and cipher names, and an unknown name will result in
   EINVAL from the kernel).

While at it, remove the use of magic numbers.

Change-Id: I0cf096fad6f974507d4aa8d429f077000b3bb639
Reviewed-on: https://go-review.googlesource.com/c/sys/+/527836
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-15 18:45:27 +00:00
Kir Kolyshkin
ee578879d8 unix: add SchedSetAttr and SchedGetAttr for Linux
Add wrappers for sched_getattr(2) and sched_setattr(2), as well as
various SCHED_ values usable for these.

The kludge in linux/types.go is needed so we can include both
linux/sched/types.h (for struct sched_attr) and sched.h (for a few
defines from include/bits/cpu-set.h).

Unfortunately, they both define struct sched_param, thus the need to
mask one of the definitions.

Change-Id: I3e13cf49ccef7ae81a75d33826d18de84a52106d
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Reviewed-on: https://go-review.googlesource.com/c/sys/+/516756
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-08-09 15:08:02 +00:00
Mauri de Souza Meneguzzo
25d0004552 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: cb3c6d7da9
GitHub-Pull-Request: golang/sys#167
Reviewed-on: https://go-review.googlesource.com/c/sys/+/510195
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-07-19 00:01:56 +00:00
Tobias Klauser
3fead03e7d 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 <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-07-13 05:43:33 +00:00
Anton Kuklin
e0c3b6e6ae unix: add Mremap for linux
For golang/go#60409

Change-Id: I75a9732ee996f0aeb91599d80803f96ada468c27
GitHub-Last-Rev: c348b6194d
GitHub-Pull-Request: golang/sys#164
Reviewed-on: https://go-review.googlesource.com/c/sys/+/502715
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2023-06-16 19:37:35 +00:00
Brad Fitzpatrick
55b11dcdae 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 <tobias.klauser@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-06-12 14:18:21 +00:00
Guoqi Chen
5059a07aa4 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 <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-06-09 14:43:47 +00:00
Mateusz Poliwczak
b52f5441ce unix: add Getresuid, Getresgid for linux
Fixes golang/go#60483

Change-Id: Id4c1bf8367066485a16bedeea337c384a3555942
GitHub-Last-Rev: 61f0fe6f6a
GitHub-Pull-Request: golang/sys#159
Reviewed-on: https://go-review.googlesource.com/c/sys/+/499055
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-05-31 15:03:40 +00:00
Ian Lance Taylor
ff18efa0a3 unix: change Setrlimit/Prlimit to always call syscall functions
As of Go 1.21 syscall.Setrlimit and syscall.prlimit can affect
starting a new process, by restoring the original NOFILE rlimit.
That is recorded locally in the syscall package, so just always
call the syscall functions.

For golang/go#46279

Change-Id: I2f3dafe5562a7dde1297bad6f5d34a80af5d620b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/476695
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-03-15 21:12:13 +00:00
Tobias Klauser
147085206c unix: add SetsockoptTCPMD5Sig on linux
This allows to set the TCP MD5 signature (see
https://www.rfc-editor.org/rfc/rfc2385) using TCPMD5Sig introduced in CL
106656.

Also export the storage data field in SockaddrStorage and convert it to
a byte array so the address in TCPMD5Sig.Addr can be set from an net.IP
without conversion.

Change-Id: I6bccfab57c188fcef857a6a3c514c943ca00b670
Reviewed-on: https://go-review.googlesource.com/c/sys/+/472835
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
2023-03-02 17:30:46 +00:00
Tobias Klauser
a6bfb89d2f unix: use unsafe.Slice in anyToSockaddr
Same as CL 471436 did in package syscall.

Change-Id: Ic3f3a5ebb7ebe0cc7b6bbf377dd993cdbeaaa961
Reviewed-on: https://go-review.googlesource.com/c/sys/+/472015
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-02-28 18:48:22 +00:00
Tobias Klauser
a3b23cc77e unix: use SYS_PTRACE in generated ptracePtr
CL 469835 broke the syscall wrapper generation on linux and freebsd by
generating a wrapper for the inexistent SYS_PTRACE_PTR syscall. The
ptracePtr added by CL 469835 correctly uses SYS_PTRACE, likely because
it was manually edited in that CL. However, the incorrect SYS_PTRACE_PTR
syscall is used when regenerating the syscall wrappers.

Change-Id: I270d66511f926d30a9d347930e977a026e033998
Reviewed-on: https://go-review.googlesource.com/c/sys/+/470175
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-22 18:57:16 +00:00
Dmitri Goutnik
2977c7732d unix: add ptracePtr that accepts pointer arg as unsafe.Pointer
The existing ptrace wrapper accepts pointer argument as an uintptr which
often points to the memory allocated in Go. This violates unsafe.Pointer safety
rules.

For golang/go#58387

Change-Id: Ib3b4c50368725191f0862c6c7c6d46b0568523c7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/469835
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-02-21 23:06:39 +00:00
Kir Kolyshkin
3b9b58b717 unix: Faccess: check CAP_DAC_OVERRIDE on Linux
CL 126516 added support for flags argument, implemented in the same way
as glibc does (it tries to guess what the kernel would do).

CL 246537 added using faccess2(2) Linux syscall which supports the flags
directly. For older kernels, though, the syscall is not available, and
the code uses glibc-like fallback.

There is one very specific scenario in which the fallback fails.
The scenario involves all these conditions:
 - no faccessat2 support available (i.e. either Linux kernel < 5.8,
   or a seccomp set up to disable faccessat2);
 - the current user is not root (i.e. geteuid() != 0);
 - CAP_DAC_OVERRIDE capability is set for the current process;
 - the file to be executed does not have executable permission
   bit set for either the current EUID or EGID;
 - the file to be executed have at least one executable bit set.

Unfortunately, this set of conditions was observed in the wild -- a
container run as a non-root user with the binary file owned by root with
executable permission set for a user only [1]. Essentially it means it
is not as rare as it may seem.

Now, CAP_DAC_OVERRIDE essentially makes the kernel bypass most of the
checks, so execve(2) and friends work the same was as for root user,
i.e. if at least one executable bit it set, the permission to execute
is granted (see generic_permission() function in the Linux kernel).

Modify the code to check for CAP_DAC_OVERRIDE and mimic the kernel
behavior for permission checks.

This is essentially the same fix as CL 468735 for Go syscall package.

Tested on CentOS 7 with the repro similar to the one from [2].

[1] https://github.com/opencontainers/runc/issues/3715
[2] https://github.com/golang/go/issues/58552#issuecomment-1432505621

Change-Id: I726b6acab6a6e6d0358ef98e6a582b405c347614
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Reviewed-on: https://go-review.googlesource.com/c/sys/+/468877
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-02-17 22:21:29 +00:00
James Clark
c3037ed066 unix: add support for clock_adjtime on Linux
This provides a ClockAdjtime function providing access to the clock_adjtime system call on Linux.
The clock_adjtime system call is like adjtimex, but takes a clockid_t as its first argument.
The unix package already provides Adjtimex and the associated Timex struct; it also provides
the other functions that take a clockid_t (like ClockGettime). ClockAdjtime is an essential
system call for programs that want to use the Linux PTP hardware clock infrastructure (see
https://docs.kernel.org/driver-api/ptp.html).

Fixes golang/go#57618

Change-Id: I68d022425eb9cd394a204ad7fedab985c0496fee
Reviewed-on: https://go-review.googlesource.com/c/sys/+/463056
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-01-27 19:11:10 +00:00
Russ Cox
17fce3ac51 unix: avoid false positive in vet shift check
A uint64 >> 64 is reported as a mistake by the vet shift check.
This is arguably a bug in vet, but we can't fix the old releases,
so work around it.

Works around golang/go#58030.

Change-Id: Ic6b9ee2eb4bf01c77d9f7fcedb35562f733fce60
Reviewed-on: https://go-review.googlesource.com/c/sys/+/463675
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-01-27 01:02:48 +00:00
Eric Lagergren
3b1fc93fc1 unix: avoid allocations for common uses of Readv, Writev, etc.
Fixes golang/go#57296

Change-Id: Ifd57487122a590df467e97e2d35f388a58cc080d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/457815
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2022-12-21 03:31:56 +00:00
Eric Lagergren
72f772c4d7 unix: offs2lohi should shift by bits, not bytes
Fixes golang/go#57291

Change-Id: I212ab8a9f47563d9c124a0f20c17df35d7aa8e6d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/457315
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
2022-12-15 14:26:47 +00:00
Ian Lance Taylor
5726498127 unix: in Linux sendmsgN actually send one normal byte
A bug in CL 412497 caused us to set up an iovec for a dummy byte
but fail to use it

Fixes golang/go#56384

Change-Id: If56fea5c47e5c6fac92f9707d4c3dd78f7999a65
Reviewed-on: https://go-review.googlesource.com/c/sys/+/445255
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-10-25 17:44:04 +00:00
Tobias Klauser
f11e5e49a4 unix: use unsafe.Slice in (*FileHandle).Bytes
Change-Id: Ic2b88577ec6fd975bbba0538790d2ff312d85d3f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/435776
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-09-28 14:01:12 +00:00
Lorenz Bauer
d9d178bc13 unix: add PthreadSigmask for Linux
Add a syscall wrapper for SYS_RT_SIGPROCMASK and export it as
PthreadSigmask. The latter is defined by POSIX and can therefore
be implemented by Darwin, etc. later on.

Follow the approach used by Signalfd of passing _C__NSIG/8 as
sigsetsize. This avoids exporting _C__NSIG and allows the syscall
to work with the current definition of Sigset_t, which doesn't
match the kernel definition of Sigset_t.

Updates golang/go#55349

Change-Id: I49dc93366a7d316d820b0c25ecdef2ebb584634b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/435095
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-09-27 17:03:52 +00:00
Mateusz Poliwczak
d0df966e69 unix: support all Setuid/Setgid and related syscalls on Linux
Fixes golang/go#53444

Change-Id: I284e85f954f1646f7026478987db74993ae06d4a
GitHub-Last-Rev: 490f814484
GitHub-Pull-Request: golang/sys#134
Reviewed-on: https://go-review.googlesource.com/c/sys/+/428174
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-09-06 16:55:34 +00:00
Tobias Klauser
d48e67d002 unix: use strconv.Itoa instead of local implementation
This was originally copied over from package syscall where it was
replaced by internal/itoa in CL 301549.

For golang.org/x/sys/unix we may import strconv, so use strconv.Itoa
instead.

Change-Id: Iac125fbd0f64c385f9f0c02d4a7af762364b67aa
Reviewed-on: https://go-review.googlesource.com/c/sys/+/425304
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2022-08-29 20:07:55 +00:00
Tobias Klauser
a90be44021 unix: fix sendmsgN return value for empty iovecs and non-empty oob
Don't shadow the empty var when determining whether to send a single
byte when iovecs are empty but oob is non-empty. This will lead to the
n value correctly being reset to 0 before return.

No test because it's not possible to trigger this case on all platforms,
e.g. darwin where sendmsg with empty buf and non-empty oob returns
EINVAL.

This was introduced by CL 412497 and CL 419396.

Updates golang/go#52885

Change-Id: Iafc5a4b22e10b396ba5f7d4f2ac1c50df195a125
Reviewed-on: https://go-review.googlesource.com/c/sys/+/419914
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Florian Lehner <lehner.florian86@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-07-31 17:44:39 +00:00
Ian Lance Taylor
87e55d7148 unix: add RecvmsgBuffers and SendmsgBuffers
Fixes golang/go#52885

Change-Id: I04b5be1ac9543a3791ebc4cd59b9e35e958e0ba2
Reviewed-on: https://go-review.googlesource.com/c/sys/+/412497
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-06-24 22:08:33 +00:00
Russ Cox
b5fbb4746d all: gofmt
Gofmt to update doc comments to the new formatting.

For golang/go#51082.

Change-Id: I9a1c4b671c06820a1c383ee515f7884965fefa54
Reviewed-on: https://go-review.googlesource.com/c/sys/+/399602
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
2022-04-29 23:34:32 +00:00
Damien Neil
33da011f77 unix: check correct group in Faccessat
The Faccessat call checks the user, group, or other permission bits of a
file to see if the calling process can access it. The test to see if the
group permissions should be used was made with the wrong group id, using
the process's group id rather than the file's group id. Fix this to use
the correct group id.

This change only affects Linux versions prior to 5.8. Linux 5.8 added
the faccessat2 system call, which we use in preference to the internal
implementation.

No test since we cannot easily change file permissions when not running
as root and the test is meaningless if running as root.

For golang/go#52313

Change-Id: I6fa64379a50c9380207eab9d095ef7fbd05a2d59
Reviewed-on: https://go-review.googlesource.com/c/sys/+/400074
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-04-12 21:12:40 +00:00
Alexey Perevalov
889880a91f unix: fsmount fspick fsopen linux syscall
Patches were submitted to Linux manpages:
https://lwn.net/Articles/802096/, but not yet applied.
Generated on linux kernel v5.16.

Fsconfig couldn't implemented by generator, it requires
special cases handling.

Change-Id: I7f9560f4bc5b4bbe1e00c63ce1bc25c781aa1293
Reviewed-on: https://go-review.googlesource.com/c/sys/+/398434
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2022-04-12 07:17:39 +00:00
Alexey Perevalov
289d7a0edf unix: add MoveMount syscall on linux
This syscall is not yet described in linux man pages
(https://github.com/mkerrisk/man-pages.git),
but it was submitted to lkml https://lwn.net/Articles/802095/
This syscall appeared in linux v5.2.

Change-Id: I0708bfceda8d7a7608d0d0e75e36c3d81302dedb
Reviewed-on: https://go-review.googlesource.com/c/sys/+/397095
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2022-04-06 15:52:45 +00:00
Alexey Perevalov
483a9cbc67 unix: add OpenTree on linux
This syscall is not yet described in linux man pages
(https://github.com/mkerrisk/man-pages.git)
but it was attempts to do it (https://lwn.net/Articles/829496/)
This syscall appeared in linux kernel v5.2

Change-Id: If44aa74c4ddd200831011c6c4bf4bd4fee440785
Reviewed-on: https://go-review.googlesource.com/c/sys/+/397094
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-03 02:05:50 +00:00
Matt Layher
36772127a2 unix: implement Waitid on Linux
waitid(2) can be used to wait on pidfds. Update TestPidfd to test this new
functionality as well.

Change-Id: I5f26140b9afd5a6ec3f04217fb1c91542936a2c3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/395936
Trust: Matt Layher <mdlayher@gmail.com>
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2022-03-25 20:38:50 +00:00
Matt Layher
a9b59b0215 unix: add PidfdSendSignal on Linux
This completes the pidfd_* family of syscalls and adds a test to verify that a
child process can be terminated using the new PidfdSendSignal function.

Change-Id: I71f6a1e26518f513731e20afef02030462e9a2c0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/393794
Trust: Matt Layher <mdlayher@gmail.com>
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-19 13:42:39 +00:00
Tobias Klauser
51cd9980da unix: unify Recvmsg epilogues
Follow CL 361258 which did the same in package syscall.

Change-Id: I721406286d84ec999978e7e1ea25b6a2b3e195e6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/393294
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-17 06:15:10 +00:00
Tobias Klauser
22a226b3d1 unix: unify Sendmsg prologues
Follow CL 361256 which did the same in package syscall.

Change-Id: Ifd22e515c220806f02400baded821ec583959d78
Reviewed-on: https://go-review.googlesource.com/c/sys/+/393274
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-17 06:14:57 +00:00
Kir Kolyshkin
0005352912 unix: Getwd: ensure returned path is absolute
Since Linux kernel 2.6.36, the pathname returned by the getcwd() system
call can be prefixed with the string "(unreachable)" in some cases [1].

Getcwd should return an absolute path, and doing otherwise is a
conformance issue; it also can be dangerous, since the path returned
can be an existing relative path.

Fix by returning ENOENT in case the path is not absolute. This is
essentially the same as what glibc does (since [2]).

[1] https://man7.org/linux/man-pages/man2/getcwd.2.html#BUGS
[2] https://sourceware.org/git/?p=glibc.git;a=commit;h=52a713fdd0a30e1bd79818e2e3c4ab44ddca1a94

Change-Id: I6c48e7ec9b53be348138e3d974d3f11401c7bea6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/387194
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
2022-02-22 17:22:38 +00:00
Matt Layher
3681064d51 unix: implement getitimer(2) and setitimer(2) on Linux
Wrap the low-level system calls with a more idiomatic Go API and a set of
constants to indicate which timer should be queried or modified.

man 2 getitimer indicates that these system calls are obsolete as of
POSIX.1-2008, but the code I am working on has not been ported to the modern
timer_gettime(2) and timer_settime(2) APIs as of yet.

Change-Id: I91482e141047846cadf47aa2417b8770955986bf
Reviewed-on: https://go-review.googlesource.com/c/sys/+/384054
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Matt Layher <mdlayher@gmail.com>
2022-02-09 21:45:40 +00:00