diff options
author | Simon Rozman <simon@rozman.si> | 2020-11-09 15:38:10 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-11-13 14:42:54 +0100 |
commit | 22647958aee9828ecdd16f09e3a1bdf6b606578f (patch) | |
tree | 40dea82c966d1e33fe35b57cf653bf2c66ece234 | |
parent | build: make arm64 binary by copying arm binary (diff) | |
download | wireguard-windows-22647958aee9828ecdd16f09e3a1bdf6b606578f.tar.xz wireguard-windows-22647958aee9828ecdd16f09e3a1bdf6b606578f.zip |
installer: updater: introduce ARM64 MSI packages
Windows 10 ARM64 refuses to install ARM MSI.
Signed-off-by: Simon Rozman <simon@rozman.si>
-rw-r--r-- | installer/.gitignore | 1 | ||||
-rw-r--r-- | installer/build.bat | 3 | ||||
-rw-r--r-- | installer/wireguard.wxs | 4 | ||||
-rw-r--r-- | updater/mksyscall.go | 8 | ||||
-rw-r--r-- | updater/syscall_windows.go | 55 | ||||
-rw-r--r-- | updater/versions.go | 15 | ||||
-rw-r--r-- | updater/versions_arm.go | 34 | ||||
-rw-r--r-- | updater/versions_default.go | 28 | ||||
-rw-r--r-- | updater/zsyscall_windows.go | 52 |
9 files changed, 186 insertions, 14 deletions
diff --git a/installer/.gitignore b/installer/.gitignore index 3b5ee366..fc4d2127 100644 --- a/installer/.gitignore +++ b/installer/.gitignore @@ -6,3 +6,4 @@ /x86 /amd64 /arm +/arm64 diff --git a/installer/build.bat b/installer/build.bat index f7ac7246..ae8a24e3 100644 --- a/installer/build.bat +++ b/installer/build.bat @@ -20,7 +20,7 @@ if exist .deps\prepared goto :build rmdir /s /q .deps 2> NUL mkdir .deps || goto :error cd .deps || goto :error - call :download wix-binaries.zip https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip 2c1888d5d1dba377fc7fa14444cf556963747ff9a0a289a3599cf09da03b9e2e || goto :error + call :download wix-binaries.zip https://wixtoolset.org/downloads/v3.14.0.4118/wix314-binaries.zip 34dcbba9952902bfb710161bd45ee2e721ffa878db99f738285a21c9b09c6edb || goto :error echo [+] Extracting wix-binaries.zip mkdir wix\bin || goto :error tar -xf wix-binaries.zip -C wix\bin || goto :error @@ -38,6 +38,7 @@ if exist .deps\prepared goto :build call :msi x86 i686 x86 || goto :error call :msi amd64 x86_64 x64 || goto :error call :msi arm armv7 arm || goto :error + call :msi arm64 aarch64 arm64 || goto :error if exist ..\sign.bat call ..\sign.bat if "%SigningCertificate%"=="" goto :success if "%TimestampServer%"=="" goto :success diff --git a/installer/wireguard.wxs b/installer/wireguard.wxs index 85e09e08..56d00163 100644 --- a/installer/wireguard.wxs +++ b/installer/wireguard.wxs @@ -5,7 +5,7 @@ Copyright (C) 2019 WireGuard LLC. All Rights Reserved. --> -<?if $(var.WIREGUARD_PLATFORM) = "amd64"?> +<?if $(var.WIREGUARD_PLATFORM) = "amd64" Or $(var.WIREGUARD_PLATFORM) = "arm64"?> <?define PlatformProgramFilesFolder = "ProgramFiles64Folder"?> <?else?> <?define PlatformProgramFilesFolder = "ProgramFilesFolder"?> @@ -16,6 +16,8 @@ <?define UpgradeCode = "62754a0a-fee9-4412-b739-e8da2e7c9405"?> <?elseif $(var.WIREGUARD_PLATFORM) = "arm"?> <?define UpgradeCode = "f90bca59-9627-431d-92b4-a5c2d9a529ff"?> +<?elseif $(var.WIREGUARD_PLATFORM) = "arm64"?> + <?define UpgradeCode = "7ff76099-8940-4d3e-99b9-50a3b3ca1ee9"?> <?else?> <?error Unknown platform ?> <?endif?> diff --git a/updater/mksyscall.go b/updater/mksyscall.go new file mode 100644 index 00000000..8287e501 --- /dev/null +++ b/updater/mksyscall.go @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019-2020 WireGuard LLC. All Rights Reserved. + */ + +package updater + +//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go syscall_windows.go diff --git a/updater/syscall_windows.go b/updater/syscall_windows.go new file mode 100644 index 00000000..0410e708 --- /dev/null +++ b/updater/syscall_windows.go @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019-2020 WireGuard LLC. All Rights Reserved. + */ + +package updater + +import "golang.org/x/sys/windows" + +const ( + // TODO: Push those constants upstream. golang.zx2c4.com/wireguard/tun/wintun/memmod is declaring them too. It will share the benefit. + IMAGE_FILE_MACHINE_UNKNOWN = 0 + IMAGE_FILE_MACHINE_TARGET_HOST = 0x0001 // Useful for indicating we want to interact with the host and not a WoW guest. + IMAGE_FILE_MACHINE_I386 = 0x014c // Intel 386. + IMAGE_FILE_MACHINE_R3000 = 0x0162 // MIPS little-endian, 0x160 big-endian + IMAGE_FILE_MACHINE_R4000 = 0x0166 // MIPS little-endian + IMAGE_FILE_MACHINE_R10000 = 0x0168 // MIPS little-endian + IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x0169 // MIPS little-endian WCE v2 + IMAGE_FILE_MACHINE_ALPHA = 0x0184 // Alpha_AXP + IMAGE_FILE_MACHINE_SH3 = 0x01a2 // SH3 little-endian + IMAGE_FILE_MACHINE_SH3DSP = 0x01a3 + IMAGE_FILE_MACHINE_SH3E = 0x01a4 // SH3E little-endian + IMAGE_FILE_MACHINE_SH4 = 0x01a6 // SH4 little-endian + IMAGE_FILE_MACHINE_SH5 = 0x01a8 // SH5 + IMAGE_FILE_MACHINE_ARM = 0x01c0 // ARM Little-Endian + IMAGE_FILE_MACHINE_THUMB = 0x01c2 // ARM Thumb/Thumb-2 Little-Endian + IMAGE_FILE_MACHINE_ARMNT = 0x01c4 // ARM Thumb-2 Little-Endian + IMAGE_FILE_MACHINE_AM33 = 0x01d3 + IMAGE_FILE_MACHINE_POWERPC = 0x01F0 // IBM PowerPC Little-Endian + IMAGE_FILE_MACHINE_POWERPCFP = 0x01f1 + IMAGE_FILE_MACHINE_IA64 = 0x0200 // Intel 64 + IMAGE_FILE_MACHINE_MIPS16 = 0x0266 // MIPS + IMAGE_FILE_MACHINE_ALPHA64 = 0x0284 // ALPHA64 + IMAGE_FILE_MACHINE_MIPSFPU = 0x0366 // MIPS + IMAGE_FILE_MACHINE_MIPSFPU16 = 0x0466 // MIPS + IMAGE_FILE_MACHINE_AXP64 = IMAGE_FILE_MACHINE_ALPHA64 + IMAGE_FILE_MACHINE_TRICORE = 0x0520 // Infineon + IMAGE_FILE_MACHINE_CEF = 0x0CEF + IMAGE_FILE_MACHINE_EBC = 0x0EBC // EFI Byte Code + IMAGE_FILE_MACHINE_AMD64 = 0x8664 // AMD64 (K8) + IMAGE_FILE_MACHINE_M32R = 0x9041 // M32R little-endian + IMAGE_FILE_MACHINE_ARM64 = 0xAA64 // ARM64 Little-Endian + IMAGE_FILE_MACHINE_CEE = 0xC0EE +) + +//sys isWow64Process2Internal(process windows.Handle, processMachine *uint16, nativeMachine *uint16) (err error) = kernel32.IsWow64Process2 + +func isWow64Process2(process windows.Handle) (processMachine, nativeMachine uint16, err error) { + err = procIsWow64Process2.Find() + if err != nil { + return + } + err = isWow64Process2Internal(process, &processMachine, &nativeMachine) + return +} diff --git a/updater/versions.go b/updater/versions.go index c0009ad8..08830d32 100644 --- a/updater/versions.go +++ b/updater/versions.go @@ -8,7 +8,6 @@ package updater import ( "errors" "fmt" - "runtime" "strconv" "strings" @@ -55,17 +54,9 @@ func versionNewerThanUs(candidate string) (bool, error) { } func findCandidate(candidates fileList) (*UpdateFound, error) { - var arch string - if runtime.GOARCH == "amd64" { - arch = "amd64" - } else if runtime.GOARCH == "386" { - arch = "x86" - } else if runtime.GOARCH == "arm" { - arch = "arm" - } else if runtime.GOARCH == "arm64" { - arch = "arm64" - } else { - return nil, errors.New("Invalid GOARCH") + arch, err := findArch() + if err != nil { + return nil, err } prefix := fmt.Sprintf(msiArchPrefix, arch) suffix := msiSuffix diff --git a/updater/versions_arm.go b/updater/versions_arm.go new file mode 100644 index 00000000..2ffb4b74 --- /dev/null +++ b/updater/versions_arm.go @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019-2020 WireGuard LLC. All Rights Reserved. + */ + +package updater + +import ( + "errors" + + "golang.org/x/sys/windows" +) + +func findArch() (arch string, err error) { + process := windows.CurrentProcess() + _, nativeMachine, err2 := isWow64Process2(process) + if err2 != nil { + var isWow64 bool + if windows.IsWow64Process(process, &isWow64) != nil || !isWow64 { + nativeMachine = IMAGE_FILE_MACHINE_ARMNT + } else { + nativeMachine = IMAGE_FILE_MACHINE_ARM64 + } + } + switch nativeMachine { + case IMAGE_FILE_MACHINE_ARM64: + arch = "arm64" + case IMAGE_FILE_MACHINE_ARMNT: + arch = "arm" + default: + err = errors.New("Invalid GOARCH") + } + return +} diff --git a/updater/versions_default.go b/updater/versions_default.go new file mode 100644 index 00000000..268e97ce --- /dev/null +++ b/updater/versions_default.go @@ -0,0 +1,28 @@ +// +build !arm + +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019-2020 WireGuard LLC. All Rights Reserved. + */ + +package updater + +import ( + "errors" + "runtime" +) + +func findArch() (arch string, err error) { + if runtime.GOARCH == "amd64" { + arch = "amd64" + } else if runtime.GOARCH == "386" { + arch = "x86" + } else if runtime.GOARCH == "arm" { + arch = "arm" + } else if runtime.GOARCH == "arm64" { + arch = "arm64" + } else { + err = errors.New("Invalid GOARCH") + } + return +} diff --git a/updater/zsyscall_windows.go b/updater/zsyscall_windows.go new file mode 100644 index 00000000..a2d32cc9 --- /dev/null +++ b/updater/zsyscall_windows.go @@ -0,0 +1,52 @@ +// Code generated by 'go generate'; DO NOT EDIT. + +package updater + +import ( + "syscall" + "unsafe" + + "golang.org/x/sys/windows" +) + +var _ unsafe.Pointer + +// Do the interface allocations only once for common +// Errno values. +const ( + errnoERROR_IO_PENDING = 997 +) + +var ( + errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) + errERROR_EINVAL error = syscall.EINVAL +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return errERROR_EINVAL + case errnoERROR_IO_PENDING: + return errERROR_IO_PENDING + } + // TODO: add more here, after collecting data on the common + // error values see on Windows. (perhaps when running + // all.bat?) + return e +} + +var ( + modkernel32 = windows.NewLazySystemDLL("kernel32.dll") + + procIsWow64Process2 = modkernel32.NewProc("IsWow64Process2") +) + +func isWow64Process2Internal(process windows.Handle, processMachine *uint16, nativeMachine *uint16) (err error) { + r1, _, e1 := syscall.Syscall(procIsWow64Process2.Addr(), 3, uintptr(process), uintptr(unsafe.Pointer(processMachine)), uintptr(unsafe.Pointer(nativeMachine))) + if r1 == 0 { + err = errnoErr(e1) + } + return +} |