VirtualBox

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

Last change on this file since 24330 was 22073, checked in by vboxsync, 16 years ago

iprt/r0drv/solaris: context assertions (RT_MORE_STRICT).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: alloc-r0drv-solaris.c 22073 2009-08-07 15:26:56Z vboxsync $ */
2/** @file
3 * IPRT - Memory Allocation, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include "the-solaris-kernel.h"
36#include "internal/iprt.h"
37#include <iprt/mem.h>
38
39#include <iprt/assert.h>
40#include <iprt/param.h>
41#include <iprt/thread.h>
42#include "r0drv/alloc-r0drv.h"
43
44
45/**
46 * OS specific allocation function.
47 */
48PRTMEMHDR rtMemAlloc(size_t cb, uint32_t fFlags)
49{
50 size_t cbAllocated = cb;
51 PRTMEMHDR pHdr;
52#ifdef RT_ARCH_AMD64
53 if (fFlags & RTMEMHDR_FLAG_EXEC)
54 {
55 cbAllocated = RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE) - sizeof(*pHdr);
56 pHdr = (PRTMEMHDR)segkmem_alloc(heaptext_arena, cbAllocated + sizeof(*pHdr), KM_SLEEP);
57 }
58 else
59#endif
60 if (fFlags & RTMEMHDR_FLAG_ZEROED)
61 pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), KM_SLEEP);
62 else
63 pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), KM_SLEEP);
64 if (pHdr)
65 {
66 pHdr->u32Magic = RTMEMHDR_MAGIC;
67 pHdr->fFlags = fFlags;
68 pHdr->cb = cbAllocated;
69 pHdr->cbReq = cb;
70 }
71 else
72 printf("rtMemAlloc(%#x, %#x) failed\n", cb + sizeof(*pHdr), fFlags);
73 return pHdr;
74}
75
76
77/**
78 * OS specific free function.
79 */
80void rtMemFree(PRTMEMHDR pHdr)
81{
82 pHdr->u32Magic += 1;
83#ifdef RT_ARCH_AMD64
84 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC)
85 segkmem_free(heaptext_arena, pHdr, pHdr->cb + sizeof(*pHdr));
86 else
87#endif
88 kmem_free(pHdr, pHdr->cb + sizeof(*pHdr));
89}
90
91
92RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
93{
94 AssertPtr(pPhys);
95 Assert(cb > 0);
96 RT_ASSERT_PREEMPTIBLE();
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 RT_ASSERT_PREEMPTIBLE();
113 if (pv)
114 i_ddi_mem_free(pv, NULL);
115}
116
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