[ofw] [PATCH] uDAPL v2: winof: Convert windows version of dapl and dat libaries to use private heaps.
Arlin Davis
arlin.r.davis at intel.com
Thu Sep 3 12:43:44 PDT 2009
This allows for better support of memory registration caching by upper
level libaries (MPI) that use SecureMemoryCacheCallback.
It also makes it easier to debug heap corruption issues.
Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
dapl/openib_scm/cm.c | 2 +-
dapl/udapl/windows/dapl_osd.c | 7 ++++++-
dapl/udapl/windows/dapl_osd.h | 19 +++++++++++++------
dat/udat/windows/dat_osd.c | 5 +++++
dat/udat/windows/dat_osd.h | 7 +++++--
5 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/dapl/openib_scm/cm.c b/dapl/openib_scm/cm.c
index 06fff95..8560788 100644
--- a/dapl/openib_scm/cm.c
+++ b/dapl/openib_scm/cm.c
@@ -1845,7 +1845,7 @@ void cr_thread(void *arg)
}
dapl_os_unlock(&hca_ptr->ib_trans.lock);
- free(set);
+ dapl_os_free(set, sizeof(struct dapl_fd_set));
out:
hca_ptr->ib_trans.cr_state = IB_THREAD_EXIT;
dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " cr_thread(hca %p) exit\n", hca_ptr);
diff --git a/dapl/udapl/windows/dapl_osd.c b/dapl/udapl/windows/dapl_osd.c
index 8097560..eb409cd 100644
--- a/dapl/udapl/windows/dapl_osd.c
+++ b/dapl/udapl/windows/dapl_osd.c
@@ -48,7 +48,7 @@
#include <sys/timeb.h>
#include <stdlib.h> /* needed for getenv() */
-
+HANDLE heap;
/*
* DllMain
@@ -75,6 +75,10 @@ DllMain (
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
+ heap = HeapCreate(0, 0, 0);
+ if (heap == NULL) {
+ return FALSE;
+ }
/*
* We don't attach/detach threads that need any sort
* of initialization, so disable this ability to optimize
@@ -112,6 +116,7 @@ DllMain (
*/
dapl_fini ();
#endif
+ HeapDestroy(heap);
break;
}
return TRUE;
diff --git a/dapl/udapl/windows/dapl_osd.h b/dapl/udapl/windows/dapl_osd.h
index 6266f1f..5fb9363 100644
--- a/dapl/udapl/windows/dapl_osd.h
+++ b/dapl/udapl/windows/dapl_osd.h
@@ -350,6 +350,8 @@ dapl_os_wait_object_destroy (
* Memory Functions
*/
+extern HANDLE heap;
+
/* function prototypes */
STATIC __inline void *dapl_os_alloc (int size);
@@ -389,19 +391,18 @@ dapl_os_sync_rdma_write (
STATIC __inline void *dapl_os_alloc (int size)
{
- return malloc (size);
+ return HeapAlloc(heap, 0, size);
}
STATIC __inline void *dapl_os_realloc (void *ptr, int size)
{
- return realloc(ptr, size);
+ return HeapReAlloc(heap, 0, ptr, size);
}
STATIC __inline void dapl_os_free (void *ptr, int size)
{
- size = size;
- free (ptr);
- ptr = NULL;
+ UNREFERENCED_PARAMETER(size);
+ HeapFree(heap, 0, ptr);
}
STATIC __inline void * dapl_os_memzero (void *loc, int size)
@@ -427,7 +428,13 @@ STATIC __inline unsigned int dapl_os_strlen(const char *str)
STATIC __inline char * dapl_os_strdup(const char *str)
{
- return _strdup(str);
+ char *dup;
+
+ dup = dapl_os_alloc(strlen(str) + 1);
+ if (!dup)
+ return NULL;
+ strcpy(dup, str);
+ return dup;
}
diff --git a/dat/udat/windows/dat_osd.c b/dat/udat/windows/dat_osd.c
index 5b57f43..37f3087 100644
--- a/dat/udat/windows/dat_osd.c
+++ b/dat/udat/windows/dat_osd.c
@@ -124,6 +124,7 @@ dat_os_dbg_print (
}
}
+HANDLE heap;
BOOL APIENTRY
DllMain(
@@ -138,12 +139,16 @@ DllMain(
switch( ul_reason_for_call )
{
case DLL_PROCESS_ATTACH:
+ heap = HeapCreate(0, 0, 0);
+ if (heap == NULL)
+ return FALSE;
DisableThreadLibraryCalls( h_module );
udat_check_state();
break;
case DLL_PROCESS_DETACH:
dat_fini();
+ HeapDestroy(heap);
}
return TRUE;
diff --git a/dat/udat/windows/dat_osd.h b/dat/udat/windows/dat_osd.h
index d78fe44..6941e46 100644
--- a/dat/udat/windows/dat_osd.h
+++ b/dat/udat/windows/dat_osd.h
@@ -244,11 +244,13 @@ dat_os_usleep(
* *
*********************************************************************/
+extern HANDLE heap;
+
STATIC INLINE void *
dat_os_alloc (
int size)
{
- return malloc (size);
+ return HeapAlloc(heap, 0, size);
}
STATIC INLINE void
@@ -256,7 +258,8 @@ dat_os_free (
void *ptr,
int size)
{
- free (ptr);
+ UNREFERENCED_PARAMETER(size);
+ HeapFree(heap, 0, ptr);
}
STATIC INLINE void *
--
1.5.2.5
More information about the ofw
mailing list