## @file\r
# This file is used to define checkpoints used by ECC tool\r
#\r
-# Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
# which accompanies this distribution. The full text of the license may be found at\r
import EccGlobalData\r
import c\r
from Common.LongFilePathSupport import OpenLongFilePath as open\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
\r
## Check\r
#\r
self.DeclAndDataTypeCheck()\r
self.FunctionLayoutCheck()\r
self.NamingConventionCheck()\r
+ self.SmmCommParaCheck()\r
+\r
+ def SmmCommParaCheck(self):\r
+ self.SmmCommParaCheckBufferType()\r
+\r
+\r
+ # Check if SMM communication function has correct parameter type\r
+ # 1. Get function calling with instance./->Communicate() interface\r
+ # and make sure the protocol instance is of type EFI_SMM_COMMUNICATION_PROTOCOL.\r
+ # 2. Find the origin of the 2nd parameter of Communicate() interface, if -\r
+ # a. it is a local buffer on stack\r
+ # report error.\r
+ # b. it is a global buffer, check the driver that holds the global buffer is of type DXE_RUNTIME_DRIVER\r
+ # report success.\r
+ # c. it is a buffer by AllocatePage/AllocatePool (may be wrapped by nested function calls),\r
+ # check the EFI_MEMORY_TYPE to be EfiRuntimeServicesCode,EfiRuntimeServicesData,\r
+ # EfiACPIMemoryNVS or EfiReservedMemoryType\r
+ # report success.\r
+ # d. it is a buffer located via EFI_SYSTEM_TABLE.ConfigurationTable (may be wrapped by nested function calls)\r
+ # report warning to indicate human code review.\r
+ # e. it is a buffer from other kind of pointers (may need to trace into nested function calls to locate),\r
+ # repeat checks in a.b.c and d.\r
+ def SmmCommParaCheckBufferType(self):\r
+ if EccGlobalData.gConfig.SmmCommParaCheckBufferType == '1' or EccGlobalData.gConfig.SmmCommParaCheckAll == '1':\r
+ EdkLogger.quiet("Checking SMM communication parameter type ...")\r
+ # Get all EFI_SMM_COMMUNICATION_PROTOCOL interface\r
+ CommApiList = []\r
+ for IdentifierTable in EccGlobalData.gIdentifierTableList:\r
+ SqlCommand = """select ID, Name, BelongsToFile from %s\r
+ where Modifier = 'EFI_SMM_COMMUNICATION_PROTOCOL*' """ % (IdentifierTable)\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ if RecordSet:\r
+ for Record in RecordSet:\r
+ if Record[1] not in CommApiList:\r
+ CommApiList.append(Record[1])\r
+ # For each interface, check the second parameter\r
+ for CommApi in CommApiList:\r
+ for IdentifierTable in EccGlobalData.gIdentifierTableList:\r
+ SqlCommand = """select ID, Name, Value, BelongsToFile, StartLine from %s\r
+ where Name = '%s->Communicate' and Model = %s""" \\r
+ % (IdentifierTable, CommApi, MODEL_IDENTIFIER_FUNCTION_CALLING)\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ if RecordSet:\r
+ # print IdentifierTable\r
+ for Record in RecordSet:\r
+ # Get the second parameter for Communicate function\r
+ SecondPara = Record[2].split(',')[1].strip()\r
+ SecondParaIndex = None\r
+ if SecondPara.startswith('&'):\r
+ SecondPara = SecondPara[1:]\r
+ if SecondPara.endswith(']'):\r
+ SecondParaIndex = SecondPara[SecondPara.find('[') + 1:-1]\r
+ SecondPara = SecondPara[:SecondPara.find('[')]\r
+ # Get the ID\r
+ Id = Record[0]\r
+ # Get the BelongsToFile\r
+ BelongsToFile = Record[3]\r
+ # Get the source file path\r
+ SqlCommand = """select FullPath from File where ID = %s""" % BelongsToFile\r
+ NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ FullPath = NewRecordSet[0][0]\r
+ # Get the line no of function calling\r
+ StartLine = Record[4]\r
+ # Get the module type\r
+ SqlCommand = """select Value3 from INF where BelongsToFile = (select ID from File\r
+ where Path = (select Path from File where ID = %s) and Model = 1011)\r
+ and Value2 = 'MODULE_TYPE'""" % BelongsToFile\r
+ NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ ModuleType = NewRecordSet[0][0] if NewRecordSet else None\r
+\r
+ # print BelongsToFile, FullPath, StartLine, ModuleType, SecondPara\r
+\r
+ Value = FindPara(FullPath, SecondPara, StartLine)\r
+ # Find the value of the parameter\r
+ if Value:\r
+ if 'AllocatePage' in Value \\r
+ or 'AllocatePool' in Value \\r
+ or 'AllocateRuntimePool' in Value \\r
+ or 'AllocateZeroPool' in Value:\r
+ pass\r
+ else:\r
+ if '->' in Value:\r
+ if not EccGlobalData.gException.IsException(\r
+ ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE,\r
+ OtherMsg="Please review the buffer type"\r
+ + "is correct or not. If it is correct" +\r
+ " please add [%s] to exception list"\r
+ % Value,\r
+ BelongsToTable=IdentifierTable,\r
+ BelongsToItem=Id)\r
+ else:\r
+ if not EccGlobalData.gException.IsException(\r
+ ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE,\r
+ OtherMsg="Please review the buffer type"\r
+ + "is correct or not. If it is correct" +\r
+ " please add [%s] to exception list"\r
+ % Value,\r
+ BelongsToTable=IdentifierTable,\r
+ BelongsToItem=Id)\r
+\r
+\r
+ # Not find the value of the parameter\r
+ else:\r
+ SqlCommand = """select ID, Modifier, Name, Value, Model, BelongsToFunction from %s\r
+ where Name = '%s' and StartLine < %s order by StartLine DESC""" \\r
+ % (IdentifierTable, SecondPara, StartLine)\r
+ NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ if NewRecordSet:\r
+ Value = NewRecordSet[0][1]\r
+ if 'AllocatePage' in Value \\r
+ or 'AllocatePool' in Value \\r
+ or 'AllocateRuntimePool' in Value \\r
+ or 'AllocateZeroPool' in Value:\r
+ pass\r
+ else:\r
+ if not EccGlobalData.gException.IsException(\r
+ ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value):\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE,\r
+ OtherMsg="Please review the buffer type"\r
+ + "is correct or not. If it is correct" +\r
+ " please add [%s] to exception list"\r
+ % Value,\r
+ BelongsToTable=IdentifierTable,\r
+ BelongsToItem=Id)\r
+ else:\r
+ pass\r
\r
# Check UNI files\r
def UniCheck(self):\r
for Key in RecordDict:\r
if len(RecordDict[Key]) > 1:\r
for Item in RecordDict[Key]:\r
- Path = Item[1].replace(EccGlobalData.gWorkspace, '')\r
- if Path.startswith('\\') or Path.startswith('/'):\r
- Path = Path[1:]\r
+ Path = mws.relpath(Item[1], EccGlobalData.gWorkspace)\r
if not EccGlobalData.gException.IsException(ERROR_INCLUDE_FILE_CHECK_NAME, Path):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_INCLUDE_FILE_CHECK_NAME, OtherMsg="The file name for [%s] is duplicate" % Path, BelongsToTable='File', BelongsToItem=Item[0])\r
\r
if LibraryClass[1].upper() == 'NULL' or LibraryClass[1].startswith('!ifdef') or LibraryClass[1].startswith('!ifndef') or LibraryClass[1].endswith('!endif'):\r
continue\r
else:\r
- LibraryIns = os.path.normpath(os.path.join(EccGlobalData.gWorkspace, LibraryClass[2]))\r
+ LibraryIns = os.path.normpath(mws.join(EccGlobalData.gWorkspace, LibraryClass[2]))\r
+ SkipDirString = '|'.join(EccGlobalData.gConfig.SkipDirList)\r
+ p = re.compile(r'.*[\\/](?:%s^\S)[\\/]?.*' % SkipDirString)\r
+ if p.match(os.path.split(LibraryIns)[0].upper()):\r
+ continue\r
SqlCommand = """select Value3 from Inf where BelongsToFile =\r
(select ID from File where lower(FullPath) = lower('%s'))\r
and Value2 = '%s'""" % (LibraryIns, 'LIBRARY_CLASS')\r
for Record in RecordSet:\r
FdfID = Record[0]\r
FilePath = Record[1]\r
- FilePath = os.path.normpath(os.path.join(EccGlobalData.gWorkspace, FilePath))\r
+ FilePath = os.path.normpath(mws.join(EccGlobalData.gWorkspace, FilePath))\r
SqlCommand = """select ID from Inf where Model = %s and BelongsToFile = (select ID from File where FullPath like '%s')\r
""" % (MODEL_EFI_SOURCE_FILE, FilePath)\r
NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
RecordSet = Table.Exec(SqlCommand)\r
Path = ""\r
for Record in RecordSet:\r
- Path = Record[0].replace(EccGlobalData.gWorkspace, '')\r
- if Path.startswith('\\') or Path.startswith('/'):\r
- Path = Path[1:]\r
+ Path = mws.relpath(Record[0], EccGlobalData.gWorkspace)\r
return Path\r
\r
# Check whether two module INFs under one workspace has the same FILE_GUID value\r
\r
# Check Guid Format in module INF\r
def MetaDataFileCheckModuleFileGuidFormat(self):\r
- if EccGlobalData.gConfig.MetaDataFileCheckModuleFileGuidFormat or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ if EccGlobalData.gConfig.MetaDataFileCheckModuleFileGuidFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
EdkLogger.quiet("Check Guid Format in module INF ...")\r
Table = EccGlobalData.gDb.TblInf\r
SqlCommand = """\r
\r
# Check Protocol Format in module INF\r
def MetaDataFileCheckModuleFileProtocolFormat(self):\r
- if EccGlobalData.gConfig.MetaDataFileCheckModuleFileProtocolFormat or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ if EccGlobalData.gConfig.MetaDataFileCheckModuleFileProtocolFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
EdkLogger.quiet("Check Protocol Format in module INF ...")\r
Table = EccGlobalData.gDb.TblInf\r
SqlCommand = """\r
\r
# Check Ppi Format in module INF\r
def MetaDataFileCheckModuleFilePpiFormat(self):\r
- if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePpiFormat or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePpiFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
EdkLogger.quiet("Check Ppi Format in module INF ...")\r
Table = EccGlobalData.gDb.TblInf\r
SqlCommand = """\r
\r
# Check Pcd Format in module INF\r
def MetaDataFileCheckModuleFilePcdFormat(self):\r
- if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePcdFormat or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePcdFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
EdkLogger.quiet("Check Pcd Format in module INF ...")\r
Table = EccGlobalData.gDb.TblInf\r
SqlCommand = """\r
SqlCommand = """\r
select A.ID, A.Value1 from %s as A, %s as B\r
where A.Model = %s and B.Model = %s\r
- and A.Value1 = B.Value1 and A.ID <> B.ID\r
+ and A.Value1 like B.Value1 and A.ID <> B.ID\r
and A.Scope1 = B.Scope1\r
and A.Enabled > -1\r
and B.Enabled > -1\r
SqlCommand = """\r
select A.ID, A.Value1, A.Value2 from %s as A, %s as B\r
where A.Model = %s and B.Model = %s\r
- and A.Value2 = B.Value2 and A.ID <> B.ID\r
+ and A.Value2 like B.Value2 and A.ID <> B.ID\r
and A.Scope1 = B.Scope1 and A.Value1 <> B.Value1\r
group by A.ID\r
""" % (Table.Table, Table.Table, Model, Model)\r
FileTable = 'Identifier' + str(Id)\r
self.NamingConventionCheckDefineStatement(FileTable)\r
self.NamingConventionCheckTypedefStatement(FileTable)\r
- self.NamingConventionCheckIfndefStatement(FileTable)\r
self.NamingConventionCheckVariableName(FileTable)\r
self.NamingConventionCheckSingleCharacterVariable(FileTable)\r
+ if os.path.splitext(F)[1] in ('.h'):\r
+ self.NamingConventionCheckIfndefStatement(FileTable)\r
\r
self.NamingConventionCheckPathName()\r
self.NamingConventionCheckFunctionName()\r
\r
# Check whether the #ifndef at the start of an include file uses both prefix and postfix underscore characters, '_'.\r
def NamingConventionCheckIfndefStatement(self, FileTable):\r
- if EccGlobalData.gConfig.NamingConventionCheckTypedefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ if EccGlobalData.gConfig.NamingConventionCheckIfndefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
EdkLogger.quiet("Checking naming covention of #ifndef statement ...")\r
\r
SqlCommand = """select ID, Value from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_MACRO_IFNDEF)\r
SqlCommand = """select ID, Name from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_VARIABLE)\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
for Record in RecordSet:\r
- if not Pattern.match(Record[1]):\r
+ Var = Record[1]\r
+ if Var.startswith('CONST'):\r
+ Var = Var[5:].lstrip()\r
+ if not Pattern.match(Var):\r
if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Record[1]):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, OtherMsg="The variable name [%s] does not follow the rules" % (Record[1]), BelongsToTable=FileTable, BelongsToItem=Record[0])\r
\r
if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_SINGLE_CHARACTER_VARIABLE, Record[1]):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_SINGLE_CHARACTER_VARIABLE, OtherMsg="The variable name [%s] does not follow the rules" % (Record[1]), BelongsToTable=FileTable, BelongsToItem=Record[0])\r
\r
+def FindPara(FilePath, Para, CallingLine):\r
+ Lines = open(FilePath).readlines()\r
+ Line = ''\r
+ for Index in range(CallingLine - 1, 0, -1):\r
+ # Find the nearest statement for Para\r
+ Line = Lines[Index].strip()\r
+ if Line.startswith('%s = ' % Para):\r
+ Line = Line.strip()\r
+ return Line\r
+ break\r
+\r
+ return ''\r
+\r
##\r
#\r
# This acts like the main() function for the script, unless it is 'import'ed into another\r