Commit Graph

753 Commits

Author SHA1 Message Date
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
Brad Fitzpatrick
3626398d77 cpu: don't depend on the golang.org/x/sys/unix package for AIX
gccgo support can happen in a future CL.

Updates golang/go#32102

Change-Id: Ic9e8d7b3e413079d277bdba565551845a2b78121
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179178
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2019-05-28 18:36:47 +00:00
Yuval Pavel Zholkover
adf421d2ca unix: fix Signalfd function signature on linux
The kernel raw syscall takes an additional parameter specifying
the size of the Sigset_t parameter, returns a file descriptor and sets errno.

Add a uintptr maxSize parameter, adjust the return to be (newfd int, err error).
Add the _NSIG #define and a wrapper to call with maxSize set to _C__NSIG/8 as done
in glibc/musl.

Change-Id: I277db0aab5c12364533c26ea800b7f394ec83ae4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178858
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-28 01:25:30 +00:00
Takuto Ikuta
9cd6430ef9 windows: add ResumeThread function
ref:
https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-resumethread

Change-Id: I114846c85bc5b8eb8dc742fdc3bdacb7b28cddaa
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179037
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-27 10:42:16 +00:00
Jason A. Donenfeld
ea4c425e90 windows: allow Windows-style printf debugging via MessageBox
I realize that at this time, x/sys/windows is most certainly not aiming
to be some sort of UI library or anything remotely close to that.
However, MessageBox is sort of the one universal Windows API that's used
even for console programs. It's *the* classic debugging helper. It's
even pretty customary for console programs to display their usage
message in a message box rather than stdout. I realize this might be
somewhat disturbing to consider if you're in the blissful Unix utopia,
but on Windows, this is just sort of how things roll. Easy access to
MessageBox() is important.

Change-Id: I16183b69e8a27a5ddaf73d1d4e106bb7b201a6f0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178899
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-27 09:26:32 +00:00
Jason A. Donenfeld
56c252d053 windows: add ShellExecute
This is the way to do things like execute a process elevated with UAC
and interact with that whole system. It turns out to be quite important
for writing Windows software.

Change-Id: I5e05dc9b89ea308d42ac86ba563fd01922fc940c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178898
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-05-27 09:25:20 +00:00
Jason A. Donenfeld
791d8a0f4d windows: allow determining if running 32-on-64bit
This is useful for determining whether or not it's going to be possible
to install device drivers, for example.

Change-Id: I628c6f3279b16832bcd6b4ca66dfa3e7334b88ff
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178897
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-05-26 05:23:59 +00:00
Jason A. Donenfeld
2219a0101f windows: add SID getter functions for the various components
These allow actual inspection of SIDs. For example, it might be
desirable to iterate through the group SIDs in order to find one set by
SERVICE_CONFIG_SERVICE_SID_INFO:

    for _, g := range groups {
        if g.Attributes != windows.SE_GROUP_ENABLED|windows.SE_GROUP_ENABLED_BY_DEFAULT|windows.SE_GROUP_OWNER {
            continue
        }
        if !g.Sid.IsValid() {
            continue
        }
        if g.Sid.IdentifierAuthority() != windows.SECURITY_NT_AUTHORITY {
            continue
        }
        if g.Sid.SubAuthorityCount() < 6 || g.Sid.SubAuthority(0) != 80 {
            continue
        }
        sid = g.Sid
        break
    }

Another usage of the APIs added would be to find if a user is in the
administrator group with either an elevated or unelevated token:

    isAdmin := false
    for _, g := range groups {
        if g.Attributes&(windows.SE_GROUP_ENABLED|windows.SE_GROUP_USE_FOR_DENY_ONLY) == 0 {
            continue
	}
        if !g.Sid.IsWellKnown(windows.WinBuiltinAdministratorsSid) {
            continue
	}
        isAdmin = true
        break
    }

Change-Id: I8f8dc8d37b71ec58fd51e21ea1f1b3aada6d66b0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/177841
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-05-26 03:56:09 +00:00
Takuto Ikuta
e44a3b55db windows: add SetErrorMode function
Change-Id: I79cd7d7e5b49b55281e63131388bc4693b7eed1e
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178779
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-26 03:10:47 +00:00
Jason A. Donenfeld
dbbf3f1254 windows: add IP() accessor to SocketAddress type
This is what everybody winds up doing with this object, so we make it
somewhat nicer than copying and pasting this everywhere or using type
aliases.

Change-Id: I3e12395cadfe212a7d01ce86478de9486383729a
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178577
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-24 15:25:21 +00:00
Takuto Ikuta
c3d486d151 windows: add JobObject functions
Change-Id: Ib8c3fe735ed72e3b211328c89170eb03fc64b102
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178777
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-24 15:12:52 +00:00
Tobias Klauser
abf6ff7781 unix: add MCAST_* constants on linux
This will also add two BPF_* consts which weren't added as part of
CL 174978 because they were generated before the Linux version update
in CL 175158.

