aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile23
-rw-r--r--build.bat22
-rw-r--r--conf/path_windows.go40
-rw-r--r--embeddable-dll-service/build.bat27
-rw-r--r--go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch59
-rw-r--r--go-patches/0002-syscall-add-support-for-proc-thread-attribute-lists.patch158
-rw-r--r--go-patches/0003-syscall-restrict-inherited-handles-on-Windows.patch79
-rw-r--r--go-patches/0004-syscall-introduce-SysProcAttr.AdditionalInheritedHan.patch55
-rw-r--r--go-patches/0005-os-mark-pipes-returned-by-os.Pipe-as-inheritable-by-.patch39
-rw-r--r--go-patches/0006-syscall-introduce-SysProcAttr.ParentProcess-on-Windo.patch171
-rw-r--r--go.mod12
-rw-r--r--go.mod.master2
-rw-r--r--go.sum15
-rw-r--r--main.go5
-rw-r--r--ui/aboutdialog.go2
-rw-r--r--updater/versions.go2
-rw-r--r--version/useragent.go59
17 files changed, 58 insertions, 712 deletions
diff --git a/Makefile b/Makefile
index d204e657..f9ad2bad 100644
--- a/Makefile
+++ b/Makefile
@@ -25,15 +25,17 @@ define download =
if ! mv $$@.unverified $$@; then rm -f $$@.unverified; exit 1; fi
endef
-$(eval $(call download,go.tar.gz,https://golang.org/dl/go1.16rc1.linux-amd64.tar.gz,6a62610f56a04bae8702cd2bd73bfea34645c1b89ded3f0b81a841393b6f1f14))
+$(eval $(call download,go.zip,https://download.wireguard.com/windows-toolchain/distfiles/go1.16-2021-02-18.zip,3b214888f70f2c0d7f96eed6335adda262c24c83f0fdfeefdeb5302703d05f46))
+$(eval $(call download,go-bootstrap.tar.gz,https://dl.google.com/go/go1.4.3.linux-amd64.tar.gz,ce3140662f45356eb78bc16a88fc7cfb29fb00e18d7c632608245b789b2086d2))
$(eval $(call download,wintun.zip,https://www.wintun.net/builds/wintun-0.10.1.zip,ff871508b3316701fa2c9ab72b919ef23cf2683ba04bbc405df4b509aa06e368))
-.deps/go/prepared: .distfiles/go.tar.gz $(wildcard go-patches/*.patch)
+.deps/go/prepared: .distfiles/go.zip .distfiles/go-bootstrap.tar.gz
mkdir -p .deps
- rm -rf .deps/go
- tar -C .deps -xzf .distfiles/go.tar.gz
- chmod -R +w .deps/go
- cat $(filter %.patch,$^) | patch -f -N -r- -p1 -d .deps/go
+ rm -rf .deps/go .deps/go-bootstrap
+ bsdtar -C .deps -s '/^go/go-bootstrap/' -xzf .distfiles/go-bootstrap.tar.gz
+ bsdtar -C .deps -xzf .distfiles/go.zip
+ cd .deps/go/src && GOARCH=amd64 GOOS=linux CGO_ENABLED=0 GOROOT_BOOTSTRAP=$(CURDIR)/.deps/go-bootstrap ./make.bash
+ rm -rf .deps/go-bootstrap
touch $@
.deps/wintun/prepared: .distfiles/wintun.zip
@@ -54,6 +56,9 @@ resources_386.syso: $(RESOURCE_FILES)
resources_arm.syso: $(RESOURCE_FILES)
armv7-w64-mingw32-windres $(RCFLAGS) -I .deps/wintun/bin/arm -i $< -o $@
+resources_arm64.syso: $(RESOURCE_FILES)
+ aarch64-w64-mingw32-windres $(RCFLAGS) -I .deps/wintun/bin/arm64 -i $< -o $@
+
amd64/wireguard.exe: export GOARCH := amd64
amd64/wireguard.exe: resources_amd64.syso $(SOURCE_FILES)
go build $(GOFLAGS) -o $@
@@ -67,9 +72,9 @@ arm/wireguard.exe: export GOARM := 7
arm/wireguard.exe: resources_arm.syso $(SOURCE_FILES)
go build $(GOFLAGS) -o $@
-arm64/wireguard.exe: arm/wireguard.exe
- mkdir -p $(@D)
- cp $< $@
+arm64/wireguard.exe: export GOARCH := arm64
+arm64/wireguard.exe: resources_arm64.syso $(SOURCE_FILES)
+ go build $(GOFLAGS) -o $@
remaster: export GOARCH := amd64
remaster: export GOPROXY := direct
diff --git a/build.bat b/build.bat
index 1075ac08..46316839 100644
--- a/build.bat
+++ b/build.bat
@@ -4,7 +4,7 @@ rem Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
setlocal enabledelayedexpansion
set BUILDDIR=%~dp0
-set PATH=%BUILDDIR%.deps\go\bin;%BUILDDIR%.deps;%PATH%
+set PATH=%BUILDDIR%.deps\llvm-mingw\bin;%BUILDDIR%.deps\go\bin;%BUILDDIR%.deps;%PATH%
set PATHEXT=.exe
cd /d %BUILDDIR% || exit /b 1
@@ -13,7 +13,9 @@ if exist .deps\prepared goto :render
rmdir /s /q .deps 2> NUL
mkdir .deps || goto :error
cd .deps || goto :error
- call :download go.zip https://golang.org/dl/go1.16rc1.windows-amd64.zip ff765c31cf321b431f9a11ec42e61d42ec87d56333c847f5a87d30e01aaed3df || goto :error
+ call :download go.zip https://download.wireguard.com/windows-toolchain/distfiles/go1.16-2021-02-18.zip 3b214888f70f2c0d7f96eed6335adda262c24c83f0fdfeefdeb5302703d05f46 || goto :error
+ mkdir go-bootstrap || goto :error
+ call :download go-bootstrap.zip https://dl.google.com/go/go1.4.3.windows-amd64.zip a88486b386c7aa10e72b804888e79733d573f97e38b16b6bc3a001d875663f92 "-C go-bootstrap --strip-components 1" || goto :error
rem Mirror of https://github.com/mstorsjo/llvm-mingw/releases/download/20201020/llvm-mingw-20201020-msvcrt-x86_64.zip
call :download llvm-mingw-msvcrt.zip https://download.wireguard.com/windows-toolchain/distfiles/llvm-mingw-20201020-msvcrt-x86_64.zip 2e46593245090df96d15e360e092f0b62b97e93866e0162dca7f93b16722b844 || goto :error
rem Mirror of https://imagemagick.org/download/binaries/ImageMagick-7.0.8-42-portable-Q16-x64.zip
@@ -21,11 +23,12 @@ if exist .deps\prepared goto :render
rem Mirror of https://sourceforge.net/projects/ezwinports/files/make-4.2.1-without-guile-w32-bin.zip
call :download make.zip https://download.wireguard.com/windows-toolchain/distfiles/make-4.2.1-without-guile-w32-bin.zip 30641be9602712be76212b99df7209f4f8f518ba764cf564262bc9d6e4047cc7 "--strip-components 1 bin" || goto :error
call :download wireguard-tools.zip https://git.zx2c4.com/wireguard-tools/snapshot/wireguard-tools-e8fa0f662f2541952e745d9c7fff0eeaec538a5c.zip feda0818551493eb608b2ca2a6ecd972ce7548d4221847f9bb3994199e28b44b "--exclude wg-quick --strip-components 1" || goto :error
- rem Mirror of https://sourceforge.net/projects/gnuwin32/files/patch/2.5.9-7/patch-2.5.9-7-bin.zip with fixed manifest
- call :download patch.zip https://download.wireguard.com/windows-toolchain/distfiles/patch-2.5.9-7-bin-fixed-manifest.zip 25977006ca9713f2662a5d0a2ed3a5a138225b8be3757035bd7da9dcf985d0a1 "--strip-components 1 bin" || goto :error
call :download wintun.zip https://www.wintun.net/builds/wintun-0.10.1.zip ff871508b3316701fa2c9ab72b919ef23cf2683ba04bbc405df4b509aa06e368 || goto :error
- echo [+] Patching go
- for %%a in ("..\go-patches\*.patch") do .\patch.exe -f -N -r- -d go -p1 --binary < "%%a" || goto :error
+ echo [+] Building go
+ set GOROOT_BOOTSTRAP=%CD%\go-bootstrap
+ set CGO_ENABLED=0
+ cmd /d /c "cd go\src && .\make.bat" || goto :error
+ rmdir /s /q go-bootstrap || goto :error
copy /y NUL prepared > NUL || goto :error
cd .. || goto :error
@@ -41,7 +44,6 @@ if exist .deps\prepared goto :render
set GOARM=7
set GOPATH=%BUILDDIR%.deps\gopath
set GOROOT=%BUILDDIR%.deps\go
- set PATH=%BUILDDIR%.deps\llvm-mingw\bin;%PATH%
if "%GoGenerate%"=="yes" (
echo [+] Regenerating files
go generate ./... || exit /b 1
@@ -79,11 +81,7 @@ if exist .deps\prepared goto :render
echo [+] Assembling resources %1
%~2-w64-mingw32-windres -I ".deps\wintun\bin\%~1" -DWIREGUARD_VERSION_ARRAY=%WIREGUARD_VERSION_ARRAY% -DWIREGUARD_VERSION_STR=%WIREGUARD_VERSION% -i resources.rc -o "resources_%~3.syso" -O coff -c 65001 || exit /b %errorlevel%
echo [+] Building program %1
- if %1==arm64 (
- copy "arm\wireguard.exe" "%~1\wireguard.exe" || exit /b 1
- ) else (
- go build -tags load_wintun_from_rsrc -ldflags="-H windowsgui -s -w" -trimpath -v -o "%~1\wireguard.exe" || exit /b 1
- )
+ go build -tags load_wintun_from_rsrc -ldflags="-H windowsgui -s -w" -trimpath -v -o "%~1\wireguard.exe" || exit /b 1
if not exist "%~1\wg.exe" (
echo [+] Building command line tools %1
del .deps\src\*.exe .deps\src\*.o .deps\src\wincompat\*.o 2> NUL
diff --git a/conf/path_windows.go b/conf/path_windows.go
index d635e008..e9ff783a 100644
--- a/conf/path_windows.go
+++ b/conf/path_windows.go
@@ -6,7 +6,6 @@
package conf
import (
- "debug/pe"
"errors"
"os"
"path/filepath"
@@ -14,7 +13,6 @@ import (
"unsafe"
"golang.org/x/sys/windows"
- "golang.org/x/sys/windows/registry"
)
var cachedConfigFileDir string
@@ -48,41 +46,9 @@ func RootDirectory(create bool) (string, error) {
if cachedRootDir != "" {
return cachedRootDir, nil
}
- //TODO: remove the wow detection logic when Go supports arm64
- var isWow bool
- var processMachine, nativeMachine uint16
- err := windows.IsWow64Process2(windows.CurrentProcess(), &processMachine, &nativeMachine)
- if err == nil {
- isWow = processMachine != pe.IMAGE_FILE_MACHINE_UNKNOWN
- } else {
- if !errors.Is(err, windows.ERROR_PROC_NOT_FOUND) {
- return "", err
- }
- err = windows.IsWow64Process(windows.CurrentProcess(), &isWow)
- if err != nil {
- return "", err
- }
- }
- var root string
- if !isWow {
- root, err = windows.KnownFolderPath(windows.FOLDERID_ProgramFiles, windows.KF_FLAG_DEFAULT)
- if err != nil {
- return "", err
- }
- } else {
- key, err := registry.OpenKey(windows.HKEY_LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion`, registry.READ|registry.WOW64_64KEY)
- if err != nil {
- return "", err
- }
- var typ uint32
- root, typ, err = key.GetStringValue("ProgramFilesDir")
- key.Close()
- if err != nil {
- return "", err
- }
- if typ != registry.SZ {
- return "", registry.ErrUnexpectedType
- }
+ root, err := windows.KnownFolderPath(windows.FOLDERID_ProgramFiles, windows.KF_FLAG_DEFAULT)
+ if err != nil {
+ return "", err
}
root = filepath.Join(root, "WireGuard")
if !create {
diff --git a/embeddable-dll-service/build.bat b/embeddable-dll-service/build.bat
index 85d01ca6..0d2cbdbb 100644
--- a/embeddable-dll-service/build.bat
+++ b/embeddable-dll-service/build.bat
@@ -4,47 +4,32 @@ rem Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
setlocal
set BUILDDIR=%~dp0
-set PATH=%BUILDDIR%..\.deps\go\bin;%BUILDDIR%..\.deps;%PATH%
+set PATH=%BUILDDIR%..\.deps\llvm-mingw\bin;%BUILDDIR%..\.deps\go\bin;%PATH%
set PATHEXT=.exe
cd /d %BUILDDIR% || exit /b 1
-if exist .prepared goto :build
+if exist ..\.deps\prepared goto :build
:installdeps
call ..\build.bat || goto :error
- pushd ..\.deps || goto :error
- rem Mirror of https://musl.cc/i686-w64-mingw32-native.zip
- call :download mingw-x86.zip https://download.wireguard.com/windows-toolchain/distfiles/i686-w64-mingw32-native-20200907.zip c972c00993727ac9bff83c799f4df65662adb95bc871fa30cfa8857e744a7fbd || goto :error
- rem Mirror of https://musl.cc/x86_64-w64-mingw32-native.zip
- call :download mingw-amd64.zip https://download.wireguard.com/windows-toolchain/distfiles/x86_64-w64-mingw32-native-20200907.zip e34fbacbd25b007a8074fc96f7e08f886241e0473a055987ee57483c37567aa5 || goto :error
- popd || goto :error
- copy /y NUL .prepared > NUL || goto :error
:build
set GOOS=windows
+ set GOARM=7
set GOPATH=%BUILDDIR%..\.deps\gopath
set GOROOT=%BUILDDIR%..\.deps\go
set CGO_ENABLED=1
set CGO_CFLAGS=-O3 -Wall -Wno-unused-function -Wno-switch -std=gnu11 -DWINVER=0x0601
call :build_plat x86 i686 386 || goto :error
call :build_plat amd64 x86_64 amd64 || goto :error
+ rem Uncomment when cgo is implemented:
+ rem call :build_plat arm armv7 arm || goto :error
+ rem call :build_plat arm64 aarch64 arm64 || goto :error
:success
echo [+] Success
exit /b 0
-:download
- echo [+] Downloading %1
- curl -#fLo %1 %2 || exit /b 1
- echo [+] Verifying %1
- for /f %%a in ('CertUtil -hashfile %1 SHA256 ^| findstr /r "^[0-9a-f]*$"') do if not "%%a"=="%~3" exit /b 1
- echo [+] Extracting %1
- tar -xf %1 %~4 || exit /b 1
- echo [+] Cleaning up %1
- del %1 || exit /b 1
- goto :eof
-
:build_plat
- set PATH=%BUILDDIR%..\.deps\%~2-w64-mingw32-native\bin;%PATH%
set CC=%~2-w64-mingw32-gcc
set GOARCH=%~3
mkdir %1 >NUL 2>&1
diff --git a/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch b/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch
deleted file mode 100644
index d02eeb2d..00000000
--- a/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch
+++ /dev/null
@@ -1,59 +0,0 @@
-From 7b5c04be2cd231d33a8d12db1542055318767c81 Mon Sep 17 00:00:00 2001
-From: "Jason A. Donenfeld" <Jason@zx2c4.com>
-Date: Thu, 3 Dec 2020 13:29:58 +0100
-Subject: [PATCH 1/6] runtime: allow builtin write function to be redirected
- with function pointer
-
-The x/sys/windows package currently uses go:linkname for other facilities
-inside of runtime that are not suitable to be exposed as a public API
-due to their dangers but are still necessary for manipulating any
-low-level plumbing that the runtime controls.
-
-Logging, via the built-in println and panic handler, is one such
-low-level plumbing feature. In this case, x/sys/windows/svc needs to be
-able to redirect panics to the Windows event log. Because the event log
-is a complicated interface, this requires a bit more fiddling than the
-simple solution used on Android (baking it into runtime itself), and
-because Windows services are very diverse, the event log might not even
-always be a desirable destination.
-
-This commit accomplishes this by exposing a function pointer called
-"overrideWrite" that low-level runtime packages like x/sys/windows/svc
-can use to redirect output logs toward the event log or otherwise.
-
-It is not safe or acceptable to use as a generic mechanism, and for that
-reason, we wouldn't want to expose this as a real stable API, similar to
-the other instances of go:linkname in x/sys/windows. But for packages
-that must interoperate with low-level Go runtime fundamentals, this is a
-safety hatch for packages that are developed in tandem with the runtime.
-x/sys/windows is one such package.
-
-Fixes #42888.
-
-Change-Id: I77a32ff7e1494324e8cc38e792e007f86d32672d
----
- src/runtime/time_nofake.go | 5 +++++
- 1 file changed, 5 insertions(+)
-
-diff --git a/src/runtime/time_nofake.go b/src/runtime/time_nofake.go
-index 1912a94e87..0564448b2e 100644
---- a/src/runtime/time_nofake.go
-+++ b/src/runtime/time_nofake.go
-@@ -23,9 +23,14 @@ func walltime() (sec int64, nsec int32) {
- return walltime1()
- }
-
-+var overrideWrite func(fd uintptr, p unsafe.Pointer, n int32) int32
-+
- // write must be nosplit on Windows (see write1)
- //
- //go:nosplit
- func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
-+ if overrideWrite != nil {
-+ return overrideWrite(fd, noescape(p), n)
-+ }
- return write1(fd, p, n)
- }
---
-2.30.0
-
diff --git a/go-patches/0002-syscall-add-support-for-proc-thread-attribute-lists.patch b/go-patches/0002-syscall-add-support-for-proc-thread-attribute-lists.patch
deleted file mode 100644
index f3e3a959..00000000
--- a/go-patches/0002-syscall-add-support-for-proc-thread-attribute-lists.patch
+++ /dev/null
@@ -1,158 +0,0 @@
-From ed7ed5c7b3ce4db8abd0219b12ff17ad9074f1cb Mon Sep 17 00:00:00 2001
-From: "Jason A. Donenfeld" <Jason@zx2c4.com>
-Date: Sun, 31 Jan 2021 17:37:20 +0100
-Subject: [PATCH 2/6] syscall: add support for proc thread attribute lists
-
-This will allow us to pass additional attributes when starting
-processes.
-
-Updates #44011.
-
-Change-Id: I4af365c5544a6d421830f247593ec970200e5e03
----
- src/syscall/syscall_windows.go | 28 ++++++++++++++++++++++++++++
- src/syscall/types_windows.go | 14 ++++++++++++++
- src/syscall/zsyscall_windows.go | 24 ++++++++++++++++++++++++
- 3 files changed, 66 insertions(+)
-
-diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go
-index ba69133d81..d892cc110d 100644
---- a/src/syscall/syscall_windows.go
-+++ b/src/syscall/syscall_windows.go
-@@ -284,6 +284,9 @@ func NewCallbackCDecl(fn interface{}) uintptr {
- // This function returns 1 byte BOOLEAN rather than the 4 byte BOOL.
- //sys CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) [failretval&0xff==0] = CreateSymbolicLinkW
- //sys CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) [failretval&0xff==0] = CreateHardLinkW
-+//sys initializeProcThreadAttributeList(attrlist *_PROC_THREAD_ATTRIBUTE_LIST, attrcount uint32, flags uint32, size *uintptr) (err error) = InitializeProcThreadAttributeList
-+//sys deleteProcThreadAttributeList(attrlist *_PROC_THREAD_ATTRIBUTE_LIST) = DeleteProcThreadAttributeList
-+//sys updateProcThreadAttribute(attrlist *_PROC_THREAD_ATTRIBUTE_LIST, flags uint32, attr uintptr, value uintptr, size uintptr, prevvalue uintptr, returnedsize *uintptr) (err error) = UpdateProcThreadAttribute
-
- // syscall interface implementation for other packages
-
-@@ -1209,3 +1212,28 @@ func Readlink(path string, buf []byte) (n int, err error) {
-
- return n, nil
- }
-+
-+// newProcThreadAttributeList allocates new PROC_THREAD_ATTRIBUTE_LIST, with a have maximum of maxattrcount attributes.
-+func newProcThreadAttributeList(maxattrcount uint32) (*_PROC_THREAD_ATTRIBUTE_LIST, error) {
-+ var size uintptr
-+ err := initializeProcThreadAttributeList(nil, maxattrcount, 0, &size)
-+ if err != ERROR_INSUFFICIENT_BUFFER {
-+ if err == nil {
-+ return nil, errorspkg.New("InitializeProcThreadAttributeList returned no error")
-+ }
-+ return nil, err
-+ }
-+ al := (*_PROC_THREAD_ATTRIBUTE_LIST)(unsafe.Pointer(&make([]byte, size)[0]))
-+ runtime.SetFinalizer(al, func(al *_PROC_THREAD_ATTRIBUTE_LIST) {
-+ deleteProcThreadAttributeList(al)
-+ })
-+ err = initializeProcThreadAttributeList(al, maxattrcount, 0, &size)
-+ if err != nil {
-+ return nil, err
-+ }
-+ return al, err
-+}
-+
-+func (al *_PROC_THREAD_ATTRIBUTE_LIST) Add(attribute uintptr, value unsafe.Pointer, size uintptr) error {
-+ return updateProcThreadAttribute(al, 0, attribute, uintptr(value), size, 0, nil)
-+}
-diff --git a/src/syscall/types_windows.go b/src/syscall/types_windows.go
-index 0349f3b180..59231bdb83 100644
---- a/src/syscall/types_windows.go
-+++ b/src/syscall/types_windows.go
-@@ -482,6 +482,20 @@ type StartupInfo struct {
- StdErr Handle
- }
-
-+type _PROC_THREAD_ATTRIBUTE_LIST [1]byte
-+
-+const (
-+ _PROC_THREAD_ATTRIBUTE_PARENT_PROCESS = 0x00020000
-+ _PROC_THREAD_ATTRIBUTE_HANDLE_LIST = 0x00020002
-+)
-+
-+type _STARTUPINFOEXW struct {
-+ StartupInfo
-+ ProcThreadAttributeList *_PROC_THREAD_ATTRIBUTE_LIST
-+}
-+
-+const _EXTENDED_STARTUPINFO_PRESENT = 0x00080000
-+
- type ProcessInformation struct {
- Process Handle
- Thread Handle
-diff --git a/src/syscall/zsyscall_windows.go b/src/syscall/zsyscall_windows.go
-index 2166be595b..db9e6e10ea 100644
---- a/src/syscall/zsyscall_windows.go
-+++ b/src/syscall/zsyscall_windows.go
-@@ -93,6 +93,7 @@ var (
- procCreateSymbolicLinkW = modkernel32.NewProc("CreateSymbolicLinkW")
- procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot")
- procDeleteFileW = modkernel32.NewProc("DeleteFileW")
-+ procDeleteProcThreadAttributeList = modkernel32.NewProc("DeleteProcThreadAttributeList")
- procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
- procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
- procExitProcess = modkernel32.NewProc("ExitProcess")
-@@ -131,6 +132,7 @@ var (
- procGetTempPathW = modkernel32.NewProc("GetTempPathW")
- procGetTimeZoneInformation = modkernel32.NewProc("GetTimeZoneInformation")
- procGetVersion = modkernel32.NewProc("GetVersion")
-+ procInitializeProcThreadAttributeList = modkernel32.NewProc("InitializeProcThreadAttributeList")
- procLoadLibraryW = modkernel32.NewProc("LoadLibraryW")
- procLocalFree = modkernel32.NewProc("LocalFree")
- procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
-@@ -153,6 +155,7 @@ var (
- procSetHandleInformation = modkernel32.NewProc("SetHandleInformation")
- procTerminateProcess = modkernel32.NewProc("TerminateProcess")
- procUnmapViewOfFile = modkernel32.NewProc("UnmapViewOfFile")
-+ procUpdateProcThreadAttribute = modkernel32.NewProc("UpdateProcThreadAttribute")
- procVirtualLock = modkernel32.NewProc("VirtualLock")
- procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
- procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject")
-@@ -569,6 +572,11 @@ func DeleteFile(path *uint16) (err error) {
- return
- }
-
-+func deleteProcThreadAttributeList(attrlist *_PROC_THREAD_ATTRIBUTE_LIST) {
-+ Syscall(procDeleteProcThreadAttributeList.Addr(), 1, uintptr(unsafe.Pointer(attrlist)), 0, 0)
-+ return
-+}
-+
- func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBufferSize uint32, outBuffer *byte, outBufferSize uint32, bytesReturned *uint32, overlapped *Overlapped) (err error) {
- r1, _, e1 := Syscall9(procDeviceIoControl.Addr(), 8, uintptr(handle), uintptr(ioControlCode), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferSize), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferSize), uintptr(unsafe.Pointer(bytesReturned)), uintptr(unsafe.Pointer(overlapped)), 0)
- if r1 == 0 {
-@@ -897,6 +905,14 @@ func GetVersion() (ver uint32, err error) {
- return
- }
-
-+func initializeProcThreadAttributeList(attrlist *_PROC_THREAD_ATTRIBUTE_LIST, attrcount uint32, flags uint32, size *uintptr) (err error) {
-+ r1, _, e1 := Syscall6(procInitializeProcThreadAttributeList.Addr(), 4, uintptr(unsafe.Pointer(attrlist)), uintptr(attrcount), uintptr(flags), uintptr(unsafe.Pointer(size)), 0, 0)
-+ if r1 == 0 {
-+ err = errnoErr(e1)
-+ }
-+ return
-+}
-+
- func LoadLibrary(libname string) (handle Handle, err error) {
- var _p0 *uint16
- _p0, err = UTF16PtrFromString(libname)
-@@ -1099,6 +1115,14 @@ func UnmapViewOfFile(addr uintptr) (err error) {
- return
- }
-
-+func updateProcThreadAttribute(attrlist *_PROC_THREAD_ATTRIBUTE_LIST, flags uint32, attr uintptr, value uintptr, size uintptr, prevvalue uintptr, returnedsize *uintptr) (err error) {
-+ r1, _, e1 := Syscall9(procUpdateProcThreadAttribute.Addr(), 7, uintptr(unsafe.Pointer(attrlist)), uintptr(flags), uintptr(attr), uintptr(value), uintptr(size), uintptr(prevvalue), uintptr(unsafe.Pointer(returnedsize)), 0, 0)
-+ if r1 == 0 {
-+ err = errnoErr(e1)
-+ }
-+ return
-+}
-+
- func VirtualLock(addr uintptr, length uintptr) (err error) {
- r1, _, e1 := Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0)
- if r1 == 0 {
---
-2.30.0
-
diff --git a/go-patches/0003-syscall-restrict-inherited-handles-on-Windows.patch b/go-patches/0003-syscall-restrict-inherited-handles-on-Windows.patch
deleted file mode 100644
index 13372c4c..00000000
--- a/go-patches/0003-syscall-restrict-inherited-handles-on-Windows.patch
+++ /dev/null
@@ -1,79 +0,0 @@
-From fa5c848c8db44c4e40ace3ca6a0c630500b323e3 Mon Sep 17 00:00:00 2001
-From: "Jason A. Donenfeld" <Jason@zx2c4.com>
-Date: Sun, 31 Jan 2021 17:54:27 +0100
-Subject: [PATCH 3/6] syscall: restrict inherited handles on Windows
-
-Windows does not have CLOEXEC, but rather handles are marked explicitly
-for being inherited by new processes. This isn't threadsafe, and various
-win32 functions can wind up creating a new process. syscall.StartProcess
-has traditionally used a mutex to prevent races with itself, but this
-hasn't handled races elsewhere very well.
-
-Fortunately there's a solution: PROC_THREAD_ATTRIBUTE_HANDLE_LIST allows
-us to pass the entire list of handles that we want to be inherited. This
-lets us get rid of the mutex and also makes process creation safe across
-the Go runtime.
-
-Updates #44011.
-
-Change-Id: Ia3424cd2ec64868849cbd6cbb5b0d765224bf4ab
----
- src/syscall/exec_windows.go | 24 ++++++++++++++----------
- 1 file changed, 14 insertions(+), 10 deletions(-)
-
-diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go
-index 46cbd7567d..6aea91e718 100644
---- a/src/syscall/exec_windows.go
-+++ b/src/syscall/exec_windows.go
-@@ -310,12 +310,6 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
- }
- }
-
-- // Acquire the fork lock so that no other threads
-- // create new fds that are not yet close-on-exec
-- // before we fork.
-- ForkLock.Lock()
-- defer ForkLock.Unlock()
--
- p, _ := GetCurrentProcess()
- fd := make([]Handle, len(attr.Files))
- for i := range attr.Files {
-@@ -327,7 +321,11 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
- defer CloseHandle(Handle(fd[i]))
- }
- }
-- si := new(StartupInfo)
-+ si := new(_STARTUPINFOEXW)
-+ si.ProcThreadAttributeList, err = newProcThreadAttributeList(1)
-+ if err != nil {
-+ return 0, 0, err
-+ }
- si.Cb = uint32(unsafe.Sizeof(*si))
- si.Flags = STARTF_USESTDHANDLES
- if sys.HideWindow {
-@@ -338,13 +336,19 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
- si.StdOutput = fd[1]
- si.StdErr = fd[2]
-
-+ // Do not accidentally inherit more than these handles.
-+ err = si.ProcThreadAttributeList.Add(_PROC_THREAD_ATTRIBUTE_HANDLE_LIST, unsafe.Pointer(&fd[0]), uintptr(len(fd))*unsafe.Sizeof(fd[0]))
-+ if err != nil {
-+ return 0, 0, err
-+ }
-+
- pi := new(ProcessInformation)
-
-- flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT
-+ flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT | _EXTENDED_STARTUPINFO_PRESENT
- if sys.Token != 0 {
-- err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.NoInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
-+ err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.NoInheritHandles, flags, createEnvBlock(attr.Env), dirp, &si.StartupInfo, pi)
- } else {
-- err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.NoInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
-+ err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.NoInheritHandles, flags, createEnvBlock(attr.Env), dirp, &si.StartupInfo, pi)
- }
- if err != nil {
- return 0, 0, err
---
-2.30.0
-
diff --git a/go-patches/0004-syscall-introduce-SysProcAttr.AdditionalInheritedHan.patch b/go-patches/0004-syscall-introduce-SysProcAttr.AdditionalInheritedHan.patch
deleted file mode 100644
index 74f2b235..00000000
--- a/go-patches/0004-syscall-introduce-SysProcAttr.AdditionalInheritedHan.patch
+++ /dev/null
@@ -1,55 +0,0 @@
-From cfd236cd9a5122d12047751f0ba561c81779a337 Mon Sep 17 00:00:00 2001
-From: "Jason A. Donenfeld" <Jason@zx2c4.com>
-Date: Sun, 31 Jan 2021 18:07:43 +0100
-Subject: [PATCH 4/6] syscall: introduce SysProcAttr.AdditionalInheritedHandles
- on Windows
-
-This allows users to specify handles that they explicitly want to be
-inherited by the new process. These handles must already be marked as
-inheritable.
-
-Updates #44011.
-Updates #21085.
-
-Change-Id: Ib18322e7dc2909e68c4209e80385492804fa15d3
----
- src/syscall/exec_windows.go | 16 +++++++++-------
- 1 file changed, 9 insertions(+), 7 deletions(-)
-
-diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go
-index 6aea91e718..958b11260f 100644
---- a/src/syscall/exec_windows.go
-+++ b/src/syscall/exec_windows.go
-@@ -235,13 +235,14 @@ type ProcAttr struct {
- }
-
- type SysProcAttr struct {
-- HideWindow bool
-- CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
-- CreationFlags uint32
-- Token Token // if set, runs new process in the security context represented by the token
-- ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
-- ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
-- NoInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process
-+ HideWindow bool
-+ CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
-+ CreationFlags uint32
-+ Token Token // if set, runs new process in the security context represented by the token
-+ ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
-+ ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
-+ NoInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process
-+ AdditionalInheritedHandles []Handle // a list of additional handles, already marked as inheritable, that will be inherited by the new process
- }
-
- var zeroProcAttr ProcAttr
-@@ -336,6 +337,7 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
- si.StdOutput = fd[1]
- si.StdErr = fd[2]
-
-+ fd = append(fd, sys.AdditionalInheritedHandles...)
- // Do not accidentally inherit more than these handles.
- err = si.ProcThreadAttributeList.Add(_PROC_THREAD_ATTRIBUTE_HANDLE_LIST, unsafe.Pointer(&fd[0]), uintptr(len(fd))*unsafe.Sizeof(fd[0]))
- if err != nil {
---
-2.30.0
-
diff --git a/go-patches/0005-os-mark-pipes-returned-by-os.Pipe-as-inheritable-by-.patch b/go-patches/0005-os-mark-pipes-returned-by-os.Pipe-as-inheritable-by-.patch
deleted file mode 100644
index a20f91f4..00000000
--- a/go-patches/0005-os-mark-pipes-returned-by-os.Pipe-as-inheritable-by-.patch
+++ /dev/null
@@ -1,39 +0,0 @@
-From 39d70b6441f914a41cf8568d0930c299b926c139 Mon Sep 17 00:00:00 2001
-From: "Jason A. Donenfeld" <Jason@zx2c4.com>
-Date: Sun, 31 Jan 2021 19:51:45 +0100
-Subject: [PATCH 5/6] os: mark pipes returned by os.Pipe() as inheritable by
- default
-
-Now that we don't automatically pass all inheritable handles to new
-processes, we can make pipes returned by os.Pipe() inheritable, just
-like they are on Unix. This then allows them to be passed through the
-SysProcAttr.AdditionalInheritedHandles parameter simply.
-
-Updates #44011.
-Fixes #21085.
-
-Change-Id: I8eae329fbc74f9dc7962136fa9aae8fb66879751
----
- src/os/file_windows.go | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/src/os/file_windows.go b/src/os/file_windows.go
-index dfc5fc6ce6..239690ce43 100644
---- a/src/os/file_windows.go
-+++ b/src/os/file_windows.go
-@@ -279,10 +279,10 @@ func rename(oldname, newname string) error {
- }
-
- // Pipe returns a connected pair of Files; reads from r return bytes written to w.
--// It returns the files and an error, if any.
-+// It returns the files and an error, if any. This handle is inheritable by default.
- func Pipe() (r *File, w *File, err error) {
- var p [2]syscall.Handle
-- e := syscall.CreatePipe(&p[0], &p[1], nil, 0)
-+ e := syscall.Pipe(p[:])
- if e != nil {
- return nil, nil, NewSyscallError("pipe", e)
- }
---
-2.30.0
-
diff --git a/go-patches/0006-syscall-introduce-SysProcAttr.ParentProcess-on-Windo.patch b/go-patches/0006-syscall-introduce-SysProcAttr.ParentProcess-on-Windo.patch
deleted file mode 100644
index b7453be0..00000000
--- a/go-patches/0006-syscall-introduce-SysProcAttr.ParentProcess-on-Windo.patch
+++ /dev/null
@@ -1,171 +0,0 @@
-From fd146509dda08eca30b2145deddb669b789da6e0 Mon Sep 17 00:00:00 2001
-From: "Jason A. Donenfeld" <Jason@zx2c4.com>
-Date: Sun, 31 Jan 2021 18:14:56 +0100
-Subject: [PATCH 6/6] syscall: introduce SysProcAttr.ParentProcess on Windows
-
-This allows users to specify which process should be used as the parent
-process when creating a new process.
-
-Note that this doesn't just trivially pass the handle onward to
-PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, because inherited handles must be
-valid in the parent process, so if we're changing the destination
-process, then we must also change the origin of the parent handles. And,
-the StartProcess function must clean up these handles successfully when
-exiting, regardless of where the duplication happened. So, we take care
-in this commit to use DuplicateHandle for both duplicating and for
-closing the inherited handles.
-
-The test was taken originally from CL 288272 and adjusted for use here.
-
-Fixes #44011.
-
-Change-Id: Ib3b132028dcab1aded3dc0e65126c8abebfa35eb
----
- src/syscall/exec_windows.go | 17 ++++++--
- src/syscall/exec_windows_test.go | 73 ++++++++++++++++++++++++++++++++
- 2 files changed, 87 insertions(+), 3 deletions(-)
-
-diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go
-index 958b11260f..89257be0a4 100644
---- a/src/syscall/exec_windows.go
-+++ b/src/syscall/exec_windows.go
-@@ -243,6 +243,7 @@ type SysProcAttr struct {
- ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
- NoInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process
- AdditionalInheritedHandles []Handle // a list of additional handles, already marked as inheritable, that will be inherited by the new process
-+ ParentProcess Handle // if non-zero, the new process regards the process given by this handle as its parent process
- }
-
- var zeroProcAttr ProcAttr
-@@ -312,18 +313,22 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
- }
-
- p, _ := GetCurrentProcess()
-+ parentProcess := p
-+ if sys.ParentProcess != 0 {
-+ parentProcess = sys.ParentProcess
-+ }
- fd := make([]Handle, len(attr.Files))
- for i := range attr.Files {
- if attr.Files[i] > 0 {
-- err := DuplicateHandle(p, Handle(attr.Files[i]), p, &fd[i], 0, true, DUPLICATE_SAME_ACCESS)
-+ err := DuplicateHandle(p, Handle(attr.Files[i]), parentProcess, &fd[i], 0, true, DUPLICATE_SAME_ACCESS)
- if err != nil {
- return 0, 0, err
- }
-- defer CloseHandle(Handle(fd[i]))
-+ defer DuplicateHandle(parentProcess, fd[i], 0, nil, 0, false, DUPLICATE_CLOSE_SOURCE)
- }
- }
- si := new(_STARTUPINFOEXW)
-- si.ProcThreadAttributeList, err = newProcThreadAttributeList(1)
-+ si.ProcThreadAttributeList, err = newProcThreadAttributeList(2)
- if err != nil {
- return 0, 0, err
- }
-@@ -333,6 +338,12 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
- si.Flags |= STARTF_USESHOWWINDOW
- si.ShowWindow = SW_HIDE
- }
-+ if sys.ParentProcess != 0 {
-+ err = si.ProcThreadAttributeList.Add(_PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, unsafe.Pointer(&sys.ParentProcess), unsafe.Sizeof(sys.ParentProcess))
-+ if err != nil {
-+ return 0, 0, err
-+ }
-+ }
- si.StdInput = fd[0]
- si.StdOutput = fd[1]
- si.StdErr = fd[2]
-diff --git a/src/syscall/exec_windows_test.go b/src/syscall/exec_windows_test.go
-index eda1d36877..8a1c2ceaae 100644
---- a/src/syscall/exec_windows_test.go
-+++ b/src/syscall/exec_windows_test.go
-@@ -5,8 +5,14 @@
- package syscall_test
-
- import (
-+ "fmt"
-+ "io/ioutil"
-+ "os"
-+ "os/exec"
-+ "path/filepath"
- "syscall"
- "testing"
-+ "time"
- )
-
- func TestEscapeArg(t *testing.T) {
-@@ -41,3 +47,70 @@ func TestEscapeArg(t *testing.T) {
- }
- }
- }
-+
-+func TestChangingProcessParent(t *testing.T) {
-+ if os.Getenv("GO_WANT_HELPER_PROCESS") == "parent" {
-+ // in parent process
-+
-+ // Parent does nothign. It is just used as a parent of a child process.
-+ time.Sleep(time.Minute)
-+ os.Exit(0)
-+ }
-+
-+ if os.Getenv("GO_WANT_HELPER_PROCESS") == "child" {
-+ // in child process
-+ dumpPath := os.Getenv("GO_WANT_HELPER_PROCESS_FILE")
-+ if dumpPath == "" {
-+ fmt.Fprintf(os.Stderr, "Dump file path cannot be blank.")
-+ os.Exit(1)
-+ }
-+ err := os.WriteFile(dumpPath, []byte(fmt.Sprintf("%d", os.Getppid())), 0644)
-+ if err != nil {
-+ fmt.Fprintf(os.Stderr, "Error writing dump file: %v", err)
-+ os.Exit(2)
-+ }
-+ os.Exit(0)
-+ }
-+
-+ // run parent process
-+
-+ parent := exec.Command(os.Args[0], "-test.run=TestChangingProcessParent")
-+ parent.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=parent")
-+ err := parent.Start()
-+ if err != nil {
-+ t.Fatal(err)
-+ }
-+ defer func() {
-+ parent.Process.Kill()
-+ parent.Wait()
-+ }()
-+
-+ // run child process
-+
-+ const _PROCESS_CREATE_PROCESS = 0x0080
-+ const _PROCESS_DUP_HANDLE = 0x0040
-+ childDumpPath := filepath.Join(t.TempDir(), "ppid.txt")
-+ ph, err := syscall.OpenProcess(_PROCESS_CREATE_PROCESS|_PROCESS_DUP_HANDLE|syscall.PROCESS_QUERY_INFORMATION,
-+ false, uint32(parent.Process.Pid))
-+ if err != nil {
-+ t.Fatal(err)
-+ }
-+ defer syscall.CloseHandle(ph)
-+
-+ child := exec.Command(os.Args[0], "-test.run=TestChangingProcessParent")
-+ child.Env = append(os.Environ(),
-+ "GO_WANT_HELPER_PROCESS=child",
-+ "GO_WANT_HELPER_PROCESS_FILE="+childDumpPath)
-+ child.SysProcAttr = &syscall.SysProcAttr{ParentProcess: ph}
-+ childOutput, err := child.CombinedOutput()
-+ if err != nil {
-+ t.Errorf("child failed: %v: %v", err, string(childOutput))
-+ }
-+ childOutput, err = ioutil.ReadFile(childDumpPath)
-+ if err != nil {
-+ t.Fatalf("reading child ouput failed: %v", err)
-+ }
-+ if got, want := string(childOutput), fmt.Sprintf("%d", parent.Process.Pid); got != want {
-+ t.Fatalf("child output: want %q, got %q", want, got)
-+ }
-+}
---
-2.30.0
-
diff --git a/go.mod b/go.mod
index 0e5a47bc..ac8314b1 100644
--- a/go.mod
+++ b/go.mod
@@ -1,18 +1,18 @@
module golang.zx2c4.com/wireguard/windows
-go 1.15
+go 1.16
require (
github.com/lxn/walk v0.0.0-20210112085537-c389da54e794
github.com/lxn/win v0.0.0-20201111105847-2a20daff6a55
- golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
- golang.org/x/net v0.0.0-20210119194325-5f4716e94777
- golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c
+ golang.org/x/crypto v0.0.0-20210218145215-b8e89b74b9df
+ golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
+ golang.org/x/sys v0.0.0-20210218145245-beda7e5e158e
golang.org/x/text v0.3.5
- golang.zx2c4.com/wireguard v0.0.0-20210203165646-9c7bd73be2cc
+ golang.zx2c4.com/wireguard v0.0.0-20210217211927-8bf4204d2ea3
)
replace (
github.com/lxn/walk => golang.zx2c4.com/wireguard/windows v0.0.0-20210121140954-e7fc19d483bd
- github.com/lxn/win => golang.zx2c4.com/wireguard/windows v0.0.0-20201107183008-659a4e955570
+ github.com/lxn/win => golang.zx2c4.com/wireguard/windows v0.0.0-20210203225805-358658953538
)
diff --git a/go.mod.master b/go.mod.master
index 6993a3ac..a61c1ed9 100644
--- a/go.mod.master
+++ b/go.mod.master
@@ -1,6 +1,6 @@
module golang.zx2c4.com/wireguard/windows
-go 1.15
+go 1.16
require (
github.com/lxn/walk latest
diff --git a/go.sum b/go.sum
index 276004c5..30af4381 100644
--- a/go.sum
+++ b/go.sum
@@ -1,6 +1,7 @@
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
+golang.org/x/crypto v0.0.0-20210218145215-b8e89b74b9df h1:y7QZzfUiTwWam+xBn29Ulb8CBwVN5UdzmMDavl9Whlw=
+golang.org/x/crypto v0.0.0-20210218145215-b8e89b74b9df/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
@@ -10,8 +11,8 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210105210732-16f7687f5001/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
-golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210218145245-beda7e5e158e h1:f5mksnk+hgXHnImpZoWj64ja99j9zV7YUgrVG95uFE4=
+golang.org/x/sys v0.0.0-20210218145245-beda7e5e158e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -20,9 +21,9 @@ golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.zx2c4.com/wireguard v0.0.0-20210203165646-9c7bd73be2cc h1:Ry6kx9k19dltIUYhpT57DOY2ti0x1LHngiF72USugrc=
-golang.zx2c4.com/wireguard v0.0.0-20210203165646-9c7bd73be2cc/go.mod h1:r0ExowOoGFfDoLDxx+M9SYbNVsoZ0xviLL+K4f2mt+A=
-golang.zx2c4.com/wireguard/windows v0.0.0-20201107183008-659a4e955570 h1:sbXpfRwl+7YQY72KBuzyacG7ucr6w4OueJiEb7+pvSk=
-golang.zx2c4.com/wireguard/windows v0.0.0-20201107183008-659a4e955570/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk=
+golang.zx2c4.com/wireguard v0.0.0-20210217211927-8bf4204d2ea3 h1:1TprVg/dTRUXeAsC6hY1gqxwYiFVIVQd3CCeLVwmeaM=
+golang.zx2c4.com/wireguard v0.0.0-20210217211927-8bf4204d2ea3/go.mod h1:LofpIKqPJNvHiwKXuzsBshJCTe7IgRAz3iizquljFDk=
golang.zx2c4.com/wireguard/windows v0.0.0-20210121140954-e7fc19d483bd h1:kAUzMAITME2MCtrXBaUa9P4tndiXGWO674k9gn6ZR28=
golang.zx2c4.com/wireguard/windows v0.0.0-20210121140954-e7fc19d483bd/go.mod h1:Y+FYqVFaQO6a+1uigm0N0GiuaZrLEaBxEiJ8tfH9sMQ=
+golang.zx2c4.com/wireguard/windows v0.0.0-20210203225805-358658953538 h1:4QShzjqAmuoTMDIiormkQzuVDBqbK1E8yjoo9bspbkk=
+golang.zx2c4.com/wireguard/windows v0.0.0-20210203225805-358658953538/go.mod h1:KxxjdtRkfNoYDCUP5ryK7XJJNTnpC8atvtmTheChOtk=
diff --git a/main.go b/main.go
index 84c8ebe0..5862d4e3 100644
--- a/main.go
+++ b/main.go
@@ -11,7 +11,6 @@ import (
"fmt"
"log"
"os"
- "runtime"
"strconv"
"strings"
"time"
@@ -68,10 +67,6 @@ func checkForWow64() {
var processMachine, nativeMachine uint16
err := windows.IsWow64Process2(windows.CurrentProcess(), &processMachine, &nativeMachine)
if err == nil {
- if nativeMachine == pe.IMAGE_FILE_MACHINE_ARM64 && runtime.GOARCH == "arm" {
- //TODO: remove this exception when Go supports arm64
- return false, nil
- }
return processMachine != pe.IMAGE_FILE_MACHINE_UNKNOWN, nil
}
if !errors.Is(err, windows.ERROR_PROC_NOT_FOUND) {
diff --git a/ui/aboutdialog.go b/ui/aboutdialog.go
index 5fc478c8..f9be1f90 100644
--- a/ui/aboutdialog.go
+++ b/ui/aboutdialog.go
@@ -95,7 +95,7 @@ func runAboutDialog(owner walk.Form) error {
return err
}
detailsLbl.SetTextAlignment(walk.AlignHCenterVNear)
- detailsLbl.SetText(l18n.Sprintf("App version: %s\nGo backend version: %s\nGo version: %s-%s\nOperating system: %s\nArchitecture: %s", version.Number, version.ProtoImplementation(), strings.TrimPrefix(runtime.Version(), "go"), runtime.GOARCH, version.OsName(), version.NativeArch()))
+ detailsLbl.SetText(l18n.Sprintf("App version: %s\nGo backend version: %s\nGo version: %s-%s\nOperating system: %s\nArchitecture: %s", version.Number, version.ProtoImplementation(), strings.TrimPrefix(runtime.Version(), "go"), runtime.GOARCH, version.OsName(), version.Arch()))
copyrightLbl, err := walk.NewTextLabel(showingAboutDialog)
if err != nil {
diff --git a/updater/versions.go b/updater/versions.go
index a6671b12..5b42a748 100644
--- a/updater/versions.go
+++ b/updater/versions.go
@@ -54,7 +54,7 @@ func versionNewerThanUs(candidate string) (bool, error) {
}
func findCandidate(candidates fileList) (*UpdateFound, error) {
- prefix := fmt.Sprintf(msiArchPrefix, version.NativeArch())
+ prefix := fmt.Sprintf(msiArchPrefix, version.Arch())
suffix := msiSuffix
for name, hash := range candidates {
if strings.HasPrefix(name, prefix) && strings.HasSuffix(name, suffix) {
diff --git a/version/useragent.go b/version/useragent.go
index 8062ec52..698e185b 100644
--- a/version/useragent.go
+++ b/version/useragent.go
@@ -6,64 +6,21 @@
package version
import (
- "debug/pe"
- "errors"
"fmt"
"runtime"
-
- "golang.org/x/sys/windows"
)
-var arch string
-
-func NativeArch() string {
- if len(arch) > 0 {
- return arch
- }
- var processMachine, nativeMachine uint16
- err := windows.IsWow64Process2(windows.CurrentProcess(), &processMachine, &nativeMachine)
- if err != nil && errors.Is(err, windows.ERROR_PROC_NOT_FOUND) {
- var b bool
- err = windows.IsWow64Process(windows.CurrentProcess(), &b)
- if err != nil {
- panic(err)
- }
- if b && runtime.GOARCH == "x86" {
- nativeMachine = pe.IMAGE_FILE_MACHINE_AMD64
- } else if b && runtime.GOARCH == "arm" {
- nativeMachine = pe.IMAGE_FILE_MACHINE_ARM64
- } else {
- switch runtime.GOARCH {
- case "arm":
- nativeMachine = pe.IMAGE_FILE_MACHINE_ARMNT
- case "arm64":
- nativeMachine = pe.IMAGE_FILE_MACHINE_ARM64
- case "amd64":
- nativeMachine = pe.IMAGE_FILE_MACHINE_AMD64
- case "386":
- nativeMachine = pe.IMAGE_FILE_MACHINE_I386
- default:
- panic("Unrecognized GOARCH")
- }
- }
- } else if err != nil {
- panic(err)
- }
- switch nativeMachine {
- case pe.IMAGE_FILE_MACHINE_ARMNT:
- arch = "arm"
- case pe.IMAGE_FILE_MACHINE_ARM64:
- arch = "arm64"
- case pe.IMAGE_FILE_MACHINE_AMD64:
- arch = "amd64"
- case pe.IMAGE_FILE_MACHINE_I386:
- arch = "x86"
+func Arch() string {
+ switch runtime.GOARCH {
+ case "arm", "arm64", "amd64":
+ return runtime.GOARCH
+ case "386":
+ return "x86"
default:
- panic("Unrecognized machine type")
+ panic("Unrecognized GOARCH")
}
- return arch
}
func UserAgent() string {
- return fmt.Sprintf("WireGuard/%s (%s; %s)", Number, OsName(), NativeArch())
+ return fmt.Sprintf("WireGuard/%s (%s; %s)", Number, OsName(), Arch())
}