Lines 1-4
Link Here
|
1 |
--- src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c.orig 2018-10-15 14:31:31 UTC |
1 |
--- src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c.orig 2020-07-09 16:57:38 UTC |
2 |
+++ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c |
2 |
+++ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c |
3 |
@@ -105,6 +105,7 @@ static vm_map_t rtR0MemObjFreeBSDGetMap(PRTR0MEMOBJINT |
3 |
@@ -105,6 +105,7 @@ static vm_map_t rtR0MemObjFreeBSDGetMap(PRTR0MEMOBJINT |
4 |
|
4 |
|
Lines 114-120
Link Here
|
114 |
vm_page_unlock_queues(); |
114 |
vm_page_unlock_queues(); |
115 |
#endif |
115 |
#endif |
116 |
} |
116 |
} |
117 |
@@ -364,58 +364,77 @@ static int rtR0MemObjFreeBSDAllocHelper(PRTR0MEMOBJFRE |
117 |
@@ -323,7 +323,8 @@ static int rtR0MemObjFreeBSDAllocHelper(PRTR0MEMOBJFRE |
|
|
118 |
size_t cPages = atop(pMemFreeBSD->Core.cb); |
119 |
int rc; |
120 |
|
121 |
- pMemFreeBSD->pObject = vm_object_allocate(OBJT_PHYS, cPages); |
122 |
+ pMemFreeBSD->pObject = vm_pager_allocate(OBJT_PHYS, NULL, |
123 |
+ pMemFreeBSD->Core.cb, VM_PROT_ALL, 0, curthread->td_ucred); |
124 |
|
125 |
/* No additional object reference for auto-deallocation upon unmapping. */ |
126 |
#if __FreeBSD_version >= 1000055 |
127 |
@@ -364,58 +365,77 @@ static int rtR0MemObjFreeBSDAllocHelper(PRTR0MEMOBJFRE |
118 |
} |
128 |
} |
119 |
DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable) |
129 |
DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable) |
120 |
{ |
130 |
{ |
Lines 192-198
Link Here
|
192 |
return rc; |
202 |
return rc; |
193 |
} |
203 |
} |
194 |
|
204 |
|
195 |
@@ -425,6 +444,7 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB |
205 |
@@ -425,6 +445,7 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB |
196 |
RTHCPHYS PhysHighest, size_t uAlignment, |
206 |
RTHCPHYS PhysHighest, size_t uAlignment, |
197 |
bool fContiguous, int rcNoMem) |
207 |
bool fContiguous, int rcNoMem) |
198 |
{ |
208 |
{ |
Lines 200-206
Link Here
|
200 |
uint32_t cPages = atop(cb); |
210 |
uint32_t cPages = atop(cb); |
201 |
vm_paddr_t VmPhysAddrHigh; |
211 |
vm_paddr_t VmPhysAddrHigh; |
202 |
|
212 |
|
203 |
@@ -432,7 +452,10 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB |
213 |
@@ -432,9 +453,13 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB |
204 |
PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), |
214 |
PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), |
205 |
enmType, NULL, cb); |
215 |
enmType, NULL, cb); |
206 |
if (!pMemFreeBSD) |
216 |
if (!pMemFreeBSD) |
Lines 209-217
Link Here
|
209 |
return VERR_NO_MEMORY; |
219 |
return VERR_NO_MEMORY; |
210 |
+ } |
220 |
+ } |
211 |
|
221 |
|
212 |
pMemFreeBSD->pObject = vm_object_allocate(OBJT_PHYS, atop(cb)); |
222 |
- pMemFreeBSD->pObject = vm_object_allocate(OBJT_PHYS, atop(cb)); |
|
|
223 |
+ pMemFreeBSD->pObject = vm_pager_allocate(OBJT_PHYS, NULL, |
224 |
+ pMemFreeBSD->Core.cb, VM_PROT_ALL, 0, curthread->td_ucred); |
213 |
|
225 |
|
214 |
@@ -470,6 +493,7 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB |
226 |
if (PhysHighest != NIL_RTHCPHYS) |
|
|
227 |
VmPhysAddrHigh = PhysHighest; |
228 |
@@ -470,6 +495,7 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB |
215 |
rtR0MemObjDelete(&pMemFreeBSD->Core); |
229 |
rtR0MemObjDelete(&pMemFreeBSD->Core); |
216 |
} |
230 |
} |
217 |
|
231 |
|
Lines 219-225
Link Here
|
219 |
return rc; |
233 |
return rc; |
220 |
} |
234 |
} |
221 |
|
235 |
|
222 |
@@ -489,17 +513,22 @@ DECLHIDDEN(int) rtR0MemObjNativeAllocPhysNC(PPRTR0MEMO |
236 |
@@ -489,17 +515,22 @@ DECLHIDDEN(int) rtR0MemObjNativeAllocPhysNC(PPRTR0MEMO |
223 |
DECLHIDDEN(int) rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy) |
237 |
DECLHIDDEN(int) rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy) |
224 |
{ |
238 |
{ |
225 |
AssertReturn(uCachePolicy == RTMEM_CACHE_POLICY_DONT_CARE, VERR_NOT_SUPPORTED); |
239 |
AssertReturn(uCachePolicy == RTMEM_CACHE_POLICY_DONT_CARE, VERR_NOT_SUPPORTED); |
Lines 242-248
Link Here
|
242 |
return VINF_SUCCESS; |
256 |
return VINF_SUCCESS; |
243 |
} |
257 |
} |
244 |
|
258 |
|
245 |
@@ -511,6 +540,7 @@ static int rtR0MemObjNativeLockInMap(PPRTR0MEMOBJINTER |
259 |
@@ -511,6 +542,7 @@ static int rtR0MemObjNativeLockInMap(PPRTR0MEMOBJINTER |
246 |
vm_offset_t AddrStart, size_t cb, uint32_t fAccess, |
260 |
vm_offset_t AddrStart, size_t cb, uint32_t fAccess, |
247 |
RTR0PROCESS R0Process, int fFlags) |
261 |
RTR0PROCESS R0Process, int fFlags) |
248 |
{ |
262 |
{ |
Lines 250-256
Link Here
|
250 |
int rc; |
264 |
int rc; |
251 |
NOREF(fAccess); |
265 |
NOREF(fAccess); |
252 |
|
266 |
|
253 |
@@ -519,21 +549,28 @@ static int rtR0MemObjNativeLockInMap(PPRTR0MEMOBJINTER |
267 |
@@ -519,21 +551,28 @@ static int rtR0MemObjNativeLockInMap(PPRTR0MEMOBJINTER |
254 |
if (!pMemFreeBSD) |
268 |
if (!pMemFreeBSD) |
255 |
return VERR_NO_MEMORY; |
269 |
return VERR_NO_MEMORY; |
256 |
|
270 |
|
Lines 287-293
Link Here
|
287 |
return VERR_NO_MEMORY;/** @todo fix mach -> vbox error conversion for freebsd. */ |
301 |
return VERR_NO_MEMORY;/** @todo fix mach -> vbox error conversion for freebsd. */ |
288 |
} |
302 |
} |
289 |
|
303 |
|
290 |
@@ -569,6 +606,7 @@ DECLHIDDEN(int) rtR0MemObjNativeLockKernel(PPRTR0MEMOB |
304 |
@@ -569,6 +608,7 @@ DECLHIDDEN(int) rtR0MemObjNativeLockKernel(PPRTR0MEMOB |
291 |
*/ |
305 |
*/ |
292 |
static int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process, vm_map_t pMap) |
306 |
static int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process, vm_map_t pMap) |
293 |
{ |
307 |
{ |
Lines 295-301
Link Here
|
295 |
int rc; |
309 |
int rc; |
296 |
|
310 |
|
297 |
/* |
311 |
/* |
298 |
@@ -626,11 +664,13 @@ static int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJIN |
312 |
@@ -626,11 +666,13 @@ static int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJIN |
299 |
pMemFreeBSD->Core.pv = (void *)MapAddress; |
313 |
pMemFreeBSD->Core.pv = (void *)MapAddress; |
300 |
pMemFreeBSD->Core.u.ResVirt.R0Process = R0Process; |
314 |
pMemFreeBSD->Core.u.ResVirt.R0Process = R0Process; |
301 |
*ppMem = &pMemFreeBSD->Core; |
315 |
*ppMem = &pMemFreeBSD->Core; |
Lines 309-315
Link Here
|
309 |
return rc; |
323 |
return rc; |
310 |
|
324 |
|
311 |
} |
325 |
} |
312 |
@@ -652,6 +692,8 @@ DECLHIDDEN(int) rtR0MemObjNativeReserveUser(PPRTR0MEMO |
326 |
@@ -652,6 +694,8 @@ DECLHIDDEN(int) rtR0MemObjNativeReserveUser(PPRTR0MEMO |
313 |
DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment, |
327 |
DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment, |
314 |
unsigned fProt, size_t offSub, size_t cbSub) |
328 |
unsigned fProt, size_t offSub, size_t cbSub) |
315 |
{ |
329 |
{ |
Lines 318-324
Link Here
|
318 |
// AssertMsgReturn(!offSub && !cbSub, ("%#x %#x\n", offSub, cbSub), VERR_NOT_SUPPORTED); |
332 |
// AssertMsgReturn(!offSub && !cbSub, ("%#x %#x\n", offSub, cbSub), VERR_NOT_SUPPORTED); |
319 |
AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED); |
333 |
AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED); |
320 |
|
334 |
|
321 |
@@ -707,6 +749,7 @@ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJ |
335 |
@@ -707,6 +751,7 @@ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJ |
322 |
Assert((vm_offset_t)pMemFreeBSD->Core.pv == Addr); |
336 |
Assert((vm_offset_t)pMemFreeBSD->Core.pv == Addr); |
323 |
pMemFreeBSD->Core.u.Mapping.R0Process = NIL_RTR0PROCESS; |
337 |
pMemFreeBSD->Core.u.Mapping.R0Process = NIL_RTR0PROCESS; |
324 |
*ppMem = &pMemFreeBSD->Core; |
338 |
*ppMem = &pMemFreeBSD->Core; |
Lines 326-332
Link Here
|
326 |
return VINF_SUCCESS; |
340 |
return VINF_SUCCESS; |
327 |
} |
341 |
} |
328 |
rc = vm_map_remove(kernel_map, Addr, Addr + cbSub); |
342 |
rc = vm_map_remove(kernel_map, Addr, Addr + cbSub); |
329 |
@@ -715,6 +758,7 @@ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJ |
343 |
@@ -715,6 +760,7 @@ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJ |
330 |
else |
344 |
else |
331 |
vm_object_deallocate(pMemToMapFreeBSD->pObject); |
345 |
vm_object_deallocate(pMemToMapFreeBSD->pObject); |
332 |
|
346 |
|
Lines 334-340
Link Here
|
334 |
return VERR_NO_MEMORY; |
348 |
return VERR_NO_MEMORY; |
335 |
} |
349 |
} |
336 |
|
350 |
|
337 |
@@ -722,6 +766,8 @@ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJ |
351 |
@@ -722,6 +768,8 @@ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJ |
338 |
DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, |
352 |
DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, |
339 |
unsigned fProt, RTR0PROCESS R0Process) |
353 |
unsigned fProt, RTR0PROCESS R0Process) |
340 |
{ |
354 |
{ |
Lines 343-349
Link Here
|
343 |
/* |
357 |
/* |
344 |
* Check for unsupported stuff. |
358 |
* Check for unsupported stuff. |
345 |
*/ |
359 |
*/ |
346 |
@@ -751,7 +797,12 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJIN |
360 |
@@ -751,7 +799,12 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJIN |
347 |
{ |
361 |
{ |
348 |
/** @todo is this needed?. */ |
362 |
/** @todo is this needed?. */ |
349 |
PROC_LOCK(pProc); |
363 |
PROC_LOCK(pProc); |
Lines 357-363
Link Here
|
357 |
PROC_UNLOCK(pProc); |
371 |
PROC_UNLOCK(pProc); |
358 |
} |
372 |
} |
359 |
else |
373 |
else |
360 |
@@ -793,6 +844,7 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJIN |
374 |
@@ -774,10 +827,9 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJIN |
|
|
375 |
0); /* copy-on-write and similar flags */ |
376 |
|
377 |
if (rc == KERN_SUCCESS) |
378 |
- { |
379 |
rc = vm_map_wire(pProcMap, AddrR3, AddrR3 + pMemToMap->cb, VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES); |
380 |
- AssertMsg(rc == KERN_SUCCESS, ("%#x\n", rc)); |
381 |
- |
382 |
+ if (rc == KERN_SUCCESS) |
383 |
+ { |
384 |
rc = vm_map_inherit(pProcMap, AddrR3, AddrR3 + pMemToMap->cb, VM_INHERIT_SHARE); |
385 |
AssertMsg(rc == KERN_SUCCESS, ("%#x\n", rc)); |
386 |
|
387 |
@@ -793,6 +845,7 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJIN |
361 |
Assert((vm_offset_t)pMemFreeBSD->Core.pv == AddrR3); |
388 |
Assert((vm_offset_t)pMemFreeBSD->Core.pv == AddrR3); |
362 |
pMemFreeBSD->Core.u.Mapping.R0Process = R0Process; |
389 |
pMemFreeBSD->Core.u.Mapping.R0Process = R0Process; |
363 |
*ppMem = &pMemFreeBSD->Core; |
390 |
*ppMem = &pMemFreeBSD->Core; |
Lines 365-371
Link Here
|
365 |
return VINF_SUCCESS; |
392 |
return VINF_SUCCESS; |
366 |
} |
393 |
} |
367 |
|
394 |
|
368 |
@@ -802,19 +854,25 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJIN |
395 |
@@ -802,19 +855,25 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJIN |
369 |
else |
396 |
else |
370 |
vm_object_deallocate(pMemToMapFreeBSD->pObject); |
397 |
vm_object_deallocate(pMemToMapFreeBSD->pObject); |
371 |
|
398 |
|
Lines 391-397
Link Here
|
391 |
|
418 |
|
392 |
if ((fProt & RTMEM_PROT_NONE) == RTMEM_PROT_NONE) |
419 |
if ((fProt & RTMEM_PROT_NONE) == RTMEM_PROT_NONE) |
393 |
ProtectionFlags = VM_PROT_NONE; |
420 |
ProtectionFlags = VM_PROT_NONE; |
394 |
@@ -826,6 +884,7 @@ DECLHIDDEN(int) rtR0MemObjNativeProtect(PRTR0MEMOBJINT |
421 |
@@ -826,6 +885,7 @@ DECLHIDDEN(int) rtR0MemObjNativeProtect(PRTR0MEMOBJINT |
395 |
ProtectionFlags |= VM_PROT_EXECUTE; |
422 |
ProtectionFlags |= VM_PROT_EXECUTE; |
396 |
|
423 |
|
397 |
int krc = vm_map_protect(pVmMap, AddrStart, AddrEnd, ProtectionFlags, FALSE); |
424 |
int krc = vm_map_protect(pVmMap, AddrStart, AddrEnd, ProtectionFlags, FALSE); |
Lines 399-405
Link Here
|
399 |
if (krc == KERN_SUCCESS) |
426 |
if (krc == KERN_SUCCESS) |
400 |
return VINF_SUCCESS; |
427 |
return VINF_SUCCESS; |
401 |
|
428 |
|
402 |
@@ -850,11 +909,19 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P |
429 |
@@ -850,11 +910,19 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P |
403 |
|
430 |
|
404 |
vm_offset_t pb = (vm_offset_t)pMemFreeBSD->Core.pv + ptoa(iPage); |
431 |
vm_offset_t pb = (vm_offset_t)pMemFreeBSD->Core.pv + ptoa(iPage); |
405 |
|
432 |
|
Lines 423-429
Link Here
|
423 |
} |
450 |
} |
424 |
|
451 |
|
425 |
case RTR0MEMOBJTYPE_MAPPING: |
452 |
case RTR0MEMOBJTYPE_MAPPING: |
426 |
@@ -863,11 +930,15 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P |
453 |
@@ -863,11 +931,15 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P |
427 |
|
454 |
|
428 |
if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS) |
455 |
if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS) |
429 |
{ |
456 |
{ |
Lines 440-446
Link Here
|
440 |
} |
467 |
} |
441 |
return vtophys(pb); |
468 |
return vtophys(pb); |
442 |
} |
469 |
} |
443 |
@@ -877,6 +948,7 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P |
470 |
@@ -877,6 +949,7 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P |
444 |
case RTR0MEMOBJTYPE_PHYS_NC: |
471 |
case RTR0MEMOBJTYPE_PHYS_NC: |
445 |
{ |
472 |
{ |
446 |
RTHCPHYS addr; |
473 |
RTHCPHYS addr; |
Lines 448-454
Link Here
|
448 |
#if __FreeBSD_version >= 1000030 |
475 |
#if __FreeBSD_version >= 1000030 |
449 |
VM_OBJECT_WLOCK(pMemFreeBSD->pObject); |
476 |
VM_OBJECT_WLOCK(pMemFreeBSD->pObject); |
450 |
#else |
477 |
#else |
451 |
@@ -888,6 +960,7 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P |
478 |
@@ -888,6 +961,7 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P |
452 |
#else |
479 |
#else |
453 |
VM_OBJECT_UNLOCK(pMemFreeBSD->pObject); |
480 |
VM_OBJECT_UNLOCK(pMemFreeBSD->pObject); |
454 |
#endif |
481 |
#endif |