- Timestamp:
- Jun 13, 2009 8:21:48 PM (16 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPDrv.c
r20315 r20528 209 209 DECLASM(int) UNWIND_WRAP(RTR0MemObjMapKernelEx)(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt, size_t offSub, size_t cbSub); 210 210 DECLASM(int) UNWIND_WRAP(RTR0MemObjMapUser)(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process); 211 DECLASM(int) UNWIND_WRAP(RTR0MemObjProtect)(RTR0MEMOBJ hMemObj, size_t offsub, size_t cbSub, uint32_t fProt); 211 212 /*DECLASM(void *) UNWIND_WRAP(RTR0MemObjAddress)(RTR0MEMOBJ MemObj); - not necessary */ 212 213 /*DECLASM(RTR3PTR) UNWIND_WRAP(RTR0MemObjAddressR3)(RTR0MEMOBJ MemObj); - not necessary */ … … 364 365 { "RTR0MemObjMapKernelEx", (void *)UNWIND_WRAP(RTR0MemObjMapKernelEx) }, 365 366 { "RTR0MemObjMapUser", (void *)UNWIND_WRAP(RTR0MemObjMapUser) }, 367 { "RTR0MemObjProtect", (void *)UNWIND_WRAP(RTR0MemObjProtect) }, 366 368 { "RTR0MemObjAddress", (void *)RTR0MemObjAddress }, 367 369 { "RTR0MemObjAddressR3", (void *)RTR0MemObjAddressR3 }, … … 1587 1589 } 1588 1590 1591 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_PAGE_PROTECT): 1592 { 1593 /* validate */ 1594 PSUPPAGEPROTECT pReq = (PSUPPAGEPROTECT)pReqHdr; 1595 REQ_CHECK_SIZES(SUP_IOCTL_PAGE_PROTECT); 1596 REQ_CHECK_EXPR_FMT(!(pReq->u.In.fProt & ~(RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC | RTMEM_PROT_NONE)), 1597 ("SUP_IOCTL_PAGE_PROTECT: fProt=%#x!\n", pReq->u.In.fProt)); 1598 REQ_CHECK_EXPR_FMT(!(pReq->u.In.offSub & PAGE_OFFSET_MASK), ("SUP_IOCTL_PAGE_PROTECT: offSub=%#x\n", pReq->u.In.offSub)); 1599 REQ_CHECK_EXPR_FMT(pReq->u.In.cbSub && !(pReq->u.In.cbSub & PAGE_OFFSET_MASK), 1600 ("SUP_IOCTL_PAGE_PROTECT: cbSub=%#x\n", pReq->u.In.cbSub)); 1601 1602 /* execute */ 1603 pReq->Hdr.rc = SUPR0PageProtect(pSession, pReq->u.In.pvR3, pReq->u.In.pvR0, pReq->u.In.offSub, pReq->u.In.cbSub, pReq->u.In.fProt); 1604 return 0; 1605 } 1606 1589 1607 case SUP_CTL_CODE_NO_SIZE(SUP_IOCTL_PAGE_FREE): 1590 1608 { … … 2794 2812 2795 2813 /** 2796 * Allocates a chunk of memory with a kernel or/and a user mode mapping. 2797 * 2798 * The memory is fixed and it's possible to query the physical addresses using 2799 * SUPR0MemGetPhys(). 2814 * Maps a chunk of memory previously allocated by SUPR0PageAllocEx into kernel 2815 * space. 2800 2816 * 2801 2817 * @returns IPRT status code. 2802 2818 * @param pSession The session to associated the allocation with. 2803 * @param cPages The number of pages to allocate. 2804 * @param fFlags Flags, reserved for the future. Must be zero. 2805 * @param ppvR3 Where to store the address of the Ring-3 mapping. 2806 * NULL if no ring-3 mapping. 2807 * @param ppvR3 Where to store the address of the Ring-0 mapping. 2808 * NULL if no ring-0 mapping. 2809 * @param paPages Where to store the addresses of the pages. Optional. 2819 * @param pvR3 The ring-3 address returned by SUPR0PageAllocEx. 2820 * @param offSub Where to start mapping. Must be page aligned. 2821 * @param cbSub How much to map. Must be page aligned. 2822 * @param fFlags Flags, MBZ. 2823 * @param ppvR0 Where to reutrn the address of the ring-0 mapping on 2824 * success. 2810 2825 */ 2811 2826 SUPR0DECL(int) SUPR0PageMapKernel(PSUPDRVSESSION pSession, RTR3PTR pvR3, uint32_t offSub, uint32_t cbSub, … … 2879 2894 } 2880 2895 return rc; 2896 } 2897 2898 2899 /** 2900 * Changes the page level protection of one or more pages previously allocated 2901 * by SUPR0PageAllocEx. 2902 * 2903 * @returns IPRT status code. 2904 * @param pSession The session to associated the allocation with. 2905 * @param pvR3 The ring-3 address returned by SUPR0PageAllocEx. 2906 * NIL_RTR3PTR if the ring-3 mapping should be unaffected. 2907 * @param pvR0 The ring-0 address returned by SUPR0PageAllocEx. 2908 * NIL_RTR0PTR if the ring-0 mapping should be unaffected. 2909 * @param offSub Where to start changing. Must be page aligned. 2910 * @param cbSub How much to change. Must be page aligned. 2911 * @param fProt The new page level protection, see RTMEM_PROT_*. 2912 */ 2913 SUPR0DECL(int) SUPR0PageProtect(PSUPDRVSESSION pSession, RTR3PTR pvR3, RTR0PTR pvR0, uint32_t offSub, uint32_t cbSub, uint32_t fProt) 2914 { 2915 int rc; 2916 PSUPDRVBUNDLE pBundle; 2917 RTSPINLOCKTMP SpinlockTmp = RTSPINLOCKTMP_INITIALIZER; 2918 RTR0MEMOBJ hMemObjR0 = NIL_RTR0MEMOBJ; 2919 RTR0MEMOBJ hMemObjR3 = NIL_RTR0MEMOBJ; 2920 LogFlow(("SUPR0PageProtect: pSession=%p pvR3=%p pvR0=%p offSub=%#x cbSub=%#x fProt-%#x\n", pSession, pvR3, pvR0, offSub, cbSub, fProt)); 2921 2922 /* 2923 * Validate input. The allowed allocation size must be at least equal to the maximum guest VRAM size. 2924 */ 2925 AssertReturn(SUP_IS_SESSION_VALID(pSession), VERR_INVALID_PARAMETER); 2926 AssertReturn(!(fProt & ~(RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC | RTMEM_PROT_NONE)), VERR_INVALID_PARAMETER); 2927 AssertReturn(!(offSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER); 2928 AssertReturn(!(cbSub & PAGE_OFFSET_MASK), VERR_INVALID_PARAMETER); 2929 AssertReturn(cbSub, VERR_INVALID_PARAMETER); 2930 2931 /* 2932 * Find the memory object. 2933 */ 2934 RTSpinlockAcquire(pSession->Spinlock, &SpinlockTmp); 2935 for (pBundle = &pSession->Bundle; pBundle; pBundle = pBundle->pNext) 2936 { 2937 if (pBundle->cUsed > 0) 2938 { 2939 unsigned i; 2940 for (i = 0; i < RT_ELEMENTS(pBundle->aMem); i++) 2941 { 2942 if ( pBundle->aMem[i].eType == MEMREF_TYPE_PAGE 2943 && pBundle->aMem[i].MemObj != NIL_RTR0MEMOBJ 2944 && ( pBundle->aMem[i].MapObjR3 != NIL_RTR0MEMOBJ 2945 || pvR3 == NIL_RTR3PTR) 2946 && ( pvR0 != NIL_RTR0PTR 2947 || RTR0MemObjAddress(pBundle->aMem[i].MemObj)) 2948 && ( pvR3 != NIL_RTR3PTR 2949 || RTR0MemObjAddressR3(pBundle->aMem[i].MapObjR3) == pvR3)) 2950 { 2951 if (pvR0 != NIL_RTR0PTR) 2952 hMemObjR0 = pBundle->aMem[i].MemObj; 2953 if (pvR3 != NIL_RTR3PTR) 2954 hMemObjR3 = pBundle->aMem[i].MapObjR3; 2955 break; 2956 } 2957 } 2958 } 2959 } 2960 RTSpinlockRelease(pSession->Spinlock, &SpinlockTmp); 2961 2962 rc = VERR_INVALID_PARAMETER; 2963 if ( hMemObjR0 != NIL_RTR0MEMOBJ 2964 || hMemObjR3 != NIL_RTR0MEMOBJ) 2965 { 2966 /* 2967 * Do some furter input validations before calling IPRT. 2968 */ 2969 size_t cbMemObj = hMemObjR0 != NIL_RTR0PTR ? RTR0MemObjSize(hMemObjR0) : RTR0MemObjSize(hMemObjR3); 2970 if ( offSub < cbMemObj 2971 && cbSub <= cbMemObj 2972 && offSub + cbSub <= cbMemObj) 2973 { 2974 rc = VINF_SUCCESS; 2975 if (hMemObjR3 != NIL_RTR0PTR) 2976 rc = RTR0MemObjProtect(hMemObjR3, offSub, cbSub, fProt); 2977 if (hMemObjR0 != NIL_RTR0PTR && RT_SUCCESS(rc)) 2978 rc = RTR0MemObjProtect(hMemObjR0, offSub, cbSub, fProt); 2979 } 2980 else 2981 SUPR0Printf("SUPR0PageMapKernel: cbMemObj=%#x offSub=%#x cbSub=%#x\n", cbMemObj, offSub, cbSub); 2982 2983 } 2984 return rc; 2985 2881 2986 } 2882 2987 -
trunk/src/VBox/HostDrivers/Support/SUPDrvIOC.h
r20504 r20528 196 196 * and renaming the related IOCtls too. 197 197 */ 198 #define SUPDRV_IOC_VERSION 0x000d000 0198 #define SUPDRV_IOC_VERSION 0x000d0001 199 199 200 200 /** SUP_IOCTL_COOKIE. */ … … 1113 1113 1114 1114 1115 /** @name SUP_IOCTL_PAGE_PROTECT 1116 * Changes the page level protection of the user and/or kernel mappings of 1117 * memory previously allocated by SUPR0PageAllocEx. 1118 * 1119 * @remarks Not necessarily supported on all platforms. 1120 * 1121 * @{ 1122 */ 1123 #define SUP_IOCTL_PAGE_PROTECT SUP_CTL_CODE_SIZE(28, SUP_IOCTL_PAGE_PROTECT_SIZE) 1124 #define SUP_IOCTL_PAGE_PROTECT_SIZE sizeof(SUPPAGEPROTECT) 1125 #define SUP_IOCTL_PAGE_PROTECT_SIZE_IN sizeof(SUPPAGEPROTECT) 1126 #define SUP_IOCTL_PAGE_PROTECT_SIZE_OUT sizeof(SUPPAGEPROTECT) 1127 typedef struct SUPPAGEPROTECT 1128 { 1129 /** The header. */ 1130 SUPREQHDR Hdr; 1131 union 1132 { 1133 struct 1134 { 1135 /** The pointer of to the previously allocated memory. 1136 * Pass NIL_RTR3PTR if the ring-0 mapping should remain unaffected. */ 1137 RTR3PTR pvR3; 1138 /** The pointer of to the previously allocated memory. 1139 * Pass NIL_RTR0PTR if the ring-0 mapping should remain unaffected. */ 1140 RTR0PTR pvR0; 1141 /** The offset to start changing protection at. */ 1142 uint32_t offSub; 1143 /** Size of the portion that should be changed. */ 1144 uint32_t cbSub; 1145 /** Protection flags, RTMEM_PROT_*. */ 1146 uint32_t fProt; 1147 } In; 1148 } u; 1149 } SUPPAGEPROTECT, *PSUPPAGEPROTECT; 1150 /** @} */ 1151 1152 1115 1153 #pragma pack() /* paranoia */ 1116 1154 -
trunk/src/VBox/HostDrivers/Support/SUPLib.cpp
r20339 r20528 260 260 strcpy(CookieReq.u.In.szMagic, SUPCOOKIE_MAGIC); 261 261 CookieReq.u.In.u32ReqVersion = SUPDRV_IOC_VERSION; 262 const uint32_t MinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) >= 0x000d0000263 ? 0x000d0000262 const uint32_t MinVersion = (SUPDRV_IOC_VERSION & 0xffff0000) == 0x000d0000 263 ? 0x000d0001 264 264 : SUPDRV_IOC_VERSION & 0xffff0000; 265 265 CookieReq.u.In.u32MinVersion = MinVersion; … … 1145 1145 1146 1146 1147 SUPR3DECL(int) SUPR3PageProtect(void *pvR3, RTR0PTR R0Ptr, uint32_t off, uint32_t cb, uint32_t fProt) 1148 { 1149 /* 1150 * Validate. 1151 */ 1152 AssertPtrReturn(pvR3, VERR_INVALID_POINTER); 1153 Assert(!(off & PAGE_OFFSET_MASK)); 1154 Assert(!(cb & PAGE_OFFSET_MASK) && cb); 1155 AssertReturn(!(fProt & ~(RTMEM_PROT_NONE | RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC)), VERR_INVALID_PARAMETER); 1156 1157 /* fake */ 1158 if (RT_UNLIKELY(g_u32FakeMode)) 1159 return RTMemProtect((uint8_t *)pvR3 + off, cb, fProt); 1160 1161 /* 1162 * Some OSes can do this from ring-3, so try that before we 1163 * issue the IOCtl to the SUPDRV kernel module. 1164 * (Yea, this isn't very nice, but just try get the job done for now.) 1165 */ 1166 RTMemProtect((uint8_t *)pvR3 + off, cb, fProt); 1167 1168 SUPPAGEPROTECT Req; 1169 Req.Hdr.u32Cookie = g_u32Cookie; 1170 Req.Hdr.u32SessionCookie = g_u32SessionCookie; 1171 Req.Hdr.cbIn = SUP_IOCTL_PAGE_PROTECT_SIZE_IN; 1172 Req.Hdr.cbOut = SUP_IOCTL_PAGE_PROTECT_SIZE_OUT; 1173 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT; 1174 Req.Hdr.rc = VERR_INTERNAL_ERROR; 1175 Req.u.In.pvR3 = pvR3; 1176 Req.u.In.pvR0 = R0Ptr; 1177 Req.u.In.offSub = off; 1178 Req.u.In.cbSub = cb; 1179 Req.u.In.fProt = fProt; 1180 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_PAGE_PROTECT, &Req, SUP_IOCTL_PAGE_PROTECT_SIZE); 1181 if (RT_SUCCESS(rc)) 1182 rc = Req.Hdr.rc; 1183 return rc; 1184 } 1185 1186 1147 1187 SUPR3DECL(int) SUPR3PageFreeEx(void *pvPages, size_t cPages) 1148 1188 { -
trunk/src/VBox/HostDrivers/Support/win/SUPDrvA-win.asm
r20124 r20528 103 103 NtWrapDyn2DrvFunctionWith7Params supdrvNtWrap, RTR0MemObjMapKernelEx 104 104 NtWrapDyn2DrvFunctionWith6Params supdrvNtWrap, RTR0MemObjMapUser 105 NtWrapDyn2DrvFunctionWithAllRegParams supdrvNtWrap, RTR0MemObjProtect 105 106 ;NtWrapDyn2DrvFunctionWithAllRegParams supdrvNtWrap, RTR0MemObjAddress - not necessary 106 107 ;NtWrapDyn2DrvFunctionWithAllRegParams supdrvNtWrap, RTR0MemObjAddressR3 - not necessary
Note:
See TracChangeset
for help on using the changeset viewer.