Print this page
update to acpica-unix2-20140114
update to acpica-unix2-20131218
update to acpica-unix2-20130927
acpica-unix2-20130823
PANKOVs restructure
   1 /******************************************************************************
   2  *
   3  * Module Name: utalloc - local memory allocation routines
   4  *
   5  *****************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2011, Intel Corp.
   9  * All rights reserved.
  10  *
  11  * Redistribution and use in source and binary forms, with or without
  12  * modification, are permitted provided that the following conditions
  13  * are met:
  14  * 1. Redistributions of source code must retain the above copyright
  15  *    notice, this list of conditions, and the following disclaimer,
  16  *    without modification.
  17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18  *    substantially similar to the "NO WARRANTY" disclaimer below
  19  *    ("Disclaimer") and any redistribution must be conditioned upon
  20  *    including a substantially similar Disclaimer requirement for further
  21  *    binary redistribution.
  22  * 3. Neither the names of the above-listed copyright holders nor the names
  23  *    of any contributors may be used to endorse or promote products derived
  24  *    from this software without specific prior written permission.
  25  *
  26  * Alternatively, this software may be distributed under the terms of the
  27  * GNU General Public License ("GPL") version 2 as published by the Free
  28  * Software Foundation.


  34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41  * POSSIBILITY OF SUCH DAMAGES.
  42  */
  43 
  44 #define __UTALLOC_C__
  45 
  46 #include "acpi.h"
  47 #include "accommon.h"
  48 #include "acdebug.h"
  49 
  50 #define _COMPONENT          ACPI_UTILITIES
  51         ACPI_MODULE_NAME    ("utalloc")
  52 
  53 

  54 /*******************************************************************************
  55  *






































  56  * FUNCTION:    AcpiUtCreateCaches
  57  *
  58  * PARAMETERS:  None
  59  *
  60  * RETURN:      Status
  61  *
  62  * DESCRIPTION: Create all local caches
  63  *
  64  ******************************************************************************/
  65 
  66 ACPI_STATUS
  67 AcpiUtCreateCaches (
  68     void)
  69 {
  70     ACPI_STATUS             Status;
  71 
  72 
  73     /* Object Caches, for frequently used objects */
  74 
  75     Status = AcpiOsCreateCache ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),


 268     /*
 269      * Buffer->Length is used as both an input and output parameter. Get the
 270      * input actual length and set the output required buffer length.
 271      */
 272     InputBufferLength = Buffer->Length;
 273     Buffer->Length = RequiredLength;
 274 
 275     /*
 276      * The input buffer length contains the actual buffer length, or the type
 277      * of buffer to be allocated by this routine.
 278      */
 279     switch (InputBufferLength)
 280     {
 281     case ACPI_NO_BUFFER:
 282 
 283         /* Return the exception (and the required buffer length) */
 284 
 285         return (AE_BUFFER_OVERFLOW);
 286 
 287     case ACPI_ALLOCATE_BUFFER:
 288 
 289         /* Allocate a new buffer */
 290 




 291         Buffer->Pointer = AcpiOsAllocate (RequiredLength);
 292         break;
 293 
 294     case ACPI_ALLOCATE_LOCAL_BUFFER:
 295 
 296         /* Allocate a new buffer with local interface to allow tracking */
 297 
 298         Buffer->Pointer = ACPI_ALLOCATE (RequiredLength);
 299         break;
 300 
 301     default:
 302 
 303         /* Existing buffer: Validate the size of the buffer */
 304 
 305         if (InputBufferLength < RequiredLength)
 306         {
 307             return (AE_BUFFER_OVERFLOW);
 308         }
 309         break;
 310     }
 311 
 312     /* Validate allocation from above or input buffer pointer */
 313 
 314     if (!Buffer->Pointer)
 315     {
 316         return (AE_NO_MEMORY);
 317     }
 318 
 319     /* Have a valid buffer, clear it */
 320 
 321     ACPI_MEMSET (Buffer->Pointer, 0, RequiredLength);
 322     return (AE_OK);
 323 }
 324 
 325 
 326 /*******************************************************************************
 327  *
 328  * FUNCTION:    AcpiUtAllocate
 329  *
 330  * PARAMETERS:  Size                - Size of the allocation
 331  *              Component           - Component type of caller
 332  *              Module              - Source file name of caller
 333  *              Line                - Line number of caller
 334  *
 335  * RETURN:      Address of the allocated memory on success, NULL on failure.
 336  *
 337  * DESCRIPTION: Subsystem equivalent of malloc.
 338  *
 339  ******************************************************************************/
 340 
 341 void *
 342 AcpiUtAllocate (
 343     ACPI_SIZE               Size,
 344     UINT32                  Component,
 345     const char              *Module,
 346     UINT32                  Line)
 347 {
 348     void                    *Allocation;
 349 
 350 
 351     ACPI_FUNCTION_TRACE_U32 (UtAllocate, Size);
 352 
 353 
 354     /* Check for an inadvertent size of zero bytes */
 355 
 356     if (!Size)
 357     {
 358         ACPI_WARNING ((Module, Line,
 359             "Attempt to allocate zero bytes, allocating 1 byte"));
 360         Size = 1;
 361     }
 362 
 363     Allocation = AcpiOsAllocate (Size);
 364     if (!Allocation)
 365     {
 366         /* Report allocation error */
 367 
 368         ACPI_WARNING ((Module, Line,
 369             "Could not allocate size %u", (UINT32) Size));
 370 
 371         return_PTR (NULL);
 372     }
 373 
 374     return_PTR (Allocation);
 375 }
 376 
 377 
 378 /*******************************************************************************
 379  *
 380  * FUNCTION:    AcpiUtAllocateZeroed
 381  *
 382  * PARAMETERS:  Size                - Size of the allocation
 383  *              Component           - Component type of caller
 384  *              Module              - Source file name of caller
 385  *              Line                - Line number of caller
 386  *
 387  * RETURN:      Address of the allocated memory on success, NULL on failure.
 388  *
 389  * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
 390  *
 391  ******************************************************************************/
 392 
 393 void *
 394 AcpiUtAllocateZeroed (
 395     ACPI_SIZE               Size,
 396     UINT32                  Component,
 397     const char              *Module,
 398     UINT32                  Line)
 399 {
 400     void                    *Allocation;
 401 
 402 
 403     ACPI_FUNCTION_ENTRY ();
 404 
 405 
 406     Allocation = AcpiUtAllocate (Size, Component, Module, Line);
 407     if (Allocation)
 408     {
 409         /* Clear the memory block */
 410 
 411         ACPI_MEMSET (Allocation, 0, Size);
 412     }
 413 
 414     return (Allocation);
 415 }
 416 
   1 /******************************************************************************
   2  *
   3  * Module Name: utalloc - local memory allocation routines
   4  *
   5  *****************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2014, Intel Corp.
   9  * All rights reserved.
  10  *
  11  * Redistribution and use in source and binary forms, with or without
  12  * modification, are permitted provided that the following conditions
  13  * are met:
  14  * 1. Redistributions of source code must retain the above copyright
  15  *    notice, this list of conditions, and the following disclaimer,
  16  *    without modification.
  17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18  *    substantially similar to the "NO WARRANTY" disclaimer below
  19  *    ("Disclaimer") and any redistribution must be conditioned upon
  20  *    including a substantially similar Disclaimer requirement for further
  21  *    binary redistribution.
  22  * 3. Neither the names of the above-listed copyright holders nor the names
  23  *    of any contributors may be used to endorse or promote products derived
  24  *    from this software without specific prior written permission.
  25  *
  26  * Alternatively, this software may be distributed under the terms of the
  27  * GNU General Public License ("GPL") version 2 as published by the Free
  28  * Software Foundation.


  34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41  * POSSIBILITY OF SUCH DAMAGES.
  42  */
  43 
  44 #define __UTALLOC_C__
  45 
  46 #include "acpi.h"
  47 #include "accommon.h"
  48 #include "acdebug.h"
  49 
  50 #define _COMPONENT          ACPI_UTILITIES
  51         ACPI_MODULE_NAME    ("utalloc")
  52 
  53 
  54 #if !defined (USE_NATIVE_ALLOCATE_ZEROED)
  55 /*******************************************************************************
  56  *
  57  * FUNCTION:    AcpiOsAllocateZeroed
  58  *
  59  * PARAMETERS:  Size                - Size of the allocation
  60  *
  61  * RETURN:      Address of the allocated memory on success, NULL on failure.
  62  *
  63  * DESCRIPTION: Subsystem equivalent of calloc. Allocate and zero memory.
  64  *              This is the default implementation. Can be overridden via the
  65  *              USE_NATIVE_ALLOCATE_ZEROED flag.
  66  *
  67  ******************************************************************************/
  68 
  69 void *
  70 AcpiOsAllocateZeroed (
  71     ACPI_SIZE               Size)
  72 {
  73     void                    *Allocation;
  74 
  75 
  76     ACPI_FUNCTION_ENTRY ();
  77 
  78 
  79     Allocation = AcpiOsAllocate (Size);
  80     if (Allocation)
  81     {
  82         /* Clear the memory block */
  83 
  84         ACPI_MEMSET (Allocation, 0, Size);
  85     }
  86 
  87     return (Allocation);
  88 }
  89 
  90 #endif /* !USE_NATIVE_ALLOCATE_ZEROED */
  91 
  92 
  93 /*******************************************************************************
  94  *
  95  * FUNCTION:    AcpiUtCreateCaches
  96  *
  97  * PARAMETERS:  None
  98  *
  99  * RETURN:      Status
 100  *
 101  * DESCRIPTION: Create all local caches
 102  *
 103  ******************************************************************************/
 104 
 105 ACPI_STATUS
 106 AcpiUtCreateCaches (
 107     void)
 108 {
 109     ACPI_STATUS             Status;
 110 
 111 
 112     /* Object Caches, for frequently used objects */
 113 
 114     Status = AcpiOsCreateCache ("Acpi-Namespace", sizeof (ACPI_NAMESPACE_NODE),


 307     /*
 308      * Buffer->Length is used as both an input and output parameter. Get the
 309      * input actual length and set the output required buffer length.
 310      */
 311     InputBufferLength = Buffer->Length;
 312     Buffer->Length = RequiredLength;
 313 
 314     /*
 315      * The input buffer length contains the actual buffer length, or the type
 316      * of buffer to be allocated by this routine.
 317      */
 318     switch (InputBufferLength)
 319     {
 320     case ACPI_NO_BUFFER:
 321 
 322         /* Return the exception (and the required buffer length) */
 323 
 324         return (AE_BUFFER_OVERFLOW);
 325 
 326     case ACPI_ALLOCATE_BUFFER:
 327         /*
 328          * Allocate a new buffer. We directectly call AcpiOsAllocate here to
 329          * purposefully bypass the (optionally enabled) internal allocation
 330          * tracking mechanism since we only want to track internal
 331          * allocations. Note: The caller should use AcpiOsFree to free this
 332          * buffer created via ACPI_ALLOCATE_BUFFER.
 333          */
 334         Buffer->Pointer = AcpiOsAllocate (RequiredLength);
 335         break;
 336 
 337     case ACPI_ALLOCATE_LOCAL_BUFFER:
 338 
 339         /* Allocate a new buffer with local interface to allow tracking */
 340 
 341         Buffer->Pointer = ACPI_ALLOCATE (RequiredLength);
 342         break;
 343 
 344     default:
 345 
 346         /* Existing buffer: Validate the size of the buffer */
 347 
 348         if (InputBufferLength < RequiredLength)
 349         {
 350             return (AE_BUFFER_OVERFLOW);
 351         }
 352         break;
 353     }
 354 
 355     /* Validate allocation from above or input buffer pointer */
 356 
 357     if (!Buffer->Pointer)
 358     {
 359         return (AE_NO_MEMORY);
 360     }
 361 
 362     /* Have a valid buffer, clear it */
 363 
 364     ACPI_MEMSET (Buffer->Pointer, 0, RequiredLength);
 365     return (AE_OK);
 366 }