Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / libcaptive / mm / mdl.c
index 6658133..5e9f1f4 100644 (file)
@@ -27,7 +27,7 @@
  * MmProbeAndLockPages:
  * @Mdl: Pointer to the #MDL specification structure to probe and lock.
  * %NULL value is forbidden.
- * @AccessMode: Access at which to probe the pages. Ignored by libcaptive.
+ * @AccessMode: Access at which to lock the pages. %KernelMode required by libcaptive.
  * @Operation: One of %IoReadAccess, %IoWriteAccess or %IoModifyAccess.
  *
  * Probles the specified @AccessMode and locks those pages specified by @Mdl to memory
@@ -37,6 +37,7 @@
 VOID MmProbeAndLockPages(PMDL Mdl,KPROCESSOR_MODE AccessMode,LOCK_OPERATION Operation)
 {
        g_return_if_fail(Mdl!=NULL);
+       g_return_if_fail(AccessMode==KernelMode /* || AccessMode==UserMode */);
 
        Mdl->MdlFlags|=MDL_PAGES_LOCKED;
 }
@@ -62,7 +63,7 @@ VOID MmUnlockPages(PMDL Mdl)
  * MmMapLockedPages:
  * @Mdl: Pointer to the #MDL specification structure to map.
  * %NULL value is forbidden.
- * @AccessMode: Access at which to lock the pages. Ignored by libcaptive.
+ * @AccessMode: Access at which to lock the pages. %KernelMode required by libcaptive.
  *
  * Leaves the pages at their original location as they are never moved anyway
  * by libcaptive.
@@ -74,6 +75,7 @@ PVOID MmMapLockedPages(PMDL Mdl,KPROCESSOR_MODE AccessMode)
 {
        g_return_val_if_fail(Mdl!=NULL,NULL);
        g_assert(Mdl->StartVa!=NULL);
+       g_return_val_if_fail(AccessMode==KernelMode /* || AccessMode==UserMode */ ,NULL);
 
        if (Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA) {
                /* already mapped */
@@ -90,8 +92,8 @@ PVOID MmMapLockedPages(PMDL Mdl,KPROCESSOR_MODE AccessMode)
 
 
 /**
- * @MmUnmapLockedPages:
- * BaseAddress: Address of the mapped pages base.
+ * MmUnmapLockedPages:
+ * @BaseAddress: Address of the mapped pages base.
  * This offset does not neet to be %PAGE_SIZE aligned.
  * @Mdl: Pointer to the #MDL specification structure to unmap.
  *
@@ -103,9 +105,51 @@ VOID MmUnmapLockedPages(PVOID BaseAddress,PMDL Mdl)
 {
        g_return_if_fail(BaseAddress!=NULL);
        g_return_if_fail(Mdl!=NULL);
-       g_return_if_fail(Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA);
-       g_return_if_fail(BaseAddress!=Mdl->MappedSystemVa);
+       g_return_if_fail(BaseAddress==Mdl->MappedSystemVa);
 
+       /* No mapping is done for pages from MmBuildMdlForNonPagedPool(). */
+       if (Mdl->MdlFlags&MDL_SOURCE_IS_NONPAGED_POOL) {
+               g_return_if_fail(!(Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA));
+               }
+       else {
+               g_return_if_fail(Mdl->MdlFlags&MDL_MAPPED_TO_SYSTEM_VA);
+               Mdl->MdlFlags&=~MDL_MAPPED_TO_SYSTEM_VA;
+               }
        Mdl->MappedSystemVa=NULL;
-       Mdl->MdlFlags&=~MDL_MAPPED_TO_SYSTEM_VA;
+}
+
+/**
+ * MmMapLockedPagesSpecifyCache:
+ * @Mdl: Pointer to the #MDL specification structure to map.
+ * %NULL value is forbidden.
+ * @AccessMode: Access at which to lock the pages. %KernelMode required by libcaptive.
+ * @CacheType: Suggested caching type. %MmNonCached, %MmCached or %MmWriteCombined required by libcaptive.
+ * @BaseAddress: Required block base address if @AccessMode is %UserMode. Ignored by libcaptive.
+ * @BugCheckOnFailure: Whether to call KeBugCheck() instead of returning %NULL. Ignored by libcaptive.
+ * @Priority: Suggested pages priority. %LowPagePriority, %NormalPagePriority or %HighPagePriority required by libcaptive.
+ *
+ * Leaves the pages at their original location as they are never moved anyway
+ * by libcaptive. This call is just a wrapper around MmMapLockedPages() in libcaptive.
+ *
+ * Returns: Address of the mapped pages base.
+ * This offset does not neet to be %PAGE_SIZE aligned.
+ */
+PVOID MmMapLockedPagesSpecifyCache(IN PMDL Mdl,
+               IN KPROCESSOR_MODE AccessMode,IN MEMORY_CACHING_TYPE CacheType,IN PVOID BaseAddress,
+               IN ULONG BugCheckOnFailure,IN MM_PAGE_PRIORITY Priority)
+{
+       g_return_val_if_fail(Mdl!=NULL,NULL);
+       g_return_val_if_fail(AccessMode==KernelMode /* || AccessMode==UserMode */ ,NULL);
+       g_return_val_if_fail(0
+                                       || CacheType==MmNonCached
+                                       || CacheType==MmCached
+                                       || CacheType==MmWriteCombined,
+                       NULL);
+       g_return_val_if_fail(0
+                                       || Priority==LowPagePriority
+                                       || Priority==NormalPagePriority
+                                       || Priority==HighPagePriority,
+                       NULL);
+
+       return MmMapLockedPages(Mdl,AccessMode);
 }