static FORCEINLINE PVOID __DebugAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(Length, DEBUG_TAG); }
static FORCEINLINE PVOID __CacheAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(Length, CACHE_TAG); }
static FORCEINLINE PVOID __PdoAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(Length, PDO_TAG); }
static FORCEINLINE PVOID __ThreadAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(Length, THREAD_POOL); }
static FORCEINLINE PVOID __EmulatedAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(Length, EMULATED_TAG); }
static FORCEINLINE PCHAR #pragma warning(suppress: 28195) __DriverFormatV( __in PCHAR Fmt, __in va_list Args ) { NTSTATUS Status; PCHAR Str; ULONG Size = 32; for (;;) { Str = (PCHAR)__AllocateNonPagedPoolWithTag(__FUNCTION__, __LINE__, Size, FORMAT_POOL_TAG); if (!Str) { return NULL; } Status = RtlStringCchVPrintfA(Str, Size - 1, Fmt, Args); if (Status == STATUS_SUCCESS) { Str[Size - 1] = '\0'; return Str; } __FreePoolWithTag(Str, FORMAT_POOL_TAG); if (Status == STATUS_BUFFER_OVERFLOW) { Size *= 2; } else { return NULL; } } }
static FORCEINLINE PVOID __VifAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(Length, VIF_POOL); }
static FORCEINLINE PVOID __GnttabAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(Length, GNTTAB_TAG); }
static FORCEINLINE PVOID __NotifierAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(Length, NOTIFIER_POOL); }
static FORCEINLINE PVOID __BlockRingAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(__FUNCTION__, __LINE__, Length, BLOCKRING_POOL_TAG); }
static FORCEINLINE PVOID __RegistryAllocate( IN ULONG Length ) { return __AllocateNonPagedPoolWithTag(__FUNCTION__, __LINE__, Length, REGISTRY_POOL); }
static FORCEINLINE PVOID #pragma warning(suppress: 28195) ___FrontendAlloc( __in PCHAR Caller, __in ULONG Line, __in ULONG Size ) { return __AllocateNonPagedPoolWithTag(Caller, Line, Size, FRONTEND_POOL_TAG); }
static DECLSPEC_NOINLINE BOOLEAN __DriverGetOption( __in PWCHAR Options, __in PWCHAR Parameter, __out PWCHAR* Value ) { PWCHAR Ptr; PWCHAR Buffer; ULONG Index; ULONG Length; *Value = NULL; Ptr = wcsstr(Options, Parameter); if (Ptr == NULL) return FALSE; // option not present // skip Parameter while (*Parameter) { ++Ptr; ++Parameter; } // find length of Value, up to next NULL or whitespace for (Length = 0; __IsValid(Ptr[Length]); ++Length) ; if (Length == 0) return TRUE; // found the option, it had no value so *Value == NULL! Buffer = (PWCHAR)__AllocateNonPagedPoolWithTag(__FUNCTION__, __LINE__, (Length + 1) * sizeof(WCHAR), XENVBD_POOL_TAG); if (Buffer == NULL) return FALSE; // memory allocation failure, ignore option // copy Value for (Index = 0; Index < Length; ++Index) Buffer[Index] = Ptr[Index]; Buffer[Length] = L'\0'; *Value = Buffer; return TRUE; }
static DECLSPEC_NOINLINE NTSTATUS __DriverGetSystemStartParams( __out PWCHAR* Options ) { UNICODE_STRING Unicode; OBJECT_ATTRIBUTES Attributes; HANDLE Key; PKEY_VALUE_PARTIAL_INFORMATION Value; ULONG Size; NTSTATUS Status; RtlInitUnicodeString(&Unicode, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control"); InitializeObjectAttributes(&Attributes, &Unicode, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL); Status = ZwOpenKey(&Key, KEY_READ, &Attributes); if (!NT_SUCCESS(Status)) goto fail1; RtlInitUnicodeString(&Unicode, L"SystemStartOptions"); Status = ZwQueryValueKey(Key, &Unicode, KeyValuePartialInformation, NULL, 0, &Size); if (Status != STATUS_BUFFER_TOO_SMALL && Status != STATUS_BUFFER_OVERFLOW) goto fail2; Status = STATUS_NO_MEMORY; #pragma prefast(suppress:6102) Value = (PKEY_VALUE_PARTIAL_INFORMATION)__AllocateNonPagedPoolWithTag(__FUNCTION__, __LINE__, Size, XENVBD_POOL_TAG); if (Value == NULL) goto fail3; Status = ZwQueryValueKey(Key, &Unicode, KeyValuePartialInformation, Value, Size, &Size); if (!NT_SUCCESS(Status)) goto fail4; Status = STATUS_INVALID_PARAMETER; if (Value->Type != REG_SZ) goto fail5; Status = STATUS_NO_MEMORY; *Options = (PWCHAR)__AllocateNonPagedPoolWithTag(__FUNCTION__, __LINE__, Value->DataLength + sizeof(WCHAR), XENVBD_POOL_TAG); if (*Options == NULL) goto fail6; RtlCopyMemory(*Options, Value->Data, Value->DataLength); __FreePoolWithTag(Value, XENVBD_POOL_TAG); ZwClose(Key); return STATUS_SUCCESS; fail6: fail5: fail4: __FreePoolWithTag(Value, XENVBD_POOL_TAG); fail3: fail2: ZwClose(Key); fail1: *Options = NULL; return Status; }