ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

utalloc.c
Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * Module Name: utalloc - local memory allocation routines
00004  *
00005  *****************************************************************************/
00006 
00007 /******************************************************************************
00008  *
00009  * 1. Copyright Notice
00010  *
00011  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00012  * All rights reserved.
00013  *
00014  * 2. License
00015  *
00016  * 2.1. This is your license from Intel Corp. under its intellectual property
00017  * rights.  You may have additional license terms from the party that provided
00018  * you this software, covering your right to use that party's intellectual
00019  * property rights.
00020  *
00021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00022  * copy of the source code appearing in this file ("Covered Code") an
00023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00024  * base code distributed originally by Intel ("Original Intel Code") to copy,
00025  * make derivatives, distribute, use and display any portion of the Covered
00026  * Code in any form, with the right to sublicense such rights; and
00027  *
00028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00029  * license (with the right to sublicense), under only those claims of Intel
00030  * patents that are infringed by the Original Intel Code, to make, use, sell,
00031  * offer to sell, and import the Covered Code and derivative works thereof
00032  * solely to the minimum extent necessary to exercise the above copyright
00033  * license, and in no event shall the patent license extend to any additions
00034  * to or modifications of the Original Intel Code.  No other license or right
00035  * is granted directly or by implication, estoppel or otherwise;
00036  *
00037  * The above copyright and patent license is granted only if the following
00038  * conditions are met:
00039  *
00040  * 3. Conditions
00041  *
00042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00043  * Redistribution of source code of any substantial portion of the Covered
00044  * Code or modification with rights to further distribute source must include
00045  * the above Copyright Notice, the above License, this list of Conditions,
00046  * and the following Disclaimer and Export Compliance provision.  In addition,
00047  * Licensee must cause all Covered Code to which Licensee contributes to
00048  * contain a file documenting the changes Licensee made to create that Covered
00049  * Code and the date of any change.  Licensee must include in that file the
00050  * documentation of any changes made by any predecessor Licensee.  Licensee
00051  * must include a prominent statement that the modification is derived,
00052  * directly or indirectly, from Original Intel Code.
00053  *
00054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00055  * Redistribution of source code of any substantial portion of the Covered
00056  * Code or modification without rights to further distribute source must
00057  * include the following Disclaimer and Export Compliance provision in the
00058  * documentation and/or other materials provided with distribution.  In
00059  * addition, Licensee may not authorize further sublicense of source of any
00060  * portion of the Covered Code, and must include terms to the effect that the
00061  * license from Licensee to its licensee is limited to the intellectual
00062  * property embodied in the software Licensee provides to its licensee, and
00063  * not to intellectual property embodied in modifications its licensee may
00064  * make.
00065  *
00066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00067  * substantial portion of the Covered Code or modification must reproduce the
00068  * above Copyright Notice, and the following Disclaimer and Export Compliance
00069  * provision in the documentation and/or other materials provided with the
00070  * distribution.
00071  *
00072  * 3.4. Intel retains all right, title, and interest in and to the Original
00073  * Intel Code.
00074  *
00075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00076  * Intel shall be used in advertising or otherwise to promote the sale, use or
00077  * other dealings in products derived from or relating to the Covered Code
00078  * without prior written authorization from Intel.
00079  *
00080  * 4. Disclaimer and Export Compliance
00081  *
00082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00088  * PARTICULAR PURPOSE.
00089  *
00090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00097  * LIMITED REMEDY.
00098  *
00099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00100  * software or system incorporating such software without first obtaining any
00101  * required license or other approval from the U. S. Department of Commerce or
00102  * any other agency or department of the United States Government.  In the
00103  * event Licensee exports any such software from the United States or
00104  * re-exports any such software from a foreign destination, Licensee shall
00105  * ensure that the distribution and export/re-export of the software is in
00106  * compliance with all laws, regulations, orders, or other restrictions of the
00107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00108  * any of its subsidiaries will export/re-export any technical data, process,
00109  * software, or service, directly or indirectly, to any country for which the
00110  * United States government or any agency thereof requires an export license,
00111  * other governmental approval, or letter of assurance, without first obtaining
00112  * such license, approval or letter.
00113  *
00114  *****************************************************************************/
00115 
00116 #define __UTALLOC_C__
00117 
00118 #include "acpi.h"
00119 #include "accommon.h"
00120 #include "acdebug.h"
00121 
00122 #define _COMPONENT          ACPI_UTILITIES
00123         ACPI_MODULE_NAME    ("utalloc")
00124 
00125 
00126 /*******************************************************************************
00127  *
00128  * FUNCTION:    AcpiUtCreateCaches
00129  *
00130  * PARAMETERS:  None
00131  *
00132  * RETURN:      Status
00133  *
00134  * DESCRIPTION: Create all local caches
00135  *
00136  ******************************************************************************/
00137 
00138 ACPI_STATUS
00139 AcpiUtCreateCaches (
00140     void)
00141 {
00142     ACPI_STATUS             Status;
00143 
00144 
00145     /* Object Caches, for frequently used objects */
00146 
00147     Status = AcpiOsCreateCache ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
00148                 ACPI_MAX_NAMESPACE_CACHE_DEPTH, &AcpiGbl_NamespaceCache);
00149     if (ACPI_FAILURE (Status))
00150     {
00151         return (Status);
00152     }
00153 
00154     Status = AcpiOsCreateCache ("Acpi-State", sizeof (ACPI_GENERIC_STATE),
00155                 ACPI_MAX_STATE_CACHE_DEPTH, &AcpiGbl_StateCache);
00156     if (ACPI_FAILURE (Status))
00157     {
00158         return (Status);
00159     }
00160 
00161     Status = AcpiOsCreateCache ("Acpi-Parse", sizeof (ACPI_PARSE_OBJ_COMMON),
00162                 ACPI_MAX_PARSE_CACHE_DEPTH, &AcpiGbl_PsNodeCache);
00163     if (ACPI_FAILURE (Status))
00164     {
00165         return (Status);
00166     }
00167 
00168     Status = AcpiOsCreateCache ("Acpi-ParseExt", sizeof (ACPI_PARSE_OBJ_NAMED),
00169                 ACPI_MAX_EXTPARSE_CACHE_DEPTH, &AcpiGbl_PsNodeExtCache);
00170     if (ACPI_FAILURE (Status))
00171     {
00172         return (Status);
00173     }
00174 
00175     Status = AcpiOsCreateCache ("Acpi-Operand", sizeof (ACPI_OPERAND_OBJECT),
00176                 ACPI_MAX_OBJECT_CACHE_DEPTH, &AcpiGbl_OperandCache);
00177     if (ACPI_FAILURE (Status))
00178     {
00179         return (Status);
00180     }
00181 
00182 
00183 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
00184 
00185     /* Memory allocation lists */
00186 
00187     Status = AcpiUtCreateList ("Acpi-Global", 0,
00188                 &AcpiGbl_GlobalList);
00189     if (ACPI_FAILURE (Status))
00190     {
00191         return (Status);
00192     }
00193 
00194     Status = AcpiUtCreateList ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),
00195                 &AcpiGbl_NsNodeList);
00196     if (ACPI_FAILURE (Status))
00197     {
00198         return (Status);
00199     }
00200 #endif
00201 
00202     return (AE_OK);
00203 }
00204 
00205 
00206 /*******************************************************************************
00207  *
00208  * FUNCTION:    AcpiUtDeleteCaches
00209  *
00210  * PARAMETERS:  None
00211  *
00212  * RETURN:      Status
00213  *
00214  * DESCRIPTION: Purge and delete all local caches
00215  *
00216  ******************************************************************************/
00217 
00218 ACPI_STATUS
00219 AcpiUtDeleteCaches (
00220     void)
00221 {
00222 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
00223     char                    Buffer[7];
00224 
00225     if (AcpiGbl_DisplayFinalMemStats)
00226     {
00227         ACPI_STRCPY (Buffer, "MEMORY");
00228         (void) AcpiDbDisplayStatistics (Buffer);
00229     }
00230 #endif
00231 
00232     (void) AcpiOsDeleteCache (AcpiGbl_NamespaceCache);
00233     AcpiGbl_NamespaceCache = NULL;
00234 
00235     (void) AcpiOsDeleteCache (AcpiGbl_StateCache);
00236     AcpiGbl_StateCache = NULL;
00237 
00238     (void) AcpiOsDeleteCache (AcpiGbl_OperandCache);
00239     AcpiGbl_OperandCache = NULL;
00240 
00241     (void) AcpiOsDeleteCache (AcpiGbl_PsNodeCache);
00242     AcpiGbl_PsNodeCache = NULL;
00243 
00244     (void) AcpiOsDeleteCache (AcpiGbl_PsNodeExtCache);
00245     AcpiGbl_PsNodeExtCache = NULL;
00246 
00247 
00248 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
00249 
00250     /* Debug only - display leftover memory allocation, if any */
00251 
00252     AcpiUtDumpAllocations (ACPI_UINT32_MAX, NULL);
00253 
00254     /* Free memory lists */
00255 
00256     AcpiOsFree (AcpiGbl_GlobalList);
00257     AcpiGbl_GlobalList = NULL;
00258 
00259     AcpiOsFree (AcpiGbl_NsNodeList);
00260     AcpiGbl_NsNodeList = NULL;
00261 #endif
00262 
00263     return (AE_OK);
00264 }
00265 
00266 
00267 /*******************************************************************************
00268  *
00269  * FUNCTION:    AcpiUtValidateBuffer
00270  *
00271  * PARAMETERS:  Buffer              - Buffer descriptor to be validated
00272  *
00273  * RETURN:      Status
00274  *
00275  * DESCRIPTION: Perform parameter validation checks on an ACPI_BUFFER
00276  *
00277  ******************************************************************************/
00278 
00279 ACPI_STATUS
00280 AcpiUtValidateBuffer (
00281     ACPI_BUFFER             *Buffer)
00282 {
00283 
00284     /* Obviously, the structure pointer must be valid */
00285 
00286     if (!Buffer)
00287     {
00288         return (AE_BAD_PARAMETER);
00289     }
00290 
00291     /* Special semantics for the length */
00292 
00293     if ((Buffer->Length == ACPI_NO_BUFFER)              ||
00294         (Buffer->Length == ACPI_ALLOCATE_BUFFER)        ||
00295         (Buffer->Length == ACPI_ALLOCATE_LOCAL_BUFFER))
00296     {
00297         return (AE_OK);
00298     }
00299 
00300     /* Length is valid, the buffer pointer must be also */
00301 
00302     if (!Buffer->Pointer)
00303     {
00304         return (AE_BAD_PARAMETER);
00305     }
00306 
00307     return (AE_OK);
00308 }
00309 
00310 
00311 /*******************************************************************************
00312  *
00313  * FUNCTION:    AcpiUtInitializeBuffer
00314  *
00315  * PARAMETERS:  Buffer              - Buffer to be validated
00316  *              RequiredLength      - Length needed
00317  *
00318  * RETURN:      Status
00319  *
00320  * DESCRIPTION: Validate that the buffer is of the required length or
00321  *              allocate a new buffer. Returned buffer is always zeroed.
00322  *
00323  ******************************************************************************/
00324 
00325 ACPI_STATUS
00326 AcpiUtInitializeBuffer (
00327     ACPI_BUFFER             *Buffer,
00328     ACPI_SIZE               RequiredLength)
00329 {
00330     ACPI_SIZE               InputBufferLength;
00331 
00332 
00333     /* Parameter validation */
00334 
00335     if (!Buffer || !RequiredLength)
00336     {
00337         return (AE_BAD_PARAMETER);
00338     }
00339 
00340     /*
00341      * Buffer->Length is used as both an input and output parameter. Get the
00342      * input actual length and set the output required buffer length.
00343      */
00344     InputBufferLength = Buffer->Length;
00345     Buffer->Length = RequiredLength;
00346 
00347     /*
00348      * The input buffer length contains the actual buffer length, or the type
00349      * of buffer to be allocated by this routine.
00350      */
00351     switch (InputBufferLength)
00352     {
00353     case ACPI_NO_BUFFER:
00354 
00355         /* Return the exception (and the required buffer length) */
00356 
00357         return (AE_BUFFER_OVERFLOW);
00358 
00359     case ACPI_ALLOCATE_BUFFER:
00360 
00361         /* Allocate a new buffer */
00362 
00363         Buffer->Pointer = AcpiOsAllocate (RequiredLength);
00364         break;
00365 
00366     case ACPI_ALLOCATE_LOCAL_BUFFER:
00367 
00368         /* Allocate a new buffer with local interface to allow tracking */
00369 
00370         Buffer->Pointer = ACPI_ALLOCATE (RequiredLength);
00371         break;
00372 
00373     default:
00374 
00375         /* Existing buffer: Validate the size of the buffer */
00376 
00377         if (InputBufferLength < RequiredLength)
00378         {
00379             return (AE_BUFFER_OVERFLOW);
00380         }
00381         break;
00382     }
00383 
00384     /* Validate allocation from above or input buffer pointer */
00385 
00386     if (!Buffer->Pointer)
00387     {
00388         return (AE_NO_MEMORY);
00389     }
00390 
00391     /* Have a valid buffer, clear it */
00392 
00393     ACPI_MEMSET (Buffer->Pointer, 0, RequiredLength);
00394     return (AE_OK);
00395 }
00396 
00397 
00398 /*******************************************************************************
00399  *
00400  * FUNCTION:    AcpiUtAllocate
00401  *
00402  * PARAMETERS:  Size                - Size of the allocation
00403  *              Component           - Component type of caller
00404  *              Module              - Source file name of caller
00405  *              Line                - Line number of caller
00406  *
00407  * RETURN:      Address of the allocated memory on success, NULL on failure.
00408  *
00409  * DESCRIPTION: Subsystem equivalent of malloc.
00410  *
00411  ******************************************************************************/
00412 
00413 void *
00414 AcpiUtAllocate (
00415     ACPI_SIZE               Size,
00416     UINT32                  Component,
00417     const char              *Module,
00418     UINT32                  Line)
00419 {
00420     void                    *Allocation;
00421 
00422 
00423     ACPI_FUNCTION_TRACE_U32 (UtAllocate, Size);
00424 
00425 
00426     /* Check for an inadvertent size of zero bytes */
00427 
00428     if (!Size)
00429     {
00430         ACPI_WARNING ((Module, Line,
00431             "Attempt to allocate zero bytes, allocating 1 byte"));
00432         Size = 1;
00433     }
00434 
00435     Allocation = AcpiOsAllocate (Size);
00436     if (!Allocation)
00437     {
00438         /* Report allocation error */
00439 
00440         ACPI_WARNING ((Module, Line,
00441             "Could not allocate size %u", (UINT32) Size));
00442 
00443         return_PTR (NULL);
00444     }
00445 
00446     return_PTR (Allocation);
00447 }
00448 
00449 
00450 /*******************************************************************************
00451  *
00452  * FUNCTION:    AcpiUtAllocateZeroed
00453  *
00454  * PARAMETERS:  Size                - Size of the allocation
00455  *              Component           - Component type of caller
00456  *              Module              - Source file name of caller
00457  *              Line                - Line number of caller
00458  *
00459  * RETURN:      Address of the allocated memory on success, NULL on failure.
00460  *
00461  * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
00462  *
00463  ******************************************************************************/
00464 
00465 void *
00466 AcpiUtAllocateZeroed (
00467     ACPI_SIZE               Size,
00468     UINT32                  Component,
00469     const char              *Module,
00470     UINT32                  Line)
00471 {
00472     void                    *Allocation;
00473 
00474 
00475     ACPI_FUNCTION_ENTRY ();
00476 
00477 
00478     Allocation = AcpiUtAllocate (Size, Component, Module, Line);
00479     if (Allocation)
00480     {
00481         /* Clear the memory block */
00482 
00483         ACPI_MEMSET (Allocation, 0, Size);
00484     }
00485 
00486     return (Allocation);
00487 }
00488 

Generated on Sat May 26 2012 04:25:56 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.