VirtualBox

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

Last change on this file since 32707 was 32707, checked in by vboxsync, 14 years ago

IPRT: Added RTMemAllocEx[Tag] and RTMemFreeEx, only implemented in ring-0 only.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: alloc-r0drv-solaris.c 32707 2010-09-23 10:15:08Z vboxsync $ */
2/** @file
3 * IPRT - Memory Allocation, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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#include "internal/iprt.h"
33#include <iprt/mem.h>
34
35#include <iprt/assert.h>
36#include <iprt/log.h>
37#include <iprt/param.h>
38#include <iprt/thread.h>
39#include "r0drv/alloc-r0drv.h"
40
41
42
43/**
44 * OS specific allocation function.
45 */
46int rtR0MemAllocEx(size_t cb, uint32_t fFlags, PRTMEMHDR *ppHdr)
47{
48 size_t cbAllocated = cb;
49 PRTMEMHDR pHdr;
50
51#ifdef RT_ARCH_AMD64
52 if (fFlags & RTMEMHDR_FLAG_EXEC)
53 {
54 AssertReturn(!(fFlags & RTMEMHDR_FLAG_ANY_CTX), NULL);
55 cbAllocated = RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE) - sizeof(*pHdr);
56 pHdr = (PRTMEMHDR)vbi_text_alloc(cbAllocated + sizeof(*pHdr));
57 }
58 else
59#endif
60 {
61 unsigned fKmFlags = fFlags & RTMEMHDR_FLAG_ANY_CTX_ALLOC ? KM_NOSLEEP : KM_SLEEP;
62 if (fFlags & RTMEMHDR_FLAG_ZEROED)
63 pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), fKmFlags);
64 else
65 pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), fKmFlags);
66 }
67 if (RT_UNLIKELY(!pHdr))
68 {
69 LogRel(("rtMemAllocEx(%u, %#x) failed\n", (unsigned)cb + sizeof(*pHdr), fFlags));
70 return VERR_NO_MEMORY;
71 }
72
73 pHdr->u32Magic = RTMEMHDR_MAGIC;
74 pHdr->fFlags = fFlags;
75 pHdr->cb = cbAllocated;
76 pHdr->cbReq = cb;
77
78 *ppHdr = pHdr;
79 return VINF_SUCCESS;
80}
81
82
83/**
84 * OS specific free function.
85 */
86void rtR0MemFree(PRTMEMHDR pHdr)
87{
88 pHdr->u32Magic += 1;
89#ifdef RT_ARCH_AMD64
90 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC)
91 vbi_text_free(pHdr, pHdr->cb + sizeof(*pHdr));
92 else
93#endif
94 kmem_free(pHdr, pHdr->cb + sizeof(*pHdr));
95}
96
97
98RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
99{
100 AssertPtrReturn(pPhys, NULL);
101 AssertReturn(cb > 0, NULL);
102 RT_ASSERT_PREEMPTIBLE();
103
104 /* Allocate physically contiguous (< 4GB) page-aligned memory. */
105 uint64_t physAddr = _4G -1;
106 caddr_t virtAddr = vbi_contig_alloc(&physAddr, cb);
107 if (virtAddr == NULL)
108 {
109 LogRel(("vbi_contig_alloc failed to allocate %u bytes\n", cb));
110 return NULL;
111 }
112
113 Assert(physAddr < _4G);
114 *pPhys = physAddr;
115 return virtAddr;
116}
117
118
119RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
120{
121 RT_ASSERT_PREEMPTIBLE();
122 if (pv)
123 vbi_contig_free(pv, cb);
124}
125
Note: See TracBrowser for help on using the repository browser.

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