~siretart/ubuntu/raring/virtualbox-ose/bug.1101867

« back to all changes in this revision

Viewing changes to src/VBox/VMM/VMMAll/PGMAllShw.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: PGMAllShw.h $ */
 
1
/* $Id: PGMAllShw.h 32036 2010-08-27 10:14:39Z vboxsync $ */
2
2
/** @file
3
3
 * VBox - Page Manager, Shadow Paging Template - All context code.
4
4
 */
30
30
#undef SHW_PD_SHIFT
31
31
#undef SHW_PD_MASK
32
32
#undef SHW_PTE_PG_MASK
 
33
#undef SHW_PTE_IS_P
 
34
#undef SHW_PTE_IS_RW
 
35
#undef SHW_PTE_IS_US
 
36
#undef SHW_PTE_IS_A
 
37
#undef SHW_PTE_IS_D
 
38
#undef SHW_PTE_IS_P_RW
 
39
#undef SHW_PTE_IS_TRACK_DIRTY
 
40
#undef SHW_PTE_GET_HCPHYS
 
41
#undef SHW_PTE_GET_U
 
42
#undef SHW_PTE_LOG64
 
43
#undef SHW_PTE_SET
 
44
#undef SHW_PTE_ATOMIC_SET
 
45
#undef SHW_PTE_ATOMIC_SET2
 
46
#undef SHW_PTE_SET_RO
 
47
#undef SHW_PTE_SET_RW
33
48
#undef SHW_PT_SHIFT
34
49
#undef SHW_PT_MASK
35
50
#undef SHW_TOTAL_PD_ENTRIES
39
54
#undef SHW_POOL_ROOT_IDX
40
55
 
41
56
#if PGM_SHW_TYPE == PGM_TYPE_32BIT
42
 
# define SHWPT                  X86PT
43
 
# define PSHWPT                 PX86PT
44
 
# define SHWPTE                 X86PTE
45
 
# define PSHWPTE                PX86PTE
46
 
# define SHWPD                  X86PD
47
 
# define PSHWPD                 PX86PD
48
 
# define SHWPDE                 X86PDE
49
 
# define PSHWPDE                PX86PDE
50
 
# define SHW_PDE_PG_MASK        X86_PDE_PG_MASK
51
 
# define SHW_PD_SHIFT           X86_PD_SHIFT
52
 
# define SHW_PD_MASK            X86_PD_MASK
53
 
# define SHW_TOTAL_PD_ENTRIES   X86_PG_ENTRIES
54
 
# define SHW_PTE_PG_MASK        X86_PTE_PG_MASK
55
 
# define SHW_PT_SHIFT           X86_PT_SHIFT
56
 
# define SHW_PT_MASK            X86_PT_MASK
57
 
# define SHW_POOL_ROOT_IDX      PGMPOOL_IDX_PD
 
57
# define SHWPT                          X86PT
 
58
# define PSHWPT                         PX86PT
 
59
# define SHWPTE                         X86PTE
 
60
# define PSHWPTE                        PX86PTE
 
61
# define SHWPD                          X86PD
 
62
# define PSHWPD                         PX86PD
 
63
# define SHWPDE                         X86PDE
 
64
# define PSHWPDE                        PX86PDE
 
65
# define SHW_PDE_PG_MASK                X86_PDE_PG_MASK
 
66
# define SHW_PD_SHIFT                   X86_PD_SHIFT
 
67
# define SHW_PD_MASK                    X86_PD_MASK
 
68
# define SHW_TOTAL_PD_ENTRIES           X86_PG_ENTRIES
 
69
# define SHW_PTE_PG_MASK                X86_PTE_PG_MASK
 
70
# define SHW_PTE_IS_P(Pte)              ( (Pte).n.u1Present )
 
71
# define SHW_PTE_IS_RW(Pte)             ( (Pte).n.u1Write )
 
72
# define SHW_PTE_IS_US(Pte)             ( (Pte).n.u1User )
 
73
# define SHW_PTE_IS_A(Pte)              ( (Pte).n.u1Accessed )
 
74
# define SHW_PTE_IS_D(Pte)              ( (Pte).n.u1Dirty )
 
75
# define SHW_PTE_IS_P_RW(Pte)           ( (Pte).n.u1Present && (Pte).n.u1Write )
 
76
# define SHW_PTE_IS_TRACK_DIRTY(Pte)    ( !!((Pte).u & PGM_PTFLAGS_TRACK_DIRTY) )
 
77
# define SHW_PTE_GET_HCPHYS(Pte)        ( (Pte).u & X86_PTE_PG_MASK )
 
78
# define SHW_PTE_LOG64(Pte)             ( (uint64_t)(Pte).u )
 
79
# define SHW_PTE_GET_U(Pte)             ( (Pte).u )             /**< Use with care. */
 
80
# define SHW_PTE_SET(Pte, uNew)         do { (Pte).u = (uNew); } while (0)
 
81
# define SHW_PTE_ATOMIC_SET(Pte, uNew)  do { ASMAtomicWriteU32(&(Pte).u, (uNew)); } while (0)
 
82
# define SHW_PTE_ATOMIC_SET2(Pte, Pte2) do { ASMAtomicWriteU32(&(Pte).u, (Pte2).u); } while (0)
 
83
# define SHW_PTE_SET_RO(Pte)            do { (Pte).n.u1Write = 0; } while (0)
 
84
# define SHW_PTE_SET_RW(Pte)            do { (Pte).n.u1Write = 1; } while (0)
 
85
# define SHW_PT_SHIFT                   X86_PT_SHIFT
 
86
# define SHW_PT_MASK                    X86_PT_MASK
 
87
# define SHW_POOL_ROOT_IDX              PGMPOOL_IDX_PD
58
88
 
59
89
#elif PGM_SHW_TYPE == PGM_TYPE_EPT
60
 
# define SHWPT                  EPTPT
61
 
# define PSHWPT                 PEPTPT
62
 
# define SHWPTE                 EPTPTE
63
 
# define PSHWPTE                PEPTPTE
64
 
# define SHWPD                  EPTPD
65
 
# define PSHWPD                 PEPTPD
66
 
# define SHWPDE                 EPTPDE
67
 
# define PSHWPDE                PEPTPDE
68
 
# define SHW_PDE_PG_MASK        EPT_PDE_PG_MASK
69
 
# define SHW_PD_SHIFT           EPT_PD_SHIFT
70
 
# define SHW_PD_MASK            EPT_PD_MASK
71
 
# define SHW_PTE_PG_MASK        EPT_PTE_PG_MASK
72
 
# define SHW_PT_SHIFT           EPT_PT_SHIFT
73
 
# define SHW_PT_MASK            EPT_PT_MASK
74
 
# define SHW_PDPT_SHIFT         EPT_PDPT_SHIFT
75
 
# define SHW_PDPT_MASK          EPT_PDPT_MASK
76
 
# define SHW_PDPE_PG_MASK       EPT_PDPE_PG_MASK
77
 
# define SHW_TOTAL_PD_ENTRIES   (EPT_PG_AMD64_ENTRIES*EPT_PG_AMD64_PDPE_ENTRIES)
78
 
# define SHW_POOL_ROOT_IDX      PGMPOOL_IDX_NESTED_ROOT      /* do not use! exception is real mode & protected mode without paging. */
 
90
# define SHWPT                          EPTPT
 
91
# define PSHWPT                         PEPTPT
 
92
# define SHWPTE                         EPTPTE
 
93
# define PSHWPTE                        PEPTPTE
 
94
# define SHWPD                          EPTPD
 
95
# define PSHWPD                         PEPTPD
 
96
# define SHWPDE                         EPTPDE
 
97
# define PSHWPDE                        PEPTPDE
 
98
# define SHW_PDE_PG_MASK                EPT_PDE_PG_MASK
 
99
# define SHW_PD_SHIFT                   EPT_PD_SHIFT
 
100
# define SHW_PD_MASK                    EPT_PD_MASK
 
101
# define SHW_PTE_PG_MASK                EPT_PTE_PG_MASK
 
102
# define SHW_PTE_IS_P(Pte)              ( (Pte).n.u1Present )  /* Approximation, works for us. */
 
