Commit Graph

1160 Commits

Author SHA1 Message Date
Tobias Klauser
46babdb380 unix: add flags to SockaddrVM
The Flags member was added to struct sockaddr_vm in Linux kernel 5.11
and successively into RawSockaddrVM when updating to that kernel version
in CL 291637. Add the flags to SockaddrVM as well.

While at it, also update the list of CID values with VMADDR_CID_LOCAL.

Change-Id: I08828136f4c5ded3cca2fd07aefac066b9977b13
Reviewed-on: https://go-review.googlesource.com/c/sys/+/308990
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-04-12 22:03:33 +00:00
Jason A. Donenfeld
5e06dd20ab windows: ensure SECURITY_DESCRIPTOR allocation is large enough
Self-relative security descriptors can sometimes be smaller than the
header size of the SECURITY_DESCRIPTOR struct, which is fine in C, but
checkptr complains about it, so instead, ensure that the allocation is
at least the size of the SECURITY_DESCRIPTOR struct.

This fixes this splat:

fatal error: checkptr: converted pointer straddles multiple allocations

goroutine 36 [running]:
runtime.throw(0x761c5f, 0x3a)
        /usr/lib/go/src/runtime/panic.go:1117 +0x79 fp=0xc00005dd90 sp=0xc00005dd60 pc=0x5fb8d9
runtime.checkptrAlignment(0xc0001a4020, 0x741860, 0x1)
        /usr/lib/go/src/runtime/checkptr.go:20 +0xc9 fp=0xc00005ddc0 sp=0xc00005dd90 pc=0x5c7729
golang.org/x/sys/windows.(*SECURITY_DESCRIPTOR).copySelfRelativeSecurityDescriptor(0x1b9ad638190, 0x2)
        /home/zx2c4/Projects/golang-dev/sys/windows/security_windows.go:1359 +0x1b7 fp=0xc00005de50 sp=0xc00005ddc0 pc=0x6f0077
golang.org/x/sys/windows.SecurityDescriptorFromString(0x754f2b, 0x2, 0x0, 0x0, 0x0)
        /home/zx2c4/Projects/golang-dev/sys/windows/security_windows.go:1371 +0xde fp=0xc00005deb8 sp=0xc00005de50 pc=0x6f019e

Change-Id: I552017a93d4ca6f6debc6f8f445dac5c6717fed1
Reviewed-on: https://go-review.googlesource.com/c/sys/+/307129
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2021-04-03 16:11:42 +00:00
Jason A. Donenfeld
700132347e windows: allocate SECURITY_DESCRIPTOR with uintptr alignment
This struct has pointers in it, which means checkptr expects for it to
be aligned properly. When we're copying a Windows-allocated struct to a
Go-allocated one, make sure that the Go allocation is aligned to the
pointer size.

This fixes the following checkptr splat:

goroutine 29 [running]:
runtime.throw(0x4f8dd9, 0x3a)
	C:/hostedtoolcache/windows/go/1.16.2/x64/src/runtime/panic.go:1117 +0x79 fp=0xc000041c50 sp=0xc000041c20 pc=0x2f9879
runtime.checkptrAlignment(0xc00009c180, 0x4d8a00, 0x1)
	C:/hostedtoolcache/windows/go/1.16.2/x64/src/runtime/checkptr.go:20 +0xc9 fp=0xc000041c80 sp=0xc000041c50 pc=0x2c4d09
golang.org/x/sys/windows.(*SECURITY_DESCRIPTOR).copySelfRelativeSecurityDescriptor(0x227284caa00, 0x2)
	C:/Users/runneradmin/go/pkg/mod/golang.org/x/sys@v0.0.0-20210309040221-94ec62e08169/windows/security_windows.go:1347 +0x11f fp=0xc000041ce8 sp=0xc000041c80 pc=0x467f9f
golang.org/x/sys/windows.SecurityDescriptorFromString(0x4ebfb0, 0x2, 0x0, 0x0, 0x0)

Change-Id: I7eb9c07e7afb7f139473b660f82a23541663ec50
Reviewed-on: https://go-review.googlesource.com/c/sys/+/306889
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2021-04-02 19:21:33 +00:00
Tobias Klauser
43e1dd70ce unix: add ICMP6_FILTER on solaris
Also add IP_RECVTOS and O_DIRECT which were generated when running
mkall.sh on SunOS openindiana 5.11.

