Skip to content

[NativeAOT/ARM] NativePrimitiveDecoder generates unaligned accesses with VLDR instruction #97912

@filipnavara

Description

@filipnavara

Code:

public static byte ReadUInt8(ref byte* stream)
{
byte result = *(stream); // Assumes little endian and unaligned access
stream++;
return result;
}
public static ushort ReadUInt16(ref byte* stream)
{
ushort result = *(ushort*)(stream); // Assumes little endian and unaligned access
stream += 2;
return result;
}
public static uint ReadUInt32(ref byte* stream)
{
uint result = *(uint*)(stream); // Assumes little endian and unaligned access
stream += 4;
return result;
}
public static ulong ReadUInt64(ref byte* stream)
{
ulong result = *(ulong*)(stream); // Assumes little endian and unaligned access
stream += 8;
return result;
}

Crash at runtime:

* thread #1, name = 'System.Runtime.', stop reason = signal SIGBUS
  * frame #0: 0x0204ba16 System.Runtime.Tests`Internal.Metadata.NativeFormat.MetadataReader__GetConstantSingleValue(this=0xf49a9454, handle=(_value = 403231906)) at NativeFormatReaderGen.cs:10446
    frame #1: 0x0203cf36 System.Runtime.Tests`System.Reflection.Runtime.General.NativeFormatMetadataReaderExtensions__ParseConstantNumericValue(handle=<unavailable>, reader=<unavailable>) at MetadataReaderExtensions.NativeFormat.cs:278
    frame #2: 0x0203d050 System.Runtime.Tests`System.Reflection.Runtime.General.NativeFormatMetadataReaderExtensions__TryParseConstantValue(handle=<unavailable>, reader=<unavailable>, value=0xf50eb2f0) at MetadataReaderExtensions.NativeFormat.cs:303
    frame #3: 0x0203d4e6 System.Runtime.Tests`System.Reflection.Runtime.General.NativeFormatMetadataReaderExtensions__TryParseConstantArray(handle=<unavailable>, reader=0xf49a9454, exception=0xf03fe26c) at MetadataReaderExtensions.NativeFormat.cs:405
    frame #4: 0x0203d0da System.Runtime.Tests`System.Reflection.Runtime.General.NativeFormatMetadataReaderExtensions__TryParseConstantValue(handle=<unavailable>, reader=<unavailable>, value=0xf03fe2c8) at MetadataReaderExtensions.NativeFormat.cs:327
    frame #5: 0x02041922 System.Runtime.Tests`System.Reflection.Runtime.CustomAttributes.NativeFormat.NativeFormatCustomAttributeData__GetConstructorArguments(this=0xf50eb1b0, throwIfMissingMetadata=true) at NativeFormatCustomAttributeData.cs:132
    frame #6: 0x020405a4 System.Runtime.Tests`System.Reflection.Runtime.CustomAttributes.RuntimeCustomAttributeData__get_ConstructorArguments(this=<unavailable>) at RuntimeCustomAttributeData.cs:24
    ...

  0x204ba16 <+53>: vldr   s8, [r3]

        r3 = 0x00a88312  System.Runtime.Tests`__embedded_metadata + 578722

VLDR is not handled by the kernel unalignment traps (ref: raspberrypi/linux#3099) and it doesn't natively support unaligned access.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions