From 791d8a0f4d093bd8fe272dea2cd28991154796fb Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 25 May 2019 15:13:12 +0200 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- windows/syscall_windows.go | 1 + windows/zsyscall_windows.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go index a0592309..c37fbccd 100644 --- a/windows/syscall_windows.go +++ b/windows/syscall_windows.go @@ -138,6 +138,7 @@ func NewCallbackCDecl(fn interface{}) uintptr { //sys GetVersion() (ver uint32, err error) //sys FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) = FormatMessageW //sys ExitProcess(exitcode uint32) +//sys IsWow64Process(handle Handle, isWow64 *bool) (err error) = IsWow64Process //sys CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile Handle) (handle Handle, err error) [failretval==InvalidHandle] = CreateFileW //sys ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) //sys WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go index 7520defd..25e88389 100644 --- a/windows/zsyscall_windows.go +++ b/windows/zsyscall_windows.go @@ -76,6 +76,7 @@ var ( procGetVersion = modkernel32.NewProc("GetVersion") procFormatMessageW = modkernel32.NewProc("FormatMessageW") procExitProcess = modkernel32.NewProc("ExitProcess") + procIsWow64Process = modkernel32.NewProc("IsWow64Process") procCreateFileW = modkernel32.NewProc("CreateFileW") procReadFile = modkernel32.NewProc("ReadFile") procWriteFile = modkernel32.NewProc("WriteFile") @@ -646,6 +647,18 @@ func ExitProcess(exitcode uint32) { return } +func IsWow64Process(handle Handle, isWow64 *bool) (err error) { + r1, _, e1 := syscall.Syscall(procIsWow64Process.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(isWow64)), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile Handle) (handle Handle, err error) { r0, _, e1 := syscall.Syscall9(procCreateFileW.Addr(), 7, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0) handle = Handle(r0)