103
# define SHW_PTE_IS_RW(Pte)             ( (Pte).n.u1Write )
 
104
# define SHW_PTE_IS_US(Pte)             ( true )
 
105
# define SHW_PTE_IS_A(Pte)              ( true )
 
106
# define SHW_PTE_IS_D(Pte)              ( true )
 
107
# define SHW_PTE_IS_P_RW(Pte)           ( (Pte).n.u1Present && (Pte).n.u1Write )
 
108
# define SHW_PTE_IS_TRACK_DIRTY(Pte)    ( false )
 
109
# define SHW_PTE_GET_HCPHYS(Pte)        ( (Pte).u & X86_PTE_PG_MASK )
 
110
# define SHW_PTE_LOG64(Pte)             ( (Pte).u )
 
111
# define SHW_PTE_GET_U(Pte)             ( (Pte).u )             /**< Use with care. */
 
112
# define SHW_PTE_SET(Pte, uNew)         do { (Pte).u = (uNew); } while (0)
 
113
# define SHW_PTE_ATOMIC_SET(Pte, uNew)  do { ASMAtomicWriteU64(&(Pte).u, (uNew)); } while (0)
 
114
# define SHW_PTE_ATOMIC_SET2(Pte, Pte2) do { ASMAtomicWriteU64(&(Pte).u, (Pte2).u); } while (0)
 
115
# define SHW_PTE_SET_RO(Pte)            do { (Pte).n.u1Write = 0; } while (0)
 
116
# define SHW_PTE_SET_RW(Pte)            do { (Pte).n.u1Write = 1; } while (0)
 
117
# define SHW_PT_SHIFT                   EPT_PT_SHIFT
 
118
# define SHW_PT_MASK                    EPT_PT_MASK
 
119
# define SHW_PDPT_SHIFT                 EPT_PDPT_SHIFT
 
120
# define SHW_PDPT_MASK                  EPT_PDPT_MASK
 
121
# define SHW_PDPE_PG_MASK               EPT_PDPE_PG_MASK
 
122
# define SHW_TOTAL_PD_ENTRIES           (EPT_PG_AMD64_ENTRIES*EPT_PG_AMD64_PDPE_ENTRIES)
 
123
# define SHW_POOL_ROOT_IDX              PGMPOOL_IDX_NESTED_ROOT      /* do not use! exception is real mode & protected mode without paging. */
79
124
 
80
125
#else
81
 
# define SHWPT                  X86PTPAE
82
 
# define PSHWPT                 PX86PTPAE
83
 
# define SHWPTE                 X86PTEPAE
84
 
# define PSHWPTE                PX86PTEPAE
85
 
# define SHWPD                  X86PDPAE
86
 
# define PSHWPD                 PX86PDPAE
87
 
# define SHWPDE                 X86PDEPAE
88
 
# define PSHWPDE                PX86PDEPAE
89
 
# define SHW_PDE_PG_MASK        X86_PDE_PAE_PG_MASK
90
 
# define SHW_PD_SHIFT           X86_PD_PAE_SHIFT
91
 
# define SHW_PD_MASK            X86_PD_PAE_MASK
92
 
# define SHW_PTE_PG_MASK        X86_PTE_PAE_PG_MASK
93
 
# define SHW_PT_SHIFT           X86_PT_PAE_SHIFT
94
 
# define SHW_PT_MASK            X86_PT_PAE_MASK
 
126
# define SHWPT                          PGMSHWPTPAE
 
127
# define PSHWPT                         PPGMSHWPTPAE
 
128
# define SHWPTE                         PGMSHWPTEPAE
 
129
# define PSHWPTE                        PPGMSHWPTEPAE
 
130
# define SHWPD                          X86PDPAE
 
131
# define PSHWPD                         PX86PDPAE
 
132
# define SHWPDE                         X86PDEPAE
 
133
# define PSHWPDE                        PX86PDEPAE
 
134
# define SHW_PDE_PG_MASK                X86_PDE_PAE_PG_MASK
 
135
# define SHW_PD_SHIFT                   X86_PD_PAE_SHIFT
 
