VirtualBox

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

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

Use size_t for the page index. Added API for querying the ring-3 address.

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