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 Dennis Friis <peavey@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 /** On windows, all dll files and executables have their own private heap,
32 * whereas on POSIX systems, shared objects loaded into an executable share
33 * the executable's heap. This means that if we pass an arbitrary pointer to
34 * a windows DLL which is not allocated in that dll, without some form of
35 * marshalling, we get a page fault. To fix this, these overridden operators
36 * new and delete use the windows HeapAlloc and HeapFree functions to claim
37 * memory from the windows global heap. This makes windows 'act like' POSIX
38 * when it comes to memory usage between dlls and exes.
41 void * ::operator new(size_t iSize)
43 void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize);
44 /* This is the correct behaviour according to C++ standards for out of memory,
45 * not returning null -- Brain
48 throw std::bad_alloc();
53 void ::operator delete(void * ptr)
56 HeapFree(GetProcessHeap(), 0, ptr);
59 void * operator new[] (size_t iSize)
61 void* ptr = HeapAlloc(GetProcessHeap(), 0, iSize);
63 throw std::bad_alloc();
68 void operator delete[] (void* ptr)
71 HeapFree(GetProcessHeap(), 0, ptr);