2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2024-06-07 10:37:56 +01:00
|
|
|
* Copyright (C) 2013, 2022 Sadie Powell <sadie@witchery.services>
|
2022-12-30 11:31:28 +00:00
|
|
|
* Copyright (C) 2013 Adam <Adam@anope.org>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2012 Robby <robby@chatbelgie.be>
|
|
|
|
* Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
|
2024-06-21 10:36:09 +01:00
|
|
|
* Copyright (C) 2009 John Brooks <john@jbrooks.io>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2007-2008 Craig Edwards <brain@inspircd.org>
|
2021-03-05 02:04:16 +00:00
|
|
|
* Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
|
2012-04-19 20:58:29 +02:00
|
|
|
* Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
* redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
|
|
|
|
2013-04-02 20:12:15 +01:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
#include <exception>
|
|
|
|
#include <new>
|
2022-01-26 08:50:29 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
2007-07-16 17:30:04 +00:00
|
|
|
|
|
|
|
/** 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
|
2020-04-21 06:34:17 +00:00
|
|
|
* marshalling, we get a page fault. To fix this, these overridden operators
|
2007-07-16 17:30:04 +00:00
|
|
|
* 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)
|
|
|
|
{
|
Windows: In-depth cleanup (see details)
-Fix x64 builds for Windows. Now all configurations compile.
-Remove the non-working rebase stuff.
-Remove the Windows fork hack and instead use FreeConsole() to emulate the behavior. This directly allows us to compile with ASLR, which is turned on now.
-Remove the old IPC mechanism for the removed GUI. This is not needed anymore as the GUI wasn't ever supported on anything newer than 1.2
-Remove the WIN32/WINDOWS macros. _WIN32 is supported on all x86-based VC++ targets, so that's what we need.
-Enable optimizations for release builds.
-De-duplicate printf_c(), it was previously copy-pasted into colors.h for configure
-Add the VC++ specific bad files in .gitignore
-Disable PID writing on Windows. This is only making sense for *nix builds.
-Replace the CPU usage retrieval with an algorithm analogous to the *nix behavior. Also supports separated now/total values. (Tested with a dummy busy loop - seems working)
-Removed certain unused functions and variables
-Remove stdint defines from the windows wrapper
-Remove CRT debug alloc. This is a bad idea as it would define a macro to replace free which breaks builds.
-Re-evaluated the warnings list, commented it.
-Moved inspircd_config/_version to include/ to match *nix
-Removed the creation of inspircd_se_config, as it isn't used at all.
-Made non-git builds show as "r0" instead of "r" (thanks to @SaberUK for pointing this out)
-Fixed up m_spanningtree's project paths. Now all configurations (debug/release x86/x64) have been tested and build properly.
-Moved FindDNS out of the wrapper and matched its log behavior with *nix. (It's pointless having it in the wrapper after the recent slimming down)
-Replaced random/srandom wrappers with a mechanism that tries to use Windows' Random API first is no SSL module is loaded.
-Removed more old junk from support for compilers older than VC++ 2010 (we don't have project files for these, so compiling them would be hard anyways)
-Removed the unused ClearConsole()
-Removed unused includes from the wrapper. Also, do not include psapi.h here if we don't link psapi.lib. This should be done where appropriate.
-Made inet_aton an inline function for increased performance
-C4800, performance warning about bool forcing, resolved at all occurrences.
-C4701, uninitialized variable 'cached', resolved at all occurrences.
-dlerror() was migrated out of the wrapper for more thread safety (no global buffer being shared) and increased performance.
-Removed the wrong CRT debug flags. This drains a lot of performance.
-Removed the clock_gettime/gettimeofday wrappers
-Replaced all TCHAR/ANSI mix-ups of functions with the correct respective function.
-Added a block of C4355 for < VS2012
-Update project files for c870714
2012-10-12 22:31:38 +02:00
|
|
|
void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize);
|
2007-07-16 17:30:04 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
2009-07-19 07:27:30 +00:00
|
|
|
if (ptr)
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
2007-07-16 17:30:04 +00:00
|
|
|
}
|
2008-04-17 20:27:33 +00:00
|
|
|
|
2013-03-14 15:19:41 -04:00
|
|
|
void * operator new[] (size_t iSize)
|
|
|
|
{
|
Windows: In-depth cleanup (see details)
-Fix x64 builds for Windows. Now all configurations compile.
-Remove the non-working rebase stuff.
-Remove the Windows fork hack and instead use FreeConsole() to emulate the behavior. This directly allows us to compile with ASLR, which is turned on now.
-Remove the old IPC mechanism for the removed GUI. This is not needed anymore as the GUI wasn't ever supported on anything newer than 1.2
-Remove the WIN32/WINDOWS macros. _WIN32 is supported on all x86-based VC++ targets, so that's what we need.
-Enable optimizations for release builds.
-De-duplicate printf_c(), it was previously copy-pasted into colors.h for configure
-Add the VC++ specific bad files in .gitignore
-Disable PID writing on Windows. This is only making sense for *nix builds.
-Replace the CPU usage retrieval with an algorithm analogous to the *nix behavior. Also supports separated now/total values. (Tested with a dummy busy loop - seems working)
-Removed certain unused functions and variables
-Remove stdint defines from the windows wrapper
-Remove CRT debug alloc. This is a bad idea as it would define a macro to replace free which breaks builds.
-Re-evaluated the warnings list, commented it.
-Moved inspircd_config/_version to include/ to match *nix
-Removed the creation of inspircd_se_config, as it isn't used at all.
-Made non-git builds show as "r0" instead of "r" (thanks to @SaberUK for pointing this out)
-Fixed up m_spanningtree's project paths. Now all configurations (debug/release x86/x64) have been tested and build properly.
-Moved FindDNS out of the wrapper and matched its log behavior with *nix. (It's pointless having it in the wrapper after the recent slimming down)
-Replaced random/srandom wrappers with a mechanism that tries to use Windows' Random API first is no SSL module is loaded.
-Removed more old junk from support for compilers older than VC++ 2010 (we don't have project files for these, so compiling them would be hard anyways)
-Removed the unused ClearConsole()
-Removed unused includes from the wrapper. Also, do not include psapi.h here if we don't link psapi.lib. This should be done where appropriate.
-Made inet_aton an inline function for increased performance
-C4800, performance warning about bool forcing, resolved at all occurrences.
-C4701, uninitialized variable 'cached', resolved at all occurrences.
-dlerror() was migrated out of the wrapper for more thread safety (no global buffer being shared) and increased performance.
-Removed the wrong CRT debug flags. This drains a lot of performance.
-Removed the clock_gettime/gettimeofday wrappers
-Replaced all TCHAR/ANSI mix-ups of functions with the correct respective function.
-Added a block of C4355 for < VS2012
-Update project files for c870714
2012-10-12 22:31:38 +02:00
|
|
|
void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize);
|
2008-04-17 20:27:33 +00:00
|
|
|
if (!ptr)
|
|
|
|
throw std::bad_alloc();
|
|
|
|
else
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator delete[] (void* ptr)
|
|
|
|
{
|
2009-07-19 07:27:30 +00:00
|
|
|
if (ptr)
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
2008-04-17 20:27:33 +00:00
|
|
|
}
|