public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "gaoliming" <gaoliming@byosoft.com.cn>
To: "'Konstantin Aladyshev'" <aladyshev22@gmail.com>, <devel@edk2.groups.io>
Cc: <bob.c.feng@intel.com>, <yuwei.chen@intel.com>
Subject: 回复: [PATCH v2] BaseTools: Correct initialization data size check for array PCDs
Date: Tue, 27 Sep 2022 10:17:13 +0800	[thread overview]
Message-ID: <016e01d8d217$41e53210$c5af9630$@byosoft.com.cn> (raw)
In-Reply-To: <20220830102054.18641-1-aladyshev22@gmail.com>

Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

> -----邮件原件-----
> 发件人: Konstantin Aladyshev <aladyshev22@gmail.com>
> 发送时间: 2022年8月30日 18:21
> 收件人: devel@edk2.groups.io
> 抄送: bob.c.feng@intel.com; gaoliming@byosoft.com.cn;
> yuwei.chen@intel.com; Konstantin Aladyshev <aladyshev22@gmail.com>
> 主题: [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@gmail.com>
> ---
>  .../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




  reply	other threads:[~2022-09-27  2:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-30 10:20 [PATCH v2] BaseTools: Correct initialization data size check for array PCDs Konstantin Aladyshev
2022-09-27  2:17 ` gaoliming [this message]
2022-10-01 14:43 ` Bob Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='016e01d8d217$41e53210$c5af9630$@byosoft.com.cn' \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox