syscall: switch go:generate directives back to mksyscall_windows.go

Adjust mksyscall_windows.go to activate module mode and set
-mod=readonly, and to suppress its own deprecation warning when run
from within GOROOT/src.

We can't vendor the mkwinsyscall tool in to the std module directly,
because std-vendored dependencies (unlike the dependencies of all
other modules) turn into actual, distinct packages in 'std' when
viewed from outside the 'std' module. We don't want to introduce a
binary in the 'std' meta-pattern, but we also don't particularly want
to add more special-cases to the 'go' command right now when we have
an existing wrapper program that can do the job.

I also regenerated the affected packages to ensure that they are
consistent with the current version of mksyscall, which produced some
declaration-order changes in
internal/syscall/windows/zsyscall_windows.go.

Fixes #41916
Updates #25922

Change-Id: If6e6f8ba3dd372a7ecd6820ee6c0ca38d55f0f35
Reviewed-on: https://go-review.googlesource.com/c/go/+/261499
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
Bryan C. Mills 2020-10-12 10:51:34 -04:00
parent d5388e23b5
commit cb65c8d58a
5 changed files with 54 additions and 20 deletions

View File

@ -6,4 +6,4 @@
package windows
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall_windows.go security_windows.go psapi_windows.go symlink_windows.go
//go:generate go run ../../../syscall/mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go security_windows.go psapi_windows.go symlink_windows.go

View File

@ -6,4 +6,4 @@
package registry
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall.go
//go:generate go run ../../../../syscall/mksyscall_windows.go -output zsyscall_windows.go syscall.go

View File

@ -40,14 +40,15 @@ var (
modkernel32 = syscall.NewLazyDLL(sysdll.Add("kernel32.dll"))
modws2_32 = syscall.NewLazyDLL(sysdll.Add("ws2_32.dll"))
modnetapi32 = syscall.NewLazyDLL(sysdll.Add("netapi32.dll"))
modadvapi32 = syscall.NewLazyDLL(sysdll.Add("advapi32.dll"))
moduserenv = syscall.NewLazyDLL(sysdll.Add("userenv.dll"))
modadvapi32 = syscall.NewLazyDLL(sysdll.Add("advapi32.dll"))
modpsapi = syscall.NewLazyDLL(sysdll.Add("psapi.dll"))
procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
procMoveFileExW = modkernel32.NewProc("MoveFileExW")
procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW")
procSetFileInformationByHandle = modkernel32.NewProc("SetFileInformationByHandle")
procWSASocketW = modws2_32.NewProc("WSASocketW")
procLockFileEx = modkernel32.NewProc("LockFileEx")
procUnlockFileEx = modkernel32.NewProc("UnlockFileEx")
@ -71,7 +72,6 @@ var (
procNetUserGetLocalGroups = modnetapi32.NewProc("NetUserGetLocalGroups")
procGetProcessMemoryInfo = modpsapi.NewProc("GetProcessMemoryInfo")
procGetFileInformationByHandleEx = modkernel32.NewProc("GetFileInformationByHandleEx")
procSetFileInformationByHandle = modkernel32.NewProc("SetFileInformationByHandle")
)
func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
@ -82,18 +82,6 @@ func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapter
return
}
func SetFileInformationByHandle(handle syscall.Handle, fileInformationClass uint32, buf uintptr, bufsize uint32) (err error) {
r1, _, e1 := syscall.Syscall6(procSetFileInformationByHandle.Addr(), 4, uintptr(handle), uintptr(fileInformationClass), uintptr(buf), uintptr(bufsize), 0, 0)
if r1 == 0 {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) {
r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
if r1 == 0 {
@ -131,6 +119,18 @@ func GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32,
return
}
func SetFileInformationByHandle(handle syscall.Handle, fileInformationClass uint32, buf uintptr, bufsize uint32) (err error) {
r1, _, e1 := syscall.Syscall6(procSetFileInformationByHandle.Addr(), 4, uintptr(handle), uintptr(fileInformationClass), uintptr(buf), uintptr(bufsize), 0, 0)
if r1 == 0 {
if e1 != 0 {
err = errnoErr(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func WSASocket(af int32, typ int32, protocol int32, protinfo *syscall.WSAProtocolInfo, group uint32, flags uint32) (handle syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall6(procWSASocketW.Addr(), 6, uintptr(af), uintptr(typ), uintptr(protocol), uintptr(unsafe.Pointer(protinfo)), uintptr(group), uintptr(flags))
handle = syscall.Handle(r0)

View File

@ -4,9 +4,11 @@
// +build ignore
// mksyscall_windows wraps golang.org/x/sys/windows/mkwinsyscall.
package main
import (
"bytes"
"os"
"os/exec"
"path/filepath"
@ -14,11 +16,43 @@ import (
)
func main() {
goTool := filepath.Join(runtime.GOROOT(), "bin", "go")
listCmd := exec.Command(goTool, "list", "-m")
listCmd.Env = append(os.Environ(), "GO111MODULE=on")
var (
cmdEnv []string
modArgs []string
)
if out, err := listCmd.Output(); err == nil && string(bytes.TrimSpace(out)) == "std" {
// Force module mode to use mkwinsyscall at the same version as the x/sys
// module vendored into the standard library.
cmdEnv = append(os.Environ(), "GO111MODULE=on")
// Force -mod=readonly instead of the default -mod=vendor.
//
// mkwinsyscall is not itself vendored into the standard library, and it is
// not feasible to do so at the moment: std-vendored libraries are included
// in the "std" meta-pattern (because in general they *are* linked into
// users binaries separately from the original import paths), and we can't
// allow a binary in the "std" meta-pattern.
modArgs = []string{"-mod=readonly"}
} else {
// Nobody outside the standard library should be using this wrapper: other
// modules can vendor in the mkwinsyscall tool directly (as described in
// https://golang.org/issue/25922), so they don't need this wrapper to
// set module mode and -mod=readonly explicitly.
os.Stderr.WriteString("WARNING: Please switch from using:\n go run $GOROOT/src/syscall/mksyscall_windows.go\nto using:\n go run golang.org/x/sys/windows/mkwinsyscall\n")
args := append([]string{"run", "golang.org/x/sys/windows/mkwinsyscall"}, os.Args[1:]...)
cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), args...)
}
args := append([]string{"run"}, modArgs...)
args = append(args, "golang.org/x/sys/windows/mkwinsyscall")
args = append(args, os.Args[1:]...)
cmd := exec.Command(goTool, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = cmdEnv
err := cmd.Run()
if err != nil {
os.Exit(1)

View File

@ -26,7 +26,7 @@
//
package syscall
//go:generate go run golang.org/x/sys/windows/mkwinsyscall -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
//go:generate go run ./mksyscall_windows.go -systemdll -output zsyscall_windows.go syscall_windows.go security_windows.go
// StringByteSlice converts a string to a NUL-terminated []byte,
// If s contains a NUL byte this function panics instead of