Fix ARM architecture detection for aarch64#1158
Open
VincentVbs wants to merge 1 commit into
Open
Conversation
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
drewnoakes
approved these changes
May 2, 2026
Member
drewnoakes
left a comment
There was a problem hiding this comment.
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"); | ||
| } |
Member
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Tested with 12 unit tests covering all ARM variants and non-ARM architectures.
Fixes #1116