Jelajahi Sumber

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 <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Jason A. Donenfeld 6 tahun lalu
induk
melakukan
791d8a0f4d
2 mengubah file dengan 14 tambahan dan 0 penghapusan
  1. 1 0
      windows/syscall_windows.go
  2. 13 0
      windows/zsyscall_windows.go

+ 1 - 0
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)

+ 13 - 0
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)