[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH] Stash a pointer to _snprintf_s in the ADAPTER structure



It is problematic if we don't, as on resume from suspend we need to
re-acquire the function pointer and this seems to lead to a BSOD, despite
there being no documentation to suggest that use of the aux_klib functions
at DISPATCH_LEVEL is disallowed.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xennet/adapter.c | 61 +++++++++++++++++++++++++++-------------------------
 1 file changed, 32 insertions(+), 29 deletions(-)

diff --git a/src/xennet/adapter.c b/src/xennet/adapter.c
index d85f4d1..dc69a7f 100644
--- a/src/xennet/adapter.c
+++ b/src/xennet/adapter.c
@@ -81,6 +81,12 @@ struct _XENNET_ADAPTER {
     PXENNET_RECEIVER            Receiver;
     PXENNET_TRANSMITTER         Transmitter;
     BOOLEAN                     Enabled;
+
+    NTSTATUS                    (*_snprintf_s)(char *,
+                                               size_t,
+                                               size_t,
+                                               const char *,
+                                               ...);
 };
 
 static LONG AdapterCount;
@@ -1300,11 +1306,6 @@ __AdapterSetDistribution(
     )
 {
     ULONG               Index;
-    NTSTATUS            (*___snprintf_s)(char *,
-                                         size_t,
-                                         size_t,
-                                         const char *,
-                                         ...);
     CHAR                Distribution[MAXNAMELEN];
     CHAR                Vendor[MAXNAMELEN];
     const CHAR          *Product;
@@ -1312,21 +1313,15 @@ __AdapterSetDistribution(
 
     Trace("====>\n");
 
-    status = LinkGetRoutineAddress("ntdll.dll",
-                                   "_snprintf_s",
-                                   (PVOID *)&___snprintf_s);
-    if (!NT_SUCCESS(status))
-        goto fail1;
-
     Index = 0;
     while (Index <= MAXIMUM_INDEX) {
         PCHAR   Buffer;
 
-        (VOID) ___snprintf_s(Distribution,
-                             MAXNAMELEN,
-                             _TRUNCATE,
-                             "%u",
-                             Index);
+        (VOID) Adapter->_snprintf_s(Distribution,
+                                    MAXNAMELEN,
+                                    _TRUNCATE,
+                                    "%u",
+                                    Index);
 
         status = XENBUS_STORE(Read,
                               &Adapter->StoreInterface,
@@ -1338,7 +1333,7 @@ __AdapterSetDistribution(
             if (status == STATUS_OBJECT_NAME_NOT_FOUND)
                 goto update;
 
-            goto fail2;
+            goto fail1;
         }
 
         XENBUS_STORE(Free,
@@ -1349,14 +1344,14 @@ __AdapterSetDistribution(
     }
 
     status = STATUS_UNSUCCESSFUL;
-    goto fail3;
+    goto fail2;
 
 update:
-    (VOID) ___snprintf_s(Vendor,
-                         MAXNAMELEN,
-                         _TRUNCATE,
-                         "%s",
-                         VENDOR_NAME_STR);
+    (VOID) Adapter->_snprintf_s(Vendor,
+                                MAXNAMELEN,
+                                _TRUNCATE,
+                                "%s",
+                                VENDOR_NAME_STR);
 
     for (Index  = 0; Vendor[Index] != '\0'; Index++)
         if (!isalnum((UCHAR)Vendor[Index]))
@@ -1389,9 +1384,6 @@ update:
     Trace("<====\n");
     return STATUS_SUCCESS;
 
-fail3:
-    Error("fail3\n");
-
 fail2:
     Error("fail2\n");
 
@@ -1498,16 +1490,22 @@ AdapterEnable(
     if (!NT_SUCCESS(status))
         goto fail2;
 
-    status = AdapterSetDistribution(Adapter);
+    status = LinkGetRoutineAddress("ntdll.dll",
+                                   "_snprintf_s",
+                                   (PVOID *)&Adapter->_snprintf_s);
     if (!NT_SUCCESS(status))
         goto fail3;
 
+    status = AdapterSetDistribution(Adapter);
+    if (!NT_SUCCESS(status))
+        goto fail4;
+
     status = XENVIF_VIF(Enable,
                         &Adapter->VifInterface,
                         AdapterVifCallback,
                         Adapter);
     if (!NT_SUCCESS(status))
-        goto fail4;
+        goto fail5;
 
     AdapterMediaStateChange(Adapter);
 
@@ -1515,9 +1513,12 @@ AdapterEnable(
 
     return NDIS_STATUS_SUCCESS;
 
-fail4:
+fail5:
     AdapterClearDistribution(Adapter);
 
+fail4:
+    Adapter->_snprintf_s = NULL;
+
 fail3:
     XENBUS_SUSPEND(Release, &Adapter->SuspendInterface);
 
@@ -1543,6 +1544,8 @@ AdapterDisable(
 
     AdapterClearDistribution(Adapter);
 
+    Adapter->_snprintf_s = NULL;
+
     XENBUS_SUSPEND(Release, &Adapter->SuspendInterface);
     XENBUS_STORE(Release, &Adapter->StoreInterface);
 }
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.