136
# define SHW_PD_MASK                    X86_PD_PAE_MASK
 
137
# define SHW_PTE_PG_MASK                X86_PTE_PAE_PG_MASK
 
138
# define SHW_PTE_IS_P(Pte)              PGMSHWPTEPAE_IS_P(Pte)
 
139
# define SHW_PTE_IS_RW(Pte)             PGMSHWPTEPAE_IS_RW(Pte)
 
140
# define SHW_PTE_IS_US(Pte)             PGMSHWPTEPAE_IS_US(Pte)
 
141
# define SHW_PTE_IS_A(Pte)              PGMSHWPTEPAE_IS_A(Pte)
 
142
# define SHW_PTE_IS_D(Pte)              PGMSHWPTEPAE_IS_D(Pte)
 
143
# define SHW_PTE_IS_P_RW(Pte)           PGMSHWPTEPAE_IS_P_RW(Pte)
 
144
# define SHW_PTE_IS_TRACK_DIRTY(Pte)    PGMSHWPTEPAE_IS_TRACK_DIRTY(Pte)
 
145
# define SHW_PTE_GET_HCPHYS(Pte)        PGMSHWPTEPAE_GET_HCPHYS(Pte)
 
146
# define SHW_PTE_LOG64(Pte)             PGMSHWPTEPAE_GET_LOG(Pte)
 
147
# define SHW_PTE_GET_U(Pte)             PGMSHWPTEPAE_GET_U(Pte)     /**< Use with care. */
 
148
# define SHW_PTE_SET(Pte, uNew)         PGMSHWPTEPAE_SET(Pte, uNew)
 
149
# define SHW_PTE_ATOMIC_SET(Pte, uNew)  PGMSHWPTEPAE_ATOMIC_SET(Pte, uNew)
 
150
# define SHW_PTE_ATOMIC_SET2(Pte, Pte2) PGMSHWPTEPAE_ATOMIC_SET2(Pte, Pte2)
 
151
# define SHW_PTE_SET_RO(Pte)            PGMSHWPTEPAE_SET_RO(Pte)
 
152
# define SHW_PTE_SET_RW(Pte)            PGMSHWPTEPAE_SET_RW(Pte)
 
153
# define SHW_PT_SHIFT                   X86_PT_PAE_SHIFT
 
154
# define SHW_PT_MASK                    X86_PT_PAE_MASK
95
155
 
96
156
# if PGM_SHW_TYPE == PGM_TYPE_AMD64
97
 
#  define SHW_PDPT_SHIFT        X86_PDPT_SHIFT
98
 
#  define SHW_PDPT_MASK         X86_PDPT_MASK_AMD64
99
 
#  define SHW_PDPE_PG_MASK      X86_PDPE_PG_MASK
100
 
#  define SHW_TOTAL_PD_ENTRIES  (X86_PG_AMD64_ENTRIES*X86_PG_AMD64_PDPE_ENTRIES)
101
 
#  define SHW_POOL_ROOT_IDX     PGMPOOL_IDX_AMD64_CR3
 
157
#  define SHW_PDPT_SHIFT                X86_PDPT_SHIFT
 
158
#  define SHW_PDPT_MASK                 X86_PDPT_MASK_AMD64
 
159
#  define SHW_PDPE_PG_MASK              X86_PDPE_PG_MASK
 
160
#  define SHW_TOTAL_PD_ENTRIES          (X86_PG_AMD64_ENTRIES * X86_PG_AMD64_PDPE_ENTRIES)
 
161
#  define SHW_POOL_ROOT_IDX             PGMPOOL_IDX_AMD64_CR3
102
162
 
103
163
# else /* 32 bits PAE mode */
104
 
#  define SHW_PDPT_SHIFT        X86_PDPT_SHIFT
105
 
#  define SHW_PDPT_MASK         X86_PDPT_MASK_PAE
106
 
#  define SHW_PDPE_PG_MASK      X86_PDPE_PG_MASK
107
 
#  define SHW_TOTAL_PD_ENTRIES  (X86_PG_PAE_ENTRIES*X86_PG_PAE_PDPE_ENTRIES)
108
 
