[ofw] [PATCH] ofed libs: prevent double initialization of critical section

Sean Hefty sean.hefty at intel.com
Wed Aug 26 09:17:10 PDT 2009


DllMain is called multiple times for a given process.  Prevent double
initialization of critical sections by only initializing it during process
attach.  This avoids corrupting the critical section while it may be in use.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
This should go into winof 2.1

Index: ulp/libibverbs/src/ibv_main.cpp
===================================================================
--- ulp/libibverbs/src/ibv_main.cpp	(revision 2373)
+++ ulp/libibverbs/src/ibv_main.cpp	(working copy)
@@ -34,9 +34,18 @@
 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
 {
 	UNREFERENCED_PARAMETER(hInstance);
-	UNREFERENCED_PARAMETER(dwReason);
 	UNREFERENCED_PARAMETER(lpReserved);
 
-	InitializeCriticalSection(&lock);
+	switch (dwReason) {
+	case DLL_PROCESS_ATTACH:
+		InitializeCriticalSection(&lock);
+		break;
+	case DLL_PROCESS_DETACH:
+		DeleteCriticalSection(&lock);
+		break;
+	default:
+		break;
+	}
+
 	return TRUE;
 }
Index: ulp/librdmacm/src/cma_main.cpp
===================================================================
--- ulp/librdmacm/src/cma_main.cpp	(revision 2373)
+++ ulp/librdmacm/src/cma_main.cpp	(working copy)
@@ -35,10 +35,18 @@
 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
 {
 	UNREFERENCED_PARAMETER(hInstance);
-	UNREFERENCED_PARAMETER(dwReason);
 	UNREFERENCED_PARAMETER(lpReserved);
 
-	InitializeCriticalSection(&lock);
+	switch (dwReason) {
+	case DLL_PROCESS_ATTACH:
+		InitializeCriticalSection(&lock);
+		break;
+	case DLL_PROCESS_DETACH:
+		DeleteCriticalSection(&lock);
+		break;
+	default:
+		break;
+	}
 
 	return TRUE;
 }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: dllmain.diff
Type: application/octet-stream
Size: 1336 bytes
Desc: not available
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20090826/25f44377/attachment.obj>


More information about the ofw mailing list