~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/r0drv/solaris/vbi/memobj-r0drv-solaris.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
/*******************************************************************************
33
33
*   Header Files                                                               *
34
34
*******************************************************************************/
35
 
#include "the-solaris-kernel.h"
36
 
 
 
35
#include "../the-solaris-kernel.h"
 
36
#include "internal/iprt.h"
37
37
#include <iprt/memobj.h>
38
 
#include <iprt/mem.h>
 
38
 
 
39
#include <iprt/assert.h>
39
40
#include <iprt/err.h>
40
 
#include <iprt/assert.h>
41
41
#include <iprt/log.h>
 
42
#include <iprt/mem.h>
42
43
#include <iprt/param.h>
43
44
#include <iprt/process.h>
44
45
#include "internal/memobj.h"
57
58
    /** Pointer to kernel memory cookie. */
58
59
    ddi_umem_cookie_t   Cookie;
59
60
    /** Shadow locked pages. */
60
 
    void              *handle;
 
61
    void               *pvHandle;
 
62
    /** Access during locking. */
 
63
    int                 fAccess;
61
64
} RTR0MEMOBJSOLARIS, *PRTR0MEMOBJSOLARIS;
62
65
 
63
66
 
81
84
            break;
82
85
 
83
86
        case RTR0MEMOBJTYPE_LOCK:
84
 
            vbi_unlock_va(pMemSolaris->Core.pv, pMemSolaris->Core.cb, pMemSolaris->handle);
 
87
            vbi_unlock_va(pMemSolaris->Core.pv, pMemSolaris->Core.cb, pMemSolaris->fAccess, pMemSolaris->pvHandle);
85
88
            break;
86
89
 
87
90
        case RTR0MEMOBJTYPE_MAPPING:
88
91
            vbi_unmap(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
89
92
            break;
90
93
 
 
94
        case RTR0MEMOBJTYPE_RES_VIRT:
 
95
        {
 
96
            if (pMemSolaris->Core.u.ResVirt.R0Process == NIL_RTR0PROCESS)
 
97
                vmem_xfree(heap_arena, pMemSolaris->Core.pv, pMemSolaris->Core.cb);
 
98
            else
 
99
                AssertFailed();
 
100
            break;
 
101
        }
 
102
 
91
103
        /* unused */
92
104
        case RTR0MEMOBJTYPE_PHYS:
93
 
        case RTR0MEMOBJTYPE_RES_VIRT:
94
105
        default:
95
106
            AssertMsgFailed(("enmType=%d\n", pMemSolaris->Core.enmType));
96
107
            return VERR_INTERNAL_ERROR;
115
126
    }
116
127
 
117
128
    pMemSolaris->Core.pv = virtAddr;
118
 
    pMemSolaris->handle = NULL;
 
129
    pMemSolaris->pvHandle = NULL;
119
130
    *ppMem = &pMemSolaris->Core;
120
131
    return VINF_SUCCESS;
121
132
}
140
151
        return VERR_NO_LOW_MEMORY;
141
152
    }
142
153
    pMemSolaris->Core.pv = virtAddr;
143
 
    pMemSolaris->handle = NULL;
 
154
    pMemSolaris->pvHandle = NULL;
144
155
    *ppMem = &pMemSolaris->Core;
145
156
    return VINF_SUCCESS;
146
157
}
167
178
    Assert(phys < (uint64_t)1 << 32);
168
179
    pMemSolaris->Core.pv = virtAddr;
169
180
    pMemSolaris->Core.u.Cont.Phys = phys;
170
 
    pMemSolaris->handle = NULL;
 
181
    pMemSolaris->pvHandle = NULL;
171
182
    *ppMem = &pMemSolaris->Core;
172
183
    return VINF_SUCCESS;
173
184
}
203
214
}
204
215
 
205
216
 
206
 
int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process)
 
217
int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
207
218
{
208
219
    AssertReturn(R0Process == RTR0ProcHandleSelf(), VERR_INVALID_PARAMETER);
 
220
    NOREF(fAccess);
209
221
 
210
222
    /* Create the locking object */
211
223
    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
212
224
    if (!pMemSolaris)
213
225
        return VERR_NO_MEMORY;
214
226
 
215
 
    void *ppl;
 
227
    int fPageAccess = S_READ;
 
228
    if (fAccess & RTMEM_PROT_WRITE)
 
229
        fPageAccess = S_WRITE;
 
230
    if (fAccess & RTMEM_PROT_EXEC)
 
231
        fPageAccess = S_EXEC;
 
232
    void *pvPageList = NULL;
216
233
 
217
234
    /* Lock down user pages */
218
 
    int rc = vbi_lock_va((caddr_t)R3Ptr, cb, &ppl);
 
235
    int rc = vbi_lock_va((caddr_t)R3Ptr, cb, fPageAccess, &pvPageList);
219
236
    if (rc != 0)
220
237
    {
221
238
        cmn_err(CE_NOTE,"rtR0MemObjNativeLockUser: vbi_lock_va failed rc=%d\n", rc);
 
239
        rtR0MemObjDelete(&pMemSolaris->Core);
222
240
        return VERR_LOCK_FAILED;
223
241
    }
224
242
 
225
243
    pMemSolaris->Core.u.Lock.R0Process = (RTR0PROCESS)vbi_proc();
226
 
    pMemSolaris->handle = ppl;
 
244
    pMemSolaris->pvHandle = pvPageList;
 
245
    pMemSolaris->fAccess = fPageAccess;
227
246
    *ppMem = &pMemSolaris->Core;
228
247
    return VINF_SUCCESS;
229
248
}
230
249
 
231
250
 
232
 
int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb)
 
251
int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
233
252
{
 
253
    NOREF(fAccess);
 
254
 
234
255
    PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, pv, cb);
235
256
    if (!pMemSolaris)
236
257
        return VERR_NO_MEMORY;
237
258
 
238
 
    void *ppl;
239
 
    int rc = vbi_lock_va((caddr_t)pv, cb, &ppl);
 
259
    int fPageAccess = S_READ;
 
260
    if (fAccess & RTMEM_PROT_WRITE)
 
261
        fPageAccess = S_WRITE;
 
262
    if (fAccess & RTMEM_PROT_EXEC)
 
263
        fPageAccess = S_EXEC;
 
264
    void *pvPageList = NULL;
 
265
    int rc = vbi_lock_va((caddr_t)pv, cb, fPageAccess, &pvPageList);
240
266
    if (rc != 0)
241
267
    {
242
268
        cmn_err(CE_NOTE,"rtR0MemObjNativeLockKernel: vbi_lock_va failed rc=%d\n", rc);
 
269
        rtR0MemObjDelete(&pMemSolaris->Core);
243
270
        return VERR_LOCK_FAILED;
244
271
    }
245
272
 
246
273
    pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
247
 
    pMemSolaris->handle = ppl;
 
274
    pMemSolaris->pvHandle = pvPageList;
 
275
    pMemSolaris->fAccess = fPageAccess;
248
276
    *ppMem = &pMemSolaris->Core;
249
277
    return VINF_SUCCESS;
250
278
}
252
280
 
253
281
int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
254
282
{
255
 
    return VERR_NOT_IMPLEMENTED;
 
283
    PRTR0MEMOBJSOLARIS  pMemSolaris;
 
284
    void               *pv;
 
285
 
 
286
    /*
 
287
     * Use xalloc.
 
288
     */
 
289
    pv = vmem_xalloc(heap_arena, cb, uAlignment, 0 /*phase*/, 0 /*nocross*/,
 
290
                     NULL /*minaddr*/, NULL /*maxaddr*/, VM_SLEEP);
 
291
    if (!pv)
 
292
        return VERR_NO_MEMORY;
 
293
    pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_RES_VIRT, pv, cb);
 
294
    if (!pMemSolaris)
 
295
    {
 
296
        vmem_xfree(heap_arena, pv, cb);
 
297
        return VERR_NO_MEMORY;
 
298
    }
 
299
 
 
300
    pMemSolaris->Core.u.ResVirt.R0Process = NIL_RTR0PROCESS;
 
301
    *ppMem = &pMemSolaris->Core;
 
302
    return VINF_SUCCESS;
256
303
}
257
304
 
258
305
 
264
311
int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
265
312
                              unsigned fProt, size_t offSub, size_t cbSub)
266
313
{
267
 
    /* @todo rtR0MemObjNativeMapKernel / Solaris - Should be fairly simple alloc kernel memory and memload it. */
 
314
    /** @todo rtR0MemObjNativeMapKernel / Solaris - Should be fairly simple alloc kernel memory and memload it. */
268
315
    return VERR_NOT_IMPLEMENTED;
269
316
}
270
317
 
 
318
 
271
319
int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
272
320
{
273
321
    AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
274
322
    AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
275
 
    AssertMsgReturn(uAlignment == 0 || uAlignment == PAGE_SIZE, ("%d\n", uAlignment), VERR_NOT_SUPPORTED);
 
323
    if (uAlignment > PAGE_SIZE)
 
324
        return VERR_NOT_SUPPORTED;
276
325
 
277
326
    PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap;
278
327
    size_t size = pMemToMapSolaris->Core.cb;
296
345
        {
297
346
            cmn_err(CE_NOTE, "rtR0MemObjNativeMapUser: no page to map.\n");
298
347
            rc = VERR_MAP_FAILED;
299
 
            goto done;
 
348
            goto l_done;
300
349
        }
301
350
        pv = (void *)((uintptr_t)pv + PAGE_SIZE);
302
351
    }
307
356
        cmn_err(CE_NOTE, "rtR0MemObjNativeMapUser: vbi failure.\n");
308
357
        rc = VERR_MAP_FAILED;
309
358
        rtR0MemObjDelete(&pMemSolaris->Core);
310
 
        goto done;
 
359
        goto l_done;
311
360
    }
312
361
    else
313
362
        rc = VINF_SUCCESS;
315
364
    pMemSolaris->Core.u.Mapping.R0Process = (RTR0PROCESS)vbi_proc();
316
365
    pMemSolaris->Core.pv = addr;
317
366
    *ppMem = &pMemSolaris->Core;
318
 
done:
 
367
l_done:
319
368
    kmem_free(paddrs, sizeof(uint64_t) * cPages);
320
369
    return rc;
321
370
}