Commit 1eecfa15 authored by David Goodell's avatar David Goodell
Browse files

[svn-r6344] Add real error handling in MPIR_Localcopy to aid debugging in the field.

This adds two new macros, MPIU_MEM_RANGES_OVERLAP and
MPIU_ERR_CHKMEMCPYANDJUMP, which can be used for error checking memcpy
invocations in "mpi_errno" situations.  Also refactor
MPIU_MEM_CHECK_MEMCPY to use the new _RANGES_OVERLAP macro.

This commit also uses CHKMEMCPYANDJUMP in MPIR_Localcopy so that we can
figure out the code paths where we are missing alias checking when we
get bug reports from users.  Prior to this commit we would typically get
assertion failures instead without a backtrace.

No reviewer.
parent 7836cef2
......@@ -395,6 +395,12 @@
#define MPIU_ERR_POPFATAL_LABEL(err_, label_) \
MPIU_ERR_SETFATALANDSTMT(err_,MPI_ERR_OTHER,goto label_,"**fail")
/* some simple memcpy aliasing checks */
#define MPIU_ERR_CHKMEMCPYANDSTMT(err_,stmt_,src_,dst_,len_) \
MPIU_ERR_CHKANDSTMT3(MPIU_MEM_RANGES_OVERLAP((dst_),(len_),(src_),(len_)),mpi_errno,MPI_ERR_INTERN,stmt_,"**memcpyalias","**memcpy %p %p %L",(src_),(dst_),(len_))
#define MPIU_ERR_CHKMEMCPYANDJUMP(err_,src_,dst_,len_) \
MPIU_ERR_CHKMEMCPYANDSTMT((err_),goto fn_fail,(src_),(dst_),(len_))
/* If you add any macros to this list, make sure that you update
maint/extracterrmsgs to handle the additional macros (see the hash
KnownErrRoutines in that script)
......
......@@ -434,9 +434,11 @@ if (pointer_) { \
*/
void MPIU_Basename(char *path, char **basename);
/* May be used to perform sanity and range checking on memcpy and mempcy-like
function calls. This macro will bail out much like an MPIU_Assert if any of
the checks fail. */
/* Evaluates to a boolean expression, true if the given byte ranges overlap,
* false otherwise. That is, true iff [a_,a_+a_len_) overlaps with [b_,b_+b_len_) */
#define MPIU_MEM_RANGES_OVERLAP(a_,a_len_,b_,b_len_) \
( ((char *)(a_) >= (char *)(b_) && ((char *)(a_) < ((char *)(b_) + (b_len_)))) || \
((char *)(b_) >= (char *)(a_) && ((char *)(b_) < ((char *)(a_) + (a_len_)))) )
#if (!defined(NDEBUG) && defined(HAVE_ERROR_CHECKING))
#ifndef TRUE
......@@ -446,16 +448,17 @@ void MPIU_Basename(char *path, char **basename);
#define FALSE 0
#endif
/* May be used to perform sanity and range checking on memcpy and mempcy-like
function calls. This macro will bail out much like an MPIU_Assert if any of
the checks fail. */
#define MPIU_MEM_CHECK_MEMCPY(dst_,src_,len_) \
do { \
if (len_) { \
if (len_) { \
MPIU_Assert((dst_) != NULL); \
MPIU_Assert((src_) != NULL); \
MPL_VG_CHECK_MEM_IS_ADDRESSABLE((dst_),(len_)); \
MPL_VG_CHECK_MEM_IS_ADDRESSABLE((src_),(len_)); \
if (((char *)(dst_) >= (char *)(src_) && ((char *)(dst_) < ((char *)(src_) + (len_)))) || \
((char *)(src_) >= (char *)(dst_) && ((char *)(src_) < ((char *)(dst_) + (len_))))) \
{ \
MPL_VG_CHECK_MEM_IS_ADDRESSABLE((dst_),(len_)); \
MPL_VG_CHECK_MEM_IS_ADDRESSABLE((src_),(len_)); \
if (MPIU_MEM_RANGES_OVERLAP((dst_),(len_),(src_),(len_))) { \
MPIU_Assert_fmt_msg(FALSE,("memcpy argument memory ranges overlap, dst_=%p src_=%p len_=%ld\n", \
(dst_), (src_), (long)(len_))); \
} \
......
......@@ -331,9 +331,15 @@ int MPIR_Localcopy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
if (mpi_errno) { MPIU_ERR_POP(mpi_errno); }
if (sendtype_iscontig && recvtype_iscontig)
{
MPIU_Memcpy(((char *) recvbuf + recvtype_true_lb),
((char *) sendbuf + sendtype_true_lb),
{
#if defined(HAVE_ERROR_CHECKING)
MPIU_ERR_CHKMEMCPYANDJUMP(mpi_errno,
((char *)recvbuf + recvtype_true_lb),
((char *)sendbuf + sendtype_true_lb),
copy_sz);
#endif
MPIU_Memcpy(((char *) recvbuf + recvtype_true_lb),
((char *) sendbuf + sendtype_true_lb),
copy_sz);
}
else if (sendtype_iscontig)
......
......@@ -176,6 +176,9 @@ MPI_TYPECLASS_INTEGER, or MPI_TYPECLASS_COMPLEX
**dynamic_node_ids: Node information for dynamic processes currently is not implemnted
**memcpyalias:memcpy arguments alias each other
**memcpyalias %p %p %L:memcpy arguments alias each other, dst=%d src=%d len=%L
# -- FIXME: Some (but not all) of the messages below this line have been used
#---- The messages below this line haven't been used yet.
#
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment