VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/os2/alloc-r0drv-os2.cpp

Last change on this file was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.7 KB
Line 
1/* $Id: alloc-r0drv-os2.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * IPRT - Memory Allocation, Ring-0 Driver, OS/2.
4 */
5
6/*
7 * Contributed by knut st. osmundsen.
8 *
9 * Copyright (C) 2007-2024 Oracle and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.virtualbox.org.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * The contents of this file may alternatively be used under the terms
28 * of the Common Development and Distribution License Version 1.0
29 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
30 * in the VirtualBox distribution, in which case the provisions of the
31 * CDDL are applicable instead of those of the GPL.
32 *
33 * You may elect to license modified versions of this file under the
34 * terms and conditions of either the GPL or the CDDL or both.
35 *
36 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
37 * --------------------------------------------------------------------
38 *
39 * This code is based on:
40 *
41 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
42 *
43 * Permission is hereby granted, free of charge, to any person
44 * obtaining a copy of this software and associated documentation
45 * files (the "Software"), to deal in the Software without
46 * restriction, including without limitation the rights to use,
47 * copy, modify, merge, publish, distribute, sublicense, and/or sell
48 * copies of the Software, and to permit persons to whom the
49 * Software is furnished to do so, subject to the following
50 * conditions:
51 *
52 * The above copyright notice and this permission notice shall be
53 * included in all copies or substantial portions of the Software.
54 *
55 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
57 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
58 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
59 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
60 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
61 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
62 * OTHER DEALINGS IN THE SOFTWARE.
63 */
64
65
66/*********************************************************************************************************************************
67* Header Files *
68*********************************************************************************************************************************/
69#include "the-os2-kernel.h"
70#include "internal/iprt.h"
71#include <iprt/mem.h>
72
73#include <iprt/assert.h>
74#include <iprt/errcore.h>
75#include <iprt/param.h>
76#include "r0drv/alloc-r0drv.h" /** @todo drop the r0drv/alloc-r0drv.cpp stuff on OS/2? */
77
78
79DECLHIDDEN(int) rtR0MemAllocEx(size_t cb, uint32_t fFlags, PRTMEMHDR *ppHdr)
80{
81 if (fFlags & RTMEMHDR_FLAG_ANY_CTX)
82 return VERR_NOT_SUPPORTED;
83
84 void *pv = NULL;
85 APIRET rc = KernVMAlloc(cb + sizeof(RTMEMHDR), VMDHA_FIXED, &pv, (void **)-1, NULL);
86 if (RT_UNLIKELY(rc != NO_ERROR))
87 return RTErrConvertFromOS2(rc);
88
89 PRTMEMHDR pHdr = (PRTMEMHDR)pv;
90 pHdr->u32Magic = RTMEMHDR_MAGIC;
91 pHdr->fFlags = fFlags;
92 pHdr->cb = cb;
93 pHdr->cbReq = cb;
94 *ppHdr = pHdr;
95 return VINF_SUCCESS;
96}
97
98
99DECLHIDDEN(void) rtR0MemFree(PRTMEMHDR pHdr)
100{
101 pHdr->u32Magic += 1;
102 APIRET rc = KernVMFree(pHdr);
103 Assert(!rc); NOREF(rc);
104}
105
106
107RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
108{
109 /*
110 * Validate input.
111 */
112 AssertPtr(pPhys);
113 Assert(cb > 0);
114
115 /*
116 * All physical memory in OS/2 is below 4GB, so this should be kind of easy.
117 */
118 cb = RT_ALIGN_Z(cb, PAGE_SIZE); /* -> page aligned result. */
119 PVOID pv = NULL;
120 PVOID PhysAddr = (PVOID)~0UL;
121 APIRET rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pv, &PhysAddr, NULL);
122 if (!rc)
123 {
124 Assert(PhysAddr != (PVOID)~0UL);
125 Assert(!((uintptr_t)pv & PAGE_OFFSET_MASK));
126 *pPhys = (uintptr_t)PhysAddr;
127 return pv;
128 }
129 return NULL;
130}
131
132
133RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
134{
135 if (pv)
136 {
137 AssertMsg(!((uintptr_t)pv & PAGE_OFFSET_MASK), ("pv=%p\n", pv));
138 KernVMFree(pv);
139 }
140}
141
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