runtime: SEHException on misaligned access
Run the following code on an arm64 machine (e.g. Apple-M1):
using System.Runtime.CompilerServices;
long[] a = new long[100];
ref long misalignedLong = ref Unsafe.As<byte, long>(
ref Unsafe.Add(ref Unsafe.As<long, byte>(ref a[0]), 1));
Test(ref misalignedLong);
[MethodImpl(MethodImplOptions.NoInlining)]
long Test(ref long misalignedLong) => Volatile.Read(ref misalignedLong);
Expected:
No exception or DataMisalignedException is thrown
Actual:
SEHException is thrown
About this issue
- Original URL
- State: open
- Created 10 months ago
- Comments: 18 (18 by maintainers)
I’ve found the culprit. When we map the exception codes to managed exception, the data misalignment is mapped only for arm, not for arm64.
https://github.com/dotnet/runtime/blob/a3a0f5cf2223026e3518ab8f2028b4db6ed375cd/src/coreclr/inc/stdmacros.h#L148-L150
https://github.com/dotnet/runtime/blob/a3a0f5cf2223026e3518ab8f2028b4db6ed375cd/src/coreclr/vm/excep.cpp#L3133-L3136