2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
6 * Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
7 * Copyright (C) 2011, 2013 Adam <Adam@anope.org>
8 * Copyright (C) 2009 John Brooks <special@inspircd.org>
9 * Copyright (C) 2007-2008 Craig Edwards <brain@inspircd.org>
10 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 /** On windows, all dll files and executables have their own private heap,
33 * whereas on POSIX systems, shared objects loaded into an executable share
34 * the executable's heap. This means that if we pass an arbitrary pointer to
35 * a windows DLL which is not allocated in that dll, without some form of
36 * marshalling, we get a page fault. To fix this, these overridden operators
37 * new and delete use the windows HeapAlloc and HeapFree functions to claim
38 * memory from the windows global heap. This makes windows 'act like' POSIX
39 * when it comes to memory usage between dlls and exes.
42 void * ::operator new(size_t iSize)
44 void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize);
45 /* This is the correct behaviour according to C++ standards for out of memory,
46 * not returning null -- Brain
49 throw std::bad_alloc();
54 void ::operator delete(void * ptr)
57 HeapFree(GetProcessHeap(), 0, ptr);
60 void * operator new[] (size_t iSize)
62 void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize);
64 throw std::bad_alloc();
69 void operator delete[] (void* ptr)
72 HeapFree(GetProcessHeap(), 0, ptr);