summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNickle Wang <nicklew@nvidia.com>2023-09-18 20:03:30 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-09-22 03:59:03 +0000
commitf67e1934d985dcb8a465dcf44484be3688be99a5 (patch)
tree6f949a22933265de6b811c28043c3734146435e4
parentea628f28e59849ee7b91e6660c0ecd1a5c6e0884 (diff)
downloadedk2-f67e1934d985dcb8a465dcf44484be3688be99a5.tar.gz
edk2-f67e1934d985dcb8a465dcf44484be3688be99a5.tar.bz2
edk2-f67e1934d985dcb8a465dcf44484be3688be99a5.zip
RedfishPkg/JsonLib: fix JsonObjectGetValue issue
JsonObjectGetValue() cannot find corresponding JSON value when the EDKII_JSON_VALUE object is created by another UEFI driver. This is because "hashtable_seed" is initialized by current time while JsonLib is loaded. So, "hashtable_seed" will be different in each individual UEFI driver. Signed-off-by: Nickle Wang <nicklew@nvidia.com> Cc: Abner Chang <abner.chang@amd.com> Cc: Igor Kulchytskyy <igork@ami.com> Cc: Nick Ramirez <nramirez@nvidia.com> Reviewed-by: Igor Kulchytskyy <igork@ami.com> Reviewed-by: Abner Chang <abner.chang@amd.com>
-rw-r--r--RedfishPkg/Library/JsonLib/JsonLib.c35
-rw-r--r--RedfishPkg/Library/JsonLib/JsonLib.inf1
2 files changed, 36 insertions, 0 deletions
diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/JsonLib/JsonLib.c
index 9b758b9402..6c3373d205 100644
--- a/RedfishPkg/Library/JsonLib/JsonLib.c
+++ b/RedfishPkg/Library/JsonLib/JsonLib.c
@@ -19,6 +19,8 @@
#include "jansson.h"
+extern volatile UINT32 hashtable_seed;
+
/**
The function is used to initialize a JSON value which contains a new JSON array,
or NULL on error. Initially, the array is empty.
@@ -1138,3 +1140,36 @@ JsonGetType (
{
return (EDKII_JSON_TYPE)(((json_t *)JsonValue)->type);
}
+
+/**
+ JSON Library constructor.
+
+ @param ImageHandle The image handle.
+ @param SystemTable The system table.
+
+ @retval EFI_SUCCESS Protocol listener is registered successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+JsonLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ //
+ // hashtable_seed is initalized by current time while JsonLib is loaded.
+ // Due to above mechanism, hashtable_seed will be different in each individual
+ // UEFI driver. As the result, the hash of same key in different UEFI driver
+ // would be different. This breaks JsonObjectGetValue() because
+ // JsonObjectGetValue() won't be able to find corresponding JSON value if
+ // this EDKII_JSON_VALUE is created by another UEFI driver.
+ //
+ // Initial the seed to a fixed magic value for JsonLib to be working in all
+ // UEFI drivers. This fixed number will be removed after the protocol version
+ // of JsonLib is implemented in the future.
+ //
+ hashtable_seed = 0xFDAE2143;
+
+ return EFI_SUCCESS;
+}
diff --git a/RedfishPkg/Library/JsonLib/JsonLib.inf b/RedfishPkg/Library/JsonLib/JsonLib.inf
index 9d52a622e1..b0d1bcac7c 100644
--- a/RedfishPkg/Library/JsonLib/JsonLib.inf
+++ b/RedfishPkg/Library/JsonLib/JsonLib.inf
@@ -15,6 +15,7 @@
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = JsonLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER
+ CONSTRUCTOR = JsonLibConstructor
#
# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 RISCV64