-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Unsafe.ReadUnaligned causes System.AccessViolationException on Windows ARM64 #76194
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsHi! I faced with
Output:
Looks like it tries to load 8 bytes from x0:
.NET 6.0.401
|
Looks like one of those issues where we read more then requested. |
Repro: [StructLayout(LayoutKind.Explicit, Size = 5)]
public struct Data
{
[FieldOffset(0)]
public byte Byte;
[FieldOffset(1)]
public int Int;
}
static unsafe Data Foo(void* ptr) =>
Unsafe.ReadUnaligned<Data>(ptr); ARM Codegen (x86 is fine): ; Method Program:Foo(ulong):Data
G_M59270_IG01: ;; offset=0000H
A9BF7BFD stp fp, lr, [sp, #-0x10]!
910003FD mov fp, sp
;; size=8 bbWeight=1 PerfScore 1.50
G_M59270_IG02: ;; offset=0008H
F9400000 ldr x0, [x0]
;; size=4 bbWeight=1 PerfScore 3.00
G_M59270_IG03: ;; offset=000CH
A8C17BFD ldp fp, lr, [sp], #0x10
D65F03C0 ret lr
;; size=8 bbWeight=1 PerfScore 2.00
; Total bytes of code: 20 Looks like it happens in lowering (struct IND -> long IND) |
diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp
index 176828d17ed..af8d5a13b85 100644
--- a/src/coreclr/jit/lower.cpp
+++ b/src/coreclr/jit/lower.cpp
@@ -3654,8 +3654,16 @@ void Lowering::LowerRetStruct(GenTreeUnOp* ret)
break;
case GT_OBJ:
+ if (genTypeSize(nativeReturnType) != retVal->AsObj()->Size())
+ {
+ LIR::Use retValUse(BlockRange(), &ret->gtOp1, ret);
+ ReplaceWithLclVar(retValUse);
+ LowerRetSingleRegStructLclVar(ret);
+ break;
+ }
retVal->ChangeOper(GT_IND);
FALLTHROUGH;
+
case GT_IND:
retVal->ChangeType(nativeReturnType);
LowerIndir(retVal->AsIndir()); It's an incomplete fix though, the |
I actually did the same locally, spilled to a local 🙂 but feel free to file a PR with a fix if you want @SingleAccretion |
I think I won't have the time for it this week. |
Hi!
I faced with
System.AccessViolationException
when reading 5-byte structure in .NET 6 / .NET 7 RC1 / Arm64 .NET Framework 4.8.1 app on Windows ARM64, here is demo app:Output:
Looks like it tries to load 8 bytes from x0:
.NET 6.0.401
.NET 7.0.100-rc.1.22431.12
.NET Framework 4.8.1 ARM64 4.8.9093.0
Windows 11 21H2 22000.978
The text was updated successfully, but these errors were encountered: