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 probe the pages. Ignored 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);
41 Mdl->MdlFlags|=MDL_PAGES_LOCKED;
47 * @Mdl: Pointer to the #MDL specification structure to unlock.
48 * %NULL value is forbidden.
50 * Unlock the pages specified by @Mdl from memory.
51 * libcaptive does NOP here as it just clears the %MDL_PAGES_LOCKED flag.
53 VOID MmUnlockPages(PMDL Mdl)
55 g_return_if_fail(Mdl!=NULL);
57 Mdl->MdlFlags&=~MDL_PAGES_LOCKED;
63 * @Mdl: Pointer to the #MDL specification structure to map.
64 * %NULL value is forbidden.
65 * @AccessMode: Access at which to lock the pages. Ignored by libcaptive.
67 * Leaves the pages at their original location as they are never moved anyway
70 * Returns: Address of the mapped pages base.
71 * This offset does not neet to be %PAGE_SIZE aligned.
73 PVOID MmMapLockedPages(PMDL Mdl,KPROCESSOR_MODE AccessMode)
75 g_return_val_if_fail(Mdl!=NULL,NULL);
76 g_assert(Mdl->StartVa!=NULL);
78 if (Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA) {
80 g_assert(Mdl->MappedSystemVa==Mdl->StartVa+Mdl->ByteOffset);
84 Mdl->MappedSystemVa=Mdl->StartVa+Mdl->ByteOffset;
85 Mdl->MdlFlags|=MDL_MAPPED_TO_SYSTEM_VA;
88 return Mdl->MappedSystemVa;
93 * @MmUnmapLockedPages:
94 * BaseAddress: Address of the mapped pages base.
95 * This offset does not neet to be %PAGE_SIZE aligned.
96 * @Mdl: Pointer to the #MDL specification structure to unmap.
98 * Declares the specified @Mdl pages as unmapped. @BaseAddress
99 * is required to be previously returned by MmMapLockedPages().
100 * You must not call this function twice without MmMapLockedPages() between.
102 VOID MmUnmapLockedPages(PVOID BaseAddress,PMDL Mdl)
104 g_return_if_fail(BaseAddress!=NULL);
105 g_return_if_fail(Mdl!=NULL);
106 g_return_if_fail(Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA);
107 g_return_if_fail(BaseAddress!=Mdl->MappedSystemVa);
109 Mdl->MappedSystemVa=NULL;
110 Mdl->MdlFlags&=~MDL_MAPPED_TO_SYSTEM_VA;