Print this page
update to acpica-unix2-20140114
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 - 2014, 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 ↓ 60 lines elided ↑ open up ↑
 278  300      AcpiGbl_GlobalList->CurrentTotalSize -= DebugBlock->Size;
 279  301  
 280  302      Status = AcpiUtRemoveAllocation (DebugBlock,
 281  303                      Component, Module, Line);
 282  304      if (ACPI_FAILURE (Status))
 283  305      {
 284  306          ACPI_EXCEPTION ((AE_INFO, Status, "Could not free memory"));
 285  307      }
 286  308  
 287  309      AcpiOsFree (DebugBlock);
 288      -    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", Allocation));
      310 +    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed (block %p)\n",
      311 +        Allocation, DebugBlock));
 289  312      return_VOID;
 290  313  }
 291  314  
 292  315  
 293  316  /*******************************************************************************
 294  317   *
 295  318   * FUNCTION:    AcpiUtFindAllocation
 296  319   *
 297  320   * PARAMETERS:  Allocation              - Address of allocated memory
 298  321   *
 299      - * RETURN:      A list element if found; NULL otherwise.
      322 + * RETURN:      Three cases:
      323 + *              1) List is empty, NULL is returned.
      324 + *              2) Element was found. Returns Allocation parameter.
      325 + *              3) Element was not found. Returns position where it should be
      326 + *                  inserted into the list.
 300  327   *
 301  328   * DESCRIPTION: Searches for an element in the global allocation tracking list.
      329 + *              If the element is not found, returns the location within the
      330 + *              list where the element should be inserted.
 302  331   *
      332 + *              Note: The list is ordered by larger-to-smaller addresses.
      333 + *
      334 + *              This global list is used to detect memory leaks in ACPICA as
      335 + *              well as other issues such as an attempt to release the same
      336 + *              internal object more than once. Although expensive as far
      337 + *              as cpu time, this list is much more helpful for finding these
      338 + *              types of issues than using memory leak detectors outside of
      339 + *              the ACPICA code.
      340 + *
 303  341   ******************************************************************************/
 304  342  
 305  343  static ACPI_DEBUG_MEM_BLOCK *
 306  344  AcpiUtFindAllocation (
 307      -    void                    *Allocation)
      345 +    ACPI_DEBUG_MEM_BLOCK    *Allocation)
 308  346  {
 309  347      ACPI_DEBUG_MEM_BLOCK    *Element;
 310  348  
 311  349  
 312      -    ACPI_FUNCTION_ENTRY ();
 313      -
 314      -
 315  350      Element = AcpiGbl_GlobalList->ListHead;
      351 +    if (!Element)
      352 +    {
      353 +        return (NULL);
      354 +    }
 316  355  
 317      -    /* Search for the address. */
 318      -
 319      -    while (Element)
      356 +    /*
      357 +     * Search for the address.
      358 +     *
      359 +     * Note: List is ordered by larger-to-smaller addresses, on the
      360 +     * assumption that a new allocation usually has a larger address
      361 +     * than previous allocations.
      362 +     */
      363 +    while (Element > Allocation)
 320  364      {
 321      -        if (Element == Allocation)
      365 +        /* Check for end-of-list */
      366 +
      367 +        if (!Element->Next)
 322  368          {
 323  369              return (Element);
 324  370          }
 325  371  
 326  372          Element = Element->Next;
 327  373      }
 328  374  
 329      -    return (NULL);
      375 +    if (Element == Allocation)
      376 +    {
      377 +        return (Element);
      378 +    }
      379 +
      380 +    return (Element->Previous);
 330  381  }
 331  382  
 332  383  
 333  384  /*******************************************************************************
 334  385   *
 335  386   * FUNCTION:    AcpiUtTrackAllocation
 336  387   *
 337  388   * PARAMETERS:  Allocation          - Address of allocated memory
 338  389   *              Size                - Size of the allocation
 339  390   *              AllocType           - MEM_MALLOC or MEM_CALLOC
 340  391   *              Component           - Component type of caller
 341  392   *              Module              - Source file name of caller
 342  393   *              Line                - Line number of caller
 343  394   *
 344      - * RETURN:      None.
      395 + * RETURN:      Status
 345  396   *
 346  397   * DESCRIPTION: Inserts an element into the global allocation tracking list.
 347  398   *
 348  399   ******************************************************************************/
 349  400  
 350  401  static ACPI_STATUS
 351  402  AcpiUtTrackAllocation (
 352  403      ACPI_DEBUG_MEM_BLOCK    *Allocation,
 353  404      ACPI_SIZE               Size,
 354  405      UINT8                   AllocType,
↓ open down ↓ 15 lines elided ↑ open up ↑
 370  421      }
 371  422  
 372  423      MemList = AcpiGbl_GlobalList;
 373  424      Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
 374  425      if (ACPI_FAILURE (Status))
 375  426      {
 376  427          return_ACPI_STATUS (Status);
 377  428      }
 378  429  
 379  430      /*
 380      -     * Search list for this address to make sure it is not already on the list.
 381      -     * This will catch several kinds of problems.
      431 +     * Search the global list for this address to make sure it is not
      432 +     * already present. This will catch several kinds of problems.
 382  433       */
 383  434      Element = AcpiUtFindAllocation (Allocation);
 384      -    if (Element)
      435 +    if (Element == Allocation)
 385  436      {
 386  437          ACPI_ERROR ((AE_INFO,
 387      -            "UtTrackAllocation: Allocation already present in list! (%p)",
      438 +            "UtTrackAllocation: Allocation (%p) already present in global list!",
 388  439              Allocation));
 389      -
 390      -        ACPI_ERROR ((AE_INFO, "Element %p Address %p",
 391      -            Element, Allocation));
 392      -
 393  440          goto UnlockAndExit;
 394  441      }
 395  442  
 396      -    /* Fill in the instance data. */
      443 +    /* Fill in the instance data */
 397  444  
 398  445      Allocation->Size      = (UINT32) Size;
 399  446      Allocation->AllocType = AllocType;
 400  447      Allocation->Component = Component;
 401  448      Allocation->Line      = Line;
 402  449  
 403  450      ACPI_STRNCPY (Allocation->Module, Module, ACPI_MAX_MODULE_NAME);
 404  451      Allocation->Module[ACPI_MAX_MODULE_NAME-1] = 0;
 405  452  
 406      -    /* Insert at list head */
 407      -
 408      -    if (MemList->ListHead)
      453 +    if (!Element)
 409  454      {
 410      -        ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Allocation;
      455 +        /* Insert at list head */
      456 +
      457 +        if (MemList->ListHead)
      458 +        {
      459 +            ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Allocation;
      460 +        }
      461 +
      462 +        Allocation->Next = MemList->ListHead;
      463 +        Allocation->Previous = NULL;
      464 +
      465 +        MemList->ListHead = Allocation;
 411  466      }
      467 +    else
      468 +    {
      469 +        /* Insert after element */
 412  470  
 413      -    Allocation->Next = MemList->ListHead;
 414      -    Allocation->Previous = NULL;
      471 +        Allocation->Next = Element->Next;
      472 +        Allocation->Previous = Element;
 415  473  
 416      -    MemList->ListHead = Allocation;
      474 +        if (Element->Next)
      475 +        {
      476 +            (Element->Next)->Previous = Allocation;
      477 +        }
 417  478  
      479 +        Element->Next = Allocation;
      480 +    }
 418  481  
      482 +
 419  483  UnlockAndExit:
 420  484      Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
 421  485      return_ACPI_STATUS (Status);
 422  486  }
 423  487  
 424  488  
 425  489  /*******************************************************************************
 426  490   *
 427  491   * FUNCTION:    AcpiUtRemoveAllocation
 428  492   *
 429  493   * PARAMETERS:  Allocation          - Address of allocated memory
 430  494   *              Component           - Component type of caller
 431  495   *              Module              - Source file name of caller
 432  496   *              Line                - Line number of caller
 433  497   *
 434      - * RETURN:
      498 + * RETURN:      Status
 435  499   *
 436  500   * DESCRIPTION: Deletes an element from the global allocation tracking list.
 437  501   *
 438  502   ******************************************************************************/
 439  503  
 440  504  static ACPI_STATUS
 441  505  AcpiUtRemoveAllocation (
 442  506      ACPI_DEBUG_MEM_BLOCK    *Allocation,
 443  507      UINT32                  Component,
 444  508      const char              *Module,
 445  509      UINT32                  Line)
 446  510  {
 447  511      ACPI_MEMORY_LIST        *MemList;
 448  512      ACPI_STATUS             Status;
 449  513  
 450  514  
 451      -    ACPI_FUNCTION_TRACE (UtRemoveAllocation);
      515 +    ACPI_FUNCTION_NAME (UtRemoveAllocation);
 452  516  
 453  517  
 454  518      if (AcpiGbl_DisableMemTracking)
 455  519      {
 456      -        return_ACPI_STATUS (AE_OK);
      520 +        return (AE_OK);
 457  521      }
 458  522  
 459  523      MemList = AcpiGbl_GlobalList;
 460  524      if (NULL == MemList->ListHead)
 461  525      {
 462  526          /* No allocations! */
 463  527  
 464  528          ACPI_ERROR ((Module, Line,
 465  529              "Empty allocation list, nothing to free!"));
 466  530  
 467      -        return_ACPI_STATUS (AE_OK);
      531 +        return (AE_OK);
 468  532      }
 469  533  
 470  534      Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
 471  535      if (ACPI_FAILURE (Status))
 472  536      {
 473      -        return_ACPI_STATUS (Status);
      537 +        return (Status);
 474  538      }
 475  539  
 476  540      /* Unlink */
 477  541  
 478  542      if (Allocation->Previous)
 479  543      {
 480  544          (Allocation->Previous)->Next = Allocation->Next;
 481  545      }
 482  546      else
 483  547      {
 484  548          MemList->ListHead = Allocation->Next;
 485  549      }
 486  550  
 487  551      if (Allocation->Next)
 488  552      {
 489  553          (Allocation->Next)->Previous = Allocation->Previous;
 490  554      }
 491  555  
      556 +    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing %p, size 0%X\n",
      557 +        &Allocation->UserSpace, Allocation->Size));
      558 +
 492  559      /* Mark the segment as deleted */
 493  560  
 494  561      ACPI_MEMSET (&Allocation->UserSpace, 0xEA, Allocation->Size);
 495  562  
 496      -    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n",
 497      -        Allocation->Size));
 498      -
 499  563      Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
 500      -    return_ACPI_STATUS (Status);
      564 +    return (Status);
 501  565  }
 502  566  
 503  567  
 504  568  /*******************************************************************************
 505  569   *
 506  570   * FUNCTION:    AcpiUtDumpAllocationInfo
 507  571   *
 508      - * PARAMETERS:
      572 + * PARAMETERS:  None
 509  573   *
 510  574   * RETURN:      None
 511  575   *
 512  576   * DESCRIPTION: Print some info about the outstanding allocations.
 513  577   *
 514  578   ******************************************************************************/
 515  579  
 516  580  void
 517  581  AcpiUtDumpAllocationInfo (
 518  582      void)
