VirtualBox

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

Last change on this file since 31157 was 31157, checked in by vboxsync, 14 years ago

iprt,++: Tag allocation in all builds with a string, defaulting to FILE.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1/* $Id: alloc-ef-cpp.cpp 31157 2010-07-28 03:15:35Z vboxsync $ */
2/** @file
3 * IPRT - Memory Allocation, C++ electric fence.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
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#if defined(RTALLOC_EFENCE_CPP) || defined(RTMEM_WRAP_TO_EF_APIS) /* rest of the file */
33
34#include <iprt/asm.h>
35#include <new>
36
37
38/*******************************************************************************
39* Defined Constants And Macros *
40*******************************************************************************/
41/** @todo test this on MSC */
42
43/* MSC declares the operators as cdecl it seems. */
44#ifdef _MSC_VER
45# define RT_EF_CDECL __cdecl
46#else
47# define RT_EF_CDECL
48#endif
49
50/* MSC doesn't use the standard namespace. */
51#ifdef _MSC_VER
52# define RT_EF_SIZE_T size_t
53#else
54# define RT_EF_SIZE_T std::size_t
55#endif
56
57
58void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc)
59{
60 void *pv = rtR3MemAlloc("new", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
61 if (!pv)
62 throw std::bad_alloc();
63 return pv;
64}
65
66
67void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
68{
69 void *pv = rtR3MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
70 return pv;
71}
72
73
74void RT_EF_CDECL operator delete(void *pv) throw()
75{
76 rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
77}
78
79
80void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) throw()
81{
82 rtR3MemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
83}
84
85
86/*
87 *
88 * Array object form.
89 * Array object form.
90 * Array object form.
91 *
92 */
93
94void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc)
95{
96 void *pv = rtR3MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
97 if (!pv)
98 throw std::bad_alloc();
99 return pv;
100}
101
102
103void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
104{
105 void *pv = rtR3MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
106 return pv;
107}
108
109
110void RT_EF_CDECL operator delete[](void * pv) throw()
111{
112 rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
113}
114
115
116void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) throw()
117{
118 rtR3MemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
119}
120
121#endif /* RTALLOC_EFENCE_CPP || RTMEM_WRAP_TO_EF_APIS */
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