VirtualBox

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

Last change on this file since 103224 was 100358, checked in by vboxsync, 15 months ago

Runtime/RTR0MemObj*: Add PhysHighest parameter to RTR0MemObjAllocCont to indicate the maximum allowed physical address for an allocation, bugref:10457 [typo]

  • Property eol-style set to native
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 38.4 KB
Line 
1/** @file
2 * IPRT - Memory Objects (Ring-0).
3 */
4
5/*
6 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_memobj_h
37#define IPRT_INCLUDED_memobj_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/cdefs.h>
43#include <iprt/types.h>
44
45RT_C_DECLS_BEGIN
46
47/** @defgroup grp_rt_memobj RTMemObj - Memory Object Manipulation (Ring-0)
48 * @ingroup grp_rt
49 * @{
50 */
51
52/** @def RTMEM_TAG
53 * The default allocation tag used by the RTMem allocation APIs.
54 *
55 * When not defined before the inclusion of iprt/memobj.h or iprt/mem.h, this
56 * will default to the pointer to the current file name. The memory API will
57 * make of use of this as pointer to a volatile but read-only string.
58 */
59#ifndef RTMEM_TAG
60# define RTMEM_TAG (__FILE__)
61#endif
62
63#ifdef IN_RING0
64
65/**
66 * Checks if this is mapping or not.
67 *
68 * @returns true if it's a mapping, otherwise false.
69 * @param MemObj The ring-0 memory object handle.
70 */
71RTR0DECL(bool) RTR0MemObjIsMapping(RTR0MEMOBJ MemObj);
72
73/**
74 * Gets the address of a ring-0 memory object.
75 *
76 * @returns The address of the memory object.
77 * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
78 * @param MemObj The ring-0 memory object handle.
79 */
80RTR0DECL(void *) RTR0MemObjAddress(RTR0MEMOBJ MemObj);
81
82/**
83 * Gets the ring-3 address of a ring-0 memory object.
84 *
85 * This only applies to ring-0 memory object with ring-3 mappings of some kind, i.e.
86 * locked user memory, reserved user address space and user mappings. This API should
87 * not be used on any other objects.
88 *
89 * @returns The address of the memory object.
90 * @returns NIL_RTR3PTR if the handle is invalid or if it's not an object with a ring-3 mapping.
91 * Strict builds will assert in both cases.
92 * @param MemObj The ring-0 memory object handle.
93 */
94RTR0DECL(RTR3PTR) RTR0MemObjAddressR3(RTR0MEMOBJ MemObj);
95
96/**
97 * Gets the size of a ring-0 memory object.
98 *
99 * The returned value may differ from the one specified to the API creating the
100 * object because of alignment adjustments. The minimal alignment currently
101 * employed by any API is PAGE_SIZE, so the result can safely be shifted by
102 * PAGE_SHIFT to calculate a page count.
103 *
104 * @returns The object size.
105 * @returns 0 if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
106 * @param MemObj The ring-0 memory object handle.
107 */
108RTR0DECL(size_t) RTR0MemObjSize(RTR0MEMOBJ MemObj);
109
110/**
111 * Get the physical address of an page in the memory object.
112 *
113 * @returns The physical address.
114 * @returns NIL_RTHCPHYS if the object doesn't contain fixed physical pages.
115 * @returns NIL_RTHCPHYS if the iPage is out of range.
116 * @returns NIL_RTHCPHYS if the object handle isn't valid.
117 * @param MemObj The ring-0 memory object handle.
118 * @param iPage The page number within the object.
119 */
120RTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, size_t iPage);
121
122/**
123 * Checks whether the allocation was zero initialized or not.
124 *
125 * This only works on allocations. It is not meaningful for mappings, reserved
126 * memory and entered physical address, and will return false for these.
127 *
128 * @returns true if the allocation was initialized to zero at allocation time,
129 * false if not or query not meaningful to the object type.
130 * @param hMemObj The ring-0 memory object to be freed.
131 *
132 * @remarks It can be expected that memory allocated in the same fashion will
133 * have the same initialization state. So, if this returns true for
134 * one allocation it will return true for all other similarly made
135 * allocations.
136 */
137RTR0DECL(bool) RTR0MemObjWasZeroInitialized(RTR0MEMOBJ hMemObj);
138
139/**
140 * Frees a ring-0 memory object.
141 *
142 * @returns IPRT status code.
143 * @retval VERR_INVALID_HANDLE if
144 * @param MemObj The ring-0 memory object to be freed. NULL is accepted.
145 * @param fFreeMappings Whether or not to free mappings of the object.
146 */
147RTR0DECL(int) RTR0MemObjFree(RTR0MEMOBJ MemObj, bool fFreeMappings);
148
149/**
150 * Allocates page aligned virtual kernel memory (default tag).
151 *
152 * The memory is taken from a non paged (= fixed physical memory backing) pool.
153 *
154 * @returns IPRT status code.
155 * @param pMemObj Where to store the ring-0 memory object handle.
156 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
157 * @param fExecutable Flag indicating whether it should be permitted to
158 * executed code in the memory object. The user must
159 * use RTR0MemObjProtect after initialization the
160 * allocation to actually make it executable.
161 */
162#define RTR0MemObjAllocPage(pMemObj, cb, fExecutable) \
163 RTR0MemObjAllocPageTag((pMemObj), (cb), (fExecutable), RTMEM_TAG)
164
165/**
166 * Allocates page aligned virtual kernel memory (custom tag).
167 *
168 * The memory is taken from a non paged (= fixed physical memory backing) pool.
169 *
170 * @returns IPRT status code.
171 * @param pMemObj Where to store the ring-0 memory object handle.
172 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
173 * @param fExecutable Flag indicating whether it should be permitted to
174 * executed code in the memory object. The user must
175 * use RTR0MemObjProtect after initialization the
176 * allocation to actually make it executable.
177 * @param pszTag Allocation tag used for statistics and such.
178 */
179RTR0DECL(int) RTR0MemObjAllocPageTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag);
180
181/**
182 * Allocates large page aligned virtual kernel memory (default tag).
183 *
184 * Each large page in the allocation is backed by a contiguous chunk of physical
185 * memory aligned to the page size. The memory is taken from a non paged (=
186 * fixed physical memory backing) pool.
187 *
188 * On some hosts we only support allocating a single large page at a time, they
189 * will return VERR_NOT_SUPPORTED if @a cb is larger than @a cbLargePage.
190 *
191 * @returns IPRT status code.
192 * @retval VERR_TRY_AGAIN instead of VERR_NO_MEMORY when
193 * RTMEMOBJ_ALLOC_LARGE_F_FAST is set and supported.
194 * @param pMemObj Where to store the ring-0 memory object handle.
195 * @param cb Number of bytes to allocate. This is rounded up to
196 * nearest large page.
197 * @param cbLargePage The large page size. The allowed values varies from
198 * architecture to architecture and the paging mode
199 * used by the OS.
200 * @param fFlags Flags, RTMEMOBJ_ALLOC_LARGE_F_XXX.
201 *
202 * @note The implicit kernel mapping of this allocation does not necessarily
203 * have to be aligned on a @a cbLargePage boundrary.
204 */
205#define RTR0MemObjAllocLarge(pMemObj, cb, cbLargePage, fFlags) \
206 RTR0MemObjAllocLargeTag((pMemObj), (cb), (cbLargePage), (fFlags), RTMEM_TAG)
207
208/**
209 * Allocates large page aligned virtual kernel memory (custom tag).
210 *
211 * Each large page in the allocation is backed by a contiguous chunk of physical
212 * memory aligned to the page size. The memory is taken from a non paged (=
213 * fixed physical memory backing) pool.
214 *
215 * On some hosts we only support allocating a single large page at a time, they
216 * will return VERR_NOT_SUPPORTED if @a cb is larger than @a cbLargePage.
217 *
218 * @returns IPRT status code.
219 * @retval VERR_TRY_AGAIN instead of VERR_NO_MEMORY when
220 * RTMEMOBJ_ALLOC_LARGE_F_FAST is set and supported.
221 * @param pMemObj Where to store the ring-0 memory object handle.
222 * @param cb Number of bytes to allocate. This is rounded up to
223 * nearest large page.
224 * @param cbLargePage The large page size. The allowed values varies from
225 * architecture to architecture and the paging mode
226 * used by the OS.
227 * @param fFlags Flags, RTMEMOBJ_ALLOC_LARGE_F_XXX.
228 * @param pszTag Allocation tag used for statistics and such.
229 *
230 * @note The implicit kernel mapping of this allocation does not necessarily
231 * have to be aligned on a @a cbLargePage boundrary.
232 */
233RTR0DECL(int) RTR0MemObjAllocLargeTag(PRTR0MEMOBJ pMemObj, size_t cb, size_t cbLargePage, uint32_t fFlags, const char *pszTag);
234
235/** @name RTMEMOBJ_ALLOC_LARGE_F_XXX
236 * @{ */
237/** Indicates that it is okay to fail if there aren't enough large pages handy,
238 * cancelling any expensive search and reshuffling of memory (when supported).
239 * @note This flag can't be realized on all OSes. (Those who do support it
240 * will return VERR_TRY_AGAIN instead of VERR_NO_MEMORY if they
241 * cannot satisfy the request.) */
242#define RTMEMOBJ_ALLOC_LARGE_F_FAST RT_BIT_32(0)
243/** Mask with valid bits. */
244#define RTMEMOBJ_ALLOC_LARGE_F_VALID_MASK UINT32_C(0x00000001)
245/** @} */
246
247/**
248 * Allocates page aligned virtual kernel memory with physical backing below 4GB
249 * (default tag).
250 *
251 * The physical memory backing the allocation is fixed.
252 *
253 * @returns IPRT status code.
254 * @param pMemObj Where to store the ring-0 memory object handle.
255 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
256 * @param fExecutable Flag indicating whether it should be permitted to
257 * executed code in the memory object. The user must
258 * use RTR0MemObjProtect after initialization the
259 * allocation to actually make it executable.
260 */
261#define RTR0MemObjAllocLow(pMemObj, cb, fExecutable) \
262 RTR0MemObjAllocLowTag((pMemObj), (cb), (fExecutable), RTMEM_TAG)
263
264/**
265 * Allocates page aligned virtual kernel memory with physical backing below 4GB
266 * (custom tag).
267 *
268 * The physical memory backing the allocation is fixed.
269 *
270 * @returns IPRT status code.
271 * @param pMemObj Where to store the ring-0 memory object handle.
272 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
273 * @param fExecutable Flag indicating whether it should be permitted to
274 * executed code in the memory object. The user must
275 * use RTR0MemObjProtect after initialization the
276 * allocation to actually make it executable.
277 * @param pszTag Allocation tag used for statistics and such.
278 */
279RTR0DECL(int) RTR0MemObjAllocLowTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag);
280
281/**
282 * Allocates page aligned virtual kernel memory with contiguous physical backing
283 * (default tag).
284 *
285 * The physical memory backing the allocation is fixed.
286 *
287 * @returns IPRT status code.
288 * @param pMemObj Where to store the ring-0 memory object handle.
289 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
290 * @param PhysHighest The highest permitable address (inclusive).
291 * Pass NIL_RTHCPHYS if any address is acceptable.
292 * @param fExecutable Flag indicating whether it should be permitted to
293 * executed code in the memory object. The user must
294 * use RTR0MemObjProtect after initialization the
295 * allocation to actually make it executable.
296 */
297#define RTR0MemObjAllocCont(pMemObj, cb, PhysHighest, fExecutable) \
298 RTR0MemObjAllocContTag((pMemObj), (cb), (PhysHighest), (fExecutable), RTMEM_TAG)
299
300/**
301 * Allocates page aligned virtual kernel memory with contiguous physical
302 * backing (custom tag).
303 *
304 * The physical memory backing the allocation is fixed.
305 *
306 * @returns IPRT status code.
307 * @param pMemObj Where to store the ring-0 memory object handle.
308 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
309 * @param PhysHighest The highest permitable address (inclusive).
310 * Pass NIL_RTHCPHYS if any address is acceptable.
311 * @param fExecutable Flag indicating whether it should be permitted to
312 * executed code in the memory object. The user must
313 * use RTR0MemObjProtect after initialization the
314 * allocation to actually make it executable.
315 * @param pszTag Allocation tag used for statistics and such.
316 */
317RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, bool fExecutable, const char *pszTag);
318
319/**
320 * Locks a range of user virtual memory (default tag).
321 *
322 * @returns IPRT status code.
323 * @param pMemObj Where to store the ring-0 memory object handle.
324 * @param R3Ptr User virtual address. This is rounded down to a page
325 * boundary.
326 * @param cb Number of bytes to lock. This is rounded up to
327 * nearest page boundary.
328 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
329 * and RTMEM_PROT_WRITE.
330 * @param R0Process The process to lock pages in. NIL_RTR0PROCESS is an
331 * alias for the current one.
332 *
333 * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded
334 * down address.
335 *
336 * @remarks Linux: This API requires that the memory begin locked is in a memory
337 * mapping that is not required in any forked off child process. This
338 * is not intented as permanent restriction, feel free to help out
339 * lifting it.
340 */
341#define RTR0MemObjLockUser(pMemObj, R3Ptr, cb, fAccess, R0Process) \
342 RTR0MemObjLockUserTag((pMemObj), (R3Ptr), (cb), (fAccess), (R0Process), RTMEM_TAG)
343
344/**
345 * Locks a range of user virtual memory (custom tag).
346 *
347 * @returns IPRT status code.
348 * @param pMemObj Where to store the ring-0 memory object handle.
349 * @param R3Ptr User virtual address. This is rounded down to a page
350 * boundary.
351 * @param cb Number of bytes to lock. This is rounded up to
352 * nearest page boundary.
353 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
354 * and RTMEM_PROT_WRITE.
355 * @param R0Process The process to lock pages in. NIL_RTR0PROCESS is an
356 * alias for the current one.
357 * @param pszTag Allocation tag used for statistics and such.
358 *
359 * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded
360 * down address.
361 *
362 * @remarks Linux: This API requires that the memory begin locked is in a memory
363 * mapping that is not required in any forked off child process. This
364 * is not intented as permanent restriction, feel free to help out
365 * lifting it.
366 */
367RTR0DECL(int) RTR0MemObjLockUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess,
368 RTR0PROCESS R0Process, const char *pszTag);
369
370/**
371 * Locks a range of kernel virtual memory (default tag).
372 *
373 * @returns IPRT status code.
374 * @param pMemObj Where to store the ring-0 memory object handle.
375 * @param pv Kernel virtual address. This is rounded down to a page boundary.
376 * @param cb Number of bytes to lock. This is rounded up to nearest page boundary.
377 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
378 * and RTMEM_PROT_WRITE.
379 *
380 * @remark RTR0MemGetAddress() will return the rounded down address.
381 */
382#define RTR0MemObjLockKernel(pMemObj, pv, cb, fAccess) \
383 RTR0MemObjLockKernelTag((pMemObj), (pv), (cb), (fAccess), RTMEM_TAG)
384
385/**
386 * Locks a range of kernel virtual memory (custom tag).
387 *
388 * @returns IPRT status code.
389 * @param pMemObj Where to store the ring-0 memory object handle.
390 * @param pv Kernel virtual address. This is rounded down to a page boundary.
391 * @param cb Number of bytes to lock. This is rounded up to nearest page boundary.
392 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
393 * and RTMEM_PROT_WRITE.
394 * @param pszTag Allocation tag used for statistics and such.
395 *
396 * @remark RTR0MemGetAddress() will return the rounded down address.
397 */
398RTR0DECL(int) RTR0MemObjLockKernelTag(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess, const char *pszTag);
399
400/**
401 * Allocates contiguous page aligned physical memory without (necessarily) any
402 * kernel mapping (default tag).
403 *
404 * @returns IPRT status code.
405 * @param pMemObj Where to store the ring-0 memory object handle.
406 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
407 * @param PhysHighest The highest permitable address (inclusive).
408 * Pass NIL_RTHCPHYS if any address is acceptable.
409 */
410#define RTR0MemObjAllocPhys(pMemObj, cb, PhysHighest) \
411 RTR0MemObjAllocPhysTag((pMemObj), (cb), (PhysHighest), RTMEM_TAG)
412
413/**
414 * Allocates contiguous page aligned physical memory without (necessarily) any
415 * kernel mapping (custom tag).
416 *
417 * @returns IPRT status code.
418 * @param pMemObj Where to store the ring-0 memory object handle.
419 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
420 * @param PhysHighest The highest permitable address (inclusive).
421 * Pass NIL_RTHCPHYS if any address is acceptable.
422 * @param pszTag Allocation tag used for statistics and such.
423 */
424RTR0DECL(int) RTR0MemObjAllocPhysTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag);
425
426/**
427 * Allocates contiguous physical memory without (necessarily) any kernel mapping
428 * (default tag).
429 *
430 * @returns IPRT status code.
431 * @param pMemObj Where to store the ring-0 memory object handle.
432 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
433 * @param PhysHighest The highest permitable address (inclusive).
434 * Pass NIL_RTHCPHYS if any address is acceptable.
435 * @param uAlignment The alignment of the reserved memory.
436 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G.
437 */
438#define RTR0MemObjAllocPhysEx(pMemObj, cb, PhysHighest, uAlignment) \
439 RTR0MemObjAllocPhysExTag((pMemObj), (cb), (PhysHighest), (uAlignment), RTMEM_TAG)
440
441/**
442 * Allocates contiguous physical memory without (necessarily) any kernel mapping
443 * (custom tag).
444 *
445 * @returns IPRT status code.
446 * @param pMemObj Where to store the ring-0 memory object handle.
447 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
448 * @param PhysHighest The highest permitable address (inclusive).
449 * Pass NIL_RTHCPHYS if any address is acceptable.
450 * @param uAlignment The alignment of the reserved memory.
451 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G.
452 * @param pszTag Allocation tag used for statistics and such.
453 */
454RTR0DECL(int) RTR0MemObjAllocPhysExTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment, const char *pszTag);
455
456/**
457 * Allocates non-contiguous page aligned physical memory without (necessarily)
458 * any kernel mapping (default tag).
459 *
460 * This API is for allocating huge amounts of pages and will return
461 * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
462 * manner.
463 *
464 * @returns IPRT status code.
465 * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
466 * physical memory on this platform. The caller should expect
467 * this error and have a fallback strategy for it.
468 *
469 * @param pMemObj Where to store the ring-0 memory object handle.
470 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
471 * @param PhysHighest The highest permitable address (inclusive).
472 * Pass NIL_RTHCPHYS if any address is acceptable.
473 */
474#define RTR0MemObjAllocPhysNC(pMemObj, cb, PhysHighest) \
475 RTR0MemObjAllocPhysNCTag((pMemObj), (cb), (PhysHighest), RTMEM_TAG)
476
477/**
478 * Allocates non-contiguous page aligned physical memory without (necessarily)
479 * any kernel mapping (custom tag).
480 *
481 * This API is for allocating huge amounts of pages and will return
482 * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
483 * manner.
484 *
485 * @returns IPRT status code.
486 * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
487 * physical memory on this platform. The caller should expect
488 * this error and have a fallback strategy for it.
489 *
490 * @param pMemObj Where to store the ring-0 memory object handle.
491 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
492 * @param PhysHighest The highest permitable address (inclusive).
493 * Pass NIL_RTHCPHYS if any address is acceptable.
494 * @param pszTag Allocation tag used for statistics and such.
495 */
496RTR0DECL(int) RTR0MemObjAllocPhysNCTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag);
497
498/** Memory cache policy for RTR0MemObjEnterPhys.
499 * @{
500 */
501/** Default caching policy -- don't care. */
502#define RTMEM_CACHE_POLICY_DONT_CARE UINT32_C(0)
503/** MMIO caching policy -- uncachable. */
504#define RTMEM_CACHE_POLICY_MMIO UINT32_C(1)
505/** @} */
506
507/**
508 * Creates a page aligned, contiguous, physical memory object (default tag).
509 *
510 * No physical memory is allocated, we trust you do know what you're doing.
511 *
512 * @returns IPRT status code.
513 * @param pMemObj Where to store the ring-0 memory object handle.
514 * @param Phys The physical address to start at. This is rounded down to the
515 * nearest page boundary.
516 * @param cb The size of the object in bytes. This is rounded up to nearest page boundary.
517 * @param uCachePolicy One of the RTMEM_CACHE_XXX modes.
518 */
519#define RTR0MemObjEnterPhys(pMemObj, Phys, cb, uCachePolicy) \
520 RTR0MemObjEnterPhysTag((pMemObj), (Phys), (cb), (uCachePolicy), RTMEM_TAG)
521
522/**
523 * Creates a page aligned, contiguous, physical memory object (custom tag).
524 *
525 * No physical memory is allocated, we trust you do know what you're doing.
526 *
527 * @returns IPRT status code.
528 * @param pMemObj Where to store the ring-0 memory object handle.
529 * @param Phys The physical address to start at. This is rounded down to the
530 * nearest page boundary.
531 * @param cb The size of the object in bytes. This is rounded up to nearest page boundary.
532 * @param uCachePolicy One of the RTMEM_CACHE_XXX modes.
533 * @param pszTag Allocation tag used for statistics and such.
534 */
535RTR0DECL(int) RTR0MemObjEnterPhysTag(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy, const char *pszTag);
536
537/**
538 * Reserves kernel virtual address space (default tag).
539 *
540 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
541 * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
542 * you have a safe physical address range to make use of...
543 *
544 * @returns IPRT status code.
545 * @param pMemObj Where to store the ring-0 memory object handle.
546 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
547 * @param cb The number of bytes to reserve. This is rounded up to nearest page.
548 * @param uAlignment The alignment of the reserved memory.
549 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
550 */
551#define RTR0MemObjReserveKernel(pMemObj, pvFixed, cb, uAlignment) \
552 RTR0MemObjReserveKernelTag((pMemObj), (pvFixed), (cb), (uAlignment), RTMEM_TAG)
553
554/**
555 * Reserves kernel virtual address space (custom tag).
556 *
557 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
558 * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
559 * you have a safe physical address range to make use of...
560 *
561 * @returns IPRT status code.
562 * @param pMemObj Where to store the ring-0 memory object handle.
563 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
564 * @param cb The number of bytes to reserve. This is rounded up to nearest page.
565 * @param uAlignment The alignment of the reserved memory.
566 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
567 * @param pszTag Allocation tag used for statistics and such.
568 */
569RTR0DECL(int) RTR0MemObjReserveKernelTag(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment, const char *pszTag);
570
571/**
572 * Reserves user virtual address space in the current process (default tag).
573 *
574 * @returns IPRT status code.
575 * @param pMemObj Where to store the ring-0 memory object handle.
576 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
577 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
578 * @param uAlignment The alignment of the reserved memory.
579 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
580 * @param R0Process The process to reserve the memory in.
581 * NIL_RTR0PROCESS is an alias for the current one.
582 */
583#define RTR0MemObjReserveUser(pMemObj, R3PtrFixed, cb, uAlignment, R0Process) \
584 RTR0MemObjReserveUserTag((pMemObj), (R3PtrFixed), (cb), (uAlignment), (R0Process), RTMEM_TAG)
585
586/**
587 * Reserves user virtual address space in the current process (custom tag).
588 *
589 * @returns IPRT status code.
590 * @param pMemObj Where to store the ring-0 memory object handle.
591 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
592 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
593 * @param uAlignment The alignment of the reserved memory.
594 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
595 * @param R0Process The process to reserve the memory in.
596 * NIL_RTR0PROCESS is an alias for the current one.
597 * @param pszTag Allocation tag used for statistics and such.
598 */
599RTR0DECL(int) RTR0MemObjReserveUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment,
600 RTR0PROCESS R0Process, const char *pszTag);
601
602/**
603 * Maps a memory object into kernel virtual address space (default tag).
604 *
605 * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set
606 * to zero.
607 *
608 * @returns IPRT status code.
609 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
610 * @param MemObjToMap The object to be map.
611 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
612 * @param uAlignment The alignment of the reserved memory.
613 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
614 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
615 */
616#define RTR0MemObjMapKernel(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt) \
617 RTR0MemObjMapKernelTag((pMemObj), (MemObjToMap), (pvFixed), (uAlignment), (fProt), RTMEM_TAG)
618
619/**
620 * Maps a memory object into kernel virtual address space (custom tag).
621 *
622 * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set
623 * to zero.
624 *
625 * @returns IPRT status code.
626 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
627 * @param MemObjToMap The object to be map.
628 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
629 * @param uAlignment The alignment of the reserved memory.
630 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
631 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
632 * @param pszTag Allocation tag used for statistics and such.
633 */
634RTR0DECL(int) RTR0MemObjMapKernelTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed,
635 size_t uAlignment, unsigned fProt, const char *pszTag);
636
637/**
638 * Maps a memory object into kernel virtual address space (default tag).
639 *
640 * The ability to map subsections of the object into kernel space is currently
641 * not implemented on all platforms. All/Most of platforms supports mapping the
642 * whole object into kernel space.
643 *
644 * @returns IPRT status code.
645 * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
646 * memory object on this platform. When you hit this, try implement it.
647 *
648 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
649 * @param MemObjToMap The object to be map.
650 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
651 * @param uAlignment The alignment of the reserved memory.
652 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
653 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
654 * @param offSub Where in the object to start mapping. If non-zero
655 * the value must be page aligned and cbSub must be
656 * non-zero as well.
657 * @param cbSub The size of the part of the object to be mapped. If
658 * zero the entire object is mapped. The value must be
659 * page aligned.
660 */
661#define RTR0MemObjMapKernelEx(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt, offSub, cbSub) \
662 RTR0MemObjMapKernelExTag((pMemObj), (MemObjToMap), (pvFixed), (uAlignment), (fProt), (offSub), (cbSub), RTMEM_TAG)
663
664/**
665 * Maps a memory object into kernel virtual address space (custom tag).
666 *
667 * The ability to map subsections of the object into kernel space is currently
668 * not implemented on all platforms. All/Most of platforms supports mapping the
669 * whole object into kernel space.
670 *
671 * @returns IPRT status code.
672 * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
673 * memory object on this platform. When you hit this, try implement it.
674 *
675 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
676 * @param MemObjToMap The object to be map.
677 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
678 * @param uAlignment The alignment of the reserved memory.
679 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
680 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
681 * @param offSub Where in the object to start mapping. If non-zero
682 * the value must be page aligned and cbSub must be
683 * non-zero as well.
684 * @param cbSub The size of the part of the object to be mapped. If
685 * zero the entire object is mapped. The value must be
686 * page aligned.
687 * @param pszTag Allocation tag used for statistics and such.
688 */
689RTR0DECL(int) RTR0MemObjMapKernelExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment,
690 unsigned fProt, size_t offSub, size_t cbSub, const char *pszTag);
691
692/**
693 * Maps a memory object into user virtual address space in the current process
694 * (default tag).
695 *
696 * @returns IPRT status code.
697 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
698 * @param MemObjToMap The object to be map.
699 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
700 * @param uAlignment The alignment of the reserved memory.
701 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
702 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
703 * @param R0Process The process to map the memory into. NIL_RTR0PROCESS
704 * is an alias for the current one.
705 */
706#define RTR0MemObjMapUser(pMemObj, MemObjToMap, R3PtrFixed, uAlignment, fProt, R0Process) \
707 RTR0MemObjMapUserTag((pMemObj), (MemObjToMap), (R3PtrFixed), (uAlignment), (fProt), (R0Process), RTMEM_TAG)
708
709/**
710 * Maps a memory object into user virtual address space in the current process
711 * (custom tag).
712 *
713 * @returns IPRT status code.
714 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
715 * @param MemObjToMap The object to be map.
716 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
717 * @param uAlignment The alignment of the reserved memory.
718 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
719 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
720 * @param R0Process The process to map the memory into. NIL_RTR0PROCESS
721 * is an alias for the current one.
722 * @param pszTag Allocation tag used for statistics and such.
723 */
724RTR0DECL(int) RTR0MemObjMapUserTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed,
725 size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, const char *pszTag);
726
727/**
728 * Maps a memory object into user virtual address space in the current process
729 * (default tag).
730 *
731 * @returns IPRT status code.
732 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
733 * @param MemObjToMap The object to be map.
734 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
735 * @param uAlignment The alignment of the reserved memory.
736 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
737 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
738 * @param R0Process The process to map the memory into. NIL_RTR0PROCESS
739 * is an alias for the current one.
740 * @param offSub Where in the object to start mapping. If non-zero
741 * the value must be page aligned and cbSub must be
742 * non-zero as well.
743 * @param cbSub The size of the part of the object to be mapped. If
744 * zero the entire object is mapped. The value must be
745 * page aligned.
746 */
747#define RTR0MemObjMapUserEx(pMemObj, MemObjToMap, R3PtrFixed, uAlignment, fProt, R0Process, offSub, cbSub) \
748 RTR0MemObjMapUserExTag((pMemObj), (MemObjToMap), (R3PtrFixed), (uAlignment), (fProt), (R0Process), \
749 (offSub), (cbSub), RTMEM_TAG)
750
751/**
752 * Maps a memory object into user virtual address space in the current process
753 * (custom tag).
754 *
755 * @returns IPRT status code.
756 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
757 * @param MemObjToMap The object to be map.
758 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
759 * @param uAlignment The alignment of the reserved memory.
760 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
761 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
762 * @param R0Process The process to map the memory into. NIL_RTR0PROCESS
763 * is an alias for the current one.
764 * @param offSub Where in the object to start mapping. If non-zero
765 * the value must be page aligned and cbSub must be
766 * non-zero as well.
767 * @param cbSub The size of the part of the object to be mapped. If
768 * zero the entire object is mapped. The value must be
769 * page aligned.
770 * @param pszTag Allocation tag used for statistics and such.
771 */
772RTR0DECL(int) RTR0MemObjMapUserExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
773 unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub, const char *pszTag);
774
775/**
776 * Change the page level protection of one or more pages in a memory object.
777 *
778 * @returns IPRT status code.
779 * @retval VERR_NOT_SUPPORTED if the OS doesn't provide any way to manipulate
780 * page level protection. The caller must handle this status code
781 * gracefully. (Note that it may also occur if the implementation is
782 * missing, in which case just go ahead and implement it.)
783 *
784 * @param hMemObj Memory object handle.
785 * @param offSub Offset into the memory object. Must be page aligned.
786 * @param cbSub Number of bytes to change the protection of. Must be
787 * page aligned.
788 * @param fProt Combination of RTMEM_PROT_* flags.
789 */
790RTR0DECL(int) RTR0MemObjProtect(RTR0MEMOBJ hMemObj, size_t offSub, size_t cbSub, uint32_t fProt);
791
792#endif /* IN_RING0 */
793
794/** @} */
795
796RT_C_DECLS_END
797
798#endif /* !IPRT_INCLUDED_memobj_h */
799
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