↓ open down ↓ 40 lines elided ↑ open up ↑
 559  623  */
 560  624      return_VOID;
 561  625  }
 562  626  
 563  627  
 564  628  /*******************************************************************************
 565  629   *
 566  630   * FUNCTION:    AcpiUtDumpAllocations
 567  631   *
 568  632   * PARAMETERS:  Component           - Component(s) to dump info for.
 569      - *              Module              - Module to dump info for.  NULL means all.
      633 + *              Module              - Module to dump info for. NULL means all.
 570  634   *
 571  635   * RETURN:      None
 572  636   *
 573  637   * DESCRIPTION: Print a list of all outstanding allocations.
 574  638   *
 575  639   ******************************************************************************/
 576  640  
 577  641  void
 578  642  AcpiUtDumpAllocations (
 579  643      UINT32                  Component,
↓ open down ↓ 3 lines elided ↑ open up ↑
 583  647      ACPI_DESCRIPTOR         *Descriptor;
 584  648      UINT32                  NumOutstanding = 0;
 585  649      UINT8                   DescriptorType;
 586  650  
 587  651  
 588  652      ACPI_FUNCTION_TRACE (UtDumpAllocations);
 589  653  
 590  654  
 591  655      if (AcpiGbl_DisableMemTracking)
 592  656      {
 593      -        return;
      657 +        return_VOID;
 594  658      }
 595  659  
 596  660      /*
 597  661       * Walk the allocation list.
 598  662       */
 599  663      if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY)))
 600  664      {
 601      -        return;
      665 +        return_VOID;
 602  666      }
 603  667  
 604  668      Element = AcpiGbl_GlobalList->ListHead;
 605  669      while (Element)
 606  670      {
 607  671          if ((Element->Component & Component) &&
 608  672              ((Module == NULL) || (0 == ACPI_STRCMP (Module, Element->Module))))
 609  673          {
 610  674              Descriptor = ACPI_CAST_PTR (ACPI_DESCRIPTOR, &Element->UserSpace);
 611  675  
↓ open down ↓ 14 lines elided ↑ open up ↑
 626  690                          Descriptor, Element->Size, Element->Module,
 627  691                          Element->Line, AcpiUtGetDescriptorName (Descriptor));
 628  692  
 629  693                      /* Validate the descriptor type using Type field and length */
 630  694  
 631  695                      DescriptorType = 0; /* Not a valid descriptor type */
 632  696  
 633  697                      switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
 634  698                      {
 635  699                      case ACPI_DESC_TYPE_OPERAND:
 636      -                        if (Element->Size == sizeof (ACPI_DESC_TYPE_OPERAND))
      700 +
      701 +                        if (Element->Size == sizeof (ACPI_OPERAND_OBJECT))
 637  702                          {
 638  703                              DescriptorType = ACPI_DESC_TYPE_OPERAND;
 639  704                          }
 640  705                          break;
 641  706  
 642  707                      case ACPI_DESC_TYPE_PARSER:
 643      -                        if (Element->Size == sizeof (ACPI_DESC_TYPE_PARSER))
      708 +
      709 +                        if (Element->Size == sizeof (ACPI_PARSE_OBJECT))
 644  710                          {
 645  711                              DescriptorType = ACPI_DESC_TYPE_PARSER;
 646  712                          }
 647  713                          break;
 648  714  
 649  715                      case ACPI_DESC_TYPE_NAMED:
 650      -                        if (Element->Size == sizeof (ACPI_DESC_TYPE_NAMED))
      716 +
      717 +                        if (Element->Size == sizeof (ACPI_NAMESPACE_NODE))
 651  718                          {
 652  719                              DescriptorType = ACPI_DESC_TYPE_NAMED;
 653  720                          }
 654  721                          break;
 655  722  
 656  723                      default:
      724 +
 657  725                          break;
 658  726                      }
 659  727  
 660  728                      /* Display additional info for the major descriptor types */
 661  729  
 662  730                      switch (DescriptorType)
 663  731                      {
 664  732                      case ACPI_DESC_TYPE_OPERAND:
      733 +
 665  734                          AcpiOsPrintf ("%12.12s  RefCount 0x%04X\n",
 666  735                              AcpiUtGetTypeName (Descriptor->Object.Common.Type),
 667  736                              Descriptor->Object.Common.ReferenceCount);
 668  737                          break;
 669  738  
 670  739                      case ACPI_DESC_TYPE_PARSER:
      740 +
 671  741                          AcpiOsPrintf ("AmlOpcode 0x%04hX\n",
 672  742                              Descriptor->Op.Asl.AmlOpcode);
 673  743                          break;
 674  744  
 675  745                      case ACPI_DESC_TYPE_NAMED:
      746 +
 676  747                          AcpiOsPrintf ("%4.4s\n",
 677  748                              AcpiUtGetNodeName (&Descriptor->Node));
 678  749                          break;
 679  750  
 680  751                      default:
      752 +
 681  753                          AcpiOsPrintf ( "\n");
 682  754                          break;
 683  755                      }
 684  756                  }
 685  757              }
 686  758  
 687  759              NumOutstanding++;
 688  760          }
 689  761  
 690  762          Element = Element->Next;
↓ open down ↓ 10 lines elided ↑ open up ↑
 701  773      else
 702  774      {
 703  775          ACPI_ERROR ((AE_INFO, "%u(0x%X) Outstanding allocations",
 704  776              NumOutstanding, NumOutstanding));
 705  777      }
 706  778  
 707  779      return_VOID;
 708  780  }
 709  781  
 710  782  #endif  /* ACPI_DBG_TRACK_ALLOCATIONS */
 711      -
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX