VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/alloc-ef.h@ 27295

Last change on this file since 27295 was 27295, checked in by vboxsync, 15 years ago

Runtime/alloc-ef: back out accidental commit

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1/* $Id: alloc-ef.h 27295 2010-03-11 16:58:54Z vboxsync $ */
2/** @file
3 * IPRT - Memory Allocation, electric fence.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___alloc_ef_h
32#define ___alloc_ef_h
33
34/*******************************************************************************
35* Defined Constants And Macros *
36*******************************************************************************/
37#if defined(DOXYGEN_RUNNING)
38# define RTALLOC_USE_EFENCE
39# define RTALLOC_EFENCE_IN_FRONT
40# define RTALLOC_EFENCE_FREE_FILL 'f'
41#endif
42
43/** @def RTALLOC_USE_EFENCE
44 * If defined the electric fence put up for ALL allocations by RTMemAlloc(),
45 * RTMemAllocZ(), RTMemRealloc(), RTMemTmpAlloc() and RTMemTmpAllocZ().
46 */
47#if 0// defined(DEBUG_bird)
48# define RTALLOC_USE_EFENCE
49#endif
50
51/** @def RTALLOC_EFENCE_SIZE
52 * The size of the fence. This must be page aligned.
53 */
54#define RTALLOC_EFENCE_SIZE PAGE_SIZE
55
56/** @def RTALLOC_EFENCE_IN_FRONT
57 * Define this to put the fence up in front of the block.
58 * The default (when this isn't defined) is to up it up after the block.
59 */
60//# define RTALLOC_EFENCE_IN_FRONT
61
62/** @def RTALLOC_EFENCE_TRACE
63 * Define this to support actual free and reallocation of blocks.
64 */
65#define RTALLOC_EFENCE_TRACE
66
67/** @def RTALLOC_EFENCE_FREE_DELAYED
68 * This define will enable free() delay and protection of the freed data
69 * while it's being delayed. The value of RTALLOC_EFENCE_FREE_DELAYED defines
70 * the threshold of the delayed blocks.
71 * Delayed blocks does not consume any physical memory, only virtual address space.
72 * Requires RTALLOC_EFENCE_TRACE.
73 */
74#define RTALLOC_EFENCE_FREE_DELAYED (20 * _1M)
75
76/** @def RTALLOC_EFENCE_FREE_FILL
77 * This define will enable memset(,RTALLOC_EFENCE_FREE_FILL,)'ing the user memory
78 * in the block before freeing/decommitting it. This is useful in GDB since GDB
79 * appeares to be able to read the content of the page even after it's been
80 * decommitted.
81 * Requires RTALLOC_EFENCE_TRACE.
82 */
83#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
84# define RTALLOC_EFENCE_FREE_FILL 'f'
85#endif
86
87/** @def RTALLOC_EFENCE_FILLER
88 * This define will enable memset(,RTALLOC_EFENCE_FILLER,)'ing the allocated
89 * memory when the API doesn't require it to be zero'ed.
90 */
91#define RTALLOC_EFENCE_FILLER 0xef
92
93/** @def RTALLOC_EFENCE_NOMAN_FILLER
94 * This define will enable memset(,RTALLOC_EFENCE_NOMAN_FILLER,)'ing the
95 * unprotected but not allocated area of memory, the so called no man's land.
96 */
97#define RTALLOC_EFENCE_NOMAN_FILLER 0xaa
98
99/** @def RTALLOC_EFENCE_FENCE_FILLER
100 * This define will enable memset(,RTALLOC_EFENCE_FENCE_FILLER,)'ing the
101 * fence itself, as debuggers can usually read them.
102 */
103#define RTALLOC_EFENCE_FENCE_FILLER 0xcc
104
105#if defined(DOXYGEN_RUNNING)
106/** @def RTALLOC_EFENCE_CPP
107 * This define will enable the new and delete wrappers.
108 */
109# define RTALLOC_EFENCE_CPP
110#endif
111
112
113
114/*******************************************************************************
115* Header Files *
116*******************************************************************************/
117#ifdef RT_OS_WINDOWS
118# include <Windows.h>
119#else
120# include <sys/mman.h>
121#endif
122#include <iprt/avl.h>
123#include <iprt/thread.h>
124
125
126/*******************************************************************************
127* Structures and Typedefs *
128*******************************************************************************/
129/**
130 * Allocation types.
131 */
132typedef enum RTMEMTYPE
133{
134 RTMEMTYPE_RTMEMALLOC,
135 RTMEMTYPE_RTMEMALLOCZ,
136 RTMEMTYPE_RTMEMREALLOC,
137 RTMEMTYPE_RTMEMFREE,
138
139 RTMEMTYPE_NEW,
140 RTMEMTYPE_NEW_ARRAY,
141 RTMEMTYPE_DELETE,
142 RTMEMTYPE_DELETE_ARRAY
143} RTMEMTYPE;
144
145#ifdef RTALLOC_EFENCE_TRACE
146/**
147 * Node tracking a memory allocation.
148 */
149typedef struct RTMEMBLOCK
150{
151 /** Avl node code, key is the user block pointer. */
152 AVLPVNODECORE Core;
153 /** Allocation type. */
154 RTMEMTYPE enmType;
155 /** The size of the block. */
156 size_t cb;
157 /** The return address of the allocator function. */
158 void *pvCaller;
159 /** Line number of the alloc call. */
160 unsigned iLine;
161 /** File from within the allocation was made. */
162 const char *pszFile;
163 /** Function from within the allocation was made. */
164 const char *pszFunction;
165} RTMEMBLOCK, *PRTMEMBLOCK;
166
167#endif
168
169
170/*******************************************************************************
171* Internal Functions *
172******************************************************************************/
173RT_C_DECLS_BEGIN
174void * rtMemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cb, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);
175void * rtMemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);
176void rtMemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);
177RT_C_DECLS_END
178
179#endif
180
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