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 /src | |
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
Diffstat (limited to 'src')
-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 |
5 files changed, 74 insertions, 1 deletions
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); +} |