diff --git a/src/assert.cpp b/src/assert.cpp index 46ce98803..f05965fc8 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -146,12 +146,19 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) #include "windows.h" #include "libtorrent/utf8.hpp" +#include "libtorrent/thread.hpp" #include "winbase.h" #include "dbghelp.h" +static libtorrent::mutex dbghlp_mutex; + TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth) { + // all calls to DbgHlp.dll are thread-unsafe. i.e. they all need to be + // synchronized and not called concurrently. This mutex serializes access + libtorrent::mutex::scoped_lock l(dbghlp_mutex); + typedef USHORT (WINAPI *RtlCaptureStackBackTrace_t)( __in ULONG FramesToSkip, __in ULONG FramesToCapture, diff --git a/test/main.cpp b/test/main.cpp index 3f210aa53..678774e3d 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -51,6 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. #include // fot SetErrorMode #include // for _dup and _dup2 #include // for _getpid +#include #define dup _dup #define dup2 _dup2 @@ -224,6 +225,12 @@ EXPORT int main(int argc, char const* argv[]) | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); SetUnhandledExceptionFilter(&seh_exception_handler); + +#ifdef _DEBUG + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); +#endif + #endif #ifdef O_NONBLOCK