[16/22] uio: Wrap call into try/except block

Message ID 1597360905-74106-17-git-send-email-navasile@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series windows/netuio: add netuio driver for Windows |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Narcisa Ana Maria Vasile Aug. 13, 2020, 11:21 p.m. UTC
  From: Narcisa Vasile <navasile@microsoft.com>

MmMapLockedPagesSpecifyCache can raise an exception when
it cannot map the specified pages.

Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
Reported-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 kernel/windows/netuio/netuio_queue.c | 36 ++++++++++++++++++----------
 1 file changed, 23 insertions(+), 13 deletions(-)
  

Patch

diff --git a/kernel/windows/netuio/netuio_queue.c b/kernel/windows/netuio/netuio_queue.c
index 9c7ff7d06..c2bc998dc 100644
--- a/kernel/windows/netuio/netuio_queue.c
+++ b/kernel/windows/netuio/netuio_queue.c
@@ -53,13 +53,18 @@  netuio_map_address_into_user_process(_In_ PNETUIO_CONTEXT_DATA netuio_contextdat
 
     // Map the scratch memory regions to the user's process context
     MmBuildMdlForNonPagedPool(netuio_contextdata->dpdk_seg.mdl);
-    netuio_contextdata->dpdk_seg.mem.user_mapped_virt_addr =
-        MmMapLockedPagesSpecifyCache(
-            netuio_contextdata->dpdk_seg.mdl, UserMode, MmCached,
-            NULL, FALSE, (NormalPagePriority | MdlMappingNoExecute));
+    __try {
+        netuio_contextdata->dpdk_seg.mem.user_mapped_virt_addr =
+            MmMapLockedPagesSpecifyCache(netuio_contextdata->dpdk_seg.mdl, UserMode,
+                                         MmCached, NULL, FALSE, NormalPagePriority);
 
-    if (netuio_contextdata->dpdk_seg.mem.user_mapped_virt_addr == NULL) {
-        status = STATUS_INSUFFICIENT_RESOURCES;
+        if (netuio_contextdata->dpdk_seg.mem.user_mapped_virt_addr == NULL) {
+            status = STATUS_INSUFFICIENT_RESOURCES;
+            goto end;
+        }
+    }
+    __except (EXCEPTION_EXECUTE_HANDLER) {
+        status = GetExceptionCode();
         goto end;
     }
 
@@ -70,13 +75,18 @@  netuio_map_address_into_user_process(_In_ PNETUIO_CONTEXT_DATA netuio_contextdat
         }
 
         MmBuildMdlForNonPagedPool(netuio_contextdata->dpdk_hw[idx].mdl);
-        netuio_contextdata->dpdk_hw[idx].mem.user_mapped_virt_addr =
-            MmMapLockedPagesSpecifyCache(
-                netuio_contextdata->dpdk_hw[idx].mdl, UserMode, MmCached,
-                NULL, FALSE, (NormalPagePriority | MdlMappingNoExecute));
-
-        if (netuio_contextdata->dpdk_hw[idx].mem.user_mapped_virt_addr == NULL) {
-            status = STATUS_INSUFFICIENT_RESOURCES;
+        __try {
+            netuio_contextdata->dpdk_hw[idx].mem.user_mapped_virt_addr =
+                MmMapLockedPagesSpecifyCache(netuio_contextdata->dpdk_hw[idx].mdl, UserMode,
+                                             MmCached, NULL, FALSE, NormalPagePriority);
+
+            if (netuio_contextdata->dpdk_hw[idx].mem.user_mapped_virt_addr == NULL) {
+                status = STATUS_INSUFFICIENT_RESOURCES;
+                goto end;
+            }
+        }
+        __except (EXCEPTION_EXECUTE_HANDLER) {
+            status = GetExceptionCode();
             goto end;
         }
     }