VirtualBox

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

Last change on this file since 98110 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property eol-style set to native
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 38.1 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 * below 4GB (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 fExecutable Flag indicating whether it should be permitted to
291 * executed code in the memory object. The user must
292 * use RTR0MemObjProtect after initialization the
293 * allocation to actually make it executable.
294 */
295#define RTR0MemObjAllocCont(pMemObj, cb, fExecutable) \
296 RTR0MemObjAllocContTag((pMemObj), (cb), (fExecutable), RTMEM_TAG)
297
298/**
299 * Allocates page aligned virtual kernel memory with contiguous physical backing
300 * below 4GB (custom tag).
301 *
302 * The physical memory backing the allocation is fixed.
303 *
304 * @returns IPRT status code.
305 * @param pMemObj Where to store the ring-0 memory object handle.
306 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
307 * @param fExecutable Flag indicating whether it should be permitted to
308 * executed code in the memory object. The user must
309 * use RTR0MemObjProtect after initialization the
310 * allocation to actually make it executable.
311 * @param pszTag Allocation tag used for statistics and such.
312 */
313RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag);
314
315/**
316 * Locks a range of user virtual memory (default tag).
317 *
318 * @returns IPRT status code.
319 * @param pMemObj Where to store the ring-0 memory object handle.
320 * @param R3Ptr User virtual address. This is rounded down to a page
321 * boundary.
322 * @param cb Number of bytes to lock. This is rounded up to
323 * nearest page boundary.
324 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
325 * and RTMEM_PROT_WRITE.
326 * @param R0Process The process to lock pages in. NIL_RTR0PROCESS is an
327 * alias for the current one.
328 *
329 * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded
330 * down address.
331 *
332 * @remarks Linux: This API requires that the memory begin locked is in a memory
333 * mapping that is not required in any forked off child process. This
334 * is not intented as permanent restriction, feel free to help out
335 * lifting it.
336 */
337#define RTR0MemObjLockUser(pMemObj, R3Ptr, cb, fAccess, R0Process) \
338 RTR0MemObjLockUserTag((pMemObj), (R3Ptr), (cb), (fAccess), (R0Process), RTMEM_TAG)
339
340/**
341 * Locks a range of user virtual memory (custom tag).
342 *
343 * @returns IPRT status code.
344 * @param pMemObj Where to store the ring-0 memory object handle.
345 * @param R3Ptr User virtual address. This is rounded down to a page
346 * boundary.
347 * @param cb Number of bytes to lock. This is rounded up to
348 * nearest page boundary.
349 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
350 * and RTMEM_PROT_WRITE.
351 * @param R0Process The process to lock pages in. NIL_RTR0PROCESS is an
352 * alias for the current one.
353 * @param pszTag Allocation tag used for statistics and such.
354 *
355 * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded
356 * down address.
357 *
358 * @remarks Linux: This API requires that the memory begin locked is in a memory
359 * mapping that is not required in any forked off child process. This
360 * is not intented as permanent restriction, feel free to help out
361 * lifting it.
362 */
363RTR0DECL(int) RTR0MemObjLockUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess,
364 RTR0PROCESS R0Process, const char *pszTag);
365
366/**
367 * Locks a range of kernel virtual memory (default tag).
368 *
369 * @returns IPRT status code.
370 * @param pMemObj Where to store the ring-0 memory object handle.
371 * @param pv Kernel virtual address. This is rounded down to a page boundary.
372 * @param cb Number of bytes to lock. This is rounded up to nearest page boundary.
373 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
374 * and RTMEM_PROT_WRITE.
375 *
376 * @remark RTR0MemGetAddress() will return the rounded down address.
377 */
378#define RTR0MemObjLockKernel(pMemObj, pv, cb, fAccess) \
379 RTR0MemObjLockKernelTag((pMemObj), (pv), (cb), (fAccess), RTMEM_TAG)
380
381/**
382 * Locks a range of kernel virtual memory (custom tag).
383 *
384 * @returns IPRT status code.
385 * @param pMemObj Where to store the ring-0 memory object handle.
386 * @param pv Kernel virtual address. This is rounded down to a page boundary.
387 * @param cb Number of bytes to lock. This is rounded up to nearest page boundary.
388 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
389 * and RTMEM_PROT_WRITE.
390 * @param pszTag Allocation tag used for statistics and such.
391 *
392 * @remark RTR0MemGetAddress() will return the rounded down address.
393 */
394RTR0DECL(int) RTR0MemObjLockKernelTag(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess, const char *pszTag);
395
396/**
397 * Allocates contiguous page aligned physical memory without (necessarily) any
398 * kernel mapping (default tag).
399 *
400 * @returns IPRT status code.
401 * @param pMemObj Where to store the ring-0 memory object handle.
402 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
403 * @param PhysHighest The highest permitable address (inclusive).
404 * Pass NIL_RTHCPHYS if any address is acceptable.
405 */
406#define RTR0MemObjAllocPhys(pMemObj, cb, PhysHighest) \
407 RTR0MemObjAllocPhysTag((pMemObj), (cb), (PhysHighest), RTMEM_TAG)
408
409/**
410 * Allocates contiguous page aligned physical memory without (necessarily) any
411 * kernel mapping (custom tag).
412 *
413 * @returns IPRT status code.
414 * @param pMemObj Where to store the ring-0 memory object handle.
415 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
416 * @param PhysHighest The highest permitable address (inclusive).
417 * Pass NIL_RTHCPHYS if any address is acceptable.
418 * @param pszTag Allocation tag used for statistics and such.
419 */
420RTR0DECL(int) RTR0MemObjAllocPhysTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag);
421
422/**
423 * Allocates contiguous physical memory without (necessarily) any kernel mapping
424 * (default tag).
425 *
426 * @returns IPRT status code.
427 * @param pMemObj Where to store the ring-0 memory object handle.
428 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
429 * @param PhysHighest The highest permitable address (inclusive).
430 * Pass NIL_RTHCPHYS if any address is acceptable.
431 * @param uAlignment The alignment of the reserved memory.
432 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G.
433 */
434#define RTR0MemObjAllocPhysEx(pMemObj, cb, PhysHighest, uAlignment) \
435 RTR0MemObjAllocPhysExTag((pMemObj), (cb), (PhysHighest), (uAlignment), RTMEM_TAG)
436
437/**
438 * Allocates contiguous physical memory without (necessarily) any kernel mapping
439 * (custom tag).
440 *
441 * @returns IPRT status code.
442 * @param pMemObj Where to store the ring-0 memory object handle.
443 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
444 * @param PhysHighest The highest permitable address (inclusive).
445 * Pass NIL_RTHCPHYS if any address is acceptable.
446 * @param uAlignment The alignment of the reserved memory.
447 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G.
448 * @param pszTag Allocation tag used for statistics and such.
449 */
450RTR0DECL(int) RTR0MemObjAllocPhysExTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment, const char *pszTag);
451
452/**
453 * Allocates non-contiguous page aligned physical memory without (necessarily)
454 * any kernel mapping (default tag).
455 *
456 * This API is for allocating huge amounts of pages and will return
457 * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
458 * manner.
459 *
460 * @returns IPRT status code.
461 * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
462 * physical memory on this platform. The caller should expect
463 * this error and have a fallback strategy for it.
464 *
465 * @param pMemObj Where to store the ring-0 memory object handle.
466 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
467 * @param PhysHighest The highest permitable address (inclusive).
468 * Pass NIL_RTHCPHYS if any address is acceptable.
469 */
470#define RTR0MemObjAllocPhysNC(pMemObj, cb, PhysHighest) \
471 RTR0MemObjAllocPhysNCTag((pMemObj), (cb), (PhysHighest), RTMEM_TAG)
472
473/**
474 * Allocates non-contiguous page aligned physical memory without (necessarily)
475 * any kernel mapping (custom tag).
476 *
477 * This API is for allocating huge amounts of pages and will return
478 * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
479 * manner.
480 *
481 * @returns IPRT status code.
482 * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
483 * physical memory on this platform. The caller should expect
484 * this error and have a fallback strategy for it.
485 *
486 * @param pMemObj Where to store the ring-0 memory object handle.
487 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
488 * @param PhysHighest The highest permitable address (inclusive).
489 * Pass NIL_RTHCPHYS if any address is acceptable.
490 * @param pszTag Allocation tag used for statistics and such.
491 */
492RTR0DECL(int) RTR0MemObjAllocPhysNCTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag);
493
494/** Memory cache policy for RTR0MemObjEnterPhys.
495 * @{
496 */
497/** Default caching policy -- don't care. */
498#define RTMEM_CACHE_POLICY_DONT_CARE UINT32_C(0)
499/** MMIO caching policy -- uncachable. */
500#define RTMEM_CACHE_POLICY_MMIO UINT32_C(1)
501/** @} */
502
503/**
504 * Creates a page aligned, contiguous, physical memory object (default tag).
505 *
506 * No physical memory is allocated, we trust you do know what you're doing.
507 *
508 * @returns IPRT status code.
509 * @param pMemObj Where to store the ring-0 memory object handle.
510 * @param Phys The physical address to start at. This is rounded down to the
511 * nearest page boundary.
512 * @param cb The size of the object in bytes. This is rounded up to nearest page boundary.
513 * @param uCachePolicy One of the RTMEM_CACHE_XXX modes.
514 */
515#define RTR0MemObjEnterPhys(pMemObj, Phys, cb, uCachePolicy) \
516 RTR0MemObjEnterPhysTag((pMemObj), (Phys), (cb), (uCachePolicy), RTMEM_TAG)
517
518/**
519 * Creates a page aligned, contiguous, physical memory object (custom tag).
520 *
521 * No physical memory is allocated, we trust you do know what you're doing.
522 *
523 * @returns IPRT status code.
524 * @param pMemObj Where to store the ring-0 memory object handle.
525 * @param Phys The physical address to start at. This is rounded down to the
526 * nearest page boundary.
527 * @param cb The size of the object in bytes. This is rounded up to nearest page boundary.
528 * @param uCachePolicy One of the RTMEM_CACHE_XXX modes.
529 * @param pszTag Allocation tag used for statistics and such.
530 */
531RTR0DECL(int) RTR0MemObjEnterPhysTag(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy, const char *pszTag);
532
533/**
534 * Reserves kernel virtual address space (default tag).
535 *
536 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
537 * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
538 * you have a safe physical address range to make use of...
539 *
540 * @returns IPRT status code.
541 * @param pMemObj Where to store the ring-0 memory object handle.
542 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
543 * @param cb The number of bytes to reserve. This is rounded up to nearest page.
544 * @param uAlignment The alignment of the reserved memory.
545 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
546 */
547#define RTR0MemObjReserveKernel(pMemObj, pvFixed, cb, uAlignment) \
548 RTR0MemObjReserveKernelTag((pMemObj), (pvFixed), (cb), (uAlignment), RTMEM_TAG)
549
550/**
551 * Reserves kernel virtual address space (custom tag).
552 *
553 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
554 * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
555 * you have a safe physical address range to make use of...
556 *
557 * @returns IPRT status code.
558 * @param pMemObj Where to store the ring-0 memory object handle.
559 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
560 * @param cb The number of bytes to reserve. This is rounded up to nearest page.
561 * @param uAlignment The alignment of the reserved memory.
562 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
563 * @param pszTag Allocation tag used for statistics and such.
564 */
565RTR0DECL(int) RTR0MemObjReserveKernelTag(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment, const char *pszTag);
566
567/**
568 * Reserves user virtual address space in the current process (default tag).
569 *
570 * @returns IPRT status code.
571 * @param pMemObj Where to store the ring-0 memory object handle.
572 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
573 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
574 * @param uAlignment The alignment of the reserved memory.
575 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
576 * @param R0Process The process to reserve the memory in.
577 * NIL_RTR0PROCESS is an alias for the current one.
578 */
579#define RTR0MemObjReserveUser(pMemObj, R3PtrFixed, cb, uAlignment, R0Process) \
580 RTR0MemObjReserveUserTag((pMemObj), (R3PtrFixed), (cb), (uAlignment), (R0Process), RTMEM_TAG)
581
582/**
583 * Reserves user virtual address space in the current process (custom tag).
584 *
585 * @returns IPRT status code.
586 * @param pMemObj Where to store the ring-0 memory object handle.
587 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
588 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
589 * @param uAlignment The alignment of the reserved memory.
590 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
591 * @param R0Process The process to reserve the memory in.
592 * NIL_RTR0PROCESS is an alias for the current one.
593 * @param pszTag Allocation tag used for statistics and such.
594 */
595RTR0DECL(int) RTR0MemObjReserveUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment,
596 RTR0PROCESS R0Process, const char *pszTag);
597
598/**
599 * Maps a memory object into kernel virtual address space (default tag).
600 *
601 * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set
602 * to zero.
603 *
604 * @returns IPRT status code.
605 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
606 * @param MemObjToMap The object to be map.
607 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
608 * @param uAlignment The alignment of the reserved memory.
609 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
610 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
611 */
612#define RTR0MemObjMapKernel(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt) \
613 RTR0MemObjMapKernelTag((pMemObj), (MemObjToMap), (pvFixed), (uAlignment), (fProt), RTMEM_TAG)
614
615/**
616 * Maps a memory object into kernel virtual address space (custom tag).
617 *
618 * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set
619 * to zero.
620 *
621 * @returns IPRT status code.
622 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
623 * @param MemObjToMap The object to be map.
624 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
625 * @param uAlignment The alignment of the reserved memory.
626 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
627 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
628 * @param pszTag Allocation tag used for statistics and such.
629 */
630RTR0DECL(int) RTR0MemObjMapKernelTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed,
631 size_t uAlignment, unsigned fProt, const char *pszTag);
632
633/**
634 * Maps a memory object into kernel virtual address space (default tag).
635 *
636 * The ability to map subsections of the object into kernel space is currently
637 * not implemented on all platforms. All/Most of platforms supports mapping the
638 * whole object into kernel space.
639 *
640 * @returns IPRT status code.
641 * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
642 * memory object on this platform. When you hit this, try implement it.
643 *
644 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
645 * @param MemObjToMap The object to be map.
646 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
647 * @param uAlignment The alignment of the reserved memory.
648 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
649 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
650 * @param offSub Where in the object to start mapping. If non-zero
651 * the value must be page aligned and cbSub must be
652 * non-zero as well.
653 * @param cbSub The size of the part of the object to be mapped. If
654 * zero the entire object is mapped. The value must be
655 * page aligned.
656 */
657#define RTR0MemObjMapKernelEx(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt, offSub, cbSub) \
658 RTR0MemObjMapKernelExTag((pMemObj), (MemObjToMap), (pvFixed), (uAlignment), (fProt), (offSub), (cbSub), RTMEM_TAG)
659
660/**
661 * Maps a memory object into kernel virtual address space (custom tag).
662 *
663 * The ability to map subsections of the object into kernel space is currently
664 * not implemented on all platforms. All/Most of platforms supports mapping the
665 * whole object into kernel space.
666 *
667 * @returns IPRT status code.
668 * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
669 * memory object on this platform. When you hit this, try implement it.
670 *
671 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
672 * @param MemObjToMap The object to be map.
673 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
674 * @param uAlignment The alignment of the reserved memory.
675 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
676 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
677 * @param offSub Where in the object to start mapping. If non-zero
678 * the value must be page aligned and cbSub must be
679 * non-zero as well.
680 * @param cbSub The size of the part of the object to be mapped. If
681 * zero the entire object is mapped. The value must be
682 * page aligned.
683 * @param pszTag Allocation tag used for statistics and such.
684 */
685RTR0DECL(int) RTR0MemObjMapKernelExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment,
686 unsigned fProt, size_t offSub, size_t cbSub, const char *pszTag);
687
688/**
689 * Maps a memory object into user virtual address space in the current process
690 * (default tag).
691 *
692 * @returns IPRT status code.
693 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
694 * @param MemObjToMap The object to be map.
695 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
696 * @param uAlignment The alignment of the reserved memory.
697 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
698 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
699 * @param R0Process The process to map the memory into. NIL_RTR0PROCESS
700 * is an alias for the current one.
701 */
702#define RTR0MemObjMapUser(pMemObj, MemObjToMap, R3PtrFixed, uAlignment, fProt, R0Process) \
703 RTR0MemObjMapUserTag((pMemObj), (MemObjToMap), (R3PtrFixed), (uAlignment), (fProt), (R0Process), RTMEM_TAG)
704
705/**
706 * Maps a memory object into user virtual address space in the current process
707 * (custom tag).
708 *
709 * @returns IPRT status code.
710 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
711 * @param MemObjToMap The object to be map.
712 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
713 * @param uAlignment The alignment of the reserved memory.
714 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
715 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
716 * @param R0Process The process to map the memory into. NIL_RTR0PROCESS
717 * is an alias for the current one.
718 * @param pszTag Allocation tag used for statistics and such.
719 */
720RTR0DECL(int) RTR0MemObjMapUserTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed,
721 size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, const char *pszTag);
722
723/**
724 * Maps a memory object into user virtual address space in the current process
725 * (default tag).
726 *
727 * @returns IPRT status code.
728 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
729 * @param MemObjToMap The object to be map.
730 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
731 * @param uAlignment The alignment of the reserved memory.
732 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
733 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
734 * @param R0Process The process to map the memory into. NIL_RTR0PROCESS
735 * is an alias for the current one.
736 * @param offSub Where in the object to start mapping. If non-zero
737 * the value must be page aligned and cbSub must be
738 * non-zero as well.
739 * @param cbSub The size of the part of the object to be mapped. If
740 * zero the entire object is mapped. The value must be
741 * page aligned.
742 */
743#define RTR0MemObjMapUserEx(pMemObj, MemObjToMap, R3PtrFixed, uAlignment, fProt, R0Process, offSub, cbSub) \
744 RTR0MemObjMapUserExTag((pMemObj), (MemObjToMap), (R3PtrFixed), (uAlignment), (fProt), (R0Process), \
745 (offSub), (cbSub), RTMEM_TAG)
746
747/**
748 * Maps a memory object into user virtual address space in the current process
749 * (custom tag).
750 *
751 * @returns IPRT status code.
752 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
753 * @param MemObjToMap The object to be map.
754 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
755 * @param uAlignment The alignment of the reserved memory.
756 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
757 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
758 * @param R0Process The process to map the memory into. NIL_RTR0PROCESS
759 * is an alias for the current one.
760 * @param offSub Where in the object to start mapping. If non-zero
761 * the value must be page aligned and cbSub must be
762 * non-zero as well.
763 * @param cbSub The size of the part of the object to be mapped. If
764 * zero the entire object is mapped. The value must be
765 * page aligned.
766 * @param pszTag Allocation tag used for statistics and such.
767 */
768RTR0DECL(int) RTR0MemObjMapUserExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
769 unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub, const char *pszTag);
770
771/**
772 * Change the page level protection of one or more pages in a memory object.
773 *
774 * @returns IPRT status code.
775 * @retval VERR_NOT_SUPPORTED if the OS doesn't provide any way to manipulate
776 * page level protection. The caller must handle this status code
777 * gracefully. (Note that it may also occur if the implementation is
778 * missing, in which case just go ahead and implement it.)
779 *
780 * @param hMemObj Memory object handle.
781 * @param offSub Offset into the memory object. Must be page aligned.
782 * @param cbSub Number of bytes to change the protection of. Must be
783 * page aligned.
784 * @param fProt Combination of RTMEM_PROT_* flags.
785 */
786RTR0DECL(int) RTR0MemObjProtect(RTR0MEMOBJ hMemObj, size_t offSub, size_t cbSub, uint32_t fProt);
787
788#endif /* IN_RING0 */
789
790/** @} */
791
792RT_C_DECLS_END
793
794#endif /* !IPRT_INCLUDED_memobj_h */
795
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