VirtualBox

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

最後變更 在這個檔案從32674是 32674,由 vboxsync 提交於 15 年 前

IPRT: started on some internal ring-0 alloc api.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.4 KB
 
1/* $Id: alloc-r0drv-solaris.c 32674 2010-09-21 16:51:50Z 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.alldomusa.eu.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
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_ALLOC_ANY_CTX ? 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 (pHdr)
68 {
69 pHdr->u32Magic = RTMEMHDR_MAGIC;
70 pHdr->fFlags = fFlags;
71 pHdr->cb = cbAllocated;
72 pHdr->cbReq = cb;
73 }
74 else
75 LogRel(("rtMemAlloc(%u, %#x) failed\n", (unsigned)cb + sizeof(*pHdr), fFlags));
76 return pHdr;
77}
78
79
80/**
81 * OS specific free function.
82 */
83void rtR0MemFree(PRTMEMHDR pHdr)
84{
85 pHdr->u32Magic += 1;
86#ifdef RT_ARCH_AMD64
87 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC)
88 vbi_text_free(pHdr, pHdr->cb + sizeof(*pHdr));
89 else
90#endif
91 kmem_free(pHdr, pHdr->cb + sizeof(*pHdr));
92}
93
94
95RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
96{
97 AssertPtrReturn(pPhys, NULL);
98 AssertReturn(cb > 0, NULL);
99 RT_ASSERT_PREEMPTIBLE();
100
101 /* Allocate physically contiguous (< 4GB) page-aligned memory. */
102 uint64_t physAddr = _4G -1;
103 caddr_t virtAddr = vbi_contig_alloc(&physAddr, cb);
104 if (virtAddr == NULL)
105 {
106 LogRel(("vbi_contig_alloc failed to allocate %u bytes\n", cb));
107 return NULL;
108 }
109
110 Assert(physAddr < _4G);
111 *pPhys = physAddr;
112 return virtAddr;
113}
114
115
116RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
117{
118 RT_ASSERT_PREEMPTIBLE();
119 if (pv)
120 vbi_contig_free(pv, cb);
121}
122
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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