VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/alloc-r0drv-solaris.c@ 5999

Last change on this file since 5999 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1/* $Id: alloc-r0drv-solaris.c 5999 2007-12-07 15:05:06Z 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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include "the-solaris-kernel.h"
32
33#include <iprt/alloc.h>
34#include <iprt/assert.h>
35#include <iprt/types.h>
36#include <iprt/param.h>
37#include "r0drv/alloc-r0drv.h"
38
39
40/**
41 * OS specific allocation function.
42 */
43PRTMEMHDR rtMemAlloc(size_t cb, uint32_t fFlags)
44{
45 Assert(cb != sizeof(void *));
46 PRTMEMHDR pHdr;
47#ifdef RT_ARCH_AMD64
48 if (fFlags & RTMEMHDR_FLAG_EXEC)
49 pHdr = (PRTMEMHDR)segkmem_alloc(heaptext_arena, RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE), KM_SLEEP);
50 else
51#endif
52 if (fFlags & RTMEMHDR_FLAG_ZEROED)
53 pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), KM_SLEEP);
54 else
55 pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), KM_SLEEP);
56 if (pHdr)
57 {
58 pHdr->u32Magic = RTMEMHDR_MAGIC;
59 pHdr->fFlags = fFlags;
60 pHdr->cb = cb;
61 pHdr->u32Padding= 0;
62 }
63 else
64 printf("rmMemAlloc(%#x, %#x) failed\n", cb + sizeof(*pHdr), fFlags);
65 return pHdr;
66}
67
68
69/**
70 * OS specific free function.
71 */
72void rtMemFree(PRTMEMHDR pHdr)
73{
74 pHdr->u32Magic += 1;
75#ifdef RT_ARCH_AMD64
76 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC)
77 segkmem_free(heaptext_arena, pHdr, RT_ALIGN_Z(pHdr->cb + sizeof(*pHdr), PAGE_SIZE));
78 else
79#endif
80 kmem_free(pHdr, pHdr->cb + sizeof(*pHdr));
81}
82
83
84/**
85 * Allocates physical contiguous memory (below 4GB).
86 * The allocation is page aligned and the content is undefined.
87 *
88 * @returns Pointer to the memory block. This is page aligned.
89 * @param pPhys Where to store the physical address.
90 * @param cb The allocation size in bytes. This is always
91 * rounded up to PAGE_SIZE.
92 */
93RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
94{
95 AssertPtr(pPhys);
96 Assert(cb > 0);
97
98 /* Allocate physically contiguous page-aligned memory. */
99 caddr_t virtAddr;
100 int rc = i_ddi_mem_alloc(NULL, &g_SolarisX86PhysMemLimits, cb, 1, 0, NULL, &virtAddr, NULL, NULL);
101 if (rc != DDI_SUCCESS)
102 return NULL;
103
104 *pPhys = PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr);
105 return virtAddr;
106}
107
108
109RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
110{
111 NOREF(cb);
112 if (pv)
113 i_ddi_mem_free(pv, NULL);
114}
115
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette