ReactOS  0.4.14-dev-604-gcfdd483
utalloc.c File Reference
#include "acpi.h"
#include "accommon.h"
#include "acdebug.h"
Include dependency graph for utalloc.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_UTILITIES
 

Functions

voidAcpiOsAllocateZeroed (ACPI_SIZE Size)
 
ACPI_STATUS AcpiUtCreateCaches (void)
 
ACPI_STATUS AcpiUtDeleteCaches (void)
 
ACPI_STATUS AcpiUtValidateBuffer (ACPI_BUFFER *Buffer)
 
ACPI_STATUS AcpiUtInitializeBuffer (ACPI_BUFFER *Buffer, ACPI_SIZE RequiredLength)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_UTILITIES

Definition at line 48 of file utalloc.c.

Function Documentation

◆ AcpiOsAllocateZeroed()

void* AcpiOsAllocateZeroed ( ACPI_SIZE  Size)

Definition at line 68 of file utalloc.c.

70 {
71  void *Allocation;
72 
73 
75 
76 
77  Allocation = AcpiOsAllocate (Size);
78  if (Allocation)
79  {
80  /* Clear the memory block */
81 
82  memset (Allocation, 0, Size);
83  }
84 
85  return (Allocation);
86 }
void * AcpiOsAllocate(ACPI_SIZE Size)
Definition: osl.c:160
#define ACPI_FUNCTION_ENTRY()
Definition: acoutput.h:484
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define memset(x, y, z)
Definition: compat.h:39

◆ AcpiUtCreateCaches()

ACPI_STATUS AcpiUtCreateCaches ( void  )

Definition at line 104 of file utalloc.c.

106 {
108 
109 
110  /* Object Caches, for frequently used objects */
111 
112  Status = AcpiOsCreateCache ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
113  ACPI_MAX_NAMESPACE_CACHE_DEPTH, &AcpiGbl_NamespaceCache);
114  if (ACPI_FAILURE (Status))
115  {
116  return (Status);
117  }
118 
119  Status = AcpiOsCreateCache ("Acpi-State", sizeof (ACPI_GENERIC_STATE),
120  ACPI_MAX_STATE_CACHE_DEPTH, &AcpiGbl_StateCache);
121  if (ACPI_FAILURE (Status))
122  {
123  return (Status);
124  }
125 
126  Status = AcpiOsCreateCache ("Acpi-Parse", sizeof (ACPI_PARSE_OBJ_COMMON),
127  ACPI_MAX_PARSE_CACHE_DEPTH, &AcpiGbl_PsNodeCache);
128  if (ACPI_FAILURE (Status))
129  {
130  return (Status);
131  }
132 
133  Status = AcpiOsCreateCache ("Acpi-ParseExt", sizeof (ACPI_PARSE_OBJ_NAMED),
134  ACPI_MAX_EXTPARSE_CACHE_DEPTH, &AcpiGbl_PsNodeExtCache);
135  if (ACPI_FAILURE (Status))
136  {
137  return (Status);
138  }
139 
140  Status = AcpiOsCreateCache ("Acpi-Operand", sizeof (ACPI_OPERAND_OBJECT),
141  ACPI_MAX_OBJECT_CACHE_DEPTH, &AcpiGbl_OperandCache);
142  if (ACPI_FAILURE (Status))
143  {
144  return (Status);
145  }
146 
147 #ifdef ACPI_ASL_COMPILER
148  /*
149  * For use with the ASL-/ASL+ option. This cache keeps track of regular
150  * 0xA9 0x01 comments.
151  */
152  Status = AcpiOsCreateCache ("Acpi-Comment", sizeof (ACPI_COMMENT_NODE),
153  ACPI_MAX_COMMENT_CACHE_DEPTH, &AcpiGbl_RegCommentCache);
154  if (ACPI_FAILURE (Status))
155  {
156  return (Status);
157  }
158 
159  /*
160  * This cache keeps track of the starting addresses of where the comments
161  * lie. This helps prevent duplication of comments.
162  */
163  Status = AcpiOsCreateCache ("Acpi-Comment-Addr", sizeof (ACPI_COMMENT_ADDR_NODE),
164  ACPI_MAX_COMMENT_CACHE_DEPTH, &AcpiGbl_CommentAddrCache);
165  if (ACPI_FAILURE (Status))
166  {
167  return (Status);
168  }
169 
170  /*
171  * This cache will be used for nodes that represent files.
172  */
173  Status = AcpiOsCreateCache ("Acpi-File", sizeof (ACPI_FILE_NODE),
174  ACPI_MAX_COMMENT_CACHE_DEPTH, &AcpiGbl_FileCache);
175  if (ACPI_FAILURE (Status))
176  {
177  return (Status);
178  }
179 #endif
180 
181 
182 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
183 
184  /* Memory allocation lists */
185 
186  Status = AcpiUtCreateList ("Acpi-Global", 0,
187  &AcpiGbl_GlobalList);
188  if (ACPI_FAILURE (Status))
189  {
190  return (Status);
191  }
192 
193  Status = AcpiUtCreateList ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
194  &AcpiGbl_NsNodeList);
195  if (ACPI_FAILURE (Status))
196  {
197  return (Status);
198  }
199 #endif
200 
201  return (AE_OK);
202 }
#define ACPI_MAX_COMMENT_CACHE_DEPTH
Definition: acconfig.h:82
#define ACPI_MAX_NAMESPACE_CACHE_DEPTH
Definition: acconfig.h:81
ACPI_STATUS AcpiOsCreateCache(char *CacheName, UINT16 ObjectSize, UINT16 MaxDepth, ACPI_CACHE_T **ReturnCache)
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_MAX_OBJECT_CACHE_DEPTH
Definition: acconfig.h:80
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define ACPI_MAX_PARSE_CACHE_DEPTH
Definition: acconfig.h:78
#define ACPI_MAX_EXTPARSE_CACHE_DEPTH
Definition: acconfig.h:79
Status
Definition: gdiplustypes.h:24
#define ACPI_MAX_STATE_CACHE_DEPTH
Definition: acconfig.h:77
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiUtInitGlobals().

◆ AcpiUtDeleteCaches()

ACPI_STATUS AcpiUtDeleteCaches ( void  )

Definition at line 218 of file utalloc.c.

220 {
221 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
222  char Buffer[7];
223 
224 
225  if (AcpiGbl_DisplayFinalMemStats)
226  {
227  strcpy (Buffer, "MEMORY");
229  }
230 #endif
231 
232  (void) AcpiOsDeleteCache (AcpiGbl_NamespaceCache);
233  AcpiGbl_NamespaceCache = NULL;
234 
235  (void) AcpiOsDeleteCache (AcpiGbl_StateCache);
236  AcpiGbl_StateCache = NULL;
237 
238  (void) AcpiOsDeleteCache (AcpiGbl_OperandCache);
239  AcpiGbl_OperandCache = NULL;
240 
241  (void) AcpiOsDeleteCache (AcpiGbl_PsNodeCache);
242  AcpiGbl_PsNodeCache = NULL;
243 
244  (void) AcpiOsDeleteCache (AcpiGbl_PsNodeExtCache);
245  AcpiGbl_PsNodeExtCache = NULL;
246 
247 #ifdef ACPI_ASL_COMPILER
248  (void) AcpiOsDeleteCache (AcpiGbl_RegCommentCache);
249  AcpiGbl_RegCommentCache = NULL;
250 
251  (void) AcpiOsDeleteCache (AcpiGbl_CommentAddrCache);
252  AcpiGbl_CommentAddrCache = NULL;
253 
254  (void) AcpiOsDeleteCache (AcpiGbl_FileCache);
255  AcpiGbl_FileCache = NULL;
256 #endif
257 
258 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
259 
260  /* Debug only - display leftover memory allocation, if any */
261 
262  AcpiUtDumpAllocations (ACPI_UINT32_MAX, NULL);
263 
264  /* Free memory lists */
265 
266  AcpiOsFree (AcpiGbl_GlobalList);
267  AcpiGbl_GlobalList = NULL;
268 
269  AcpiOsFree (AcpiGbl_NsNodeList);
270  AcpiGbl_NsNodeList = NULL;
271 #endif
272 
273  return (AE_OK);
274 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
ACPI_STATUS AcpiOsDeleteCache(ACPI_CACHE_T *Cache)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define ACPI_UINT32_MAX
Definition: actypes.h:66
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
void AcpiOsFree(void *Memory)
Definition: osl.c:167
#define AE_OK
Definition: acexcep.h:97
ACPI_STATUS AcpiDbDisplayStatistics(char *TypeArg)

Referenced by AcpiUtSubsystemShutdown().

◆ AcpiUtInitializeBuffer()

ACPI_STATUS AcpiUtInitializeBuffer ( ACPI_BUFFER Buffer,
ACPI_SIZE  RequiredLength 
)

Definition at line 336 of file utalloc.c.

339 {
340  ACPI_SIZE InputBufferLength;
341 
342 
343  /* Parameter validation */
344 
345  if (!Buffer || !RequiredLength)
346  {
347  return (AE_BAD_PARAMETER);
348  }
349 
350  /*
351  * Buffer->Length is used as both an input and output parameter. Get the
352  * input actual length and set the output required buffer length.
353  */
354  InputBufferLength = Buffer->Length;
355  Buffer->Length = RequiredLength;
356 
357  /*
358  * The input buffer length contains the actual buffer length, or the type
359  * of buffer to be allocated by this routine.
360  */
361  switch (InputBufferLength)
362  {
363  case ACPI_NO_BUFFER:
364 
365  /* Return the exception (and the required buffer length) */
366 
367  return (AE_BUFFER_OVERFLOW);
368 
370  /*
371  * Allocate a new buffer. We directectly call AcpiOsAllocate here to
372  * purposefully bypass the (optionally enabled) internal allocation
373  * tracking mechanism since we only want to track internal
374  * allocations. Note: The caller should use AcpiOsFree to free this
375  * buffer created via ACPI_ALLOCATE_BUFFER.
376  */
377  Buffer->Pointer = AcpiOsAllocate (RequiredLength);
378  break;
379 
381 
382  /* Allocate a new buffer with local interface to allow tracking */
383 
384  Buffer->Pointer = ACPI_ALLOCATE (RequiredLength);
385  break;
386 
387  default:
388 
389  /* Existing buffer: Validate the size of the buffer */
390 
392  {
393  return (AE_BUFFER_OVERFLOW);
394  }
395  break;
396  }
397 
398  /* Validate allocation from above or input buffer pointer */
399 
400  if (!Buffer->Pointer)
401  {
402  return (AE_NO_MEMORY);
403  }
404 
405  /* Have a valid buffer, clear it */
406 
407  memset (Buffer->Pointer, 0, RequiredLength);
408  return (AE_OK);
409 }
void * AcpiOsAllocate(ACPI_SIZE Size)
Definition: osl.c:160
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
#define ACPI_ALLOCATE(a)
Definition: actypes.h:384
#define AE_BUFFER_OVERFLOW
Definition: acexcep.h:119
#define ACPI_ALLOCATE_LOCAL_BUFFER
Definition: actypes.h:1036
Definition: bufpool.h:45
#define ACPI_ALLOCATE_BUFFER
Definition: actypes.h:1035
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:29
#define ACPI_NO_BUFFER
Definition: actypes.h:1026
#define memset(x, y, z)
Definition: compat.h:39
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiEvaluateObject(), AcpiGetSystemInfo(), AcpiNsHandleToName(), AcpiNsHandleToPathname(), AcpiRsCreateAmlResources(), AcpiRsCreatePciRoutingTable(), AcpiRsCreateResourceList(), and AcpiRsMatchVendorResource().

◆ AcpiUtValidateBuffer()

ACPI_STATUS AcpiUtValidateBuffer ( ACPI_BUFFER Buffer)

Definition at line 290 of file utalloc.c.

292 {
293 
294  /* Obviously, the structure pointer must be valid */
295 
296  if (!Buffer)
297  {
298  return (AE_BAD_PARAMETER);
299  }
300 
301  /* Special semantics for the length */
302 
303  if ((Buffer->Length == ACPI_NO_BUFFER) ||
304  (Buffer->Length == ACPI_ALLOCATE_BUFFER) ||
305  (Buffer->Length == ACPI_ALLOCATE_LOCAL_BUFFER))
306  {
307  return (AE_OK);
308  }
309 
310  /* Length is valid, the buffer pointer must be also */
311 
312  if (!Buffer->Pointer)
313  {
314  return (AE_BAD_PARAMETER);
315  }
316 
317  return (AE_OK);
318 }
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
#define ACPI_ALLOCATE_LOCAL_BUFFER
Definition: actypes.h:1036
Definition: bufpool.h:45
#define ACPI_ALLOCATE_BUFFER
Definition: actypes.h:1035
#define ACPI_NO_BUFFER
Definition: actypes.h:1026
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiGetName(), AcpiGetSystemInfo(), and AcpiRsValidateParameters().