VirtualBox

source: vbox/trunk/include/iprt/memobj.h@ 4697

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

CR/LF

  • Property eol-style set to native
File size: 11.0 KB
Line 
1/** @file
2 * innotek Portable Runtime - Memory Objects (Ring-0).
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef ___iprt_memobj_h
18#define ___iprt_memobj_h
19
20#include <iprt/cdefs.h>
21#include <iprt/types.h>
22
23__BEGIN_DECLS
24
25/** @defgroup grp_rt_memobj RTMemObj - Memory Object Manipulation (Ring-0)
26 * @ingroup grp_rt
27 * @{
28 */
29
30#ifdef IN_RING0
31
32/**
33 * Checks if this is mapping or not.
34 *
35 * @returns true if it's a mapping, otherwise false.
36 * @param MemObj The ring-0 memory object handle.
37 */
38RTR0DECL(bool) RTR0MemObjIsMapping(RTR0MEMOBJ MemObj);
39
40/**
41 * Gets the address of a ring-0 memory object.
42 *
43 * @returns The address of the memory object.
44 * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
45 * @param MemObj The ring-0 memory object handle.
46 */
47RTR0DECL(void *) RTR0MemObjAddress(RTR0MEMOBJ MemObj);
48
49/**
50 * Gets the ring-3 address of a ring-0 memory object.
51 *
52 * This only applies to ring-0 memory object with ring-3 mappings of some kind, i.e.
53 * locked user memory, reserved user address space and user mappings. This API should
54 * not be used on any other objects.
55 *
56 * @returns The address of the memory object.
57 * @returns NIL_RTR3PTR if the handle is invalid or if it's not an object with a ring-3 mapping.
58 * Strict builds will assert in both cases.
59 * @param MemObj The ring-0 memory object handle.
60 */
61RTR0DECL(RTR3PTR) RTR0MemObjAddressR3(RTR0MEMOBJ MemObj);
62
63/**
64 * Gets the size of a ring-0 memory object.
65 *
66 * @returns The address of the memory object.
67 * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
68 * @param MemObj The ring-0 memory object handle.
69 */
70RTR0DECL(size_t) RTR0MemObjSize(RTR0MEMOBJ MemObj);
71
72/**
73 * Get the physical address of an page in the memory object.
74 *
75 * @returns The physical address.
76 * @returns NIL_RTHCPHYS if the object doesn't contain fixed physical pages.
77 * @returns NIL_RTHCPHYS if the iPage is out of range.
78 * @returns NIL_RTHCPHYS if the object handle isn't valid.
79 * @param MemObj The ring-0 memory object handle.
80 * @param iPage The page number within the object.
81 */
82RTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, size_t iPage);
83
84/**
85 * Frees a ring-0 memory object.
86 *
87 * @returns IPRT status code.
88 * @retval VERR_INVALID_HANDLE if
89 * @param MemObj The ring-0 memory object to be freed. NULL is accepted.
90 * @param fFreeMappings Whether or not to free mappings of the object.
91 */
92RTR0DECL(int) RTR0MemObjFree(RTR0MEMOBJ MemObj, bool fFreeMappings);
93
94/**
95 * Allocates page aligned virtual kernel memory.
96 *
97 * The memory is taken from a non paged (= fixed physical memory backing) pool.
98 *
99 * @returns IPRT status code.
100 * @param pMemObj Where to store the ring-0 memory object handle.
101 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
102 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
103 */
104RTR0DECL(int) RTR0MemObjAllocPage(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
105
106/**
107 * Allocates page aligned virtual kernel memory with physical backing below 4GB.
108 *
109 * The physical memory backing the allocation is fixed.
110 *
111 * @returns IPRT status code.
112 * @param pMemObj Where to store the ring-0 memory object handle.
113 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
114 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
115 */
116RTR0DECL(int) RTR0MemObjAllocLow(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
117
118/**
119 * Allocates page aligned virtual kernel memory with contiguous physical backing below 4GB.
120 *
121 * The physical memory backing the allocation is fixed.
122 *
123 * @returns IPRT status code.
124 * @param pMemObj Where to store the ring-0 memory object handle.
125 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
126 * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
127 */
128RTR0DECL(int) RTR0MemObjAllocCont(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
129
130/**
131 * Locks a range of user virtual memory.
132 *
133 * @returns IPRT status code.
134 * @param pMemObj Where to store the ring-0 memory object handle.
135 * @param R3Ptr User virtual address. This is rounded down to a page boundrary.
136 * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary.
137 * @param R0Process The process to lock pages in. NIL_R0PROCESS is an alias for the current one.
138 *
139 * @remark RTR0MemGetAddressR3() and RTR0MemGetAddress() will return the rounded down address.
140 */
141RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process);
142
143/**
144 * Locks a range of kernel virtual memory.
145 *
146 * @returns IPRT status code.
147 * @param pMemObj Where to store the ring-0 memory object handle.
148 * @param pv Kernel virtual address. This is rounded down to a page boundrary.
149 * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary.
150 *
151 * @remark RTR0MemGetAddress() will return the rounded down address.
152 */
153RTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb);
154
155/**
156 * Allocates contiguous page aligned physical memory without (necessarily) any kernel mapping.
157 *
158 * @returns IPRT status code.
159 * @param pMemObj Where to store the ring-0 memory object handle.
160 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
161 * @param PhysHighest The highest permittable address (inclusive).
162 * Pass NIL_RTHCPHYS if any address is acceptable.
163 */
164RTR0DECL(int) RTR0MemObjAllocPhys(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest);
165
166/**
167 * Allocates non-contiguous page aligned physical memory without (necessarily) any kernel mapping.
168 *
169 * This API is for allocating huge amounts of pages and will return
170 * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
171 * manner.
172 *
173 * @returns IPRT status code.
174 * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
175 * physical memory on this platform. The caller should expect
176 * this error and have a fallback strategy for it.
177 * @param pMemObj Where to store the ring-0 memory object handle.
178 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
179 * @param PhysHighest The highest permittable address (inclusive).
180 * Pass NIL_RTHCPHYS if any address is acceptable.
181 */
182RTR0DECL(int) RTR0MemObjAllocPhysNC(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest);
183
184/**
185 * Creates a page aligned, contiguous, physical memory object.
186 *
187 * No physical memory is allocated, we trust you do know what you're doing.
188 *
189 * @returns IPRT status code.
190 * @param pMemObj Where to store the ring-0 memory object handle.
191 * @param Phys The physical address to start at. This is rounded down to the
192 * nearest page boundrary.
193 * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary.
194 */
195RTR0DECL(int) RTR0MemObjEnterPhys(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb);
196
197/**
198 * Reserves kernel virtual address space.
199 *
200 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
201 * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
202 * you have a safe physical address range to make use of...
203 *
204 * @returns IPRT status code.
205 * @param pMemObj Where to store the ring-0 memory object handle.
206 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
207 * @param cb The number of bytes to reserve. This is rounded up to nearest page.
208 * @param uAlignment The alignment of the reserved memory.
209 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
210 */
211RTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment);
212
213/**
214 * Reserves user virtual address space in the current process.
215 *
216 * @returns IPRT status code.
217 * @param pMemObj Where to store the ring-0 memory object handle.
218 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
219 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
220 * @param uAlignment The alignment of the reserved memory.
221 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
222 * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one.
223 */
224RTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process);
225
226/**
227 * Maps a memory object into kernel virtual address space.
228 *
229 * @returns IPRT status code.
230 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
231 * @param MemObjToMap The object to be map.
232 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
233 * @param uAlignment The alignment of the reserved memory.
234 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
235 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
236 */
237RTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt);
238
239/**
240 * Maps a memory object into user virtual address space in the current process.
241 *
242 * @returns IPRT status code.
243 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
244 * @param MemObjToMap The object to be map.
245 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
246 * @param uAlignment The alignment of the reserved memory.
247 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
248 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
249 * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
250 */
251RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process);
252
253#endif /* IN_RING0 */
254
255/** @} */
256
257__END_DECLS
258
259#endif
260
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