Changeset 91675 in vbox for trunk/src/VBox/Runtime/r0drv/nt/memuserkernel-r0drv-nt.cpp
- Timestamp:
- Oct 11, 2021 8:43:10 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/nt/memuserkernel-r0drv-nt.cpp
r82968 r91675 97 97 RTR0DECL(int) RTR0MemKernelCopyFrom(void *pvDst, void const *pvSrc, size_t cb) 98 98 { 99 __try 100 { 101 memcpy(pvDst, pvSrc, cb); 102 } 103 __except(EXCEPTION_EXECUTE_HANDLER) 104 { 105 return VERR_ACCESS_DENIED; 106 } 99 if (!RTR0MemKernelIsValidAddr((void *)pvSrc)) 100 return VERR_ACCESS_DENIED; 101 102 uint8_t *pbDst = (uint8_t *)pvDst; 103 uint8_t const *pbSrc = (uint8_t const *)pvSrc; 104 105 #if 0 106 /* 107 * The try+except stuff does not work for kernel addresses. 108 */ 109 __try 110 { 111 while (cb-- > 0) 112 *pbDst++ = *pbSrc++; 113 } 114 __except(EXCEPTION_EXECUTE_HANDLER) 115 { 116 return VERR_ACCESS_DENIED; 117 } 118 #else 119 /* 120 * This is the best I can come up with for now: Work page-by-page using MmIsAddressValid. 121 */ 122 while (cb > 0) 123 { 124 if (!MmIsAddressValid((PVOID)pbSrc)) 125 return VERR_ACCESS_DENIED; 126 127 size_t cbToCopy = (uintptr_t)pbSrc & PAGE_OFFSET_MASK; 128 if (cbToCopy > cb) 129 cbToCopy = cb; 130 cb -= cbToCopy; 131 132 __try /* doesn't work, but can't hurt, right? */ 133 { 134 while (cbToCopy-- > 0) 135 *pbDst++ = *pbSrc++; 136 } 137 __except(EXCEPTION_EXECUTE_HANDLER) 138 { 139 return VERR_ACCESS_DENIED; 140 } 141 } 142 #endif 107 143 return VINF_SUCCESS; 108 144 } … … 111 147 RTR0DECL(int) RTR0MemKernelCopyTo(void *pvDst, void const *pvSrc, size_t cb) 112 148 { 113 __try 114 { 115 memcpy(pvDst, pvSrc, cb); 116 } 117 __except(EXCEPTION_EXECUTE_HANDLER) 118 { 119 return VERR_ACCESS_DENIED; 120 } 121 return VINF_SUCCESS; 122 } 123 149 if (!RTR0MemKernelIsValidAddr(pvDst)) 150 return VERR_ACCESS_DENIED; 151 #if 0 152 uint8_t *pbDst = (uint8_t *)pvDst; 153 uint8_t const *pbSrc = (uint8_t const *)pvSrc; 154 # if 0 155 /* 156 * The try+except stuff does not work for kernel addresses. 157 */ 158 __try 159 { 160 while (cb-- > 0) 161 *pbDst++ = *pbSrc++; 162 } 163 __except(EXCEPTION_EXECUTE_HANDLER) 164 { 165 return VERR_ACCESS_DENIED; 166 } 167 168 # else 169 /* 170 * This is the best I can come up with for now: Work page-by-page using MmIsAddressValid. 171 * Note! MmIsAddressValid does not indicate that it's writable, so we're a bit buggered if it isn't... 172 */ 173 while (cb > 0) 174 { 175 if (!MmIsAddressValid((PVOID)pbSrc)) 176 return VERR_ACCESS_DENIED; 177 178 size_t cbToCopy = (uintptr_t)pbSrc & PAGE_OFFSET_MASK; 179 if (cbToCopy > cb) 180 cbToCopy = cb; 181 cb -= cbToCopy; 182 183 __try /* doesn't work, but can't hurt, right? */ 184 { 185 while (cbToCopy-- > 0) 186 *pbDst++ = *pbSrc++; 187 } 188 __except(EXCEPTION_EXECUTE_HANDLER) 189 { 190 return VERR_ACCESS_DENIED; 191 } 192 } 193 # endif 194 return VINF_SUCCESS; 195 #else 196 RT_NOREF(pvDst, pvSrc, cb); 197 return VERR_NOT_SUPPORTED; 198 #endif 199 } 200
Note:
See TracChangeset
for help on using the changeset viewer.