回复: [PATCH v2] BaseTools: Correct initialization data size check for array PCDs


gaoliming
 

Reviewed-by: Liming Gao <gaoliming@...>

-----邮件原件-----
发件人: Konstantin Aladyshev <aladyshev22@...>
发送时间: 2022年8月30日 18:21
收件人: devel@edk2.groups.io
抄送: bob.c.feng@...; gaoliming@...;
yuwei.chen@...; Konstantin Aladyshev <aladyshev22@...>
主题: [PATCH v2] BaseTools: Correct initialization data size check for
array
PCDs

Currently it is not possible to initialize all elements in the
array PCD.

For example, this PCD would result to a build failure:
gTokenSpaceGuid.PcdArray|{0x11, 0x22}|UINT8[2]|0x4C4CB9A3

Correct logical operator in the initialization data size checks to
fix the issue.

Signed-off-by: Konstantin Aladyshev <aladyshev22@...>
---
.../Source/Python/Workspace/DscBuildData.py | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
b/BaseTools/Source/Python/Workspace/DscBuildData.py
index e9f68384b4..73c6ee4006 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -2089,12 +2089,12 @@ class DscBuildData(PlatformBuildClassObject):
pcdarraysize = Pcd.PcdArraySize()

if "{CODE(" in Pcd.DefaultValueFromDec:

if Pcd.Capacity[-1] != "-1":

- CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) < %d * sizeof(%s), "Pcd %s.%s
Value in Dec exceed the array capability %s"); // From %s Line %s \n ' %
(Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCNa
me,
Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.Defa
ultValueFromDecInfo[1])

+ CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_INIT_Value) <= %d * sizeof(%s), "Pcd %s.%s
Value in Dec exceed the array capability %s"); // From %s Line %s \n ' %
(Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCNa
me,
Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.Defa
ultValueFromDecInfo[1])

CApp = CApp + ' PcdArraySize =
sizeof(%s_%s_INIT_Value);\n ' % (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName)

CApp = CApp + ' memcpy
(Pcd, %s_%s_INIT_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName)

else:

if Pcd.Capacity[-1] != "-1":

- CApp = CApp + '__STATIC_ASSERT(%d < %d *
sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); //
From %s Line %s \n' %
(ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.Defa
ultValueFromDecInfo[1])

+ CApp = CApp + '__STATIC_ASSERT(%d <= %d *
sizeof(%s), "Pcd %s.%s Value in Dec exceed the array capability %s"); //
From %s Line %s \n' %
(ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,Pcd.DatumType,Pcd.DefaultValueFromDecInfo[0],Pcd.Defa
ultValueFromDecInfo[1])

CApp = CApp + ' PcdArraySize = %d;\n' % ValueSize

CApp = CApp + ' Value = %s; // From DEC
Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize),
Pcd.DefaultValueFromDec)

CApp = CApp + ' memcpy (Pcd, Value,
PcdArraySize);\n'

@@ -2204,7 +2204,7 @@ class DscBuildData(PlatformBuildClassObject):
if "{CODE(" in Value:

if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":

pcdarraysize = Pcd.PcdArraySize()

- CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s),
"Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' %
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
ame, Pcd.TokenCName,Pcd.DatumType, valuefrom)

+ CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s),
"Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' %
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
ame, Pcd.TokenCName,Pcd.DatumType, valuefrom)

CApp = CApp+ ' PcdArraySize =
sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,SkuName, DefaultStoreName)

CApp = CApp + ' memcpy (Pcd,
&%s_%s_%s_%s_Value,PcdArraySize);\n ' % (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,SkuName, DefaultStoreName)

else:

@@ -2217,12 +2217,12 @@ class DscBuildData(PlatformBuildClassObject):
pcdarraysize = Pcd.PcdArraySize()

if "{CODE(" in pcddefaultvalue:

if Pcd.Capacity[-1] != "-1":

- CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s),
"Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n'
%
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)

+ CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s),
"Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n'
%
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)

CApp = CApp + ' PcdArraySize =
sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,SkuName, DefaultStoreName)

CApp = CApp + ' memcpy
(Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,SkuName, DefaultStoreName)

else:

if Pcd.Capacity[-1] != "-1":

- CApp = CApp +
'__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the
array capability %s"); // From %s \n' %
(ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,Pcd.DatumType,valuefrom)

+ CApp = CApp +
'__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the
array capability %s"); // From %s \n' %
(ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,Pcd.DatumType,valuefrom)

CApp = CApp + ' PcdArraySize = %d;\n' %
ValueSize

CApp = CApp + ' Value = %s; //
From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value,
ValueSize),
Pcd.DefaultFromDSC.get(TAB_DEFAULT,
{}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if
Pcd.DefaultFromDSC else Pcd.DefaultValue)

CApp = CApp + ' memcpy (Pcd, Value,
PcdArraySize);\n'

@@ -2238,7 +2238,7 @@ class DscBuildData(PlatformBuildClassObject):
if "{CODE(" in Value:

if Pcd.IsArray() and Pcd.Capacity[-1] != "-1":

pcdarraysize = Pcd.PcdArraySize()

- CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s),
"Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' %
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)

+ CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s),
"Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n' %
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)

CApp = CApp + ' PcdArraySize =
sizeof(%s_%s_%s_%s_Value);\n '% (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,SkuName, DefaultStoreName)

CApp = CApp + ' memcpy (Pcd,
&%s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,SkuName, DefaultStoreName)

else:

@@ -2251,12 +2251,12 @@ class DscBuildData(PlatformBuildClassObject):
pcdarraysize = Pcd.PcdArraySize()

if "{CODE(" in pcddefaultvalue:

if Pcd.Capacity[-1] != "-1":

- CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) < %d * sizeof(%s),
"Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n'
%
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)

+ CApp = CApp +
'__STATIC_ASSERT(sizeof(%s_%s_%s_%s_Value) <= %d * sizeof(%s),
"Pcd %s.%s Value in Dsc exceed the array capability %s"); // From %s \n'
%
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,
DefaultStoreName,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCN
ame, Pcd.TokenCName,Pcd.DatumType,valuefrom)

CApp + ' PcdArraySize =
sizeof(%s_%s_%s_%s_Value);\n ' % (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,SkuName, DefaultStoreName)

CApp = CApp + ' memcpy
(Pcd, %s_%s_%s_%s_Value, PcdArraySize);\n' % (Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,SkuName, DefaultStoreName)

else:

if Pcd.Capacity[-1] != "-1":

- CApp = CApp +
'__STATIC_ASSERT(%d < %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the
array capability %s"); // From %s \n' %
(ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,Pcd.DatumType,valuefrom)

+ CApp = CApp +
'__STATIC_ASSERT(%d <= %d * sizeof(%s), "Pcd %s.%s Value in Dsc exceed the
array capability %s"); // From %s \n' %
(ValueSize,pcdarraysize,Pcd.BaseDatumType,Pcd.TokenSpaceGuidCName,
Pcd.TokenCName,Pcd.DatumType,valuefrom)

CApp = CApp + ' PcdArraySize = %d;\n' %
ValueSize

CApp = CApp + ' Value = %s; //
From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value,
ValueSize),
Pcd.DscRawValue.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT,
Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)

CApp = CApp + ' memcpy (Pcd, Value,
PcdArraySize);\n'

--
2.25.1

Join devel@edk2.groups.io to automatically receive all group messages.