Print this page
update to acpica-unix2-20130927
acpica-unix2-20130823
PANKOVs restructure

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/io/acpica/utilities/uttrack.c
          +++ new/usr/src/common/acpica/components/utilities/uttrack.c
   1    1  /******************************************************************************
   2    2   *
   3    3   * Module Name: uttrack - Memory allocation tracking routines (debug only)
   4    4   *
   5    5   *****************************************************************************/
   6    6  
   7    7  /*
   8      - * Copyright (C) 2000 - 2011, Intel Corp.
        8 + * Copyright (C) 2000 - 2013, Intel Corp.
   9    9   * All rights reserved.
  10   10   *
  11   11   * Redistribution and use in source and binary forms, with or without
  12   12   * modification, are permitted provided that the following conditions
  13   13   * are met:
  14   14   * 1. Redistributions of source code must retain the above copyright
  15   15   *    notice, this list of conditions, and the following disclaimer,
  16   16   *    without modification.
  17   17   * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18   18   *    substantially similar to the "NO WARRANTY" disclaimer below
↓ open down ↓ 19 lines elided ↑ open up ↑
  38   38   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39   39   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40   40   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41   41   * POSSIBILITY OF SUCH DAMAGES.
  42   42   */
  43   43  
  44   44  /*
  45   45   * These procedures are used for tracking memory leaks in the subsystem, and
  46   46   * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
  47   47   *
  48      - * Each memory allocation is tracked via a doubly linked list.  Each
       48 + * Each memory allocation is tracked via a doubly linked list. Each
  49   49   * element contains the caller's component, module name, function name, and
  50      - * line number.  AcpiUtAllocate and AcpiUtAllocateZeroed call
       50 + * line number. AcpiUtAllocate and AcpiUtAllocateZeroed call
  51   51   * AcpiUtTrackAllocation to add an element to the list; deletion
  52   52   * occurs in the body of AcpiUtFree.
  53   53   */
  54   54  
  55   55  #define __UTTRACK_C__
  56   56  
  57   57  #include "acpi.h"
  58   58  #include "accommon.h"
  59   59  
  60   60  #ifdef ACPI_DBG_TRACK_ALLOCATIONS
  61   61  
  62   62  #define _COMPONENT          ACPI_UTILITIES
  63   63          ACPI_MODULE_NAME    ("uttrack")
  64   64  
       65 +
  65   66  /* Local prototypes */
  66   67  
  67   68  static ACPI_DEBUG_MEM_BLOCK *
  68   69  AcpiUtFindAllocation (
  69      -    void                    *Allocation);
       70 +    ACPI_DEBUG_MEM_BLOCK    *Allocation);
  70   71  
  71   72  static ACPI_STATUS
  72   73  AcpiUtTrackAllocation (
  73   74      ACPI_DEBUG_MEM_BLOCK    *Address,
  74   75      ACPI_SIZE               Size,
  75   76      UINT8                   AllocType,
  76   77      UINT32                  Component,
  77   78      const char              *Module,
  78   79      UINT32                  Line);
  79   80  
↓ open down ↓ 63 lines elided ↑ open up ↑
 143  144  AcpiUtAllocateAndTrack (
 144  145      ACPI_SIZE               Size,
 145  146      UINT32                  Component,
 146  147      const char              *Module,
 147  148      UINT32                  Line)
 148  149  {
 149  150      ACPI_DEBUG_MEM_BLOCK    *Allocation;
 150  151      ACPI_STATUS             Status;
 151  152  
 152  153  
 153      -    Allocation = AcpiUtAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER),
 154      -                    Component, Module, Line);
      154 +    /* Check for an inadvertent size of zero bytes */
      155 +
      156 +    if (!Size)
      157 +    {
      158 +        ACPI_WARNING ((Module, Line,
      159 +            "Attempt to allocate zero bytes, allocating 1 byte"));
      160 +        Size = 1;
      161 +    }
      162 +
      163 +    Allocation = AcpiOsAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER));
 155  164      if (!Allocation)
 156  165      {
      166 +        /* Report allocation error */
      167 +
      168 +        ACPI_WARNING ((Module, Line,
      169 +            "Could not allocate size %u", (UINT32) Size));
      170 +
 157  171          return (NULL);
 158  172      }
 159  173  
 160  174      Status = AcpiUtTrackAllocation (Allocation, Size,
 161  175                      ACPI_MEM_MALLOC, Component, Module, Line);
 162  176      if (ACPI_FAILURE (Status))
 163  177      {
 164  178          AcpiOsFree (Allocation);
 165  179          return (NULL);
 166  180      }
