-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Expand file tree
/
Copy pathfunceval.cpp
More file actions
4032 lines (3503 loc) · 141 KB
/
funceval.cpp
File metadata and controls
4032 lines (3503 loc) · 141 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
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// ****************************************************************************
// File: funceval.cpp
//
//
// funceval.cpp - Debugger func-eval routines.
//
// ****************************************************************************
// Putting code & #includes, #defines, etc, before the stdafx.h will
// cause the code,etc, to be silently ignored
#include "stdafx.h"
#include "debugdebugger.h"
#include "../inc/common.h"
#include "eeconfig.h" // This is here even for retail & free builds...
#include "vars.hpp"
#include "threads.h"
#include "appdomain.inl"
#include <limits.h>
#include "ilformatter.h"
#ifndef DACCESS_COMPILE
//
// This is the main file for processing func-evals. Nestle in
// with a cup o' tea and read on.
//
// The most common case is handled in GCProtectArgsAndDoNormalFuncEval(), which follows
// all the comments below. The two other corner cases are handled in
// FuncEvalHijackWorker(), and are extremely straight-forward.
//
// There are several steps to successfully processing a func-eval. At a
// very high level, the first step is to gather all the information necessary
// to make the call (specifically, gather arg info and method info); the second
// step is to actually make the call to managed code; finally, the third step
// is to take all results and unpackage them.
//
// The first step (gathering arg and method info) has several critical passes that
// must be made.
// a) Protect all passed in args from a GC.
// b) Transition into the appropriate AppDomain if necessary
// c) Pre-allocate object for 'new' calls and, if necessary, box the 'this' argument. (May cause a GC)
// d) Gather method info (May cause GC)
// e) Gather info from runtime about args. (May cause a GC)
// f) Box args that need to be, GC-protecting the newly boxed items. (May cause a GC)
// g) Pre-allocate object for return values. (May cause a GC)
// h) Copy to pBufferForArgsArray all the args. This array is used to hold values that
// may need writable memory for ByRef args.
// i) Create and load pArgumentArray to be passed as the stack for the managed call.
// NOTE: From the time we load the first argument into the stack we cannot cause a GC
// as the argument array cannot be GC-protected.
//
// The second step (Making the managed call), is relatively easy, and is a single call.
//
// The third step (unpacking all results), has a couple of passes as well.
// a) Copy back all resulting values.
// b) Free all temporary work memory.
//
//
// The most difficult part of doing a func-eval is the first step, since once you
// have everything set up, unpacking and calling are reverse, gc-safe, operations. Thus,
// elaboration is needed on the first step.
//
// a) Protect all passed in args from a GC. This must be done in a gc-forbid region,
// and the code path to this function must not trigger a gc either. In this function five
// parallel arrays are used: pObjectRefArray, pMaybeInteriorPtrArray, pByRefMaybeInteriorPtrArray,
// pBufferForArgsArray, and pArguments.
// pObjectRefArray is used to gc-protect all arguments and results that are objects.
// pMaybeInteriorPtrArray is used to gc-protect all arguments that might be pointers
// to an interior of a managed object.
// pByRefMaybeInteriorPtrArray is similar to pMaybeInteriorPtrArray, except that it protects the
// address of the arguments instead of the arguments themselves. This is needed because we may have
// by ref arguments whose address is an interior pointer into the GC heap.
// pBufferForArgsArray is used strictly as a buffer for copying primitives
// that need to be passed as ByRef, or may be enregistered. This array also holds
// handles.
// These first two arrays are mutually exclusive, that is, if there is an entry
// in one array at index i, there should be no entry in either of the other arrays at
// the same index.
// pArguments is used as the complete array of arguments to pass to the managed function.
//
// Unfortunately the necessary information to complete pass (a) perfectly may cause a gc, so
// instead, pass (a) is over-aggressive and protects the following: All object refs into
// pObjectRefArray, and puts all values that could be raw pointers into pMaybeInteriorPtrArray.
//
// b) Discovers the method to be called, and if it is a 'new' allocate an object for the result.
//
// c) Gather information about the method that will be called.
//
// d) Here we gather information from the method signature which tells which args are
// ByRef and various other flags. We will use this information in later passes.
//
// e) Using the information in pass (c), for each argument: box arguments, placing newly
// boxed items into pObjectRefArray immediately after creating them.
//
// f) Pre-allocate any object for a returned value.
//
// g) Using the information is pass (c), all arguments are copied into a scratch buffer before
// invoking the managed function.
//
// h) pArguments is loaded from the pre-allocated return object, the individual elements
// of the other 3 arrays, and from any non-ByRef literals. This is the complete stack
// to be passed to the managed function. For performance increase, it can remove any
// overly aggressive items that were placed in pMaybeInteriorPtrArray.
//
//
// IsElementTypeSpecial()
//
// This is a simple function used to check if a CorElementType needs special handling for func eval.
//
// parameters: type - the CorElementType which we need to check
//
// return value: true if the specified type needs special handling
//
inline static bool IsElementTypeSpecial(CorElementType type)
{
LIMITED_METHOD_CONTRACT;
return ((type == ELEMENT_TYPE_CLASS) ||
(type == ELEMENT_TYPE_OBJECT) ||
(type == ELEMENT_TYPE_ARRAY) ||
(type == ELEMENT_TYPE_SZARRAY) ||
(type == ELEMENT_TYPE_STRING));
}
//
// GetAndSetLiteralValue()
//
// This helper function extracts the value out of the source pointer while taking into account alignment and size.
// Then it stores the value into the destination pointer, again taking into account alignment and size.
//
// parameters: pDst - destination pointer
// dstType - the CorElementType of the destination value
// pSrc - source pointer
// srcType - the CorElementType of the source value
//
// return value: none
//
inline static void GetAndSetLiteralValue(LPVOID pDst, CorElementType dstType, LPVOID pSrc, CorElementType srcType)
{
LIMITED_METHOD_CONTRACT;
UINT64 srcValue;
// Retrieve the value using the source CorElementType.
switch (g_pEEInterface->GetSizeForCorElementType(srcType))
{
case 1:
srcValue = (UINT64)*((BYTE*)pSrc);
break;
case 2:
srcValue = (UINT64)*((USHORT*)pSrc);
break;
case 4:
srcValue = (UINT64)*((UINT32*)pSrc);
break;
case 8:
srcValue = (UINT64)*((UINT64*)pSrc);
break;
default:
UNREACHABLE();
}
// Cast to the appropriate type using the destination CorElementType.
switch (dstType)
{
case ELEMENT_TYPE_BOOLEAN:
*(BYTE*)pDst = (BYTE)!!srcValue;
break;
case ELEMENT_TYPE_I1:
*(INT8*)pDst = (INT8)srcValue;
break;
case ELEMENT_TYPE_U1:
*(UINT8*)pDst = (UINT8)srcValue;
break;
case ELEMENT_TYPE_I2:
*(INT16*)pDst = (INT16)srcValue;
break;
case ELEMENT_TYPE_U2:
case ELEMENT_TYPE_CHAR:
*(UINT16*)pDst = (UINT16)srcValue;
break;
#if !defined(HOST_64BIT)
case ELEMENT_TYPE_I:
#endif
case ELEMENT_TYPE_I4:
*(int*)pDst = (int)srcValue;
break;
#if !defined(HOST_64BIT)
case ELEMENT_TYPE_U:
#endif
case ELEMENT_TYPE_U4:
case ELEMENT_TYPE_R4:
*(unsigned*)pDst = (unsigned)srcValue;
break;
#if defined(HOST_64BIT)
case ELEMENT_TYPE_I:
#endif
case ELEMENT_TYPE_I8:
case ELEMENT_TYPE_R8:
*(INT64*)pDst = (INT64)srcValue;
break;
#if defined(HOST_64BIT)
case ELEMENT_TYPE_U:
#endif
case ELEMENT_TYPE_U8:
*(UINT64*)pDst = (UINT64)srcValue;
break;
case ELEMENT_TYPE_FNPTR:
case ELEMENT_TYPE_PTR:
*(void **)pDst = (void *)(SIZE_T)srcValue;
break;
default:
UNREACHABLE();
}
}
//
// Throw on not supported func evals
//
static void ValidateFuncEvalReturnType(DebuggerIPCE_FuncEvalType evalType, MethodTable * pMT)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
}
CONTRACTL_END;
if (pMT == g_pStringClass)
{
if (evalType == DB_IPCE_FET_NEW_OBJECT || evalType == DB_IPCE_FET_NEW_OBJECT_NC)
{
// Cannot call New object on String constructor.
COMPlusThrow(kArgumentException,W("Argument_CannotCreateString"));
}
}
else if (g_pEEInterface->IsTypedReference(pMT))
{
// Cannot create typed references through funceval.
if (evalType == DB_IPCE_FET_NEW_OBJECT || evalType == DB_IPCE_FET_NEW_OBJECT_NC || evalType == DB_IPCE_FET_NORMAL)
{
COMPlusThrow(kArgumentException, W("Argument_CannotCreateTypedReference"));
}
}
}
//
// Given a register, return the value.
//
static SIZE_T GetRegisterValue(DebuggerEval *pDE, CorDebugRegister reg, void *regAddr, SIZE_T regValue)
{
LIMITED_METHOD_CONTRACT;
SIZE_T ret = 0;
// Check whether the register address is the marker value for a register in a non-leaf frame.
// This is related to the funceval breaking change.
//
if (regAddr == CORDB_ADDRESS_TO_PTR(kNonLeafFrameRegAddr))
{
ret = regValue;
}
else
{
switch (reg)
{
case REGISTER_STACK_POINTER:
ret = (SIZE_T)GetSP(&pDE->m_context);
break;
case REGISTER_FRAME_POINTER:
ret = (SIZE_T)GetFP(&pDE->m_context);
break;
#if defined(TARGET_X86)
case REGISTER_X86_EAX:
ret = pDE->m_context.Eax;
break;
case REGISTER_X86_ECX:
ret = pDE->m_context.Ecx;
break;
case REGISTER_X86_EDX:
ret = pDE->m_context.Edx;
break;
case REGISTER_X86_EBX:
ret = pDE->m_context.Ebx;
break;
case REGISTER_X86_ESI:
ret = pDE->m_context.Esi;
break;
case REGISTER_X86_EDI:
ret = pDE->m_context.Edi;
break;
#elif defined(TARGET_AMD64)
case REGISTER_AMD64_RAX:
ret = pDE->m_context.Rax;
break;
case REGISTER_AMD64_RCX:
ret = pDE->m_context.Rcx;
break;
case REGISTER_AMD64_RDX:
ret = pDE->m_context.Rdx;
break;
case REGISTER_AMD64_RBX:
ret = pDE->m_context.Rbx;
break;
case REGISTER_AMD64_RSI:
ret = pDE->m_context.Rsi;
break;
case REGISTER_AMD64_RDI:
ret = pDE->m_context.Rdi;
break;
case REGISTER_AMD64_R8:
ret = pDE->m_context.R8;
break;
case REGISTER_AMD64_R9:
ret = pDE->m_context.R9;
break;
case REGISTER_AMD64_R10:
ret = pDE->m_context.R10;
break;
case REGISTER_AMD64_R11:
ret = pDE->m_context.R11;
break;
case REGISTER_AMD64_R12:
ret = pDE->m_context.R12;
break;
case REGISTER_AMD64_R13:
ret = pDE->m_context.R13;
break;
case REGISTER_AMD64_R14:
ret = pDE->m_context.R14;
break;
case REGISTER_AMD64_R15:
ret = pDE->m_context.R15;
break;
// fall through
case REGISTER_AMD64_XMM0:
case REGISTER_AMD64_XMM1:
case REGISTER_AMD64_XMM2:
case REGISTER_AMD64_XMM3:
case REGISTER_AMD64_XMM4:
case REGISTER_AMD64_XMM5:
case REGISTER_AMD64_XMM6:
case REGISTER_AMD64_XMM7:
case REGISTER_AMD64_XMM8:
case REGISTER_AMD64_XMM9:
case REGISTER_AMD64_XMM10:
case REGISTER_AMD64_XMM11:
case REGISTER_AMD64_XMM12:
case REGISTER_AMD64_XMM13:
case REGISTER_AMD64_XMM14:
case REGISTER_AMD64_XMM15:
ret = FPSpillToR8(&(pDE->m_context.Xmm0) + (reg - REGISTER_AMD64_XMM0));
break;
#elif defined(TARGET_ARM64)
// fall through
case REGISTER_ARM64_X0:
case REGISTER_ARM64_X1:
case REGISTER_ARM64_X2:
case REGISTER_ARM64_X3:
case REGISTER_ARM64_X4:
case REGISTER_ARM64_X5:
case REGISTER_ARM64_X6:
case REGISTER_ARM64_X7:
case REGISTER_ARM64_X8:
case REGISTER_ARM64_X9:
case REGISTER_ARM64_X10:
case REGISTER_ARM64_X11:
case REGISTER_ARM64_X12:
case REGISTER_ARM64_X13:
case REGISTER_ARM64_X14:
case REGISTER_ARM64_X15:
case REGISTER_ARM64_X16:
case REGISTER_ARM64_X17:
case REGISTER_ARM64_X18:
case REGISTER_ARM64_X19:
case REGISTER_ARM64_X20:
case REGISTER_ARM64_X21:
case REGISTER_ARM64_X22:
case REGISTER_ARM64_X23:
case REGISTER_ARM64_X24:
case REGISTER_ARM64_X25:
case REGISTER_ARM64_X26:
case REGISTER_ARM64_X27:
case REGISTER_ARM64_X28:
ret = pDE->m_context.X[reg - REGISTER_ARM64_X0];
break;
case REGISTER_ARM64_LR:
ret = pDE->m_context.Lr;
break;
case REGISTER_ARM64_V0:
case REGISTER_ARM64_V1:
case REGISTER_ARM64_V2:
case REGISTER_ARM64_V3:
case REGISTER_ARM64_V4:
case REGISTER_ARM64_V5:
case REGISTER_ARM64_V6:
case REGISTER_ARM64_V7:
case REGISTER_ARM64_V8:
case REGISTER_ARM64_V9:
case REGISTER_ARM64_V10:
case REGISTER_ARM64_V11:
case REGISTER_ARM64_V12:
case REGISTER_ARM64_V13:
case REGISTER_ARM64_V14:
case REGISTER_ARM64_V15:
case REGISTER_ARM64_V16:
case REGISTER_ARM64_V17:
case REGISTER_ARM64_V18:
case REGISTER_ARM64_V19:
case REGISTER_ARM64_V20:
case REGISTER_ARM64_V21:
case REGISTER_ARM64_V22:
case REGISTER_ARM64_V23:
case REGISTER_ARM64_V24:
case REGISTER_ARM64_V25:
case REGISTER_ARM64_V26:
case REGISTER_ARM64_V27:
case REGISTER_ARM64_V28:
case REGISTER_ARM64_V29:
case REGISTER_ARM64_V30:
case REGISTER_ARM64_V31:
ret = FPSpillToR8(&pDE->m_context.V[reg - REGISTER_ARM64_V0]);
break;
#endif // !TARGET_X86 && !TARGET_AMD64 && !TARGET_ARM64
default:
_ASSERT(!"Invalid register number!");
}
}
return ret;
}
//
// Given a register, set its value.
//
static void SetRegisterValue(DebuggerEval *pDE, CorDebugRegister reg, void *regAddr, SIZE_T newValue)
{
CONTRACTL
{
THROWS;
}
CONTRACTL_END;
// Check whether the register address is the marker value for a register in a non-leaf frame.
// If so, then we can't update the register. Throw an exception to communicate this error.
if (regAddr == CORDB_ADDRESS_TO_PTR(kNonLeafFrameRegAddr))
{
COMPlusThrowHR(CORDBG_E_FUNC_EVAL_CANNOT_UPDATE_REGISTER_IN_NONLEAF_FRAME);
return;
}
else
{
switch (reg)
{
case REGISTER_STACK_POINTER:
SetSP(&pDE->m_context, newValue);
break;
case REGISTER_FRAME_POINTER:
SetFP(&pDE->m_context, newValue);
break;
#ifdef TARGET_X86
case REGISTER_X86_EAX:
pDE->m_context.Eax = newValue;
break;
case REGISTER_X86_ECX:
pDE->m_context.Ecx = newValue;
break;
case REGISTER_X86_EDX:
pDE->m_context.Edx = newValue;
break;
case REGISTER_X86_EBX:
pDE->m_context.Ebx = newValue;
break;
case REGISTER_X86_ESI:
pDE->m_context.Esi = newValue;
break;
case REGISTER_X86_EDI:
pDE->m_context.Edi = newValue;
break;
#elif defined(TARGET_AMD64)
case REGISTER_AMD64_RAX:
pDE->m_context.Rax = newValue;
break;
case REGISTER_AMD64_RCX:
pDE->m_context.Rcx = newValue;
break;
case REGISTER_AMD64_RDX:
pDE->m_context.Rdx = newValue;
break;
case REGISTER_AMD64_RBX:
pDE->m_context.Rbx = newValue;
break;
case REGISTER_AMD64_RSI:
pDE->m_context.Rsi = newValue;
break;
case REGISTER_AMD64_RDI:
pDE->m_context.Rdi = newValue;
break;
case REGISTER_AMD64_R8:
pDE->m_context.R8= newValue;
break;
case REGISTER_AMD64_R9:
pDE->m_context.R9= newValue;
break;
case REGISTER_AMD64_R10:
pDE->m_context.R10= newValue;
break;
case REGISTER_AMD64_R11:
pDE->m_context.R11 = newValue;
break;
case REGISTER_AMD64_R12:
pDE->m_context.R12 = newValue;
break;
case REGISTER_AMD64_R13:
pDE->m_context.R13 = newValue;
break;
case REGISTER_AMD64_R14:
pDE->m_context.R14 = newValue;
break;
case REGISTER_AMD64_R15:
pDE->m_context.R15 = newValue;
break;
// fall through
case REGISTER_AMD64_XMM0:
case REGISTER_AMD64_XMM1:
case REGISTER_AMD64_XMM2:
case REGISTER_AMD64_XMM3:
case REGISTER_AMD64_XMM4:
case REGISTER_AMD64_XMM5:
case REGISTER_AMD64_XMM6:
case REGISTER_AMD64_XMM7:
case REGISTER_AMD64_XMM8:
case REGISTER_AMD64_XMM9:
case REGISTER_AMD64_XMM10:
case REGISTER_AMD64_XMM11:
case REGISTER_AMD64_XMM12:
case REGISTER_AMD64_XMM13:
case REGISTER_AMD64_XMM14:
case REGISTER_AMD64_XMM15:
R8ToFPSpill(&(pDE->m_context.Xmm0) + (reg - REGISTER_AMD64_XMM0), newValue);
break;
#elif defined(TARGET_ARM64)
// fall through
case REGISTER_ARM64_X0:
case REGISTER_ARM64_X1:
case REGISTER_ARM64_X2:
case REGISTER_ARM64_X3:
case REGISTER_ARM64_X4:
case REGISTER_ARM64_X5:
case REGISTER_ARM64_X6:
case REGISTER_ARM64_X7:
case REGISTER_ARM64_X8:
case REGISTER_ARM64_X9:
case REGISTER_ARM64_X10:
case REGISTER_ARM64_X11:
case REGISTER_ARM64_X12:
case REGISTER_ARM64_X13:
case REGISTER_ARM64_X14:
case REGISTER_ARM64_X15:
case REGISTER_ARM64_X16:
case REGISTER_ARM64_X17:
case REGISTER_ARM64_X18:
case REGISTER_ARM64_X19:
case REGISTER_ARM64_X20:
case REGISTER_ARM64_X21:
case REGISTER_ARM64_X22:
case REGISTER_ARM64_X23:
case REGISTER_ARM64_X24:
case REGISTER_ARM64_X25:
case REGISTER_ARM64_X26:
case REGISTER_ARM64_X27:
case REGISTER_ARM64_X28:
pDE->m_context.X[reg - REGISTER_ARM64_X0] = newValue;
break;
case REGISTER_ARM64_LR:
pDE->m_context.Lr = newValue;
break;
case REGISTER_ARM64_V0:
case REGISTER_ARM64_V1:
case REGISTER_ARM64_V2:
case REGISTER_ARM64_V3:
case REGISTER_ARM64_V4:
case REGISTER_ARM64_V5:
case REGISTER_ARM64_V6:
case REGISTER_ARM64_V7:
case REGISTER_ARM64_V8:
case REGISTER_ARM64_V9:
case REGISTER_ARM64_V10:
case REGISTER_ARM64_V11:
case REGISTER_ARM64_V12:
case REGISTER_ARM64_V13:
case REGISTER_ARM64_V14:
case REGISTER_ARM64_V15:
case REGISTER_ARM64_V16:
case REGISTER_ARM64_V17:
case REGISTER_ARM64_V18:
case REGISTER_ARM64_V19:
case REGISTER_ARM64_V20:
case REGISTER_ARM64_V21:
case REGISTER_ARM64_V22:
case REGISTER_ARM64_V23:
case REGISTER_ARM64_V24:
case REGISTER_ARM64_V25:
case REGISTER_ARM64_V26:
case REGISTER_ARM64_V27:
case REGISTER_ARM64_V28:
case REGISTER_ARM64_V29:
case REGISTER_ARM64_V30:
case REGISTER_ARM64_V31:
R8ToFPSpill(&pDE->m_context.V[reg - REGISTER_ARM64_V0], newValue);
break;
#endif // !TARGET_X86 && !TARGET_AMD64 && !TARGET_ARM64
default:
_ASSERT(!"Invalid register number!");
}
}
}
/*
* GetRegisterValueAndReturnAddress
*
* This routine takes out a value from a register, or set of registers, into one of
* the given buffers (depending on size), and returns a pointer to the filled in
* buffer, or NULL on error.
*
* Parameters:
* pDE - pointer to the DebuggerEval object being processed.
* pFEAD - Information about this particular argument.
* pInt64Buf - pointer to a buffer of type INT64
* pSizeTBuf - pointer to a buffer of native size type.
*
* Returns:
* pointer to the filled in buffer, else NULL on error.
*
*/
static PVOID GetRegisterValueAndReturnAddress(DebuggerEval *pDE,
DebuggerIPCE_FuncEvalArgData *pFEAD,
INT64 *pInt64Buf,
SIZE_T *pSizeTBuf
)
{
LIMITED_METHOD_CONTRACT;
PVOID pAddr;
#if !defined(HOST_64BIT)
pAddr = pInt64Buf;
DWORD *pLow = (DWORD*)(pInt64Buf);
DWORD *pHigh = pLow + 1;
#endif // HOST_64BIT
switch (pFEAD->argHome.kind)
{
#if !defined(HOST_64BIT)
case RAK_REGREG:
*pLow = GetRegisterValue(pDE, pFEAD->argHome.u.reg2, pFEAD->argHome.u.reg2Addr, pFEAD->argHome.u.reg2Value);
*pHigh = GetRegisterValue(pDE, pFEAD->argHome.reg1, pFEAD->argHome.reg1Addr, pFEAD->argHome.reg1Value);
break;
case RAK_MEMREG:
*pLow = GetRegisterValue(pDE, pFEAD->argHome.reg1, pFEAD->argHome.reg1Addr, pFEAD->argHome.reg1Value);
*pHigh = *((DWORD*)CORDB_ADDRESS_TO_PTR(pFEAD->argHome.addr));
break;
case RAK_REGMEM:
*pLow = *((DWORD*)CORDB_ADDRESS_TO_PTR(pFEAD->argHome.addr));
*pHigh = GetRegisterValue(pDE, pFEAD->argHome.reg1, pFEAD->argHome.reg1Addr, pFEAD->argHome.reg1Value);
break;
#endif // HOST_64BIT
case RAK_REG:
// Simply grab the value out of the proper register.
*pSizeTBuf = GetRegisterValue(pDE, pFEAD->argHome.reg1, pFEAD->argHome.reg1Addr, pFEAD->argHome.reg1Value);
pAddr = pSizeTBuf;
break;
default:
pAddr = NULL;
break;
}
return pAddr;
}
//---------------------------------------------------------------------------------------
//
// Clean up any temporary value class variables we have allocated for the funceval.
//
// Arguments:
// pStackStructArray - array whose elements track the location and type of the temporary variables
//
void CleanUpTemporaryVariables(ValueClassInfo ** ppProtectedValueClasses)
{
while (*ppProtectedValueClasses != NULL)
{
ValueClassInfo * pValueClassInfo = *ppProtectedValueClasses;
*ppProtectedValueClasses = pValueClassInfo->pNext;
DeleteInteropSafe(reinterpret_cast<BYTE *>(pValueClassInfo));
}
}
#ifdef _DEBUG
//
// Create a parallel array that tracks that we have initialized information in
// each array.
//
#define MAX_DATA_LOCATIONS_TRACKED 100
typedef DWORD DataLocation;
#define DL_NonExistent 0x00
#define DL_ObjectRefArray 0x01
#define DL_MaybeInteriorPtrArray 0x02
#define DL_BufferForArgsArray 0x04
#define DL_All 0xFF
#endif // _DEBUG
/*
* GetFuncEvalArgValue
*
* This routine is used to fill the pArgument array with the appropriate value. This function
* uses the three parallel array entries given, and places the correct value, or reference to
* the value in pArgument.
*
* Parameters:
* pDE - pointer to the DebuggerEval object being processed.
* pFEAD - Information about this particular argument.
* isByRef - Is the argument being passed ByRef.
* fNeedBoxOrUnbox - Did the argument need boxing or unboxing.
* argTH - The type handle for the argument.
* byrefArgSigType - The signature type of a parameter that isByRef == true.
* pArgument - Location to place the reference or value.
* pMaybeInteriorPtrArg - A pointer that contains a value that may be pointers to
* the interior of a managed object.
* pObjectRefArg - A pointer that contains an object ref. It was built previously.
* pBufferArg - A pointer for holding stuff that did not need to be protected.
*
* Returns:
* None.
*
*/
static void GetFuncEvalArgValue(DebuggerEval *pDE,
DebuggerIPCE_FuncEvalArgData *pFEAD,
bool isByRef,
bool fNeedBoxOrUnbox,
TypeHandle argTH,
CorElementType byrefArgSigType,
TypeHandle byrefArgTH,
ARG_SLOT *pArgument,
void *pMaybeInteriorPtrArg,
OBJECTREF *pObjectRefArg,
INT64 *pBufferArg,
ValueClassInfo ** ppProtectedValueClasses,
CorElementType argSigType
DEBUG_ARG(DataLocation dataLocation)
)
{
CONTRACTL
{
THROWS;
GC_NOTRIGGER;
}
CONTRACTL_END;
_ASSERTE((dataLocation != DL_NonExistent) ||
(pFEAD->argElementType == ELEMENT_TYPE_VALUETYPE));
switch (pFEAD->argElementType)
{
case ELEMENT_TYPE_I8:
case ELEMENT_TYPE_U8:
case ELEMENT_TYPE_R8:
{
INT64 *pSource;
#if defined(HOST_64BIT)
_ASSERTE(dataLocation & DL_MaybeInteriorPtrArray);
pSource = (INT64 *)pMaybeInteriorPtrArg;
#else // !HOST_64BIT
_ASSERTE(dataLocation & DL_BufferForArgsArray);
pSource = pBufferArg;
#endif // !HOST_64BIT
if (!isByRef)
{
*((INT64*)pArgument) = *pSource;
}
else
{
*pArgument = PtrToArgSlot(pSource);
}
}
break;
case ELEMENT_TYPE_VALUETYPE:
{
SIZE_T v = 0;
LPVOID pAddr = NULL;
INT64 bigVal = 0;
if (pFEAD->argAddr != NULL)
{
pAddr = *((void **)pMaybeInteriorPtrArg);
}
else
{
pAddr = GetRegisterValueAndReturnAddress(pDE, pFEAD, &bigVal, &v);
if (pAddr == NULL)
{
COMPlusThrow(kArgumentNullException);
}
}
_ASSERTE(pAddr);
if (!fNeedBoxOrUnbox && !isByRef)
{
_ASSERTE(argTH.GetMethodTable());
unsigned size = argTH.GetMethodTable()->GetNumInstanceFieldBytes();
if (size <= sizeof(ARG_SLOT)
#if defined(TARGET_AMD64)
// On AMD64 we pass value types of size which are not powers of 2 by ref.
&& ((size & (size-1)) == 0)
#endif // TARGET_AMD64
)
{
memcpyNoGCRefs(ArgSlotEndiannessFixup(pArgument, sizeof(LPVOID)), pAddr, size);
}
else
{
_ASSERTE(pFEAD->argAddr != NULL);
#if defined(ENREGISTERED_PARAMTYPE_MAXSIZE)
if (ArgIterator::IsArgPassedByRef(argTH))
{
// On X64, by-value value class arguments which are bigger than 8 bytes are passed by reference
// according to the native calling convention. The same goes for value class arguments whose size
// is smaller than 8 bytes but not a power of 2. To avoid side effets, we need to allocate a
// temporary variable and pass that by reference instead. On ARM64, by-value value class
// arguments which are bigger than 16 bytes are passed by reference.
_ASSERTE(ppProtectedValueClasses != NULL);
BYTE * pTemp = new (interopsafe) BYTE[ALIGN_UP(sizeof(ValueClassInfo), 8) + size];
ValueClassInfo * pValueClassInfo = (ValueClassInfo *)pTemp;
LPVOID pData = pTemp + ALIGN_UP(sizeof(ValueClassInfo), 8);
memcpyNoGCRefs(pData, pAddr, size);
*pArgument = PtrToArgSlot(pData);
pValueClassInfo->pData = pData;
pValueClassInfo->pMT = argTH.GetMethodTable();
pValueClassInfo->pNext = *ppProtectedValueClasses;
*ppProtectedValueClasses = pValueClassInfo;
}
else
#endif // ENREGISTERED_PARAMTYPE_MAXSIZE
*pArgument = PtrToArgSlot(pAddr);
}
}
else
{
if (fNeedBoxOrUnbox)
{
*pArgument = ObjToArgSlot(*pObjectRefArg);
}
else
{
if (pFEAD->argAddr)
{
*pArgument = PtrToArgSlot(pAddr);
}
else
{
// The argument is the address of where we're holding the primitive in the PrimitiveArg array. We
// stick the real value from the register into the PrimitiveArg array. It should be in a single
// register since it is pointer-sized.
_ASSERTE( pFEAD->argHome.kind == RAK_REG );
*pArgument = PtrToArgSlot(pBufferArg);
*pBufferArg = (INT64)v;
}
}
}
}
break;
default:
// literal values smaller than 8 bytes and "special types" (e.g. object, string, etc.)
{
INT64 *pSource;
INDEBUG(DataLocation expectedLocation);
#ifdef TARGET_X86
if ((pFEAD->argElementType == ELEMENT_TYPE_I4) ||
(pFEAD->argElementType == ELEMENT_TYPE_U4) ||
(pFEAD->argElementType == ELEMENT_TYPE_R4))
{
INDEBUG(expectedLocation = DL_MaybeInteriorPtrArray);
pSource = (INT64 *)pMaybeInteriorPtrArg;
}
else
#endif
if (IsElementTypeSpecial(pFEAD->argElementType))
{
INDEBUG(expectedLocation = DL_ObjectRefArray);
pSource = (INT64 *)pObjectRefArg;
}
else
{
INDEBUG(expectedLocation = DL_BufferForArgsArray);
pSource = pBufferArg;
}
if (pFEAD->argAddr != NULL)
{