Change-Id: I5dfecbecb9d94b56d01490a5f17f2250ad5b30d4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178658
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-05-24 12:25:48 +00:00
Tobias Klauser
0e01d883c5 unix: add RawSockaddrDatalink on aix
This is already part of package syscall, so add it to x/sys/unix as
well.

Change-Id: I2eb015dd439d37894519858f010cc45d6e3da50a
Reviewed-on: https://go-review.googlesource.com/c/sys/+/178657
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-23 14:25:57 +00:00
Jason A. Donenfeld
8097e1b27f windows: do not query library for inline functions
The GetCurrent*Token variety of functions are actually implemented as
inline functions in the header files of the SDK. Attempting to call out
to these as library functions is an error. This commit also adds a test
to ensure that these work as expected.

Change-Id: I105f1ca1a8936114fe61bc22188200c31f240a23
Reviewed-on: https://go-review.googlesource.com/c/sys/+/177840
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-22 04:47:17 +00:00
Jason A. Donenfeld
30999d67c8 windows: add missing service constants
This adds a number of useful comments for ChangeServiceConfig2. It looks
like the MingW headers have these in two different places, awkwardly,
and whoever imported these constants missed the second half of them,
whereas the real Microsoft header files have them all together in one
place.

Change-Id: I723c4bcd86e5a1b905cb738c5c2b49805a354af4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/177842
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-22 04:46:51 +00:00
Jason A. Donenfeld
c46e0d965b windows/registry: do not generate unaligned loads
Byte slices aren't necessarily aligned, which means casting them to
integer types and dereferencing may result in an unaligned load. This
is mostly fine on Intel but isn't necessarily fine on other platforms.
Any good compiler will generate optimal code for the platform using the
pattern of this commit.

Change-Id: I6dd8debad1cb850b8562ee96ae0f366d1f822a6f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/176857
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-05-22 03:42:48 +00:00
Tobias Klauser
c432e742b0 unix: remove unused stringsFromByteSlice for tests on aix
stringsFromByteSlice is only used in xattr_test.go which isn't enabled
for aix.

Change-Id: I95948cbac285d8efe7f5299de85625cb7541e906
Reviewed-on: https://go-review.googlesource.com/c/sys/+/177839
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
2019-05-20 20:13:01 +00:00
Clément Chigot
ad400b1274 unix: remove StTimespec type on AIX
On AIX, Stat_t's fields dealing with time are of type StTimespec while
all other GOOS are using Timespec.
StTimespec and Timespec are the same on ppc but not in ppc64. Therefore,
values returned by ppc64 syscalls need to be adjusted in order to
allow the use of Timespec instead of StTimespec.

Fixes golang/go#32073

Change-Id: I0c212bf1741a27c49e995bf928d4941b6d583e54
Reviewed-on: https://go-review.googlesource.com/c/sys/+/177838
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-20 16:14:52 +00:00
Jason A. Donenfeld
61b9204099 windows: add functions for dealing with elevated tokens
These are required when dealing with UAC or launching processes as
elevated administrators on behalf of other users.

Change-Id: If256c838b1f0202a8703d91496ffdbe16be3a700
Reviewed-on: https://go-review.googlesource.com/c/sys/+/176858
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-05-16 11:00:30 +00:00
Jason A. Donenfeld
cedb8e16d1 windows: add token group adjustment function
We have the useful AdjustTokenPrivileges, but we don't have the equally
as useful AdjustTokenGroups function. So this CL adds it.

Change-Id: Ic09b4688ee5ec7f1a626a21216a85b075961aad5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/176859
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2019-05-16 10:27:23 +00:00
Yuval Pavel Zholkover
cab07311ab unix: fix TestStatFieldNames on aix and TestUtimesNanoAt on darwin
Following CL 175157 which renames Stat_t time fields to [AMCB]tim.

Updates golang/go#31735

Change-Id: I0791c59bab307d237b315c1b919265902f7d9917
Reviewed-on: https://go-review.googlesource.com/c/sys/+/177437
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-16 01:48:33 +00:00
Yuval Pavel Zholkover
87c872767d unix: rename Stat_t time fields to [AMCB]tim
Birthtime/Birthtimespec was renamed to Btim to match the others.
Also unexport the [ACMB]tim_ext fields on freebsd 386.
Update mkpost.go to do the renames.

Ran the following on the existing ztypes_*.go files:

  #!/bin/sh
  set -e

  for f in ztypes_*.go; do
      cat $f | go run mkpost.go | gofmt > $f.tmp
      mv $f.tmp $f
  done;

  cat ztypes_freebsd_386.go | env GOOS=freebsd GOARCH=386 go run mkpost.go | gofmt > ztypes_freebsd_386.go.tmp
  mv ztypes_freebsd_386.go{.tmp,}

Fixes golang/go#31735

Change-Id: I15765d690ee8d2be6bbb37f465322bc019722e08
Reviewed-on: https://go-review.googlesource.com/c/sys/+/175157
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-15 19:05:49 +00:00