1 | /* $Id: alloc-ef-cpp.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime - Memory Allocation, C++ electric fence.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
8 | *
|
---|
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.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #include "alloc-ef.h"
|
---|
22 |
|
---|
23 | #ifdef RTALLOC_EFENCE_CPP /* rest of the file */
|
---|
24 |
|
---|
25 | #include <new>
|
---|
26 |
|
---|
27 |
|
---|
28 | /*******************************************************************************
|
---|
29 | * Defined Constants And Macros *
|
---|
30 | *******************************************************************************/
|
---|
31 | /** @todo test this on MSC */
|
---|
32 |
|
---|
33 | /* MSC declares the operators as cdecl it seems. */
|
---|
34 | #ifdef _MSC_VER
|
---|
35 | # define RT_EF_CDECL __cdecl
|
---|
36 | #else
|
---|
37 | # define RT_EF_CDECL
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | /* MSC doesn't use the standard namespace. */
|
---|
41 | #ifdef _MSC_VER
|
---|
42 | # define RT_EF_SIZE_T size_t
|
---|
43 | #else
|
---|
44 | # define RT_EF_SIZE_T std::size_t
|
---|
45 | #endif
|
---|
46 |
|
---|
47 |
|
---|
48 | void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc)
|
---|
49 | {
|
---|
50 | void *pv = rtMemAlloc("new", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
|
---|
51 | if (!pv)
|
---|
52 | throw std::bad_alloc();
|
---|
53 | return pv;
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
|
---|
58 | {
|
---|
59 | void *pv = rtMemAlloc("new nothrow", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
|
---|
60 | return pv;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | void RT_EF_CDECL operator delete(void *pv) throw()
|
---|
65 | {
|
---|
66 | rtMemFree("delete", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) throw()
|
---|
71 | {
|
---|
72 | rtMemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | /*
|
---|
77 | *
|
---|
78 | * Array object form.
|
---|
79 | * Array object form.
|
---|
80 | * Array object form.
|
---|
81 | *
|
---|
82 | */
|
---|
83 |
|
---|
84 | void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc)
|
---|
85 | {
|
---|
86 | void *pv = rtMemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
|
---|
87 | if (!pv)
|
---|
88 | throw std::bad_alloc();
|
---|
89 | return pv;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
|
---|
94 | {
|
---|
95 | void *pv = rtMemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
|
---|
96 | return pv;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | void RT_EF_CDECL operator delete[](void * pv) throw()
|
---|
101 | {
|
---|
102 | rtMemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) throw()
|
---|
107 | {
|
---|
108 | rtMemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
|
---|
109 | }
|
---|
110 |
|
---|
111 | #endif /* RTALLOC_EFENCE_CPP */
|
---|