VirtualBox

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

Last change on this file since 76553 was 76553, checked in by vboxsync, 5 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.9 KB
RevLine 
[1]1/* $Id: alloc-ef-cpp.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
[8245]3 * IPRT - Memory Allocation, C++ electric fence.
[1]4 */
5
6/*
[76553]7 * Copyright (C) 2006-2019 Oracle Corporation
[1]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
[5999]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.
[1]25 */
26
[57358]27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
[1]31#include "alloc-ef.h"
32
[28298]33#include <iprt/asm.h>
[1]34#include <new>
35
36
[57358]37/*********************************************************************************************************************************
38* Defined Constants And Macros *
39*********************************************************************************************************************************/
[1]40/** @todo test this on MSC */
41
[39088]42/** MSC declares the operators as cdecl it seems. */
[1]43#ifdef _MSC_VER
44# define RT_EF_CDECL __cdecl
45#else
46# define RT_EF_CDECL
47#endif
48
[39088]49/** MSC doesn't use the standard namespace. */
[1]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
[39088]56/** The hint that we're throwing std::bad_alloc is not apprecitated by MSC. */
[39089]57#ifdef RT_EXCEPTIONS_ENABLED
58# ifdef _MSC_VER
[39092]59# define RT_EF_THROWS_BAD_ALLOC
[57434]60# define RT_EF_NOTHROW RT_NO_THROW_DEF
[39088]61# else
[54372]62# ifdef _GLIBCXX_THROW
63# define RT_EF_THROWS_BAD_ALLOC _GLIBCXX_THROW(std::bad_alloc)
64# else
65# define RT_EF_THROWS_BAD_ALLOC throw(std::bad_alloc)
66# endif
[57434]67# define RT_EF_NOTHROW throw()
[39088]68# endif
[39089]69#else /* !RT_EXCEPTIONS_ENABLED */
70# define RT_EF_THROWS_BAD_ALLOC
[57434]71# define RT_EF_NOTHROW
[39089]72#endif /* !RT_EXCEPTIONS_ENABLED */
[1]73
[39088]74
75void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb) RT_EF_THROWS_BAD_ALLOC
[1]76{
[31157]77 void *pv = rtR3MemAlloc("new", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
[1]78 if (!pv)
79 throw std::bad_alloc();
80 return pv;
81}
82
83
[57434]84void *RT_EF_CDECL operator new(RT_EF_SIZE_T cb, const std::nothrow_t &) RT_EF_NOTHROW
[1]85{
[31157]86 void *pv = rtR3MemAlloc("new nothrow", RTMEMTYPE_NEW, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
[1]87 return pv;
88}
89
90
[57434]91void RT_EF_CDECL operator delete(void *pv) RT_EF_NOTHROW
[1]92{
[28298]93 rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
[1]94}
95
96
[59273]97#ifdef __cpp_sized_deallocation
98void RT_EF_CDECL operator delete(void *pv, RT_EF_SIZE_T cb) RT_EF_NOTHROW
99{
100 NOREF(cb);
101 AssertMsgFailed(("cb ignored!\n"));
102 rtR3MemFree("delete", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
103}
104#endif
105
106
[57434]107void RT_EF_CDECL operator delete(void * pv, const std::nothrow_t &) RT_EF_NOTHROW
[1]108{
[28298]109 rtR3MemFree("delete nothrow", RTMEMTYPE_DELETE, pv, ASMReturnAddress(), NULL, 0, NULL);
[1]110}
111
112
113/*
114 *
115 * Array object form.
116 * Array object form.
117 * Array object form.
118 *
119 */
120
[39088]121void *RT_EF_CDECL operator new[](RT_EF_SIZE_T cb) RT_EF_THROWS_BAD_ALLOC
[1]122{
[31157]123 void *pv = rtR3MemAlloc("new[]", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
[1]124 if (!pv)
125 throw std::bad_alloc();
126 return pv;
127}
128
129
[57434]130void * RT_EF_CDECL operator new[](RT_EF_SIZE_T cb, const std::nothrow_t &) RT_EF_NOTHROW
[1]131{
[31157]132 void *pv = rtR3MemAlloc("new[] nothrow", RTMEMTYPE_NEW_ARRAY, cb, cb, NULL, ASMReturnAddress(), NULL, 0, NULL);
[1]133 return pv;
134}
135
136
[57434]137void RT_EF_CDECL operator delete[](void * pv) RT_EF_NOTHROW
[1]138{
[28298]139 rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
[1]140}
141
142
[59273]143#ifdef __cpp_sized_deallocation
144void RT_EF_CDECL operator delete[](void * pv, RT_EF_SIZE_T cb) RT_EF_NOTHROW
145{
146 NOREF(cb);
147 AssertMsgFailed(("cb ignored!\n"));
148 rtR3MemFree("delete[]", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
149}
150#endif
151
152
[57434]153void RT_EF_CDECL operator delete[](void *pv, const std::nothrow_t &) RT_EF_NOTHROW
[1]154{
[28298]155 rtR3MemFree("delete[] nothrow", RTMEMTYPE_DELETE_ARRAY, pv, ASMReturnAddress(), NULL, 0, NULL);
[1]156}
157
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use