VirtualBox

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

Last change on this file since 29281 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: alloc-r0drv-solaris.c 28800 2010-04-27 08:22:32Z 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 */
46PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags)
47{
48 size_t cbAllocated = cb;
49 PRTMEMHDR pHdr;
50#ifdef RT_ARCH_AMD64
51 if (fFlags & RTMEMHDR_FLAG_EXEC)
52 {
53 cbAllocated = RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE) - sizeof(*pHdr);
54 pHdr = (PRTMEMHDR)vbi_text_alloc(cbAllocated + sizeof(*pHdr));
55 }
56 else
57#endif
58 if (fFlags & RTMEMHDR_FLAG_ZEROED)
59 pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), KM_SLEEP);
60 else
61 pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), KM_SLEEP);
62 if (pHdr)
63 {
64 pHdr->u32Magic = RTMEMHDR_MAGIC;
65 pHdr->fFlags = fFlags;
66 pHdr->cb = cbAllocated;
67 pHdr->cbReq = cb;
68 }
69 else
70 LogRel(("rtMemAlloc(%u, %#x) failed\n", (unsigned)cb + sizeof(*pHdr), fFlags));
71 return pHdr;
72}
73
74
75/**
76 * OS specific free function.
77 */
78void rtR0MemFree(PRTMEMHDR pHdr)
79{
80 pHdr->u32Magic += 1;
81#ifdef RT_ARCH_AMD64
82 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC)
83 vbi_text_free(pHdr, pHdr->cb + sizeof(*pHdr));
84 else
85#endif
86 kmem_free(pHdr, pHdr->cb + sizeof(*pHdr));
87}
88
89
90RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
91{
92 AssertPtrReturn(pPhys, NULL);
93 AssertReturn(cb > 0, NULL);
94 RT_ASSERT_PREEMPTIBLE();
95
96 /* Allocate physically contiguous (< 4GB) page-aligned memory. */
97 uint64_t physAddr = _4G -1;
98 caddr_t virtAddr = vbi_contig_alloc(&physAddr, cb);
99 if (virtAddr == NULL)
100 {
101 LogRel(("vbi_contig_alloc failed to allocate %u bytes\n", cb));
102 return NULL;
103 }
104
105 Assert(physAddr < _4G);
106 *pPhys = physAddr;
107 return virtAddr;
108}
109
110
111RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
112{
113 RT_ASSERT_PREEMPTIBLE();
114 if (pv)
115 vbi_contig_free(pv, cb);
116}
117
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