VirtualBox

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

Last change on this file since 90057 was 85504, checked in by vboxsync, 4 years ago

IPRT/memobj-r0drv*: Change the fExecutable flag to WX semantics where possible (linux 5.8+ only atm). Linux 5.8 adjustments. bugref:9801

  • Property eol-style set to native
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 33.6 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 page aligned virtual kernel memory with physical backing below 4GB
156 * (default tag).
157 *
158 * The physical memory backing the allocation is fixed.
159 *
160 * @returns IPRT status code.
161 * @param pMemObj Where to store the ring-0 memory object handle.
162 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
163 * @param fExecutable Flag indicating whether it should be permitted to
164 * executed code in the memory object. The user must
165 * use RTR0MemObjProtect after initialization the
166 * allocation to actually make it executable.
167 */
168#define RTR0MemObjAllocLow(pMemObj, cb, fExecutable) \
169 RTR0MemObjAllocLowTag((pMemObj), (cb), (fExecutable), RTMEM_TAG)
170
171/**
172 * Allocates page aligned virtual kernel memory with physical backing below 4GB
173 * (custom tag).
174 *
175 * The physical memory backing the allocation is fixed.
176 *
177 * @returns IPRT status code.
178 * @param pMemObj Where to store the ring-0 memory object handle.
179 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
180 * @param fExecutable Flag indicating whether it should be permitted to
181 * executed code in the memory object. The user must
182 * use RTR0MemObjProtect after initialization the
183 * allocation to actually make it executable.
184 * @param pszTag Allocation tag used for statistics and such.
185 */
186RTR0DECL(int) RTR0MemObjAllocLowTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag);
187
188/**
189 * Allocates page aligned virtual kernel memory with contiguous physical backing
190 * below 4GB (default tag).
191 *
192 * The physical memory backing the allocation is fixed.
193 *
194 * @returns IPRT status code.
195 * @param pMemObj Where to store the ring-0 memory object handle.
196 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
197 * @param fExecutable Flag indicating whether it should be permitted to
198 * executed code in the memory object. The user must
199 * use RTR0MemObjProtect after initialization the
200 * allocation to actually make it executable.
201 */
202#define RTR0MemObjAllocCont(pMemObj, cb, fExecutable) \
203 RTR0MemObjAllocContTag((pMemObj), (cb), (fExecutable), RTMEM_TAG)
204
205/**
206 * Allocates page aligned virtual kernel memory with contiguous physical backing
207 * below 4GB (custom tag).
208 *
209 * The physical memory backing the allocation is fixed.
210 *
211 * @returns IPRT status code.
212 * @param pMemObj Where to store the ring-0 memory object handle.
213 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
214 * @param fExecutable Flag indicating whether it should be permitted to
215 * executed code in the memory object. The user must
216 * use RTR0MemObjProtect after initialization the
217 * allocation to actually make it executable.
218 * @param pszTag Allocation tag used for statistics and such.
219 */
220RTR0DECL(int) RTR0MemObjAllocContTag(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable, const char *pszTag);
221
222/**
223 * Locks a range of user virtual memory (default tag).
224 *
225 * @returns IPRT status code.
226 * @param pMemObj Where to store the ring-0 memory object handle.
227 * @param R3Ptr User virtual address. This is rounded down to a page
228 * boundary.
229 * @param cb Number of bytes to lock. This is rounded up to
230 * nearest page boundary.
231 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
232 * and RTMEM_PROT_WRITE.
233 * @param R0Process The process to lock pages in. NIL_R0PROCESS is an
234 * alias for the current one.
235 *
236 * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded
237 * down address.
238 *
239 * @remarks Linux: This API requires that the memory begin locked is in a memory
240 * mapping that is not required in any forked off child process. This
241 * is not intented as permanent restriction, feel free to help out
242 * lifting it.
243 */
244#define RTR0MemObjLockUser(pMemObj, R3Ptr, cb, fAccess, R0Process) \
245 RTR0MemObjLockUserTag((pMemObj), (R3Ptr), (cb), (fAccess), (R0Process), RTMEM_TAG)
246
247/**
248 * Locks a range of user virtual memory (custom tag).
249 *
250 * @returns IPRT status code.
251 * @param pMemObj Where to store the ring-0 memory object handle.
252 * @param R3Ptr User virtual address. This is rounded down to a page
253 * boundary.
254 * @param cb Number of bytes to lock. This is rounded up to
255 * nearest page boundary.
256 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
257 * and RTMEM_PROT_WRITE.
258 * @param R0Process The process to lock pages in. NIL_R0PROCESS is an
259 * alias for the current one.
260 * @param pszTag Allocation tag used for statistics and such.
261 *
262 * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded
263 * down address.
264 *
265 * @remarks Linux: This API requires that the memory begin locked is in a memory
266 * mapping that is not required in any forked off child process. This
267 * is not intented as permanent restriction, feel free to help out
268 * lifting it.
269 */
270RTR0DECL(int) RTR0MemObjLockUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess,
271 RTR0PROCESS R0Process, const char *pszTag);
272
273/**
274 * Locks a range of kernel virtual memory (default tag).
275 *
276 * @returns IPRT status code.
277 * @param pMemObj Where to store the ring-0 memory object handle.
278 * @param pv Kernel virtual address. This is rounded down to a page boundary.
279 * @param cb Number of bytes to lock. This is rounded up to nearest page boundary.
280 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
281 * and RTMEM_PROT_WRITE.
282 *
283 * @remark RTR0MemGetAddress() will return the rounded down address.
284 */
285#define RTR0MemObjLockKernel(pMemObj, pv, cb, fAccess) \
286 RTR0MemObjLockKernelTag((pMemObj), (pv), (cb), (fAccess), RTMEM_TAG)
287
288/**
289 * Locks a range of kernel virtual memory (custom tag).
290 *
291 * @returns IPRT status code.
292 * @param pMemObj Where to store the ring-0 memory object handle.
293 * @param pv Kernel virtual address. This is rounded down to a page boundary.
294 * @param cb Number of bytes to lock. This is rounded up to nearest page boundary.
295 * @param fAccess The desired access, a combination of RTMEM_PROT_READ
296 * and RTMEM_PROT_WRITE.
297 * @param pszTag Allocation tag used for statistics and such.
298 *
299 * @remark RTR0MemGetAddress() will return the rounded down address.
300 */
301RTR0DECL(int) RTR0MemObjLockKernelTag(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess, const char *pszTag);
302
303/**
304 * Allocates contiguous page aligned physical memory without (necessarily) any
305 * kernel mapping (default tag).
306 *
307 * @returns IPRT status code.
308 * @param pMemObj Where to store the ring-0 memory object handle.
309 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
310 * @param PhysHighest The highest permitable address (inclusive).
311 * Pass NIL_RTHCPHYS if any address is acceptable.
312 */
313#define RTR0MemObjAllocPhys(pMemObj, cb, PhysHighest) \
314 RTR0MemObjAllocPhysTag((pMemObj), (cb), (PhysHighest), RTMEM_TAG)
315
316/**
317 * Allocates contiguous page aligned physical memory without (necessarily) any
318 * kernel mapping (custom tag).
319 *
320 * @returns IPRT status code.
321 * @param pMemObj Where to store the ring-0 memory object handle.
322 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
323 * @param PhysHighest The highest permitable address (inclusive).
324 * Pass NIL_RTHCPHYS if any address is acceptable.
325 * @param pszTag Allocation tag used for statistics and such.
326 */
327RTR0DECL(int) RTR0MemObjAllocPhysTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag);
328
329/**
330 * Allocates contiguous physical memory without (necessarily) any kernel mapping
331 * (default tag).
332 *
333 * @returns IPRT status code.
334 * @param pMemObj Where to store the ring-0 memory object handle.
335 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
336 * @param PhysHighest The highest permitable address (inclusive).
337 * Pass NIL_RTHCPHYS if any address is acceptable.
338 * @param uAlignment The alignment of the reserved memory.
339 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G.
340 */
341#define RTR0MemObjAllocPhysEx(pMemObj, cb, PhysHighest, uAlignment) \
342 RTR0MemObjAllocPhysExTag((pMemObj), (cb), (PhysHighest), (uAlignment), RTMEM_TAG)
343
344/**
345 * Allocates contiguous physical memory without (necessarily) any kernel mapping
346 * (custom tag).
347 *
348 * @returns IPRT status code.
349 * @param pMemObj Where to store the ring-0 memory object handle.
350 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
351 * @param PhysHighest The highest permitable address (inclusive).
352 * Pass NIL_RTHCPHYS if any address is acceptable.
353 * @param uAlignment The alignment of the reserved memory.
354 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G.
355 * @param pszTag Allocation tag used for statistics and such.
356 */
357RTR0DECL(int) RTR0MemObjAllocPhysExTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment, const char *pszTag);
358
359/**
360 * Allocates non-contiguous page aligned physical memory without (necessarily)
361 * any kernel mapping (default tag).
362 *
363 * This API is for allocating huge amounts of pages and will return
364 * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
365 * manner.
366 *
367 * @returns IPRT status code.
368 * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
369 * physical memory on this platform. The caller should expect
370 * this error and have a fallback strategy for it.
371 *
372 * @param pMemObj Where to store the ring-0 memory object handle.
373 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
374 * @param PhysHighest The highest permitable address (inclusive).
375 * Pass NIL_RTHCPHYS if any address is acceptable.
376 */
377#define RTR0MemObjAllocPhysNC(pMemObj, cb, PhysHighest) \
378 RTR0MemObjAllocPhysNCTag((pMemObj), (cb), (PhysHighest), RTMEM_TAG)
379
380/**
381 * Allocates non-contiguous page aligned physical memory without (necessarily)
382 * any kernel mapping (custom tag).
383 *
384 * This API is for allocating huge amounts of pages and will return
385 * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
386 * manner.
387 *
388 * @returns IPRT status code.
389 * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
390 * physical memory on this platform. The caller should expect
391 * this error and have a fallback strategy for it.
392 *
393 * @param pMemObj Where to store the ring-0 memory object handle.
394 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
395 * @param PhysHighest The highest permitable address (inclusive).
396 * Pass NIL_RTHCPHYS if any address is acceptable.
397 * @param pszTag Allocation tag used for statistics and such.
398 */
399RTR0DECL(int) RTR0MemObjAllocPhysNCTag(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, const char *pszTag);
400
401/** Memory cache policy for RTR0MemObjEnterPhys.
402 * @{
403 */
404/** Default caching policy -- don't care. */
405#define RTMEM_CACHE_POLICY_DONT_CARE UINT32_C(0)
406/** MMIO caching policy -- uncachable. */
407#define RTMEM_CACHE_POLICY_MMIO UINT32_C(1)
408/** @} */
409
410/**
411 * Creates a page aligned, contiguous, physical memory object (default tag).
412 *
413 * No physical memory is allocated, we trust you do know what you're doing.
414 *
415 * @returns IPRT status code.
416 * @param pMemObj Where to store the ring-0 memory object handle.
417 * @param Phys The physical address to start at. This is rounded down to the
418 * nearest page boundary.
419 * @param cb The size of the object in bytes. This is rounded up to nearest page boundary.
420 * @param uCachePolicy One of the RTMEM_CACHE_XXX modes.
421 */
422#define RTR0MemObjEnterPhys(pMemObj, Phys, cb, uCachePolicy) \
423 RTR0MemObjEnterPhysTag((pMemObj), (Phys), (cb), (uCachePolicy), RTMEM_TAG)
424
425/**
426 * Creates a page aligned, contiguous, physical memory object (custom tag).
427 *
428 * No physical memory is allocated, we trust you do know what you're doing.
429 *
430 * @returns IPRT status code.
431 * @param pMemObj Where to store the ring-0 memory object handle.
432 * @param Phys The physical address to start at. This is rounded down to the
433 * nearest page boundary.
434 * @param cb The size of the object in bytes. This is rounded up to nearest page boundary.
435 * @param uCachePolicy One of the RTMEM_CACHE_XXX modes.
436 * @param pszTag Allocation tag used for statistics and such.
437 */
438RTR0DECL(int) RTR0MemObjEnterPhysTag(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy, const char *pszTag);
439
440/**
441 * Reserves kernel virtual address space (default tag).
442 *
443 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
444 * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
445 * you have a safe physical address range to make use of...
446 *
447 * @returns IPRT status code.
448 * @param pMemObj Where to store the ring-0 memory object handle.
449 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
450 * @param cb The number of bytes to reserve. This is rounded up to nearest page.
451 * @param uAlignment The alignment of the reserved memory.
452 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
453 */
454#define RTR0MemObjReserveKernel(pMemObj, pvFixed, cb, uAlignment) \
455 RTR0MemObjReserveKernelTag((pMemObj), (pvFixed), (cb), (uAlignment), RTMEM_TAG)
456
457/**
458 * Reserves kernel virtual address space (custom tag).
459 *
460 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
461 * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
462 * you have a safe physical address range to make use of...
463 *
464 * @returns IPRT status code.
465 * @param pMemObj Where to store the ring-0 memory object handle.
466 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
467 * @param cb The number of bytes to reserve. This is rounded up to nearest page.
468 * @param uAlignment The alignment of the reserved memory.
469 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
470 * @param pszTag Allocation tag used for statistics and such.
471 */
472RTR0DECL(int) RTR0MemObjReserveKernelTag(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment, const char *pszTag);
473
474/**
475 * Reserves user virtual address space in the current process (default tag).
476 *
477 * @returns IPRT status code.
478 * @param pMemObj Where to store the ring-0 memory object handle.
479 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
480 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
481 * @param uAlignment The alignment of the reserved memory.
482 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
483 * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one.
484 */
485#define RTR0MemObjReserveUser(pMemObj, R3PtrFixed, cb, uAlignment, R0Process) \
486 RTR0MemObjReserveUserTag((pMemObj), (R3PtrFixed), (cb), (uAlignment), (R0Process), RTMEM_TAG)
487
488/**
489 * Reserves user virtual address space in the current process (custom tag).
490 *
491 * @returns IPRT status code.
492 * @param pMemObj Where to store the ring-0 memory object handle.
493 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
494 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
495 * @param uAlignment The alignment of the reserved memory.
496 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
497 * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one.
498 * @param pszTag Allocation tag used for statistics and such.
499 */
500RTR0DECL(int) RTR0MemObjReserveUserTag(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment,
501 RTR0PROCESS R0Process, const char *pszTag);
502
503/**
504 * Maps a memory object into kernel virtual address space (default tag).
505 *
506 * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set
507 * to zero.
508 *
509 * @returns IPRT status code.
510 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
511 * @param MemObjToMap The object to be map.
512 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
513 * @param uAlignment The alignment of the reserved memory.
514 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
515 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
516 */
517#define RTR0MemObjMapKernel(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt) \
518 RTR0MemObjMapKernelTag((pMemObj), (MemObjToMap), (pvFixed), (uAlignment), (fProt), RTMEM_TAG)
519
520/**
521 * Maps a memory object into kernel virtual address space (custom tag).
522 *
523 * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set
524 * to zero.
525 *
526 * @returns IPRT status code.
527 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
528 * @param MemObjToMap The object to be map.
529 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
530 * @param uAlignment The alignment of the reserved memory.
531 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
532 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
533 * @param pszTag Allocation tag used for statistics and such.
534 */
535RTR0DECL(int) RTR0MemObjMapKernelTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed,
536 size_t uAlignment, unsigned fProt, const char *pszTag);
537
538/**
539 * Maps a memory object into kernel virtual address space (default tag).
540 *
541 * The ability to map subsections of the object into kernel space is currently
542 * not implemented on all platforms. All/Most of platforms supports mapping the
543 * whole object into kernel space.
544 *
545 * @returns IPRT status code.
546 * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
547 * memory object on this platform. When you hit this, try implement it.
548 *
549 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
550 * @param MemObjToMap The object to be map.
551 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
552 * @param uAlignment The alignment of the reserved memory.
553 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
554 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
555 * @param offSub Where in the object to start mapping. If non-zero
556 * the value must be page aligned and cbSub must be
557 * non-zero as well.
558 * @param cbSub The size of the part of the object to be mapped. If
559 * zero the entire object is mapped. The value must be
560 * page aligned.
561 */
562#define RTR0MemObjMapKernelEx(pMemObj, MemObjToMap, pvFixed, uAlignment, fProt, offSub, cbSub) \
563 RTR0MemObjMapKernelExTag((pMemObj), (MemObjToMap), (pvFixed), (uAlignment), (fProt), (offSub), (cbSub), RTMEM_TAG)
564
565/**
566 * Maps a memory object into kernel virtual address space (custom tag).
567 *
568 * The ability to map subsections of the object into kernel space is currently
569 * not implemented on all platforms. All/Most of platforms supports mapping the
570 * whole object into kernel space.
571 *
572 * @returns IPRT status code.
573 * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
574 * memory object on this platform. When you hit this, try implement it.
575 *
576 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
577 * @param MemObjToMap The object to be map.
578 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
579 * @param uAlignment The alignment of the reserved memory.
580 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
581 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
582 * @param offSub Where in the object to start mapping. If non-zero
583 * the value must be page aligned and cbSub must be
584 * non-zero as well.
585 * @param cbSub The size of the part of the object to be mapped. If
586 * zero the entire object is mapped. The value must be
587 * page aligned.
588 * @param pszTag Allocation tag used for statistics and such.
589 */
590RTR0DECL(int) RTR0MemObjMapKernelExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment,
591 unsigned fProt, size_t offSub, size_t cbSub, const char *pszTag);
592
593/**
594 * Maps a memory object into user virtual address space in the current process
595 * (default tag).
596 *
597 * @returns IPRT status code.
598 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
599 * @param MemObjToMap The object to be map.
600 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
601 * @param uAlignment The alignment of the reserved memory.
602 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
603 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
604 * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
605 */
606#define RTR0MemObjMapUser(pMemObj, MemObjToMap, R3PtrFixed, uAlignment, fProt, R0Process) \
607 RTR0MemObjMapUserTag((pMemObj), (MemObjToMap), (R3PtrFixed), (uAlignment), (fProt), (R0Process), RTMEM_TAG)
608
609/**
610 * Maps a memory object into user virtual address space in the current process
611 * (custom tag).
612 *
613 * @returns IPRT status code.
614 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
615 * @param MemObjToMap The object to be map.
616 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
617 * @param uAlignment The alignment of the reserved memory.
618 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
619 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
620 * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
621 * @param pszTag Allocation tag used for statistics and such.
622 */
623RTR0DECL(int) RTR0MemObjMapUserTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed,
624 size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process, const char *pszTag);
625
626/**
627 * Maps a memory object into user virtual address space in the current process
628 * (default tag).
629 *
630 * @returns IPRT status code.
631 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
632 * @param MemObjToMap The object to be map.
633 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
634 * @param uAlignment The alignment of the reserved memory.
635 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
636 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
637 * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
638 * @param offSub Where in the object to start mapping. If non-zero
639 * the value must be page aligned and cbSub must be
640 * non-zero as well.
641 * @param cbSub The size of the part of the object to be mapped. If
642 * zero the entire object is mapped. The value must be
643 * page aligned.
644 */
645#define RTR0MemObjMapUserEx(pMemObj, MemObjToMap, R3PtrFixed, uAlignment, fProt, R0Process, offSub, cbSub) \
646 RTR0MemObjMapUserExTag((pMemObj), (MemObjToMap), (R3PtrFixed), (uAlignment), (fProt), (R0Process), \
647 (offSub), (cbSub), RTMEM_TAG)
648
649/**
650 * Maps a memory object into user virtual address space in the current process
651 * (custom tag).
652 *
653 * @returns IPRT status code.
654 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
655 * @param MemObjToMap The object to be map.
656 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
657 * @param uAlignment The alignment of the reserved memory.
658 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
659 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
660 * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
661 * @param offSub Where in the object to start mapping. If non-zero
662 * the value must be page aligned and cbSub must be
663 * non-zero as well.
664 * @param cbSub The size of the part of the object to be mapped. If
665 * zero the entire object is mapped. The value must be
666 * page aligned.
667 * @param pszTag Allocation tag used for statistics and such.
668 */
669RTR0DECL(int) RTR0MemObjMapUserExTag(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
670 unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub, const char *pszTag);
671
672/**
673 * Change the page level protection of one or more pages in a memory object.
674 *
675 * @returns IPRT status code.
676 * @retval VERR_NOT_SUPPORTED if the OS doesn't provide any way to manipulate
677 * page level protection. The caller must handle this status code
678 * gracefully. (Note that it may also occur if the implementation is
679 * missing, in which case just go ahead and implement it.)
680 *
681 * @param hMemObj Memory object handle.
682 * @param offSub Offset into the memory object. Must be page aligned.
683 * @param cbSub Number of bytes to change the protection of. Must be
684 * page aligned.
685 * @param fProt Combination of RTMEM_PROT_* flags.
686 */
687RTR0DECL(int) RTR0MemObjProtect(RTR0MEMOBJ hMemObj, size_t offSub, size_t cbSub, uint32_t fProt);
688
689#endif /* IN_RING0 */
690
691/** @} */
692
693RT_C_DECLS_END
694
695#endif /* !IPRT_INCLUDED_memobj_h */
696
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