VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/haiku/alloc-r0drv-haiku.c@ 49846

Last change on this file since 49846 was 43403, checked in by vboxsync, 12 years ago

r0drv/haiku: cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: alloc-r0drv-haiku.c 43403 2012-09-22 11:48:24Z vboxsync $ */
2/** @file
3 * IPRT - Memory Allocation, Ring-0 Driver, Haiku.
4 */
5
6/*
7 * Copyright (C) 2012 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-haiku-kernel.h"
32#include "internal/iprt.h"
33#include <iprt/mem.h>
34#include <iprt/log.h>
35
36#include <iprt/assert.h>
37#include <iprt/err.h>
38#include <iprt/thread.h>
39#include "r0drv/alloc-r0drv.h"
40
41
42/**
43 * OS specific allocation function.
44 */
45int rtR0MemAllocEx(size_t cb, uint32_t fFlags, PRTMEMHDR *ppHdr)
46{
47 if (RT_UNLIKELY(fFlags & RTMEMHDR_FLAG_ANY_CTX))
48 return VERR_NOT_SUPPORTED;
49
50 PRTMEMHDR pHdr = (PRTMEMHDR)malloc(cb + sizeof(*pHdr));
51 if (RT_UNLIKELY(!pHdr))
52 {
53 LogRel(("rtR0MemAllocEx(%u, %#x) failed\n",(unsigned)cb + sizeof(*pHdr), fFlags));
54 return VERR_NO_MEMORY;
55 }
56
57 pHdr->u32Magic = RTMEMHDR_MAGIC;
58 pHdr->fFlags = fFlags;
59 pHdr->cb = cb;
60 pHdr->cbReq = cb;
61 *ppHdr = pHdr;
62 return VINF_SUCCESS;
63}
64
65
66/**
67 * OS specific free function.
68 */
69void rtR0MemFree(PRTMEMHDR pHdr)
70{
71 pHdr->u32Magic += 1;
72 free(pHdr);
73}
74
75
76RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb) RT_NO_THROW
77{
78 /*
79 * Validate input.
80 */
81 AssertPtr(pPhys);
82 Assert(cb > 0);
83 RT_ASSERT_PREEMPTIBLE();
84
85 /*
86 * Allocate the memory and ensure that the API is still providing
87 * memory that's always below 4GB.
88 */
89 cb = RT_ALIGN_Z(cb, PAGE_SIZE);
90 void *pv;
91 area_id area = create_area("VirtualBox Contig Alloc", &pv, B_ANY_KERNEL_ADDRESS, cb, B_32_BIT_CONTIGUOUS,
92 B_READ_AREA | B_WRITE_AREA);
93 if (area >= 0)
94 {
95 physical_entry physMap[2];
96 if (get_memory_map(pv, cb, physMap, 2)>= B_OK)
97 {
98 *pPhys = physMap[0].address;
99 return pv;
100 }
101 delete_area(area);
102 AssertMsgFailed(("Cannot get_memory_map for contig alloc! cb=%u\n",(unsigned)cb));
103 }
104 else
105 AssertMsgFailed(("Cannot create_area for contig alloc! cb=%u error=0x%08lx\n",(unsigned)cb, area));
106 return NULL;
107}
108
109
110RTR0DECL(void) RTMemContFree(void *pv, size_t cb) RT_NO_THROW
111{
112 RT_ASSERT_PREEMPTIBLE();
113 if (pv)
114 {
115 Assert(cb > 0);
116
117 area_id area = area_for(pv);
118 if (area >= B_OK)
119 delete_area(area);
120 else
121 AssertMsgFailed(("Cannot find area to delete! cb=%u error=0x%08lx\n",(unsigned)cb, area));
122 }
123}
124
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