The change in mkerrors.h is necessary to avoid lots of unnecessary
ICMP6_* consts being added on solaris.

Change-Id: Ica9a4b67f2d2d7916e65bcb600a5b2fa98edb80a
Reviewed-on: https://go-review.googlesource.com/c/sys/+/306249
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2021-03-31 17:51:45 +00:00
Tobias Klauser
4fbd30eecc unix: add MCAST_* consts on freebsd/arm
Change-Id: Iad1299fd440054c4522f0c7c96d2e0fb481685a6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/305810
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-30 21:06:17 +00:00
Tobias Klauser
9b9b09a01a unix: add ICMP6_FILTER on zos
Copied from golang.org/x/net/ipv6. This will allow to replace the
socket option constants in that package with constants from x/sys/unix.

Change-Id: I92a6ee9ffb4fbfcc66f1644b7677ac5bdf202367
Reviewed-on: https://go-review.googlesource.com/c/sys/+/305811
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-30 21:06:03 +00:00
Tobias Klauser
49726bf1d1 unix: add ICMPV6_FILTER_* consts on linux
Change-Id: If626dab3c708d78768ae593b7b3f8bff280ee641
Reviewed-on: https://go-review.googlesource.com/c/sys/+/305049
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-26 22:08:04 +00:00
Tobias Klauser
47abb65194 unix: add RFC3542 IPv6 socket option constants on darwin
Change-Id: I7056c1d8805c080e50d832b5d6a3e3323f692525
Reviewed-on: https://go-review.googlesource.com/c/sys/+/303929
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-24 05:16:08 +00:00
Tobias Klauser
1e4c9ba3b0 unix: add ICMP_FILTER constant on linux
Change-Id: I9ce0932c28ae8634270d69b0bd23216e963cc105
Reviewed-on: https://go-review.googlesource.com/c/sys/+/303369
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-20 14:08:29 +00:00
Nahum Shalman
635bc2c913 unix: add Getmsg and Putmsg on illumos
Change-Id: Id1f2a2797e56a45584f70ee5e9202647a595a031
Reviewed-on: https://go-review.googlesource.com/c/sys/+/302830
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Ian Lance Taylor <iant@golang.org>
2021-03-19 07:12:55 +00:00
Nahum Shalman
193893d61a unix: expose ioctl returns with ioctlRet on solaris and illumos
Change-Id: Ide2beea5182b3ef35f1f04f429dc8f9327457c8d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/302829
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: David Anderson <dave@natulte.net>
Trust: Ian Lance Taylor <iant@golang.org>
2021-03-19 07:07:19 +00:00
Hanlin He
c4fcb01b22 unix: fix setsockopt syscall arguments on linux/s390x
Pass vallen to setsockopt syscall.

Change-Id: Ibf5b2d8c1d48ac0966631f648de6d043feb53cc4
GitHub-Last-Rev: 70805e15eb
GitHub-Pull-Request: golang/sys#99
Reviewed-on: https://go-review.googlesource.com/c/sys/+/297969
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Ian Lance Taylor <iant@golang.org>
2021-03-17 22:57:23 +00:00
Nahum Shalman
390168757d unix: create types_illumos.go
create a new types_illumos.go for illumos specific constants
and structs, bring in those needed for wireguard-go

Change-Id: I68117abcae66127b617faea1f4cc2568b8b28d58
GitHub-Last-Rev: 3003e04e7e
GitHub-Pull-Request: golang/sys#100
Reviewed-on: https://go-review.googlesource.com/c/sys/+/301713
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2021-03-17 09:18:45 +00:00
Tobias Klauser
77fc1eacc6 unix: unify Syscall{,6,9} and RawSyscall{,6} on BSD
These all just jump to the respective implementation in package syscall.

Change-Id: Ie1c0438d983c8d78dc780487bb866760460f1ce1
Reviewed-on: https://go-review.googlesource.com/c/sys/+/301490
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-16 16:44:54 +00:00
Tobias Klauser
0b90fd5c4c unix/linux: update Dockerfile to Go 1.16.2
Change-Id: I263e0ed034ded3ef8cf9bd9745d9095067cc3a25
Reviewed-on: https://go-review.googlesource.com/c/sys/+/301689
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-16 09:29:37 +00:00
Tobias Klauser
c6e025ad80 windows: add IP_HDRINCL, IP_PKTINFO, IPV6_PKTINFO
These will be used to replace the respective local definitions in
the golang.org/x/net package.

Change-Id: Ieae8908a87ee7df1ca43683e7e921128bff90b8d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/301690
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-15 16:08:23 +00:00
Yaroslav Vorobiov
07df6a1414 unix: fix -d=checkptr slice failures on aix
Fix unsafe conversions to slices that are missing length or capacity.

Change-Id: I3a1f4d57e0884b647b4c3819ff014d09b87a1ce5
GitHub-Last-Rev: 9b6895a08d
GitHub-Pull-Request: golang/sys#66
Reviewed-on: https://go-review.googlesource.com/c/sys/+/225617
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Ian Lance Taylor <iant@golang.org>
2021-03-14 19:57:30 +00:00
Matt Layher
bd2e13477e unix: add NLMSGERR constants for netlink extended acknowledgement
Change-Id: I8d23fc227d1f61b823abcf610479005356c52088
Reviewed-on: https://go-review.googlesource.com/c/sys/+/286072
Trust: Matt Layher <mdlayher@gmail.com>
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2021-03-13 20:20:42 +00:00
Kir Kolyshkin
8e9fff1a3a unix: add CloseRange
The close_range(2) syscall is available since Linux kernel v5.9,
with additional functionality of CLOSE_RANGE_CLOEXEC since v5.11.

No tests are required since this is a bare syscall.

Change-Id: I410470e3713e2005cc7acf24d1347938fe05ef63
Reviewed-on: https://go-review.googlesource.com/c/sys/+/301409
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-13 11:07:37 +00:00
Tobias Klauser
68d13333fa unix: add //go:build lines when generating files
The //+go:build lines were added by running Go 1.17 gofmt in CL 294490.
Make sure to retain them when re-generating files in this package.

For golang/go#41184.

Change-Id: Ia418b8c0eb4291a0db3f4bb97685bde78d0ff016
Reviewed-on: https://go-review.googlesource.com/c/sys/+/296889
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-09 07:47:19 +00:00
Jason A. Donenfeld
94ec62e081 windows: add SetNamedPipeHandleState
I added GetNamedPipeHandleState before but forgot the setter function,
which winds up being useful for namedpipe's tests.

Change-Id: Iefeabb2ac9584ec15e18e2ae7e4a72fbb46cbe7c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/299209
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-09 04:02:21 +00:00
Tobias Klauser
88b6017d06 unix: don't fail TestPoll on EINTR from Poll
Occassionaly TestPoll fails on some builders due to Poll getting
interrupted:

--- FAIL: TestPoll (0.00s)
    syscall_unix_test.go:516: Poll: unexpected error: interrupted system call
FAIL
FAIL	golang.org/x/sys/unix	0.956s

Fix this by retrying Poll in case of EINTR, same as CL 207861 did in
TestSelect.

Change-Id: I78ada14d7409e6cde852d76abd5a9a1b1bb645d2
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298189
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Matt Layher <mdlayher@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2021-03-08 17:07:21 +00:00
Jason A. Donenfeld
8fe3ee5dd7 windows: return ERROR_ALREADY_EXIST for non-nil handle in Create* functions
These functions sometimes return a non-nil value, while indicating
ERROR_ALREADY_EXISTS through GetLastError. In this case, return the
error along with the handle, to indicate the case.

Fixes golang/go#44539.

Change-Id: Id18e64724e57f62a34d6562511d9eafa8e6f9a3e
Reviewed-on: https://go-review.googlesource.com/c/sys/+/297332
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2021-03-05 23:01:14 +00:00
Jason A. Donenfeld
5cdee2b1b5 windows: correct NT definitions and add more resolution
Alex pointed out that some of these original types were incomplete, so
this commit fills things out a bit more. We also add more to the test
case.

Change-Id: Iff7bd9ea6e0d021ba997c6d7351fe7c4a46187a9
Reviewed-on: https://go-review.googlesource.com/c/sys/+/299189
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-05 21:54:15 +00:00
Alex Brainman
d6cf4ab887 windows/svc: use ioutil.WriteFile instead of os.WriteFile
os.WriteFile is not available on Go 1.15. But we still need to
support Go 1.15.

