From 46fa9ae1f477c7a6ec161efa7d8314611eddf37a Mon Sep 17 00:00:00 2001 From: Paul Durrant Date: Fri, 31 Jan 2014 17:44:53 +0000 Subject: [PATCH] Add a magic number to the frontend structure that can be checked for in the mib callback. There's a suspicion that the callback may be occuring after xenvif has unloaded. Signed-off-by: Paul Durrant --- src/xenvif/frontend.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/xenvif/frontend.c b/src/xenvif/frontend.c index 6b1e6e4..33c8f69 100644 --- a/src/xenvif/frontend.c +++ b/src/xenvif/frontend.c @@ -55,6 +55,7 @@ #include "assert.h" struct _XENVIF_FRONTEND { + ULONG Magic; PXENVIF_PDO Pdo; PCHAR Path; PCHAR Prefix; @@ -80,6 +81,8 @@ struct _XENVIF_FRONTEND { HANDLE Handle; }; +#define FRONTEND_MAGIC 0xf00ba4ed + static const PCHAR FrontendStateName( IN XENVIF_FRONTEND_STATE State @@ -663,6 +666,8 @@ FrontendIpAddressChange( UNREFERENCED_PARAMETER(_Row); UNREFERENCED_PARAMETER(NotificationType); + ASSERT3U(Frontend->Magic, ==, FRONTEND_MAGIC); + ThreadWake(Frontend->MibThread); } @@ -1555,6 +1560,8 @@ FrontendInitialize( Trace("====>\n"); + ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL); + Name = PdoGetName(Pdo); Length = sizeof ("devices/vif/") + (ULONG)strlen(Name); @@ -1624,6 +1631,9 @@ FrontendInitialize( if (!NT_SUCCESS(status)) goto fail11; + (*Frontend)->Magic = FRONTEND_MAGIC; + _ReadWriteBarrier(); + status = NotifyUnicastIpAddressChange(AF_UNSPEC, FrontendIpAddressChange, *Frontend, @@ -1636,7 +1646,12 @@ FrontendInitialize( // If IP Helper isn't available (as in Windows PE) then // NotifyUnicastIpAddressChange will not be supported Warning("Cannot record or update network info to XAPI %x\n", status); - (*Frontend)->Handle = NULL; + // The documentation states that in the error case, the handle is + // always populated with NULL. + ASSERT((*Frontend)->Handle == NULL); + } else { + // By inference the handle should not be NULL in the success case + ASSERT((*Frontend)->Handle != NULL); } Trace("<====\n"); @@ -1646,6 +1661,8 @@ FrontendInitialize( fail12: Error("fail12\n"); + (*Frontend)->Magic = 0; + ThreadAlert((*Frontend)->MibThread); ThreadJoin((*Frontend)->MibThread); (*Frontend)->MibThread = NULL; @@ -1726,14 +1743,23 @@ FrontendTeardown( { Trace("====>\n"); + ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL); + ASSERT(Frontend->State != FRONTEND_ENABLED); ASSERT(Frontend->State != FRONTEND_CONNECTED); if (Frontend->Handle != NULL) { - CancelMibChangeNotify2(Frontend->Handle); + NTSTATUS status; + + status = CancelMibChangeNotify2(Frontend->Handle); + ASSERT(NT_SUCCESS(status)); + Frontend->Handle = NULL; } + _ReadWriteBarrier(); + Frontend->Magic = 0; + if (Frontend->State == FRONTEND_PREPARED) { ASSERT(Frontend->Watch != NULL); -- 2.39.5