VirtualBox

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

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

alloc-ef-cpp.cpp: Always compile the stuff, so that fencing depends on linking with this library.

  • 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 39087 2011-10-24 10:05:00Z 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#include <iprt/asm.h>
33#include <new>
34
35
36/*******************************************************************************
37* Defined Constants And Macros *
38*******************************************************************************/
39/** @todo test this on MSC */
40
41/* MSC declares the operators as cdecl it seems. */
42#ifdef _MSC_VER
43# define RT_EF_CDECL __cdecl
44#else
45# define RT_EF_CDECL
46#endif
47
48/* MSC doesn't use the standard namespace. */
49#ifdef _MSC_VER
50# define RT_EF_SIZE_T size_t
51#else
52# define RT_EF_SIZE_T std::size_t
53#endif
54
55
56void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) throw(std::bad_alloc)
57{
58 void *pv = rtR3MemAlloc("new", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
59 if (!pv)
60 throw std::bad_alloc();
61 return pv;
62}
63
64
65void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
66{
67 void *pv = rtR3MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
68 return pv;
69}
70
71
72void RT_EF_CDECL operator delete(void *pv) throw()
73{
74 rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
75}
76
77
78void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) throw()
79{
80 rtR3MemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
81}
82
83
84/*
85 *
86 * Array object form.
87 * Array object form.
88 * Array object form.
89 *
90 */
91
92void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) throw(std::bad_alloc)
93{
94 void *pv = rtR3MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
95 if (!pv)
96 throw std::bad_alloc();
97 return pv;
98}
99
100
101void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) throw()
102{
103 void *pv = rtR3MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
104 return pv;
105}
106
107
108void RT_EF_CDECL operator delete[](void * pv) throw()
109{
110 rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
111}
112
113
114void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) throw()
115{
116 rtR3MemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
117}
118
119
Note: See TracBrowser for help on using the repository browser.

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