[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 1/5] Move util.h from include to src/xenvif
It should be co-located with headers such as assert.h and names.h Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> --- include/util.h | 343 ----------------------------------------------- src/xenvif/bus.c | 2 +- src/xenvif/checksum.c | 3 +- src/xenvif/driver.c | 2 +- src/xenvif/fdo.c | 2 +- src/xenvif/frontend.c | 2 +- src/xenvif/link.c | 2 +- src/xenvif/mac.c | 2 +- src/xenvif/parse.c | 3 +- src/xenvif/pdo.c | 3 +- src/xenvif/receiver.c | 7 +- src/xenvif/registry.c | 2 +- src/xenvif/thread.c | 2 +- src/xenvif/transmitter.c | 7 +- src/xenvif/util.h | 343 +++++++++++++++++++++++++++++++++++++++++++++++ src/xenvif/vif.c | 2 +- 16 files changed, 366 insertions(+), 361 deletions(-) delete mode 100644 include/util.h create mode 100644 src/xenvif/util.h diff --git a/include/util.h b/include/util.h deleted file mode 100644 index c008960..0000000 --- a/include/util.h +++ /dev/null @@ -1,343 +0,0 @@ -/* 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 _UTIL_H -#define _UTIL_H - -#include <ntddk.h> - -#include "assert.h" - -#define P2ROUNDUP(_x, _a) \ - (-(-(_x) & -(_a))) - -static FORCEINLINE LONG -__ffs( - IN unsigned long long mask - ) -{ - unsigned char *array = (unsigned char *)&mask; - unsigned int byte; - unsigned int bit; - unsigned char val; - - val = 0; - - byte = 0; - while (byte < 8) { - val = array[byte]; - - if (val != 0) - break; - - byte++; - } - if (byte == 8) - return -1; - - bit = 0; - while (bit < 8) { - if (val & 0x01) - break; - - val >>= 1; - bit++; - } - - return (byte * 8) + bit; -} - -#define __ffu(_mask) \ - __ffs(~(_mask)) - -static FORCEINLINE VOID -__CpuId( - IN ULONG Leaf, - OUT PULONG EAX OPTIONAL, - OUT PULONG EBX OPTIONAL, - OUT PULONG ECX OPTIONAL, - OUT PULONG EDX OPTIONAL - ) -{ - ULONG Value[4] = {0}; - - __cpuid(Value, Leaf); - - if (EAX) - *EAX = Value[0]; - - if (EBX) - *EBX = Value[1]; - - if (ECX) - *ECX = Value[2]; - - if (EDX) - *EDX = Value[3]; -} - -static FORCEINLINE LONG -__InterlockedAdd( - IN LONG *Value, - IN LONG Delta - ) -{ - LONG New; - LONG Old; - - do { - Old = *Value; - New = Old + Delta; - } while (InterlockedCompareExchange(Value, New, Old) != Old); - - return New; -} - -static FORCEINLINE LONG -__InterlockedSubtract( - IN LONG *Value, - IN LONG Delta - ) -{ - LONG New; - LONG Old; - - do { - Old = *Value; - New = Old - Delta; - } while (InterlockedCompareExchange(Value, New, Old) != Old); - - return New; -} - -typedef struct _NON_PAGED_BUFFER_HEADER { - SIZE_T Length; - ULONG Tag; -} NON_PAGED_BUFFER_HEADER, *PNON_PAGED_BUFFER_HEADER; - -typedef struct _NON_PAGED_BUFFER_TRAILER { - ULONG Tag; -} NON_PAGED_BUFFER_TRAILER, *PNON_PAGED_BUFFER_TRAILER; - -static FORCEINLINE PVOID -__AllocateNonPagedPoolWithTag( - IN SIZE_T Length, - IN ULONG Tag - ) -{ - PUCHAR Buffer; - PNON_PAGED_BUFFER_HEADER Header; - PNON_PAGED_BUFFER_TRAILER Trailer; - - ASSERT(Length != 0); - - Buffer = ExAllocatePoolWithTag(NonPagedPool, - sizeof (NON_PAGED_BUFFER_HEADER) + - Length + - sizeof (NON_PAGED_BUFFER_TRAILER), - Tag); - if (Buffer == NULL) - goto done; - - RtlZeroMemory(Buffer, - sizeof (NON_PAGED_BUFFER_HEADER) + - Length + - sizeof (NON_PAGED_BUFFER_TRAILER)); - - Header = (PNON_PAGED_BUFFER_HEADER)Buffer; - Header->Length = Length; - Header->Tag = Tag; - - Buffer += sizeof (NON_PAGED_BUFFER_HEADER); - - Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length); - Trailer->Tag = Tag; - -done: - return Buffer; -} - -static FORCEINLINE VOID -__FreePoolWithTag( - IN PVOID _Buffer, - IN ULONG Tag - ) -{ - PUCHAR Buffer = _Buffer; - SIZE_T Length; - PNON_PAGED_BUFFER_HEADER Header; - PNON_PAGED_BUFFER_TRAILER Trailer; - - ASSERT(Buffer != NULL); - - Buffer -= sizeof (NON_PAGED_BUFFER_HEADER); - - Header = (PNON_PAGED_BUFFER_HEADER)Buffer; - ASSERT3U(Tag, ==, Header->Tag); - Length = Header->Length; - - Buffer += sizeof (NON_PAGED_BUFFER_HEADER); - - Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length); - ASSERT3U(Tag, ==, Trailer->Tag); - - Buffer -= sizeof (NON_PAGED_BUFFER_HEADER); - - RtlFillMemory(Buffer, - sizeof (NON_PAGED_BUFFER_HEADER) + - Length + - sizeof (NON_PAGED_BUFFER_TRAILER), - 0xAA); - - ExFreePoolWithTag(Buffer, Tag); -} - -static FORCEINLINE PMDL -__AllocatePage( - VOID - ) -{ - PHYSICAL_ADDRESS LowAddress; - PHYSICAL_ADDRESS HighAddress; - LARGE_INTEGER SkipBytes; - SIZE_T TotalBytes; - PMDL Mdl; - PUCHAR MdlMappedSystemVa; - NTSTATUS status; - - LowAddress.QuadPart = 0ull; - HighAddress.QuadPart = ~0ull; - SkipBytes.QuadPart = 0ull; - TotalBytes = (SIZE_T)PAGE_SIZE; - - Mdl = MmAllocatePagesForMdlEx(LowAddress, - HighAddress, - SkipBytes, - TotalBytes, - MmCached, - 0); - - status = STATUS_NO_MEMORY; - if (Mdl == NULL) - goto fail1; - - ASSERT((Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | - MDL_PARTIAL_HAS_BEEN_MAPPED | - MDL_PARTIAL | - MDL_PARENT_MAPPED_SYSTEM_VA | - MDL_SOURCE_IS_NONPAGED_POOL | - MDL_IO_SPACE)) == 0); - - MdlMappedSystemVa = MmMapLockedPagesSpecifyCache(Mdl, - KernelMode, - MmCached, - NULL, - FALSE, - NormalPagePriority); - - status = STATUS_UNSUCCESSFUL; - if (MdlMappedSystemVa == NULL) - goto fail2; - - ASSERT3P(MdlMappedSystemVa, ==, Mdl->MappedSystemVa); - - RtlZeroMemory(MdlMappedSystemVa, PAGE_SIZE); - - return Mdl; - -fail2: - Error("fail2\n"); - - MmFreePagesFromMdl(Mdl); - ExFreePool(Mdl); - -fail1: - Error("fail1 (%08x)\n", status); - - return NULL; -} - -static FORCEINLINE VOID -__FreePage( - IN PMDL Mdl - ) -{ - PUCHAR MdlMappedSystemVa; - - ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA); - MdlMappedSystemVa = Mdl->MappedSystemVa; - - RtlFillMemory(MdlMappedSystemVa, PAGE_SIZE, 0xAA); - - MmUnmapLockedPages(MdlMappedSystemVa, Mdl); - - MmFreePagesFromMdl(Mdl); -} - -static FORCEINLINE PCHAR -__strtok_r( - IN PCHAR Buffer, - IN PCHAR Delimiter, - IN OUT PCHAR *Context - ) -{ - PCHAR Token; - PCHAR End; - - if (Buffer != NULL) - *Context = Buffer; - - Token = *Context; - - if (Token == NULL) - return NULL; - - while (*Token != L'\0' && - strchr(Delimiter, *Token) != NULL) - Token++; - - if (*Token == L'\0') - return NULL; - - End = Token + 1; - while (*End != L'\0' && - strchr(Delimiter, *End) == NULL) - End++; - - if (*End != L'\0') - *End++ = L'\0'; - - *Context = End; - - return Token; -} - -#endif // _UTIL_H diff --git a/src/xenvif/bus.c b/src/xenvif/bus.c index 07229ed..9190535 100644 --- a/src/xenvif/bus.c +++ b/src/xenvif/bus.c @@ -32,13 +32,13 @@ #include <ntddk.h> #include <stdarg.h> #include <xen.h> -#include <util.h> #include "bus.h" #include "fdo.h" #include "pdo.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" typedef struct _XENVIF_BUS_CONTEXT { LONG References; diff --git a/src/xenvif/checksum.c b/src/xenvif/checksum.c index 19a9616..ad375f6 100644 --- a/src/xenvif/checksum.c +++ b/src/xenvif/checksum.c @@ -32,14 +32,15 @@ #include <ntddk.h> #include <ntstrsafe.h> #include <stdlib.h> -#include <util.h> #include <ethernet.h> #include <tcpip.h> + #include <vif_interface.h> #include "checksum.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" static FORCEINLINE VOID __AccumulateChecksum( diff --git a/src/xenvif/driver.c b/src/xenvif/driver.c index 083fa19..589bee9 100644 --- a/src/xenvif/driver.c +++ b/src/xenvif/driver.c @@ -30,7 +30,6 @@ */ #include <ntddk.h> -#include <util.h> #include <version.h> #include "registry.h" @@ -40,6 +39,7 @@ #include "driver.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" extern PULONG InitSafeBootMode; diff --git a/src/xenvif/fdo.c b/src/xenvif/fdo.c index 6b1aeff..4b40777 100644 --- a/src/xenvif/fdo.c +++ b/src/xenvif/fdo.c @@ -35,7 +35,6 @@ #include <wdmguid.h> #include <ntstrsafe.h> #include <stdlib.h> -#include <util.h> #include <evtchn_interface.h> #include <debug_interface.h> @@ -54,6 +53,7 @@ #include "names.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" #define FDO_POOL 'ODF' diff --git a/src/xenvif/frontend.c b/src/xenvif/frontend.c index 88e387f..12b9789 100644 --- a/src/xenvif/frontend.c +++ b/src/xenvif/frontend.c @@ -33,7 +33,6 @@ #include <ntstrsafe.h> #include <stdlib.h> #include <netioapi.h> -#include <util.h> #include <xen.h> #include "driver.h" @@ -50,6 +49,7 @@ #include "link.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" struct _XENVIF_FRONTEND { PXENVIF_PDO Pdo; diff --git a/src/xenvif/link.c b/src/xenvif/link.c index 27a502b..0319767 100644 --- a/src/xenvif/link.c +++ b/src/xenvif/link.c @@ -32,11 +32,11 @@ #include <ntddk.h> #include <ntstrsafe.h> #include <aux_klib.h> -#include <util.h> #include "link.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" #define LINK_TAG 'KNIL' diff --git a/src/xenvif/mac.c b/src/xenvif/mac.c index b745625..1d60a1f 100644 --- a/src/xenvif/mac.c +++ b/src/xenvif/mac.c @@ -32,7 +32,6 @@ #include <ntddk.h> #include <ntstrsafe.h> #include <stdlib.h> -#include <util.h> #include <ethernet.h> #include "pdo.h" @@ -41,6 +40,7 @@ #include "thread.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" struct _XENVIF_MAC { PXENVIF_FRONTEND Frontend; diff --git a/src/xenvif/parse.c b/src/xenvif/parse.c index 491f834..4e70ed4 100644 --- a/src/xenvif/parse.c +++ b/src/xenvif/parse.c @@ -31,16 +31,17 @@ #include <ntddk.h> #include <ntstrsafe.h> -#include <util.h> #include <ethernet.h> #include <tcpip.h> #include <llc.h> #include <ipx.h> + #include <vif_interface.h> #include "parse.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" static FORCEINLINE NTSTATUS __ParseTcpHeader( diff --git a/src/xenvif/pdo.c b/src/xenvif/pdo.c index 5ce6c50..369efb0 100644 --- a/src/xenvif/pdo.c +++ b/src/xenvif/pdo.c @@ -38,8 +38,8 @@ #include <stdlib.h> #include <netioapi.h> #include <bcrypt.h> -#include <util.h> #include <xen.h> + #include <store_interface.h> #include <emulated_interface.h> @@ -55,6 +55,7 @@ #include "link.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" #define PDO_POOL 'ODP' diff --git a/src/xenvif/receiver.c b/src/xenvif/receiver.c index 5318baf..6f45627 100644 --- a/src/xenvif/receiver.c +++ b/src/xenvif/receiver.c @@ -32,8 +32,10 @@ #include <ntddk.h> #include <ntstrsafe.h> #include <stdlib.h> -#include <util.h> #include <xen.h> +#include <ethernet.h> +#include <tcpip.h> + #include <debug_interface.h> #include <store_interface.h> #include <cache_interface.h> @@ -44,8 +46,6 @@ #define _NETRXF_gso_prefix (4) #define NETRXF_gso_prefix (1U<<_NETRXF_gso_prefix) -#include "ethernet.h" -#include "tcpip.h" #include "pdo.h" #include "registry.h" #include "frontend.h" @@ -59,6 +59,7 @@ #include "driver.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" #define MAXNAMELEN 128 diff --git a/src/xenvif/registry.c b/src/xenvif/registry.c index 519d3f6..7f1c4cc 100644 --- a/src/xenvif/registry.c +++ b/src/xenvif/registry.c @@ -30,10 +30,10 @@ */ #include <ntddk.h> -#include <util.h> #include "registry.h" #include "assert.h" +#include "util.h" #define REGISTRY_POOL 'GERX' diff --git a/src/xenvif/thread.c b/src/xenvif/thread.c index 12aa40e..2fa0c1c 100644 --- a/src/xenvif/thread.c +++ b/src/xenvif/thread.c @@ -30,11 +30,11 @@ */ #include <ntddk.h> -#include <util.h> #include "thread.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" #define THREAD_POOL 'ERHT' diff --git a/src/xenvif/transmitter.c b/src/xenvif/transmitter.c index 8fd7d2d..9f81ca1 100644 --- a/src/xenvif/transmitter.c +++ b/src/xenvif/transmitter.c @@ -33,8 +33,10 @@ #include <ntstrsafe.h> #include <stdlib.h> #include <netioapi.h> -#include <util.h> #include <xen.h> +#include <ethernet.h> +#include <tcpip.h> + #include <debug_interface.h> #include <store_interface.h> #include <cache_interface.h> @@ -42,8 +44,6 @@ #include <range_set_interface.h> #include <evtchn_interface.h> -#include "ethernet.h" -#include "tcpip.h" #include "pdo.h" #include "frontend.h" #include "checksum.h" @@ -55,6 +55,7 @@ #include "registry.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" #ifndef XEN_NETIF_GSO_TYPE_TCPV6 #define XEN_NETIF_GSO_TYPE_TCPV6 2 diff --git a/src/xenvif/util.h b/src/xenvif/util.h new file mode 100644 index 0000000..c008960 --- /dev/null +++ b/src/xenvif/util.h @@ -0,0 +1,343 @@ +/* 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 _UTIL_H +#define _UTIL_H + +#include <ntddk.h> + +#include "assert.h" + +#define P2ROUNDUP(_x, _a) \ + (-(-(_x) & -(_a))) + +static FORCEINLINE LONG +__ffs( + IN unsigned long long mask + ) +{ + unsigned char *array = (unsigned char *)&mask; + unsigned int byte; + unsigned int bit; + unsigned char val; + + val = 0; + + byte = 0; + while (byte < 8) { + val = array[byte]; + + if (val != 0) + break; + + byte++; + } + if (byte == 8) + return -1; + + bit = 0; + while (bit < 8) { + if (val & 0x01) + break; + + val >>= 1; + bit++; + } + + return (byte * 8) + bit; +} + +#define __ffu(_mask) \ + __ffs(~(_mask)) + +static FORCEINLINE VOID +__CpuId( + IN ULONG Leaf, + OUT PULONG EAX OPTIONAL, + OUT PULONG EBX OPTIONAL, + OUT PULONG ECX OPTIONAL, + OUT PULONG EDX OPTIONAL + ) +{ + ULONG Value[4] = {0}; + + __cpuid(Value, Leaf); + + if (EAX) + *EAX = Value[0]; + + if (EBX) + *EBX = Value[1]; + + if (ECX) + *ECX = Value[2]; + + if (EDX) + *EDX = Value[3]; +} + +static FORCEINLINE LONG +__InterlockedAdd( + IN LONG *Value, + IN LONG Delta + ) +{ + LONG New; + LONG Old; + + do { + Old = *Value; + New = Old + Delta; + } while (InterlockedCompareExchange(Value, New, Old) != Old); + + return New; +} + +static FORCEINLINE LONG +__InterlockedSubtract( + IN LONG *Value, + IN LONG Delta + ) +{ + LONG New; + LONG Old; + + do { + Old = *Value; + New = Old - Delta; + } while (InterlockedCompareExchange(Value, New, Old) != Old); + + return New; +} + +typedef struct _NON_PAGED_BUFFER_HEADER { + SIZE_T Length; + ULONG Tag; +} NON_PAGED_BUFFER_HEADER, *PNON_PAGED_BUFFER_HEADER; + +typedef struct _NON_PAGED_BUFFER_TRAILER { + ULONG Tag; +} NON_PAGED_BUFFER_TRAILER, *PNON_PAGED_BUFFER_TRAILER; + +static FORCEINLINE PVOID +__AllocateNonPagedPoolWithTag( + IN SIZE_T Length, + IN ULONG Tag + ) +{ + PUCHAR Buffer; + PNON_PAGED_BUFFER_HEADER Header; + PNON_PAGED_BUFFER_TRAILER Trailer; + + ASSERT(Length != 0); + + Buffer = ExAllocatePoolWithTag(NonPagedPool, + sizeof (NON_PAGED_BUFFER_HEADER) + + Length + + sizeof (NON_PAGED_BUFFER_TRAILER), + Tag); + if (Buffer == NULL) + goto done; + + RtlZeroMemory(Buffer, + sizeof (NON_PAGED_BUFFER_HEADER) + + Length + + sizeof (NON_PAGED_BUFFER_TRAILER)); + + Header = (PNON_PAGED_BUFFER_HEADER)Buffer; + Header->Length = Length; + Header->Tag = Tag; + + Buffer += sizeof (NON_PAGED_BUFFER_HEADER); + + Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length); + Trailer->Tag = Tag; + +done: + return Buffer; +} + +static FORCEINLINE VOID +__FreePoolWithTag( + IN PVOID _Buffer, + IN ULONG Tag + ) +{ + PUCHAR Buffer = _Buffer; + SIZE_T Length; + PNON_PAGED_BUFFER_HEADER Header; + PNON_PAGED_BUFFER_TRAILER Trailer; + + ASSERT(Buffer != NULL); + + Buffer -= sizeof (NON_PAGED_BUFFER_HEADER); + + Header = (PNON_PAGED_BUFFER_HEADER)Buffer; + ASSERT3U(Tag, ==, Header->Tag); + Length = Header->Length; + + Buffer += sizeof (NON_PAGED_BUFFER_HEADER); + + Trailer = (PNON_PAGED_BUFFER_TRAILER)(Buffer + Length); + ASSERT3U(Tag, ==, Trailer->Tag); + + Buffer -= sizeof (NON_PAGED_BUFFER_HEADER); + + RtlFillMemory(Buffer, + sizeof (NON_PAGED_BUFFER_HEADER) + + Length + + sizeof (NON_PAGED_BUFFER_TRAILER), + 0xAA); + + ExFreePoolWithTag(Buffer, Tag); +} + +static FORCEINLINE PMDL +__AllocatePage( + VOID + ) +{ + PHYSICAL_ADDRESS LowAddress; + PHYSICAL_ADDRESS HighAddress; + LARGE_INTEGER SkipBytes; + SIZE_T TotalBytes; + PMDL Mdl; + PUCHAR MdlMappedSystemVa; + NTSTATUS status; + + LowAddress.QuadPart = 0ull; + HighAddress.QuadPart = ~0ull; + SkipBytes.QuadPart = 0ull; + TotalBytes = (SIZE_T)PAGE_SIZE; + + Mdl = MmAllocatePagesForMdlEx(LowAddress, + HighAddress, + SkipBytes, + TotalBytes, + MmCached, + 0); + + status = STATUS_NO_MEMORY; + if (Mdl == NULL) + goto fail1; + + ASSERT((Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | + MDL_PARTIAL_HAS_BEEN_MAPPED | + MDL_PARTIAL | + MDL_PARENT_MAPPED_SYSTEM_VA | + MDL_SOURCE_IS_NONPAGED_POOL | + MDL_IO_SPACE)) == 0); + + MdlMappedSystemVa = MmMapLockedPagesSpecifyCache(Mdl, + KernelMode, + MmCached, + NULL, + FALSE, + NormalPagePriority); + + status = STATUS_UNSUCCESSFUL; + if (MdlMappedSystemVa == NULL) + goto fail2; + + ASSERT3P(MdlMappedSystemVa, ==, Mdl->MappedSystemVa); + + RtlZeroMemory(MdlMappedSystemVa, PAGE_SIZE); + + return Mdl; + +fail2: + Error("fail2\n"); + + MmFreePagesFromMdl(Mdl); + ExFreePool(Mdl); + +fail1: + Error("fail1 (%08x)\n", status); + + return NULL; +} + +static FORCEINLINE VOID +__FreePage( + IN PMDL Mdl + ) +{ + PUCHAR MdlMappedSystemVa; + + ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA); + MdlMappedSystemVa = Mdl->MappedSystemVa; + + RtlFillMemory(MdlMappedSystemVa, PAGE_SIZE, 0xAA); + + MmUnmapLockedPages(MdlMappedSystemVa, Mdl); + + MmFreePagesFromMdl(Mdl); +} + +static FORCEINLINE PCHAR +__strtok_r( + IN PCHAR Buffer, + IN PCHAR Delimiter, + IN OUT PCHAR *Context + ) +{ + PCHAR Token; + PCHAR End; + + if (Buffer != NULL) + *Context = Buffer; + + Token = *Context; + + if (Token == NULL) + return NULL; + + while (*Token != L'\0' && + strchr(Delimiter, *Token) != NULL) + Token++; + + if (*Token == L'\0') + return NULL; + + End = Token + 1; + while (*End != L'\0' && + strchr(Delimiter, *End) == NULL) + End++; + + if (*End != L'\0') + *End++ = L'\0'; + + *Context = End; + + return Token; +} + +#endif // _UTIL_H diff --git a/src/xenvif/vif.c b/src/xenvif/vif.c index 2375d82..35af384 100644 --- a/src/xenvif/vif.c +++ b/src/xenvif/vif.c @@ -33,7 +33,6 @@ #include <ntstrsafe.h> #include <stdarg.h> #include <xen.h> -#include <util.h> #include "pdo.h" #include "vif.h" @@ -41,6 +40,7 @@ #include "thread.h" #include "dbg_print.h" #include "assert.h" +#include "util.h" struct _XENVIF_VIF_CONTEXT { PXENVIF_PDO Pdo; -- 2.1.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |