VirtualBox

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

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

Solaris/R0drv: temporary failure case logging in contig alloc.

  • 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 26643 2010-02-19 10:17:48Z 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/**
47 * OS specific allocation function.
48 */
49PRTMEMHDR rtMemAlloc(size_t cb, uint32_t fFlags)
50{
51 size_t cbAllocated = cb;
52 PRTMEMHDR pHdr;
53#ifdef RT_ARCH_AMD64
54 if (fFlags & RTMEMHDR_FLAG_EXEC)
55 {
56 cbAllocated = RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE) - sizeof(*pHdr);
57 pHdr = (PRTMEMHDR)vbi_text_alloc(cbAllocated + sizeof(*pHdr));
58 }
59 else
60#endif
61 if (fFlags & RTMEMHDR_FLAG_ZEROED)
62 pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), KM_SLEEP);
63 else
64 pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), KM_SLEEP);
65 if (pHdr)
66 {
67 pHdr->u32Magic = RTMEMHDR_MAGIC;
68 pHdr->fFlags = fFlags;
69 pHdr->cb = cbAllocated;
70 pHdr->cbReq = cb;
71 }
72 else
73 cmn_err(CE_NOTE, "rtMemAlloc(%ld, %x) failed\n", cb + sizeof(*pHdr), fFlags);
74 return pHdr;
75}
76
77
78/**
79 * OS specific free function.
80 */
81void rtMemFree(PRTMEMHDR pHdr)
82{
83 pHdr->u32Magic += 1;
84#ifdef RT_ARCH_AMD64
85 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC)
86 vbi_text_free(pHdr, pHdr->cb + sizeof(*pHdr));
87 else
88#endif
89 kmem_free(pHdr, pHdr->cb + sizeof(*pHdr));
90}
91
92
93RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
94{
95 AssertPtr(pPhys);
96 Assert(cb > 0);
97 RT_ASSERT_PREEMPTIBLE();
98
99 /* Allocate physically contiguous page-aligned memory. */
100 caddr_t virtAddr;
101 uint64_t phys = (unsigned)0xffffffff; /* insist on below 4Gig */
102
103 virtAddr = vbi_contig_alloc(&phys, cb);
104 if (virtAddr == NULL)
105 {
106 cmn_err("vbi_contig_alloc for %u failed\n", cb);
107 return NULL;
108 }
109
110 Assert(phys < (uint64_t)1 << 32);
111
112 *pPhys = phys;
113 return virtAddr;
114}
115
116
117RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
118{
119 RT_ASSERT_PREEMPTIBLE();
120 if (pv)
121 vbi_contig_free(pv, cb);
122}
123
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