[ofw] [PATCH] NDProvider: Use private heap for memory allocations

Fab Tillier ftillier at windows.microsoft.com
Wed May 20 12:51:15 PDT 2009


The registration cache functionality in MS-MPI makes use of the SecureMemoryCacheCallback APIs.  The cache callback is not allowed to use the heap affected by the callback form the callback itself.  This patch allocates a private heap for the ND provider and uses that for internal object allocation, to ensure that the MR object can be freed from the cache callback.

Note that a similar fix will be needed if any memory is freed in the deregistration path of other libraries (WSD is one, and likely WinVerbs and ND over WinVerbs.)

Committed in SVN 2193.

Signed-off-by: Fab Tillier <ftillier at microsoft.com>

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: nd_heap.patch
Type: application/octet-stream
Size: 1878 bytes
Desc: nd_heap.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20090520/4c944759/attachment.obj>


More information about the ofw mailing list