forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcinfodumper.cpp
More file actions
983 lines (855 loc) · 30.1 KB
/
gcinfodumper.cpp
File metadata and controls
983 lines (855 loc) · 30.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#ifndef SOS_INCLUDE
#include "common.h"
#endif
#include "gcinfohelpers.h"
#include "gcinfodumper.h"
#include "gcinfodecoder.h"
// Stolen from gc.h.
#define GC_CALL_INTERIOR 0x1
#define GC_CALL_PINNED 0x2
#ifdef HOST_64BIT
// All stack offsets are INT32's, so this guarantees a disjoint range of
// addresses for each register.
#define ADDRESS_SPACING UI64(0x100000000)
#elif defined(TARGET_ARM)
#define ADDRESS_SPACING 0x100000
#else
#error pick suitable ADDRESS_SPACING for platform
#endif
GcInfoDumper::GcInfoDumper (GCInfoToken gcInfoToken)
{
m_gcTable = gcInfoToken;
m_pRecords = NULL;
m_gcInfoSize = 0;
}
GcInfoDumper::~GcInfoDumper ()
{
FreePointerRecords(m_pRecords);
}
size_t GcInfoDumper::GetGCInfoSize()
{
return m_gcInfoSize;
}
//static*
void GcInfoDumper::LivePointerCallback (
LPVOID hCallback, // callback data
OBJECTREF* pObject, // address of object-reference we are reporting
uint32_t flags // is this a pinned and/or interior pointer
DAC_ARG(DacSlotLocation loc)) // the location of the slot
{
GcInfoDumper *pDumper = (GcInfoDumper*)hCallback;
LivePointerRecord **ppRecords = &pDumper->m_pRecords;
LivePointerRecord *pRecord = new LivePointerRecord();
if (!pRecord)
{
pDumper->m_Error = OUT_OF_MEMORY;
return;
}
pRecord->ppObject = pObject;
pRecord->flags = flags;
pRecord->marked = -1;
pRecord->pNext = *ppRecords;
*ppRecords = pRecord;
}
//static
void GcInfoDumper::FreePointerRecords (LivePointerRecord *pRecords)
{
while (pRecords)
{
LivePointerRecord *trash = pRecords;
pRecords = pRecords->pNext;
delete trash;
}
}
//This function tries to find the address of the managed object in the registers of the current function's context,
//failing which it checks if it is present in the stack of the current function. IF it finds one it reports appropriately
//
//For Amd64, this additionally tries to probe in the stack for the caller.
//This behavior largely seems to be present for legacy x64 jit and is not likely to be used anywhere else
BOOL GcInfoDumper::ReportPointerRecord (
UINT32 CodeOffset,
BOOL fLive,
REGDISPLAY *pRD,
LivePointerRecord *pRecord)
{
//
// Convert the flags passed to the GC into flags used by GcInfoEncoder.
//
int EncodedFlags = 0;
if (pRecord->flags & GC_CALL_INTERIOR)
EncodedFlags |= GC_SLOT_INTERIOR;
if (pRecord->flags & GC_CALL_PINNED)
EncodedFlags |= GC_SLOT_PINNED;
//
// Compare the reported pointer against the REGIDISPLAY pointers to
// figure out the register or register-relative location.
//
struct RegisterInfo
{
SIZE_T cbContextOffset;
};
static RegisterInfo rgRegisters[] = {
#define REG(reg, field) { offsetof(T_CONTEXT, field) }
#ifdef TARGET_AMD64
REG(rax, Rax),
REG(rcx, Rcx),
REG(rdx, Rdx),
REG(rbx, Rbx),
REG(rsp, Rsp),
REG(rbp, Rbp),
REG(rsi, Rsi),
REG(rdi, Rdi),
REG(r8, R8),
REG(r9, R9),
REG(r10, R10),
REG(r11, R11),
REG(r12, R12),
REG(r13, R13),
REG(r14, R14),
REG(r15, R15),
#undef REG
#define REG(reg, field) { offsetof(Amd64VolatileContextPointer, field) }
REG(r16, R16),
REG(r17, R17),
REG(r18, R18),
REG(r19, R19),
REG(r20, R20),
REG(r21, R21),
REG(r22, R22),
REG(r23, R23),
REG(r24, R24),
REG(r25, R25),
REG(r26, R26),
REG(r27, R27),
REG(r28, R28),
REG(r29, R29),
REG(r30, R30),
REG(r31, R31),
#elif defined(TARGET_ARM)
#undef REG
#define REG(reg, field) { offsetof(ArmVolatileContextPointer, field) }
REG(r0, R0),
REG(r1, R1),
REG(r2, R2),
REG(r3, R3),
#undef REG
#define REG(reg, field) { offsetof(T_KNONVOLATILE_CONTEXT_POINTERS, field) }
REG(r4, R4),
REG(r5, R5),
REG(r6, R6),
REG(r7, R7),
REG(r8, R8),
REG(r9, R9),
REG(r10, R10),
REG(r11, R11),
{ offsetof(ArmVolatileContextPointer, R12) },
{ offsetof(T_CONTEXT, Sp) },
{ offsetof(T_KNONVOLATILE_CONTEXT_POINTERS, Lr) },
{ offsetof(T_CONTEXT, Sp) },
{ offsetof(T_KNONVOLATILE_CONTEXT_POINTERS, R7) },
#elif defined(TARGET_ARM64)
#undef REG
#define REG(reg, field) { offsetof(Arm64VolatileContextPointer, field) }
REG(x0, X0),
REG(x1, X1),
REG(x2, X2),
REG(x3, X3),
REG(x4, X4),
REG(x5, X5),
REG(x6, X6),
REG(x7, X7),
REG(x8, X8),
REG(x9, X9),
REG(x10, X10),
REG(x11, X11),
REG(x12, X12),
REG(x13, X13),
REG(x14, X14),
REG(x15, X15),
REG(x16, X16),
REG(x17, X17),
#undef REG
#define REG(reg, field) { offsetof(T_KNONVOLATILE_CONTEXT_POINTERS, field) }
REG(x19, X19),
REG(x20, X20),
REG(x21, X21),
REG(x22, X22),
REG(x23, X23),
REG(x24, X24),
REG(x25, X25),
REG(x26, X26),
REG(x27, X27),
REG(x28, X28),
REG(Fp, Fp),
REG(Lr, Lr),
{ offsetof(T_CONTEXT, Sp) },
#undef REG
#elif defined(TARGET_LOONGARCH64)
#undef REG
#define REG(reg, field) { offsetof(T_KNONVOLATILE_CONTEXT_POINTERS, field) }
#define vREG(reg, field) { offsetof(LoongArch64VolatileContextPointer, field) }
vREG(zero, R0),
REG(ra, Ra),
{ offsetof(T_CONTEXT, Sp) },
vREG(a0, A0),
vREG(a1, A1),
vREG(a2, A2),
vREG(a3, A3),
vREG(a4, A4),
vREG(a5, A5),
vREG(a6, A6),
vREG(a7, A7),
vREG(t0, T0),
vREG(t1, T1),
vREG(t2, T2),
vREG(t3, T3),
vREG(t4, T4),
vREG(t5, T5),
vREG(t6, T6),
vREG(t7, T7),
vREG(t8, T8),
vREG(x0, X0),
REG(fp, Fp),
REG(s0, S0),
REG(s1, S1),
REG(s2, S2),
REG(s3, S3),
REG(s4, S4),
REG(s5, S5),
REG(s6, S6),
REG(s7, S7),
REG(s8, S8),
#undef vREG
#undef REG
#elif defined(TARGET_RISCV64)
#undef REG
#define REG(reg, field) { offsetof(T_KNONVOLATILE_CONTEXT_POINTERS, field) }
#define vREG(reg, field) { offsetof(RiscV64VolatileContextPointer, field) }
vREG(zero, R0),
REG(Ra, Ra),
{ offsetof(T_CONTEXT, Sp) },
REG(Gp, Gp),
REG(Tp, Tp),
vREG(t0, T0),
vREG(t1, T1),
vREG(t2, T2),
REG(Fp, Fp),
REG(s1, S1),
vREG(a0, A0),
vREG(a1, A1),
vREG(a2, A2),
vREG(a3, A3),
vREG(a4, A4),
vREG(a5, A5),
vREG(a6, A6),
vREG(a7, A7),
REG(s2, S2),
REG(s3, S3),
REG(s4, S4),
REG(s5, S5),
REG(s6, S6),
REG(s7, S7),
REG(s8, S8),
REG(s9, S9),
REG(s10, S10),
REG(s11, S11),
vREG(t3, T3),
vREG(t4, T4),
vREG(t5, T5),
vREG(t6, T6),
#undef vREG
#undef REG
#else
PORTABILITY_ASSERT("GcInfoDumper::ReportPointerRecord is not implemented on this platform.")
#endif
};
const UINT nCONTEXTRegisters = sizeof(rgRegisters)/sizeof(rgRegisters[0]);
UINT iFirstRegister;
UINT iSPRegister;
UINT nRegisters;
iFirstRegister = 0;
nRegisters = nCONTEXTRegisters;
#ifdef TARGET_AMD64
iSPRegister = (offsetof(CONTEXT, Rsp) - offsetof(CONTEXT, Rax)) / sizeof(ULONGLONG);
#elif defined(TARGET_ARM64)
iSPRegister = (offsetof(T_CONTEXT, Sp) - offsetof(T_CONTEXT, X0)) / sizeof(ULONGLONG);
#elif defined(TARGET_ARM)
iSPRegister = (offsetof(T_CONTEXT, Sp) - offsetof(T_CONTEXT, R0)) / sizeof(ULONG);
UINT iBFRegister = m_StackBaseRegister;
#elif defined(TARGET_LOONGARCH64)
iSPRegister = (offsetof(T_CONTEXT, Sp) - offsetof(T_CONTEXT, R0)) / sizeof(ULONGLONG);
#elif defined(TARGET_RISCV64)
iSPRegister = (offsetof(T_CONTEXT, Sp) - offsetof(T_CONTEXT, R0)) / sizeof(ULONGLONG);
#endif
#if defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
BYTE* pContext = (BYTE*)&(pRD->volatileCurrContextPointers);
#else // TARGET_ARM || TARGET_ARM64 || TARGET_RISCV64 || TARGET_LOONGARCH64
BYTE* pContext = (BYTE*)pRD->pCurrentContext;
#endif
for (int ctx = 0; ctx < 2; ctx++)
{
SIZE_T *pReg = NULL;
for (UINT iReg = 0; iReg < nRegisters; iReg++)
{
UINT iEncodedReg = iFirstRegister + iReg;
#ifdef TARGET_ARM
if (ctx == 1)
{
if ((iReg < 4 || iReg == 12)) // skip volatile registers for second context
{
continue;
}
// Force StackRegister and BaseRegister at the end (r15, r16)
if (iReg == iSPRegister || iReg == m_StackBaseRegister)
{
continue;
}
if (iReg == 15)
{
if (iBFRegister != NO_STACK_BASE_REGISTER)
{
iEncodedReg = iBFRegister;
}
else
{
continue;
}
}
if (iReg == 16)
{
iEncodedReg = iSPRegister;
}
}
if (ctx == 0 && iReg == 4) //ArmVolatileContextPointer 5th register is R12
{
iEncodedReg = 12;
}
else if (ctx == 0 && iReg > 4)
{
break;
}
#elif defined (TARGET_ARM64)
iEncodedReg = iEncodedReg + ctx; //We have to compensate for not tracking x18
if (ctx == 1)
{
if (iReg < 18 ) // skip volatile registers for second context
{
continue;
}
if (iReg == 30)
{
iEncodedReg = iSPRegister;
}
}
if (ctx == 0 && iReg > 17)
{
break;
}
#elif defined(TARGET_LOONGARCH64)
if (iEncodedReg > 1)
{
iEncodedReg++; // We have to compensate for not tracking tp
}
bool isVolatile = (iReg == 0 || (iReg >= 3 && iReg <= 20));
if (ctx == 0)
{
if (!isVolatile)
{
continue;
}
}
else if (isVolatile) // skip volatile registers for second context
{
continue;
}
#elif defined(TARGET_RISCV64)
bool isVolatile = (iReg == 0 || (iReg >= 5 && iReg <= 7) || (iReg >= 10 && iReg <= 17) || iReg >= 28);
if (ctx == 0)
{
if (!isVolatile)
{
continue;
}
}
else if (isVolatile) // skip volatile registers for second context
{
continue;
}
#elif defined(TARGET_AMD64)
if ((ctx != 0 && iEncodedReg > 15) || !IsAPXSupported())
{
break;
}
#endif // TARGET_AMD64
{
_ASSERTE(iReg < nCONTEXTRegisters);
#ifdef TARGET_ARM
pReg = *(SIZE_T**)(pContext + rgRegisters[iReg].cbContextOffset);
if (iEncodedReg == 12)
{
pReg = *(SIZE_T**)((BYTE*)&pRD->volatileCurrContextPointers + rgRegisters[iEncodedReg].cbContextOffset);
}
if (iEncodedReg == iSPRegister)
{
pReg = (SIZE_T*)((BYTE*)pRD->pCurrentContext + rgRegisters[iEncodedReg].cbContextOffset);
}
if (iEncodedReg == iBFRegister)
{
pReg = *(SIZE_T**)((BYTE*)pRD->pCurrentContextPointers + rgRegisters[iEncodedReg].cbContextOffset);
}
#elif defined(TARGET_ARM64) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
pReg = *(SIZE_T**)(pContext + rgRegisters[iReg].cbContextOffset);
if (iEncodedReg == iSPRegister)
{
pReg = (SIZE_T*)((BYTE*)pRD->pCurrentContext + rgRegisters[iReg].cbContextOffset);
}
#elif defined(TARGET_AMD64)
if (ctx == 0 && iReg == 16)
{
pContext = (BYTE*)&(pRD->volatileCurrContextPointers);
}
if (ctx == 0 && iReg >= 16)
{
pReg = *(SIZE_T**)(pContext + rgRegisters[iReg].cbContextOffset);
}
else
{
pReg = (SIZE_T*)(pContext + rgRegisters[iReg].cbContextOffset);
}
#else
pReg = (SIZE_T*)(pContext + rgRegisters[iReg].cbContextOffset);
#endif
}
SIZE_T ptr = (SIZE_T)pRecord->ppObject;
//
// Is it reporting the register?
//
if (ptr == (SIZE_T)pReg)
{
// Make sure the register is in the current frame.
#if defined(TARGET_AMD64)
if (0 != ctx)
{
m_Error = REPORTED_REGISTER_IN_CALLERS_FRAME;
return TRUE;
}
#endif
// Make sure the register isn't sp or the frame pointer.
if ( iSPRegister == iEncodedReg
|| m_StackBaseRegister == iEncodedReg)
{
m_Error = REPORTED_FRAME_POINTER;
return TRUE;
}
if (m_pfnRegisterStateChange(
CodeOffset,
iEncodedReg,
(GcSlotFlags)EncodedFlags,
fLive ? GC_SLOT_LIVE : GC_SLOT_DEAD,
m_pvCallbackData))
{
return TRUE;
}
return FALSE;
}
//
// Is it reporting an address relative to the register's value?
//
SIZE_T regVal = *pReg;
if ( ptr >= regVal - ADDRESS_SPACING/2
&& ptr < regVal + ADDRESS_SPACING/2)
{
//
// The register must be sp, caller's sp, or the frame register.
// The GcInfoEncoder interface doesn't have a way to express
// anything else.
//
if (!( iSPRegister == iEncodedReg
|| m_StackBaseRegister == iEncodedReg))
{
continue;
}
GcStackSlotBase base;
if (iSPRegister == iEncodedReg)
{
#if defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
base = GC_SP_REL;
#else
if (0 == ctx)
base = GC_SP_REL;
else
base = GC_CALLER_SP_REL;
#endif //defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
}
else
{
base = GC_FRAMEREG_REL;
}
if (m_pfnStackSlotStateChange(
CodeOffset,
(GcSlotFlags)EncodedFlags,
base,
ptr - regVal,
fLive ? GC_SLOT_LIVE : GC_SLOT_DEAD,
m_pvCallbackData))
{
return TRUE;
}
return FALSE;
}
}
#if defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
pContext = (BYTE*)pRD->pCurrentContextPointers;
#else
pContext = (BYTE*)pRD->pCallerContext;
#endif
}
m_Error = REPORTED_INVALID_POINTER;
return TRUE;
}
BOOL GcInfoDumper::ReportPointerDifferences (
UINT32 offset,
REGDISPLAY *pRD,
LivePointerRecord *pPrevState)
{
LivePointerRecord *pNewRecord;
LivePointerRecord *pOldRecord;
//
// Match up old and new records
//
for (pNewRecord = m_pRecords; pNewRecord; pNewRecord = pNewRecord->pNext)
{
for (LivePointerRecord *pOldRecord = pPrevState; pOldRecord; pOldRecord = pOldRecord->pNext)
{
if ( pOldRecord->flags == pNewRecord->flags
&& pOldRecord->ppObject == pNewRecord->ppObject)
{
pOldRecord->marked = offset;
pNewRecord->marked = offset;
}
}
}
//
// Report out any old records that were not marked as dead pointers.
//
for (pOldRecord = pPrevState; pOldRecord; pOldRecord = pOldRecord->pNext)
{
if (pOldRecord->marked != offset)
{
if ( ReportPointerRecord(offset, FALSE, pRD, pOldRecord)
|| m_Error)
{
return TRUE;
}
}
}
//
// Report any new records that were not marked as new pointers.
//
for (pNewRecord = m_pRecords; pNewRecord; pNewRecord = pNewRecord->pNext)
{
if (pNewRecord->marked != offset)
{
if ( ReportPointerRecord(offset, TRUE, pRD, pNewRecord)
|| m_Error)
{
return TRUE;
}
}
}
return FALSE;
}
GcInfoDumper::EnumerateStateChangesResults GcInfoDumper::EnumerateStateChanges (
InterruptibleStateChangeProc *pfnInterruptibleStateChange,
RegisterStateChangeProc *pfnRegisterStateChange,
StackSlotStateChangeProc *pfnStackSlotStateChange,
OnSafePointProc *pfnSafePointFunc,
PVOID pvData)
{
m_Error = SUCCESS;
//
// Save callback functions for use by helper functions
//
m_pfnRegisterStateChange = pfnRegisterStateChange;
m_pfnStackSlotStateChange = pfnStackSlotStateChange;
m_pvCallbackData = pvData;
//
// Decode header information
//
GcInfoDecoder hdrdecoder(m_gcTable,
(GcInfoDecoderFlags)( DECODE_SECURITY_OBJECT
| DECODE_CODE_LENGTH
| DECODE_GC_LIFETIMES
| DECODE_VARARG),
0);
UINT32 cbEncodedMethodSize = hdrdecoder.GetCodeLength();
m_StackBaseRegister = hdrdecoder.GetStackBaseRegister();
//
// Set up a bogus REGDISPLAY to pass to EnumerateLiveSlots. This will
// allow us to later identify registers or stack offsets passed to the
// callback.
//
REGDISPLAY regdisp;
ZeroMemory(®disp, sizeof(regdisp));
regdisp.pContext = ®disp.ctxOne;
regdisp.IsCallerContextValid = TRUE;
regdisp.pCurrentContext = ®disp.ctxOne;
regdisp.pCallerContext = ®disp.ctxTwo;
#define NEXT_ADDRESS() (UniqueAddress += ADDRESS_SPACING)
UINT iReg;
#ifdef HOST_64BIT
ULONG64 UniqueAddress = ADDRESS_SPACING*2;
ULONG64 *pReg;
#else
DWORD UniqueAddress = ADDRESS_SPACING*2;
DWORD *pReg;
#endif
#define FILL_REGS(start, count) \
do { \
for (iReg = 0, pReg = ®disp.start; iReg < count; iReg++, pReg++) \
{ \
*pReg = NEXT_ADDRESS(); \
} \
} while (0)
#ifdef TARGET_AMD64
FILL_REGS(pCurrentContext->Rax, 16);
FILL_REGS(pCallerContext->Rax, 16);
regdisp.pCurrentContextPointers = ®disp.ctxPtrsOne;
regdisp.pCallerContextPointers = ®disp.ctxPtrsTwo;
ULONGLONG **ppCurrentRax = ®disp.pCurrentContextPointers->Rax;
ULONGLONG **ppCallerRax = ®disp.pCallerContextPointers ->Rax;
for (iReg = 0; iReg < 16; iReg++)
{
*(ppCurrentRax + iReg) = ®disp.pCurrentContext->Rax + iReg;
*(ppCallerRax + iReg) = ®disp.pCallerContext ->Rax + iReg;
}
#if defined(TARGET_UNIX) && defined(HOST_UNIX)
if (IsAPXSupported())
{
ULONG64 **ppVolatileReg = ®disp.volatileCurrContextPointers.R16;
for (iReg = 0; iReg < 16; iReg++)
{
*(ppVolatileReg+iReg) = ®disp.pCurrentContext->R16 + iReg;
}
}
#endif // TARGET_UNIX
#elif defined(TARGET_ARM)
FILL_REGS(pCurrentContext->R0, 16);
FILL_REGS(pCallerContext->R0, 16);
regdisp.pCurrentContextPointers = ®disp.ctxPtrsOne;
regdisp.pCallerContextPointers = ®disp.ctxPtrsTwo;
ULONG **ppCurrentReg = ®disp.pCurrentContextPointers->R4;
ULONG **ppCallerReg = ®disp.pCallerContextPointers->R4;
for (iReg = 0; iReg < 8; iReg++)
{
*(ppCurrentReg + iReg) = ®disp.pCurrentContext->R4 + iReg;
*(ppCallerReg + iReg) = ®disp.pCallerContext->R4 + iReg;
}
/// Set Lr
*(ppCurrentReg + 8) = ®disp.pCurrentContext->R4 + 10;
*(ppCallerReg + 8) = ®disp.pCallerContext->R4 + 10;
ULONG **ppVolatileReg = ®disp.volatileCurrContextPointers.R0;
for (iReg = 0; iReg < 4; iReg++)
{
*(ppVolatileReg+iReg) = ®disp.pCurrentContext->R0 + iReg;
}
/// Set R12
*(ppVolatileReg+4) = ®disp.pCurrentContext->R0+12;
#elif defined(TARGET_ARM64)
FILL_REGS(pCurrentContext->X0, 33);
FILL_REGS(pCallerContext->X0, 33);
regdisp.pCurrentContextPointers = ®disp.ctxPtrsOne;
regdisp.pCallerContextPointers = ®disp.ctxPtrsTwo;
ULONG64 **ppCurrentReg = ®disp.pCurrentContextPointers->X19;
ULONG64 **ppCallerReg = ®disp.pCallerContextPointers->X19;
for (iReg = 0; iReg < 11; iReg++)
{
*(ppCurrentReg + iReg) = ®disp.pCurrentContext->X19 + iReg;
*(ppCallerReg + iReg) = ®disp.pCallerContext->X19 + iReg;
}
/// Set Lr
*(ppCurrentReg + 11) = ®disp.pCurrentContext->Lr;
*(ppCallerReg + 11) = ®disp.pCallerContext->Lr;
ULONG64 **ppVolatileReg = ®disp.volatileCurrContextPointers.X0;
for (iReg = 0; iReg < 18; iReg++)
{
*(ppVolatileReg+iReg) = ®disp.pCurrentContext->X0 + iReg;
}
#elif defined(TARGET_LOONGARCH64)
FILL_REGS(pCurrentContext->R0, 33);
FILL_REGS(pCallerContext->R0, 33);
regdisp.pCurrentContextPointers = ®disp.ctxPtrsOne;
regdisp.pCallerContextPointers = ®disp.ctxPtrsTwo;
ULONG64 **ppCurrentReg = ®disp.pCurrentContextPointers->S0;
ULONG64 **ppCallerReg = ®disp.pCallerContextPointers->S0;
// Set S0-S8
for (iReg = 0; iReg < 9; iReg++)
{
*(ppCurrentReg + iReg) = ®disp.pCurrentContext->S0 + iReg;
*(ppCallerReg + iReg) = ®disp.pCallerContext->S0 + iReg;
}
// Set Ra, Fp
regdisp.pCurrentContextPointers->Ra = ®disp.pCurrentContext->Ra;
regdisp.pCallerContextPointers->Ra = ®disp.pCallerContext->Ra;
regdisp.pCurrentContextPointers->Fp = ®disp.pCurrentContext->Fp;
regdisp.pCallerContextPointers->Fp = ®disp.pCallerContext->Fp;
ULONG64 **ppVolatileReg = ®disp.volatileCurrContextPointers.A0;
for (iReg = 0; iReg < 18; iReg++)
{
*(ppVolatileReg+iReg) = ®disp.pCurrentContext->A0 + iReg;
}
regdisp.volatileCurrContextPointers.R0 = ®disp.pCurrentContext->R0;
#elif defined(TARGET_RISCV64)
FILL_REGS(pCurrentContext->R0, 33);
FILL_REGS(pCallerContext->R0, 33);
regdisp.pCurrentContextPointers = ®disp.ctxPtrsOne;
regdisp.pCallerContextPointers = ®disp.ctxPtrsTwo;
// Set S1
regdisp.pCurrentContextPointers->S1 = ®disp.pCurrentContext->S1;
regdisp.pCallerContextPointers ->S1 = ®disp.pCallerContext ->S1;
ULONG64 **ppCurrentReg = ®disp.pCurrentContextPointers->S2;
ULONG64 **ppCallerReg = ®disp.pCallerContextPointers ->S2;
// Set S2-S11
for (iReg = 0; iReg < 10; iReg++)
{
*(ppCurrentReg + iReg) = ®disp.pCurrentContext->S2 + iReg;
*(ppCallerReg + iReg) = ®disp.pCallerContext ->S2 + iReg;
}
// Set Fp
regdisp.pCurrentContextPointers->Fp = ®disp.pCurrentContext->Fp;
regdisp.pCallerContextPointers ->Fp = ®disp.pCallerContext ->Fp;
// Set Gp
regdisp.pCurrentContextPointers->Gp = ®disp.pCurrentContext->Gp;
regdisp.pCallerContextPointers ->Gp = ®disp.pCallerContext ->Gp;
// Set Tp
regdisp.pCurrentContextPointers->Tp = ®disp.pCurrentContext->Tp;
regdisp.pCallerContextPointers ->Tp = ®disp.pCallerContext ->Tp;
// Set Ra
regdisp.pCurrentContextPointers->Ra = ®disp.pCurrentContext->Ra;
regdisp.pCallerContextPointers ->Ra = ®disp.pCallerContext ->Ra;
regdisp.volatileCurrContextPointers.R0 = ®disp.pCurrentContext->R0;
regdisp.volatileCurrContextPointers.A0 = ®disp.pCurrentContext->A0;
regdisp.volatileCurrContextPointers.A1 = ®disp.pCurrentContext->A1;
regdisp.volatileCurrContextPointers.A2 = ®disp.pCurrentContext->A2;
regdisp.volatileCurrContextPointers.A3 = ®disp.pCurrentContext->A3;
regdisp.volatileCurrContextPointers.A4 = ®disp.pCurrentContext->A4;
regdisp.volatileCurrContextPointers.A5 = ®disp.pCurrentContext->A5;
regdisp.volatileCurrContextPointers.A6 = ®disp.pCurrentContext->A6;
regdisp.volatileCurrContextPointers.A7 = ®disp.pCurrentContext->A7;
regdisp.volatileCurrContextPointers.T0 = ®disp.pCurrentContext->T0;
regdisp.volatileCurrContextPointers.T1 = ®disp.pCurrentContext->T1;
regdisp.volatileCurrContextPointers.T2 = ®disp.pCurrentContext->T2;
regdisp.volatileCurrContextPointers.T3 = ®disp.pCurrentContext->T3;
regdisp.volatileCurrContextPointers.T4 = ®disp.pCurrentContext->T4;
regdisp.volatileCurrContextPointers.T5 = ®disp.pCurrentContext->T5;
regdisp.volatileCurrContextPointers.T6 = ®disp.pCurrentContext->T6;
#else
PORTABILITY_ASSERT("GcInfoDumper::EnumerateStateChanges is not implemented on this platform.");
#endif
#undef FILL_REGS
#undef NEXT_ADDRESS
SyncRegDisplayToCurrentContext(®disp);
//
// Enumerate pointers at every possible offset.
//
#ifdef PARTIALLY_INTERRUPTIBLE_GC_SUPPORTED
GcInfoDecoder safePointDecoder(m_gcTable, (GcInfoDecoderFlags)0, 0);
#endif
{
GcInfoDecoder untrackedDecoder(m_gcTable, DECODE_GC_LIFETIMES, 0);
untrackedDecoder.EnumerateUntrackedSlots(®disp,
0,
&LivePointerCallback,
this);
BOOL fStop = ReportPointerDifferences(
-2,
®disp,
NULL);
FreePointerRecords(m_pRecords);
m_pRecords = NULL;
if (fStop || m_Error)
return m_Error;
}
LivePointerRecord *pLastState = NULL;
BOOL fPrevInterruptible = FALSE;
for (UINT32 offset = 0; offset <= cbEncodedMethodSize; offset++)
{
BOOL fNewInterruptible = FALSE;
GcInfoDecoder decoder1(m_gcTable,
(GcInfoDecoderFlags)( DECODE_SECURITY_OBJECT
| DECODE_CODE_LENGTH
| DECODE_VARARG
#if defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
| DECODE_HAS_TAILCALLS
#endif // TARGET_ARM || TARGET_ARM64 || TARGET_LOONGARCH64 || TARGET_RISCV64
| DECODE_INTERRUPTIBILITY),
offset);
fNewInterruptible = decoder1.IsInterruptible();
if (fNewInterruptible != fPrevInterruptible)
{
if (pfnInterruptibleStateChange(offset, fNewInterruptible, pvData))
break;
fPrevInterruptible = fNewInterruptible;
}
unsigned flags = ActiveStackFrame;
#ifdef PARTIALLY_INTERRUPTIBLE_GC_SUPPORTED
UINT32 safePointOffset = offset;
#if defined(TARGET_AMD64) || defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_RISCV64) || defined(TARGET_LOONGARCH64)
safePointOffset++;
#endif
if(safePointDecoder.IsSafePoint(safePointOffset))
{
_ASSERTE(!fNewInterruptible);
if (pfnSafePointFunc(safePointOffset, pvData))
break;
flags = 0;
}
#endif
GcInfoDecoder decoder2(m_gcTable,
(GcInfoDecoderFlags)( DECODE_SECURITY_OBJECT
| DECODE_CODE_LENGTH
| DECODE_VARARG
| DECODE_GC_LIFETIMES
| DECODE_NO_VALIDATION),
offset);
_ASSERTE(!m_pRecords);
if(!fNewInterruptible && (flags == ActiveStackFrame))
{
// Decoding at non-interruptible offsets is only
// valid in the ExecutionAborted case
flags |= ExecutionAborted;
}
if (!decoder2.EnumerateLiveSlots(
®disp,
true,
flags | NoReportUntracked,
&LivePointerCallback,
this))
{
m_Error = DECODER_FAILED;
}
if (m_Error)
break;
if (ReportPointerDifferences(
offset,
®disp,
pLastState))
{
break;
}
if (m_Error)
break;
FreePointerRecords(pLastState);
pLastState = m_pRecords;
m_pRecords = NULL;
size_t tempSize = decoder2.GetNumBytesRead();
if( m_gcInfoSize < tempSize )
m_gcInfoSize = tempSize;
}
FreePointerRecords(pLastState);
FreePointerRecords(m_pRecords);
m_pRecords = NULL;
return m_Error;
}