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

Re: [win-pv-devel] [PATCH 02/14] Refactor: Move console handler to console.h/.c



> -----Original Message-----
> From: win-pv-devel [mailto:win-pv-devel-bounces@xxxxxxxxxxxxxxxxxxxx] On
> Behalf Of owen.smith@xxxxxxxxxx
> Sent: 24 January 2018 14:05
> To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Owen Smith <owen.smith@xxxxxxxxxx>
> Subject: [win-pv-devel] [PATCH 02/14] Refactor: Move console handler to
> console.h/.c
> 
> From: Owen Smith <owen.smith@xxxxxxxxxx>
> 
> Split the console specific code from the general fdo code.
> 
> Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
> ---
>  src/xencons/console.c          | 323
> +++++++++++++++++++++++++++++++++++++++++
>  src/xencons/console.h          |  80 ++++++++++
>  src/xencons/fdo.c              | 260 +++++++--------------------------
>  vs2015/xencons/xencons.vcxproj |   1 +
>  4 files changed, 454 insertions(+), 210 deletions(-)
>  create mode 100755 src/xencons/console.c
>  create mode 100755 src/xencons/console.h
> 
> diff --git a/src/xencons/console.c b/src/xencons/console.c
> new file mode 100755
> index 0000000..e26e1db
> --- /dev/null
> +++ b/src/xencons/console.c
> @@ -0,0 +1,323 @@
> +/* Copyright (c) Citrix Systems Inc.
> +* All rights reserved.
> +*
> +* Redistribution and use in source and binary forms,
> +* with or without modification, are permitted provided
> +* that the following conditions are met:
> +*
> +* *   Redistributions of source code must retain the above
> +*     copyright notice, this list of conditions and the
> +*     following disclaimer.
> +* *   Redistributions in binary form must reproduce the above
> +*     copyright notice, this list of conditions and the
> +*     following disclaimer in the documentation and/or other
> +*     materials provided with the distribution.
> +*
> +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
> +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
> +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
> +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
> +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> +* SUCH DAMAGE.
> +*/
> +
> +#include <ntddk.h>
> +
> +#include "driver.h"
> +#include "console.h"
> +#include "stream.h"
> +#include "dbg_print.h"
> +#include "assert.h"
> +#include "util.h"
> +
> +struct _XENCONS_CONSOLE {
> +    PXENCONS_FDO        Fdo;
> +    LIST_ENTRY          List;
> +    KSPIN_LOCK          Lock;
> +};
> +
> +typedef struct _XENCONS_HANDLE {
> +    LIST_ENTRY      ListEntry;
> +    PFILE_OBJECT    FileObject;
> +    PXENCONS_STREAM Stream;
> +} XENCONS_HANDLE, *PXENCONS_HANDLE;
> +
> +#define CONSOLE_POOL 'SNOC'
> +
> +static FORCEINLINE PVOID
> +__ConsoleAllocate(
> +    IN  ULONG   Length
> +    )
> +{
> +    return __AllocatePoolWithTag(NonPagedPool, Length, CONSOLE_POOL);
> +}
> +
> +static FORCEINLINE VOID
> +__ConsoleFree(
> +    IN  PVOID   Buffer
> +    )
> +{
> +    __FreePoolWithTag(Buffer, CONSOLE_POOL);
> +}
> +
> +static VOID
> +__ConsoleDestroyHandle(
> +    IN  PXENCONS_CONSOLE    Console,
> +    IN  PXENCONS_HANDLE     Handle
> +    )
> +{
> +    UNREFERENCED_PARAMETER(Console);
> +
> +    Trace("%p\n", Handle->FileObject);
> +
> +    RtlZeroMemory(&Handle->ListEntry, sizeof(LIST_ENTRY));
> +
> +    StreamDestroy(Handle->Stream);
> +    Handle->Stream = NULL;
> +
> +    Handle->FileObject = NULL;
> +
> +    ASSERT(IsZeroMemory(Handle, sizeof(XENCONS_HANDLE)));
> +    __ConsoleFree(Handle);
> +}
> +
> +static PXENCONS_HANDLE
> +__ConsoleFindHandle(
> +    IN  PXENCONS_CONSOLE    Console,
> +    IN  PFILE_OBJECT        FileObject
> +    )
> +{
> +    KIRQL                   Irql;
> +    PLIST_ENTRY             ListEntry;
> +    PXENCONS_HANDLE         Handle;
> +    NTSTATUS                status;
> +
> +    KeAcquireSpinLock(&Console->Lock, &Irql);
> +
> +    for (ListEntry = Console->List.Flink;
> +         ListEntry != &Console->List;
> +         ListEntry = ListEntry->Flink) {
> +        Handle = CONTAINING_RECORD(ListEntry,
> +                                   XENCONS_HANDLE,
> +                                   ListEntry);
> +
> +        if (Handle->FileObject == FileObject)
> +            goto found;
> +    }
> +
> +    status = STATUS_UNSUCCESSFUL;
> +    goto fail1;
> +
> +found:
> +    KeReleaseSpinLock(&Console->Lock, Irql);
> +
> +    return Handle;
> +
> +fail1:
> +    Error("fail1 (%08x)\n", status);
> +
> +    KeReleaseSpinLock(&Console->Lock, Irql);
> +
> +    return NULL;
> +}
> +
> +NTSTATUS
> +ConsoleDispatchCreate(
> +    IN  PXENCONS_CONSOLE    Console,
> +    IN  PFILE_OBJECT        FileObject
> +    )

