From 2017e4b346f028683af8219f6f687eb45770fd57 Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Wed, 19 Sep 2007 10:46:26 -0700 Subject: [PATCH] Added valgrind support to the libibcm. Signed-off-by: Dotan Barak Signed-off-by: Sean Hefty --- configure.in | 18 ++++++++++++++++++ src/cm.c | 26 +++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index e33a188..7de8013 100644 --- a/configure.in +++ b/configure.in @@ -9,6 +9,18 @@ AM_INIT_AUTOMAKE(libibcm, 1.0-1) AM_PROG_LIBTOOL +AC_ARG_WITH([valgrind], + AC_HELP_STRING([--with-valgrind], + [Enable valgrind annotations - default NO])) + +if test "$with_valgrind" != "" && test "$with_valgrind" != "no"; then + AC_DEFINE([INCLUDE_VALGRIND], 1, + [Define to 1 to enable valgrind annotations]) + if test -d $with_valgrind; then + CPPFLAGS="$CPPLFAGS -I$with_valgrind/include" + fi +fi + AC_ARG_ENABLE(libcheck, [ --disable-libcheck do not test for presence of ib libraries], [ if test "$enableval" = "no"; then disable_libcheck=yes @@ -38,6 +50,12 @@ AC_CHECK_HEADER(infiniband/verbs.h, [], AC_MSG_ERROR([ not found. Is libibverbs installed?])) AC_CHECK_HEADER(infiniband/marshall.h, [], AC_MSG_ERROR([ not found. Is libibverbs installed?])) + +if test "$with_valgrind" != "" && test "$with_valgrind" != "no"; then +AC_CHECK_HEADER(valgrind/memcheck.h, [], + AC_MSG_ERROR([valgrind requested but not found.])) +fi + fi AC_CACHE_CHECK(whether ld accepts --version-script, ac_cv_version_script, diff --git a/src/cm.c b/src/cm.c index 2572972..7370abe 100644 --- a/src/cm.c +++ b/src/cm.c @@ -51,6 +51,17 @@ #include #include +#ifdef INCLUDE_VALGRIND +# include +# ifndef VALGRIND_MAKE_MEM_DEFINED +# warning "Valgrind requested, but VALGRIND_MAKE_MEM_DEFINED undefined" +# endif +#endif + +#ifndef VALGRIND_MAKE_MEM_DEFINED +# define VALGRIND_MAKE_MEM_DEFINED(addr,len) +#endif + #define PFX "libibcm: " static int abi_ver; @@ -226,6 +237,8 @@ int ib_cm_create_id(struct ib_cm_device *device, if (result != size) goto err; + VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp); + cm_id_priv->id.handle = resp->id; *cm_id = &cm_id_priv->id; return 0; @@ -250,6 +263,8 @@ int ib_cm_destroy_id(struct ib_cm_id *cm_id) if (result != size) return (result > 0) ? -ENODATA : result; + VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp); + cm_id_priv = container_of(cm_id, struct cm_id_private, id); pthread_mutex_lock(&cm_id_priv->mut); @@ -279,6 +294,8 @@ int ib_cm_attr_id(struct ib_cm_id *cm_id, struct ib_cm_attr_param *param) if (result != size) return (result > 0) ? -ENODATA : result; + VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp); + param->service_id = resp->service_id; param->service_mask = resp->service_mask; param->local_id = resp->local_id; @@ -307,6 +324,8 @@ int ib_cm_init_qp_attr(struct ib_cm_id *cm_id, if (result != size) return (result > 0) ? -ENODATA : result; + VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp); + *qp_attr_mask = resp->qp_attr_mask; ibv_copy_qp_attr_from_kern(qp_attr, resp); @@ -782,7 +801,7 @@ int ib_cm_get_event(struct ib_cm_device *device, struct ib_cm_event **event) msg = alloca(size); if (!msg) return -ENOMEM; - + hdr = msg; cmd = msg + sizeof(*hdr); @@ -790,6 +809,8 @@ int ib_cm_get_event(struct ib_cm_device *device, struct ib_cm_event **event) hdr->in = sizeof(*cmd); hdr->out = sizeof(*resp); + memset(cmd, 0, sizeof(*cmd)); + resp = alloca(sizeof(*resp)); if (!resp) return -ENOMEM; @@ -818,6 +839,9 @@ int ib_cm_get_event(struct ib_cm_device *device, struct ib_cm_event **event) result = (result > 0) ? -ENODATA : result; goto done; } + + VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp); + /* * decode event. */ -- 2.41.0