1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 #include "unixasmmacros.inc"
9 // Version for when we're sure to be in the GC, checks whether or not the card
10 // needs to be updated
12 // void JIT_WriteBarrier_Debug(Object** dst, Object* src)
13 LEAF_ENTRY JIT_WriteBarrier_Debug, _TEXT
15 #ifdef WRITE_BARRIER_CHECK
16 // **ALSO update the shadow GC heap if that is enabled**
17 // Do not perform the work if g_GCShadow is 0
18 PREPARE_EXTERNAL_VAR g_GCShadow, rax
19 cmp qword ptr [rax], 0
22 // If we end up outside of the heap don't corrupt random memory
24 PREPARE_EXTERNAL_VAR g_lowest_address, r11
28 // Check that our adjusted destination is somewhere in the shadow gc
30 PREPARE_EXTERNAL_VAR g_GCShadowEnd, r11
34 // Write ref into real GC// see comment below about possibility of AV
36 // Write ref into shadow GC
39 // Ensure that the write to the shadow heap occurs before the read from
40 // the GC heap so that race conditions are caught by INVALIDGCVALUE
43 // Check that GC/ShadowGC values match
48 mov r11, INVALIDGCVALUE
53 // If we don't have a shadow GC we won't have done the write yet
59 // Do the move. It is correct to possibly take an AV here, the EH code
60 // figures out that this came from a WriteBarrier and correctly maps it back
61 // to the managed method which called the WriteBarrier (see setup in
62 // InitializeExceptionHandling, vm\exceptionhandling.cpp).
65 #ifdef WRITE_BARRIER_CHECK
66 // If we had a shadow GC then we already wrote to the real GC at the same time
67 // as the shadow GC so we want to jump over the real write immediately above
71 // See if we can just quick out
72 PREPARE_EXTERNAL_VAR g_ephemeral_low, r10
75 PREPARE_EXTERNAL_VAR g_ephemeral_high, r10
79 // Check if we need to update the card table
82 PREPARE_EXTERNAL_VAR g_card_table, r10
85 // Check if this card is dirty
86 cmp byte ptr [rdi], 0FFh
87 jne UpdateCardTable_Debug
90 UpdateCardTable_Debug:
91 mov byte ptr [rdi], 0FFh
97 LEAF_END_MARKED JIT_WriteBarrier_Debug, _TEXT