]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Sample/Tools/Source/Common/MyAlloc.h
clean up the un-suitable ';' location when declaring the functions. The regular is...
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / Common / MyAlloc.h
CommitLineData
3eb9473e 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\r
29#include "Tiano.h"\r
30\r
31//\r
32// Default operation is to use the memory allocation tracking functions.\r
33// To over-ride add "#define USE_MYALLOC 0" to your program header and/or\r
34// source files as needed. Or, just do not include this header file in\r
35// your project.\r
36//\r
37#ifndef USE_MYALLOC\r
38#define USE_MYALLOC 1\r
39#endif\r
40\r
41#if USE_MYALLOC\r
42//\r
43// Replace C library allocation routines with MyAlloc routines.\r
44//\r
45#define malloc(size) MyAlloc ((size), __FILE__, __LINE__)\r
46#define calloc(count, size) MyAlloc ((count) * (size), __FILE__, __LINE__)\r
47#define realloc(ptr, size) MyRealloc ((ptr), (size), __FILE__, __LINE__)\r
48#define free(ptr) MyFree ((ptr), __FILE__, __LINE__)\r
49#define alloc_check(final) MyCheck ((final), __FILE__, __LINE__)\r
50\r
51//\r
52// Structure for checking/tracking memory allocations.\r
53//\r
54typedef struct MyAllocStruct {\r
55 UINTN Cksum;\r
56 struct MyAllocStruct *Next;\r
57 UINTN Line;\r
58 UINTN Size;\r
59 UINT8 *File;\r
60 UINT8 *Buffer;\r
61} MY_ALLOC_STRUCT;\r
62//\r
63// Cksum := (UINTN)This + (UINTN)Next + Line + Size + (UINTN)File +\r
64// (UINTN)Buffer;\r
65//\r
66// Next := Pointer to next allocation structure in the list.\r
67//\r
68// Line := __LINE__\r
69//\r
70// Size := Size of allocation request.\r
71//\r
72// File := Pointer to __FILE__ string stored immediately following\r
73// MY_ALLOC_STRUCT in memory.\r
74//\r
75// Buffer := Pointer to UINT32 aligned storage immediately following\r
76// the NULL terminated __FILE__ string. This is UINT32\r
77// aligned because the underflow signature is 32-bits and\r
78// this will place the first caller address on a 64-bit\r
79// boundary.\r
80//\r
81//\r
82// Signatures used to check for buffer overflow/underflow conditions.\r
83//\r
84#define MYALLOC_HEAD_MAGIK 0xBADFACED\r
85#define MYALLOC_TAIL_MAGIK 0xDEADBEEF\r
86\r
87VOID\r
88MyCheck (\r
89 BOOLEAN Final,\r
90 UINT8 File[],\r
91 UINTN Line\r
e00e1d46 92 );\r
3eb9473e 93//\r
94// *++\r
95// Description:\r
96//\r
97// Check for corruptions in the allocated memory chain. If a corruption\r
98// is detection program operation stops w/ an exit(1) call.\r
99//\r
100// Parameters:\r
101//\r
102// Final := When FALSE, MyCheck() returns if the allocated memory chain\r
103// has not been corrupted. When TRUE, MyCheck() returns if there\r
104// are no un-freed allocations. If there are un-freed allocations,\r
105// they are displayed and exit(1) is called.\r
106//\r
107//\r
108// File := Set to __FILE__ by macro expansion.\r
109//\r
110// Line := Set to __LINE__ by macro expansion.\r
111//\r
112// Returns:\r
113//\r
114// n/a\r
115//\r
116// --*/\r
117//\r
118VOID *\r
119MyAlloc (\r
120 UINTN Size,\r
121 UINT8 File[],\r
122 UINTN Line\r
e00e1d46 123 );\r
3eb9473e 124//\r
125// *++\r
126// Description:\r
127//\r
128// Allocate a new link in the allocation chain along with enough storage\r
129// for the File[] string, requested Size and alignment overhead. If\r
130// memory cannot be allocated or the allocation chain has been corrupted,\r
131// exit(1) will be called.\r
132//\r
133// Parameters:\r
134//\r
135// Size := Number of bytes (UINT8) requested by the called.\r
136// Size cannot be zero.\r
137//\r
138// File := Set to __FILE__ by macro expansion.\r
139//\r
140// Line := Set to __LINE__ by macro expansion.\r
141//\r
142// Returns:\r
143//\r
144// Pointer to the caller's buffer.\r
145//\r
146// --*/\r
147//\r
148VOID *\r
149MyRealloc (\r
150 VOID *Ptr,\r
151 UINTN Size,\r
152 UINT8 File[],\r
153 UINTN Line\r
e00e1d46 154 );\r
3eb9473e 155//\r
156// *++\r
157// Description:\r
158//\r
159// This does a MyAlloc(), memcpy() and MyFree(). There is no optimization\r
160// for shrinking or expanding buffers. An invalid parameter will cause\r
161// MyRealloc() to fail with a call to exit(1).\r
162//\r
163// Parameters:\r
164//\r
165// Ptr := Pointer to the caller's buffer to be re-allocated.\r
166// Ptr cannot be NULL.\r
167//\r
168// Size := Size of new buffer. Size cannot be zero.\r
169//\r
170// File := Set to __FILE__ by macro expansion.\r
171//\r
172// Line := Set to __LINE__ by macro expansion.\r
173//\r
174// Returns:\r
175//\r
176// Pointer to new caller's buffer.\r
177//\r
178// --*/\r
179//\r
180VOID\r
181MyFree (\r
182 VOID *Ptr,\r
183 UINT8 File[],\r
184 UINTN Line\r
e00e1d46 185 );\r
3eb9473e 186//\r
187// *++\r
188// Description:\r
189//\r
190// Release a previously allocated buffer. Invalid parameters will cause\r
191// MyFree() to fail with an exit(1) call.\r
192//\r
193// Parameters:\r
194//\r
195// Ptr := Pointer to the caller's buffer to be freed.\r
196// A NULL pointer will be ignored.\r
197//\r
198// File := Set to __FILE__ by macro expansion.\r
199//\r
200// Line := Set to __LINE__ by macro expansion.\r
201//\r
202// Returns:\r
203//\r
204// n/a\r
205//\r
206// --*/\r
207//\r
208#else /* USE_MYALLOC */\r
209\r
210//\r
211// Nothing to do when USE_MYALLOC is zero.\r
212//\r
213#define alloc_check(final)\r
214\r
215#endif /* USE_MYALLOC */\r
216#endif /* _MYALLOC_H_ */\r
217\r
218/* eof - MyAlloc.h */\r