#  define SHW_POOL_ROOT_IDX     PGMPOOL_IDX_PDPT
 
164
#  define SHW_PDPT_SHIFT                X86_PDPT_SHIFT
 
165
#  define SHW_PDPT_MASK                 X86_PDPT_MASK_PAE
 
166
#  define SHW_PDPE_PG_MASK              X86_PDPE_PG_MASK
 
167
#  define SHW_TOTAL_PD_ENTRIES          (X86_PG_PAE_ENTRIES * X86_PG_PAE_PDPE_ENTRIES)
 
168
#  define SHW_POOL_ROOT_IDX             PGMPOOL_IDX_PDPT
109
169
 
110
170
# endif
111
171
#endif
150
210
    X86PDEPAE Pde;
151
211
 
152
212
    /* PML4 */
153
 
    X86PML4E        Pml4e = pgmShwGetLongModePML4E(&pVCpu->pgm.s, GCPtr);
 
213
    X86PML4E        Pml4e = pgmShwGetLongModePML4E(pVCpu, GCPtr);
154
214
    if (!Pml4e.n.u1Present)
155
215
        return VERR_PAGE_TABLE_NOT_PRESENT;
156
216
 
157
217
    /* PDPT */
158
218
    PX86PDPT        pPDPT;
159
 
    int rc = PGM_HCPHYS_2_PTR(pVM, Pml4e.u & X86_PML4E_PG_MASK, &pPDPT);
 
219
    int rc = PGM_HCPHYS_2_PTR(pVM, pVCpu, Pml4e.u & X86_PML4E_PG_MASK, &pPDPT);
160
220
    if (RT_FAILURE(rc))
161
221
        return rc;
162
222
    const unsigned  iPDPT = (GCPtr >> SHW_PDPT_SHIFT) & SHW_PDPT_MASK;
166
226
 
167
227
    /* PD */
168
228
    PX86PDPAE       pPd;
169
 
    rc = PGM_HCPHYS_2_PTR(pVM, Pdpe.u & X86_PDPE_PG_MASK, &pPd);
 
229
    rc = PGM_HCPHYS_2_PTR(pVM, pVCpu, Pdpe.u & X86_PDPE_PG_MASK, &pPd);
170
230
    if (RT_FAILURE(rc))
171
231
        return rc;
172
232
    const unsigned  iPd = (GCPtr >> SHW_PD_SHIFT) & SHW_PD_MASK;
179
239
    Pde.n.u1NoExecute |= Pml4e.n.u1NoExecute | Pdpe.lm.u1NoExecute;
180
240
 
181
241
# elif PGM_SHW_TYPE == PGM_TYPE_PAE
182
 
    X86PDEPAE       Pde = pgmShwGetPaePDE(&pVCpu->pgm.s, GCPtr);
 
242
    X86PDEPAE       Pde = pgmShwGetPaePDE(pVCpu, GCPtr);
183
243
 
184
244
# elif PGM_SHW_TYPE == PGM_TYPE_EPT
185
245
    const unsigned  iPd = ((GCPtr >> SHW_PD_SHIFT) & SHW_PD_MASK);
196
256
    Pde = pPDDst->a[iPd];
197
257
 
198
258
# else /* PGM_TYPE_32BIT */
199
 
    X86PDE          Pde = pgmShwGet32BitPDE(&pVCpu->pgm.s, GCPtr);
 
259
    X86PDE          Pde = pgmShwGet32BitPDE(pVCpu, GCPtr);
200
260
# endif
201
261
    if (!Pde.n.u1Present)
202
262
        return VERR_PAGE_TABLE_NOT_PRESENT;
212
272
        if (pfFlags)
213
273
        {
214
274
            *pfFlags = (Pde.u & ~SHW_PDE_PG_MASK);
215
 
# if PGM_WITH_NX(PGM_SHW_TYPE, PGM_SHW_TYPE)
 
275
# if PGM_WITH_NX(PGM_SHW_TYPE, PGM_SHW_TYPE)    /** @todo why do we have to check the guest state here? */
216
276
            if ((Pde.u & X86_PTE_PAE_NX) && CPUMIsGuestNXEnabled(pVCpu))
217
277
                *pfFlags |= X86_PTE_PAE_NX;
218
278
# endif
230
290
    PSHWPT          pPT;
231
291
    if (!(Pde.u & PGM_PDFLAGS_MAPPING))
232
292
    {
233
 
        int rc2 = PGM_HCPHYS_2_PTR(pVM, Pde.u & SHW_PDE_PG_MASK, &pPT);
 
293
        int rc2 = PGM_HCPHYS_2_PTR(pVM, pVCpu, Pde.u & SHW_PDE_PG_MASK, &pPT);
234
294
        if (RT_FAILURE(rc2))
235
295
            return rc2;
236
296
    }
253
313
    }
254
314
    const unsigned  iPt = (GCPtr >> SHW_PT_SHIFT) & SHW_PT_MASK;
255
315
    SHWPTE          Pte = pPT->a[iPt];
256
 
    if (!Pte.n.u1Present)
 
316
    if (!SHW_PTE_IS_P(Pte))
257
317
        return VERR_PAGE_NOT_PRESENT;
258
318
 
259
319
    /*
263
323
     */
264
324
    if (pfFlags)
265
325
    {
266
 
        *pfFlags = (Pte.u & ~SHW_PTE_PG_MASK)
 
326
        *pfFlags = (SHW_PTE_GET_U(Pte) & ~SHW_PTE_PG_MASK)
267
327
                 & ((Pde.u & (X86_PTE_RW | X86_PTE_US)) | ~(uint64_t)(X86_PTE_RW | X86_PTE_US));
268
 
# if PGM_WITH_NX(PGM_SHW_TYPE, PGM_SHW_TYPE)
 
328
# if PGM_WITH_NX(PGM_SHW_TYPE, PGM_SHW_TYPE) /** @todo why do we have to check the guest state here? */
269
329
        /* The NX bit is determined by a bitwise OR between the PT and PD */
270
 
        if (((Pte.u | Pde.u) & X86_PTE_PAE_NX) && CPUMIsGuestNXEnabled(pVCpu))
 
330
        if (((SHW_PTE_GET_U(Pte) | Pde.u) & X86_PTE_PAE_NX) && CPUMIsGuestNXEnabled(pVCpu))
271
331
            *pfFlags |= X86_PTE_PAE_NX;
272
332
# endif
273
333
    }
274
334
 
275
335
    if (pHCPhys)
276
 
        *pHCPhys = Pte.u & SHW_PTE_PG_MASK;
 
336
        *pHCPhys = SHW_PTE_GET_HCPHYS(Pte);
277
337
 
278
338
    return VINF_SUCCESS;
279
339
#endif /* PGM_SHW_TYPE != PGM_TYPE_NESTED */
316
376
# if PGM_SHW_TYPE == PGM_TYPE_AMD64
317
377
        X86PDEPAE       Pde;
318
378
        /* PML4 */
319
 
        X86PML4E        Pml4e = pgmShwGetLongModePML4E(&pVCpu->pgm.s, GCPtr);
 
379
        X86PML4E        Pml4e = pgmShwGetLongModePML4E(pVCpu, GCPtr);
320
380
        if (!Pml4e.n.u1Present)
321
381
            return VERR_PAGE_TABLE_NOT_PRESENT;
322
382
 
323
383
        /* PDPT */
324
384
        PX86PDPT        pPDPT;
325
 
        rc = PGM_HCPHYS_2_PTR(pVM, Pml4e.u & X86_PML4E_PG_MASK, &pPDPT);
 
385
        rc = PGM_HCPHYS_2_PTR(pVM, pVCpu, Pml4e.u & X86_PML4E_PG_MASK, &pPDPT);
326
386
        if (RT_FAILURE(rc))
327
387
            return rc;
328
388
        const unsigned  iPDPT = (GCPtr >> SHW_PDPT_SHIFT) & SHW_PDPT_MASK;
332
392
 
333
393
        /* PD */
334
394
        PX86PDPAE       pPd;
335
 
        rc = PGM_HCPHYS_2_PTR(pVM, Pdpe.u & X86_PDPE_PG_MASK, &pPd);
 
