1 | /* $Id: memobj-r0drv-os2.cpp 32348 2010-09-09 12:28:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Ring-0 Memory Objects, OS/2.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person
|
---|
10 | * obtaining a copy of this software and associated documentation
|
---|
11 | * files (the "Software"), to deal in the Software without
|
---|
12 | * restriction, including without limitation the rights to use,
|
---|
13 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
14 | * copies of the Software, and to permit persons to whom the
|
---|
15 | * Software is furnished to do so, subject to the following
|
---|
16 | * conditions:
|
---|
17 | *
|
---|
18 | * The above copyright notice and this permission notice shall be
|
---|
19 | * included in all copies or substantial portions of the Software.
|
---|
20 | *
|
---|
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
28 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #include "the-os2-kernel.h"
|
---|
36 |
|
---|
37 | #include <iprt/memobj.h>
|
---|
38 | #include <iprt/mem.h>
|
---|
39 | #include <iprt/err.h>
|
---|
40 | #include <iprt/assert.h>
|
---|
41 | #include <iprt/log.h>
|
---|
42 | #include <iprt/param.h>
|
---|
43 | #include <iprt/process.h>
|
---|
44 | #include "internal/memobj.h"
|
---|
45 |
|
---|
46 |
|
---|
47 | /*******************************************************************************
|
---|
48 | * Structures and Typedefs *
|
---|
49 | *******************************************************************************/
|
---|
50 | /**
|
---|
51 | * The OS/2 version of the memory object structure.
|
---|
52 | */
|
---|
53 | typedef struct RTR0MEMOBJDARWIN
|
---|
54 | {
|
---|
55 | /** The core structure. */
|
---|
56 | RTR0MEMOBJINTERNAL Core;
|
---|
57 | /** Lock for the ring-3 / ring-0 pinned objectes.
|
---|
58 | * This member might not be allocated for some object types. */
|
---|
59 | KernVMLock_t Lock;
|
---|
60 | /** Array of physical pages.
|
---|
61 | * This array can be 0 in length for some object types. */
|
---|
62 | KernPageList_t aPages[1];
|
---|
63 | } RTR0MEMOBJOS2, *PRTR0MEMOBJOS2;
|
---|
64 |
|
---|
65 |
|
---|
66 | /*******************************************************************************
|
---|
67 | * Internal Functions *
|
---|
68 | *******************************************************************************/
|
---|
69 | static void rtR0MemObjFixPageList(KernPageList_t *paPages, ULONG cPages, ULONG cPagesRet);
|
---|
70 |
|
---|
71 |
|
---|
72 | int rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
|
---|
73 | {
|
---|
74 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)pMem;
|
---|
75 | int rc;
|
---|
76 |
|
---|
77 | switch (pMemOs2->Core.enmType)
|
---|
78 | {
|
---|
79 | case RTR0MEMOBJTYPE_PHYS_NC:
|
---|
80 | AssertMsgFailed(("RTR0MEMOBJTYPE_PHYS_NC\n"));
|
---|
81 | return VERR_INTERNAL_ERROR;
|
---|
82 | break;
|
---|
83 |
|
---|
84 | case RTR0MEMOBJTYPE_PHYS:
|
---|
85 | if (!pMemOs2->Core.pv)
|
---|
86 | break;
|
---|
87 |
|
---|
88 | case RTR0MEMOBJTYPE_MAPPING:
|
---|
89 | if (pMemOs2->Core.u.Mapping.R0Process == NIL_RTR0PROCESS)
|
---|
90 | break;
|
---|
91 |
|
---|
92 | /* fall thru */
|
---|
93 | case RTR0MEMOBJTYPE_PAGE:
|
---|
94 | case RTR0MEMOBJTYPE_LOW:
|
---|
95 | case RTR0MEMOBJTYPE_CONT:
|
---|
96 | rc = KernVMFree(pMemOs2->Core.pv);
|
---|
97 | AssertMsg(!rc, ("rc=%d type=%d pv=%p cb=%#zx\n", rc, pMemOs2->Core.enmType, pMemOs2->Core.pv, pMemOs2->Core.cb));
|
---|
98 | break;
|
---|
99 |
|
---|
100 | case RTR0MEMOBJTYPE_LOCK:
|
---|
101 | rc = KernVMUnlock(&pMemOs2->Lock);
|
---|
102 | AssertMsg(!rc, ("rc=%d\n", rc));
|
---|
103 | break;
|
---|
104 |
|
---|
105 | case RTR0MEMOBJTYPE_RES_VIRT:
|
---|
106 | default:
|
---|
107 | AssertMsgFailed(("enmType=%d\n", pMemOs2->Core.enmType));
|
---|
108 | return VERR_INTERNAL_ERROR;
|
---|
109 | }
|
---|
110 |
|
---|
111 | return VINF_SUCCESS;
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | int rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
|
---|
116 | {
|
---|
117 | NOREF(fExecutable);
|
---|
118 |
|
---|
119 | /* create the object. */
|
---|
120 | const ULONG cPages = cb >> PAGE_SHIFT;
|
---|
121 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_PAGE, NULL, cb);
|
---|
122 | if (!pMemOs2)
|
---|
123 | return VERR_NO_MEMORY;
|
---|
124 |
|
---|
125 | /* do the allocation. */
|
---|
126 | int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMemOs2->Core.pv, (PPVOID)-1, NULL);
|
---|
127 | if (!rc)
|
---|
128 | {
|
---|
129 | ULONG cPagesRet = cPages;
|
---|
130 | rc = KernLinToPageList(pMemOs2->Core.pv, cb, &pMemOs2->aPages[0], &cPagesRet);
|
---|
131 | if (!rc)
|
---|
132 | {
|
---|
133 | rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet);
|
---|
134 | *ppMem = &pMemOs2->Core;
|
---|
135 | return VINF_SUCCESS;
|
---|
136 | }
|
---|
137 | KernVMFree(pMemOs2->Core.pv);
|
---|
138 | }
|
---|
139 | rtR0MemObjDelete(&pMemOs2->Core);
|
---|
140 | return RTErrConvertFromOS2(rc);
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | int rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
|
---|
145 | {
|
---|
146 | NOREF(fExecutable);
|
---|
147 |
|
---|
148 | /* create the object. */
|
---|
149 | const ULONG cPages = cb >> PAGE_SHIFT;
|
---|
150 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOW, NULL, cb);
|
---|
151 | if (!pMemOs2)
|
---|
152 | return VERR_NO_MEMORY;
|
---|
153 |
|
---|
154 | /* do the allocation. */
|
---|
155 | int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMemOs2->Core.pv, (PPVOID)-1, NULL);
|
---|
156 | if (!rc)
|
---|
157 | {
|
---|
158 | ULONG cPagesRet = cPages;
|
---|
159 | rc = KernLinToPageList(pMemOs2->Core.pv, cb, &pMemOs2->aPages[0], &cPagesRet);
|
---|
160 | if (!rc)
|
---|
161 | {
|
---|
162 | rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet);
|
---|
163 | *ppMem = &pMemOs2->Core;
|
---|
164 | return VINF_SUCCESS;
|
---|
165 | }
|
---|
166 | KernVMFree(pMemOs2->Core.pv);
|
---|
167 | }
|
---|
168 | rtR0MemObjDelete(&pMemOs2->Core);
|
---|
169 | return RTErrConvertFromOS2(rc);
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
|
---|
174 | {
|
---|
175 | NOREF(fExecutable);
|
---|
176 |
|
---|
177 | /* create the object. */
|
---|
178 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_CONT, NULL, cb);
|
---|
179 | if (!pMemOs2)
|
---|
180 | return VERR_NO_MEMORY;
|
---|
181 |
|
---|
182 | /* do the allocation. */
|
---|
183 | ULONG ulPhys = ~0UL;
|
---|
184 | int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL);
|
---|
185 | if (!rc)
|
---|
186 | {
|
---|
187 | Assert(ulPhys != ~0UL);
|
---|
188 | pMemOs2->Core.u.Cont.Phys = ulPhys;
|
---|
189 | *ppMem = &pMemOs2->Core;
|
---|
190 | return VINF_SUCCESS;
|
---|
191 | }
|
---|
192 | rtR0MemObjDelete(&pMemOs2->Core);
|
---|
193 | return RTErrConvertFromOS2(rc);
|
---|
194 | }
|
---|
195 |
|
---|
196 |
|
---|
197 | int rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment)
|
---|
198 | {
|
---|
199 | AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_SUPPORTED);
|
---|
200 |
|
---|
201 | /** @todo alignment */
|
---|
202 | if (uAlignment != PAGE_SIZE)
|
---|
203 | return VERR_NOT_SUPPORTED;
|
---|
204 |
|
---|
205 | /* create the object. */
|
---|
206 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb);
|
---|
207 | if (!pMemOs2)
|
---|
208 | return VERR_NO_MEMORY;
|
---|
209 |
|
---|
210 | /* do the allocation. */
|
---|
211 | ULONG ulPhys = ~0UL;
|
---|
212 | int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G ? VMDHA_16M : 0), &pMemOs2->Core.pv, (PPVOID)&ulPhys, NULL);
|
---|
213 | if (!rc)
|
---|
214 | {
|
---|
215 | Assert(ulPhys != ~0UL);
|
---|
216 | pMemOs2->Core.u.Phys.fAllocated = true;
|
---|
217 | pMemOs2->Core.u.Phys.PhysBase = ulPhys;
|
---|
218 | *ppMem = &pMemOs2->Core;
|
---|
219 | return VINF_SUCCESS;
|
---|
220 | }
|
---|
221 | rtR0MemObjDelete(&pMemOs2->Core);
|
---|
222 | return RTErrConvertFromOS2(rc);
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
|
---|
227 | {
|
---|
228 | /** @todo rtR0MemObjNativeAllocPhys / darwin. */
|
---|
229 | return rtR0MemObjNativeAllocPhys(ppMem, cb, PhysHighest, PAGE_SIZE);
|
---|
230 | }
|
---|
231 |
|
---|
232 |
|
---|
233 | int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy)
|
---|
234 | {
|
---|
235 | AssertReturn(uCachePolicy == RTMEM_CACHE_POLICY_DONT_CARE, VERR_NOT_SUPPORTED);
|
---|
236 |
|
---|
237 | /* create the object. */
|
---|
238 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb);
|
---|
239 | if (!pMemOs2)
|
---|
240 | return VERR_NO_MEMORY;
|
---|
241 |
|
---|
242 | /* there is no allocation here, right? it needs to be mapped somewhere first. */
|
---|
243 | pMemOs2->Core.u.Phys.fAllocated = false;
|
---|
244 | pMemOs2->Core.u.Phys.PhysBase = Phys;
|
---|
245 | pMemOs2->Core.u.Phys.uCachePolicy = uCachePolicy;
|
---|
246 | *ppMem = &pMemOs2->Core;
|
---|
247 | return VINF_SUCCESS;
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
|
---|
252 | {
|
---|
253 | AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
|
---|
254 |
|
---|
255 | /* create the object. */
|
---|
256 | const ULONG cPages = cb >> PAGE_SHIFT;
|
---|
257 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
|
---|
258 | if (!pMemOs2)
|
---|
259 | return VERR_NO_MEMORY;
|
---|
260 |
|
---|
261 | /* lock it. */
|
---|
262 | ULONG cPagesRet = cPages;
|
---|
263 | int rc = KernVMLock(VMDHL_LONG | (fAccess & RTMEM_PROT_WRITE ? VMDHL_WRITE : 0),
|
---|
264 | (void *)R3Ptr, cb, &pMemOs2->Lock, &pMemOs2->aPages[0], &cPagesRet);
|
---|
265 | if (!rc)
|
---|
266 | {
|
---|
267 | rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet);
|
---|
268 | Assert(cb == pMemOs2->Core.cb);
|
---|
269 | Assert(R3Ptr == (RTR3PTR)pMemOs2->Core.pv);
|
---|
270 | pMemOs2->Core.u.Lock.R0Process = R0Process;
|
---|
271 | *ppMem = &pMemOs2->Core;
|
---|
272 | return VINF_SUCCESS;
|
---|
273 | }
|
---|
274 | rtR0MemObjDelete(&pMemOs2->Core);
|
---|
275 | return RTErrConvertFromOS2(rc);
|
---|
276 | }
|
---|
277 |
|
---|
278 |
|
---|
279 | int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
|
---|
280 | {
|
---|
281 | /* create the object. */
|
---|
282 | const ULONG cPages = cb >> PAGE_SHIFT;
|
---|
283 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb);
|
---|
284 | if (!pMemOs2)
|
---|
285 | return VERR_NO_MEMORY;
|
---|
286 |
|
---|
287 | /* lock it. */
|
---|
288 | ULONG cPagesRet = cPages;
|
---|
289 | int rc = KernVMLock(VMDHL_LONG | (fAccess & RTMEM_PROT_WRITE ? VMDHL_WRITE : 0),
|
---|
290 | pv, cb, &pMemOs2->Lock, &pMemOs2->aPages[0], &cPagesRet);
|
---|
291 | if (!rc)
|
---|
292 | {
|
---|
293 | rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet);
|
---|
294 | pMemOs2->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
|
---|
295 | *ppMem = &pMemOs2->Core;
|
---|
296 | return VINF_SUCCESS;
|
---|
297 | }
|
---|
298 | rtR0MemObjDelete(&pMemOs2->Core);
|
---|
299 | return RTErrConvertFromOS2(rc);
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
|
---|
304 | {
|
---|
305 | return VERR_NOT_SUPPORTED;
|
---|
306 | }
|
---|
307 |
|
---|
308 |
|
---|
309 | int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
|
---|
310 | {
|
---|
311 | return VERR_NOT_SUPPORTED;
|
---|
312 | }
|
---|
313 |
|
---|
314 |
|
---|
315 | int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
|
---|
316 | unsigned fProt, size_t offSub, size_t cbSub)
|
---|
317 | {
|
---|
318 | AssertMsgReturn(!offSub && !cbSub, ("%#x %#x\n", offSub, cbSub), VERR_NOT_SUPPORTED);
|
---|
319 | AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
|
---|
320 |
|
---|
321 | /*
|
---|
322 | * Check that the specified alignment is supported.
|
---|
323 | */
|
---|
324 | if (uAlignment > PAGE_SIZE)
|
---|
325 | return VERR_NOT_SUPPORTED;
|
---|
326 |
|
---|
327 |
|
---|
328 | /** @todo finish the implementation. */
|
---|
329 |
|
---|
330 | int rc;
|
---|
331 | void *pvR0 = NULL;
|
---|
332 | PRTR0MEMOBJOS2 pMemToMapOs2 = (PRTR0MEMOBJOS2)pMemToMap;
|
---|
333 | switch (pMemToMapOs2->Core.enmType)
|
---|
334 | {
|
---|
335 | /*
|
---|
336 | * These has kernel mappings.
|
---|
337 | */
|
---|
338 | case RTR0MEMOBJTYPE_PAGE:
|
---|
339 | case RTR0MEMOBJTYPE_LOW:
|
---|
340 | case RTR0MEMOBJTYPE_CONT:
|
---|
341 | pvR0 = pMemToMapOs2->Core.pv;
|
---|
342 | break;
|
---|
343 |
|
---|
344 | case RTR0MEMOBJTYPE_PHYS:
|
---|
345 | pvR0 = pMemToMapOs2->Core.pv;
|
---|
346 | if (!pvR0)
|
---|
347 | {
|
---|
348 | /* no ring-0 mapping, so allocate a mapping in the process. */
|
---|
349 | AssertMsgReturn(fProt & RTMEM_PROT_WRITE, ("%#x\n", fProt), VERR_NOT_SUPPORTED);
|
---|
350 | Assert(!pMemToMapOs2->Core.u.Phys.fAllocated);
|
---|
351 | ULONG ulPhys = pMemToMapOs2->Core.u.Phys.PhysBase;
|
---|
352 | rc = KernVMAlloc(pMemToMapOs2->Core.cb, VMDHA_PHYS, &pvR0, (PPVOID)&ulPhys, NULL);
|
---|
353 | if (rc)
|
---|
354 | return RTErrConvertFromOS2(rc);
|
---|
355 | pMemToMapOs2->Core.pv = pvR0;
|
---|
356 | }
|
---|
357 | break;
|
---|
358 |
|
---|
359 | case RTR0MEMOBJTYPE_PHYS_NC:
|
---|
360 | AssertMsgFailed(("RTR0MEMOBJTYPE_PHYS_NC\n"));
|
---|
361 | return VERR_INTERNAL_ERROR_3;
|
---|
362 | break;
|
---|
363 |
|
---|
364 | case RTR0MEMOBJTYPE_LOCK:
|
---|
365 | if (pMemToMapOs2->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
|
---|
366 | return VERR_NOT_SUPPORTED; /** @todo implement this... */
|
---|
367 | pvR0 = pMemToMapOs2->Core.pv;
|
---|
368 | break;
|
---|
369 |
|
---|
370 | case RTR0MEMOBJTYPE_RES_VIRT:
|
---|
371 | case RTR0MEMOBJTYPE_MAPPING:
|
---|
372 | default:
|
---|
373 | AssertMsgFailed(("enmType=%d\n", pMemToMapOs2->Core.enmType));
|
---|
374 | return VERR_INTERNAL_ERROR;
|
---|
375 | }
|
---|
376 |
|
---|
377 | /*
|
---|
378 | * Create a dummy mapping object for it.
|
---|
379 | *
|
---|
380 | * All mappings are read/write/execute in OS/2 and there isn't
|
---|
381 | * any cache options, so sharing is ok. And the main memory object
|
---|
382 | * isn't actually freed until all the mappings have been freed up
|
---|
383 | * (reference counting).
|
---|
384 | */
|
---|
385 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR0, pMemToMapOs2->Core.cb);
|
---|
386 | if (pMemOs2)
|
---|
387 | {
|
---|
388 | pMemOs2->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;
|
---|
389 | *ppMem = &pMemOs2->Core;
|
---|
390 | return VINF_SUCCESS;
|
---|
391 | }
|
---|
392 | return VERR_NO_MEMORY;
|
---|
393 | }
|
---|
394 |
|
---|
395 |
|
---|
396 | int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
|
---|
397 | {
|
---|
398 | AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
|
---|
399 | AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
|
---|
400 | if (uAlignment > PAGE_SIZE)
|
---|
401 | return VERR_NOT_SUPPORTED;
|
---|
402 |
|
---|
403 | int rc;
|
---|
404 | void *pvR0;
|
---|
405 | void *pvR3 = NULL;
|
---|
406 | PRTR0MEMOBJOS2 pMemToMapOs2 = (PRTR0MEMOBJOS2)pMemToMap;
|
---|
407 | switch (pMemToMapOs2->Core.enmType)
|
---|
408 | {
|
---|
409 | /*
|
---|
410 | * These has kernel mappings.
|
---|
411 | */
|
---|
412 | case RTR0MEMOBJTYPE_PAGE:
|
---|
413 | case RTR0MEMOBJTYPE_LOW:
|
---|
414 | case RTR0MEMOBJTYPE_CONT:
|
---|
415 | pvR0 = pMemToMapOs2->Core.pv;
|
---|
416 | break;
|
---|
417 |
|
---|
418 | case RTR0MEMOBJTYPE_PHYS:
|
---|
419 | pvR0 = pMemToMapOs2->Core.pv;
|
---|
420 | #if 0/* this is wrong. */
|
---|
421 | if (!pvR0)
|
---|
422 | {
|
---|
423 | /* no ring-0 mapping, so allocate a mapping in the process. */
|
---|
424 | AssertMsgReturn(fProt & RTMEM_PROT_WRITE, ("%#x\n", fProt), VERR_NOT_SUPPORTED);
|
---|
425 | Assert(!pMemToMapOs2->Core.u.Phys.fAllocated);
|
---|
426 | ULONG ulPhys = pMemToMapOs2->Core.u.Phys.PhysBase;
|
---|
427 | rc = KernVMAlloc(pMemToMapOs2->Core.cb, VMDHA_PHYS | VMDHA_PROCESS, &pvR3, (PPVOID)&ulPhys, NULL);
|
---|
428 | if (rc)
|
---|
429 | return RTErrConvertFromOS2(rc);
|
---|
430 | }
|
---|
431 | break;
|
---|
432 | #endif
|
---|
433 | return VERR_NOT_SUPPORTED;
|
---|
434 |
|
---|
435 | case RTR0MEMOBJTYPE_PHYS_NC:
|
---|
436 | AssertMsgFailed(("RTR0MEMOBJTYPE_PHYS_NC\n"));
|
---|
437 | return VERR_INTERNAL_ERROR_5;
|
---|
438 | break;
|
---|
439 |
|
---|
440 | case RTR0MEMOBJTYPE_LOCK:
|
---|
441 | if (pMemToMapOs2->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
|
---|
442 | return VERR_NOT_SUPPORTED; /** @todo implement this... */
|
---|
443 | pvR0 = pMemToMapOs2->Core.pv;
|
---|
444 | break;
|
---|
445 |
|
---|
446 | case RTR0MEMOBJTYPE_RES_VIRT:
|
---|
447 | case RTR0MEMOBJTYPE_MAPPING:
|
---|
448 | default:
|
---|
449 | AssertMsgFailed(("enmType=%d\n", pMemToMapOs2->Core.enmType));
|
---|
450 | return VERR_INTERNAL_ERROR;
|
---|
451 | }
|
---|
452 |
|
---|
453 | /*
|
---|
454 | * Map the ring-0 memory into the current process.
|
---|
455 | */
|
---|
456 | if (!pvR3)
|
---|
457 | {
|
---|
458 | Assert(pvR0);
|
---|
459 | ULONG flFlags = 0;
|
---|
460 | if (uAlignment == PAGE_SIZE)
|
---|
461 | flFlags |= VMDHGP_4MB;
|
---|
462 | if (fProt & RTMEM_PROT_WRITE)
|
---|
463 | flFlags |= VMDHGP_WRITE;
|
---|
464 | rc = RTR0Os2DHVMGlobalToProcess(flFlags, pvR0, pMemToMapOs2->Core.cb, &pvR3);
|
---|
465 | if (rc)
|
---|
466 | return RTErrConvertFromOS2(rc);
|
---|
467 | }
|
---|
468 | Assert(pvR3);
|
---|
469 |
|
---|
470 | /*
|
---|
471 | * Create a mapping object for it.
|
---|
472 | */
|
---|
473 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR3, pMemToMapOs2->Core.cb);
|
---|
474 | if (pMemOs2)
|
---|
475 | {
|
---|
476 | Assert(pMemOs2->Core.pv == pvR3);
|
---|
477 | pMemOs2->Core.u.Mapping.R0Process = R0Process;
|
---|
478 | *ppMem = &pMemOs2->Core;
|
---|
479 | return VINF_SUCCESS;
|
---|
480 | }
|
---|
481 | KernVMFree(pvR3);
|
---|
482 | return VERR_NO_MEMORY;
|
---|
483 | }
|
---|
484 |
|
---|
485 |
|
---|
486 | int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
|
---|
487 | {
|
---|
488 | NOREF(pMem);
|
---|
489 | NOREF(offSub);
|
---|
490 | NOREF(cbSub);
|
---|
491 | NOREF(fProt);
|
---|
492 | return VERR_NOT_SUPPORTED;
|
---|
493 | }
|
---|
494 |
|
---|
495 |
|
---|
496 | RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage)
|
---|
497 | {
|
---|
498 | PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)pMem;
|
---|
499 |
|
---|
500 | switch (pMemOs2->Core.enmType)
|
---|
501 | {
|
---|
502 | case RTR0MEMOBJTYPE_PAGE:
|
---|
503 | case RTR0MEMOBJTYPE_LOW:
|
---|
504 | case RTR0MEMOBJTYPE_LOCK:
|
---|
505 | case RTR0MEMOBJTYPE_PHYS_NC:
|
---|
506 | return pMemOs2->aPages[iPage].Addr;
|
---|
507 |
|
---|
508 | case RTR0MEMOBJTYPE_CONT:
|
---|
509 | return pMemOs2->Core.u.Cont.Phys + (iPage << PAGE_SHIFT);
|
---|
510 |
|
---|
511 | case RTR0MEMOBJTYPE_PHYS:
|
---|
512 | return pMemOs2->Core.u.Phys.PhysBase + (iPage << PAGE_SHIFT);
|
---|
513 |
|
---|
514 | case RTR0MEMOBJTYPE_RES_VIRT:
|
---|
515 | case RTR0MEMOBJTYPE_MAPPING:
|
---|
516 | default:
|
---|
517 | return NIL_RTHCPHYS;
|
---|
518 | }
|
---|
519 | }
|
---|
520 |
|
---|
521 |
|
---|
522 | /**
|
---|
523 | * Expands the page list so we can index pages directly.
|
---|
524 | *
|
---|
525 | * @param paPages The page list array to fix.
|
---|
526 | * @param cPages The number of pages that's supposed to go into the list.
|
---|
527 | * @param cPagesRet The actual number of pages in the list.
|
---|
528 | */
|
---|
529 | static void rtR0MemObjFixPageList(KernPageList_t *paPages, ULONG cPages, ULONG cPagesRet)
|
---|
530 | {
|
---|
531 | Assert(cPages >= cPagesRet);
|
---|
532 | if (cPages != cPagesRet)
|
---|
533 | {
|
---|
534 | ULONG iIn = cPagesRet;
|
---|
535 | ULONG iOut = cPages;
|
---|
536 | do
|
---|
537 | {
|
---|
538 | iIn--;
|
---|
539 | iOut--;
|
---|
540 | Assert(iIn <= iOut);
|
---|
541 |
|
---|
542 | KernPageList_t Page = paPages[iIn];
|
---|
543 | Assert(!(Page.Addr & PAGE_OFFSET_MASK));
|
---|
544 | Assert(Page.Size == RT_ALIGN_Z(Page.Size, PAGE_SIZE));
|
---|
545 |
|
---|
546 | if (Page.Size > PAGE_SIZE)
|
---|
547 | {
|
---|
548 | do
|
---|
549 | {
|
---|
550 | Page.Size -= PAGE_SIZE;
|
---|
551 | paPages[iOut].Addr = Page.Addr + Page.Size;
|
---|
552 | paPages[iOut].Size = PAGE_SIZE;
|
---|
553 | iOut--;
|
---|
554 | } while (Page.Size > PAGE_SIZE);
|
---|
555 | }
|
---|
556 |
|
---|
557 | paPages[iOut].Addr = Page.Addr;
|
---|
558 | paPages[iOut].Size = PAGE_SIZE;
|
---|
559 | } while ( iIn != iOut
|
---|
560 | && iIn > 0);
|
---|
561 | }
|
---|
562 | }
|
---|
563 |
|
---|