Not a fan of the naming ('cos I don't like Windows's naming). Could we have 
ConsoleOpen()...

> +{
> +    PXENCONS_HANDLE         Handle;
> +    KIRQL                   Irql;
> +    NTSTATUS                status;
> +
> +    ASSERT(__ConsoleFindHandle(Console, FileObject) == NULL);
> +
> +    Handle = __ConsoleAllocate(sizeof(XENCONS_HANDLE));
> +
> +    status = STATUS_NO_MEMORY;
> +    if (Handle == NULL)
> +        goto fail1;
> +
> +    status = StreamCreate(Console->Fdo, &Handle->Stream);
> +    if (!NT_SUCCESS(status))
> +        goto fail2;
> +
> +    Handle->FileObject = FileObject;
> +
> +    KeAcquireSpinLock(&Console->Lock, &Irql);
> +    InsertTailList(&Console->List, &Handle->ListEntry);
> +    KeReleaseSpinLock(&Console->Lock, Irql);
> +
> +    Trace("%p\n", Handle->FileObject);
> +
> +    return STATUS_SUCCESS;
> +
> +fail2:
> +    Error("fail2\n");
> +
> +    ASSERT(IsZeroMemory(Handle, sizeof(XENCONS_HANDLE)));
> +    __ConsoleFree(Handle);
> +
> +fail1:
> +    Error("fail1 (%08x)\n", status);
> +
> +    return status;
> +}
> +
> +NTSTATUS
> +ConsoleDispatchCleanup(
> +    IN  PXENCONS_CONSOLE    Console,
> +    IN  PFILE_OBJECT        FileObject
> +    )

...and ConsoleClose()?

> +{
> +    PXENCONS_HANDLE         Handle;
> +    KIRQL                   Irql;
> +    NTSTATUS                status;
> +
> +    Handle = __ConsoleFindHandle(Console, FileObject);
> +    status = STATUS_UNSUCCESSFUL;
> +
> +    if (Handle == NULL)
> +        goto fail1;
> +
> +    KeAcquireSpinLock(&Console->Lock, &Irql);
> +    RemoveEntryList(&Handle->ListEntry);
> +    KeReleaseSpinLock(&Console->Lock, Irql);
> +
> +    __ConsoleDestroyHandle(Console, Handle);
> +
> +    return STATUS_SUCCESS;
> +
> +fail1:
> +    Error("fail1 (%08x)\n", status);
> +
> +    return status;
> +}
> +
> +NTSTATUS
> +ConsoleDispatchReadWrite(
> +    IN  PXENCONS_CONSOLE    Console,
> +    IN  PIRP                Irp

How about just ConsolePutQueue() or somesuch. I guess this function could be 
used for DEVICE_CONTROL IRPs too?

  Paul

> +    )
> +{
> +    PIO_STACK_LOCATION      StackLocation;
> +    PXENCONS_HANDLE         Handle;
> +    NTSTATUS                status;
> +
> +    StackLocation = IoGetCurrentIrpStackLocation(Irp);
> +
> +    Handle = __ConsoleFindHandle(Console, StackLocation->FileObject);
> +    status = STATUS_UNSUCCESSFUL;
> +
> +    if (Handle == NULL)
> +        goto fail1;
> +
> +    status = StreamPutQueue(Handle->Stream, Irp);
> +    if (!NT_SUCCESS(status))
> +        goto fail2;
> +
> +    return STATUS_SUCCESS;
> +
> +fail2:
> +    Error("fail2\n");
> +
> +fail1:
> +    Error("fail1 (%08x)\n", status);
> +
> +    return status;
> +}
> +
> +NTSTATUS
> +ConsoleEnable(
> +    IN  PXENCONS_CONSOLE    Console
> +    )
> +{
> +    UNREFERENCED_PARAMETER(Console);
> +    return STATUS_SUCCESS;
> +}
> +
> +VOID
> +ConsoleDisable(
> +    IN  PXENCONS_CONSOLE    Console
> +    )
> +{
> +    KIRQL                   Irql;
> +    LIST_ENTRY              List;
> +    PLIST_ENTRY             ListEntry;
> +    PXENCONS_HANDLE         Handle;
> +
> +    InitializeListHead(&List);
> +
> +    KeAcquireSpinLock(&Console->Lock, &Irql);
> +
> +    ListEntry = Console->List.Flink;
> +    if (!IsListEmpty(&Console->List)) {
> +        RemoveEntryList(&Console->List);
> +        InitializeListHead(&Console->List);
> +        AppendTailList(&List, ListEntry);
> +    }
> +
> +    KeReleaseSpinLock(&Console->Lock, Irql);
> +
> +    while (!IsListEmpty(&List)) {
> +        ListEntry = RemoveHeadList(&List);
> +        ASSERT3P(ListEntry, != , &List);
> +
> +        Handle = CONTAINING_RECORD(ListEntry,
> +                                   XENCONS_HANDLE,
> +                                   ListEntry);
> +
> +        __ConsoleDestroyHandle(Console, Handle);
> +    }
> +}
> +
> +NTSTATUS
> +ConsoleCreate(
> +    IN  PXENCONS_FDO        Fdo,
> +    OUT PXENCONS_CONSOLE    *Console
> +    )
> +{
> +    NTSTATUS                status;
> +
> +    *Console = __ConsoleAllocate(sizeof(XENCONS_CONSOLE));
> +
> +    status = STATUS_NO_MEMORY;
> +    if (*Console == NULL)
> +        goto fail1;
> +
> +    (*Console)->Fdo = Fdo;
> +    InitializeListHead(&(*Console)->List);
> +    KeInitializeSpinLock(&(*Console)->Lock);
> +
> +    return STATUS_SUCCESS;
> +
> +fail1:
> +    Error("fail1 (%08x)\n", status);
> +
> +    return status;
> +}
> +
> +VOID
> +ConsoleDestroy(
> +    IN  PXENCONS_CONSOLE    Console
> +    )
> +{
> +    RtlZeroMemory(&Console->Lock, sizeof(KSPIN_LOCK));
> +
> +    ASSERT(IsListEmpty(&Console->List));
> +    RtlZeroMemory(&Console->List, sizeof(LIST_ENTRY));
> +
> +    Console->Fdo = NULL;
> +
> +    ASSERT(IsZeroMemory(Console, sizeof(XENCONS_CONSOLE)));
> +    __ConsoleFree(Console);
> +}
> diff --git a/src/xencons/console.h b/src/xencons/console.h
> new file mode 100755
> index 0000000..e295a69
> --- /dev/null
> +++ b/src/xencons/console.h
> @@ -0,0 +1,80 @@
> +/* Copyright (c) Citrix Systems Inc.
> +* All rights reserved.
> +*
> +* Redistribution and use in source and binary forms,
> +* with or without modification, are permitted provided
> +* that the following conditions are met:
> +*
> +* *   Redistributions of source code must retain the above
> +*     copyright notice, this list of conditions and the
> +*     following disclaimer.
> +* *   Redistributions in binary form must reproduce the above
> +*     copyright notice, this list of conditions and the
> +*     following disclaimer in the documentation and/or other
> +*     materials provided with the distribution.
> +*
> +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
> +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
> +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
> +* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
> +* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> +* SUCH DAMAGE.
> +*/
> +
> +#ifndef _XENCONS_CONSOLE_H
> +#define _XENCONS_CONSOLE_H
> +
> +#include <ntddk.h>
> +
> +#include "driver.h"
> +
> +typedef struct _XENCONS_CONSOLE XENCONS_CONSOLE,
> *PXENCONS_CONSOLE;
> +
> +extern NTSTATUS
> +ConsoleCreate(
> +    IN  PXENCONS_FDO        Fdo,
> +    OUT PXENCONS_CONSOLE    *Console
> +    );
> +
> +extern VOID
> +ConsoleDestroy(
> +    IN  PXENCONS_CONSOLE    Console
> +    );
> +
> +extern NTSTATUS
> +ConsoleEnable(
> +    IN  PXENCONS_CONSOLE    Console
> +    );
> +
> +extern VOID
> +ConsoleDisable(
> +    IN  PXENCONS_CONSOLE    Console
> +    );
> +
> +extern NTSTATUS
> +ConsoleDispatchCreate(
> +    IN  PXENCONS_CONSOLE    Console,
> +    IN  PFILE_OBJECT        FileObject
> +    );
> +
> +extern NTSTATUS
> +ConsoleDispatchCleanup(
> +    IN  PXENCONS_CONSOLE    Console,
> +    IN  PFILE_OBJECT        FileObject
> +    );
> +
> +extern NTSTATUS
> +ConsoleDispatchReadWrite(
> +    IN  PXENCONS_CONSOLE    Console,
> +    IN  PIRP                Irp
> +    );
> +
> +#endif  // _XENCONS_CONSOLE_H
> diff --git a/src/xencons/fdo.c b/src/xencons/fdo.c
> index 94465a5..6a7f70c 100644
> --- a/src/xencons/fdo.c
> +++ b/src/xencons/fdo.c
> @@ -47,7 +47,7 @@
>  #include "driver.h"
>  #include "registry.h"
>  #include "fdo.h"
> -#include "stream.h"
> +#include "console.h"
>  #include "thread.h"
>  #include "names.h"
>  #include "dbg_print.h"
> @@ -69,12 +69,6 @@ typedef struct _FDO_RESOURCE {
>      CM_PARTIAL_RESOURCE_DESCRIPTOR Translated;
>  } FDO_RESOURCE, *PFDO_RESOURCE;
> 
> -typedef struct _FDO_HANDLE {
> -    LIST_ENTRY      ListEntry;
> -    PFILE_OBJECT    FileObject;
> -    PXENCONS_STREAM Stream;
> -} FDO_HANDLE, *PFDO_HANDLE;
> -
>  struct _XENCONS_FDO {
>      PXENCONS_DX                 Dx;
>      PDEVICE_OBJECT              LowerDeviceObject;
> @@ -93,8 +87,7 @@ struct _XENCONS_FDO {
> 
>      FDO_RESOURCE                Resource[RESOURCE_COUNT];
> 
> -    LIST_ENTRY                  HandleList;
> -    KSPIN_LOCK                  HandleLock;
> +    PXENCONS_CONSOLE            Console;
> 
>      XENBUS_DEBUG_INTERFACE      DebugInterface;
>      XENBUS_SUSPEND_INTERFACE    SuspendInterface;
> @@ -788,18 +781,31 @@ fail1:
>      return status;
>  }
> 
> -static FORCEINLINE VOID
> +static FORCEINLINE NTSTATUS
>  __FdoD3ToD0(
>      IN  PXENCONS_FDO    Fdo
>      )
>  {
> +    NTSTATUS            status;
> +
>      Trace("====>\n");
> 
>      ASSERT3U(KeGetCurrentIrql(), ==, DISPATCH_LEVEL);
> 
> +    status = ConsoleEnable(Fdo->Console);
> +    if (!NT_SUCCESS(status))
> +        goto fail1;
> +
>      (VOID) FdoSetDistribution(Fdo);
> 
>      Trace("<====\n");
> +
> +    return STATUS_SUCCESS;
> +
> +fail1:
> +    Error("fail1 (%08x)\n", status);
> +
> +    return status;
>  }
> 
>  static FORCEINLINE VOID
> @@ -813,6 +819,8 @@ __FdoD0ToD3(
> 
>      FdoClearDistribution(Fdo);
> 
> +    ConsoleDisable(Fdo->Console);
> +
>      Trace("<====\n");
>  }
> 
> @@ -822,9 +830,12 @@ FdoSuspendCallbackLate(
>      )
>  {
>      PXENCONS_FDO    Fdo = Argument;
> +    NTSTATUS        status;
> 
>      __FdoD0ToD3(Fdo);
> -    __FdoD3ToD0(Fdo);
> +
> +    status = __FdoD3ToD0(Fdo);
> +    ASSERT(NT_SUCCESS(status));
>  }
> 
>  // This function must not touch pageable code or data
> @@ -853,7 +864,9 @@ FdoD3ToD0(
>      if (!NT_SUCCESS(status))
>          goto fail2;
> 
> -    __FdoD3ToD0(Fdo);
> +    status = __FdoD3ToD0(Fdo);
> +    if (!NT_SUCCESS(status))
> +        goto fail3;
> 
>      status = XENBUS_SUSPEND(Register,
>                              &Fdo->SuspendInterface,
> @@ -862,7 +875,7 @@ FdoD3ToD0(
>                              Fdo,
>                              &Fdo->SuspendCallbackLate);
>      if (!NT_SUCCESS(status))
> -        goto fail3;
> +        goto fail4;
> 
>      KeLowerIrql(Irql);
> 
> @@ -880,11 +893,14 @@ FdoD3ToD0(
> 
>      return STATUS_SUCCESS;
> 
> -fail3:
> +fail4:
>      Error("fail4\n");
> 
>      __FdoD0ToD3(Fdo);
> 
> +fail3:
> +    Error("fail3\n");
> +
>      XENBUS_STORE(Release, &Fdo->StoreInterface);
> 
>  fail2:
> @@ -902,77 +918,6 @@ fail1:
>      return status;
>  }
> 
> -static FORCEINLINE VOID
> -__FdoDestroyHandle(
> -    IN  PXENCONS_FDO    Fdo,
> -    IN  PFDO_HANDLE     Handle
> -    )
> -{
> -    UNREFERENCED_PARAMETER(Fdo);
> -
> -    Trace("%p\n", Handle->FileObject);
> -
> -    RtlZeroMemory(&Handle->ListEntry, sizeof (LIST_ENTRY));
> -
> -    StreamDestroy(Handle->Stream);
> -    Handle->Stream = NULL;
> -
> -    Handle->FileObject = NULL;
> -
> -    ASSERT(IsZeroMemory(Handle, sizeof (FDO_HANDLE)));
> -    __FdoFree(Handle);
> -}
> -
> -static VOID
> -FdoDestroyHandle(
> -    IN  PXENCONS_FDO    Fdo,
> -    IN  PFDO_HANDLE     Handle
> -    )
> -{
> -    KIRQL               Irql;
> -
> -    KeAcquireSpinLock(&Fdo->HandleLock, &Irql);
> -    RemoveEntryList(&Handle->ListEntry);
> -    KeReleaseSpinLock(&Fdo->HandleLock, Irql);
> -
> -    __FdoDestroyHandle(Fdo, Handle);
> -}
> -
> -static VOID
> -FdoDestroyAllHandles(
> -    IN  PXENCONS_FDO    Fdo
> -    )
> -{
> -    KIRQL               Irql;
> -    LIST_ENTRY          List;
> -    PLIST_ENTRY         ListEntry;
> -    PFDO_HANDLE         Handle;
> -
> -    InitializeListHead(&List);
> -
> -    KeAcquireSpinLock(&Fdo->HandleLock, &Irql);
> -
> -    ListEntry = Fdo->HandleList.Flink;
> -    if (!IsListEmpty(&Fdo->HandleList)) {
> -        RemoveEntryList(&Fdo->HandleList);
> -        InitializeListHead(&Fdo->HandleList);
> -        AppendTailList(&List, ListEntry);
> -    }
> -
> -    KeReleaseSpinLock(&Fdo->HandleLock, Irql);
> -
> -    while (!IsListEmpty(&List)) {
> -        ListEntry = RemoveHeadList(&List);
> -        ASSERT3P(ListEntry, !=, &List);
> -
> -        Handle = CONTAINING_RECORD(ListEntry,
> -                                   FDO_HANDLE,
> -                                   ListEntry);
> -
> -        __FdoDestroyHandle(Fdo, Handle);
> -    }
> -}
> -
>  // This function must not touch pageable code or data
>  static DECLSPEC_NOINLINE VOID
>  FdoD0ToD3(
> @@ -991,8 +936,6 @@ FdoD0ToD3(
>  #pragma prefast(suppress:28123)
>      (VOID) IoSetDeviceInterfaceState(&Dx->Link, FALSE);
> 
> -    FdoDestroyAllHandles(Fdo);
> -
>      PowerState.DeviceState = PowerDeviceD3;
>      PoSetPowerState(Fdo->Dx->DeviceObject,
>                      DevicePowerState,
> @@ -2166,88 +2109,6 @@ done:
>      return status;
>  }
> 
> -static NTSTATUS
> -FdoCreateHandle(
> -    IN  PXENCONS_FDO    Fdo,
> -    IN  PFILE_OBJECT    FileObject
> -    )
> -{
> -    PFDO_HANDLE         Handle;
> -    KIRQL               Irql;
> -    NTSTATUS            status;
> -
> -    Handle = __FdoAllocate(sizeof (FDO_HANDLE));
> -
> -    status = STATUS_NO_MEMORY;
> -    if (Handle == NULL)
> -        goto fail1;
> -
> -    status = StreamCreate(Fdo, &Handle->Stream);
> -    if (!NT_SUCCESS(status))
> -        goto fail2;
> -
> -    Handle->FileObject = FileObject;
> -
> -    KeAcquireSpinLock(&Fdo->HandleLock, &Irql);
> -    InsertTailList(&Fdo->HandleList, &Handle->ListEntry);
> -    KeReleaseSpinLock(&Fdo->HandleLock, Irql);
> -
> -    Trace("%p\n", Handle->FileObject);
> -
> -    return STATUS_SUCCESS;
> -
> -fail2:
> -    Error("fail2\n");
> -
> -    ASSERT(IsZeroMemory(Handle, sizeof (FDO_HANDLE)));
> -    __FdoFree(Handle);
> -
> -fail1:
> -    Error("fail1 (%08x)\n", status);
> -
> -    return status;
> -}
> -
> -static PFDO_HANDLE
> -FdoFindHandle(
> -    IN  PXENCONS_FDO    Fdo,
> -    IN  PFILE_OBJECT    FileObject
> -    )
> -{
> -    KIRQL               Irql;
> -    PLIST_ENTRY         ListEntry;
> -    PFDO_HANDLE         Handle;
> -    NTSTATUS            status;
> -
> -    KeAcquireSpinLock(&Fdo->HandleLock, &Irql);
> -
> -    for (ListEntry = Fdo->HandleList.Flink;
> -         ListEntry != &Fdo->HandleList;
> -         ListEntry = ListEntry->Flink) {
> -        Handle = CONTAINING_RECORD(ListEntry,
> -                                   FDO_HANDLE,
> -                                   ListEntry);
> -
> -        if (Handle->FileObject == FileObject)
> -            goto found;
> -    }
> -
> -    status = STATUS_UNSUCCESSFUL;
> -    goto fail1;
> -
> -found:
> -    KeReleaseSpinLock(&Fdo->HandleLock, Irql);
> -
> -    return Handle;
> -
> -fail1:
> -    Error("fail1 (%08x)\n", status);
> -
> -    KeReleaseSpinLock(&Fdo->HandleLock, Irql);
> -
> -    return NULL;
> -}
> -
>  static DECLSPEC_NOINLINE NTSTATUS
>  FdoDispatchCreate(
>      IN  PXENCONS_FDO    Fdo,
> @@ -2259,7 +2120,8 @@ FdoDispatchCreate(
> 
>      StackLocation = IoGetCurrentIrpStackLocation(Irp);
> 
> -    status = FdoCreateHandle(Fdo, StackLocation->FileObject);
> +    status = ConsoleDispatchCreate(Fdo->Console,
> +                                   StackLocation->FileObject);
> 
>      Irp->IoStatus.Status = status;
>      IoCompleteRequest(Irp, IO_NO_INCREMENT);
> @@ -2274,27 +2136,12 @@ FdoDispatchCleanup(
>      )
>  {
>      PIO_STACK_LOCATION  StackLocation;
> -    PFDO_HANDLE         Handle;
>      NTSTATUS            status;
> 
>      StackLocation = IoGetCurrentIrpStackLocation(Irp);
> 
> -    Handle = FdoFindHandle(Fdo, StackLocation->FileObject);
> -
> -    status = STATUS_UNSUCCESSFUL;
> -    if (Handle == NULL)
> -        goto fail1;
> -
> -    FdoDestroyHandle(Fdo, Handle);
> -    status = STATUS_SUCCESS;
> -
> -    Irp->IoStatus.Status = status;
> -    IoCompleteRequest(Irp, IO_NO_INCREMENT);
> -
> -    return status;
> -
> -fail1:
> -    Error("fail1 (%08x)\n", status);
> +    status = ConsoleDispatchCleanup(Fdo->Console,
> +                                    StackLocation->FileObject);
> 
>      Irp->IoStatus.Status = status;
>      IoCompleteRequest(Irp, IO_NO_INCREMENT);
> @@ -2326,29 +2173,17 @@ FdoDispatchReadWrite(
>      IN  PIRP            Irp
>      )
>  {
> -    PIO_STACK_LOCATION  StackLocation;
> -    PFDO_HANDLE         Handle;
>      NTSTATUS            status;
> 
> -    StackLocation = IoGetCurrentIrpStackLocation(Irp);
> -
> -    Handle = FdoFindHandle(Fdo, StackLocation->FileObject);
> -
> -    status = STATUS_UNSUCCESSFUL;
> -    if (Handle == NULL)
> -        goto fail1;
> -
>      IoMarkIrpPending(Irp);
> 
> -    status = StreamPutQueue(Handle->Stream, Irp);
> +    status = ConsoleDispatchReadWrite(Fdo->Console,
> +                                      Irp);
>      if (!NT_SUCCESS(status))
> -        goto fail2;
> +        goto fail1;
> 
>      return STATUS_PENDING;
> 
> -fail2:
> -    Error("fail2\n");
> -
>  fail1:
>      Error("fail1 (%08x)\n", status);
> 
> @@ -2641,8 +2476,9 @@ FdoCreate(
>      if (!NT_SUCCESS(status))
>          goto fail11;
> 
> -    InitializeListHead(&Fdo->HandleList);
> -    KeInitializeSpinLock(&Fdo->HandleLock);
> +    status = ConsoleCreate(Fdo, &Fdo->Console);
> +    if (!NT_SUCCESS(status))
> +        goto fail12;
> 
>      FunctionDeviceObject->Flags |= DO_BUFFERED_IO;
> 
> @@ -2655,11 +2491,17 @@ FdoCreate(
>      FunctionDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
>      return STATUS_SUCCESS;
> 
> +fail12:
> +    Error("fail12\n");
> +
> +    RtlZeroMemory(&Fdo->ConsoleInterface,
> +                  sizeof(XENBUS_CONSOLE_INTERFACE));
> +
>  fail11:
>      Error("fail11\n");
> 
> -    RtlZeroMemory(&Fdo->ConsoleInterface,
> -                  sizeof (XENBUS_CONSOLE_INTERFACE));
> +    RtlZeroMemory(&Fdo->StoreInterface,
> +                  sizeof (XENBUS_STORE_INTERFACE));
> 
>  fail10:
>      Error("fail10\n");
> @@ -2744,10 +2586,8 @@ FdoDestroy(
> 
>      Dx->Fdo = NULL;
> 
> -    RtlZeroMemory(&Fdo->HandleLock, sizeof (KSPIN_LOCK));
> -
> -    ASSERT(IsListEmpty(&Fdo->HandleList));
> -    RtlZeroMemory(&Fdo->HandleList, sizeof (LIST_ENTRY));
> +    ConsoleDestroy(Fdo->Console);
> +    Fdo->Console = NULL;
> 
>      RtlZeroMemory(&Fdo->ConsoleInterface,
>                    sizeof (XENBUS_CONSOLE_INTERFACE));
> diff --git a/vs2015/xencons/xencons.vcxproj
> b/vs2015/xencons/xencons.vcxproj
> index ff65d9f..12f5b70 100644
> --- a/vs2015/xencons/xencons.vcxproj
> +++ b/vs2015/xencons/xencons.vcxproj
> @@ -67,6 +67,7 @@
>      <ClCompile Include="../../src/xencons/driver.c" />
>      <ClCompile Include="../../src/xencons/fdo.c" />
>      <ClCompile Include="../../src/xencons/registry.c" />
> +    <ClCompile Include="../../src/xencons/console.c" />
>      <ClCompile Include="../../src/xencons/stream.c" />
>      <ClCompile Include="../../src/xencons/thread.c" />
>    </ItemGroup>
> --
> 2.8.3
> 
> 
> _______________________________________________
> win-pv-devel mailing list
> win-pv-devel@xxxxxxxxxxxxxxxxxxxx
> https://lists.xenproject.org/mailman/listinfo/win-pv-devel
_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/win-pv-devel

 


Rackspace

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