[zeromq-dev] [PATCH] Throw noncontinuable exception on Win32 instead of abort

Pieter Hintjens ph at imatix.com
Mon Oct 17 19:08:27 CEST 2011


Hi Paul,

This is great. To apply this to libzmq we need a signed-off patch, see
http://www.zeromq.org/docs:contributing

You can also make pull requests to the zeromq2-1 and zeromq3-0
repositories, then I'll push these changes into the next 2-1 and 3-0
versions.

-Pieter

On Mon, Oct 17, 2011 at 10:45 AM, Paul Betts <paul at paulbetts.org> wrote:
> This patch changes the Win32 version to call RaiseException instead of abort
> (which eventually calls TerminateProcess). This allows crash dumps to be sent
> correctly and code to be debugged more easily. Since the
> EXCEPTION_NONCONTINUABLE flag is passed into RaiseException, the process is
> still guaranteed to terminate.
>
> ---
>  src/err.cpp | 10 ++++++++++
>  src/err.hpp | 20 ++++++++++++--------
>  2 files changed, 22 insertions(+), 8 deletions(-)
> diff --git a/src/err.cpp b/src/err.cpp
> index f374de9..6bc7699 100644
> --- a/src/err.cpp
> +++ b/src/err.cpp
> @@ -236,4 +236,14 @@ void zmq::wsa_error_to_errno ()
>  }
>  }
>
> +void _abort(const char* errmsg)
> +{
> + void* extra_info[1];
> + extra_info[0] = errmsg;
> +
> + RaiseException(0x40000015 /* STATUS_FATAL_APP_EXIT */,
> + EXCEPTION_NONCONTINUABLE,
> + 1, extra_info);
> +}
> +
>  #endif
> diff --git a/src/err.hpp b/src/err.hpp
> index 9558a10..f4abdd7 100644
> --- a/src/err.hpp
> +++ b/src/err.hpp
> @@ -54,6 +54,8 @@ namespace zmq
>  void wsa_error_to_errno ();
>  }
>
> +void _abort(const char* errmsg);
> +
>  // Provides convenient way to check WSA-style errors on Windows.
>  #define wsa_assert(x) \
>  do {\
> @@ -62,7 +64,7 @@ namespace zmq
>  if (errstr != NULL) {\
>  fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
>  __FILE__, __LINE__);\
> - abort ();\
> + _abort (errstr);\
>  }\
>  }\
>  } while (false)
> @@ -74,7 +76,7 @@ namespace zmq
>  if (errstr != NULL) {\
>  fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
>  __FILE__, __LINE__);\
> - abort ();\
> + _abort (errstr);\
>  }\
>  } while (false)
>
> @@ -86,10 +88,12 @@ namespace zmq
>  zmq::win_error (errstr, 256);\
>  fprintf (stderr, "Assertion failed: %s (%s:%d)\n", errstr, \
>  __FILE__, __LINE__);\
> - abort ();\
> + _abort (errstr);\
>  }\
>  } while (false)
>
> +#else
> +#define _abort(x) abort()
>  #endif
>
>  // This macro works in exactly the same way as the normal assert. It is used
> @@ -100,7 +104,7 @@ namespace zmq
>  if (unlikely (!(x))) {\
>  fprintf (stderr, "Assertion failed: %s (%s:%d)\n", #x, \
>  __FILE__, __LINE__);\
> - abort ();\
> + _abort (#x);\
>  }\
>  } while (false)
>
> @@ -110,7 +114,7 @@ namespace zmq
>  if (unlikely (!(x))) {\
>  perror (NULL);\
>  fprintf (stderr, "%s (%s:%d)\n", #x, __FILE__, __LINE__);\
> - abort ();\
> + _abort (#x);\
>  }\
>  } while (false)
>
> @@ -119,7 +123,7 @@ namespace zmq
>  do {\
>  if (unlikely (x)) {\
>  fprintf (stderr, "%s (%s:%d)\n", strerror (x), __FILE__, __LINE__);\
> - abort ();\
> + _abort (#x);\
>  }\
>  } while (false)
>
> @@ -129,7 +133,7 @@ namespace zmq
>  if (unlikely (x)) {\
>  const char *errstr = gai_strerror (x);\
>  fprintf (stderr, "%s (%s:%d)\n", errstr, __FILE__, __LINE__);\
> - abort ();\
> + _abort (errstr);\
>  }\
>  } while (false)
>
> @@ -139,7 +143,7 @@ namespace zmq
>  if (unlikely (!x)) {\
>  fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s:%d)\n",\
>  __FILE__, __LINE__);\
> - abort ();\
> + _abort ("OUT OF MEMORY");\
>  }\
>  } while (false)
>
> --
> 1.7.6
>
> --
> Paul Betts <paul at paulbetts.org>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>



More information about the zeromq-dev mailing list