VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/alloc-ef-cpp.cpp@ 6677

Last change on this file since 6677 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1/* $Id: alloc-ef-cpp.cpp 5999 2007-12-07 15:05:06Z 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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include "alloc-ef.h"
31
32#ifdef RTALLOC_EFENCE_CPP /* rest of the file */
33
34#include <new>
35
36
37/*******************************************************************************
38* Defined Constants And Macros *
39*******************************************************************************/
40/** @todo test this on MSC */
41
42/* MSC declares the operators as cdecl it seems. */
43#ifdef _MSC_VER
44# define RT_EF_CDECL __cdecl
45#else
46# define RT_EF_CDECL
47#endif
48
49/* MSC doesn't use the standard namespace. */
50#ifdef _MSC_VER
51# define RT_EF_SIZE_T size_t
52#else
53# define RT_EF_SIZE_T std::size_t
54#endif
55
56
57void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc)
58{
59 void *pv = rtMemAlloc("new", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
60 if (!pv)
61 throw std::bad_alloc();
62 return pv;
63}
64
65
66void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
67{
68 void *pv = rtMemAlloc("new nothrow", RTMEMTYPE_NEW, cb, ((void **)&cb)[-1], 0, NULL, NULL);
69 return pv;
70}
71
72
73void RT_EF_CDECL operator delete(void *pv) throw()
74{
75 rtMemFree("delete", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
76}
77
78
79void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) throw()
80{
81 rtMemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ((void **)&pv)[-1], 0, NULL, NULL);
82}
83
84
85/*
86 *
87 * Array object form.
88 * Array object form.
89 * Array object form.
90 *
91 */
92
93void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc)
94{
95 void *pv = rtMemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
96 if (!pv)
97 throw std::bad_alloc();
98 return pv;
99}
100
101
102void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
103{
104 void *pv = rtMemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, ((void **)&cb)[-1], 0, NULL, NULL);
105 return pv;
106}
107
108
109void RT_EF_CDECL operator delete[](void * pv) throw()
110{
111 rtMemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
112}
113
114
115void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) throw()
116{
117 rtMemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ((void **)&pv)[-1], 0, NULL, NULL);
118}
119
120#endif /* RTALLOC_EFENCE_CPP */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette