-
Notifications
You must be signed in to change notification settings - Fork 9
/
patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c
162 lines (152 loc) · 5.56 KB
/
patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
--- src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c.orig 2016-07-18 19:56:55.000000000 +0800
+++ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c 2016-07-26 16:04:55.282395000 +0800
@@ -121,16 +121,15 @@
case RTR0MEMOBJTYPE_LOCK:
{
- vm_map_t pMap = kernel_map;
-
- if (pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
- pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map;
+ if (pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS) {
+ vm_map_t pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map;
- rc = vm_map_unwire(pMap,
+ rc = vm_map_unwire(pMap,
(vm_offset_t)pMemFreeBSD->Core.pv,
(vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb,
VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
- AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
+ AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
+ }
break;
}
@@ -224,18 +223,23 @@
#else
VM_OBJECT_UNLOCK(pObject);
#endif
- if (pPages)
+ if (pPages || cTries >= 1)
break;
+#if __FreeBSD_version >= 1100092
+ if (!vm_page_reclaim_contig(fFlags, cPages, 0, VmPhysAddrHigh, uAlignment, 0))
+ break;
+#elif __FreeBSD_version >= 1000015
vm_pageout_grow_cache(cTries, 0, VmPhysAddrHigh);
+#else
+ vm_contig_grow_cache(cTries, 0, VmPhysAddrHigh);
+#endif
cTries++;
}
-
- return pPages;
#else
- while (cTries <= 1)
+ while (1)
{
pPages = vm_phys_alloc_contig(cPages, 0, VmPhysAddrHigh, uAlignment, 0);
- if (pPages)
+ if (pPages || cTries >= 1)
break;
vm_contig_grow_cache(cTries, 0, VmPhysAddrHigh);
cTries++;
@@ -243,11 +247,8 @@
if (!pPages)
return pPages;
-#if __FreeBSD_version >= 1000030
- VM_OBJECT_WLOCK(pObject);
-#else
+
VM_OBJECT_LOCK(pObject);
-#endif
for (vm_pindex_t iPage = 0; iPage < cPages; iPage++)
{
vm_page_t pPage = pPages + iPage;
@@ -259,13 +260,9 @@
atomic_add_int(&cnt.v_wire_count, 1);
}
}
-#if __FreeBSD_version >= 1000030
- VM_OBJECT_WUNLOCK(pObject);
-#else
VM_OBJECT_UNLOCK(pObject);
#endif
return pPages;
-#endif
}
static int rtR0MemObjFreeBSDPhysAllocHelper(vm_object_t pObject, u_long cPages,
@@ -292,16 +289,17 @@
#else
VM_OBJECT_LOCK(pObject);
#endif
+
while (iPage-- > 0)
{
pPage = vm_page_lookup(pObject, iPage);
-#if __FreeBSD_version < 1000000
+#if __FreeBSD_version < 900000
vm_page_lock_queues();
#endif
if (fWire)
vm_page_unwire(pPage, 0);
vm_page_free(pPage);
-#if __FreeBSD_version < 1000000
+#if __FreeBSD_version < 900000
vm_page_unlock_queues();
#endif
}
@@ -519,14 +517,19 @@
if (!pMemFreeBSD)
return VERR_NO_MEMORY;
- /*
- * We could've used vslock here, but we don't wish to be subject to
- * resource usage restrictions, so we'll call vm_map_wire directly.
- */
- rc = vm_map_wire(pVmMap, /* the map */
- AddrStart, /* start */
- AddrStart + cb, /* end */
- fFlags); /* flags */
+ if (pVmMap != kernel_map) {
+ /*
+ * We could've used vslock here, but we don't wish to be subject to
+ * resource usage restrictions, so we'll call vm_map_wire directly.
+ */
+ rc = vm_map_wire(pVmMap, /* the map */
+ AddrStart, /* start */
+ AddrStart + cb, /* end */
+ fFlags); /* flags */
+ }
+ else
+ rc = KERN_SUCCESS;
+
if (rc == KERN_SUCCESS)
{
pMemFreeBSD->Core.u.Lock.R0Process = R0Process;
@@ -751,7 +754,12 @@
{
/** @todo: is this needed?. */
PROC_LOCK(pProc);
- AddrR3 = round_page((vm_offset_t)pProc->p_vmspace->vm_daddr + lim_max(pProc, RLIMIT_DATA));
+ AddrR3 = round_page((vm_offset_t)pProc->p_vmspace->vm_daddr +
+#if __FreeBSD_version >= 1100077
+ lim_max_proc(pProc, RLIMIT_DATA));
+#else
+ lim_max(pProc, RLIMIT_DATA));
+#endif
PROC_UNLOCK(pProc);
}
else
@@ -850,11 +858,15 @@
vm_offset_t pb = (vm_offset_t)pMemFreeBSD->Core.pv + ptoa(iPage);
- struct proc *pProc = (struct proc *)pMemFreeBSD->Core.u.Lock.R0Process;
- struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
- pmap_t pPhysicalMap = vm_map_pmap(pProcMap);
+ if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
+ {
+ struct proc *pProc = (struct proc *)pMemFreeBSD->Core.u.Lock.R0Process;
+ struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
+ pmap_t pPhysicalMap = vm_map_pmap(pProcMap);
- return pmap_extract(pPhysicalMap, pb);
+ return pmap_extract(pPhysicalMap, pb);
+ }
+ return vtophys(pb);
}
case RTR0MEMOBJTYPE_MAPPING: