1
/* $Id: alloc-ef-cpp.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
3
* innotek Portable Runtime - Memory Allocation, C++ electric fence.
7
* Copyright (C) 2006-2007 innotek GmbH
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
* available from http://www.virtualbox.org. This file is free software;
11
* you can redistribute it and/or modify it under the terms of the GNU
12
* General Public License as published by the Free Software Foundation,
13
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14
* distribution. VirtualBox OSE is distributed in the hope that it will
15
* be useful, but WITHOUT ANY WARRANTY of any kind.
18
/*******************************************************************************
20
*******************************************************************************/
23
#ifdef RTALLOC_EFENCE_CPP /* rest of the file */
28
/*******************************************************************************
29
* Defined Constants And Macros *
30
*******************************************************************************/
31
/** @todo test this on MSC */
33
/* MSC declares the operators as cdecl it seems. */
35
# define RT_EF_CDECL __cdecl
40
/* MSC doesn't use the standard namespace. */
42
# define RT_EF_SIZE_T size_t
44
# define RT_EF_SIZE_T std::size_t
48
void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc)
50
void *pv = rtMemAlloc("new", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
52
throw std::bad_alloc();
57
void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
59
void *pv = rtMemAlloc("new nothrow", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
64
void RT_EF_CDECL operator delete(void *pv) throw()
66
rtMemFree("delete", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
70
void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) throw()
72
rtMemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
84
void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc)
86
void *pv = rtMemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
88
throw std::bad_alloc();
93
void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
95
void *pv = rtMemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
100
void RT_EF_CDECL operator delete[](void * pv) throw()
102
rtMemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
106
void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) throw()
108
rtMemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
111
#endif /* RTALLOC_EFENCE_CPP */