Skip to content

Commit

Permalink
HostInfo.NativeArchitecture support older Windows builds (#201)
Browse files Browse the repository at this point in the history
Function IsWow64Process2 was introduced in Windows 10 version 1709, 
so ensure that ERROR_PROC_NOT_FOUND is handled on earlier versions.

NOTE: Only x86 (32 bit) applications can be run on Windows 10 on ARM.
Windows 11 on ARM also supports x86_64 (64 bit) applications.
  • Loading branch information
intxgo authored Feb 13, 2024
1 parent 80edf3d commit 92fd1d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/201.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
HostInfo.NativeArchitecture is not available on Windows system prior Windows 10 version 1709.
```
11 changes: 11 additions & 0 deletions providers/windows/arch_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package windows

import (
"errors"

"golang.org/x/sys/windows"

gowindows "github.com/elastic/go-windows"
Expand All @@ -44,8 +46,17 @@ func NativeArchitecture() (string, error) {
// the pseudo handle doesn't need to be closed
var currentProcessHandle = windows.CurrentProcess()

// IsWow64Process2 was introduced in version 1709 (build 16299 acording to the tables)
// https://learn.microsoft.com/en-us/windows/release-health/release-information
// https://learn.microsoft.com/en-us/windows/release-health/windows-server-release-info
err := windows.IsWow64Process2(currentProcessHandle, &processMachine, &nativeMachine)
if err != nil {
if errors.Is(err, windows.ERROR_PROC_NOT_FOUND) {
major, minor, build := windows.RtlGetNtVersionNumbers()
if major < 10 || (major == 10 && minor == 0 && build < 16299) {
return "", nil
}
}
return "", err
}

Expand Down

0 comments on commit 92fd1d4

Please sign in to comment.