Commit Graph

774 Commits

Author SHA1 Message Date
utkarsh-extc
0c73a916fa windows/svc: safe closure on error 2019-07-24 00:28:27 +05:30
utkarsh-extc
87093553ba add test for delayed start 2019-07-23 15:58:38 +05:30
utkarsh-extc
2baf3a60a8 add support for delayed automatic service start 2019-07-23 15:40:34 +05:30
utkarsh-extc
a9b5334b0f add support for delayed automatic service start 2019-07-23 15:39:27 +05:30
utkarsh-extc
7e62a73d66 add support for delayed automatic start 2019-07-23 15:36:41 +05:30
Tobias Klauser
fae7ac547c unix: add constants and types to work with Linux loop devices
Change-Id: I0996df39a561b50822a6e42e770d96421d6b4965
Reviewed-on: https://go-review.googlesource.com/c/sys/+/185498
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-07-12 06:29:09 +00:00
Tobias Klauser
6ec70d6a55 unix: update Dockerfile to Linux 5.2 and Go 1.13beta1
Change-Id: I1a63f6ae5fe6b8b6fb4f493837b12dbe3c2860d4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/185497
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-07-10 14:34:15 +00:00
Tobias Klauser
04f50cda93 unix: add missing dirent* helper functions on aix
These are needed by ParseDirent and were missing in CL 183897.

Change-Id: I5b340fea9c0dc1b65b717b0d3cfd8cbb40d3cae9
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183997
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-06-26 22:19:50 +00:00
Tobias Klauser
e07cf5db27 unix: don't use syscall.ParseDirent
Implement ParseDirent in x/sys/unix instead of calling
syscall.ParseDirent. The latter uses offsets into syscall.Dirent which
might not be matching unix.Dirent depending on Go version. This is e.g.
the case with of FreeBSD whose Dirent structure was updated for Go 1.12.

This fixes TestDirent and TestGetdirentries on freebsd with Go 1.11

Reverts CL 88475

Change-Id: I04318f59c6fbf148c75ce3667255a0c0428288e2
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183897
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2019-06-26 15:08:13 +00:00
Tobias Klauser
c5567b49c5 unix: add Getdents on dragonfly
Add a syscall wrapper for Getdents on dragonfly and use it to
implement ReadDirent

Change-Id: Ie54c0edeaf89491cab2355557fb442bd5bec2987
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183227
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2019-06-24 14:20:23 +00:00
Tobias Klauser
e93b963712 unix: use ParseDirent in testGetdirentries
Use ParseDirent to get the directory entries instead of manually parsing
them. This fixes the test on dragonfly where type Dirent doesn't have a
Reclen member.

Manually tested on darwin, dragonfly and freebsd.

Change-Id: I234c6aff78243fec8bba8784c1d4948fbbb4d027
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183226
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2019-06-24 14:20:14 +00:00
Tobias Klauser
d432491b91 unix: fix nil pointer dereference in Getdirentries on 32-bit freebsd 12
Don't attempt to dereference basep if it's nil, just pass it to
getdirentries_freebsd12 as is.

Change-Id: I043a9ee9262e6333c35fd9ecc52694c8fd2de9f6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183223
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Yuval Pavel Zholkover <paulzhol@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-21 20:38:18 +00:00
Tobias Klauser
4d873483be unix: add missing import in readdirent_getdirentries.go
CL 182321 missed this and the trybots didn't catch it because they
neither test darwin nor dragonfly.

Change-Id: I6093805e702d528dae9035a5acf827099e0c2eaa
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183222
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-06-21 19:03:02 +00:00
Yuval Pavel Zholkover
a26fa11ef6 unix: fix Getdirentries emulation using Getdents on netbsd, openbsd
CL 182319 used the wrong shift offset, correct and enable the TestGetdirentries.

Change-Id: I45d8d420a071fd79fa1b37642b984d80943f492b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183221
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-21 18:44:11 +00:00
Tobias Klauser
d6ba46b060 unix: add test for Getdirentries
Copied and adapted from the respective test in std syscall.

Change-Id: Ia35864e201c8b628dfc21a8da79305d5741d4acc
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183219
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Yuval Pavel Zholkover <paulzhol@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-21 18:37:10 +00:00
Tobias Klauser
8f4f963083 unix: merge implementation for ReadDirent
Provide common implementation for ReadDirent based on Getdents for
aix, *bsd and linux.

