2 * Copyright (c) 2014 VMware, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #define OVS_DBG_MOD OVS_DBG_OTHERS
25 extern NDIS_HANDLE gOvsExtDriverHandle;
28 OvsAllocateMemoryWithTag(size_t size, ULONG tag)
30 OVS_VERIFY_IRQL_LE(DISPATCH_LEVEL);
31 return NdisAllocateMemoryWithTagPriority(gOvsExtDriverHandle,
32 (UINT32)size, tag, NormalPoolPriority);
36 OvsFreeMemoryWithTag(VOID *ptr, ULONG tag)
39 NdisFreeMemoryWithTagPriority(gOvsExtDriverHandle, ptr, tag);
43 OvsAllocateMemory(size_t size)
45 OVS_VERIFY_IRQL_LE(DISPATCH_LEVEL);
46 return NdisAllocateMemoryWithTagPriority(gOvsExtDriverHandle,
47 (UINT32)size, OVS_MEMORY_TAG, NormalPoolPriority);
51 OvsAllocateAlignedMemory(size_t size, UINT16 align)
53 OVS_VERIFY_IRQL_LE(DISPATCH_LEVEL);
55 ASSERT((align == 8) || (align == 16));
57 if ((align == 8) || (align == 16)) {
59 * XXX: NdisAllocateMemory*() functions don't talk anything about
60 * alignment. Hence using ExAllocatePool*();
62 return (VOID *)ExAllocatePoolWithTagPriority(NonPagedPool, size,
67 /* Invalid user input. */
72 OvsFreeMemory(VOID *ptr)
75 NdisFreeMemoryWithTagPriority(gOvsExtDriverHandle, ptr, OVS_MEMORY_TAG);
79 OvsFreeAlignedMemory(VOID *ptr)
82 ExFreePoolWithTag(ptr, OVS_MEMORY_TAG);
86 OvsAppendList(PLIST_ENTRY dst, PLIST_ENTRY src)
88 PLIST_ENTRY srcFirst, srcLast, dstLast;
89 if (IsListEmpty(src)) {
92 srcFirst = src->Flink;
96 dstLast->Flink = srcFirst;
97 srcFirst->Blink = dstLast;
100 dst->Blink = srcLast;
107 OvsCompareString(PVOID string1, PVOID string2)
110 * Not a super-efficient string compare since we walk over the strings
111 * twice: to initialize, and then to do the comparison.
115 RtlInitString(&str1, string1);
116 RtlInitString(&str2, string2);
117 return RtlEqualString(&str1, &str2, FALSE);