VirtualBox

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

Last change on this file since 8170 was 8170, checked in by vboxsync, 16 years ago

Rebranding: replacing more innotek strings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.8 KB
Line 
1/* $Id: alloc-ef.h 8170 2008-04-18 17:52:25Z vboxsync $ */
2/** @file
3 * Incredibly Portable Runtime - Memory Allocation, electric fence.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * 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__)
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)
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#if defined(__DOXYGEN__)
94/** @def RTALLOC_EFENCE_CPP
95 * This define will enable the new and delete wrappers.
96 */
97# define RTALLOC_EFENCE_CPP
98#endif
99
100
101
102/*******************************************************************************
103* Header Files *
104*******************************************************************************/
105#ifdef RT_OS_WINDOWS
106# include <Windows.h>
107#else
108# include <sys/mman.h>
109#endif
110#include <iprt/avl.h>
111#include <iprt/thread.h>
112
113
114/*******************************************************************************
115* Structures and Typedefs *
116*******************************************************************************/
117/**
118 * Allocation types.
119 */
120typedef enum RTMEMTYPE
121{
122 RTMEMTYPE_RTMEMALLOC,
123 RTMEMTYPE_RTMEMALLOCZ,
124 RTMEMTYPE_RTMEMREALLOC,
125 RTMEMTYPE_RTMEMFREE,
126
127 RTMEMTYPE_NEW,
128 RTMEMTYPE_NEW_ARRAY,
129 RTMEMTYPE_DELETE,
130 RTMEMTYPE_DELETE_ARRAY
131} RTMEMTYPE;
132
133#ifdef RTALLOC_EFENCE_TRACE
134/**
135 * Node tracking a memory allocation.
136 */
137typedef struct RTMEMBLOCK
138{
139 /** Avl node code, key is the user block pointer. */
140 AVLPVNODECORE Core;
141 /** Allocation type. */
142 RTMEMTYPE enmType;
143 /** The size of the block. */
144 size_t cb;
145 /** The return address of the allocator function. */
146 void *pvCaller;
147 /** Line number of the alloc call. */
148 unsigned iLine;
149 /** File from within the allocation was made. */
150 const char *pszFile;
151 /** Function from within the allocation was made. */
152 const char *pszFunction;
153} RTMEMBLOCK, *PRTMEMBLOCK;
154
155#endif
156
157
158/*******************************************************************************
159* Internal Functions *
160*******************************************************************************/
161__BEGIN_DECLS
162RTDECL(void *) rtMemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cb, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);
163RTDECL(void *) rtMemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);
164RTDECL(void) rtMemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);
165__END_DECLS
166
167#endif
168
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