Add Getdents on aix as a wrapper around getdirent.

Keep the implementation for ReadDirent based on Getdirentries for
darwin and dragonfly.

Change-Id: I09094156a1452118ba48af4f14dfe44b1ab745d3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182321
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2019-06-21 18:36:46 +00:00
Tobias Klauser
943d5127bd unix: add support to get/set Linux capabilities
Add wrappers for Getcap/Setcap on Linux as well as some related types
and consts.

Change-Id: I07764c2e64717214850ea3cbdc238e313d1e38c4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183218
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-06-21 15:33:39 +00:00
Tobias Klauser
06bbe82148 unix: correctly rename Val member in Sigset_t on freebsd
The generated name X__bits should be changed to Val to match the type on
Linux. This was done manually in CL 179099 when Sigset_t was added for
freebsd. Modify mkpost.go to do it, so future changes won't revert the
rename.

Change-Id: I0ce135cbd8d03648a1576244d9c977b39c8f5889
Reviewed-on: https://go-review.googlesource.com/c/sys/+/183220
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-06-21 13:41:30 +00:00
rayrapetyan
bf70e46780 unix: add ptrace support for FreeBSD
Change-Id: Iaf95e3e7bd3d33ad7e214c45ed87b9e967b16631
GitHub-Last-Rev: e0308dc7ad
GitHub-Pull-Request: golang/sys#34
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179099
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-06-21 06:25:56 +00:00
Tobias Klauser
6f217b454f unix: add AT_SYMLINK_FOLLOW const on openbsd
Change-Id: I60d7ce4a06e5a016cbb9fbf773a34748a5fd96f5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182899
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-06-20 07:01:43 +00:00
Tobias Klauser
6f551f7d2b unix: add AT_SYMLINK_FOLLOW const on netbsd
Change-Id: I6f6d9534389800b6f245021db051f96e90411173
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182897
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2019-06-20 07:01:26 +00:00
Jason A. Donenfeld
e40ef342dc windows: make CoTaskMemFree public
It's a useful function for people doing things with OLE32 from
elsewhere.

Change-Id: Id729d1c2b382ab4c097a06fb73448e671c0ad2f0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182157
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-06-19 22:31:25 +00:00
Gernot Vormayr
17bc6164aa unix: remove net dependency
According to godoc x/sys/unix is supposed to be a base for packages 'such
as "os", "time" and "net"'[1]. If we ever plan to make net a dependency
on x/sys/unix, this would lead to a circular dependency.

[1] https://godoc.org/golang.org/x/sys/unix

Change-Id: I3e2a62674148afd7e4f6db6acc3a364684b31379
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182320
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-19 18:30:51 +00:00
Jason A. Donenfeld
516e3c2063 windows: allow determining real version number
Other functions, like GetVersion(), will lie about the OS version
depending on various win32 and manifest compatibility shims in place.
Calling RtlGetVersion is the proper way to retrieve the true OS version.

Change-Id: I2bd6d097dd763df51617cd825dc0ad300abf6212
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182718
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
2019-06-18 15:50:05 +00:00
Yuval Pavel Zholkover
15dcb6c006 unix: fix Getdirentries emulation using Getdents on netbsd, openbsd
Call Seek if basep is not nil to read the current dir offset.
Return EIO error if the offset doesn't fit into a 32-bit uintptr.
Make Getdents public.

Update golang/go#32498

Change-Id: Idfbc48d3fc3a6cc8a979242681e8882d39998285
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182319
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-06-16 12:48:12 +00:00
Yuval Pavel Zholkover
b47fdc9379 unix: change the mksysnum master to point to stable/11 on freebsd
Add a COMPAT10 directive to mksysnum.go to keep generating SYS_PIPE.

Updates golang/go#27619

Change-Id: Ifb54a812baf79c9426ce864bb0ef0e66b19d7f3b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182318
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-06-14 16:08:38 +00:00
Takuto Ikuta
d442b75600 windows: rename some arguments to follow MSDN
This is followup for CL 182097.

Change-Id: I55227381148dc5f83e185fafc294077b7a10df39
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182218
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jason Donenfeld <Jason@zx2c4.com>
2019-06-14 08:40:37 +00:00
Jason A. Donenfeld
5ed2794edf windows: allow looking up well-known folder paths
This adds the recommended API for determining well-known folder paths,
such as where to place application configuration data. The MSDN
documentation mentions an optimization for the "current user" by passing
NULL as the token, so we provide both variants.

Updates golang/go#32248

Change-Id: I4a2d5d833543e6a0ba8f318944dd6493a0ec31d3
Reviewed-on: https://go-review.googlesource.com/c/sys/+/181637
Reviewed-by: Jason Donenfeld <Jason@zx2c4.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-13 12:46:09 +00:00
Takuto Ikuta
ab3f67ed27 windows: add OpenThread function
ref:
https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-openthread

Change-Id: I4ba1d48603581e93c2f5cd9798f8ef067b714753
Reviewed-on: https://go-review.googlesource.com/c/sys/+/182097
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-06-13 10:11:56 +00:00
Takuto Ikuta
914ada52e9 windows: add GetProcessId function
ref:
https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getprocessid

Document does not say anything about return value, but when I use 0 for HANDLE, GetProcessId
returns 0 with ERROR_INVALID_HANDLE from GetLastError().

Change-Id: Ib6782ccd5a4917e93ddbcf18c533921b12c67e3b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/180924
Reviewed-by: Marc-Antoine Ruel <maruel@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-13 09:49:25 +00:00
Keith Randall
93c9922d18 unix: fix Getdirentries on 32-bit freebsd 12
On freebsd 12, the system call for getdirentries writes 64 bits to
*basep, even on 32-bit systems. Accomodate that by providing a uint64
to the system call and copy the base to/from that uint64.
The uint64 seems to be a virtual file offset, so failing if the high
bits are not zero should be fine for reasonable-sized directories.

Update golang/go#32498

Change-Id: I4451894aff4e353c9f009c06ad2fdd5578dfd9f8
Reviewed-on: https://go-review.googlesource.com/c/sys/+/181500
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-06-10 20:04:19 +00:00
Takuto Ikuta
1e42afee0f windows: expose GetCurrentProcessId function
Change-Id: I537bce4415871f0d4669398bd72e4eb7c9c03481
Reviewed-on: https://go-review.googlesource.com/c/sys/+/180921
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-06-10 08:10:24 +00:00
Jason A. Donenfeld
301114b31c windows: allow determining if manager is locked
The SCM can be locked by NT. While traditionally any process could lock
the SCM using "LockServiceDatabase", Microsoft removed this
functionality because it created so many bugs, and that function now
does nothing. However, the system itself, via the "NT Service Control
Manager", is still allowed to lock the SCM.

For example, at boot time on Windows 8.1, the SCM is locked after a
service is started until that service reports itself in a running state.
This poses a bit of a problem: it's useful to install device drivers
from inside services as part of their initialization, and mark the
service as having started only after the device has installed. But
device installation might potentially load new drivers, and drivers
themselves exist as a special type of service. This means that if a
driver is installed before marking the service as started, the entire
SCM will deadlock, and the OS will be partially unresponsive for a
minute or two.

Fortunately Microsoft supplies an API for exactly this purpose. The
solution is to mark the service as started before installing device
drivers, only under the circumstance that the SCM is locked. So, this
commit adds the proper API for determining this. It can be used like
this:

    if m, err := mgr.Connect(); err == nil {
        if lockStatus, err := m.LockStatus(); err == nil && lockStatus.IsLocked {
            log.Printf("SCM locked for %v by %s, marking service as started", lockStatus.Age, lockStatus.Owner)
            changes <- svc.Status{State: svc.Running}
        }
        m.Disconnect()
    }
    deviceDriver.Install()

This creates messages like the following, indicating that this API
works:

    SCM locked for 1s by .\NT Service Control Manager, marking service as started

Change-Id: Ic2f5b387e23efc3a287b2ab96ff84b357b712e36
Reviewed-on: https://go-review.googlesource.com/c/sys/+/180977
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-06-09 08:25:36 +00:00
Jason A. Donenfeld
6df407bc07 windows: correct types and error values of internal GUID handling
This corrects the Windows int type to be the more correct int32 Go
analog, as well as not using GetLastError() for the error value of the
GUID string parsing function.

Change-Id: I9716f991ef649f7d299295e3f4e75d3986ec3a74
Reviewed-on: https://go-review.googlesource.com/c/sys/+/181397
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-06-09 07:43:00 +00:00
Takuto Ikuta
5b15430b70 windows: add Thread32{First,Next} funcions
ref:
https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-thread32first
https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/nf-tlhelp32-thread32next
https://docs.microsoft.com/en-us/windows/desktop/api/tlhelp32/ns-tlhelp32-tagthreadentry32

Update #32404

Change-Id: I6c8150d1077cf1e8abd0b06403313fef01f4b6e4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/180918
Reviewed-by: Marc-Antoine Ruel <maruel@chromium.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-08 05:02:28 +00:00
Jason A. Donenfeld
83eebf7133 windows: properly plumb sidtype into service creation
Many service attributes are settable using the ordinary CreateService
function, but ones added later in Windows need to be set using the
ChangeServiceConfig2 function. One of these is the Description field,
which is nicely plumbed behind the scenes, so that users of the API can
set it, and the mgr package will just figure out what to do with it.
Another one that works exactly the same way is SidType. Support for its
constants was added in 30999d6 ("windows: add missing service
constants"), but it wasn't actually built into the mgr package's
configuration struct, creating inconstancies in interface.

This commit rectifies that by adding proper support to mgr's config
struct.

Change-Id: I4f148f2d2477a03a65e8a571a8401392f6fe9f28
Reviewed-on: https://go-review.googlesource.com/c/sys/+/180978
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-06-08 04:32:40 +00:00
Jason A. Donenfeld
7fc4e5ec14 windows: add GUID handling functions
Virtually every project that works with x/sys/window's GUIDs winds up
rolling their own version of this in one way or another. So let's add
the correct win32 wrappers for it, so that these are always generated,
parsed, and converted in the uniform correct way.

Change-Id: I35f4b4ab5fc681d3e16fc5bbaf2cb20031eb3f12
Reviewed-on: https://go-review.googlesource.com/c/sys/+/180938
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-06-06 20:33:20 +00:00
Jason A. Donenfeld
5da285871e windows: add accessor for duration since boot
In order to deal with boot time race conditions, sometimes it is
useful to determine the time since boot.

Change-Id: Ibc907b49a9b072b3ef3b6c94eec7e2e6428943ba
Reviewed-on: https://go-review.googlesource.com/c/sys/+/180899
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2019-06-06 16:51:38 +00:00
Takuto Ikuta
79a91cf218 windows: add constants for access rights
This CL adds access rights constants for process and thread.
https://docs.microsoft.com/en-us/windows/desktop/procthread/process-security-and-access-rights
https://docs.microsoft.com/en-us/windows/desktop/procthread/thread-security-and-access-rights

Change-Id: I478216cf60c2e082d55a63479781d8f4640c73da
Reviewed-on: https://go-review.googlesource.com/c/sys/+/180697
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-06-06 12:20:18 +00:00
Jason A. Donenfeld
4c4f7f33c9 windows: make it easier to iterate over groups and privileges
Rather than having to write grotesque things like:

    groups, _ := processToken.GetTokenGroups()
    for _, g := range (*[(1 << 28) - 1]windows.SIDAndAttributes)(unsafe.Pointer(&groups.Groups[0]))[:groups.GroupCount] {
        // ...
    }

Users can now write clean things like this:

    groups, _ := processToken.GetTokenGroups()
    for _, g := range groups.AllGroups() {
        // ...
    }

Change-Id: Ief06de6899c497175628ff51b9d6ae55a90d14f1
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178857
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-06-02 01:53:25 +00:00
Alex Brainman
afe098805b windows: delete mkerrors.go
mkerrors.go is called by 'go generate' command to generate
zerrors_windows.go

mkerrors.go executes mkerrors.bash. But mkerrors.bash requires
winerror.h to be present on the system to succeed. And winerror.h is
never present on the system. So executing mkerrors.go always fails.

zerrors_windows.go is never changes. It was changed recently once.
The change before that was in 2014.

This change removes mkerrors.go, so other commands that are part of
'go generate' execution can proceed. If someone needs to update
zerrors_windows.go, they can call mkerrors.bash directly.

Fixes golang/go#32349

Change-Id: I9b3e581e183377201e8f74c2d991d97564f36778
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179582
Reviewed-by: Takuto Ikuta <tikuta@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Jason Donenfeld <Jason@zx2c4.com>
2019-06-02 01:07:38 +00:00
Joel Sing
4c3a928424 unix: provide linux/riscv64 assembly for syscalls
While the linux/riscv64 port is not yet upstream, most of the syscalls package
already has linux/riscv64 support and this will make testing and development
easier.

Updates golang/go#27532

Change-Id: I6e505be55fdbb2942fb6e4f34c040e7b82809630
Reviewed-on: https://go-review.googlesource.com/c/sys/+/177799
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-31 17:50:56 +00:00
Tobias Klauser
69e3a3a65b unix: fix TestFchmodat on illumos
Like linux/android, illumos doesn't support Fchmodat flags != 0.

The comment already mentions this, so update the condition as well now
that GOOS illumos is known.

Change-Id: Ic6542223129ec5fd8bb56dab3c8a042dc29ec7cc
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179362
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-31 13:24:40 +00:00
Alex Brainman
46560c3f3c Revert "windows: make zsyscall_windows.go generatable on non-WSL env"
This reverts commit ad28b68e88.

Reason for revert: It completely breaks 'go generate' on windows

Update golang/go#32349

Change-Id: I4bedc6cf5130eb48c18c3208c8029433407430e4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179580
Reviewed-by: Takuto Ikuta <tikuta@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-05-31 07:31:56 +00:00
Takuto Ikuta
ad28b68e88 windows: make zsyscall_windows.go generatable on non-WSL env
mkerrors.bash requires a Windows host, as it hard-codes paths like
/mnt/c/Program Files (x86)/Windows Kits.
But this does not allow to generate in non-WSL env.

Currently mkerrors.bash runs earlier than mksyscall_windows.go
when we run `go generate` and it fails on non-WSL env.
So zsyscall_windows.go is not generated in that case.

To fix that, I reoreder of code generation in this CL so that we can
generate zsyscall_windows.go in non-WSL env.

Also update error message in mkerrors.bash.

Change-Id: I04eccdbfe1e1ff56f8c405250f0724000d66d579
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178781
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-30 18:20:44 +00:00
Takuto Ikuta
95d888ea44 windows: add GenerateConsoleCtrlEvent function
ref:
https://docs.microsoft.com/en-us/windows/console/generateconsolectrlevent

Change-Id: Id5db1d4c7d73a142405061353f578b1be93dbbb9
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179538
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-30 18:20:36 +00:00
Visweswara R
6a60838ec2 plan9: modify mkall.sh to support zsyscall*.go files generation
Modify mkall.sh to support generation of zsyscall_plan9_{386,amd64,arm}.go
files. This does not generate any git diff as they were manually generated
with the same commands.

Fixes golang/go#29586

Change-Id: I5316fdb46f306974584eee653b439408294ea1cf
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179041
Reviewed-by: David du Colombier <0intro@gmail.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-05-29 16:45:35 +00:00
Tobias Klauser
5219a1e1c5 cpu: add missing linkname for libc_getsystemcfg on aix/ppc64
This fixes the aix/ppc64 build after CL 179178

Change-Id: Ie8d762b533c05d6ca262030b34ae137140896d44
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179317
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2019-05-29 13:00:38 +00:00
Takuto Ikuta
cc920278c2 windows: add SetInformationJobObject functions
This CL also adds some struct for the function.
https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_jobobject_extended_limit_information
https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_jobobject_basic_limit_information
https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_jobobject_basic_ui_restrictions
https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-io_counters

Change-Id: Ie3b7570fc344a25ad2a39129b74434b8baa1eed9
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179039
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-29 11:55:39 +00:00
Takuto Ikuta
854af27f14 windows: add functions for priority class
took const value from
https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-setpriorityclass
https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getpriorityclass

Change-Id: I376bb8e1f5de8968177512857d60169cb7b7c776
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179038
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-29 08:50:34 +00:00