VirtualBox

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

Last change on this file since 91688 was 91448, checked in by vboxsync, 3 years ago

IPRT/memobj: Adding RTR0MemObjAllocLarge for speeding up large page allocations. [doxygen fix] bugref:5324

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