⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aslanalyze.c

📁 acpi tools for linux include acpiexec and acpixtract
💻 C
📖 第 1 页 / 共 5 页
字号:
        if ((!AnLastStatementIsReturn (Op)) &&            (!(Op->Asl.CompileFlags & NODE_HAS_NO_EXIT)))        {            /*             * No return statement, and execution can possibly exit             * via this path. This is equivalent to Return ()             */            MethodInfo->NumReturnNoValue++;        }        /*         * Check for case where some return statements have a return value         * and some do not. Exit without a return statement is a return with         * no value         */        if (MethodInfo->NumReturnNoValue &&            MethodInfo->NumReturnWithValue)        {            AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op,                Op->Asl.ExternalName);        }        /*         * If there are any RETURN() statements with no value, or there is a         * control path that allows the method to exit without a return value,         * we mark the method as a method that does not return a value. This         * knowledge can be used to check method invocations that expect a         * returned value.         */        if (MethodInfo->NumReturnNoValue)        {            if (MethodInfo->NumReturnWithValue)            {                Op->Asl.CompileFlags |= NODE_METHOD_SOME_NO_RETVAL;            }            else            {                Op->Asl.CompileFlags |= NODE_METHOD_NO_RETVAL;            }        }        /*         * Check predefined method names for correct return behavior         * and correct number of arguments         */        AnCheckForReservedMethod (Op, MethodInfo);        ACPI_FREE (MethodInfo);        break;    case PARSEOP_RETURN:        /*         * The parent block does not "exit" and continue execution -- the         * method is terminated here with the Return() statement.         */        Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;        /* Used in the "typing" pass later */        Op->Asl.ParentMethod = MethodInfo->Op;        /*         * If there is a peer node after the return statement, then this         * node is unreachable code -- i.e., it won't be executed because of         * the preceeding Return() statement.         */        if (Op->Asl.Next)        {            AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE, Op->Asl.Next, NULL);        }        break;    case PARSEOP_IF:        if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&            (Op->Asl.Next) &&            (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE))        {            /*             * This IF has a corresponding ELSE. The IF block has no exit,             * (it contains an unconditional Return)             * mark the ELSE block to remember this fact.             */            Op->Asl.Next->Asl.CompileFlags |= NODE_IF_HAS_NO_EXIT;        }        break;    case PARSEOP_ELSE:        if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&            (Op->Asl.CompileFlags & NODE_IF_HAS_NO_EXIT))        {            /*             * This ELSE block has no exit and the corresponding IF block             * has no exit either. Therefore, the parent node has no exit.             */            Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;        }        break;    default:        if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) &&            (Op->Asl.Parent))        {            /* If this node has no exit, then the parent has no exit either */            Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT;        }        break;    }    return AE_OK;}/******************************************************************************* * * FUNCTION:    AnMethodTypingWalkBegin * * PARAMETERS:  ASL_WALK_CALLBACK * * RETURN:      Status * * DESCRIPTION: Descending callback for the typing walk. * ******************************************************************************/ACPI_STATUSAnMethodTypingWalkBegin (    ACPI_PARSE_OBJECT       *Op,    UINT32                  Level,    void                    *Context){    return AE_OK;}/******************************************************************************* * * FUNCTION:    AnMethodTypingWalkEnd * * PARAMETERS:  ASL_WALK_CALLBACK * * RETURN:      Status * * DESCRIPTION: Ascending callback for typing walk. Complete the method *              return analysis. Check methods for: *              1) Initialized local variables *              2) Valid arguments *              3) Return types * ******************************************************************************/ACPI_STATUSAnMethodTypingWalkEnd (    ACPI_PARSE_OBJECT       *Op,    UINT32                  Level,    void                    *Context){    UINT32                  ThisNodeBtype;    switch (Op->Asl.ParseOpcode)    {    case PARSEOP_METHOD:        Op->Asl.CompileFlags |= NODE_METHOD_TYPED;        break;    case PARSEOP_RETURN:        if ((Op->Asl.Child) &&            (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG))        {            ThisNodeBtype = AnGetBtype (Op->Asl.Child);            if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) &&                (ThisNodeBtype == (ACPI_UINT32_MAX -1)))            {                /*                 * The called method is untyped at this time (typically a                 * forward reference).                 *                 * Check for a recursive method call first.                 */                if (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op)                {                    /* We must type the method here */                    TrWalkParseTree (Op->Asl.Child->Asl.Node->Op,                        ASL_WALK_VISIT_TWICE, AnMethodTypingWalkBegin,                        AnMethodTypingWalkEnd, NULL);                    ThisNodeBtype = AnGetBtype (Op->Asl.Child);                }            }            /* Returns a value, save the value type */            if (Op->Asl.ParentMethod)            {                Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisNodeBtype;            }        }        break;    default:        break;    }    return AE_OK;}/******************************************************************************* * * FUNCTION:    AnCheckMethodReturnValue * * PARAMETERS:  Op                  - Parent *              OpInfo              - Parent info *              ArgOp               - Method invocation op *              RequiredBtypes      - What caller requires *              ThisNodeBtype       - What this node returns (if anything) * * RETURN:      None * * DESCRIPTION: Check a method invocation for 1) A return value and if it does *              in fact return a value, 2) check the type of the return value. * ******************************************************************************/static voidAnCheckMethodReturnValue (    ACPI_PARSE_OBJECT       *Op,    const ACPI_OPCODE_INFO  *OpInfo,    ACPI_PARSE_OBJECT       *ArgOp,    UINT32                  RequiredBtypes,    UINT32                  ThisNodeBtype){    ACPI_PARSE_OBJECT       *OwningOp;    ACPI_NAMESPACE_NODE     *Node;    Node = ArgOp->Asl.Node;    /* Examine the parent op of this method */    OwningOp = Node->Op;    if (OwningOp->Asl.CompileFlags & NODE_METHOD_NO_RETVAL)    {        /* Method NEVER returns a value */        AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, Op->Asl.ExternalName);    }    else if (OwningOp->Asl.CompileFlags & NODE_METHOD_SOME_NO_RETVAL)    {        /* Method SOMETIMES returns a value, SOMETIMES not */        AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL, Op, Op->Asl.ExternalName);    }    else if (!(ThisNodeBtype & RequiredBtypes))    {        /* Method returns a value, but the type is wrong */        AnFormatBtype (StringBuffer, ThisNodeBtype);        AnFormatBtype (StringBuffer2, RequiredBtypes);        /*         * The case where the method does not return any value at all         * was already handled in the namespace cross reference         * -- Only issue an error if the method in fact returns a value,         * but it is of the wrong type         */        if (ThisNodeBtype != 0)        {            sprintf (MsgBuffer,                "Method returns [%s], %s operator requires [%s]",                StringBuffer, OpInfo->Name, StringBuffer2);            AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer);        }    }}/******************************************************************************* * * FUNCTION:    AnOperandTypecheckWalkBegin * * PARAMETERS:  ASL_WALK_CALLBACK * * RETURN:      Status * * DESCRIPTION: Descending callback for the analysis walk. Check methods for: *              1) Initialized local variables *              2) Valid arguments *              3) Return types * ******************************************************************************/ACPI_STATUSAnOperandTypecheckWalkBegin (    ACPI_PARSE_OBJECT       *Op,    UINT32                  Level,    void                    *Context){    return AE_OK;}/******************************************************************************* * * FUNCTION:    AnOperandTypecheckWalkEnd * * PARAMETERS:  ASL_WALK_CALLBACK * * RETURN:      Status * * DESCRIPTION: Ascending callback for analysis walk. Complete method *              return analysis. * ******************************************************************************/ACPI_STATUSAnOperandTypecheckWalkEnd (    ACPI_PARSE_OBJECT       *Op,    UINT32                  Level,    void                    *Context){    const ACPI_OPCODE_INFO  *OpInfo;    UINT32                  RuntimeArgTypes;    UINT32                  RuntimeArgTypes2;    UINT32                  RequiredBtypes;    UINT32                  ThisNodeBtype;    UINT32                  CommonBtypes;    UINT32                  OpcodeClass;    ACPI_PARSE_OBJECT       *ArgOp;    UINT32                  ArgType;    switch (Op->Asl.AmlOpcode)    {    case AML_RAW_DATA_BYTE:    case AML_RAW_DATA_WORD:    case AML_RAW_DATA_DWORD:    case AML_RAW_DATA_QWORD:    case AML_RAW_DATA_BUFFER:    case AML_RAW_DATA_CHAIN:    case AML_PACKAGE_LENGTH:    case AML_UNASSIGNED_OPCODE:    case AML_DEFAULT_ARG_OP:        /* Ignore the internal (compiler-only) AML opcodes */        return (AE_OK);    default:        break;    }    OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);    if (!OpInfo)    {        return (AE_OK);    }    ArgOp           = Op->Asl.Child;    RuntimeArgTypes = OpInfo->RuntimeArgs;    OpcodeClass     = OpInfo->Class;    /*     * Special case for control opcodes IF/RETURN/WHILE since they     * have no runtime arg list (at this time)     */    switch (Op->Asl.AmlOpcode)    {    case AML_IF_OP:    case AML_WHILE_OP:    case AML_RETURN_OP:        if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL)        {            /* Check for an internal method */            if (AnIsInternalMethod (ArgOp))            {                return (AE_OK);            }            /* The lone arg is a method call, check it */            RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER);            if (Op->Asl.AmlOpcode == AML_RETURN_OP)            {                RequiredBtypes = 0xFFFFFFFF;            }            ThisNodeBtype = AnGetBtype (ArgOp);            if (ThisNodeBtype == ACPI_UINT32_MAX)            {                return (AE_OK);            }            AnCheckMethodReturnValue (Op, OpInfo, ArgOp,                RequiredBtypes, ThisNodeBtype);        }        return (AE_OK);    default:        break;    }    /* Ignore the non-executable opcodes */    if (RuntimeArgTypes == ARGI_INVALID_OPCODE)    {        return (AE_OK);    }    switch (OpcodeClass)    {    case AML_CLASS_EXECUTE:    case AML_CLASS_CREATE:    case AML_CLASS_CONTROL:    case AML_CLASS_RETURN_VALUE:        /* TBD: Change class or fix typechecking for these */        if ((Op->Asl.AmlOpcode == AML_BUFFER_OP)        ||            (Op->Asl.AmlOpcode == AML_PACKAGE_OP)       ||            (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP))        {            break;        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -