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

exnames.c
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003  *
00004  * Module Name: exnames - interpreter/scanner name load/execute
00005  *
00006  *****************************************************************************/
00007 
00008 /******************************************************************************
00009  *
00010  * 1. Copyright Notice
00011  *
00012  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00013  * All rights reserved.
00014  *
00015  * 2. License
00016  *
00017  * 2.1. This is your license from Intel Corp. under its intellectual property
00018  * rights.  You may have additional license terms from the party that provided
00019  * you this software, covering your right to use that party's intellectual
00020  * property rights.
00021  *
00022  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00023  * copy of the source code appearing in this file ("Covered Code") an
00024  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00025  * base code distributed originally by Intel ("Original Intel Code") to copy,
00026  * make derivatives, distribute, use and display any portion of the Covered
00027  * Code in any form, with the right to sublicense such rights; and
00028  *
00029  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00030  * license (with the right to sublicense), under only those claims of Intel
00031  * patents that are infringed by the Original Intel Code, to make, use, sell,
00032  * offer to sell, and import the Covered Code and derivative works thereof
00033  * solely to the minimum extent necessary to exercise the above copyright
00034  * license, and in no event shall the patent license extend to any additions
00035  * to or modifications of the Original Intel Code.  No other license or right
00036  * is granted directly or by implication, estoppel or otherwise;
00037  *
00038  * The above copyright and patent license is granted only if the following
00039  * conditions are met:
00040  *
00041  * 3. Conditions
00042  *
00043  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00044  * Redistribution of source code of any substantial portion of the Covered
00045  * Code or modification with rights to further distribute source must include
00046  * the above Copyright Notice, the above License, this list of Conditions,
00047  * and the following Disclaimer and Export Compliance provision.  In addition,
00048  * Licensee must cause all Covered Code to which Licensee contributes to
00049  * contain a file documenting the changes Licensee made to create that Covered
00050  * Code and the date of any change.  Licensee must include in that file the
00051  * documentation of any changes made by any predecessor Licensee.  Licensee
00052  * must include a prominent statement that the modification is derived,
00053  * directly or indirectly, from Original Intel Code.
00054  *
00055  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00056  * Redistribution of source code of any substantial portion of the Covered
00057  * Code or modification without rights to further distribute source must
00058  * include the following Disclaimer and Export Compliance provision in the
00059  * documentation and/or other materials provided with distribution.  In
00060  * addition, Licensee may not authorize further sublicense of source of any
00061  * portion of the Covered Code, and must include terms to the effect that the
00062  * license from Licensee to its licensee is limited to the intellectual
00063  * property embodied in the software Licensee provides to its licensee, and
00064  * not to intellectual property embodied in modifications its licensee may
00065  * make.
00066  *
00067  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00068  * substantial portion of the Covered Code or modification must reproduce the
00069  * above Copyright Notice, and the following Disclaimer and Export Compliance
00070  * provision in the documentation and/or other materials provided with the
00071  * distribution.
00072  *
00073  * 3.4. Intel retains all right, title, and interest in and to the Original
00074  * Intel Code.
00075  *
00076  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00077  * Intel shall be used in advertising or otherwise to promote the sale, use or
00078  * other dealings in products derived from or relating to the Covered Code
00079  * without prior written authorization from Intel.
00080  *
00081  * 4. Disclaimer and Export Compliance
00082  *
00083  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00084  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00085  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00086  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00087  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00088  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00089  * PARTICULAR PURPOSE.
00090  *
00091  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00092  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00093  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00094  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00095  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00096  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00097  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00098  * LIMITED REMEDY.
00099  *
00100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00101  * software or system incorporating such software without first obtaining any
00102  * required license or other approval from the U. S. Department of Commerce or
00103  * any other agency or department of the United States Government.  In the
00104  * event Licensee exports any such software from the United States or
00105  * re-exports any such software from a foreign destination, Licensee shall
00106  * ensure that the distribution and export/re-export of the software is in
00107  * compliance with all laws, regulations, orders, or other restrictions of the
00108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00109  * any of its subsidiaries will export/re-export any technical data, process,
00110  * software, or service, directly or indirectly, to any country for which the
00111  * United States government or any agency thereof requires an export license,
00112  * other governmental approval, or letter of assurance, without first obtaining
00113  * such license, approval or letter.
00114  *
00115  *****************************************************************************/
00116 
00117 #define __EXNAMES_C__
00118 
00119 #include "acpi.h"
00120 #include "accommon.h"
00121 #include "acinterp.h"
00122 #include "amlcode.h"
00123 
00124 #define _COMPONENT          ACPI_EXECUTER
00125         ACPI_MODULE_NAME    ("exnames")
00126 
00127 /* Local prototypes */
00128 
00129 static char *
00130 AcpiExAllocateNameString (
00131     UINT32                  PrefixCount,
00132     UINT32                  NumNameSegs);
00133 
00134 static ACPI_STATUS
00135 AcpiExNameSegment (
00136     UINT8                   **InAmlAddress,
00137     char                    *NameString);
00138 
00139 
00140 /*******************************************************************************
00141  *
00142  * FUNCTION:    AcpiExAllocateNameString
00143  *
00144  * PARAMETERS:  PrefixCount         - Count of parent levels. Special cases:
00145  *                                    (-1)==root,  0==none
00146  *              NumNameSegs         - count of 4-character name segments
00147  *
00148  * RETURN:      A pointer to the allocated string segment.  This segment must
00149  *              be deleted by the caller.
00150  *
00151  * DESCRIPTION: Allocate a buffer for a name string. Ensure allocated name
00152  *              string is long enough, and set up prefix if any.
00153  *
00154  ******************************************************************************/
00155 
00156 static char *
00157 AcpiExAllocateNameString (
00158     UINT32                  PrefixCount,
00159     UINT32                  NumNameSegs)
00160 {
00161     char                    *TempPtr;
00162     char                    *NameString;
00163     UINT32                   SizeNeeded;
00164 
00165     ACPI_FUNCTION_TRACE (ExAllocateNameString);
00166 
00167 
00168     /*
00169      * Allow room for all \ and ^ prefixes, all segments and a MultiNamePrefix.
00170      * Also, one byte for the null terminator.
00171      * This may actually be somewhat longer than needed.
00172      */
00173     if (PrefixCount == ACPI_UINT32_MAX)
00174     {
00175         /* Special case for root */
00176 
00177         SizeNeeded = 1 + (ACPI_NAME_SIZE * NumNameSegs) + 2 + 1;
00178     }
00179     else
00180     {
00181         SizeNeeded = PrefixCount + (ACPI_NAME_SIZE * NumNameSegs) + 2 + 1;
00182     }
00183 
00184     /*
00185      * Allocate a buffer for the name.
00186      * This buffer must be deleted by the caller!
00187      */
00188     NameString = ACPI_ALLOCATE (SizeNeeded);
00189     if (!NameString)
00190     {
00191         ACPI_ERROR ((AE_INFO,
00192             "Could not allocate size %u", SizeNeeded));
00193         return_PTR (NULL);
00194     }
00195 
00196     TempPtr = NameString;
00197 
00198     /* Set up Root or Parent prefixes if needed */
00199 
00200     if (PrefixCount == ACPI_UINT32_MAX)
00201     {
00202         *TempPtr++ = AML_ROOT_PREFIX;
00203     }
00204     else
00205     {
00206         while (PrefixCount--)
00207         {
00208             *TempPtr++ = AML_PARENT_PREFIX;
00209         }
00210     }
00211 
00212 
00213     /* Set up Dual or Multi prefixes if needed */
00214 
00215     if (NumNameSegs > 2)
00216     {
00217         /* Set up multi prefixes   */
00218 
00219         *TempPtr++ = AML_MULTI_NAME_PREFIX_OP;
00220         *TempPtr++ = (char) NumNameSegs;
00221     }
00222     else if (2 == NumNameSegs)
00223     {
00224         /* Set up dual prefixes */
00225 
00226         *TempPtr++ = AML_DUAL_NAME_PREFIX;
00227     }
00228 
00229     /*
00230      * Terminate string following prefixes. AcpiExNameSegment() will
00231      * append the segment(s)
00232      */
00233     *TempPtr = 0;
00234 
00235     return_PTR (NameString);
00236 }
00237 
00238 /*******************************************************************************
00239  *
00240  * FUNCTION:    AcpiExNameSegment
00241  *
00242  * PARAMETERS:  InAmlAddress    - Pointer to the name in the AML code
00243  *              NameString      - Where to return the name. The name is appended
00244  *                                to any existing string to form a namepath
00245  *
00246  * RETURN:      Status
00247  *
00248  * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream
00249  *
00250  ******************************************************************************/
00251 
00252 static ACPI_STATUS
00253 AcpiExNameSegment (
00254     UINT8                   **InAmlAddress,
00255     char                    *NameString)
00256 {
00257     char                    *AmlAddress = (void *) *InAmlAddress;
00258     ACPI_STATUS             Status = AE_OK;
00259     UINT32                  Index;
00260     char                    CharBuf[5];
00261 
00262 
00263     ACPI_FUNCTION_TRACE (ExNameSegment);
00264 
00265 
00266     /*
00267      * If first character is a digit, then we know that we aren't looking at a
00268      * valid name segment
00269      */
00270     CharBuf[0] = *AmlAddress;
00271 
00272     if ('0' <= CharBuf[0] && CharBuf[0] <= '9')
00273     {
00274         ACPI_ERROR ((AE_INFO, "Invalid leading digit: %c", CharBuf[0]));
00275         return_ACPI_STATUS (AE_CTRL_PENDING);
00276     }
00277 
00278     ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "Bytes from stream:\n"));
00279 
00280     for (Index = 0;
00281         (Index < ACPI_NAME_SIZE) && (AcpiUtValidAcpiChar (*AmlAddress, 0));
00282         Index++)
00283     {
00284         CharBuf[Index] = *AmlAddress++;
00285         ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "%c\n", CharBuf[Index]));
00286     }
00287 
00288 
00289     /* Valid name segment  */
00290 
00291     if (Index == 4)
00292     {
00293         /* Found 4 valid characters */
00294 
00295         CharBuf[4] = '\0';
00296 
00297         if (NameString)
00298         {
00299             ACPI_STRCAT (NameString, CharBuf);
00300             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
00301                 "Appended to - %s\n", NameString));
00302         }
00303         else
00304         {
00305             ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
00306                 "No Name string - %s\n", CharBuf));
00307         }
00308     }
00309     else if (Index == 0)
00310     {
00311         /*
00312          * First character was not a valid name character,
00313          * so we are looking at something other than a name.
00314          */
00315         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
00316             "Leading character is not alpha: %02Xh (not a name)\n",
00317             CharBuf[0]));
00318         Status = AE_CTRL_PENDING;
00319     }
00320     else
00321     {
00322         /*
00323          * Segment started with one or more valid characters, but fewer than
00324          * the required 4
00325          */
00326         Status = AE_AML_BAD_NAME;
00327         ACPI_ERROR ((AE_INFO,
00328             "Bad character 0x%02x in name, at %p",
00329             *AmlAddress, AmlAddress));
00330     }
00331 
00332     *InAmlAddress = ACPI_CAST_PTR (UINT8, AmlAddress);
00333     return_ACPI_STATUS (Status);
00334 }
00335 
00336 
00337 /*******************************************************************************
00338  *
00339  * FUNCTION:    AcpiExGetNameString
00340  *
00341  * PARAMETERS:  DataType            - Object type to be associated with this
00342  *                                    name
00343  *              InAmlAddress        - Pointer to the namestring in the AML code
00344  *              OutNameString       - Where the namestring is returned
00345  *              OutNameLength       - Length of the returned string
00346  *
00347  * RETURN:      Status, namestring and length
00348  *
00349  * DESCRIPTION: Extract a full namepath from the AML byte stream,
00350  *              including any prefixes.
00351  *
00352  ******************************************************************************/
00353 
00354 ACPI_STATUS
00355 AcpiExGetNameString (
00356     ACPI_OBJECT_TYPE        DataType,
00357     UINT8                   *InAmlAddress,
00358     char                    **OutNameString,
00359     UINT32                  *OutNameLength)
00360 {
00361     ACPI_STATUS             Status = AE_OK;
00362     UINT8                   *AmlAddress = InAmlAddress;
00363     char                    *NameString = NULL;
00364     UINT32                  NumSegments;
00365     UINT32                  PrefixCount = 0;
00366     BOOLEAN                 HasPrefix = FALSE;
00367 
00368 
00369     ACPI_FUNCTION_TRACE_PTR (ExGetNameString, AmlAddress);
00370 
00371 
00372     if (ACPI_TYPE_LOCAL_REGION_FIELD == DataType   ||
00373         ACPI_TYPE_LOCAL_BANK_FIELD == DataType     ||
00374         ACPI_TYPE_LOCAL_INDEX_FIELD == DataType)
00375     {
00376         /* Disallow prefixes for types associated with FieldUnit names */
00377 
00378         NameString = AcpiExAllocateNameString (0, 1);
00379         if (!NameString)
00380         {
00381             Status = AE_NO_MEMORY;
00382         }
00383         else
00384         {
00385             Status = AcpiExNameSegment (&AmlAddress, NameString);
00386         }
00387     }
00388     else
00389     {
00390         /*
00391          * DataType is not a field name.
00392          * Examine first character of name for root or parent prefix operators
00393          */
00394         switch (*AmlAddress)
00395         {
00396         case AML_ROOT_PREFIX:
00397 
00398             ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "RootPrefix(\\) at %p\n",
00399                 AmlAddress));
00400 
00401             /*
00402              * Remember that we have a RootPrefix --
00403              * see comment in AcpiExAllocateNameString()
00404              */
00405             AmlAddress++;
00406             PrefixCount = ACPI_UINT32_MAX;
00407             HasPrefix = TRUE;
00408             break;
00409 
00410 
00411         case AML_PARENT_PREFIX:
00412 
00413             /* Increment past possibly multiple parent prefixes */
00414 
00415             do
00416             {
00417                 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "ParentPrefix (^) at %p\n",
00418                     AmlAddress));
00419 
00420                 AmlAddress++;
00421                 PrefixCount++;
00422 
00423             } while (*AmlAddress == AML_PARENT_PREFIX);
00424 
00425             HasPrefix = TRUE;
00426             break;
00427 
00428 
00429         default:
00430 
00431             /* Not a prefix character */
00432 
00433             break;
00434         }
00435 
00436         /* Examine first character of name for name segment prefix operator */
00437 
00438         switch (*AmlAddress)
00439         {
00440         case AML_DUAL_NAME_PREFIX:
00441 
00442             ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "DualNamePrefix at %p\n",
00443                 AmlAddress));
00444 
00445             AmlAddress++;
00446             NameString = AcpiExAllocateNameString (PrefixCount, 2);
00447             if (!NameString)
00448             {
00449                 Status = AE_NO_MEMORY;
00450                 break;
00451             }
00452 
00453             /* Indicate that we processed a prefix */
00454 
00455             HasPrefix = TRUE;
00456 
00457             Status = AcpiExNameSegment (&AmlAddress, NameString);
00458             if (ACPI_SUCCESS (Status))
00459             {
00460                 Status = AcpiExNameSegment (&AmlAddress, NameString);
00461             }
00462             break;
00463 
00464 
00465         case AML_MULTI_NAME_PREFIX_OP:
00466 
00467             ACPI_DEBUG_PRINT ((ACPI_DB_LOAD, "MultiNamePrefix at %p\n",
00468                 AmlAddress));
00469 
00470             /* Fetch count of segments remaining in name path */
00471 
00472             AmlAddress++;
00473             NumSegments = *AmlAddress;
00474 
00475             NameString = AcpiExAllocateNameString (PrefixCount, NumSegments);
00476             if (!NameString)
00477             {
00478                 Status = AE_NO_MEMORY;
00479                 break;
00480             }
00481 
00482             /* Indicate that we processed a prefix */
00483 
00484             AmlAddress++;
00485             HasPrefix = TRUE;
00486 
00487             while (NumSegments &&
00488                     (Status = AcpiExNameSegment (&AmlAddress, NameString)) ==
00489                         AE_OK)
00490             {
00491                 NumSegments--;
00492             }
00493 
00494             break;
00495 
00496 
00497         case 0:
00498 
00499             /* NullName valid as of 8-12-98 ASL/AML Grammar Update */
00500 
00501             if (PrefixCount == ACPI_UINT32_MAX)
00502             {
00503                 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
00504                     "NameSeg is \"\\\" followed by NULL\n"));
00505             }
00506 
00507             /* Consume the NULL byte */
00508 
00509             AmlAddress++;
00510             NameString = AcpiExAllocateNameString (PrefixCount, 0);
00511             if (!NameString)
00512             {
00513                 Status = AE_NO_MEMORY;
00514                 break;
00515             }
00516 
00517             break;
00518 
00519 
00520         default:
00521 
00522             /* Name segment string */
00523 
00524             NameString = AcpiExAllocateNameString (PrefixCount, 1);
00525             if (!NameString)
00526             {
00527                 Status = AE_NO_MEMORY;
00528                 break;
00529             }
00530 
00531             Status = AcpiExNameSegment (&AmlAddress, NameString);
00532             break;
00533         }
00534     }
00535 
00536     if (AE_CTRL_PENDING == Status && HasPrefix)
00537     {
00538         /* Ran out of segments after processing a prefix */
00539 
00540         ACPI_ERROR ((AE_INFO,
00541             "Malformed Name at %p", NameString));
00542         Status = AE_AML_BAD_NAME;
00543     }
00544 
00545     if (ACPI_FAILURE (Status))
00546     {
00547         if (NameString)
00548         {
00549             ACPI_FREE (NameString);
00550         }
00551         return_ACPI_STATUS (Status);
00552     }
00553 
00554     *OutNameString = NameString;
00555     *OutNameLength = (UINT32) (AmlAddress - InAmlAddress);
00556 
00557     return_ACPI_STATUS (Status);
00558 }
00559 
00560 

Generated on Sat May 26 2012 04:25:47 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.