Commit Graph

1483 Commits

Author SHA1 Message Date
Bryan C. Mills
ca59edaa5a windows: use unsafe.Add instead of pointer arithmetic on a uintptr
The existing uintptr arithmetic is arguably valid because the
environment block is not located within the Go heap
(see golang/go#58625).

However, unsafe.Add (added in Go 1.17) expresses the same logic with
fewer conversions, and in addition avoids triggering the unsafeptr
vet check.

For golang/go#41205.

Change-Id: Ifc509279a13fd707be570908ec779d8518b4f75b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/492415
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
v0.8.0
2023-05-03 21:21:24 +00:00
Alex Brainman
6c5289959c windows: return error if DecomposeCommandLine parameter contains NUL
DecomposeCommandLine is documented to use CommandLineToArgv, and the
CommandLineToArgvW system call inherently does not support strings with
internal NUL bytes. This CL changes DecomposeCommandLine to reject those
strings with an error instead of panicking.

Fixes golang/go#58817

Change-Id: I22a026bf2e69344a21f04849c50ba19b6e7b2007
Reviewed-on: https://go-review.googlesource.com/c/sys/+/487695
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
2023-04-25 08:07:06 +00:00
Craig Davison
9524d496ef windows/svc/mgr: Service.Control: populate Status when returning certain errors
Fixes golang/go#59015

Change-Id: I45f22049f3a05f807f78d20c9ed67c6c79e3d3c1
GitHub-Last-Rev: 929aeb4acb
GitHub-Pull-Request: golang/sys#156
Reviewed-on: https://go-review.googlesource.com/c/sys/+/484895
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-25 08:02:03 +00:00
Tobias Klauser
2a33a30b79 execabs: let hasExec return false on wasip1
Wasm cannot execute processes. Follow CL 479622 and update hasExec to
match internal/testenv.HasExec.

Updates golang/go#58141

Change-Id: Ie44dc356ee589784c44906694fda387fb1448ad5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/485655
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: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-04-18 17:08:16 +00:00
Tobias Klauser
39c2d6a01d unix: add UDP socket option constants on linux
Change-Id: I4c947319f98754a5135b306d8ff042a986ab5440
Reviewed-on: https://go-review.googlesource.com/c/sys/+/484637
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
2023-04-14 20:11:08 +00:00
Tobias Klauser
1fb6828e5b unix: convert Iovec.Base to *byte in mkpost.go on solaris
Instead of defining a dedicated type goIovec with the correct *byte type
for its Base field like CL 412496 did, modify the Base field of the
original type Iovec (generated from struct iovec) in mkpost.go. This is
akin to how we already change []int8 to []byte for several other types.

Fixes golang/go#55997

Change-Id: If30799bb2bfe6d17678370b45348ff0b7c5de2e9
Reviewed-on: https://go-review.googlesource.com/c/sys/+/484635
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-04-14 16:57:27 +00:00
Tobias Klauser
3125361ba6 unix: allow overriding GOOS using GOOS_TARGET in mkpost.go
mkpost.go is platform independent and can in principle be run on a GOOS
other than the one we're generating the syscall wrappers for. Allow
overriding GOOS by setting GOOS_TARGET, similar to other generator
programs in the repo. This e.g. allows testing mkpost.go changes on a
different GOOS.

Follows CL 256278 which did the same for mksyscall.go

Change-Id: Ib99aa5cd266f7d27543cf9433cfb028f367eef63
Reviewed-on: https://go-review.googlesource.com/c/sys/+/484636
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
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: David Chase <drchase@google.com>
2023-04-14 16:29:20 +00:00
Sebastian Soto
dbd8f99a5e windows: add Service.ListDependentServices
This method allows a user to list all Windows services which are
dependent upon a given service.

This commit makes use of the EnumDependentServices Windows API call.
Without this, a user would have to iterate through each service on the
system, and check if the given service is listed in each service's
dependencies list.

The implementation of ListDependentServices is mostly the same as
Mgr.ListServices, as the API calls behave in the same way.

Fixes golang/go#56766

Change-Id: I9ec18c97afd02f48deef691ccdd5c26d6501add1
Reviewed-on: https://go-review.googlesource.com/c/sys/+/451363
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2023-04-14 09:16:30 +00:00
masshash
f25ff604a2 windows: add JobObjectInformationClass consts for QueryInformationJobObject
Reference:
https://learn.microsoft.com/en-us/windows/win32/api/jobapi2/nf-jobapi2-queryinformationjobobject#parameters

Change-Id: I0d10895ffc18b345f371cc7e0cbf8362fd67f71a
GitHub-Last-Rev: 28163917a0
GitHub-Pull-Request: golang/sys#154
Reviewed-on: https://go-review.googlesource.com/c/sys/+/481455
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-10 20:17:12 +00:00
Ed Schouten
64840c112d unix: add bindings for setattrlist() on macOS
The setattrlist() function can be used to mutate the attributes of files through a single call. For example, one can perform a chmod(), chown(), chflags(), [...] all at once.

This change also adds bindings for the UF_* and SF_* flags that are accepted by chflags(). This makes it possible to use setattrlist() to perform the equivalent of lchflags(), for which we currently have no binding.

Change-Id: Ib5a604503a984b95a02b65ad1a437246cd170584
GitHub-Last-Rev: 45dd9d475a
GitHub-Pull-Request: golang/sys#155
Reviewed-on: https://go-review.googlesource.com/c/sys/+/481815
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
v0.7.0
2023-04-04 14:21:21 +00:00
Mikołaj Kuranowski
90abad3705 unix: add AT_EACCESS on Darwin
The AT_EACCESS constant, used by faccessat syscall is present on Linux, Solaris and other BSD platforms. This commit also adds this constant on Darwin.

The constant (and the associated faccessat syscall) is part of POSIX.1-2008.

Fixes golang/go#59265.

Change-Id: Iae0ac35107cc291eba523cc88e68d3a9ddb7d01e
GitHub-Last-Rev: a6a16c4471
GitHub-Pull-Request: golang/sys#153
Reviewed-on: https://go-review.googlesource.com/c/sys/+/480115
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-04-03 14:25:53 +00:00
masshash
94933fc7d0 windows: fix constant values for JobObjectInformationClass
The constant values were incorrect and has been fixed in this CL.

Reference:
https://learn.microsoft.com/en-us/windows/win32/api/jobapi2/nf-jobapi2-setinformationjobobject#parameters

Change-Id: Id97e561b6838a18216617d86aa11c79b6b2f4095
GitHub-Last-Rev: cd1e32d2de
GitHub-Pull-Request: golang/sys#150
Reviewed-on: https://go-review.googlesource.com/c/sys/+/479375
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-03-29 21:53:09 +00:00
Jason A. Donenfeld
00d8004a14 unix: match ioctl req argument type to libc type
On Solaris, AIX, and zOS, the req argument of ioctl() is a signed int,
not an unsigned long like on other platforms, which means many constants
are negative, causing friction when passing them to a uint argument.
Correct the signature of these functions to pass the req argument as
signed, just like libc.

Fixes golang/go#59030.

Change-Id: Ia14e92a150f4b5fb9488c5032ca296cb786e9811
Reviewed-on: https://go-review.googlesource.com/c/sys/+/476515
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Nahum Shalman <nahamu@gmail.com>
2023-03-17 00:07:53 +00:00
Nahum Shalman
d0781cc69b unix: make solaris syscall tests less flaky
Fixes golang/go#58259

Change-Id: I1e8a83ed6ee3be8165c771b81a3cbdd474216c02
Reviewed-on: https://go-review.googlesource.com/c/sys/+/465055
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-03-16 22:08:31 +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
Meng Zhuo
494aa493cc unix: skip ip related tests if EAFNOSUPPORT raised
Skipping EADDRNOTAVAIL is not enough for system doesn't support
ipv4/ipv6 family.
This CL skips TestPktInfo and TestParseOrigDstAddr if EAFNOSUPPORT
raised.

Fixes golang/go#58832

Change-Id: Icf74749f9cc0f9a6d60646f92f7ddf53ae2de8ab
Reviewed-on: https://go-review.googlesource.com/c/sys/+/473257
Run-TryBot: M Zhuo <mzh@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-03-04 19:08:18 +00:00
Francis Laniel
c7a1bf9a0b unix: define PerfBitWriteBackward
Change-Id: I0b95006039b4efcd0094ba96281100abeafc993e
GitHub-Last-Rev: 43383aac90
GitHub-Pull-Request: golang/sys#149
Reviewed-on: https://go-review.googlesource.com/c/sys/+/473135
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
v0.6.0
2023-03-04 03:20:52 +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
c10701f35e windows: use unsafe.Slice in (*RawSockaddrAny).Sockaddr on windows
Same as CL 472035 did in package syscall.

Change-Id: I153dfaa19933a2707848e4183d6ca704c2800a0e
Reviewed-on: https://go-review.googlesource.com/c/sys/+/472016
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-28 18:47:45 +00:00
Will Hawkins
6f250766ac unix: define extended TCPInfo on Linux
On Linux platforms, the kernel can fill out an extended version of
the tcp_info struct. Allow users of the sys package to have access to
that information.

Change-Id: Ib42ad572dd56c774c6d9e8b17fe3bdd8126147bb
Reviewed-on: https://go-review.googlesource.com/c/sys/+/471275
Run-TryBot: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Matt Layher <mdlayher@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: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-02-28 17:07:46 +00:00
Dmitri Goutnik
10499f4574 unix: add ioctlPtr with unsafe.Pointer arg on other unices (cont)
CL 469315 missed a few conversions, this CL adds them. While
here, also update syscall wrapper generators.

For golang/go#44834

Change-Id: I4418a8c177ee6d1a269c1cc2c806b199dc7ccf0b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/471119
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-02-24 21:46:34 +00:00
Dmitri Goutnik
92c4c39f76 unix: add Dup3 on FreeBSD
Other BSDs provide dup3(2) syscall, on FreeBSD it is implemented as libc
function using fcntl(2). This CL adds similar Go implementation.

Fixes golang/go#55935

Change-Id: I9c6d762415c7bed5442966a7fcbf9a6f8dfdaf2a
Reviewed-on: https://go-review.googlesource.com/c/sys/+/470675
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-02-24 13:20:54 +00:00
Tobias Klauser
748af6eb5d unix: pass PROT_MPROTECT(PROT_READ|PROT_WRITE) to initial Mmap on netbsd
On NetBSD PAX mprotect prohibits setting protection bits
missing from the original mmap call unless explicitly
requested with PROT_MPROTECT.

Fixes golang/go#58660

Change-Id: I1e97e920bc617ed1674855adaae5047638a30394
Reviewed-on: https://go-review.googlesource.com/c/sys/+/470775
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-02-23 17:06:30 +00:00
Tobias Klauser
972870e3e1 unix/linux: update to Linux kernel 6.2, glibc 2.37 and Go 1.20.1
Also remove some manually defined AT_* contstants which are now defined
in the libc headers.

Change-Id: I342976a22948e9b05e38dc7503d9dd356cee6c7b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/470176
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2023-02-23 15:22:10 +00:00
Dmitri Goutnik
cc0b67d799 unix: use C.ioctl in generated ioctlPtr
Changes made in CL 469315 broke aix syscall wrapper generaton by
generating a wrapper for a non-existent C.ioctl_ptr() function.

Change-Id: Iaeee3056480637c62a09ea61e2ec14793c59790a
Reviewed-on: https://go-review.googlesource.com/c/sys/+/470235
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com>
2023-02-22 19:20:54 +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
Jordan Whited
71a906ea0c unix/linux: add TUN flags and virtio_net_hdr constants
Change-Id: I10c86c100f4db77740eff6f07d91d6489b21b6f8
GitHub-Last-Rev: 3e8d7343cd
GitHub-Pull-Request: golang/sys#148
Reviewed-on: https://go-review.googlesource.com/c/sys/+/468656
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-22 15:47:51 +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
Ian Lance Taylor
6877dccfc2 execabs: don't override Go 1.19 error with our error
Go 1.19 incorporates the functionality of execabs directly.
If it has already reported an error, don't report our own error.

In particular Go 1.19 moved the error from lookPathErr to Err.
The code was already checking to not override lookPathErr.
With this change we also do not override Err.

Tested with Go 1.17 through Go 1.20.

Fixes golang/go#58606

Change-Id: I110127a3925f3800cc058d93e704604a59aa38f7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/469735
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-02-21 18:19:21 +00:00
Dmitri Goutnik
b13f40e221 unix: add ioctlPtr with unsafe.Pointer arg on other unices
This is a followup for CL 340915 that adds ioctlPtr for all other
UNIX-like platforms.

For golang/go#44834

Change-Id: I0ecf84e53f13e5a8da736b3ba7f643262596d23c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/469315
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-02-21 11:26:31 +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
Brad Fitzpatrick
2da1413846 cpu: get hwcap/auxv from the Go 1.21+ runtime
Depends on https://go.dev/cl/458256

This change only does Linux for now.

Updates golang/go#57336

Change-Id: I0659697c1bdc6e2577c6251b964a0df32047ee12
Reviewed-on: https://go-review.googlesource.com/c/sys/+/465295
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
2023-02-17 19:36:37 +00:00
PumpkinSeed
4fee21c923 windows: Add WSALookupService syscall wrappers
Create WSAQUERYSET struct, add LUP_XX constants,
implement wrappers around WSALookupService functions.

Fixes golang/go#54232

Change-Id: I26624df1b2b44cd8750350fe4526b806513913fe
Reviewed-on: https://go-review.googlesource.com/c/sys/+/461296
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2023-02-08 14:13:08 +00:00
Bryan C. Mills
c79a742fd1 unix: fix a use-after-free bug in PtraceIO on freebsd
In CL 419915, both pointer fields of the PtraceIoDesc struct were
converted to type uintptr to address golang/go#54113.

However, that change was overzealous: the fix needed to convert fields
that refer to addresses in the child process, but the Addr field of
PtraceIoDesc is not even in the child process! It is instead an
address in the parent (Go) process.

Go's unsafe.Pointer rules prohibit converting a Go pointer to a
uintptr except when immediately converting back to an unsafe.Pointer
or calling a system call. Populating a PtraceIoDesc struct is neither
of those things, so converting the Addr field to uintptr introduced a
use-after-free bug.

This change reverts the change to the Addr field from CL 419915 and
consolidates the implementation of PtraceIO to reduce the the amount
of code that varies with GOARCH.

This change does not address the remaining ptrace uintptr bug
(golang/go#58387), which is also present in the Linux implementation.

Fixes golang/go#58351.
Updates golang/go#54113.
For golang/go#41205.

Change-Id: I14bdb4af42130aa7b4375e3f53fd1a0435f14307
Reviewed-on: https://go-review.googlesource.com/c/sys/+/465676
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-08 01:11:03 +00:00
Bryan C. Mills
90c8f94a05 unix: avoid converting non-pointers to unsafe.Pointer in PtraceIO
Despite having the misleading type "void*" in the C API, the "offs"
field of the ptrace_io_desc struct is an offset within the child
process, and thus is not necessarily a valid pointer at all in the
parent process. The Go unsafe.Pointer type must refer only to valid
pointers, so converting this field through unsafe.Pointer is incorrect
and (in some cases) dangerous.

While we're here, let's also rename the "addr" function argument to
"offs", since that's the corresponding ptrace_io_desc field. It's very
confusing to have a function argument named "attr" that doesn't map to
the struct field of the same name!

For golang/go#58351.

Change-Id: Id899f823e8d398b51fb0c42f466d7ae2f957c26b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/465675
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
v0.5.0
2023-02-07 00:05:19 +00:00
Bryan C. Mills
4e121b1efb unix: add missing address operator in initxattrdest
The purpose of the _zero variable is to provide a valid address for a
pointer to an array of length zero. All other uses of the variable
take its address, but one reference to it (added in CL 147850043)
converts the variable (which has type uintptr) directly to an
unsafe.Pointer, producing a nil pointer instead of a non-nil pointer
to a zero-length array.

This typo is caught by 'go vet', but was masked for a long time by the
numerous false-positive warnings for the same check (#41205).

For golang/go#41205.

Change-Id: Ib3bebfadc6fc5574db19630169ff3f65da857bdd
Reviewed-on: https://go-review.googlesource.com/c/sys/+/465597
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
2023-02-06 18:23:25 +00:00
Bryan C. Mills
68f9dcb1f9 windows/debug/svc: buffer channel passed to signal.Notify
The os/signal package drops signal notifications if the channel is not
ready to receive immediately. To avoid dropping signals (for example,
while processing the other branch of a 'select'), the channel must be
buffered.

This fixes a mistake flagged by 'go vet ./...'.

Change-Id: I2a20dbe2aa27ae8ec009fff5e7be47e4409fdddd
Reviewed-on: https://go-review.googlesource.com/c/sys/+/465595
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-06 18:23:23 +00:00
Tom Thorogood
0e1262c88a unix: add ptrace(PT_DENY_ATTACH) wrapper for darwin
Change-Id: I13e4426e6e411ceb449539479d9bcee15a518cf6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/464655
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2023-02-03 18:20:27 +00:00
James Clark
6938dae65e unix: add missing constants used with struct Timex on Linux
This provides definitions for Linux of two groups of constants,
which are used with struct Timex (used with the adjtimex and
clock_adjtime system calls): the ADJ_* constants are used
for the modes field; the STA_* constants are used for the status
field. The constants are documented in the adjtimex(2) man page.

Fixes golang/go#58012

Change-Id: I054f0c40f9cfd9360a0bb10716a08e19584c0fff
Reviewed-on: https://go-review.googlesource.com/c/sys/+/464241
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2023-02-02 22:29:28 +00:00
Nahum Shalman
01b330b26f unix: improve flaky solaris test logging
relates to golang/go#58259

Change-Id: I47bbf4afb59b6e98571297ba53d7f9370712e030
Reviewed-on: https://go-review.googlesource.com/c/sys/+/465015
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-02-02 22:24:17 +00:00
cui fliter
e7d7f63158 all: fix some comments
Change-Id: I7d5bfd4caac63820b26fc3408118c13e74e6448c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/464238
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-31 16:01:37 +00:00
chenguoqi
7a75290698 unix/linux: update to glibc 2.36
Support for LoongArch has been merged upstream. This allows to
drop the loong64 specific glibc patches.

Because the header file sys/mount.h of glibc 2.36 includes fcntl.h
(commit 78a408ee7ba041fc8d5dbd5f67065b4a982c11e5), this will leads to
duplicate definition of structure stat on MIPS64.  In order to solve
this error, use the custom type my_stat to generate the Go Stat_t.

Change-Id: I888280d777d1c7089548acf1b3821762011d79b0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/453555
Reviewed-by: xiaodong liu <teaofmoli@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-01-31 14:54:23 +00:00
Davis Goodin
4112509618 windows/mkwinsyscall: write source to temp file if formatting fails
This change writes the unformatted Go source code to a temp file if
"format.Source" fails. Print the temp file path to the console to make
it easy to find. The source code is what causes formatting errors, and
it can be difficult to diagnose them without this context.

Fixes golang/go#57925

Change-Id: Ifa4d8a6e8bc5006357b0bc88afce5ba1d6fe0a48
Reviewed-on: https://go-review.googlesource.com/c/sys/+/463216
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-01-30 22:21:04 +00:00
Davis Goodin
71da690494 windows/mkwinsyscall: support "." and "-" in DLL name
This change adds "." and "-" support for DLL filenames in "//sys".

Supporting "." requires a change in how mkwinsyscall handles the
"= <filename>.<function>" syntax. Instead of assuming that only one "."
can appear in this string, now mkwinsyscall assumes that any additional
"." belongs to the filename.

Supporting "." also requires changing how Go identifiers are created for
each DLL. This change also allows mkwinsyscall to support "-". When
creating a Go identifier, "." and "-" in the DLL filename are replaced
with "_". Otherwise, mkwinsyscall would produce invalid Go code, causing
"format.Source" to fail.

Includes a test for the new behavior. There aren't yet any cases where
this code is executed while generating the x/sys/windows syscalls. The
syscalls "SetSocketMediaStreamingMode" from "windows.networking.dll" and
"WslRegisterDistribution" from "api-ms-win-wsl-api-l1-1-0.dll" can be
successfully called using this change, but these syscalls have no known
use in Go so they are not included in this change.

Fixes golang/go#57913

Change-Id: If64deeb8c7738d61520e7392fd2d81ef8920f08d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/463215
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-01-30 19:10:05 +00:00
chenguoqi
b829a39df5 unix/linux: update to gcc 13.0.0, qemu 7.1.0 for loong64
No changes in generated files.

Update loongarch64-linux-gcc to 13.0.0
- The kernel header file version is upgraded to 5.19

Update qemu-loongarch64 to 7.1.0
- Support for LoongArch has been merged upstream.

Change-Id: I637925fd9e5575dfb4ce91ece98951d5bf3053e6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/453458
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: xiaodong liu <teaofmoli@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-01-30 18:37:20 +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
Tobias Klauser
13fe000ef0 cpu: add IsBigEndian
Copy the definition of x/sys/unix.isBigEndian to x/sys/cpu.

Updates golang/go#57237

Change-Id: Iefbf4303720445611de93b0a3ea365f8208c033b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/463335
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2023-01-27 13:35:52 +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
qmuntal
a6f4650873 windows: use UTF16FromString and UTF16ToString from syscall
This CL updates the windows.UTF16FromString and windows.UTF16ToString
implementation so they forward to their syscall counterparts.

The standard library uses these particular syscall functions across
the board as it can't depend on x/sys. This means that even if the
syscall API is frozen, the implementation still receives improvements
and bug fixes, such as CL 425054.

Porting CL 425054 to x/sys is possible, but for this particular case
I think it's better to just call the syscall package. This way both
repos will benefit from future improvements (which I plan to do soon).

Change-Id: I305c4409142d79a57008d7e6d0717fb8986fe906
Reviewed-on: https://go-review.googlesource.com/c/sys/+/462875
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2023-01-20 18:56:19 +00:00