Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds HostInfo.NativeArchitecture #200

Merged
merged 6 commits into from
Feb 12, 2024
Merged

Conversation

intxgo
Copy link
Contributor

@intxgo intxgo commented Feb 5, 2024

Adds NativeArchitecture to HostInfo to empower applications to detect if they are run in emulation.

Modern desktop operating systems ported to the ARM architecture include capabilities to run x86 applications via binary translation to ease the technological transition. This is usually fine, except for applications that rely on a specific native platform, such as for installing native drivers.

Testing

Tested in the following configurations:

ARM64 CPU

macOS

  • native binary
GOARCH arm64
Architecture arm64
NativeArchitecture arm64
  • AMD64 binary
GOARCH amd64
Architecture x64_64
NativeArchitecture arm64

Linux

  • native binary
GOARCH arm64
Architecture aarch64
NativeArchitecture aarch64
  • AMD64 binary
GOARCH amd64
Architecture x64_64
NativeArchitecture aarch64

Windows

  • native binary

N/A as Go doesn't support GOOS=Windows GOARCH=arm64

  • AMD64 binary
GOARCH amd64
Architecture x64_64
NativeArchitecture arm64

AMD64 CPU

macOS

  • native binary
GOARCH amd64
Architecture x64_64
NativeArchitecture x64_64
  • ARM64 binary

N/A as Rosetta 2 is not supported on Intel platform

Linux

  • native binary
GOARCH amd64
Architecture x64_64
NativeArchitecture x64_64
  • ARM64 binary
GOARCH amd64
Architecture aarch64
NativeArchitecture x64_64

Windows

  • native binary
GOARCH amd64
Architecture x64_64
NativeArchitecture x64_64
  • ARM64 binary

N/A as Go doesn't support GOOS=Windows GOARCH=arm64

@andrewkroh andrewkroh added the enhancement New feature or request label Feb 6, 2024
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's cool that we can detect the presence of Rosetta. I had no idea about sysctl.proc_translated.

providers/windows/arch_windows.go Outdated Show resolved Hide resolved
providers/windows/arch_windows.go Outdated Show resolved Hide resolved
providers/windows/arch_windows.go Outdated Show resolved Hide resolved
providers/linux/arch_linux.go Show resolved Hide resolved
providers/linux/arch_linux.go Show resolved Hide resolved
providers/darwin/arch_darwin.go Outdated Show resolved Hide resolved
andrewkroh
andrewkroh previously approved these changes Feb 7, 2024
@fearful-symmetry
Copy link
Contributor

fearful-symmetry commented Feb 8, 2024

So, I just commented for now, but I'm a little worried that Architecture and NativeArchitecture might be functionally the same on linux.

func NativeArchitecture() (string, error) {
var processMachine, nativeMachine uint16
// the pseudo handle doesn't need to be closed
var currentProcessHandle = windows.CurrentProcess()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to close this handle after we're done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, as the explicit comment says. If you're not convinced check the manual

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, we've had issues with leaving handles open, so I'm a tad paranoid...

Copy link
Contributor

@fearful-symmetry fearful-symmetry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine, but I'm personally curious if we have a way to test the behavior of this under linux? On Darwin we have Rosetta, but is there some similar linux utility we're hoping to support?

@intxgo
Copy link
Contributor Author

intxgo commented Feb 12, 2024

Code looks fine, but I'm personally curious if we have a way to test the behavior of this under linux? On Darwin we have Rosetta, but is there some similar linux utility we're hoping to support?

Linux multiarch, that's how we run x86-64 tools in linux on Apple macbooks, etc

It's quite the contrary, we want to fail gracefully in products which cannot be run in emulation instead of giving the false impression that something is wrong with them.

@jlind23 jlind23 merged commit 80edf3d into elastic:main Feb 12, 2024
23 checks passed
@intxgo intxgo deleted the native-architecture branch February 12, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants