From 8916aba3bf29f81a426485a779a623edd4b1be61 Mon Sep 17 00:00:00 2001 From: Vitaly Pronkin Date: Wed, 27 Jul 2016 19:46:49 -0400 Subject: [PATCH] win64 fixes (partial) cherry-picked from 2f734ae2317060edb83021f17cffc966c435ad7b --- CMakeLists.txt | 5 +++-- depends/lua/src/lobject.c | 4 ++-- depends/tthread/fast_mutex.h | 2 +- library/DataStaticsFields.cpp | 5 +++++ library/Hooks-windows.cpp | 20 ++++++++++++++++++++ library/VTableInterpose.cpp | 6 +++++- library/include/DataIdentity.h | 5 +++++ library/include/VersionInfo.h | 2 +- plugins/CMakeLists.txt | 2 +- 9 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 291fab324..de8c48846 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,8 +48,8 @@ if(UNIX) endif() if(WIN32) - if((NOT MSVC) OR (NOT MSVC_VERSION STREQUAL 1600)) - message(SEND_ERROR "MSVC 2010 is required") + if((NOT MSVC) OR (NOT MSVC_VERSION STREQUAL 1900)) + message(SEND_ERROR "MSVC 2015 is required") endif() endif() @@ -177,6 +177,7 @@ ELSEIF(MSVC) # for msvc, tell it to always use 8-byte pointers to member functions to avoid confusion SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /vmg /vmm /MP") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Od") + ADD_DEFINITIONS(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS) ENDIF() # use shared libraries for protobuf diff --git a/depends/lua/src/lobject.c b/depends/lua/src/lobject.c index a44b3850f..0c6e7a9e7 100644 --- a/depends/lua/src/lobject.c +++ b/depends/lua/src/lobject.c @@ -280,7 +280,7 @@ static const char *l_str2d (const char *s, lua_Number *result) { endptr = l_str2dloc(s, result, mode); /* try to convert */ if (endptr == NULL) { /* failed? may be a different locale */ char buff[L_MAXLENNUM + 1]; - char *pdot = strchr(s, '.'); + char *pdot = (char*)strchr(s, '.'); if (strlen(s) > L_MAXLENNUM || pdot == NULL) return NULL; /* string too long or no dot; fail */ strcpy(buff, s); /* copy string to buffer */ @@ -394,7 +394,7 @@ static void pushstr (lua_State *L, const char *str, size_t l) { /* -** this function handles only '%d', '%c', '%f', '%p', and '%s' +** this function handles only '%d', '%c', '%f', '%p', and '%s' conventional formats, plus Lua-specific '%I' and '%U' */ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { diff --git a/depends/tthread/fast_mutex.h b/depends/tthread/fast_mutex.h index 6627408e4..a381b2c75 100644 --- a/depends/tthread/fast_mutex.h +++ b/depends/tthread/fast_mutex.h @@ -39,7 +39,7 @@ freely, subject to the following restrictions: // Check if we can support the assembly language level implementation (otherwise // revert to the system API) #if (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) || \ - (defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))) || \ + (defined(_MSC_VER) && (defined(_M_IX86) /*|| defined(_M_X64)*/)) || \ (defined(__GNUC__) && (defined(__ppc__))) #define _FAST_MUTEX_ASM_ #else diff --git a/library/DataStaticsFields.cpp b/library/DataStaticsFields.cpp index 96f91dd66..9115784d7 100644 --- a/library/DataStaticsFields.cpp +++ b/library/DataStaticsFields.cpp @@ -30,8 +30,13 @@ namespace df { NUMBER_IDENTITY_TRAITS(uint32_t); NUMBER_IDENTITY_TRAITS(int64_t); NUMBER_IDENTITY_TRAITS(uint64_t); +#ifdef _WIN32 + NUMBER_IDENTITY_TRAITS(long); + NUMBER_IDENTITY_TRAITS(unsigned long); +#else NUMBER_IDENTITY_TRAITS(intptr_t); NUMBER_IDENTITY_TRAITS(uintptr_t); +#endif NUMBER_IDENTITY_TRAITS(float); NUMBER_IDENTITY_TRAITS(double); diff --git a/library/Hooks-windows.cpp b/library/Hooks-windows.cpp index 7ea1385a7..3d925bc27 100644 --- a/library/Hooks-windows.cpp +++ b/library/Hooks-windows.cpp @@ -726,6 +726,22 @@ DFhackCExport uint32_t SDL_ThreadID(void) return _SDL_ThreadID(); } +static char* (*_SDL_getenv)(const char *name) = 0; +DFhackCExport char* SDL_getenv(const char *name) +{ + if(!inited) + FirstCall(); + return _SDL_getenv(name); +} + +static size_t (*_SDL_strlcat)(char *dst, const char *src, size_t maxlen) = 0; +DFhackCExport size_t SDL_strlcat(char *dst, const char *src, size_t maxlen) +{ + if(!inited) + FirstCall(); + return _SDL_strlcat(dst, src, maxlen); +} + // FIXME: this has to be thread-safe. bool FirstCall() { @@ -813,6 +829,10 @@ bool FirstCall() _SDL_SemWait = (int (*)(void *))GetProcAddress(realSDLlib,"SDL_SemWait"); _SDL_ThreadID = (uint32_t (*)(void))GetProcAddress(realSDLlib,"SDL_ThreadID"); + // new in DF 0.43.05 + _SDL_getenv = (char* (*)(const char*))GetProcAddress(realSDLlib,"SDL_getenv"); + _SDL_strlcat = (size_t (*)(char*, const char*, size_t))GetProcAddress(realSDLlib,"SDL_strlcat"); + _SDL_EnableUNICODE(1); fprintf(stderr,"Initized HOOKS!\n"); diff --git a/library/VTableInterpose.cpp b/library/VTableInterpose.cpp index d81c6d730..63edb2205 100644 --- a/library/VTableInterpose.cpp +++ b/library/VTableInterpose.cpp @@ -82,7 +82,7 @@ using namespace DFHack; // multiple, but not virtual inheritance. struct MSVC_MPTR { void *method; - intptr_t this_shift; + uint32_t this_shift; // was intptr_t pre-0.43.05 }; // Debug builds sometimes use additional thunks that @@ -97,7 +97,11 @@ static uint32_t *follow_jmp(void *ptr) switch (*p) { case 0xE9: // jmp near rel32 +#ifdef DFHACK64 + p += 5 + *(int32_t*)(p+1) + 1; +#else p += 5 + *(int32_t*)(p+1); +#endif break; case 0xEB: // jmp short rel8 p += 2 + *(int8_t*)(p+1); diff --git a/library/include/DataIdentity.h b/library/include/DataIdentity.h index 10c905df3..32bbf0d5d 100644 --- a/library/include/DataIdentity.h +++ b/library/include/DataIdentity.h @@ -487,8 +487,13 @@ namespace df NUMBER_IDENTITY_TRAITS(uint32_t); NUMBER_IDENTITY_TRAITS(int64_t); NUMBER_IDENTITY_TRAITS(uint64_t); +#ifdef _WIN32 + NUMBER_IDENTITY_TRAITS(long); + NUMBER_IDENTITY_TRAITS(unsigned long); +#else NUMBER_IDENTITY_TRAITS(intptr_t); NUMBER_IDENTITY_TRAITS(uintptr_t); +#endif NUMBER_IDENTITY_TRAITS(float); NUMBER_IDENTITY_TRAITS(double); diff --git a/library/include/VersionInfo.h b/library/include/VersionInfo.h index 58ecb2c28..b3d6c8346 100644 --- a/library/include/VersionInfo.h +++ b/library/include/VersionInfo.h @@ -53,7 +53,7 @@ namespace DFHack std::map Addresses; std::map VTables; uintptr_t base; - int rebase_delta; + uintptr_t rebase_delta; std::string version; OSType OS; public: diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index c24b940b9..46c4b8054 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -91,7 +91,7 @@ if (BUILD_SUPPORTED) DFHACK_PLUGIN(deramp deramp.cpp) DFHACK_PLUGIN(dig dig.cpp) DFHACK_PLUGIN(digFlood digFlood.cpp) - add_subdirectory(diggingInvaders) + # add_subdirectory(diggingInvaders) DFHACK_PLUGIN(dwarfmonitor dwarfmonitor.cpp LINK_LIBRARIES lua) DFHACK_PLUGIN(embark-tools embark-tools.cpp) DFHACK_PLUGIN(eventful eventful.cpp LINK_LIBRARIES lua)