[ovs-dev] [PATCH 13/15] datapath-windows: Add Core.h

Samuel Ghinet sghinet at cloudbasesolutions.com
Wed Aug 6 16:16:12 UTC 2014


Add Core.h

Functionalities & macros that are expected to be needed / used anywhere.

Such as: macros for memory allocations.
These would replace the memory allocations functions defined in Utils.c:
* There is no need to allocate memory with priority if priority = normal (default)
* There is no need to use the Ndis mem allocation function, which requires an NDIS_HANDLE,
when we can use the Executive mem allocation function (ExAllocatePoolWithTag) which does not.
* There is no need to do a check like "OVS_VERIFY_IRQL_LE(DISPATCH_LEVEL)": the maximum
IRQL that we can have in the driver is dispatch level.
* OVS_ALLOC, OVS_FREE and KZAlloc are shorter-named, improving the code clarity.

Signed-off-by: Samuel Ghinet <sghinet at cloudbasesolutions.com>
---
 datapath-windows/ovsext/Core/Core.h            | 55 ++++++++++++++++++++++++++
 datapath-windows/ovsext/ovsext.vcxproj         |  1 +
 datapath-windows/ovsext/ovsext.vcxproj.filters |  5 ++-
 datapath-windows/ovsext/precomp.h              |  1 +
 4 files changed, 61 insertions(+), 1 deletion(-)
 create mode 100644 datapath-windows/ovsext/Core/Core.h

diff --git a/datapath-windows/ovsext/Core/Core.h b/datapath-windows/ovsext/Core/Core.h
new file mode 100644
index 0000000..3c56a13
--- /dev/null
+++ b/datapath-windows/ovsext/Core/Core.h
@@ -0,0 +1,55 @@
+/*
+Copyright 2014 Cloudbase Solutions Srl
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http ://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#pragma once
+
+#include "precomp.h"
+
+//used in ASSERT-s
+#define __NEVER_TRIED_THIS__      0
+#define __NOT_IMPLEMENTED__       0
+#define __UNEXPECTED__            0
+
+#define OVS_ALLOC(size) ExAllocatePoolWithTag(NonPagedPool, size, OVS_MEMORY_TAG)
+#define OVS_FREE(p) KFreeSafe(p)
+
+#define OVS_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+#define OVS_CONST_CAST(p) ((VOID*)p)
+
+#define OVS_SIZE_ALIGNED_N(dataSize, N)        (((dataSize) / (N)) * (N) + ((dataSize) % (N) ? (N) : 0))
+#define OVS_SIZE_ALIGNED_4(dataSize)           OVS_SIZE_ALIGNED_N(dataSize, 4)
+#define OVS_SIZE_ALIGNED_16(dataSize)          OVS_SIZE_ALIGNED_N(dataSize, 16)
+#define OVS_SIZE_ALIGNED_MEM(dataSize)         OVS_SIZE_ALIGNED_N(dataSize, MEMORY_ALLOCATION_ALIGNMENT)
+
+static __inline VOID* KZAlloc(SIZE_T size)
+{
+    VOID* p = OVS_ALLOC(size);
+    if (!p)
+    {
+        return NULL;
+    }
+
+    RtlZeroMemory(p, size);
+    return p;
+}
+
+static __inline VOID KFreeSafe(VOID* p)
+{
+    if (p)
+    {
+        ExFreePoolWithTag(p, OVS_MEMORY_TAG);
+    }
+}
diff --git a/datapath-windows/ovsext/ovsext.vcxproj b/datapath-windows/ovsext/ovsext.vcxproj
index 2c62cab..ee69327 100644
--- a/datapath-windows/ovsext/ovsext.vcxproj
+++ b/datapath-windows/ovsext/ovsext.vcxproj
@@ -70,6 +70,7 @@
     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
   </ImportGroup>
   <ItemGroup Label="WrappedTaskItems">
+    <ClInclude Include="Core\Core.h" />
     <ClInclude Include="Core\Debug.h" />
     <ClInclude Include="Core\Error.h" />
     <ClInclude Include="Core\FixedSizedArray.h" />
diff --git a/datapath-windows/ovsext/ovsext.vcxproj.filters b/datapath-windows/ovsext/ovsext.vcxproj.filters
index 96cfac6..78d041b 100644
--- a/datapath-windows/ovsext/ovsext.vcxproj.filters
+++ b/datapath-windows/ovsext/ovsext.vcxproj.filters
@@ -89,6 +89,9 @@
     <ClInclude Include="Core\FixedSizedArray.h">
       <Filter>Core</Filter>
     </ClInclude>
+    <ClInclude Include="Core\Core.h">
+      <Filter>Core</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="ovsext.rc" />
@@ -185,4 +188,4 @@
       <Filter>Core</Filter>
     </ClCompile>
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/datapath-windows/ovsext/precomp.h b/datapath-windows/ovsext/precomp.h
index 3fd5da2..b28e9ec 100644
--- a/datapath-windows/ovsext/precomp.h
+++ b/datapath-windows/ovsext/precomp.h
@@ -21,6 +21,7 @@
 #include <ntstrsafe.h>
 #include <Strsafe.h>

+#include "Core/Core.h"
 #include "Core/Debug.h"
 #include "Core/Types.h"
 #include "Core/Util.h"
--
1.8.3.msysgit.0





More information about the dev mailing list