Fixes broken Go 1.15 build

https://build.golang.org/log/07b89b007d0aca2e97bc01cdf4c6a1d90e6732f9

Change-Id: I18433985ec82477160058ef96c160345304ba1ad
Reviewed-on: https://go-review.googlesource.com/c/sys/+/299309
Trust: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-05 21:05:45 +00:00
Jason A. Donenfeld
7844c3c200 windows/svc: rewrite IsWindowsService
Alex copied this from a temporary thing I had written for the runtime
package. In runtime, you can't really access other packages like
syscall, so everything has to be very manual. But in x/sys, we can do
things properly. So this reimplements the function in a more straight
forward way.

Change-Id: I1634904bb1e10f33252954ce02d4b17ae56592e5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298830
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-05 03:40:16 +00:00
Jason A. Donenfeld
61f932b4c6 windows: add QueryFullProcessImageName
This will be useful for reworking the IsWindowsService function in
svc/.

Change-Id: Ie1f7a560d7e81ee4ac3055e04748b6f9c8234edb
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298829
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-05 03:01:59 +00:00
Jason A. Donenfeld
0d6cb8bd5a windows: add ole32 instantiation functions
These are basic functions for getting function pointers to instantiated
OLE objects.

Change-Id: I5a3d179d6da2af006b6e11def18280959bb9bd98
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298469
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-05 02:34:07 +00:00
Jason A. Donenfeld
f9bc61c02a windows: add resource extraction functions
These functions make it possible to read executable resource information
at runtime.

Change-Id: I00f260199ecda8daeb3417eaa9c02198663063b7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298173
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-05 02:33:59 +00:00
Jason A. Donenfeld
7b4935edff windows: add pipe creation win32 APIs
These remaining APIs will make it possible to implement a win32 pipe
library using x/sys/windows.

Change-Id: If0cacedb7857c013c03e15cb6330b474cc010581
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298172
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-04 20:38:40 +00:00
Jason A. Donenfeld
1243437a8e windows: add various NT APIs
In anticipation of the next commit which adds win32 pipe APIs, add some
of the foundational NT APIs for that, which will be required for making
a robust Go pipe library. Also add a simple test case.

Change-Id: I898bd6c5265a8939a7f05a24c4d9b22941dc56b7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298171
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-04 20:34:36 +00:00
Jason A. Donenfeld
444254391f windows: treat proc thread attribute lists as unsafe.Pointers
It turns out that the proc thread update function doesn't actually
allocate new memory for its arguments and instead just copies the
pointer values into the preallocated memory. Since we were allocating
that memory as []byte, the garbage collector didn't scan it for pointers
to Go allocations and freed them. We _could_ fix this by requiring that
all users of this use runtime.KeepAlive for everything they pass to the
update function, but that seems harder than necessary. Instead, we can
just do the allocation as []unsafe.Pointer, which means the GC can
operate as intended and not free these from beneath our feet. In order
to ensure this remains true, we also add a test for this.

Updates golang/go#44662.

Change-Id: Iaa8b694a6682cc1876879632c7ba068e47b8666d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/297331
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-03-04 19:59:27 +00:00
Jason A. Donenfeld
afaa3650a9 windows: do not write LastStatus parameter of TEB when converting errors
The prior function updated the TEB's LastStatus member, which is not
what we want to be doing here. It's also not consistent with Microsoft's
own Go code for their pipe library, which properly uses the "NoTeb"
variant like this commit.

For good measure, we add a simple test case to make sure these paths are
being exercised.

Change-Id: I4080898f704bdc93a6048001b06ffce516fb412d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298169
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-04 15:22:09 +00:00
Jason A. Donenfeld
50617c2ba1 windows/mkwinsyscall: use "windows." prefix when referring to NTStatus
All references to "Errno" go through the syscalldot function, which
prepends "syscall." if the generation target is not in the syscall
package. Similarly so, we need a windowsdot function to prepend
"windows." to NTStatus.

Change-Id: I86affcf0155632ed5848ebabca97d175a041c6c3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/298170
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-04 12:46:12 +00:00
Jason A. Donenfeld
78dc250343 windows/mkwinsyscall: deduplicate functions before printing variables
The same symbol name might be defined multiple times with different
function names or signatures. In that case, it's an error to redefine
the proc variable. So deduplicate these before printing.

Change-Id: I7a636cd44fb1ea6f51840ef3924d6316e266faa0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/288332
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-04 12:45:23 +00:00
Jason A. Donenfeld
134d130e1a windows: add support for NTSTATUS values
The native NT API returns error values from a different namespace as the
usual Win32 one. This means it needs to be typed differently. This
commit adds broad support for using NTSTATUS values in a new type called
NTStatus.

First we add the type as a basic uint32. Then we add all of the
predefined constants from ntstatus.h, by augmenting mkerrors.bash to do
automatic extraction. There's a convenece way to convert an NT error to
a Win32 error, so we add the NTStatus.Errno() function. Since NTStatus
is an error type, we define an Error() function that returns a string by
asking ntdll.dll for its contents, in the exact same way that
syscall.Errno.Error() does, by calling FormatMessage. Since functions
need to actually use this, we add the rule that if a `//sys` declaration
returns an error value called "ntstatus", then the type underlying the
error interface is an NTStatus instead of an Errno. Finally we fix one
function that was returning an error interface of an Errno rather than
an NTStatus.

Change-Id: I06296b9563bbec526759d12a19f13ac6ad46dcc3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/297330
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-03-03 07:41:36 +00:00
Jason A. Donenfeld
77cc2087c0 windows: refresh error constants to latest SDK errors
This is simply a re-run of mkerrors.bash with the newer Windows SDK.

Change-Id: I16077dce04e38ae23ffb938df1feed8fdadc96fa
Reviewed-on: https://go-review.googlesource.com/c/sys/+/297329
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2021-03-01 09:17:18 +00:00
Tobias Kohlbau
479acdf4ea windows: add support for CommTimeouts
CommTimeouts allows the user to set the timeout on Comm devices:

docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setcommtimeouts
docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getcommtimeouts

Change-Id: I756dc93b1b01412a496c6eccab22c9ff7e5f4b83
Reviewed-on: https://go-review.googlesource.com/c/sys/+/290209
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-02-28 01:22:17 +00:00
Alex Brainman
b0d1d43c01 windows/svc: make IsWindowsService handle parent exit
IsWindowsService fails when parent process has exited.

This change makes IsWindowsService return false instead.

Added a test to verify the change.

Change-Id: Ibb2aa9478e8afd9e35011bbdc0985bdf8f0af9cc
Reviewed-on: https://go-review.googlesource.com/c/sys/+/294729
TryBot-Result: Go Bot <gobot@golang.org>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
2021-02-27 04:07:30 +00:00
Jason A. Donenfeld
f36f78243c windows: add definitions and functions for ProcThreadAttributeList
The bulk of the documentation for these is in:

https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-updateprocthreadattribute

This allows creating processes from scratch that use advanced options,
such as changing the process parent.

Fixes golang/go#44005.

Change-Id: Id5cc5400541e57710b9e888cd37ef4f925d510fe
Reviewed-on: https://go-review.googlesource.com/c/sys/+/288412
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2021-02-26 18:17:00 +00:00
Tobias Klauser
a50acf3fe0 unix: fix IoctlFileDedupeRange test
The test introduced in CL 284352 breaks on several builders, either
with IoctlFileDedupeRange returning ENOTTY (as already seen for android
in the TryBot run) or returning EINVAL in the FileDedupeRange.Status
field. Both seem to indicate that the underlying filesystem doesn't
support deduplication, so skip the test in these cases.

Also rename the test to indicate the func it is testing.

Change-Id: I29553a5fc95f98335cb233f05d4c2dfb5640dc4c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/295911
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2021-02-25 13:49:36 +00:00
Tobias Klauser
4ada9433c6 unix: test nonblocking and close-on-exec behavior of Pipe2
Following TestNonblockingPipe in package runtime.

Change-Id: Ifacec3ea6ce372a891273e3ec9fa4194f7d17619
Reviewed-on: https://go-review.googlesource.com/c/sys/+/295869
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-25 09:19:47 +00:00
Tobias Klauser
2738c018e2 unix: fix Pipe2 on dragonfly
The pipe2 on dragonfly still expects an fds array as an argument, but
does not use it to return the file descriptors. Just pass the argument
but ignore its value. This way the flags argument will be respected
correctly.

Change-Id: Id340653040999f31074eae01e9be4ea2088abae5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/295870
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-25 09:19:36 +00:00
Lluís Batlle i Rossell
8e9945a547 unix: fix and test the FIDEDUPERANGE Linux ioctl
The previous implementation didn't match the ioctl spec.

Fixes golang/go#43678

Change-Id: Ia1c292c2dbd4913fb1d7e8331d9f18e23169d64a
GitHub-Last-Rev: 5331c424ef
GitHub-Pull-Request: golang/sys#97
Reviewed-on: https://go-review.googlesource.com/c/sys/+/284352
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Ian Lance Taylor <iant@golang.org>
2021-02-25 08:00:10 +00:00
Jason A. Donenfeld
683adc9d29 windows: do not overflow key memory in GetQueuedCompletionStatus
The third argument to GetQueuedCompletionStatus is a pointer to a
uintptr, not a uint32. Users of this functions have therefore been
corrupting their memory every time they used it. Either that memory
corruption was silent (dangerous), or their programs didn't work so they
chose a different API to use.

Updates golang/go#44538.

Change-Id: Ie1f66de11001cf9c8195afaa61f003a86f821a95
Reviewed-on: https://go-review.googlesource.com/c/sys/+/295174
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-02-25 01:42:09 +00:00
billofarrell
5640770f5e unix: add support for zos/s390x
This adds sys/unix support for zos/s390x.
These changes should not affect other platforms.

Fixes golang/go#43230

Change-Id: If1c1d9df134fbc44f95ca1b214e836508696da93
Reviewed-on: https://go-review.googlesource.com/c/sys/+/275992
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-24 23:11:01 +00:00
Jason A. Donenfeld
eede4237b3 windows: add WSASocket
Simple function to complement the other ws2 functions we have:
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw

Change-Id: Idf6b17360d84a8529e48ab94561c4ac7bee1d847
Reviewed-on: https://go-review.googlesource.com/c/sys/+/295175
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2021-02-23 21:21:15 +00:00
Tobias Klauser
7937bea010 unix: add Xucred, GetsockoptXucred on freebsd
Follow CL 292330 which added these on darwin.

Generated on FreeBSD 13.0BETA3

For golang/go#41659

Change-Id: I30eeef43c4f61a9449f3fe8b5cc0033f46dfe822
Reviewed-on: https://go-review.googlesource.com/c/sys/+/294989
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-23 09:59:34 +00:00
Tom Thorogood
b80eb88b80 unix: add HIDRAW ioctls
This change adds (most) of the ioctl API for the Linux HIDRAW interface.
Reading and writing non-numbered HID reports is done using the read and
write system calls respectively.

Some of the HIDIOC* request numbers are exported directly while others
are kept unexported. This is because some of the #defines require a len
attribute that doesn't have a specific well defined value.

Wrapper types are added for most of the request numbers as is standard.
No wrapper is added for HIDIOCGRDESCSIZE as it would just be
IoctlGetUint32.

The HIDIOC[GS]FEATURE, HIDIOC[GS]INPUT and HIDIOC[GS]OUTPUT request
numbers, which are required for numbered HID reports, are entirely
ommitted as the len attribute has to be a runtime variable. These could
be added later by doing something like
 `HIDIOCGFEATURE(0) | (len << _IOC_SIZESHIFT)`,
with care taken that len doesn't overflow _IOC_XSIZEMASK.

Outdated documentation for the HIDRAW interface is available at:
https://www.kernel.org/doc/Documentation/hid/hidraw.txt.

Change-Id: I2ae5060f0f46150f6fb52959c2e55f50927c1f69
Reviewed-on: https://go-review.googlesource.com/c/sys/+/289169
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-02-23 08:53:22 +00:00
Tobias Klauser
d8cc79f4ae unix: drop pre-1.10 compatibility in TestSCMCredentials
The last pre-1.10 release - Go 1.9 - was release 2017-08-24 and is no
longer supported since Go 1.11 was released 2018-08-24.

This effectively reverts https://golang.org/cl/80275

Updates golang/go#22899

Change-Id: Id7ab3f6b6d6430977db9345def383d875396e1e7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/292969
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-23 08:51:55 +00:00