↓ open down ↓ 29 lines elided ↑ open up ↑
 196  210  AcpiUtAllocateZeroedAndTrack (
 197  211      ACPI_SIZE               Size,
 198  212      UINT32                  Component,
 199  213      const char              *Module,
 200  214      UINT32                  Line)
 201  215  {
 202  216      ACPI_DEBUG_MEM_BLOCK    *Allocation;
 203  217      ACPI_STATUS             Status;
 204  218  
 205  219  
 206      -    Allocation = AcpiUtAllocateZeroed (Size + sizeof (ACPI_DEBUG_MEM_HEADER),
 207      -                    Component, Module, Line);
      220 +    /* Check for an inadvertent size of zero bytes */
      221 +
      222 +    if (!Size)
      223 +    {
      224 +        ACPI_WARNING ((Module, Line,
      225 +            "Attempt to allocate zero bytes, allocating 1 byte"));
      226 +        Size = 1;
      227 +    }
      228 +
      229 +    Allocation = AcpiOsAllocateZeroed (Size + sizeof (ACPI_DEBUG_MEM_HEADER));
 208  230      if (!Allocation)
 209  231      {
 210  232          /* Report allocation error */
 211  233  
 212  234          ACPI_ERROR ((Module, Line,
 213  235              "Could not allocate size %u", (UINT32) Size));
 214  236          return (NULL);
 215  237      }
 216  238  
 217  239      Status = AcpiUtTrackAllocation (Allocation, Size,
↓ open down ↓ 71 lines elided ↑ open up ↑
 289  311      return_VOID;
 290  312  }
 291  313  
 292  314  
 293  315  /*******************************************************************************
 294  316   *
 295  317   * FUNCTION:    AcpiUtFindAllocation
 296  318   *
 297  319   * PARAMETERS:  Allocation              - Address of allocated memory
 298  320   *
 299      - * RETURN:      A list element if found; NULL otherwise.
      321 + * RETURN:      Three cases:
      322 + *              1) List is empty, NULL is returned.
      323 + *              2) Element was found. Returns Allocation parameter.
      324 + *              3) Element was not found. Returns position where it should be
      325 + *                  inserted into the list.
 300  326   *
 301  327   * DESCRIPTION: Searches for an element in the global allocation tracking list.
      328 + *              If the element is not found, returns the location within the
      329 + *              list where the element should be inserted.
 302  330   *
      331 + *              Note: The list is ordered by larger-to-smaller addresses.
      332 + *
      333 + *              This global list is used to detect memory leaks in ACPICA as
      334 + *              well as other issues such as an attempt to release the same
      335 + *              internal object more than once. Although expensive as far
      336 + *              as cpu time, this list is much more helpful for finding these
      337 + *              types of issues than using memory leak detectors outside of
      338 + *              the ACPICA code.
      339 + *
 303  340   ******************************************************************************/
 304  341  
 305  342  static ACPI_DEBUG_MEM_BLOCK *
 306  343  AcpiUtFindAllocation (
 307      -    void                    *Allocation)
      344 +    ACPI_DEBUG_MEM_BLOCK    *Allocation)
 308  345  {
 309  346      ACPI_DEBUG_MEM_BLOCK    *Element;
 310  347  
 311  348  
 312      -    ACPI_FUNCTION_ENTRY ();
 313      -
 314      -
 315  349      Element = AcpiGbl_GlobalList->ListHead;
      350 +    if (!Element)
      351 +    {
      352 +        return (NULL);
      353 +    }
 316  354  
 317      -    /* Search for the address. */
 318      -
 319      -    while (Element)
      355 +    /*
      356 +     * Search for the address.
      357 +     *
      358 +     * Note: List is ordered by larger-to-smaller addresses, on the
      359 +     * assumption that a new allocation usually has a larger address
      360 +     * than previous allocations.
      361 +     */
      362 +    while (Element > Allocation)
 320  363      {
 321      -        if (Element == Allocation)
      364 +        /* Check for end-of-list */
      365 +
      366 +        if (!Element->Next)
 322  367          {
 323  368              return (Element);
 324  369          }
 325  370  
 326  371          Element = Element->Next;
 327  372      }
 328  373  
 329      -    return (NULL);
      374 +    if (Element == Allocation)
      375 +    {
      376 +        return (Element);
      377 +    }
      378 +
      379 +    return (Element->Previous);
 330  380  }
 331  381  
 332  382  
 333  383  /*******************************************************************************
 334  384   *
 335  385   * FUNCTION:    AcpiUtTrackAllocation
 336  386   *
 337  387   * PARAMETERS:  Allocation          - Address of allocated memory
 338  388   *              Size                - Size of the allocation
 339  389   *              AllocType           - MEM_MALLOC or MEM_CALLOC
 340  390   *              Component           - Component type of caller
 341  391   *              Module              - Source file name of caller
 342  392   *              Line                - Line number of caller
 343  393   *
 344      - * RETURN:      None.
      394 + * RETURN:      Status
 345  395   *
 346  396   * DESCRIPTION: Inserts an element into the global allocation tracking list.
 347  397   *
 348  398   ******************************************************************************/
 349  399  
 350  400  static ACPI_STATUS
 351  401  AcpiUtTrackAllocation (
 352  402      ACPI_DEBUG_MEM_BLOCK    *Allocation,
 353  403      ACPI_SIZE               Size,
 354  404      UINT8                   AllocType,
↓ open down ↓ 15 lines elided ↑ open up ↑
 370  420      }
 371  421  
 372  422      MemList = AcpiGbl_GlobalList;
 373  423      Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
 374  424      if (ACPI_FAILURE (Status))
 375  425      {
 376  426          return_ACPI_STATUS (Status);
 377  427      }
 378  428  
 379  429      /*
 380      -     * Search list for this address to make sure it is not already on the list.
 381      -     * This will catch several kinds of problems.
      430 +     * Search the global list for this address to make sure it is not
      431 +     * already present. This will catch several kinds of problems.
 382  432       */
 383  433      Element = AcpiUtFindAllocation (Allocation);
 384      -    if (Element)
      434 +    if (Element == Allocation)
 385  435      {
 386  436          ACPI_ERROR ((AE_INFO,
 387      -            "UtTrackAllocation: Allocation already present in list! (%p)",
      437 +            "UtTrackAllocation: Allocation (%p) already present in global list!",
 388  438              Allocation));
 389      -
 390      -        ACPI_ERROR ((AE_INFO, "Element %p Address %p",
 391      -            Element, Allocation));
 392      -
 393  439          goto UnlockAndExit;
 394  440      }
 395  441  
 396      -    /* Fill in the instance data. */
      442 +    /* Fill in the instance data */
 397  443  
 398  444      Allocation->Size      = (UINT32) Size;
 399  445      Allocation->AllocType = AllocType;
 400  446      Allocation->Component = Component;
 401  447      Allocation->Line      = Line;
 402  448  
 403  449      ACPI_STRNCPY (Allocation->Module, Module, ACPI_MAX_MODULE_NAME);
 404  450      Allocation->Module[ACPI_MAX_MODULE_NAME-1] = 0;
 405  451  
 406      -    /* Insert at list head */
 407      -
 408      -    if (MemList->ListHead)
      452 +    if (!Element)
 409  453      {
 410      -        ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Allocation;
      454 +        /* Insert at list head */
      455 +
      456 +        if (MemList->ListHead)
      457 +        {
      458 +            ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Allocation;
      459 +        }
      460 +
      461 +        Allocation->Next = MemList->ListHead;
      462 +        Allocation->Previous = NULL;
      463 +
      464 +        MemList->ListHead = Allocation;
 411  465      }
      466 +    else
      467 +    {
      468 +        /* Insert after element */
 412  469  
 413      -    Allocation->Next = MemList->ListHead;
 414      -    Allocation->Previous = NULL;
      470 +        Allocation->Next = Element->Next;
      471 +        Allocation->Previous = Element;
 415  472  
 416      -    MemList->ListHead = Allocation;
      473 +        if (Element->Next)
      474 +        {
      475 +            (Element->Next)->Previous = Allocation;
      476 +        }
 417  477  
      478 +        Element->Next = Allocation;
      479 +    }
 418  480  
      481 +
 419  482  UnlockAndExit:
 420  483      Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
 421  484      return_ACPI_STATUS (Status);
 422  485  }
 423  486  
 424  487  
 425  488  /*******************************************************************************
 426  489   *
 427  490   * FUNCTION:    AcpiUtRemoveAllocation
 428  491   *
 429  492   * PARAMETERS:  Allocation          - Address of allocated memory
 430  493   *              Component           - Component type of caller
 431  494   *              Module              - Source file name of caller
 432  495   *              Line                - Line number of caller
 433  496   *
 434      - * RETURN:
      497 + * RETURN:      Status
 435  498   *
 436  499   * DESCRIPTION: Deletes an element from the global allocation tracking list.
 437  500   *
 438  501   ******************************************************************************/
 439  502  
 440  503  static ACPI_STATUS
 441  504  AcpiUtRemoveAllocation (
 442  505      ACPI_DEBUG_MEM_BLOCK    *Allocation,
 443  506      UINT32                  Component,
 444  507      const char              *Module,
 445  508      UINT32                  Line)
 446  509  {
 447  510      ACPI_MEMORY_LIST        *MemList;
 448  511      ACPI_STATUS             Status;
 449  512  
 450  513  
 451      -    ACPI_FUNCTION_TRACE (UtRemoveAllocation);
      514 +    ACPI_FUNCTION_NAME (UtRemoveAllocation);
 452  515  
 453  516  
 454  517      if (AcpiGbl_DisableMemTracking)
 455  518      {
 456      -        return_ACPI_STATUS (AE_OK);
      519 +        return (AE_OK);
 457  520      }
 458  521  
 459  522      MemList = AcpiGbl_GlobalList;
 460  523      if (NULL == MemList->ListHead)
 461  524      {
 462  525          /* No allocations! */
 463  526  
 464  527          ACPI_ERROR ((Module, Line,
 465  528              "Empty allocation list, nothing to free!"));
 466  529  
 467      -        return_ACPI_STATUS (AE_OK);
      530 +        return (AE_OK);
 468  531      }
 469  532  
 470  533      Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
 471  534      if (ACPI_FAILURE (Status))
 472  535      {
 473      -        return_ACPI_STATUS (Status);
      536 +        return (Status);
 474  537      }
 475  538  
 476  539      /* Unlink */
 477  540  
 478  541      if (Allocation->Previous)
 479  542      {
 480  543          (Allocation->Previous)->Next = Allocation->Next;
 481  544      }
 482  545      else
 483  546      {
 484  547          MemList->ListHead = Allocation->Next;
 485  548      }
 486  549  
 487  550      if (Allocation->Next)
 488  551      {
 489  552          (Allocation->Next)->Previous = Allocation->Previous;
 490  553      }
 491  554  
      555 +    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing %p, size 0%X\n",
      556 +        &Allocation->UserSpace, Allocation->Size));
      557 +
 492  558      /* Mark the segment as deleted */
 493  559  
 494  560      ACPI_MEMSET (&Allocation->UserSpace, 0xEA, Allocation->Size);
 495  561  
 496      -    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n",
 497      -        Allocation->Size));
 498      -
 499  562      Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
 500      -    return_ACPI_STATUS (Status);
      563 +    return (Status);
 501  564  }
 502  565  
 503  566  
 504  567  /*******************************************************************************
 505  568   *
 506  569   * FUNCTION:    AcpiUtDumpAllocationInfo
 507  570   *
 508      - * PARAMETERS:
      571 + * PARAMETERS:  None
 509  572   *
 510  573   * RETURN:      None
 511  574   *
 512  575   * DESCRIPTION: Print some info about the outstanding allocations.
 513  576   *
 514  577   ******************************************************************************/
 515  578  
 516  579  void
 517  580  AcpiUtDumpAllocationInfo (
 518  581      void)
↓ open down ↓ 40 lines elided ↑ open up ↑
 559  622  */
 560  623      return_VOID;
 561  624  }
 562  625  
 563  626  
 564  627  /*******************************************************************************
 565  628   *
 566  629   * FUNCTION:    AcpiUtDumpAllocations
 567  630   *
 568  631   * PARAMETERS:  Component           - Component(s) to dump info for.
 569      - *              Module              - Module to dump info for.  NULL means all.
      632 + *              Module              - Module to dump info for. NULL means all.
 570  633   *
 571  634   * RETURN:      None
 572  635   *
 573  636   * DESCRIPTION: Print a list of all outstanding allocations.
 574  637   *
 575  638   ******************************************************************************/
 576  639  
 577  640  void
 578  641  AcpiUtDumpAllocations (
 579  642      UINT32                  Component,
↓ open down ↓ 3 lines elided ↑ open up ↑
 583  646      ACPI_DESCRIPTOR         *Descriptor;
 584  647      UINT32                  NumOutstanding = 0;
 585  648      UINT8                   DescriptorType;
 586  649  
 587  650  
 588  651      ACPI_FUNCTION_TRACE (UtDumpAllocations);
 589  652  
 590  653  
 591  654      if (AcpiGbl_DisableMemTracking)
 592  655      {
 593      -        return;
      656 +        return_VOID;
 594  657      }
 595  658  
 596  659      /*
 597  660       * Walk the allocation list.
 598  661       */
 599  662      if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY)))
 600  663      {
 601      -        return;
      664 +        return_VOID;
 602  665      }
 603  666  
 604  667      Element = AcpiGbl_GlobalList->ListHead;
 605  668      while (Element)
 606  669      {
 607  670          if ((Element->Component & Component) &&
 608  671              ((Module == NULL) || (0 == ACPI_STRCMP (Module, Element->Module))))
 609  672          {
 610  673              Descriptor = ACPI_CAST_PTR (ACPI_DESCRIPTOR, &Element->UserSpace);
 611  674  
↓ open down ↓ 14 lines elided ↑ open up ↑
 626  689                          Descriptor, Element->Size, Element->Module,
 627  690                          Element->Line, AcpiUtGetDescriptorName (Descriptor));
 628  691  
 629  692                      /* Validate the descriptor type using Type field and length */
 630  693  
 631  694                      DescriptorType = 0; /* Not a valid descriptor type */
 632  695  
 633  696                      switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
 634  697                      {
 635  698                      case ACPI_DESC_TYPE_OPERAND:
 636      -                        if (Element->Size == sizeof (ACPI_DESC_TYPE_OPERAND))
      699 +
      700 +                        if (Element->Size == sizeof (ACPI_OPERAND_OBJECT))
 637  701                          {
 638  702                              DescriptorType = ACPI_DESC_TYPE_OPERAND;
 639  703                          }
 640  704                          break;
 641  705  
 642  706                      case ACPI_DESC_TYPE_PARSER:
 643      -                        if (Element->Size == sizeof (ACPI_DESC_TYPE_PARSER))
      707 +
      708 +                        if (Element->Size == sizeof (ACPI_PARSE_OBJECT))
 644  709                          {
 645  710                              DescriptorType = ACPI_DESC_TYPE_PARSER;
 646  711                          }
 647  712                          break;
 648  713  
 649  714                      case ACPI_DESC_TYPE_NAMED:
 650      -                        if (Element->Size == sizeof (ACPI_DESC_TYPE_NAMED))
      715 +
      716 +                        if (Element->Size == sizeof (ACPI_NAMESPACE_NODE))
 651  717                          {
 652  718                              DescriptorType = ACPI_DESC_TYPE_NAMED;
 653  719                          }
 654  720                          break;
 655  721  
 656  722                      default:
      723 +
 657  724                          break;
 658  725                      }
 659  726  
 660  727                      /* Display additional info for the major descriptor types */
 661  728  
 662  729                      switch (DescriptorType)
 663  730                      {
 664  731                      case ACPI_DESC_TYPE_OPERAND:
      732 +
 665  733                          AcpiOsPrintf ("%12.12s  RefCount 0x%04X\n",
 666  734                              AcpiUtGetTypeName (Descriptor->Object.Common.Type),
 667  735                              Descriptor->Object.Common.ReferenceCount);
 668  736                          break;
 669  737  
 670  738                      case ACPI_DESC_TYPE_PARSER:
      739 +
 671  740                          AcpiOsPrintf ("AmlOpcode 0x%04hX\n",
 672  741                              Descriptor->Op.Asl.AmlOpcode);
 673  742                          break;
 674  743  
 675  744                      case ACPI_DESC_TYPE_NAMED:
      745 +
 676  746                          AcpiOsPrintf ("%4.4s\n",
 677  747                              AcpiUtGetNodeName (&Descriptor->Node));
 678  748                          break;
 679  749  
 680  750                      default:
      751 +
 681  752                          AcpiOsPrintf ( "\n");
 682  753                          break;
 683  754                      }
 684  755                  }
 685  756              }
 686  757  
 687  758              NumOutstanding++;
 688  759          }
 689  760  
 690  761          Element = Element->Next;
↓ open down ↓ 10 lines elided ↑ open up ↑
 701  772      else
 702  773      {
 703  774          ACPI_ERROR ((AE_INFO, "%u(0x%X) Outstanding allocations",
 704  775              NumOutstanding, NumOutstanding));
 705  776      }
 706  777  
 707  778      return_VOID;
 708  779  }
 709  780  
 710  781  #endif  /* ACPI_DBG_TRACK_ALLOCATIONS */
 711      -
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX