forked from premiere/premiere-libtorrent
fix dbghlp heap corruption on windows
synchronize access to dbghlp.dll on windows
This commit is contained in:
parent
118d06b780
commit
7fdab0d9e9
|
@ -147,6 +147,7 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*)
|
||||||
|
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#include "libtorrent/utf8.hpp"
|
#include "libtorrent/utf8.hpp"
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "winbase.h"
|
#include "winbase.h"
|
||||||
#include "dbghelp.h"
|
#include "dbghelp.h"
|
||||||
|
@ -154,6 +155,11 @@ TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth, void*)
|
||||||
TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth
|
TORRENT_EXPORT void print_backtrace(char* out, int len, int max_depth
|
||||||
, void* ctx)
|
, void* ctx)
|
||||||
{
|
{
|
||||||
|
// all calls to DbgHlp.dll are thread-unsafe. i.e. they all need to be
|
||||||
|
// synchronized and not called concurrently. This mutex serializes access
|
||||||
|
static std::mutex dbghlp_mutex;
|
||||||
|
std::lock_guard<std::mutex> l(dbghlp_mutex);
|
||||||
|
|
||||||
CONTEXT context_record;
|
CONTEXT context_record;
|
||||||
if (ctx)
|
if (ctx)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <windows.h> // fot SetErrorMode
|
#include <windows.h> // fot SetErrorMode
|
||||||
#include <io.h> // for _dup and _dup2
|
#include <io.h> // for _dup and _dup2
|
||||||
#include <process.h> // for _getpid
|
#include <process.h> // for _getpid
|
||||||
|
#include <crtdbg.h>
|
||||||
|
|
||||||
#define dup _dup
|
#define dup _dup
|
||||||
#define dup2 _dup2
|
#define dup2 _dup2
|
||||||
|
@ -279,6 +280,11 @@ EXPORT int main(int argc, char const* argv[])
|
||||||
|
|
||||||
SetUnhandledExceptionFilter(&seh_exception_handler);
|
SetUnhandledExceptionFilter(&seh_exception_handler);
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
||||||
|
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
signal(SIGSEGV, &sig_handler);
|
signal(SIGSEGV, &sig_handler);
|
||||||
|
|
Loading…
Reference in New Issue