VirtualBox

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

Last change on this file since 3699 was 3699, checked in by vboxsync, 17 years ago

double underscore cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1/* $Id: alloc-ef.h 3699 2007-07-18 17:37:46Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Memory Allocation, electric fence.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ___alloc_ef_h
23#define ___alloc_ef_h
24
25/*******************************************************************************
26* Defined Constants And Macros *
27*******************************************************************************/
28#if defined(__DOXYGEN__)
29# define RTALLOC_USE_EFENCE
30# define RTALLOC_EFENCE_IN_FRONT
31# define RTALLOC_EFENCE_FREE_FILL 'f'
32#endif
33
34/** @def RTALLOC_USE_EFENCE
35 * If defined the electric fence put up for ALL allocations by RTMemAlloc(),
36 * RTMemAllocZ(), RTMemRealloc(), RTMemTmpAlloc() and RTMemTmpAllocZ().
37 */
38#if 0// defined(DEBUG_bird)
39# define RTALLOC_USE_EFENCE
40#endif
41
42/** @def RTALLOC_EFENCE_SIZE
43 * The size of the fence. This must be page aligned.
44 */
45#define RTALLOC_EFENCE_SIZE PAGE_SIZE
46
47/** @def RTALLOC_EFENCE_IN_FRONT
48 * Define this to put the fence up in front of the block.
49 * The default (when this isn't defined) is to up it up after the block.
50 */
51//# define RTALLOC_EFENCE_IN_FRONT
52
53/** @def RTALLOC_EFENCE_TRACE
54 * Define this to support actual free and reallocation of blocks.
55 */
56#define RTALLOC_EFENCE_TRACE
57
58/** @def RTALLOC_EFENCE_FREE_DELAYED
59 * This define will enable free() delay and protection of the freed data
60 * while it's being delayed. The value of RTALLOC_EFENCE_FREE_DELAYED defines
61 * the threshold of the delayed blocks.
62 * Delayed blocks does not consume any physical memory, only virtual address space.
63 * Requires RTALLOC_EFENCE_TRACE.
64 */
65#define RTALLOC_EFENCE_FREE_DELAYED (20 * _1M)
66
67/** @def RTALLOC_EFENCE_FREE_FILL
68 * This define will enable memset(,RTALLOC_EFENCE_FREE_FILL,)'ing the user memory
69 * in the block before freeing/decommitting it. This is useful in GDB since GDB
70 * appeares to be able to read the content of the page even after it's been
71 * decommitted.
72 * Requires RTALLOC_EFENCE_TRACE.
73 */
74#if defined(RT_OS_LINUX)
75# define RTALLOC_EFENCE_FREE_FILL 'f'
76#endif
77
78/** @def RTALLOC_EFENCE_FILLER
79 * This define will enable memset(,RTALLOC_EFENCE_FILLER,)'ing the allocated
80 * memory when the API doesn't require it to be zero'ed.
81 */
82#define RTALLOC_EFENCE_FILLER 0xef
83
84#if defined(__DOXYGEN__)
85/** @def RTALLOC_EFENCE_CPP
86 * This define will enable the new and delete wrappers.
87 */
88# define RTALLOC_EFENCE_CPP
89#endif
90
91
92
93/*******************************************************************************
94* Header Files *
95*******************************************************************************/
96#ifdef RT_OS_WINDOWS
97# include <Windows.h>
98#else
99# include <sys/mman.h>
100#endif
101#include <iprt/avl.h>
102#include <iprt/thread.h>
103
104
105/*******************************************************************************
106* Structures and Typedefs *
107*******************************************************************************/
108/**
109 * Allocation types.
110 */
111typedef enum RTMEMTYPE
112{
113 RTMEMTYPE_RTMEMALLOC,
114 RTMEMTYPE_RTMEMALLOCZ,
115 RTMEMTYPE_RTMEMREALLOC,
116 RTMEMTYPE_RTMEMFREE,
117
118 RTMEMTYPE_NEW,
119 RTMEMTYPE_NEW_ARRAY,
120 RTMEMTYPE_DELETE,
121 RTMEMTYPE_DELETE_ARRAY
122} RTMEMTYPE;
123
124#ifdef RTALLOC_EFENCE_TRACE
125/**
126 * Node tracking a memory allocation.
127 */
128typedef struct RTMEMBLOCK
129{
130 /** Avl node code, key is the user block pointer. */
131 AVLPVNODECORE Core;
132 /** Allocation type. */
133 RTMEMTYPE enmType;
134 /** The size of the block. */
135 size_t cb;
136 /** The return address of the allocator function. */
137 void *pvCaller;
138 /** Line number of the alloc call. */
139 unsigned iLine;
140 /** File from within the allocation was made. */
141 const char *pszFile;
142 /** Function from within the allocation was made. */
143 const char *pszFunction;
144} RTMEMBLOCK, *PRTMEMBLOCK;
145
146#endif
147
148
149/*******************************************************************************
150* Internal Functions *
151*******************************************************************************/
152__BEGIN_DECLS
153RTDECL(void *) rtMemAlloc(const char *pszOp, RTMEMTYPE enmType, size_t cb, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);
154RTDECL(void *) rtMemRealloc(const char *pszOp, RTMEMTYPE enmType, void *pvOld, size_t cbNew, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);
155RTDECL(void) rtMemFree(const char *pszOp, RTMEMTYPE enmType, void *pv, void *pvCaller, unsigned iLine, const char *pszFile, const char *pszFunction);
156__END_DECLS
157
158#endif
159
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