summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt9
-rw-r--r--src/core/CMakeLists.txt3
-rw-r--r--src/modules/CMakeLists.txt3
-rw-r--r--src/protocol/CMakeLists.txt3
-rw-r--r--src/win32_memory.cpp57
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);
+}