X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FVariable%2FPei%2FVariable.c;h=18e252f97312fdcd027b353e2abb01183af94ae7;hp=7385af71572e24d68c16045aaa31cdf3cf618ad2;hb=fe1e36e550c6ffcd2561903d434683d3939e1942;hpb=0c2b5da80e9551286cd02a92d91090290ae2d816 diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c index 7385af7157..18e252f973 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -1,6 +1,9 @@ -/*++ +/** @file + + Implement ReadOnly Variable Services required by PEIM and install + PI ReadOnly Varaiable2 PPI. These services operates the non volatile storage space. -Copyright (c) 2006 - 2007 Intel Corporation.
+Copyright (c) 2006 - 2008 Intel Corporation.
All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -10,13 +13,7 @@ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Module Name: - Variable.c - -Abstract: - - Framework PEIM to provide the Variable functionality - ---*/ +**/ #include "Variable.h" @@ -24,12 +21,12 @@ Abstract: // // Module globals // -static EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = { +EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = { PeiGetVariable, PeiGetNextVariableName }; -static EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = { +EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = { (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), &gEfiPeiReadOnlyVariable2PpiGuid, &mVariablePpi @@ -68,30 +65,58 @@ Returns: } -STATIC VARIABLE_HEADER * -GetNextVariablePtr ( - IN VARIABLE_HEADER *Variable +GetStartPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader ) /*++ Routine Description: - This code checks if variable header is valid or not. + This code gets the pointer to the first variable memory pointer byte Arguments: - Variable Pointer to the Variable Header. + + VarStoreHeader Pointer to the Variable Store Header. Returns: - TRUE Variable header is valid. - FALSE Variable header is not valid. + + VARIABLE_HEADER* Pointer to last unavailable Variable Header + +--*/ +{ + // + // The end of variable store + // + return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1); +} + +VARIABLE_HEADER * +GetEndPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) +/*++ + +Routine Description: + + This code gets the pointer to the last variable memory pointer byte + +Arguments: + + VarStoreHeader Pointer to the Variable Store Header. + +Returns: + + VARIABLE_HEADER* Pointer to last unavailable Variable Header --*/ { - return (VARIABLE_HEADER *) ((UINTN) GET_VARIABLE_DATA_PTR (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize)); + // + // The end of variable store + // + return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size); } -STATIC BOOLEAN EFIAPI IsValidVariableHeader ( @@ -112,17 +137,166 @@ Returns: --*/ { - if (Variable == NULL || - Variable->StartId != VARIABLE_DATA || - (sizeof (VARIABLE_HEADER) + Variable->DataSize + Variable->NameSize) > MAX_VARIABLE_SIZE - ) { + if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) { return FALSE; } return TRUE; } -STATIC + +UINTN +NameSizeOfVariable ( + IN VARIABLE_HEADER *Variable + ) +/*++ + +Routine Description: + + This code gets the size of name of variable. + +Arguments: + + Variable Pointer to the Variable Header. + +Returns: + + UINTN Size of variable in bytes + +--*/ +{ + if (Variable->State == (UINT8) (-1) || + Variable->DataSize == (UINT32) -1 || + Variable->NameSize == (UINT32) -1 || + Variable->Attributes == (UINT32) -1) { + return 0; + } + return (UINTN) Variable->NameSize; +} + +UINTN +DataSizeOfVariable ( + IN VARIABLE_HEADER *Variable + ) +/*++ + +Routine Description: + + This code gets the size of name of variable. + +Arguments: + + Variable Pointer to the Variable Header. + +Returns: + + UINTN Size of variable in bytes + +--*/ +{ + if (Variable->State == (UINT8) -1 || + Variable->DataSize == (UINT32) -1 || + Variable->NameSize == (UINT32) -1 || + Variable->Attributes == (UINT32) -1) { + return 0; + } + return (UINTN) Variable->DataSize; +} + +CHAR16 * +GetVariableNamePtr ( + IN VARIABLE_HEADER *Variable + ) +/*++ + +Routine Description: + + This code gets the pointer to the variable name. + +Arguments: + + Variable Pointer to the Variable Header. + +Returns: + + CHAR16* Pointer to Variable Name + +--*/ +{ + + return (CHAR16 *) (Variable + 1); +} + + +UINT8 * +GetVariableDataPtr ( + IN VARIABLE_HEADER *Variable + ) +/*++ + +Routine Description: + + This code gets the pointer to the variable data. + +Arguments: + + Variable Pointer to the Variable Header. + +Returns: + + UINT8* Pointer to Variable Data + +--*/ +{ + UINTN Value; + + // + // Be careful about pad size for alignment + // + Value = (UINTN) GetVariableNamePtr (Variable); + Value += NameSizeOfVariable (Variable); + Value += GET_PAD_SIZE (NameSizeOfVariable (Variable)); + + return (UINT8 *) Value; +} + +VARIABLE_HEADER * +GetNextVariablePtr ( + IN VARIABLE_HEADER *Variable + ) +/*++ + +Routine Description: + + This code gets the pointer to the next variable header. + +Arguments: + + Variable Pointer to the Variable Header. + +Returns: + + VARIABLE_HEADER* Pointer to next variable header. + +--*/ +{ + UINTN Value; + + if (!IsValidVariableHeader (Variable)) { + return NULL; + } + + Value = (UINTN) GetVariableDataPtr (Variable); + Value += DataSizeOfVariable (Variable); + Value += GET_PAD_SIZE (DataSizeOfVariable (Variable)); + + // + // Be careful about pad size for alignment + // + return (VARIABLE_HEADER *) HEADER_ALIGN (Value); +} + + VARIABLE_STORE_STATUS EFIAPI GetVariableStoreStatus ( @@ -166,7 +340,6 @@ Returns: } } -STATIC EFI_STATUS CompareWithValidVariable ( IN VARIABLE_HEADER *Variable, @@ -195,6 +368,8 @@ Returns: --*/ { + VOID *Point; + if (VariableName[0] == 0) { PtrTrack->CurrPtr = Variable; return EFI_SUCCESS; @@ -209,7 +384,9 @@ Returns: (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) && (((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3]) ) { - if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), Variable->NameSize)) { + ASSERT (NameSizeOfVariable (Variable) != 0); + Point = (VOID *) GetVariableNamePtr (Variable); + if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable))) { PtrTrack->CurrPtr = Variable; return EFI_SUCCESS; } @@ -219,11 +396,10 @@ Returns: return EFI_NOT_FOUND; } -STATIC EFI_STATUS EFIAPI FindVariable ( - IN EFI_PEI_SERVICES **PeiServices, + IN CONST EFI_PEI_SERVICES **PeiServices, IN CONST CHAR16 *VariableName, IN CONST EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack @@ -314,8 +490,8 @@ Returns: // // Find the variable by walk through non-volatile variable store // - IndexTable->StartPtr = (VARIABLE_HEADER *) (VariableStoreHeader + 1); - IndexTable->EndPtr = (VARIABLE_HEADER *) ((UINTN) VariableStoreHeader + VariableStoreHeader->Size); + IndexTable->StartPtr = GetStartPointer (VariableStoreHeader); + IndexTable->EndPtr = GetEndPointer (VariableStoreHeader); // // Start Pointers for the variable. @@ -402,10 +578,10 @@ Returns: VARIABLE_POINTER_TRACK Variable; UINTN VarDataSize; EFI_STATUS Status; - EFI_PEI_SERVICES **PeiServices; + CONST EFI_PEI_SERVICES **PeiServices; PeiServices = GetPeiServicesTablePointer (); - if (VariableName == NULL || VariableGuid == NULL) { + if (VariableName == NULL || VariableGuid == NULL || DataSize == NULL) { return EFI_INVALID_PARAMETER; } // @@ -418,9 +594,16 @@ Returns: // // Get data size // - VarDataSize = Variable.CurrPtr->DataSize; + VarDataSize = DataSizeOfVariable (Variable.CurrPtr); if (*DataSize >= VarDataSize) { - (*PeiServices)->CopyMem (Data, GET_VARIABLE_DATA_PTR (Variable.CurrPtr), VarDataSize); + // + // PO-TKW: Address one checking in this place + // + if (Data == NULL) { + return EFI_INVALID_PARAMETER; + } + + (*PeiServices)->CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize); if (Attributes != NULL) { *Attributes = Variable.CurrPtr->Attributes; @@ -472,10 +655,10 @@ Returns: VARIABLE_POINTER_TRACK Variable; UINTN VarNameSize; EFI_STATUS Status; - EFI_PEI_SERVICES **PeiServices; + CONST EFI_PEI_SERVICES **PeiServices; PeiServices = GetPeiServicesTablePointer (); - if (VariableName == NULL) { + if (VariableName == NULL || VariableGuid == NULL || VariableNameSize == NULL) { return EFI_INVALID_PARAMETER; } @@ -494,9 +677,11 @@ Returns: while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) { if (IsValidVariableHeader (Variable.CurrPtr)) { if (Variable.CurrPtr->State == VAR_ADDED) { - VarNameSize = (UINTN) Variable.CurrPtr->NameSize; + ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0); + + VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr); if (VarNameSize <= *VariableNameSize) { - (*PeiServices)->CopyMem (VariableName, GET_VARIABLE_NAME_PTR (Variable.CurrPtr), VarNameSize); + (*PeiServices)->CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize); (*PeiServices)->CopyMem (VariableGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));