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