Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

API to retrieve CPU and App architecture #7

Open
@bruno-garcia

Description

@bruno-garcia

The goal is to have a simple API that will return:

  1. Operating system architecture
  2. Application architecture

SharpRaven has some implementation although it mixes things a bit:

One thing to keep in mind is the difference of OS arch and App arch. An app can be 32 bit on a 64 bit operating system.

.NET Standard 2.0 include API for both:

  1. RuntimeInformation.OSArchitecture
  2. RuntimeInformation.ProcessArchitecture

Both return a value from the enum:

  public enum Architecture
  {
    X86, X64, Arm, Arm64,
  }

That is good news. It is also supported by Xamarin/iOS/Mac/Android but we still need to find a way on other targets since this is not available on .NET Framework prior to 4.7.1 according to MSDN

To verify the CPU arch, the SharpRaven version linked above also considers environment variable, which should always be available on Windows but is not reliable on macOS nor Linux since it's non-POSIX, bash extension. The code also calls into Win32 API when verifying the OS version supports it. It does so without a IsWindows call before doing so. This should be considered on the new implementation.

To check the App arch, a reliable way is simply: IntPtr.Size == 8 means 64bit. Although not sure if it's ia32 or arm32 or what. With that it's also known that the OS arch is 64 bit which could be a quick path for OS arch API.
On Windows a platform call like this can be considered.

A possibility for macOS, with P/Invoke is get_arch_name_from_types

As any other API in this repo, would be great to get it tested with CoreRT or other AoT runtimes like Unity or what not.

Benchmarking different calls would be interesting although challenging since the benchmark will behave differently in different platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions