aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/main.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-11 22:28:06 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-16 18:17:05 +0100
commit52966eadb5216e8fb4a3f52dd2a712403eceb4a9 (patch)
tree8c0425fc2f232e161abfa5d96d47eda679e09e43 /main.go
parentupdater: use constants from debug/pe (diff)
downloadwireguard-windows-52966eadb5216e8fb4a3f52dd2a712403eceb4a9.tar.xz
wireguard-windows-52966eadb5216e8fb4a3f52dd2a712403eceb4a9.zip
main: check for x86 emulation on arm
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'main.go')
-rw-r--r--main.go43
1 files changed, 38 insertions, 5 deletions
diff --git a/main.go b/main.go
index 2bf20a09..0c12ce93 100644
--- a/main.go
+++ b/main.go
@@ -6,13 +6,16 @@
package main
import (
+ "debug/pe"
"fmt"
"log"
"os"
"runtime"
"strconv"
"strings"
+ "syscall"
"time"
+ "unsafe"
"golang.org/x/sys/windows"
"golang.zx2c4.com/wireguard/tun"
@@ -61,17 +64,47 @@ func usage() {
os.Exit(1)
}
-func checkForWow64() {
- if runtime.GOARCH == "arm" { //TODO: remove this exception when Go supports arm64
+//TODO: replace with https://go-review.googlesource.com/c/sys/+/269077 once merged
+func isWow64Process2(handle windows.Handle, processMachine *uint16, nativeMachine *uint16) (err error) {
+ p := windows.NewLazySystemDLL("kernel32.dll").NewProc("IsWow64Process2")
+ err = p.Find()
+ if err != nil {
return
}
- var b bool
- err := windows.IsWow64Process(windows.CurrentProcess(), &b)
+ ret, _, e := syscall.Syscall(p.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(processMachine)), uintptr(unsafe.Pointer(nativeMachine)))
+ if ret == 0 {
+ err = e
+ return err
+ }
+ return
+}
+
+func checkForWow64() {
+ b, err := func() (bool, error) {
+ var processMachine, nativeMachine uint16
+ err := 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 _, isDllErr := err.(*windows.DLLError); !isDllErr {
+ return false, err
+ }
+ var b bool
+ err = windows.IsWow64Process(windows.CurrentProcess(), &b)
+ if err != nil {
+ return false, err
+ }
+ return b, nil
+ }()
if err != nil {
fatalf("Unable to determine whether the process is running under WOW64: %v", err)
}
if b {
- fatalf("You must use the 64-bit version of WireGuard on this computer.")
+ fatalf("You must use the native version of WireGuard on this computer.")
}
}