Fix MSVC2015 build.
This commit is contained in:
parent
364cd094d9
commit
2e11d3400e
@ -1,13 +1,86 @@
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Fix from from https://stackoverflow.com/a/34655235.
|
||||
//
|
||||
// __iob_func required by the MySQL we use,
|
||||
// but no longer exists in the VS 14.0+ crt.
|
||||
|
||||
#pragma comment(lib, "DbgHelp.lib")
|
||||
#pragma warning(disable:4091) // 'typedef ': ignored on left of '' when no variable is declared
|
||||
#include <DbgHelp.h>
|
||||
#include <corecrt_wstdio.h>
|
||||
|
||||
#define GET_CURRENT_CONTEXT(c, contextFlags) \
|
||||
do { \
|
||||
c.ContextFlags = contextFlags; \
|
||||
__asm call x \
|
||||
__asm x: pop eax \
|
||||
__asm mov c.Eip, eax \
|
||||
__asm mov c.Ebp, ebp \
|
||||
__asm mov c.Esp, esp \
|
||||
} while(0);
|
||||
|
||||
|
||||
FILE * __cdecl __iob_func(void)
|
||||
{
|
||||
CONTEXT c = { 0 };
|
||||
STACKFRAME64 s = { 0 };
|
||||
DWORD imageType;
|
||||
HANDLE hThread = GetCurrentThread();
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
|
||||
GET_CURRENT_CONTEXT(c, CONTEXT_FULL);
|
||||
|
||||
imageType = IMAGE_FILE_MACHINE_I386;
|
||||
s.AddrPC.Offset = c.Eip;
|
||||
s.AddrPC.Mode = AddrModeFlat;
|
||||
s.AddrFrame.Offset = c.Ebp;
|
||||
s.AddrFrame.Mode = AddrModeFlat;
|
||||
s.AddrStack.Offset = c.Esp;
|
||||
s.AddrStack.Mode = AddrModeFlat;
|
||||
|
||||
if (!StackWalk64(imageType, hProcess, hThread, &s, &c, NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (s.AddrReturn.Offset == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
{
|
||||
unsigned char const * assembly = (unsigned char const *)(s.AddrReturn.Offset);
|
||||
|
||||
if (*assembly == 0x83 && *(assembly + 1) == 0xC0 && (*(assembly + 2) == 0x20 || *(assembly + 2) == 0x40))
|
||||
{
|
||||
if (*(assembly + 2) == 32)
|
||||
{
|
||||
return (FILE*)((unsigned char *)stdout - 32);
|
||||
}
|
||||
if (*(assembly + 2) == 64)
|
||||
{
|
||||
return (FILE*)((unsigned char *)stderr - 64);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return stdin;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Adapted from dosmap.c in Visual Studio 12.0 CRT sources.
|
||||
//
|
||||
// The _dosmaperr function is required by the MySQL lib we use,
|
||||
// but no longer exists in the VS 14.0+ crt.
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static struct errentry
|
||||
{
|
||||
DWORD oscode; // OS return value
|
||||
|
Loading…
Reference in New Issue
Block a user