Use private heap for memory allocations to avoid heap corruption when using
authorftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 20 May 2009 19:50:56 +0000 (19:50 +0000)
committerftillier <ftillier@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 20 May 2009 19:50:56 +0000 (19:50 +0000)
the SecureMemoryCacheCallback functionality of the OS.

Signed-off-by: Fab Tillier <ftillier@microsoft.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2193 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/nd/user/NdProv.cpp

index e242877..720ef07 100644 (file)
@@ -58,6 +58,9 @@ uint32_t g_nd_dbg_level = TRACE_LEVEL_ERROR;
 /* WPP doesn't want here literals! */\r
 uint32_t g_nd_dbg_flags = 0x80000001; /* ND_DBG_ERROR | ND_DBG_NDI; */\r
 \r
+HANDLE ghHeap;\r
+\r
+\r
 namespace NetworkDirect\r
 {\r
 \r
@@ -381,7 +384,7 @@ void* __cdecl operator new(
     size_t count\r
     )\r
 {\r
-    return HeapAlloc( GetProcessHeap(), 0, count );\r
+    return HeapAlloc( ghHeap, 0, count );\r
 }\r
 \r
 \r
@@ -389,7 +392,7 @@ void __cdecl operator delete(
     void* object\r
     )\r
 {\r
-    HeapFree( GetProcessHeap(), 0, object );\r
+    HeapFree( ghHeap, 0, object );\r
 }\r
 \r
 extern "C" {\r
@@ -467,11 +470,7 @@ _DllMain(
 #else\r
         WPP_INIT_TRACING(L"ibndprov.dll");\r
 #endif\r
-#endif\r
-\r
-\r
-#if !defined(EVENT_TRACING)\r
-#if DBG \r
+#elif DBG \r
         TCHAR    env_var[16];\r
         DWORD    i;\r
 \r
@@ -493,14 +492,24 @@ _DllMain(
         ND_PRINT( TRACE_LEVEL_ERROR, ND_DBG_ERR ,\r
             ("(pcs %#x) IbNdProv: Debug print: level:%d, flags 0x%x\n",\r
             GetCurrentProcessId(), g_nd_dbg_level ,g_nd_dbg_flags) );\r
-\r
 #endif\r
+\r
+        ghHeap = HeapCreate( 0, 0, 0 );\r
+        if( ghHeap == NULL )\r
+        {\r
+            ND_PRINT_EXIT(\r
+                TRACE_LEVEL_ERROR, ND_DBG_NDI, ("Failed to allocate private heap.\n") );\r
+#if defined(EVENT_TRACING)\r
+            WPP_CLEANUP();\r
 #endif\r
+            return FALSE;\r
+        }\r
 \r
         ND_PRINT(TRACE_LEVEL_INFORMATION, ND_DBG_NDI, ("DllMain: DLL_PROCESS_ATTACH\n") );\r
         break;\r
 \r
     case DLL_PROCESS_DETACH:\r
+        HeapDestroy( ghHeap );\r
         ND_PRINT(TRACE_LEVEL_INFORMATION, ND_DBG_NDI,\r
             ("DllMain: DLL_PROCESS_DETACH, ref count %d\n", NetworkDirect::gnRef) );\r
 \r