1 | /* $Id: alloc-r0drv-solaris.c 4178 2007-08-16 15:07:51Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime - Memory Allocation, Ring-0 Driver, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*******************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *******************************************************************************/
|
---|
22 | #include "the-solaris-kernel.h"
|
---|
23 | #include <malloc.h>
|
---|
24 |
|
---|
25 | #include <iprt/alloc.h>
|
---|
26 | #include <iprt/assert.h>
|
---|
27 | #include <iprt/types.h>
|
---|
28 | #include "r0drv/alloc-r0drv.h"
|
---|
29 |
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * OS specific allocation function.
|
---|
33 | */
|
---|
34 | PRTMEMHDR rtMemAlloc(size_t cb, uint32_t fFlags)
|
---|
35 | {
|
---|
36 | Assert(cb != sizeof(void *));
|
---|
37 | PRTMEMHDR pHdr;
|
---|
38 | if (fFlags & RTMEMHDR_FLAG_ZEROED)
|
---|
39 | pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), KM_SLEEP);
|
---|
40 | else
|
---|
41 | pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), KM_SLEEP);
|
---|
42 | if (pHdr)
|
---|
43 | {
|
---|
44 | pHdr->u32Magic = RTMEMHDR_MAGIC;
|
---|
45 | pHdr->fFlags = fFlags;
|
---|
46 | pHdr->cb = cb;
|
---|
47 | pHdr->u32Padding= 0;
|
---|
48 | }
|
---|
49 | else
|
---|
50 | printf("rmMemAlloc(%#x, %#x) failed\n", cb + sizeof(*pHdr), fFlags);
|
---|
51 | return pHdr;
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * OS specific free function.
|
---|
57 | */
|
---|
58 | void rtMemFree(PRTMEMHDR pHdr)
|
---|
59 | {
|
---|
60 | pHdr->u32Magic += 1;
|
---|
61 | kmem_free(pHdr, pHdr->cb + sizeof(*pHdr));
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Allocates physical contiguous memory (below 4GB).
|
---|
67 | * The allocation is page aligned and the content is undefined.
|
---|
68 | *
|
---|
69 | * @returns Pointer to the memory block. This is page aligned.
|
---|
70 | * @param pPhys Where to store the physical address.
|
---|
71 | * @param cb The allocation size in bytes. This is always
|
---|
72 | * rounded up to PAGE_SIZE.
|
---|
73 | */
|
---|
74 | RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
|
---|
75 | {
|
---|
76 | /** @todo: implement RTMemContAlloc in Solaris */
|
---|
77 | /* ddi_umem_alloc without PAGEABLE flag might produce contiguous physical memory, but
|
---|
78 | the documentation doesn't talk about contiguous at all :(
|
---|
79 | If we can use ddi_umem_alloc we need to keep track of the ddi_umem_cookie
|
---|
80 | which kernel allocates, but the ContFree() function only passes us back
|
---|
81 | the address. Maybe we could for each ContAlloc build a linked list of
|
---|
82 | structures that have the cookie and corresponding virtual address. */
|
---|
83 | return NULL;
|
---|
84 | }
|
---|
85 |
|
---|
86 | RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
|
---|
87 | {
|
---|
88 | /** @todo implement RTMemContFree on solaris, see RTMemContAlloc() for details. */
|
---|
89 | NOREF(pv);
|
---|
90 | NOREF(cb);
|
---|
91 | }
|
---|