VirtualBox

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

Last change on this file since 5325 was 5325, checked in by vboxsync, 17 years ago

use segkmem_alloc on 64-bit solaris because of gcc and its kernel code model.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/* $Id: alloc-r0drv-solaris.c 5325 2007-10-16 11:53:19Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Memory Allocation, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include "the-solaris-kernel.h"
23
24#include <iprt/alloc.h>
25#include <iprt/assert.h>
26#include <iprt/types.h>
27#include <iprt/param.h>
28#include "r0drv/alloc-r0drv.h"
29
30
31/**
32 * OS specific allocation function.
33 */
34PRTMEMHDR rtMemAlloc(size_t cb, uint32_t fFlags)
35{
36 Assert(cb != sizeof(void *));
37 PRTMEMHDR pHdr;
38#ifdef RT_ARCH_AMD64
39 if (fFlags & RTMEMHDR_FLAG_EXEC)
40 pHdr = (PRTMEMHDR)segkmem_alloc(heaptext_arena, cb + sizeof(*pHdr), KM_SLEEP);
41 else
42#endif
43 if (fFlags & RTMEMHDR_FLAG_ZEROED)
44 pHdr = (PRTMEMHDR)kmem_zalloc(cb + sizeof(*pHdr), KM_SLEEP);
45 else
46 pHdr = (PRTMEMHDR)kmem_alloc(cb + sizeof(*pHdr), KM_SLEEP);
47 if (pHdr)
48 {
49 pHdr->u32Magic = RTMEMHDR_MAGIC;
50 pHdr->fFlags = fFlags;
51 pHdr->cb = cb;
52 pHdr->u32Padding= 0;
53 }
54 else
55 printf("rmMemAlloc(%#x, %#x) failed\n", cb + sizeof(*pHdr), fFlags);
56 return pHdr;
57}
58
59
60/**
61 * OS specific free function.
62 */
63void rtMemFree(PRTMEMHDR pHdr)
64{
65 pHdr->u32Magic += 1;
66#ifdef RT_ARCH_AMD64
67 if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC)
68 segkmem_free(heaptext_arena, pHdr, pHdr->cb + sizeof(*pHdr));
69 else
70#endif
71 kmem_free(pHdr, pHdr->cb + sizeof(*pHdr));
72}
73
74
75/**
76 * Allocates physical contiguous memory (below 4GB).
77 * The allocation is page aligned and the content is undefined.
78 *
79 * @returns Pointer to the memory block. This is page aligned.
80 * @param pPhys Where to store the physical address.
81 * @param cb The allocation size in bytes. This is always
82 * rounded up to PAGE_SIZE.
83 */
84RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
85{
86 AssertPtr(pPhys);
87 Assert(cb > 0);
88
89 /* Allocate physically contiguous page-aligned memory. */
90 caddr_t virtAddr;
91 int rc = i_ddi_mem_alloc(NULL, &g_SolarisX86PhysMemLimits, cb, 1, 0, NULL, &virtAddr, NULL, NULL);
92 if (rc != DDI_SUCCESS)
93 return NULL;
94
95 *pPhys = PAGE_SIZE * hat_getpfnum(kas.a_hat, virtAddr);
96 return virtAddr;
97}
98
99
100RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
101{
102 NOREF(cb);
103 if (pv)
104 i_ddi_mem_free(pv, NULL);
105}
106
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