[ofw] [PATCH 2/12] nd2: use private heap

Hefty, Sean sean.hefty at intel.com
Tue Jul 27 00:57:48 PDT 2010


Replace the use of the application heap with a private heap.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
 trunk/ulp/netdirect2/user/nd_base.h   |    6 ++++--
 trunk/ulp/netdirect2/user/nd_main.cpp |   12 +++++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/trunk/ulp/netdirect2/user/nd_base.h b/trunk/ulp/netdirect2/user/nd_base.h
index d11b1a0..23dd59e 100644
--- a/trunk/ulp/netdirect2/user/nd_base.h
+++ b/trunk/ulp/netdirect2/user/nd_base.h
@@ -51,14 +51,16 @@ public:
 protected:
 };
 
+extern HANDLE g_hHeap;
+
 __inline void* __cdecl operator new(size_t size)
 {
-	return HeapAlloc(GetProcessHeap(), 0, size);
+	return HeapAlloc(g_hHeap, 0, size);
 }
 
 __inline void __cdecl operator delete(void *pObj)
 {
-	HeapFree(GetProcessHeap(), 0, pObj);
+	HeapFree(g_hHeap, 0, pObj);
 }
 
 HRESULT NDConvertWVStatus(HRESULT hr);
diff --git a/trunk/ulp/netdirect2/user/nd_main.cpp b/trunk/ulp/netdirect2/user/nd_main.cpp
index a27764d..43c2009 100644
--- a/trunk/ulp/netdirect2/user/nd_main.cpp
+++ b/trunk/ulp/netdirect2/user/nd_main.cpp
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include "nd_provider.h"
 
+HANDLE g_hHeap;
 
 extern "C" {
 
@@ -44,10 +45,19 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
 {
 	switch (dwReason) {
 	case DLL_PROCESS_ATTACH:
+		if (_DllMainCRTStartupForGS(hInstance, dwReason, lpReserved)) {
+			return FALSE;
+		}
+
+		g_hHeap = HeapCreate(0, 0, 0);
+		return (g_hHeap != NULL);
 	case DLL_PROCESS_DETACH:
+		if (g_hHeap != NULL) {
+			HeapDestroy(g_hHeap);
+		}
 		return _DllMainCRTStartupForGS(hInstance, dwReason, lpReserved);
 	default:
-		return TRUE;
+		return FALSE;
 	}
 }
 




More information about the ofw mailing list