Added new 'bootcd' target.
[reactos.git] / reactos / include / ddk / mmfuncs.h
1 #ifndef _INCLUDE_DDK_MMFUNCS_H
2 #define _INCLUDE_DDK_MMFUNCS_H
3 /* $Id: mmfuncs.h,v 1.11 2001/11/13 22:46:24 ekohl Exp $ */
4 /* MEMORY MANAGMENT ******************************************************/
5
6
7 #ifdef __NTOSKRNL__
8 extern PVOID EXPORTED MmUserProbeAddress;
9 extern PVOID EXPORTED MmHighestUserAddress;
10 #else
11 extern PVOID IMPORTED MmUserProbeAddress;
12 extern PVOID IMPORTED MmHighestUserAddress;
13 #endif
14
15 #ifdef __NTOSKRNL__
16 extern POBJECT_TYPE EXPORTED MmSectionObjectType;
17 #else
18 extern POBJECT_TYPE IMPORTED MmSectionObjectType;
19 #endif
20
21
22 /*
23 * FUNCTION: Returns the number of pages spanned by an address range
24 * ARGUMENTS:
25 * Va = start of range
26 * Size = Size of range
27 * RETURNS: The number of pages
28 */
29 #if 0
30 extern inline unsigned int ADDRESS_AND_SIZE_TO_SPAN_PAGES(PVOID Va,
31 ULONG Size)
32 {
33 ULONG HighestAddr;
34 ULONG LowestAddr;
35
36 HighestAddr = PAGE_ROUND_UP(Size + ((ULONG)Va));
37 LowestAddr = PAGE_ROUND_DOWN((ULONG)Va);
38 return((HighestAddr - LowestAddr) / PAGESIZE);
39 }
40 #endif
41 #define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va, Size) \
42 (ULONG)((PAGE_ROUND_UP((Size) + ((ULONG)(Va))) - \
43 PAGE_ROUND_DOWN((ULONG)(Va))) / PAGESIZE)
44
45 /*
46 * FUNCTION: Returns FALSE is the pointer is NULL, TRUE otherwise
47 */
48 #define ARGUMENT_PRESENT(arg) ((arg)!=NULL)
49
50 /*
51 * FUNCTION: Returns the byte offset of the address within its page
52 */
53 #define BYTE_OFFSET(va) (((ULONG)va)%PAGESIZE)
54
55 /*
56 * FUNCTION: Takes a count in bytes and returns the number of pages
57 * required to hold it
58 */
59 #define BYTES_TO_PAGES(size) (?)
60
61 DWORD
62 STDCALL
63 MmAdjustWorkingSetSize (
64 DWORD Unknown0,
65 DWORD Unknown1,
66 DWORD Unknown2
67 );
68 PVOID
69 STDCALL
70 MmAllocateContiguousMemory (
71 IN ULONG NumberOfBytes,
72 IN PHYSICAL_ADDRESS HighestAcceptableAddress
73 );
74
75 PVOID STDCALL
76 MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
77 IN PHYSICAL_ADDRESS HighestAcceptableAddress,
78 IN ULONG Alignment);
79
80 PVOID
81 STDCALL
82 MmAllocateNonCachedMemory (
83 IN ULONG NumberOfBytes
84 );
85 /*
86 * FUNCTION: Fills in the corresponding physical page array for a given MDL
87 * for a buffer in nonpaged system space
88 * ARGUMENTS:
89 * MemoryDescriptorList = MDL to fill
90 */
91 VOID
92 STDCALL
93 MmBuildMdlForNonPagedPool (
94 PMDL MemoryDescriptorList
95 );
96 BOOLEAN
97 STDCALL
98 MmCanFileBeTruncated (
99 IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
100 IN PLARGE_INTEGER NewFileSize
101 );
102 /*
103 * FUNCTION: Allocates and initializes an MDL
104 * ARGUMENTS:
105 * MemoryDescriptorList = Optional caller allocated MDL to initalize
106 * Base = Base virtual address for buffer
107 * Length = Length in bytes of the buffer
108 * RETURNS: A pointer to the initalized MDL
109 */
110 PMDL
111 STDCALL
112 MmCreateMdl (
113 PMDL MemoryDescriptorList,
114 PVOID Base,
115 ULONG Length
116 );
117 #if 0
118 NTSTATUS
119 STDCALL
120 MmCreateSection (
121 OUT PSECTION_OBJECT * SectionObject,
122 IN ACCESS_MASK DesiredAccess,
123 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
124 IN PLARGE_INTEGER MaximumSize,
125 IN ULONG SectionPageProtection,
126 IN ULONG AllocationAttributes,
127 IN HANDLE FileHandle OPTIONAL,
128 IN PFILE_OBJECT File OPTIONAL
129 );
130 #endif
131 DWORD
132 STDCALL
133 MmDbgTranslatePhysicalAddress (
134 DWORD Unknown0,
135 DWORD Unknown1
136 );
137 BOOLEAN
138 STDCALL
139 MmDisableModifiedWriteOfSection (
140 DWORD Unknown0
141 );
142 BOOLEAN
143 STDCALL
144 MmFlushImageSection (
145 IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
146 IN MMFLUSH_TYPE FlushType
147 );
148 BOOLEAN
149 STDCALL
150 MmForceSectionClosed (
151 DWORD Unknown0,
152 DWORD Unknown1
153 );
154 VOID
155 STDCALL
156 MmFreeContiguousMemory (
157 IN OUT PVOID BaseAddress
158 );
159 VOID
160 STDCALL
161 MmFreeNonCachedMemory (
162 IN PVOID BaseAddress,
163 IN ULONG NumberOfBytes
164 );
165 /*
166 * FUNCTION: Returns the length in bytes of a buffer described by an MDL
167 * ARGUMENTS:
168 * Mdl = the mdl
169 * RETURNS: Size of the buffer
170 */
171 #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
172
173 /*
174 * FUNCTION: Returns the byte offset within a page of the buffer described
175 * by an MDL
176 * ARGUMENTS:
177 * Mdl = the mdl
178 * RETURNS: The offset in bytes
179 */
180 #define MmGetMdlByteOffset(Mdl) \
181 ((Mdl)->ByteOffset)
182
183 /*
184 * FUNCTION: Returns the initial virtual address for a buffer described
185 * by an MDL
186 * ARGUMENTS:
187 * Mdl = the mdl
188 * RETURNS: The initial virtual address
189 */
190 #define MmGetMdlVirtualAddress(Mdl) \
191 ((PVOID) ((PCHAR) (Mdl)->StartVa + (Mdl)->ByteOffset))
192
193 /*
194 * FUNCTION: Returns the physical address corresponding to a given valid
195 * virtual address
196 * ARGUMENTS:
197 * BaseAddress = the virtual address
198 * RETURNS: The physical address
199 */
200 PHYSICAL_ADDRESS
201 STDCALL
202 MmGetPhysicalAddress (
203 IN PVOID BaseAddress
204 );
205
206 #define MmGetProcedureAddress(Address) (Address)
207
208 /*
209 * PVOID
210 * MmGetSystemAddressForMdl (
211 * PMDL Mdl
212 * );
213 *
214 * FUNCTION:
215 * Maps the physical pages described by an MDL into system space
216 *
217 * ARGUMENTS:
218 * Mdl = mdl
219 *
220 * RETURNS:
221 * The base system address for the mapped buffer
222 */
223 #define MmGetSystemAddressForMdl(Mdl) \
224 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
225 ((Mdl)->MappedSystemVa):(MmMapLockedPages((Mdl),KernelMode)))
226
227 NTSTATUS
228 STDCALL
229 MmGrowKernelStack (
230 DWORD Unknown0
231 );
232
233
234 /*
235 * VOID
236 * MmInitializeMdl (
237 * PMDL MemoryDescriptorList,
238 * PVOID BaseVa,
239 * ULONG Length
240 * );
241 *
242 * FUNCTION:
243 * Initalizes an MDL
244 *
245 * ARGUMENTS:
246 * MemoryDescriptorList = MDL to be initalized
247 * BaseVa = Base virtual address of the buffer
248 * Length = Length in bytes of the buffer
249 */
250 #define MmInitializeMdl(MemoryDescriptorList,BaseVa,Length) \
251 { \
252 (MemoryDescriptorList)->Next = (PMDL)NULL; \
253 (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
254 (ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa),(Length)) * sizeof(ULONG))); \
255 (MemoryDescriptorList)->MdlFlags = 0; \
256 (MemoryDescriptorList)->StartVa = (PVOID)PAGE_ROUND_DOWN((BaseVa)); \
257 (MemoryDescriptorList)->ByteOffset = (ULONG)((BaseVa) - PAGE_ROUND_DOWN((BaseVa))); \
258 (MemoryDescriptorList)->ByteCount = (Length); \
259 (MemoryDescriptorList)->Process = PsGetCurrentProcess(); \
260 }
261
262 /*
263 * FUNCTION: Checks whether an address is valid for read/write
264 * ARGUMENTS:
265 * VirtualAddress = address to be check
266 * RETURNS: TRUE if an access would be valid
267 */
268 BOOLEAN
269 STDCALL
270 MmIsAddressValid (
271 IN PVOID VirtualAddress
272 );
273 BOOLEAN
274 STDCALL
275 MmIsNonPagedSystemAddressValid (
276 IN PVOID VirtualAddress
277 );
278 BOOLEAN
279 STDCALL
280 MmIsRecursiveIoFault (
281 VOID
282 );
283 /*
284 * FUNCTION: Checks if the current platform is a workstation or a server
285 * RETURNS: If the system is a server returns true
286 * NOTE: Drivers can use this as an estimate of the likely resources
287 * available
288 */
289 BOOLEAN
290 STDCALL
291 MmIsThisAnNtAsSystem (
292 VOID
293 );
294 /*
295 * FUNCTION: Locks a section of the driver's code into memory
296 * ARGUMENTS:
297 * AddressWithinSection = Any address in the region
298 * RETURNS: A handle to the region
299 */
300 #define MmLockPagableCodeSection(Address) \
301 MmLockPagableDataSection(Address)
302
303 /*
304 * FUNCTION: Locks a section of the driver's data into memory
305 * ARGUMENTS:
306 * AddressWithinSection = Any address in the region
307 * RETURNS: A handle to the region
308 */
309 PVOID
310 STDCALL
311 MmLockPagableDataSection (
312 PVOID AddressWithinSection
313 );
314 PVOID
315 STDCALL
316 MmLockPagableImageSection (
317 PVOID AddressWithinSection
318 );
319 /*
320 * FUNCTION: Locks a section of memory
321 * ARGUMENTS:
322 * ImageSectionHandle = handle returned from MmLockPagableCodeSection
323 * or MmLockPagableDataSection
324 */
325 VOID
326 STDCALL
327 MmLockPagableSectionByHandle (
328 PVOID ImageSectionHandle
329 );
330 PVOID
331 STDCALL
332 MmMapIoSpace (
333 PHYSICAL_ADDRESS PhysicalAddress,
334 ULONG NumberOfBytes,
335 BOOLEAN CacheEnable
336 );
337 /*
338 * FUNCTION: Maps the pages described by a given MDL
339 * ARGUMENTS:
340 * MemoryDescriptorList = MDL updated by MmProbeAndLockPages
341 * AccessMode = Access mode in which to map the MDL
342 * RETURNS: The base virtual address which maps the buffer
343 */
344 PVOID
345 STDCALL
346 MmMapLockedPages (
347 PMDL MemoryDescriptorList,
348 KPROCESSOR_MODE AccessMode
349 );
350 VOID
351 STDCALL
352 MmMapMemoryDumpMdl (
353 PVOID Unknown0
354 );
355 PVOID
356 STDCALL
357 MmMapVideoDisplay (
358 IN PHYSICAL_ADDRESS PhysicalAddress,
359 IN ULONG NumberOfBytes,
360 IN MEMORY_CACHING_TYPE CacheType
361 );
362 NTSTATUS
363 STDCALL
364 MmMapViewInSystemSpace (
365 IN PVOID Section,
366 OUT PVOID * MappedBase,
367 IN PULONG ViewSize
368 );
369 NTSTATUS
370 STDCALL
371 MmMapViewOfSection (
372 IN PVOID SectionObject,
373 IN PEPROCESS Process,
374 IN OUT PVOID * BaseAddress,
375 IN ULONG ZeroBits,
376 IN ULONG CommitSize,
377 IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
378 IN OUT PULONG ViewSize,
379 IN SECTION_INHERIT InheritDisposition,
380 IN ULONG AllocationType,
381 IN ULONG Protect
382 );
383
384 /*
385 * FUNCTION: Makes the whole driver pageable
386 * ARGUMENTS:
387 * AddressWithinSection = Any address within the driver
388 */
389 VOID
390 STDCALL
391 MmPageEntireDriver (
392 PVOID AddressWithinSection
393 );
394
395 /*
396 * VOID
397 * MmPrepareMdlForReuse (
398 * PMDL Mdl
399 * );
400 *
401 * FUNCTION:
402 * Reinitializes a caller-allocated MDL
403 *
404 * ARGUMENTS:
405 * Mdl = Points to the MDL that will be reused
406 */
407 #define MmPrepareMdlForReuse(Mdl) \
408 if (((Mdl)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) \
409 { \
410 assert(((Mdl)->MdlFlags & MDL_PARTIAL) != 0); \
411 MmUnmapLockedPages ((Mdl)->MappedSystemVa, (Mdl)); \
412 } \
413 else if (((Mdl)->MdlFlags & MDL_PARTIAL) == 0) \
414 { \
415 assert(((Mdl)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
416 }
417
418 /*
419 * FUNCTION: Probes the specified pages, makes them resident and locks
420 * the physical pages mapped by the virtual address range
421 * ARGUMENTS:
422 * MemoryDescriptorList = MDL which supplies the virtual address,
423 * byte offset and length
424 * AccessMode = Access mode with which to probe the arguments
425 * Operation = Types of operation for which the pages should be
426 * probed
427 */
428 VOID
429 STDCALL
430 MmProbeAndLockPages (
431 PMDL MemoryDescriptorList,
432 KPROCESSOR_MODE AccessMode,
433 LOCK_OPERATION Operation
434 );
435
436 /*
437 * FUNCTION: Returns an estimate of the amount of memory in the system
438 * RETURNS: Either MmSmallSystem, MmMediumSystem or MmLargeSystem
439 */
440 MM_SYSTEM_SIZE
441 STDCALL
442 MmQuerySystemSize (
443 VOID
444 );
445
446 /*
447 * FUNCTION: Resets the pageable status of a driver's sections to their
448 * compile time settings
449 * ARGUMENTS:
450 * AddressWithinSection = Any address within the driver
451 */
452 VOID
453 STDCALL
454 MmResetDriverPaging (
455 PVOID AddressWithinSection
456 );
457
458 DWORD
459 STDCALL
460 MmSecureVirtualMemory (
461 DWORD Unknown0,
462 DWORD Unknown1,
463 DWORD Unknown2
464 );
465 BOOLEAN
466 STDCALL
467 MmSetAddressRangeModified (
468 DWORD Unknown0,
469 DWORD Unknown1
470 );
471 NTSTATUS
472 STDCALL
473 MmSetBankedSection (
474 DWORD Unknown0,
475 DWORD Unknown1,
476 DWORD Unknown2,
477 DWORD Unknown3,
478 DWORD Unknown4,
479 DWORD Unknown5
480 );
481
482 /*
483 * FUNCTION: Returns the number of bytes to allocate for an MDL
484 * describing a given address range
485 * ARGUMENTS:
486 * Base = Base virtual address for the region
487 * Length = size in bytes of the region
488 * RETURNS: The number of bytes required for the MDL
489 */
490 ULONG
491 STDCALL
492 MmSizeOfMdl (
493 PVOID Base,
494 ULONG Length
495 );
496 /*
497 * FUNCTION: Unlocks the physical pages described by a given MDL
498 * ARGUMENTS:
499 * Mdl = Mdl to unlock
500 */
501 VOID
502 STDCALL
503 MmUnlockPages (
504 PMDL Mdl
505 );
506 /*
507 * FUNCTION: Releases a section of driver code or data previously locked into
508 * memory
509 * ARGUMENTS:
510 * ImageSectionHandle = Handle for the locked section
511 */
512 VOID
513 STDCALL
514 MmUnlockPagableImageSection (
515 PVOID ImageSectionHandle
516 );
517 VOID
518 STDCALL
519 MmUnmapIoSpace (
520 PVOID BaseAddress,
521 ULONG NumberOfBytes
522 );
523 VOID
524 STDCALL
525 MmUnmapLockedPages (
526 PVOID BaseAddress,
527 PMDL MemoryDescriptorList
528 );
529 VOID
530 STDCALL
531 MmUnmapVideoDisplay (
532 IN PVOID BaseAddress,
533 IN ULONG NumberOfBytes
534 );
535 NTSTATUS
536 STDCALL
537 MmUnmapViewInSystemSpace (
538 DWORD Unknown0
539 );
540 #if 0
541 NTSTATUS
542 STDCALL
543 MmUnmapViewOfSection (
544 PEPROCESS Process,
545 PMEMORY_AREA MemoryArea
546 )
547 #endif
548 VOID
549 STDCALL
550 MmUnsecureVirtualMemory (
551 DWORD Unknown0
552 );
553 #endif