diff options
author | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-12-17 20:17:30 +0000 |
---|---|---|
committer | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-12-17 20:17:30 +0000 |
commit | c4a8cc7e2f3890b8d82051c89748bea80350e8d4 (patch) | |
tree | a08d706405cf90d1b319885e56a07285315e70c7 | |
parent | 88701c226e2e13cd9e339eab46e65dced75497b2 (diff) |
Fixed issue with the MSVC++ build of Anope crashing on a DLL throwing an exception, thanks to w00t for pointing out the overloaded new/delete operators from InspIRCd.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1838 5417fbe8-f217-4b02-8779-1006273d7864
-rw-r--r-- | CMakeLists.txt | 20 | ||||
-rw-r--r-- | src/CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/core/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/modules/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/protocol/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/win32_memory.cpp | 57 |
6 files changed, 85 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e3b91faa..5169b6082 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,11 +5,13 @@ cmake_minimum_required(VERSION 2.6) # and dump it in the cache along with proper documentation, otherwise set CMAKE_BUILD_TYPE # to Debug prior to calling PROJECT() # -IF(CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") -ELSE(CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE DEBUG CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") -ENDIF(CMAKE_BUILD_TYPE) +if(NOT WIN32 OR NOT MSVC) + if(CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") + else(CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE DEBUG CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.") + endif(CMAKE_BUILD_TYPE) +endif(NOT WIN32 OR NOT MSVC) project(Anope CXX) enable_language(C) @@ -37,7 +39,7 @@ endif(NOT WIN32) if(WIN32 AND MSVC) string(REPLACE "/EHsc " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) string(REPLACE "/GX " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) - set(CXXFLAGS "${CXXFLAGS} /W4 /EHs /D_WIN32 /DMSVCPP /I${Anope_SOURCE_DIR}/include /I${Anope_BINARY_DIR}/include /I${Anope_BINARY_DIR}/lang") + set(CXXFLAGS "${CXXFLAGS} /W4 /EHa /RTC1 /D_WIN32 /DMSVCPP /I ${Anope_SOURCE_DIR}/include /I ${Anope_BINARY_DIR}/include /I ${Anope_BINARY_DIR}/lang") set(MODULE_CXXFLAGS "${CXXFLAGS} /DMODULE_COMPILE") else(WIN32 AND MSVC) set(CXXFLAGS "${CXXFLAGS} -Wall -Wshadow -I${Anope_SOURCE_DIR}/include -I${Anope_BINARY_DIR}/include -I${Anope_BINARY_DIR}/lang") @@ -52,9 +54,9 @@ else(WIN32 AND MSVC) set(MODULE_CXXFLAGS "${CXXFLAGS}") endif(WIN32 AND MSVC) message(STATUS "CMAKE_CXX_CREATE_SHARED_MODULE: ${CMAKE_CXX_CREATE_SHARED_MODULE}") -if(CMAKE_BUILD_TYPE) - set(CXXFLAGS "${CXXFLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}") -endif(CMAKE_BUILD_TYPE) +#if(CMAKE_BUILD_TYPE) +# set(CXXFLAGS "${CXXFLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}") +#endif(CMAKE_BUILD_TYPE) if(CMAKE_DL_LIBS) set(LDFLAGS "${LDFLAGS} ${CMAKE_DL_LIBS}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7df4cfc7e..cf1d51bb4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,9 @@ set(SRC_SRCS actions.c base64.c bots.cpp botserv.c channels.c chanserv.c main.c memory.c memoserv.c messages.c misc.c module.cpp modulemanager.cpp modules.c news.c nickserv.c operserv.c process.c send.c servers.c sessions.c slist.c sockutil.c timeout.c users.c) +if(WIN32 AND MSVC) + set(SRC_SRCS ${SRC_SRCS} win32_memory.cpp) +endif(WIN32 AND MSVC) list(SORT SRC_SRCS) set_source_files_properties(${SRC_SRCS} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS}") @@ -118,7 +121,11 @@ if(WIN32) message(STATUS "CMAKE_RC_OUTPUT_EXTENSION: ${CMAKE_RC_OUTPUT_EXTENSION}") endif(WIN32) add_executable(${PROGRAM_NAME} ${SRC_SRCS}) -set_target_properties(${PROGRAM_NAME} PROPERTIES LINK_FLAGS "${LDFLAGS}") +set(SERVICES_LDFLAGS "${LDFLAGS}") +if(WIN32 AND MSVC) + set(SERVICES_LDFLAGS "${SERVICES_LDFLAGS} /FIXED:NO") +endif(WIN32 AND MSVC) +set_target_properties(${PROGRAM_NAME} PROPERTIES LINK_FLAGS "${SERVICES_LDFLAGS}") set_target_properties(${PROGRAM_NAME} PROPERTIES ENABLE_EXPORTS ON) if(WIN32) target_link_libraries(${PROGRAM_NAME} wsock32) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 922a48d97..ebe8f6dca 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -55,6 +55,9 @@ foreach(SRC ${CORE_SRCS}) if(HEADERS) set_source_files_properties(${SRC} PROPERTIES OBJECT_DEPENDS "${HEADERS}") endif(HEADERS) + if(WIN32 AND MSVC) + set(SRC ${SRC} ${Anope_SOURCE_DIR}/src/win32_memory.cpp) + endif(WIN32 AND MSVC) add_library(${SO} MODULE ${SRC}) add_dependencies(${SO} ${PROGRAM_NAME}) #set_target_properties(${SO} PROPERTIES PREFIX "" SUFFIX "" COMPILE_FLAGS ${CXXFLAGS}) diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index af6fcda20..34924e362 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -50,6 +50,9 @@ foreach(SRC ${MODULES_SRCS}) if(HEADERS) set_source_files_properties(${SRC} PROPERTIES OBJECT_DEPENDS "${HEADERS}") endif(HEADERS) + if(WIN32 AND MSVC) + set(SRC ${SRC} ${Anope_SOURCE_DIR}/src/win32_memory.cpp) + endif(WIN32 AND MSVC) add_library(${SO} MODULE ${SRC}) add_dependencies(${SO} ${PROGRAM_NAME}) #set_target_properties(${SO} PROPERTIES PREFIX "" SUFFIX "" COMPILE_FLAGS ${CXXFLAGS}) diff --git a/src/protocol/CMakeLists.txt b/src/protocol/CMakeLists.txt index 50d763651..1c91a1ff2 100644 --- a/src/protocol/CMakeLists.txt +++ b/src/protocol/CMakeLists.txt @@ -50,6 +50,9 @@ foreach(SRC ${PROTOCOL_SRCS}) if(HEADERS) set_source_files_properties(${SRC} PROPERTIES OBJECT_DEPENDS "${HEADERS}") endif(HEADERS) + if(WIN32 AND MSVC) + set(SRC ${SRC} ${Anope_SOURCE_DIR}/src/win32_memory.cpp) + endif(WIN32 AND MSVC) add_library(${SO} MODULE ${SRC}) add_dependencies(${SO} ${PROGRAM_NAME}) #set_target_properties(${SO} PROPERTIES PREFIX "" SUFFIX "" COMPILE_FLAGS ${CXXFLAGS}) diff --git a/src/win32_memory.cpp b/src/win32_memory.cpp new file mode 100644 index 000000000..a83677eb2 --- /dev/null +++ b/src/win32_memory.cpp @@ -0,0 +1,57 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2008 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +#include <windows.h> +#include <exception> +#include <new> +#include <new.h> + +/** On windows, all dll files and executables have their own private heap, + * whereas on POSIX systems, shared objects loaded into an executable share + * the executable's heap. This means that if we pass an arbitrary pointer to + * a windows DLL which is not allocated in that dll, without some form of + * marshalling, we get a page fault. To fix this, these overrided operators + * new and delete use the windows HeapAlloc and HeapFree functions to claim + * memory from the windows global heap. This makes windows 'act like' POSIX + * when it comes to memory usage between dlls and exes. + */ + +void * ::operator new(size_t iSize) +{ + void *ptr = HeapAlloc(GetProcessHeap(), 0, iSize); /* zero memory for unix compatibility */ + /* This is the correct behaviour according to C++ standards for out of memory, + * not returning null -- Brain + */ + if (!ptr) + throw std::bad_alloc(); + else + return ptr; +} + +void ::operator delete(void *ptr) +{ + HeapFree(GetProcessHeap(), 0, ptr); +} + +void * operator new[](size_t iSize) { + void *ptr = HeapAlloc(GetProcessHeap(), 0, iSize); /* Why were we initializing the memory to zeros here? This is just a waste of cpu! */ + if (!ptr) + throw std::bad_alloc(); + else + return ptr; +} + +void operator delete[](void *ptr) +{ + HeapFree(GetProcessHeap(), 0, ptr); +} |