Changeset 78278 in vbox for trunk/src/VBox/Runtime/r0drv/nt/memobj-r0drv-nt.cpp
- Timestamp:
- Apr 24, 2019 4:03:59 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/memobj-r0drv-nt.cpp
r78120 r78278 70 70 /** Used MmAllocatePagesForMdl(). */ 71 71 bool fAllocatedPagesForMdl; 72 /** Set if this is sub-section of the parent. */ 73 bool fSubMapping; 72 74 /** Pointer returned by MmSecureVirtualMemory */ 73 75 PVOID pvSecureMem; … … 184 186 case RTR0MEMOBJTYPE_MAPPING: 185 187 { 186 Assert(pMemNt->cMdls == 0 && pMemNt->Core.pv);187 188 PRTR0MEMOBJNT pMemNtParent = (PRTR0MEMOBJNT)pMemNt->Core.uRel.Child.pParent; 188 189 Assert(pMemNtParent); 190 Assert(pMemNt->Core.pv); 191 Assert((pMemNt->cMdls == 0 && !pMemNt->fSubMapping) || (pMemNt->cMdls == 1 && pMemNt->fSubMapping)); 189 192 if (pMemNtParent->cMdls) 190 193 { … … 192 195 Assert( pMemNt->Core.u.Mapping.R0Process == NIL_RTR0PROCESS 193 196 || pMemNt->Core.u.Mapping.R0Process == RTR0ProcHandleSelf()); 194 MmUnmapLockedPages(pMemNt->Core.pv, pMemNtParent->apMdls[0]); 197 if (!pMemNt->cMdls) 198 MmUnmapLockedPages(pMemNt->Core.pv, pMemNtParent->apMdls[0]); 199 else 200 { 201 MmUnmapLockedPages(pMemNt->Core.pv, pMemNt->apMdls[0]); 202 IoFreeMdl(pMemNt->apMdls[0]); 203 pMemNt->apMdls[0] = NULL; 204 } 195 205 } 196 206 else … … 199 209 && !pMemNtParent->Core.u.Phys.fAllocated); 200 210 Assert(pMemNt->Core.u.Mapping.R0Process == NIL_RTR0PROCESS); 211 Assert(!pMemNt->fSubMapping); 201 212 MmUnmapIoSpace(pMemNt->Core.pv, pMemNt->Core.cb); 202 213 } … … 701 712 */ 702 713 static int rtR0MemObjNtMap(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment, 703 unsigned fProt, RTR0PROCESS R0Process )714 unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub) 704 715 { 705 716 int rc = VERR_MAP_FAILED; … … 747 758 } 748 759 760 /* Create a partial MDL if this is a sub-range request. */ 761 PMDL pMdl; 762 if (!offSub && !cbSub) 763 pMdl = pMemNtToMap->apMdls[0]; 764 else 765 { 766 pMdl = IoAllocateMdl(NULL, (ULONG)cbSub, FALSE, FALSE, NULL); 767 if (pMdl) 768 IoBuildPartialMdl(pMemNtToMap->apMdls[0], pMdl, 769 (uint8_t *)MmGetMdlVirtualAddress(pMemNtToMap->apMdls[0]) + offSub, (ULONG)cbSub); 770 else 771 { 772 IoFreeMdl(pMdl); 773 return VERR_NO_MEMORY; 774 } 775 } 776 749 777 __try 750 778 { … … 753 781 void *pv; 754 782 if (g_pfnrtMmMapLockedPagesSpecifyCache) 755 pv = g_pfnrtMmMapLockedPagesSpecifyCache(pM emNtToMap->apMdls[0],783 pv = g_pfnrtMmMapLockedPagesSpecifyCache(pMdl, 756 784 R0Process == NIL_RTR0PROCESS ? KernelMode : UserMode, 757 785 MmCached, … … 760 788 NormalPagePriority); 761 789 else 762 pv = MmMapLockedPages(pMemNtToMap->apMdls[0], 763 R0Process == NIL_RTR0PROCESS ? KernelMode : UserMode); 790 pv = MmMapLockedPages(pMdl, R0Process == NIL_RTR0PROCESS ? KernelMode : UserMode); 764 791 if (pv) 765 792 { 766 793 NOREF(fProt); 767 794 768 PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_MAPPING, pv, 769 pMemNtToMap->Core.cb); 795 PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew( !offSub && !cbSub 796 ? sizeof(*pMemNt) : RT_UOFFSETOF_DYN(RTR0MEMOBJNT, apMdls[1]), 797 RTR0MEMOBJTYPE_MAPPING, pv, pMemNtToMap->Core.cb); 770 798 if (pMemNt) 771 799 { 772 800 pMemNt->Core.u.Mapping.R0Process = R0Process; 801 if (!offSub && !cbSub) 802 pMemNt->fSubMapping = false; 803 else 804 { 805 pMemNt->apMdls[0] = pMdl; 806 pMemNt->cMdls = 1; 807 pMemNt->fSubMapping = true; 808 } 809 773 810 *ppMem = &pMemNt->Core; 774 811 return VINF_SUCCESS; … … 776 813 777 814 rc = VERR_NO_MEMORY; 778 MmUnmapLockedPages(pv, pM emNtToMap->apMdls[0]);815 MmUnmapLockedPages(pv, pMdl); 779 816 } 780 817 } … … 799 836 if (R0Process != NIL_RTR0PROCESS) 800 837 return VERR_NOT_SUPPORTED; 838 839 /* Cannot sub-mak these (yet). */ 840 AssertMsgReturn(!offSub && !cbSub, ("%#zx %#zx\n", offSub, cbSub), VERR_NOT_SUPPORTED); 841 801 842 802 843 /** @todo uAlignment */ … … 830 871 unsigned fProt, size_t offSub, size_t cbSub) 831 872 { 832 AssertMsgReturn(!offSub && !cbSub, ("%#x %#x\n", offSub, cbSub), VERR_NOT_SUPPORTED); 833 return rtR0MemObjNtMap(ppMem, pMemToMap, pvFixed, uAlignment, fProt, NIL_RTR0PROCESS); 873 return rtR0MemObjNtMap(ppMem, pMemToMap, pvFixed, uAlignment, fProt, NIL_RTR0PROCESS, offSub, cbSub); 834 874 } 835 875 … … 839 879 { 840 880 AssertReturn(R0Process == RTR0ProcHandleSelf(), VERR_NOT_SUPPORTED); 841 AssertMsgReturn(!offSub && !cbSub, ("%#zx %#zx\n", offSub, cbSub), VERR_NOT_SUPPORTED); /** @todo implement sub maps */ 842 return rtR0MemObjNtMap(ppMem, pMemToMap, (void *)R3PtrFixed, uAlignment, fProt, R0Process); 881 return rtR0MemObjNtMap(ppMem, pMemToMap, (void *)R3PtrFixed, uAlignment, fProt, R0Process, offSub, cbSub); 843 882 } 844 883
Note:
See TracChangeset
for help on using the changeset viewer.