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
|
/* $Id: TRPMAll.cpp $ */
/** @file
* TRPM - Trap Monitor - Any Context.
*/
/*
* Copyright (C) 2006-2019 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*********************************************************************************************************************************
* Header Files *
*********************************************************************************************************************************/
#define LOG_GROUP LOG_GROUP_TRPM
#include <VBox/vmm/trpm.h>
#include <VBox/vmm/pgm.h>
#include <VBox/vmm/mm.h>
#include <VBox/vmm/hm.h>
#include <VBox/vmm/patm.h>
#include <VBox/vmm/selm.h>
#include <VBox/vmm/stam.h>
#include <VBox/vmm/dbgf.h>
#include "TRPMInternal.h"
#include <VBox/vmm/vm.h>
#include <VBox/err.h>
#include <VBox/vmm/em.h>
#include <VBox/log.h>
#include <iprt/assert.h>
#include <iprt/asm.h>
#include <iprt/asm-amd64-x86.h>
#include <iprt/param.h>
#include <iprt/x86.h>
#if defined(TRPM_TRACK_GUEST_IDT_CHANGES) && !defined(IN_RING0)
/**
* @callback_method_impl{FNPGMVIRTPFHANDLER,
* \#PF Handler callback for virtual access handler ranges.}
*
* Important to realize that a physical page in a range can have aliases, and
* for ALL and WRITE handlers these will also trigger.
*/
PGM_ALL_CB2_DECL(VBOXSTRICTRC)
trpmGuestIDTWriteHandler(PVM pVM, PVMCPU pVCpu, RTGCPTR GCPtr, void *pvPtr, void *pvBuf, size_t cbBuf,
PGMACCESSTYPE enmAccessType, PGMACCESSORIGIN enmOrigin, void *pvUser)
{
Assert(enmAccessType == PGMACCESSTYPE_WRITE); NOREF(enmAccessType);
Log(("trpmGuestIDTWriteHandler: write to %RGv size %d\n", GCPtr, cbBuf)); NOREF(GCPtr); NOREF(cbBuf);
NOREF(pvPtr); NOREF(pvUser); NOREF(pvBuf); NOREF(enmOrigin); NOREF(pvUser); RT_NOREF_PV(pVM);
Assert(VM_IS_RAW_MODE_ENABLED(pVM));
/** @todo Check which IDT entry and keep the update cost low in TRPMR3SyncIDT() and CSAMCheckGates(). */
VMCPU_FF_SET(pVCpu, VMCPU_FF_TRPM_SYNC_IDT);
# ifdef IN_RC
STAM_COUNTER_INC(&pVM->trpm.s.StatRCWriteGuestIDTFault);
# endif
return VINF_PGM_HANDLER_DO_DEFAULT;
}
#endif /* TRPM_TRACK_GUEST_IDT_CHANGES && !IN_RING0 */
/**
* Query info about the current active trap/interrupt.
* If no trap is active active an error code is returned.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu8TrapNo Where to store the trap number.
* @param penmType Where to store the trap type
*/
VMMDECL(int) TRPMQueryTrap(PVMCPU pVCpu, uint8_t *pu8TrapNo, TRPMEVENT *penmType)
{
/*
* Check if we have a trap at present.
*/
if (pVCpu->trpm.s.uActiveVector != ~0U)
{
if (pu8TrapNo)
*pu8TrapNo = (uint8_t)pVCpu->trpm.s.uActiveVector;
if (penmType)
*penmType = pVCpu->trpm.s.enmActiveType;
return VINF_SUCCESS;
}
return VERR_TRPM_NO_ACTIVE_TRAP;
}
/**
* Gets the trap number for the current trap.
*
* The caller is responsible for making sure there is an active trap which
* takes an error code when making this request.
*
* @returns The current trap number.
* @param pVCpu The cross context virtual CPU structure.
*/
VMMDECL(uint8_t) TRPMGetTrapNo(PVMCPU pVCpu)
{
AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
return (uint8_t)pVCpu->trpm.s.uActiveVector;
}
/**
* Gets the error code for the current trap.
*
* The caller is responsible for making sure there is an active trap which
* takes an error code when making this request.
*
* @returns Error code.
* @param pVCpu The cross context virtual CPU structure.
*/
VMMDECL(RTGCUINT) TRPMGetErrorCode(PVMCPU pVCpu)
{
AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
#ifdef VBOX_STRICT
switch (pVCpu->trpm.s.uActiveVector)
{
case X86_XCPT_TS:
case X86_XCPT_NP:
case X86_XCPT_SS:
case X86_XCPT_GP:
case X86_XCPT_PF:
case X86_XCPT_AC:
case X86_XCPT_DF:
break;
default:
AssertMsgFailed(("This trap (%#x) doesn't have any error code\n", pVCpu->trpm.s.uActiveVector));
break;
}
#endif
return pVCpu->trpm.s.uActiveErrorCode;
}
/**
* Gets the fault address for the current trap.
*
* The caller is responsible for making sure there is an active trap 0x0e when
* making this request.
*
* @returns Fault address associated with the trap.
* @param pVCpu The cross context virtual CPU structure.
*/
VMMDECL(RTGCUINTPTR) TRPMGetFaultAddress(PVMCPU pVCpu)
{
AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
AssertMsg(pVCpu->trpm.s.uActiveVector == X86_XCPT_PF, ("Not page-fault trap!\n"));
return pVCpu->trpm.s.uActiveCR2;
}
/**
* Gets the instruction-length for the current trap (only relevant for software
* interrupts and software exceptions \#BP and \#OF).
*
* The caller is responsible for making sure there is an active trap 0x0e when
* making this request.
*
* @returns Fault address associated with the trap.
* @param pVCpu The cross context virtual CPU structure.
*/
VMMDECL(uint8_t) TRPMGetInstrLength(PVMCPU pVCpu)
{
AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
return pVCpu->trpm.s.cbInstr;
}
/**
* Clears the current active trap/exception/interrupt.
*
* The caller is responsible for making sure there is an active trap
* when making this request.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*/
VMMDECL(int) TRPMResetTrap(PVMCPU pVCpu)
{
/*
* Cannot reset non-existing trap!
*/
if (pVCpu->trpm.s.uActiveVector == ~0U)
{
AssertMsgFailed(("No active trap!\n"));
return VERR_TRPM_NO_ACTIVE_TRAP;
}
/*
* Reset it.
*/
pVCpu->trpm.s.uActiveVector = ~0U;
return VINF_SUCCESS;
}
/**
* Assert trap/exception/interrupt.
*
* The caller is responsible for making sure there is no active trap
* when making this request.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u8TrapNo The trap vector to assert.
* @param enmType Trap type.
*/
VMMDECL(int) TRPMAssertTrap(PVMCPU pVCpu, uint8_t u8TrapNo, TRPMEVENT enmType)
{
Log2(("TRPMAssertTrap: u8TrapNo=%02x type=%d\n", u8TrapNo, enmType));
/*
* Cannot assert a trap when one is already active.
*/
if (pVCpu->trpm.s.uActiveVector != ~0U)
{
AssertMsgFailed(("CPU%d: Active trap %#x\n", pVCpu->idCpu, pVCpu->trpm.s.uActiveVector));
return VERR_TRPM_ACTIVE_TRAP;
}
pVCpu->trpm.s.uActiveVector = u8TrapNo;
pVCpu->trpm.s.enmActiveType = enmType;
pVCpu->trpm.s.uActiveErrorCode = ~(RTGCUINT)0;
pVCpu->trpm.s.uActiveCR2 = 0xdeadface;
pVCpu->trpm.s.cbInstr = UINT8_MAX;
return VINF_SUCCESS;
}
/**
* Assert a page-fault exception.
*
* The caller is responsible for making sure there is no active trap
* when making this request.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param uCR2 The new fault address.
* @param uErrorCode The error code for the page-fault.
*/
VMMDECL(int) TRPMAssertXcptPF(PVMCPU pVCpu, RTGCUINTPTR uCR2, RTGCUINT uErrorCode)
{
Log2(("TRPMAssertXcptPF: uCR2=%RGv uErrorCode=%RGv\n", uCR2, uErrorCode)); /** @todo RTGCUINT to be fixed. */
/*
* Cannot assert a trap when one is already active.
*/
if (pVCpu->trpm.s.uActiveVector != ~0U)
{
AssertMsgFailed(("CPU%d: Active trap %#x\n", pVCpu->idCpu, pVCpu->trpm.s.uActiveVector));
return VERR_TRPM_ACTIVE_TRAP;
}
pVCpu->trpm.s.uActiveVector = X86_XCPT_PF;
pVCpu->trpm.s.enmActiveType = TRPM_TRAP;
pVCpu->trpm.s.uActiveErrorCode = uErrorCode;
pVCpu->trpm.s.uActiveCR2 = uCR2;
pVCpu->trpm.s.cbInstr = UINT8_MAX;
return VINF_SUCCESS;
}
/**
* Sets the error code of the current trap.
* (This function is for use in trap handlers and such.)
*
* The caller is responsible for making sure there is an active trap
* which takes an errorcode when making this request.
*
* @param pVCpu The cross context virtual CPU structure.
* @param uErrorCode The new error code.
*/
VMMDECL(void) TRPMSetErrorCode(PVMCPU pVCpu, RTGCUINT uErrorCode)
{
Log2(("TRPMSetErrorCode: uErrorCode=%RGv\n", uErrorCode)); /** @todo RTGCUINT mess! */
AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
pVCpu->trpm.s.uActiveErrorCode = uErrorCode;
#ifdef VBOX_STRICT
switch (pVCpu->trpm.s.uActiveVector)
{
case X86_XCPT_TS: case X86_XCPT_NP: case X86_XCPT_SS: case X86_XCPT_GP: case X86_XCPT_PF:
AssertMsg(uErrorCode != ~(RTGCUINT)0, ("Invalid uErrorCode=%#x u8TrapNo=%d\n", uErrorCode, pVCpu->trpm.s.uActiveVector));
break;
case X86_XCPT_AC: case X86_XCPT_DF:
AssertMsg(uErrorCode == 0, ("Invalid uErrorCode=%#x u8TrapNo=%d\n", uErrorCode, pVCpu->trpm.s.uActiveVector));
break;
default:
AssertMsg(uErrorCode == ~(RTGCUINT)0, ("Invalid uErrorCode=%#x u8TrapNo=%d\n", uErrorCode, pVCpu->trpm.s.uActiveVector));
break;
}
#endif
}
/**
* Sets the fault address of the current \#PF trap. (This function is for use in
* trap handlers and such.)
*
* The caller is responsible for making sure there is an active trap 0e
* when making this request.
*
* @param pVCpu The cross context virtual CPU structure.
* @param uCR2 The new fault address (cr2 register).
*/
VMMDECL(void) TRPMSetFaultAddress(PVMCPU pVCpu, RTGCUINTPTR uCR2)
{
Log2(("TRPMSetFaultAddress: uCR2=%RGv\n", uCR2));
AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
AssertMsg(pVCpu->trpm.s.uActiveVector == X86_XCPT_PF, ("Not trap 0e!\n"));
pVCpu->trpm.s.uActiveCR2 = uCR2;
}
/**
* Sets the instruction-length of the current trap (relevant for software
* interrupts and software exceptions like \#BP, \#OF).
*
* The caller is responsible for making sure there is an active trap 0e
* when making this request.
*
* @param pVCpu The cross context virtual CPU structure.
* @param cbInstr The instruction length.
*/
VMMDECL(void) TRPMSetInstrLength(PVMCPU pVCpu, uint8_t cbInstr)
{
Log2(("TRPMSetInstrLength: cbInstr=%u\n", cbInstr));
AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
AssertMsg( pVCpu->trpm.s.enmActiveType == TRPM_SOFTWARE_INT
|| ( pVCpu->trpm.s.enmActiveType == TRPM_TRAP
&& ( pVCpu->trpm.s.uActiveVector == X86_XCPT_BP
|| pVCpu->trpm.s.uActiveVector == X86_XCPT_OF)),
("Invalid trap type %#x\n", pVCpu->trpm.s.enmActiveType));
pVCpu->trpm.s.cbInstr = cbInstr;
}
/**
* Checks if the current active trap/interrupt/exception/fault/whatever is a software
* interrupt or not.
*
* The caller is responsible for making sure there is an active trap
* when making this request.
*
* @returns true if software interrupt, false if not.
*
* @param pVCpu The cross context virtual CPU structure.
*/
VMMDECL(bool) TRPMIsSoftwareInterrupt(PVMCPU pVCpu)
{
AssertMsg(pVCpu->trpm.s.uActiveVector != ~0U, ("No active trap!\n"));
return (pVCpu->trpm.s.enmActiveType == TRPM_SOFTWARE_INT);
}
/**
* Check if there is an active trap.
*
* @returns true if trap active, false if not.
* @param pVCpu The cross context virtual CPU structure.
*/
VMMDECL(bool) TRPMHasTrap(PVMCPU pVCpu)
{
return pVCpu->trpm.s.uActiveVector != ~0U;
}
/**
* Query all info about the current active trap/interrupt.
* If no trap is active active an error code is returned.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu8TrapNo Where to store the trap number.
* @param pEnmType Where to store the trap type
* @param puErrorCode Where to store the error code associated with some traps.
* ~0U is stored if the trap has no error code.
* @param puCR2 Where to store the CR2 associated with a trap 0E.
* @param pcbInstr Where to store the instruction-length
* associated with some traps.
*/
VMMDECL(int) TRPMQueryTrapAll(PVMCPU pVCpu, uint8_t *pu8TrapNo, TRPMEVENT *pEnmType, PRTGCUINT puErrorCode, PRTGCUINTPTR puCR2,
uint8_t *pcbInstr)
{
/*
* Check if we have a trap at present.
*/
if (pVCpu->trpm.s.uActiveVector == ~0U)
return VERR_TRPM_NO_ACTIVE_TRAP;
if (pu8TrapNo)
*pu8TrapNo = (uint8_t)pVCpu->trpm.s.uActiveVector;
if (pEnmType)
*pEnmType = pVCpu->trpm.s.enmActiveType;
if (puErrorCode)
*puErrorCode = pVCpu->trpm.s.uActiveErrorCode;
if (puCR2)
*puCR2 = pVCpu->trpm.s.uActiveCR2;
if (pcbInstr)
*pcbInstr = pVCpu->trpm.s.cbInstr;
return VINF_SUCCESS;
}
/**
* Save the active trap.
*
* This routine useful when doing try/catch in the hypervisor.
* Any function which uses temporary trap handlers should
* probably also use this facility to save the original trap.
*
* @param pVCpu The cross context virtual CPU structure.
*/
VMMDECL(void) TRPMSaveTrap(PVMCPU pVCpu)
{
pVCpu->trpm.s.uSavedVector = pVCpu->trpm.s.uActiveVector;
pVCpu->trpm.s.enmSavedType = pVCpu->trpm.s.enmActiveType;
pVCpu->trpm.s.uSavedErrorCode = pVCpu->trpm.s.uActiveErrorCode;
pVCpu->trpm.s.uSavedCR2 = pVCpu->trpm.s.uActiveCR2;
pVCpu->trpm.s.cbSavedInstr = pVCpu->trpm.s.cbInstr;
}
/**
* Restore a saved trap.
*
* Multiple restores of a saved trap is possible.
*
* @param pVCpu The cross context virtual CPU structure.
*/
VMMDECL(void) TRPMRestoreTrap(PVMCPU pVCpu)
{
pVCpu->trpm.s.uActiveVector = pVCpu->trpm.s.uSavedVector;
pVCpu->trpm.s.enmActiveType = pVCpu->trpm.s.enmSavedType;
pVCpu->trpm.s.uActiveErrorCode = pVCpu->trpm.s.uSavedErrorCode;
pVCpu->trpm.s.uActiveCR2 = pVCpu->trpm.s.uSavedCR2;
pVCpu->trpm.s.cbInstr = pVCpu->trpm.s.cbSavedInstr;
}
#ifdef VBOX_WITH_RAW_MODE_NOT_R0
/**
* Forward trap or interrupt to the guest's handler
*
*
* @returns VBox status code.
* or does not return at all (when the trap is actually forwarded)
*
* @param pVCpu The cross context virtual CPU structure.
* @param pRegFrame Pointer to the register frame for the trap.
* @param iGate Trap or interrupt gate number
* @param cbInstr Instruction size (only relevant for software interrupts)
* @param enmError TRPM_TRAP_HAS_ERRORCODE or TRPM_TRAP_NO_ERRORCODE.
* @param enmType TRPM event type
* @param iOrgTrap The original trap.
* @internal
*/
VMMDECL(int) TRPMForwardTrap(PVMCPU pVCpu, PCPUMCTXCORE pRegFrame, uint32_t iGate, uint32_t cbInstr,
TRPMERRORCODE enmError, TRPMEVENT enmType, int32_t iOrgTrap)
{
AssertReturn(VM_IS_RAW_MODE_ENABLED(pVCpu->CTX_SUFF(pVM)), VERR_TRPM_HM_IPE);
#ifdef TRPM_FORWARD_TRAPS_IN_GC
PVM pVM = pVCpu->CTX_SUFF(pVM);
X86EFLAGS eflags;
Assert(pVM->cCpus == 1);
STAM_PROFILE_ADV_START(&pVM->trpm.s.CTX_SUFF_Z(StatForwardProf), a);
# if defined(VBOX_STRICT) || defined(LOG_ENABLED)
if (pRegFrame->eflags.Bits.u1VM)
Log(("TRPMForwardTrap-VM: eip=%04X:%04X iGate=%d\n", pRegFrame->cs.Sel, pRegFrame->eip, iGate));
else
Log(("TRPMForwardTrap: eip=%04X:%08X iGate=%d\n", pRegFrame->cs.Sel, pRegFrame->eip, iGate));
switch (iGate) {
case X86_XCPT_PF:
if (pRegFrame->eip == pVCpu->trpm.s.uActiveCR2)
{
RTGCPTR pCallerGC;
# ifdef IN_RC
int rc = MMGCRamRead(pVM, &pCallerGC, (void *)pRegFrame->esp, sizeof(pCallerGC));
# else
int rc = PGMPhysSimpleReadGCPtr(pVCpu, &pCallerGC, (RTGCPTR)pRegFrame->esp, sizeof(pCallerGC));
# endif
if (RT_SUCCESS(rc))
Log(("TRPMForwardTrap: caller=%RGv\n", pCallerGC));
}
RT_FALL_THRU();
case X86_XCPT_DF:
case X86_XCPT_TS:
case X86_XCPT_NP:
case X86_XCPT_SS:
case X86_XCPT_GP:
case X86_XCPT_AC:
Assert(enmError == TRPM_TRAP_HAS_ERRORCODE || enmType == TRPM_SOFTWARE_INT);
break;
default:
Assert(enmError == TRPM_TRAP_NO_ERRORCODE);
break;
}
# endif /* VBOX_STRICT || LOG_ENABLED */
#ifdef IN_RC
AssertReturn(CPUMIsGuestInRawMode(pVCpu), VINF_EM_RESCHEDULE);
#endif
/* Retrieve the eflags including the virtualized bits. */
/* Note: hackish as the cpumctxcore structure doesn't contain the right value */
eflags.u32 = CPUMRawGetEFlags(pVCpu);
/* VMCPU_FF_INHIBIT_INTERRUPTS should be cleared upfront or don't call this function at all for dispatching hardware interrupts. */
Assert(enmType != TRPM_HARDWARE_INT || !VMCPU_FF_IS_SET(pVCpu, VMCPU_FF_INHIBIT_INTERRUPTS));
/*
* If it's a real guest trap and the guest's page fault handler is marked as safe for GC execution, then we call it directly.
* Well, only if the IF flag is set.
*/
/** @todo if the trap handler was modified and marked invalid, then we should *now* go back to the host context and install a new patch. */
if ( pVM->trpm.s.aGuestTrapHandler[iGate]
&& (eflags.Bits.u1IF)
#ifndef VBOX_RAW_V86
&& !(eflags.Bits.u1VM) /** @todo implement when needed (illegal for same privilege level transfers). */
#endif
&& !PATMIsPatchGCAddr(pVM, pRegFrame->eip)
)
{
uint16_t cbIDT;
RTGCPTR GCPtrIDT = (RTGCPTR)CPUMGetGuestIDTR(pVCpu, &cbIDT);
uint32_t cpl;
VBOXIDTE GuestIdte;
RTGCPTR pIDTEntry;
int rc;
Assert(PATMAreInterruptsEnabledByCtx(pVM, CPUMCTX_FROM_CORE(pRegFrame)));
Assert(!VMCPU_FF_IS_ANY_SET(pVCpu, VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT | VMCPU_FF_TRPM_SYNC_IDT | VMCPU_FF_SELM_SYNC_TSS));
if (GCPtrIDT && iGate * sizeof(VBOXIDTE) >= cbIDT)
goto failure;
/* Get the current privilege level. */
cpl = CPUMGetGuestCPL(pVCpu);
/*
* BIG TODO: The checks are not complete. see trap and interrupt dispatching section in Intel docs for details
* All very obscure, but still necessary.
* Currently only some CS & TSS selector checks are missing.
*
*/
pIDTEntry = (RTGCPTR)((RTGCUINTPTR)GCPtrIDT + sizeof(VBOXIDTE) * iGate);
#ifdef IN_RC
rc = MMGCRamRead(pVM, &GuestIdte, (void *)(uintptr_t)pIDTEntry, sizeof(GuestIdte));
#else
rc = PGMPhysSimpleReadGCPtr(pVCpu, &GuestIdte, pIDTEntry, sizeof(GuestIdte));
#endif
if (RT_FAILURE(rc))
{
/* The page might be out of sync. */ /** @todo might cross a page boundary) */
Log(("Page %RGv out of sync -> prefetch and try again\n", pIDTEntry));
rc = PGMPrefetchPage(pVCpu, pIDTEntry); /** @todo r=bird: rainy day: this isn't entirely safe because of access bit virtualiziation and CSAM. */
if (rc != VINF_SUCCESS)
{
Log(("TRPMForwardTrap: PGMPrefetchPage failed with rc=%Rrc\n", rc));
goto failure;
}
#ifdef IN_RC
rc = MMGCRamRead(pVM, &GuestIdte, (void *)(uintptr_t)pIDTEntry, sizeof(GuestIdte));
#else
rc = PGMPhysSimpleReadGCPtr(pVCpu, &GuestIdte, pIDTEntry, sizeof(GuestIdte));
#endif
}
if ( RT_SUCCESS(rc)
&& GuestIdte.Gen.u1Present
&& (GuestIdte.Gen.u5Type2 == VBOX_IDTE_TYPE2_TRAP_32 || GuestIdte.Gen.u5Type2 == VBOX_IDTE_TYPE2_INT_32)
&& (GuestIdte.Gen.u2DPL == 3 || GuestIdte.Gen.u2DPL == 0)
&& (GuestIdte.Gen.u16SegSel & 0xfffc) /* must not be zero */
&& (enmType == TRPM_TRAP || enmType == TRPM_HARDWARE_INT || cpl <= GuestIdte.Gen.u2DPL) /* CPL <= DPL if software int */
)
{
RTGCPTR pHandler, dummy;
RTGCPTR pTrapStackGC;
pHandler = (RTGCPTR)VBOXIDTE_OFFSET(GuestIdte);
/* Note: SELMValidateAndConvertCSAddr checks for code type, memory type, selector validity. */
/** @todo dpl <= cpl else GPF */
/* Note: don't use current eflags as we might be in V86 mode and the IDT always contains protected mode selectors */
X86EFLAGS fakeflags;
fakeflags.u32 = 0;
rc = SELMValidateAndConvertCSAddr(pVCpu, fakeflags, 0, GuestIdte.Gen.u16SegSel, NULL, pHandler, &dummy);
if (rc == VINF_SUCCESS)
{
VBOXGDTR gdtr = {0, 0};
bool fConforming = false;
int idx = 0;
uint32_t dpl;
uint32_t ss_r0;
uint32_t esp_r0;
X86DESC Desc;
RTGCPTR pGdtEntry;
CPUMGetGuestGDTR(pVCpu, &gdtr);
Assert(gdtr.pGdt && gdtr.cbGdt > GuestIdte.Gen.u16SegSel);
if (!gdtr.pGdt)
goto failure;
pGdtEntry = gdtr.pGdt + (GuestIdte.Gen.u16SegSel >> X86_SEL_SHIFT) * sizeof(X86DESC);
#ifdef IN_RC
rc = MMGCRamRead(pVM, &Desc, (void *)(uintptr_t)pGdtEntry, sizeof(Desc));
#else
rc = PGMPhysSimpleReadGCPtr(pVCpu, &Desc, pGdtEntry, sizeof(Desc));
#endif
if (RT_FAILURE(rc))
{
/* The page might be out of sync. */ /** @todo might cross a page boundary) */
Log(("Page %RGv out of sync -> prefetch and try again\n", pGdtEntry));
rc = PGMPrefetchPage(pVCpu, pGdtEntry); /** @todo r=bird: rainy day: this isn't entirely safe because of access bit virtualiziation and CSAM. */
if (rc != VINF_SUCCESS)
{
Log(("PGMPrefetchPage failed with rc=%Rrc\n", rc));
goto failure;
}
#ifdef IN_RC
rc = MMGCRamRead(pVM, &Desc, (void *)(uintptr_t)pGdtEntry, sizeof(Desc));
#else
rc = PGMPhysSimpleReadGCPtr(pVCpu, &Desc, pGdtEntry, sizeof(Desc));
#endif
if (RT_FAILURE(rc))
{
Log(("MMGCRamRead failed with %Rrc\n", rc));
goto failure;
}
}
if (Desc.Gen.u4Type & X86_SEL_TYPE_CONF)
{
Log(("Conforming code selector\n"));
fConforming = true;
}
/** @todo check descriptor type!! */
dpl = Desc.Gen.u2Dpl;
if (!fConforming && dpl < cpl) /* to inner privilege level */
{
rc = SELMGetRing1Stack(pVM, &ss_r0, &esp_r0);
if (RT_FAILURE(rc))
goto failure;
Assert((ss_r0 & X86_SEL_RPL) == 1);
if ( !esp_r0
|| !ss_r0
|| (ss_r0 & X86_SEL_RPL) != ((dpl == 0) ? 1 : dpl)
|| SELMToFlatBySelEx(pVCpu, fakeflags, ss_r0, (RTGCPTR)esp_r0, SELMTOFLAT_FLAGS_CPL1,
(PRTGCPTR)&pTrapStackGC, NULL) != VINF_SUCCESS
)
{
Log(("Invalid ring 0 stack %04X:%08RX32\n", ss_r0, esp_r0));
goto failure;
}
}
else
if (fConforming || dpl == cpl) /* to the same privilege level */
{
ss_r0 = pRegFrame->ss.Sel;
esp_r0 = pRegFrame->esp;
if ( eflags.Bits.u1VM /* illegal */
|| SELMToFlatBySelEx(pVCpu, fakeflags, ss_r0, (RTGCPTR)esp_r0, SELMTOFLAT_FLAGS_CPL1,
(PRTGCPTR)&pTrapStackGC, NULL) != VINF_SUCCESS)
{
AssertMsgFailed(("Invalid stack %04X:%08RX32??? (VM=%d)\n", ss_r0, esp_r0, eflags.Bits.u1VM));
goto failure;
}
}
else
{
Log(("Invalid cpl-dpl combo %d vs %d\n", cpl, dpl));
goto failure;
}
/*
* Build trap stack frame on guest handler's stack
*/
uint32_t *pTrapStack;
#ifdef IN_RC
Assert(eflags.Bits.u1VM || (pRegFrame->ss.Sel & X86_SEL_RPL) != 0);
/* Check maximum amount we need (10 when executing in V86 mode) */
rc = PGMVerifyAccess(pVCpu, (RTGCUINTPTR)pTrapStackGC - 10*sizeof(uint32_t), 10 * sizeof(uint32_t), X86_PTE_RW);
pTrapStack = (uint32_t *)(uintptr_t)pTrapStackGC;
#else
Assert(eflags.Bits.u1VM || (pRegFrame->ss.Sel & X86_SEL_RPL) == 0 || (pRegFrame->ss.Sel & X86_SEL_RPL) == 3 || (EMIsRawRing1Enabled(pVM) && (pRegFrame->ss.Sel & X86_SEL_RPL) == 1));
/* Check maximum amount we need (10 when executing in V86 mode) */
if ((pTrapStackGC >> PAGE_SHIFT) != ((pTrapStackGC - 10*sizeof(uint32_t)) >> PAGE_SHIFT)) /* fail if we cross a page boundary */
goto failure;
PGMPAGEMAPLOCK PageMappingLock;
rc = PGMPhysGCPtr2CCPtr(pVCpu, pTrapStackGC, (void **)&pTrapStack, &PageMappingLock);
if (RT_FAILURE(rc))
{
AssertRC(rc);
goto failure;
}
#endif
if (rc == VINF_SUCCESS)
{
/** if eflags.Bits.u1VM then push gs, fs, ds, es */
if (eflags.Bits.u1VM)
{
Log(("TRAP%02X: (VM) Handler %04X:%RGv Stack %04X:%08X RPL=%d CR2=%08X\n", iGate, GuestIdte.Gen.u16SegSel, pHandler, ss_r0, esp_r0, (pRegFrame->ss.Sel & X86_SEL_RPL), pVCpu->trpm.s.uActiveCR2));
pTrapStack[--idx] = pRegFrame->gs.Sel;
pTrapStack[--idx] = pRegFrame->fs.Sel;
pTrapStack[--idx] = pRegFrame->ds.Sel;
pTrapStack[--idx] = pRegFrame->es.Sel;
/* clear ds, es, fs & gs in current context */
pRegFrame->ds.Sel = pRegFrame->es.Sel = pRegFrame->fs.Sel = pRegFrame->gs.Sel = 0;
}
else
Log(("TRAP%02X: Handler %04X:%RGv Stack %04X:%08X RPL=%d CR2=%08X\n", iGate, GuestIdte.Gen.u16SegSel, pHandler, ss_r0, esp_r0, (pRegFrame->ss.Sel & X86_SEL_RPL), pVCpu->trpm.s.uActiveCR2));
if (!fConforming && dpl < cpl)
{
#ifdef IN_RC /* Only in RC we still see tracing of our ring modifications. */
if ( (pRegFrame->ss.Sel & X86_SEL_RPL) == 1
&& !eflags.Bits.u1VM)
pTrapStack[--idx] = pRegFrame->ss.Sel & ~1; /* Mask away traces of raw ring 0 execution (ring 1). */
else if ( EMIsRawRing1Enabled(pVM)
&& (pRegFrame->ss.Sel & X86_SEL_RPL) == 2)
pTrapStack[--idx] = (pRegFrame->ss.Sel & ~2) | 1; /* Mask away traces of raw ring 1 execution (ring 2). */
else
#endif /* IN_RC */
pTrapStack[--idx] = pRegFrame->ss.Sel;
pTrapStack[--idx] = pRegFrame->esp;
}
/* Note: We use the eflags copy, that includes the virtualized bits! */
/* Note: Not really necessary as we grab include those bits in the trap/irq handler trampoline */
pTrapStack[--idx] = eflags.u32;
#ifdef IN_RC /* Only in RC mode we still see tracing of our ring modifications */
if ( (pRegFrame->cs.Sel & X86_SEL_RPL) == 1
&& !eflags.Bits.u1VM)
pTrapStack[--idx] = pRegFrame->cs.Sel & ~1; /* Mask away traces of raw ring execution (ring 1). */
else if ( EMIsRawRing1Enabled(pVM)
&& (pRegFrame->cs.Sel & X86_SEL_RPL) == 2)
pTrapStack[--idx] = (pRegFrame->cs.Sel & ~2) | 1; /* Mask away traces of raw ring 1 execution (ring 2). */
else
#endif /* IN_RC */
pTrapStack[--idx] = pRegFrame->cs.Sel;
if (enmType == TRPM_SOFTWARE_INT)
{
Assert(cbInstr);
pTrapStack[--idx] = pRegFrame->eip + cbInstr; /* return address = next instruction */
}
else
pTrapStack[--idx] = pRegFrame->eip;
if (enmError == TRPM_TRAP_HAS_ERRORCODE)
{
pTrapStack[--idx] = pVCpu->trpm.s.uActiveErrorCode;
}
Assert(esp_r0 > -idx*sizeof(uint32_t));
/* Adjust ESP accordingly */
esp_r0 += idx*sizeof(uint32_t);
/* Mask away dangerous flags for the trap/interrupt handler. */
eflags.u32 &= ~(X86_EFL_TF | X86_EFL_VM | X86_EFL_RF | X86_EFL_NT);
#ifdef DEBUG
if (DBGFIsStepping(pVCpu))
eflags.u32 |= X86_EFL_TF;
#endif
/* Turn off interrupts for interrupt gates. */
if (GuestIdte.Gen.u5Type2 == VBOX_IDTE_TYPE2_INT_32)
eflags.Bits.u1IF = 0;
CPUMRawSetEFlags(pVCpu, eflags.u32);
#ifdef DEBUG
for (int j = idx; j < 0; j++)
LogFlow(("Stack %RRv pos %02d: %08x\n", &pTrapStack[j], j, pTrapStack[j]));
Log4(("eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n"
"eip=%08x esp=%08x ebp=%08x iopl=%d\n"
"cs=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n",
pRegFrame->eax, pRegFrame->ebx, pRegFrame->ecx, pRegFrame->edx, pRegFrame->esi, pRegFrame->edi,
pRegFrame->eip, pRegFrame->esp, pRegFrame->ebp, eflags.Bits.u2IOPL,
pRegFrame->cs.Sel, pRegFrame->ds.Sel, pRegFrame->es.Sel,
pRegFrame->fs.Sel, pRegFrame->gs.Sel, eflags.u32));
#endif
Log(("TRPM: PATM Handler %RRv Adjusted stack %08X new EFLAGS=%08X/%08x idx=%d dpl=%d cpl=%d\n",
pVM->trpm.s.aGuestTrapHandler[iGate], esp_r0, eflags.u32, CPUMRawGetEFlags(pVCpu), idx, dpl, cpl));
/* Make sure the internal guest context structure is up-to-date. */
if (iGate == X86_XCPT_PF)
CPUMSetGuestCR2(pVCpu, pVCpu->trpm.s.uActiveCR2);
#ifdef IN_RC
/* paranoia */
Assert(pRegFrame->eflags.Bits.u1IF == 1);
eflags.Bits.u1IF = 1;
Assert(pRegFrame->eflags.Bits.u2IOPL == 0);
eflags.Bits.u2IOPL = 0;
Assert(eflags.Bits.u1IF);
Assert(eflags.Bits.u2IOPL == 0);
STAM_COUNTER_INC(&pVM->trpm.s.CTX_SUFF(paStatForwardedIRQ)[iGate]);
STAM_PROFILE_ADV_STOP(&pVM->trpm.s.CTX_SUFF_Z(StatForwardProf), a);
if (iOrgTrap >= 0 && iOrgTrap < (int)RT_ELEMENTS(pVM->trpm.s.aStatGCTraps))
STAM_PROFILE_ADV_STOP(&pVM->trpm.s.aStatGCTraps[iOrgTrap], o);
PGMRZDynMapReleaseAutoSet(pVCpu);
CPUMGCCallGuestTrapHandler(pRegFrame, GuestIdte.Gen.u16SegSel | 1, pVM->trpm.s.aGuestTrapHandler[iGate],
eflags.u32, ss_r0, (RTRCPTR)esp_r0);
/* does not return */
#else
Assert(!CPUMIsGuestInRawMode(pVCpu));
pRegFrame->eflags.u32 = eflags.u32;
pRegFrame->eip = pVM->trpm.s.aGuestTrapHandler[iGate];
pRegFrame->cs.Sel = GuestIdte.Gen.u16SegSel;
pRegFrame->esp = esp_r0;
pRegFrame->ss.Sel = ss_r0 & ~X86_SEL_RPL; /* set rpl to ring 0 */
STAM_PROFILE_ADV_STOP(&pVM->trpm.s.CTX_SUFF_Z(StatForwardProf), a);
PGMPhysReleasePageMappingLock(pVM, &PageMappingLock);
NOREF(iOrgTrap);
return VINF_SUCCESS;
#endif
}
else
Log(("TRAP%02X: PGMVerifyAccess %RGv failed with %Rrc -> forward to REM\n", iGate, pTrapStackGC, rc));
}
else
Log(("SELMValidateAndConvertCSAddr failed with %Rrc\n", rc));
}
else
Log(("MMRamRead %RGv size %d failed with %Rrc\n", (RTGCUINTPTR)GCPtrIDT + sizeof(VBOXIDTE) * iGate, sizeof(GuestIdte), rc));
}
else
{
Log(("Refused to forward trap: eflags=%08x IF=%d\n", eflags.u32, eflags.Bits.u1IF));
#ifdef VBOX_WITH_STATISTICS
if (pVM->trpm.s.aGuestTrapHandler[iGate] == TRPM_INVALID_HANDLER)
STAM_COUNTER_INC(&pVM->trpm.s.StatForwardFailNoHandler);
else if (PATMIsPatchGCAddr(pVM, pRegFrame->eip))
STAM_COUNTER_INC(&pVM->trpm.s.StatForwardFailPatchAddr);
#endif
}
failure:
STAM_COUNTER_INC(&pVM->trpm.s.CTX_SUFF_Z(StatForwardFail));
STAM_PROFILE_ADV_STOP(&pVM->trpm.s.CTX_SUFF_Z(StatForwardProf), a);
Log(("TRAP%02X: forwarding to REM (ss rpl=%d eflags=%08X VMIF=%d handler=%08X\n", iGate, pRegFrame->ss.Sel & X86_SEL_RPL, pRegFrame->eflags.u32, PATMAreInterruptsEnabledByCtx(pVM, CPUMCTX_FROM_CORE(pRegFrame)), pVM->trpm.s.aGuestTrapHandler[iGate]));
#endif
return VINF_EM_RAW_GUEST_TRAP;
}
#endif /* VBOX_WITH_RAW_MODE_NOT_R0 */
/**
* Raises a cpu exception which doesn't take an error code.
*
* This function may or may not dispatch the exception before returning.
*
* @returns VBox status code fit for scheduling.
* @retval VINF_EM_RAW_GUEST_TRAP if the exception was left pending.
* @retval VINF_TRPM_XCPT_DISPATCHED if the exception was raised and dispatched for raw-mode execution.
* @retval VINF_EM_RESCHEDULE_REM if the exception was dispatched and cannot be executed in raw-mode.
*
* @param pVCpu The cross context virtual CPU structure of the calling EMT.
* @param pCtxCore The CPU context core.
* @param enmXcpt The exception.
*/
VMMDECL(int) TRPMRaiseXcpt(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, X86XCPT enmXcpt)
{
LogFlow(("TRPMRaiseXcptErr: cs:eip=%RTsel:%RX32 enmXcpt=%#x\n", pCtxCore->cs.Sel, pCtxCore->eip, enmXcpt));
NOREF(pCtxCore);
/** @todo dispatch the trap. */
pVCpu->trpm.s.uActiveVector = enmXcpt;
pVCpu->trpm.s.enmActiveType = TRPM_TRAP;
pVCpu->trpm.s.uActiveErrorCode = 0xdeadbeef;
pVCpu->trpm.s.uActiveCR2 = 0xdeadface;
pVCpu->trpm.s.cbInstr = UINT8_MAX;
return VINF_EM_RAW_GUEST_TRAP;
}
/**
* Raises a cpu exception with an errorcode.
*
* This function may or may not dispatch the exception before returning.
*
* @returns VBox status code fit for scheduling.
* @retval VINF_EM_RAW_GUEST_TRAP if the exception was left pending.
* @retval VINF_TRPM_XCPT_DISPATCHED if the exception was raised and dispatched for raw-mode execution.
* @retval VINF_EM_RESCHEDULE_REM if the exception was dispatched and cannot be executed in raw-mode.
*
* @param pVCpu The cross context virtual CPU structure of the calling EMT.
* @param pCtxCore The CPU context core.
* @param enmXcpt The exception.
* @param uErr The error code.
*/
VMMDECL(int) TRPMRaiseXcptErr(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, X86XCPT enmXcpt, uint32_t uErr)
{
LogFlow(("TRPMRaiseXcptErr: cs:eip=%RTsel:%RX32 enmXcpt=%#x uErr=%RX32\n", pCtxCore->cs.Sel, pCtxCore->eip, enmXcpt, uErr));
NOREF(pCtxCore);
/** @todo dispatch the trap. */
pVCpu->trpm.s.uActiveVector = enmXcpt;
pVCpu->trpm.s.enmActiveType = TRPM_TRAP;
pVCpu->trpm.s.uActiveErrorCode = uErr;
pVCpu->trpm.s.uActiveCR2 = 0xdeadface;
pVCpu->trpm.s.cbInstr = UINT8_MAX;
return VINF_EM_RAW_GUEST_TRAP;
}
/**
* Raises a cpu exception with an errorcode and CR2.
*
* This function may or may not dispatch the exception before returning.
*
* @returns VBox status code fit for scheduling.
* @retval VINF_EM_RAW_GUEST_TRAP if the exception was left pending.
* @retval VINF_TRPM_XCPT_DISPATCHED if the exception was raised and dispatched for raw-mode execution.
* @retval VINF_EM_RESCHEDULE_REM if the exception was dispatched and cannot be executed in raw-mode.
*
* @param pVCpu The cross context virtual CPU structure of the calling EMT.
* @param pCtxCore The CPU context core.
* @param enmXcpt The exception.
* @param uErr The error code.
* @param uCR2 The CR2 value.
*/
VMMDECL(int) TRPMRaiseXcptErrCR2(PVMCPU pVCpu, PCPUMCTXCORE pCtxCore, X86XCPT enmXcpt, uint32_t uErr, RTGCUINTPTR uCR2)
{
LogFlow(("TRPMRaiseXcptErr: cs:eip=%RTsel:%RX32 enmXcpt=%#x uErr=%RX32 uCR2=%RGv\n", pCtxCore->cs.Sel, pCtxCore->eip, enmXcpt, uErr, uCR2));
NOREF(pCtxCore);
/** @todo dispatch the trap. */
pVCpu->trpm.s.uActiveVector = enmXcpt;
pVCpu->trpm.s.enmActiveType = TRPM_TRAP;
pVCpu->trpm.s.uActiveErrorCode = uErr;
pVCpu->trpm.s.uActiveCR2 = uCR2;
pVCpu->trpm.s.cbInstr = UINT8_MAX;
return VINF_EM_RAW_GUEST_TRAP;
}
#ifdef VBOX_WITH_RAW_MODE
/**
* Clear guest trap/interrupt gate handler
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
* @param iTrap Interrupt/trap number.
*/
VMMDECL(int) trpmClearGuestTrapHandler(PVM pVM, unsigned iTrap)
{
AssertReturn(VM_IS_RAW_MODE_ENABLED(pVM), VERR_TRPM_HM_IPE);
AssertMsgReturn(iTrap < RT_ELEMENTS(pVM->trpm.s.aIdt), ("Illegal gate number %d!\n", iTrap), VERR_INVALID_PARAMETER);
if (ASMBitTest(&pVM->trpm.s.au32IdtPatched[0], iTrap))
# ifdef IN_RING3
trpmR3ClearPassThroughHandler(pVM, iTrap);
# else
AssertFailed();
# endif
pVM->trpm.s.aGuestTrapHandler[iTrap] = TRPM_INVALID_HANDLER;
return VINF_SUCCESS;
}
#endif /* VBOX_WITH_RAW_MODE */
|