]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/TianoTools/Common/MyAlloc.h
Fix capitalization
[mirror_edk2.git] / Tools / Source / TianoTools / Common / MyAlloc.h
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2004, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 MyAlloc.h\r
15\r
16Abstract:\r
17\r
18 Header file for memory allocation tracking functions.\r
19\r
20--*/\r
21\r
22#ifndef _MYALLOC_H_\r
23#define _MYALLOC_H_\r
24\r
25#include <stdio.h>\r
26#include <stdlib.h>\r
27#include <string.h>\r
28#include <Base.h>\r
29\r
30/*\r
31#include "Tiano.h"\r
32*/\r
33\r
34//\r
35// Default operation is to use the memory allocation tracking functions.\r
36// To over-ride add "#define USE_MYALLOC 0" to your program header and/or\r
37// source files as needed. Or, just do not include this header file in\r
38// your project.\r
39//\r
40#ifndef USE_MYALLOC\r
41#define USE_MYALLOC 1\r
42#endif\r
43\r
44#if USE_MYALLOC\r
45//\r
46// Replace C library allocation routines with MyAlloc routines.\r
47//\r
48#define malloc(size) MyAlloc ((size), __FILE__, __LINE__)\r
49#define calloc(count, size) MyAlloc ((count) * (size), __FILE__, __LINE__)\r
50#define realloc(ptr, size) MyRealloc ((ptr), (size), __FILE__, __LINE__)\r
51#define free(ptr) MyFree ((ptr), __FILE__, __LINE__)\r
52#define alloc_check(final) MyCheck ((final), __FILE__, __LINE__)\r
53\r
54//\r
55// Structure for checking/tracking memory allocations.\r
56//\r
57typedef struct MyAllocStruct {\r
58 UINTN Cksum;\r
59 struct MyAllocStruct *Next;\r
60 UINTN Line;\r
61 UINTN Size;\r
62 UINT8 *File;\r
63 UINT8 *Buffer;\r
64} MY_ALLOC_STRUCT;\r
65//\r
66// Cksum := (UINTN)This + (UINTN)Next + Line + Size + (UINTN)File +\r
67// (UINTN)Buffer;\r
68//\r
69// Next := Pointer to next allocation structure in the list.\r
70//\r
71// Line := __LINE__\r
72//\r
73// Size := Size of allocation request.\r
74//\r
75// File := Pointer to __FILE__ string stored immediately following\r
76// MY_ALLOC_STRUCT in memory.\r
77//\r
78// Buffer := Pointer to UINT32 aligned storage immediately following\r
79// the NULL terminated __FILE__ string. This is UINT32\r
80// aligned because the underflow signature is 32-bits and\r
81// this will place the first caller address on a 64-bit\r
82// boundary.\r
83//\r
84//\r
85// Signatures used to check for buffer overflow/underflow conditions.\r
86//\r
87#define MYALLOC_HEAD_MAGIK 0xBADFACED\r
88#define MYALLOC_TAIL_MAGIK 0xDEADBEEF\r
89\r
90VOID\r
91MyCheck (\r
92 BOOLEAN Final,\r
93 UINT8 File[],\r
94 UINTN Line\r
95 )\r
96;\r
97//\r
98// *++\r
99// Description:\r
100//\r
101// Check for corruptions in the allocated memory chain. If a corruption\r
102// is detection program operation stops w/ an exit(1) call.\r
103//\r
104// Parameters:\r
105//\r
106// Final := When FALSE, MyCheck() returns if the allocated memory chain\r
107// has not been corrupted. When TRUE, MyCheck() returns if there\r
108// are no un-freed allocations. If there are un-freed allocations,\r
109// they are displayed and exit(1) is called.\r
110//\r
111//\r
112// File := Set to __FILE__ by macro expansion.\r
113//\r
114// Line := Set to __LINE__ by macro expansion.\r
115//\r
116// Returns:\r
117//\r
118// n/a\r
119//\r
120// --*/\r
121//\r
122VOID *\r
123MyAlloc (\r
124 UINTN Size,\r
125 UINT8 File[],\r
126 UINTN Line\r
127 )\r
128;\r
129//\r
130// *++\r
131// Description:\r
132//\r
133// Allocate a new link in the allocation chain along with enough storage\r
134// for the File[] string, requested Size and alignment overhead. If\r
135// memory cannot be allocated or the allocation chain has been corrupted,\r
136// exit(1) will be called.\r
137//\r
138// Parameters:\r
139//\r
140// Size := Number of bytes (UINT8) requested by the called.\r
141// Size cannot be zero.\r
142//\r
143// File := Set to __FILE__ by macro expansion.\r
144//\r
145// Line := Set to __LINE__ by macro expansion.\r
146//\r
147// Returns:\r
148//\r
149// Pointer to the caller's buffer.\r
150//\r
151// --*/\r
152//\r
153VOID *\r
154MyRealloc (\r
155 VOID *Ptr,\r
156 UINTN Size,\r
157 UINT8 File[],\r
158 UINTN Line\r
159 )\r
160;\r
161//\r
162// *++\r
163// Description:\r
164//\r
165// This does a MyAlloc(), memcpy() and MyFree(). There is no optimization\r
166// for shrinking or expanding buffers. An invalid parameter will cause\r
167// MyRealloc() to fail with a call to exit(1).\r
168//\r
169// Parameters:\r
170//\r
171// Ptr := Pointer to the caller's buffer to be re-allocated.\r
172// Ptr cannot be NULL.\r
173//\r
174// Size := Size of new buffer. Size cannot be zero.\r
175//\r
176// File := Set to __FILE__ by macro expansion.\r
177//\r
178// Line := Set to __LINE__ by macro expansion.\r
179//\r
180// Returns:\r
181//\r
182// Pointer to new caller's buffer.\r
183//\r
184// --*/\r
185//\r
186VOID\r
187MyFree (\r
188 VOID *Ptr,\r
189 UINT8 File[],\r
190 UINTN Line\r
191 )\r
192;\r
193//\r
194// *++\r
195// Description:\r
196//\r
197// Release a previously allocated buffer. Invalid parameters will cause\r
198// MyFree() to fail with an exit(1) call.\r
199//\r
200// Parameters:\r
201//\r
202// Ptr := Pointer to the caller's buffer to be freed.\r
203// A NULL pointer will be ignored.\r
204//\r
205// File := Set to __FILE__ by macro expansion.\r
206//\r
207// Line := Set to __LINE__ by macro expansion.\r
208//\r
209// Returns:\r
210//\r
211// n/a\r
212//\r
213// --*/\r
214//\r
215#else /* USE_MYALLOC */\r
216\r
217//\r
218// Nothing to do when USE_MYALLOC is zero.\r
219//\r
220#define alloc_check(final)\r
221\r
222#endif /* USE_MYALLOC */\r
223#endif /* _MYALLOC_H_ */\r
224\r
225/* eof - MyAlloc.h */\r