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

Fix fatal SEHException on Arm calling RDTSC #1055

Merged
merged 1 commit into from
Apr 28, 2023

Conversation

jonorossi
Copy link
Contributor

@jonorossi jonorossi commented Apr 21, 2023

Arm does not have the x86 Timestamp Counter register or read timestamp counter instruction. Add an additional architecture check to prevent the code path when running on Arm. The code checks for X86/X64 as they are the only Intel-based architectures in the enum, while the enum now contains 4 Arm-based members (only in recent .NET) along with WebAssembly and more.

Running .NET on Windows on Arm, NetMQ throws a fatal exception crashing the application just starting up a poller:

Fatal error. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
   at NetMQ.Core.Utils.Clock.Rdtsc()
   at NetMQ.Core.SocketBase.ProcessCommands(Int32, Boolean, System.Threading.CancellationToken)
   at NetMQ.Core.SocketBase.Bind(System.String)
   at NetMQ.NetMQSocket.Bind(System.String)
   at NetMQ.Sockets.PairSocket.CreateSocketPair(NetMQ.Sockets.PairSocket ByRef, NetMQ.Sockets.PairSocket ByRef)
   at NetMQ.Core.Utils.StopSignaler..ctor()
   at NetMQ.NetMQPoller..ctor()
   [...]

This defect has been reported in #199 (Arm), #714 (Arm) and #1033 (FPGA). There was one fix made in #227 that added the IsARMArchitecture, however that only works on Mono.

The change will fix the defect for .NET Standard 2.0/2.1 targets (which are used for .NET Core and 5+ runtimes) as they both define NETSTANDARD1_1_OR_GREATER. It won't fix the bug for .NET Framework 4.5/4.7 targets as the RuntimeInformation class is only available on .NET Framework 4.7.1, however Windows on Arm appears to emulate the instruction for .NET Framework and the code is set up ready if this project's TFMs are changed in the future.

Arm does not have the x86 Timestamp Counter register or read timestamp
counter instruction. Add an additional architecture check to prevent
the code path when running on Arm.
@drewnoakes
Copy link
Member

drewnoakes commented Apr 28, 2023

Thanks, this looks great.

Unfortunately, it looks like there's no way currently to run CI on ARM64.

actions/runner-images#5631

@drewnoakes drewnoakes merged commit ebe5ad3 into zeromq:master Apr 28, 2023
@drewnoakes
Copy link
Member

Released in https://www.nuget.org/packages/NetMQ/4.0.1.12

@jonorossi jonorossi deleted the rdtsc-arm branch April 28, 2023 13:16
@jonorossi
Copy link
Contributor Author

Unfortunately, it looks like there's no way currently to run CI on ARM64.

I've pulled 4.0.1.12 and it runs. Cheers for making the release 👏.

@drewnoakes
Copy link
Member

Thanks for the high quality PRs and confirming the fix!

@vashek vashek mentioned this pull request May 6, 2023
vashek pushed a commit to vashek/netmq that referenced this pull request May 6, 2023
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.

2 participants