Skip to content

Fix ARM architecture detection for aarch64#1158

Open
VincentVbs wants to merge 1 commit into
zeromq:masterfrom
VincentVbs:fix-1116-aarch64-detection
Open

Fix ARM architecture detection for aarch64#1158
VincentVbs wants to merge 1 commit into
zeromq:masterfrom
VincentVbs:fix-1116-aarch64-detection

Conversation

@VincentVbs
Copy link
Copy Markdown

Add detection for "aarch" prefix to support modern 64-bit ARM architectures.

The IsARMArchitecture() method only checked for "arm" in the machine value, which failed to detect aarch64 (ARM 64-bit) architectures. This caused NetMQ to attempt using x86/x64 RDTSC instruction on ARM systems, resulting in crashes.

After Ubuntu upgrade from 16.04 (armv7l) to 24.04 (aarch64) on Raspberry Pi, the detection failed and NetMQ crashed with IllegalInstructionException.

Fix checks for both "arm" and "aarch" prefixes, supporting:

  • Legacy 32-bit ARM: armv6l, armv7l, armhf (still works)
  • Modern 64-bit ARM: aarch64, aarch32 (now works)

Tested with 12 unit tests covering all ARM variants and non-ARM architectures.

Fixes #1116

Add detection for "aarch" prefix to support modern 64-bit ARM architectures.

The IsARMArchitecture() method only checked for "arm" in the machine value,
which failed to detect aarch64 (ARM 64-bit) architectures. This caused NetMQ
to attempt using x86/x64 RDTSC instruction on ARM systems, resulting in crashes.

After Ubuntu upgrade from 16.04 (armv7l) to 24.04 (aarch64) on Raspberry Pi,
the detection failed and NetMQ crashed with IllegalInstructionException.

Fix checks for both "arm" and "aarch" prefixes, supporting:
- Legacy 32-bit ARM: armv6l, armv7l, armhf (still works)
- Modern 64-bit ARM: aarch64, aarch32 (now works)

Tested with 12 unit tests covering all ARM variants and non-ARM architectures.

Fixes zeromq#1116
Copy link
Copy Markdown
Member

@drewnoakes drewnoakes left a comment

Choose a reason for hiding this comment

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

Looks great. One suggestion to make this more robust on modern .NET.

Comment on lines 81 to 99
private static bool IsARMArchitecture()
{
// force to load from mono gac
Assembly currentAssembly = Assembly.Load("Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
Type? syscall = currentAssembly.GetType("Mono.Unix.Native.Syscall");
Type? utsname = currentAssembly.GetType("Mono.Unix.Native.Utsname");
if (syscall is null || utsname is null) return false;
MethodInfo? uname = syscall.GetMethod("uname");
object?[] parameters = { null };

var invokeResult = (int) (uname?.Invoke(null, parameters) ?? -1);

if (invokeResult != 0)
return false;

var currentValues = parameters[0];
var machineValue = (string)(utsname!.GetField("machine")?.GetValue(currentValues) ?? "unknown");
return machineValue.ToLower().Contains("arm");
return machineValue.ToLower().Contains("arm") || machineValue.ToLower().Contains("aarch");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In modern .NET, we can use something like:

bool isArmMachine = RuntimeInformation.OSArchitecture is Architecture.Arm or Architecture.Arm64;

We might need some conditional compilation for that, as we still target older .NET Framework versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rdtsc crashing on ARM after Ubuntu 16bit to 32bit update

3 participants