395
        rc = PGM_HCPHYS_2_PTR(pVM, pVCpu, Pdpe.u & X86_PDPE_PG_MASK, &pPd);
336
396
        if (RT_FAILURE(rc))
337
397
            return rc;
338
398
        const unsigned iPd = (GCPtr >> SHW_PD_SHIFT) & SHW_PD_MASK;
339
399
        Pde = pPd->a[iPd];
340
400
 
341
401
# elif PGM_SHW_TYPE == PGM_TYPE_PAE
342
 
        X86PDEPAE       Pde = pgmShwGetPaePDE(&pVCpu->pgm.s, GCPtr);
 
402
        X86PDEPAE       Pde = pgmShwGetPaePDE(pVCpu, GCPtr);
343
403
 
344
404
# elif PGM_SHW_TYPE == PGM_TYPE_EPT
345
405
        const unsigned  iPd = ((GCPtr >> SHW_PD_SHIFT) & SHW_PD_MASK);
356
416
        Pde = pPDDst->a[iPd];
357
417
 
358
418
# else /* PGM_TYPE_32BIT */
359
 
        X86PDE          Pde = pgmShwGet32BitPDE(&pVCpu->pgm.s, GCPtr);
 
419
        X86PDE          Pde = pgmShwGet32BitPDE(pVCpu, GCPtr);
360
420
# endif
361
421
        if (!Pde.n.u1Present)
362
422
            return VERR_PAGE_TABLE_NOT_PRESENT;
367
427
         * Map the page table.
368
428
         */
369
429
        PSHWPT          pPT;
370
 
        rc = PGM_HCPHYS_2_PTR(pVM, Pde.u & SHW_PDE_PG_MASK, &pPT);
 
430
        rc = PGM_HCPHYS_2_PTR(pVM, pVCpu, Pde.u & SHW_PDE_PG_MASK, &pPT);
371
431
        if (RT_FAILURE(rc))
372
432
            return rc;
373
433
 
374
434
        unsigned        iPTE = (GCPtr >> SHW_PT_SHIFT) & SHW_PT_MASK;
375
435
        while (iPTE < RT_ELEMENTS(pPT->a))
376
436
        {
377
 
            if (pPT->a[iPTE].n.u1Present)
 
437
            if (SHW_PTE_IS_P(pPT->a[iPTE]))
378
438
            {
379
439
                SHWPTE const    OrgPte = pPT->a[iPTE];
380
440
                SHWPTE          NewPte;
381
441
 
382
 
                NewPte.u = (OrgPte.u & (fMask | SHW_PTE_PG_MASK)) | (fFlags & ~SHW_PTE_PG_MASK);
383
 
                Assert(NewPte.n.u1Present);
384
 
                if (!NewPte.n.u1Present)
 
442
                SHW_PTE_SET(NewPte, (SHW_PTE_GET_U(OrgPte) & (fMask | SHW_PTE_PG_MASK)) | (fFlags & ~SHW_PTE_PG_MASK));
 
443
                if (!SHW_PTE_IS_P(NewPte))
385
444
                {
386
445
                    /** @todo Some CSAM code path might end up here and upset
387
446
                     *  the page pool. */
388
447
                    AssertFailed();
389
448
                }
390
 
                else if (   NewPte.n.u1Write
391
 
                         && !OrgPte.n.u1Write
 
449
                else if (   SHW_PTE_IS_RW(NewPte)
 
450
                         && !SHW_PTE_IS_RW(OrgPte)
392
451
                         && !(fOpFlags & PGM_MK_PG_IS_MMIO2) )
393
452
                {
394
453
                    /** @todo Optimize \#PF handling by caching data.  We can
413
472
                    }
414
473
                }
415
474
 
416
 
                ASMAtomicWriteSize(&pPT->a[iPTE], NewPte.u);
 
475
                SHW_PTE_ATOMIC_SET2(pPT->a[iPTE], NewPte);
417
476
# if PGM_SHW_TYPE == PGM_TYPE_EPT
418
477
                HWACCMInvalidatePhysPage(pVM, (RTGCPHYS)GCPtr);
419
478
# else