VirtualBox

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

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

iprt,Config.kmk: Make sure the RTMemAllocVar* alignment gets poisoned by the electric fence. Some interface refactoring.

  • 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 28298 2010-04-14 12:20:39Z 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/log.h>
41#include <iprt/param.h>
42#include <iprt/thread.h>
43#include "r0drv/alloc-r0drv.h"
44
45
46
47/**
48 * OS specific allocation function.
49 */
50PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags)
51{
52 size_t cbAllocated = cb;
53 PRTMEMHDR pHdr;
54#ifdef RT_ARCH_AMD64
55 if (fFlags & RTMEMHDR_FLAG_EXEC)
56 {
57 cbAllocated = RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE) - sizeof(*pHdr);
58 pHdr = (PRTMEMHDR)vbi_text_alloc(cbAllocated + sizeof(*pHdr));
59 }
60 else
61#endif
62 if (fFlags & RTMEMHDR_FLAG_ZEROED)
63 pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), KM_SLEEP);
64 else
65 pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), KM_SLEEP);
66 if (pHdr)
67 {
68 pHdr->u32Magic = RTMEMHDR_MAGIC;
69 pHdr->fFlags = fFlags;
70 pHdr->cb = cbAllocated;
71 pHdr->cbReq = cb;
72 }
73 else
74 LogRel(("rtMemAlloc(%u, %#x) failed\n", (unsigned)cb + sizeof(*pHdr), fFlags));
75 return pHdr;
76}
77
78
79/**
80 * OS specific free function.
81 */
82void rtR0MemFree(PRTMEMHDR pHdr)
83{
84 pHdr->u32Magic += 1;
85#ifdef RT_ARCH_AMD64
86 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC)
87 vbi_text_free(pHdr, pHdr->cb + sizeof(*pHdr));
88 else
89#endif
90 kmem_free(pHdr, pHdr->cb + sizeof(*pHdr));
91}
92
93
94RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
95{
96 AssertPtrReturn(pPhys, NULL);
97 AssertReturn(cb > 0, NULL);
98 RT_ASSERT_PREEMPTIBLE();
99
100 /* Allocate physically contiguous (< 4GB) page-aligned memory. */
101 uint64_t physAddr = _4G -1;
102 caddr_t virtAddr = vbi_contig_alloc(&physAddr, cb);
103 if (virtAddr == NULL)
104 {
105 LogRel(("vbi_contig_alloc failed to allocate %u bytes\n", cb));
106 return NULL;
107 }
108
109 Assert(physAddr < _4G);
110 *pPhys = physAddr;
111 return virtAddr;
112}
113
114
115RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
116{
117 RT_ASSERT_PREEMPTIBLE();
118 if (pv)
119 vbi_contig_free(pv, cb);
120}
121
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