2 * reactos MDL emulation of libcaptive
3 * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "reactos/ddk/mmfuncs.h" /* self */
23 #include <glib/gmessages.h>
27 * MmProbeAndLockPages:
28 * @Mdl: Pointer to the #MDL specification structure to probe and lock.
29 * %NULL value is forbidden.
30 * @AccessMode: Access at which to lock the pages. %KernelMode required by libcaptive.
31 * @Operation: One of %IoReadAccess, %IoWriteAccess or %IoModifyAccess.
33 * Probles the specified @AccessMode and locks those pages specified by @Mdl to memory
34 * with the desired @AccessMode.
35 * libcaptive does NOP here as it just sets the %MDL_PAGES_LOCKED flag.
37 VOID MmProbeAndLockPages(PMDL Mdl,KPROCESSOR_MODE AccessMode,LOCK_OPERATION Operation)
39 g_return_if_fail(Mdl!=NULL);
40 g_return_if_fail(AccessMode==KernelMode /* || AccessMode==UserMode */);
42 Mdl->MdlFlags|=MDL_PAGES_LOCKED;
48 * @Mdl: Pointer to the #MDL specification structure to unlock.
49 * %NULL value is forbidden.
51 * Unlock the pages specified by @Mdl from memory.
52 * libcaptive does NOP here as it just clears the %MDL_PAGES_LOCKED flag.
54 VOID MmUnlockPages(PMDL Mdl)
56 g_return_if_fail(Mdl!=NULL);
58 Mdl->MdlFlags&=~MDL_PAGES_LOCKED;
64 * @Mdl: Pointer to the #MDL specification structure to map.
65 * %NULL value is forbidden.
66 * @AccessMode: Access at which to lock the pages. %KernelMode required by libcaptive.
68 * Leaves the pages at their original location as they are never moved anyway
71 * Returns: Address of the mapped pages base.
72 * This offset does not neet to be %PAGE_SIZE aligned.
74 PVOID MmMapLockedPages(PMDL Mdl,KPROCESSOR_MODE AccessMode)
76 g_return_val_if_fail(Mdl!=NULL,NULL);
77 g_assert(Mdl->StartVa!=NULL);
78 g_return_val_if_fail(AccessMode==KernelMode /* || AccessMode==UserMode */ ,NULL);
80 if (Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA) {
82 g_assert(Mdl->MappedSystemVa==Mdl->StartVa+Mdl->ByteOffset);
86 Mdl->MappedSystemVa=Mdl->StartVa+Mdl->ByteOffset;
87 Mdl->MdlFlags|=MDL_MAPPED_TO_SYSTEM_VA;
90 return Mdl->MappedSystemVa;
96 * @BaseAddress: Address of the mapped pages base.
97 * This offset does not neet to be %PAGE_SIZE aligned.
98 * @Mdl: Pointer to the #MDL specification structure to unmap.
100 * Declares the specified @Mdl pages as unmapped. @BaseAddress
101 * is required to be previously returned by MmMapLockedPages().
102 * You must not call this function twice without MmMapLockedPages() between.
104 VOID MmUnmapLockedPages(PVOID BaseAddress,PMDL Mdl)
106 g_return_if_fail(BaseAddress!=NULL);
107 g_return_if_fail(Mdl!=NULL);
108 g_return_if_fail(BaseAddress==Mdl->MappedSystemVa);
110 /* No mapping is done for pages from MmBuildMdlForNonPagedPool(). */
111 if (Mdl->MdlFlags&MDL_SOURCE_IS_NONPAGED_POOL) {
112 g_return_if_fail(!(Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA));
115 g_return_if_fail(Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA);
116 Mdl->MdlFlags&=~MDL_MAPPED_TO_SYSTEM_VA;
118 Mdl->MappedSystemVa=NULL;
122 * MmMapLockedPagesSpecifyCache:
123 * @Mdl: Pointer to the #MDL specification structure to map.
124 * %NULL value is forbidden.
125 * @AccessMode: Access at which to lock the pages. %KernelMode required by libcaptive.
126 * @CacheType: Suggested caching type. %MmNonCached, %MmCached or %MmWriteCombined required by libcaptive.
127 * @BaseAddress: Required block base address if @AccessMode is %UserMode. Ignored by libcaptive.
128 * @BugCheckOnFailure: Whether to call KeBugCheck() instead of returning %NULL. Ignored by libcaptive.
129 * @Priority: Suggested pages priority. %LowPagePriority, %NormalPagePriority or %HighPagePriority required by libcaptive.
131 * Leaves the pages at their original location as they are never moved anyway
132 * by libcaptive. This call is just a wrapper around MmMapLockedPages() in libcaptive.
134 * Returns: Address of the mapped pages base.
135 * This offset does not neet to be %PAGE_SIZE aligned.
137 PVOID MmMapLockedPagesSpecifyCache(IN PMDL Mdl,
138 IN KPROCESSOR_MODE AccessMode,IN MEMORY_CACHING_TYPE CacheType,IN PVOID BaseAddress,
139 IN ULONG BugCheckOnFailure,IN MM_PAGE_PRIORITY Priority)
141 g_return_val_if_fail(Mdl!=NULL,NULL);
142 g_return_val_if_fail(AccessMode==KernelMode /* || AccessMode==UserMode */ ,NULL);
143 g_return_val_if_fail(0
144 || CacheType==MmNonCached
145 || CacheType==MmCached
146 || CacheType==MmWriteCombined,
148 g_return_val_if_fail(0
149 || Priority==LowPagePriority
150 || Priority==NormalPagePriority
151 || Priority==HighPagePriority,
154 return MmMapLockedPages(Mdl,AccessMode);