MdeModulePkg SmiHandlerProfile: Use fixed data type in data structure

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=568

Use fixed data type in data structure and make the structure
be natural aligned.
Without this update, the code must assume DXE and SMM are using
same data type (same size of UINTN), but it may be not true at
some case, for example, after standalone SMM feature is enabled.
With this update, the data structure will be phase independent
and convenient for consumer to parse the data.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
Star Zeng 2017-05-23 10:51:13 +08:00
parent 8ced192d5c
commit f248539538
3 changed files with 105 additions and 67 deletions

View File

@ -348,9 +348,9 @@ DumpSmmLoadedImage(
if (ImageStruct->Header.Signature == SMM_CORE_IMAGE_DATABASE_SIGNATURE) { if (ImageStruct->Header.Signature == SMM_CORE_IMAGE_DATABASE_SIGNATURE) {
NameString = GetDriverNameString (ImageStruct); NameString = GetDriverNameString (ImageStruct);
Print(L" <Image Name=\"%a\"", NameString); Print(L" <Image Name=\"%a\"", NameString);
Print(L" Base=\"0x%x\" Size=\"0x%x\"", ImageStruct->ImageBase, ImageStruct->ImageSize); Print(L" Base=\"0x%lx\" Size=\"0x%lx\"", ImageStruct->ImageBase, ImageStruct->ImageSize);
if (ImageStruct->EntryPoint != 0) { if (ImageStruct->EntryPoint != 0) {
Print(L" EntryPoint=\"0x%x\"", ImageStruct->EntryPoint); Print(L" EntryPoint=\"0x%lx\"", ImageStruct->EntryPoint);
} }
Print(L" FvFile=\"%g\"", &ImageStruct->FileGuid); Print(L" FvFile=\"%g\"", &ImageStruct->FileGuid);
Print(L" RefId=\"0x%x\"", ImageStruct->ImageRef); Print(L" RefId=\"0x%x\"", ImageStruct->ImageRef);
@ -540,7 +540,7 @@ DumpSmiChildContext (
CHAR16 *Str; CHAR16 *Str;
if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) { if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) {
Print(L" SwSmi=\"0x%x\"", ((EFI_SMM_SW_REGISTER_CONTEXT *)Context)->SwSmiInputValue); Print(L" SwSmi=\"0x%lx\"", ((SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *)Context)->SwSmiInputValue);
} else if (CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) { } else if (CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) {
Print(L" SxType=\"%a\"", SxTypeToString(((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Type)); Print(L" SxType=\"%a\"", SxTypeToString(((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Type));
Print(L" SxPhase=\"%a\"", SxPhaseToString(((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Phase)); Print(L" SxPhase=\"%a\"", SxPhaseToString(((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Phase));
@ -609,14 +609,14 @@ DumpSmiHandler(
Print(L" <Pdb>%a</Pdb>\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset); Print(L" <Pdb>%a</Pdb>\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset);
} }
Print(L" </Module>\n"); Print(L" </Module>\n");
Print(L" <Handler Address=\"0x%x\">\n", SmiHandlerStruct->Handler); Print(L" <Handler Address=\"0x%lx\">\n", SmiHandlerStruct->Handler);
if (ImageStruct != NULL) { if (ImageStruct != NULL) {
Print(L" <RVA>0x%x</RVA>\n", SmiHandlerStruct->Handler - ImageStruct->ImageBase); Print(L" <RVA>0x%x</RVA>\n", (UINTN) (SmiHandlerStruct->Handler - ImageStruct->ImageBase));
} }
Print(L" </Handler>\n", SmiHandlerStruct->Handler); Print(L" </Handler>\n", SmiHandlerStruct->Handler);
Print(L" <Caller Address=\"0x%x\">\n", SmiHandlerStruct->CallerAddr); Print(L" <Caller Address=\"0x%lx\">\n", SmiHandlerStruct->CallerAddr);
if (ImageStruct != NULL) { if (ImageStruct != NULL) {
Print(L" <RVA>0x%x</RVA>\n", SmiHandlerStruct->CallerAddr - ImageStruct->ImageBase); Print(L" <RVA>0x%x</RVA>\n", (UINTN) (SmiHandlerStruct->CallerAddr - ImageStruct->ImageBase));
} }
Print(L" </Caller>\n", SmiHandlerStruct->Handler); Print(L" </Caller>\n", SmiHandlerStruct->Handler);
SmiHandlerStruct = (VOID *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length); SmiHandlerStruct = (VOID *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length);

View File

@ -33,13 +33,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "PiSmmCore.h" #include "PiSmmCore.h"
#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))
typedef struct { typedef struct {
EFI_GUID FileGuid; EFI_GUID FileGuid;
UINTN ImageRef; PHYSICAL_ADDRESS EntryPoint;
UINTN EntryPoint; PHYSICAL_ADDRESS ImageBase;
UINTN ImageBase; UINT64 ImageSize;
UINTN ImageSize; UINT32 ImageRef;
UINTN PdbStringSize; UINT16 PdbStringSize;
CHAR8 *PdbString; CHAR8 *PdbString;
} IMAGE_STRUCT; } IMAGE_STRUCT;
@ -89,8 +92,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreSmiEntryList = &mSmiEntry
GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreHardwareSmiEntryList = &mHardwareSmiEntryList; GLOBAL_REMOVE_IF_UNREFERENCED LIST_ENTRY *mSmmCoreHardwareSmiEntryList = &mHardwareSmiEntryList;
GLOBAL_REMOVE_IF_UNREFERENCED IMAGE_STRUCT *mImageStruct; GLOBAL_REMOVE_IF_UNREFERENCED IMAGE_STRUCT *mImageStruct;
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mImageStructCountMax; GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mImageStructCountMax;
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mImageStructCount; GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mImageStructCount;
GLOBAL_REMOVE_IF_UNREFERENCED VOID *mSmiHandlerProfileDatabase; GLOBAL_REMOVE_IF_UNREFERENCED VOID *mSmiHandlerProfileDatabase;
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmiHandlerProfileDatabaseSize; GLOBAL_REMOVE_IF_UNREFERENCED UINTN mSmiHandlerProfileDatabaseSize;
@ -162,9 +165,9 @@ GetDriverGuid (
**/ **/
VOID VOID
AddImageStruct( AddImageStruct(
IN UINTN ImageBase, IN PHYSICAL_ADDRESS ImageBase,
IN UINTN ImageSize, IN UINT64 ImageSize,
IN UINTN EntryPoint, IN PHYSICAL_ADDRESS EntryPoint,
IN EFI_GUID *Guid, IN EFI_GUID *Guid,
IN CHAR8 *PdbString IN CHAR8 *PdbString
) )
@ -185,7 +188,7 @@ AddImageStruct(
PdbStringSize = AsciiStrSize(PdbString); PdbStringSize = AsciiStrSize(PdbString);
mImageStruct[mImageStructCount].PdbString = AllocateCopyPool (PdbStringSize, PdbString); mImageStruct[mImageStructCount].PdbString = AllocateCopyPool (PdbStringSize, PdbString);
if (mImageStruct[mImageStructCount].PdbString != NULL) { if (mImageStruct[mImageStructCount].PdbString != NULL) {
mImageStruct[mImageStructCount].PdbStringSize = PdbStringSize; mImageStruct[mImageStructCount].PdbStringSize = (UINT16) PdbStringSize;
} }
} }
@ -222,7 +225,7 @@ AddressToImageStruct(
@return image reference index @return image reference index
**/ **/
UINTN UINT32
AddressToImageRef( AddressToImageRef(
IN UINTN Address IN UINTN Address
) )
@ -233,7 +236,7 @@ AddressToImageRef(
if (ImageStruct != NULL) { if (ImageStruct != NULL) {
return ImageStruct->ImageRef; return ImageStruct->ImageRef;
} }
return (UINTN)-1; return (UINT32)-1;
} }
/** /**
@ -252,11 +255,11 @@ GetSmmLoadedImage(
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
CHAR16 *PathStr; CHAR16 *PathStr;
EFI_SMM_DRIVER_ENTRY *LoadedImagePrivate; EFI_SMM_DRIVER_ENTRY *LoadedImagePrivate;
UINTN EntryPoint; PHYSICAL_ADDRESS EntryPoint;
VOID *EntryPointInImage; VOID *EntryPointInImage;
EFI_GUID Guid; EFI_GUID Guid;
CHAR8 *PdbString; CHAR8 *PdbString;
UINTN RealImageBase; PHYSICAL_ADDRESS RealImageBase;
HandleBufferSize = 0; HandleBufferSize = 0;
HandleBuffer = NULL; HandleBuffer = NULL;
@ -286,7 +289,7 @@ GetSmmLoadedImage(
} }
NoHandles = HandleBufferSize/sizeof(EFI_HANDLE); NoHandles = HandleBufferSize/sizeof(EFI_HANDLE);
mImageStructCountMax = NoHandles; mImageStructCountMax = (UINT32) NoHandles;
mImageStruct = AllocateZeroPool(mImageStructCountMax * sizeof(IMAGE_STRUCT)); mImageStruct = AllocateZeroPool(mImageStructCountMax * sizeof(IMAGE_STRUCT));
if (mImageStruct == NULL) { if (mImageStruct == NULL) {
goto Done; goto Done;
@ -309,8 +312,8 @@ GetSmmLoadedImage(
LoadedImagePrivate = BASE_CR(LoadedImage, EFI_SMM_DRIVER_ENTRY, SmmLoadedImage); LoadedImagePrivate = BASE_CR(LoadedImage, EFI_SMM_DRIVER_ENTRY, SmmLoadedImage);
RealImageBase = (UINTN)LoadedImage->ImageBase; RealImageBase = (UINTN)LoadedImage->ImageBase;
if (LoadedImagePrivate->Signature == EFI_SMM_DRIVER_ENTRY_SIGNATURE) { if (LoadedImagePrivate->Signature == EFI_SMM_DRIVER_ENTRY_SIGNATURE) {
EntryPoint = (UINTN)LoadedImagePrivate->ImageEntryPoint; EntryPoint = LoadedImagePrivate->ImageEntryPoint;
if ((EntryPoint != 0) && ((EntryPoint < (UINTN)LoadedImage->ImageBase) || (EntryPoint >= ((UINTN)LoadedImage->ImageBase + (UINTN)LoadedImage->ImageSize)))) { if ((EntryPoint != 0) && ((EntryPoint < (UINTN)LoadedImage->ImageBase) || (EntryPoint >= ((UINTN)LoadedImage->ImageBase + LoadedImage->ImageSize)))) {
// //
// If the EntryPoint is not in the range of image buffer, it should come from emulation environment. // If the EntryPoint is not in the range of image buffer, it should come from emulation environment.
// So patch ImageBuffer here to align the EntryPoint. // So patch ImageBuffer here to align the EntryPoint.
@ -320,9 +323,9 @@ GetSmmLoadedImage(
RealImageBase = (UINTN)LoadedImage->ImageBase + EntryPoint - (UINTN)EntryPointInImage; RealImageBase = (UINTN)LoadedImage->ImageBase + EntryPoint - (UINTN)EntryPointInImage;
} }
} }
DEBUG ((DEBUG_INFO, "(0x%x - 0x%x", RealImageBase, (UINTN)LoadedImage->ImageSize)); DEBUG ((DEBUG_INFO, "(0x%lx - 0x%lx", RealImageBase, LoadedImage->ImageSize));
if (EntryPoint != 0) { if (EntryPoint != 0) {
DEBUG ((DEBUG_INFO, ", EntryPoint:0x%x", EntryPoint)); DEBUG ((DEBUG_INFO, ", EntryPoint:0x%lx", EntryPoint));
} }
DEBUG ((DEBUG_INFO, ")\n")); DEBUG ((DEBUG_INFO, ")\n"));
@ -334,7 +337,7 @@ GetSmmLoadedImage(
} }
DEBUG ((DEBUG_INFO, " (%s)\n", PathStr)); DEBUG ((DEBUG_INFO, " (%s)\n", PathStr));
AddImageStruct((UINTN)RealImageBase, (UINTN)LoadedImage->ImageSize, EntryPoint, &Guid, PdbString); AddImageStruct(RealImageBase, LoadedImage->ImageSize, EntryPoint, &Guid, PdbString);
} }
Done: Done:
@ -359,7 +362,7 @@ DumpSmiChildContext (
CHAR16 *Str; CHAR16 *Str;
if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) { if (CompareGuid (HandlerType, &gEfiSmmSwDispatch2ProtocolGuid)) {
DEBUG ((DEBUG_INFO, " SwSmi - 0x%x\n", ((EFI_SMM_SW_REGISTER_CONTEXT *)Context)->SwSmiInputValue)); DEBUG ((DEBUG_INFO, " SwSmi - 0x%lx\n", ((SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *)Context)->SwSmiInputValue));
} else if (CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) { } else if (CompareGuid (HandlerType, &gEfiSmmSxDispatch2ProtocolGuid)) {
DEBUG ((DEBUG_INFO, " SxType - 0x%x\n", ((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Type)); DEBUG ((DEBUG_INFO, " SxType - 0x%x\n", ((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Type));
DEBUG ((DEBUG_INFO, " SxPhase - 0x%x\n", ((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Phase)); DEBUG ((DEBUG_INFO, " SxPhase - 0x%x\n", ((EFI_SMM_SX_REGISTER_CONTEXT *)Context)->Phase));
@ -422,12 +425,12 @@ DumpSmiHandlerOnSmiEntry(
} }
DEBUG ((DEBUG_INFO, " Handler - 0x%x", SmiHandler->Handler)); DEBUG ((DEBUG_INFO, " Handler - 0x%x", SmiHandler->Handler));
if (ImageStruct != NULL) { if (ImageStruct != NULL) {
DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", (UINTN)SmiHandler->Handler - ImageStruct->ImageBase)); DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", (UINTN)SmiHandler->Handler - (UINTN) ImageStruct->ImageBase));
} }
DEBUG ((DEBUG_INFO, "\n")); DEBUG ((DEBUG_INFO, "\n"));
DEBUG ((DEBUG_INFO, " CallerAddr - 0x%x", SmiHandler->CallerAddr)); DEBUG ((DEBUG_INFO, " CallerAddr - 0x%x", SmiHandler->CallerAddr));
if (ImageStruct != NULL) { if (ImageStruct != NULL) {
DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", SmiHandler->CallerAddr - ImageStruct->ImageBase)); DEBUG ((DEBUG_INFO, " <== RVA - 0x%x", SmiHandler->CallerAddr - (UINTN) ImageStruct->ImageBase));
} }
DEBUG ((DEBUG_INFO, "\n")); DEBUG ((DEBUG_INFO, "\n"));
} }
@ -533,11 +536,11 @@ GetSmmImageDatabaseSize(
) )
{ {
UINTN Size; UINTN Size;
UINTN Index; UINT32 Index;
Size = (sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE)) * mImageStructCount; Size = 0;
for (Index = 0; Index < mImageStructCount; Index++) { for (Index = 0; Index < mImageStructCount; Index++) {
Size += mImageStruct[Index].PdbStringSize; Size += sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64));
} }
return Size; return Size;
} }
@ -564,7 +567,7 @@ GetSmmSmiHandlerSizeOnSmiEntry(
ListEntry != &SmiEntry->SmiHandlers; ListEntry != &SmiEntry->SmiHandlers;
ListEntry = ListEntry->ForwardLink) { ListEntry = ListEntry->ForwardLink) {
SmiHandler = CR(ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE); SmiHandler = CR(ListEntry, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);
Size += sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + SmiHandler->ContextSize; Size += sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64));
} }
return Size; return Size;
@ -640,11 +643,11 @@ GetSmmImageDatabaseData (
if (Size >= ExpectedSize) { if (Size >= ExpectedSize) {
return 0; return 0;
} }
if (sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + mImageStruct[Index].PdbStringSize > ExpectedSize - Size) { if (sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64)) > ExpectedSize - Size) {
return 0; return 0;
} }
ImageStruct->Header.Signature = SMM_CORE_IMAGE_DATABASE_SIGNATURE; ImageStruct->Header.Signature = SMM_CORE_IMAGE_DATABASE_SIGNATURE;
ImageStruct->Header.Length = (UINT32)(sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + mImageStruct[Index].PdbStringSize); ImageStruct->Header.Length = (UINT32)(sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64)));
ImageStruct->Header.Revision = SMM_CORE_IMAGE_DATABASE_REVISION; ImageStruct->Header.Revision = SMM_CORE_IMAGE_DATABASE_REVISION;
CopyGuid(&ImageStruct->FileGuid, &mImageStruct[Index].FileGuid); CopyGuid(&ImageStruct->FileGuid, &mImageStruct[Index].FileGuid);
ImageStruct->ImageRef = mImageStruct[Index].ImageRef; ImageStruct->ImageRef = mImageStruct[Index].ImageRef;
@ -658,7 +661,7 @@ GetSmmImageDatabaseData (
ImageStruct->PdbStringOffset = 0; ImageStruct->PdbStringOffset = 0;
} }
ImageStruct = (SMM_CORE_IMAGE_DATABASE_STRUCTURE *)((UINTN)ImageStruct + ImageStruct->Header.Length); ImageStruct = (SMM_CORE_IMAGE_DATABASE_STRUCTURE *)((UINTN)ImageStruct + ImageStruct->Header.Length);
Size += sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + mImageStruct[Index].PdbStringSize; Size += sizeof(SMM_CORE_IMAGE_DATABASE_STRUCTURE) + GET_OCCUPIED_SIZE (mImageStruct[Index].PdbStringSize, sizeof (UINT64));
} }
if (ExpectedSize != Size) { if (ExpectedSize != Size) {
@ -682,7 +685,7 @@ GetSmmSmiHandlerDataOnSmiEntry(
IN SMI_ENTRY *SmiEntry, IN SMI_ENTRY *SmiEntry,
IN OUT VOID *Data, IN OUT VOID *Data,
IN UINTN MaxSize, IN UINTN MaxSize,
OUT UINTN *Count OUT UINT32 *Count
) )
{ {
SMM_CORE_SMI_HANDLER_STRUCTURE *SmiHandlerStruct; SMM_CORE_SMI_HANDLER_STRUCTURE *SmiHandlerStruct;
@ -702,11 +705,11 @@ GetSmmSmiHandlerDataOnSmiEntry(
*Count = 0; *Count = 0;
return 0; return 0;
} }
if (sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + SmiHandler->ContextSize > MaxSize - Size) { if (sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64)) > MaxSize - Size) {
*Count = 0; *Count = 0;
return 0; return 0;
} }
SmiHandlerStruct->Length = (UINT32)(sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + SmiHandler->ContextSize); SmiHandlerStruct->Length = (UINT32)(sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64)));
SmiHandlerStruct->CallerAddr = (UINTN)SmiHandler->CallerAddr; SmiHandlerStruct->CallerAddr = (UINTN)SmiHandler->CallerAddr;
SmiHandlerStruct->Handler = (UINTN)SmiHandler->Handler; SmiHandlerStruct->Handler = (UINTN)SmiHandler->Handler;
SmiHandlerStruct->ImageRef = AddressToImageRef((UINTN)SmiHandler->Handler); SmiHandlerStruct->ImageRef = AddressToImageRef((UINTN)SmiHandler->Handler);
@ -717,7 +720,7 @@ GetSmmSmiHandlerDataOnSmiEntry(
} else { } else {
SmiHandlerStruct->ContextBufferOffset = 0; SmiHandlerStruct->ContextBufferOffset = 0;
} }
Size += sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + SmiHandler->ContextSize; Size += sizeof(SMM_CORE_SMI_HANDLER_STRUCTURE) + GET_OCCUPIED_SIZE (SmiHandler->ContextSize, sizeof (UINT64));
SmiHandlerStruct = (SMM_CORE_SMI_HANDLER_STRUCTURE *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length); SmiHandlerStruct = (SMM_CORE_SMI_HANDLER_STRUCTURE *)((UINTN)SmiHandlerStruct + SmiHandlerStruct->Length);
*Count = *Count + 1; *Count = *Count + 1;
} }
@ -748,7 +751,7 @@ GetSmmSmiDatabaseData(
SMI_ENTRY *SmiEntry; SMI_ENTRY *SmiEntry;
UINTN Size; UINTN Size;
UINTN SmiHandlerSize; UINTN SmiHandlerSize;
UINTN SmiHandlerCount; UINT32 SmiHandlerCount;
SmiStruct = Data; SmiStruct = Data;
Size = 0; Size = 0;
@ -1132,6 +1135,36 @@ ConvertSmiHandlerUsbContext (
return SmiHandlerUsbContext; return SmiHandlerUsbContext;
} }
/**
Convert EFI_SMM_SW_REGISTER_CONTEXT to SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT.
@param SwContext A pointer to EFI_SMM_SW_REGISTER_CONTEXT
@param SwContextSize The size of EFI_SMM_SW_REGISTER_CONTEXT in bytes
@param SmiHandlerSwContextSize The size of SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT in bytes
@return SmiHandlerSwContext A pointer to SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT
**/
SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *
ConvertSmiHandlerSwContext (
IN EFI_SMM_SW_REGISTER_CONTEXT *SwContext,
IN UINTN SwContextSize,
OUT UINTN *SmiHandlerSwContextSize
)
{
SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT *SmiHandlerSwContext;
ASSERT (SwContextSize == sizeof(EFI_SMM_SW_REGISTER_CONTEXT));
SmiHandlerSwContext = AllocatePool (sizeof (SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT));
if (SmiHandlerSwContext == NULL) {
*SmiHandlerSwContextSize = 0;
return NULL;
}
SmiHandlerSwContext->SwSmiInputValue = SwContext->SwSmiInputValue;
*SmiHandlerSwContextSize = sizeof (SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT);
return SmiHandlerSwContext;
}
/** /**
This function is called by SmmChildDispatcher module to report This function is called by SmmChildDispatcher module to report
a new SMI handler is registered, to SmmCore. a new SMI handler is registered, to SmmCore.
@ -1186,6 +1219,8 @@ SmiHandlerProfileRegisterHandler (
if (Context != NULL) { if (Context != NULL) {
if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) { if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
SmiHandler->Context = ConvertSmiHandlerUsbContext (Context, ContextSize, &SmiHandler->ContextSize); SmiHandler->Context = ConvertSmiHandlerUsbContext (Context, ContextSize, &SmiHandler->ContextSize);
} else if (CompareGuid (HandlerGuid, &gEfiSmmSwDispatch2ProtocolGuid)) {
SmiHandler->Context = ConvertSmiHandlerSwContext (Context, ContextSize, &SmiHandler->ContextSize);
} else { } else {
SmiHandler->Context = AllocateCopyPool (ContextSize, Context); SmiHandler->Context = AllocateCopyPool (ContextSize, Context);
} }
@ -1261,6 +1296,8 @@ SmiHandlerProfileUnregisterHandler (
if (Context != NULL) { if (Context != NULL) {
if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) { if (CompareGuid (HandlerGuid, &gEfiSmmUsbDispatch2ProtocolGuid)) {
SearchContext = ConvertSmiHandlerUsbContext (Context, ContextSize, &SearchContextSize); SearchContext = ConvertSmiHandlerUsbContext (Context, ContextSize, &SearchContextSize);
} else if (CompareGuid (HandlerGuid, &gEfiSmmSwDispatch2ProtocolGuid)) {
SearchContext = ConvertSmiHandlerSwContext (Context, ContextSize, &SearchContextSize);
} }
} }

View File

@ -25,12 +25,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Protocol/SmmSxDispatch2.h> #include <Protocol/SmmSxDispatch2.h>
#include <Protocol/SmmUsbDispatch2.h> #include <Protocol/SmmUsbDispatch2.h>
#pragma pack(1)
typedef struct { typedef struct {
UINT32 Signature; UINT32 Signature;
UINT32 Length; UINT32 Length;
UINT32 Revision; UINT32 Revision;
UINT8 Reserved[4];
} SMM_CORE_DATABASE_COMMON_HEADER; } SMM_CORE_DATABASE_COMMON_HEADER;
#define SMM_CORE_IMAGE_DATABASE_SIGNATURE SIGNATURE_32 ('S','C','I','D') #define SMM_CORE_IMAGE_DATABASE_SIGNATURE SIGNATURE_32 ('S','C','I','D')
@ -39,12 +38,12 @@ typedef struct {
typedef struct { typedef struct {
SMM_CORE_DATABASE_COMMON_HEADER Header; SMM_CORE_DATABASE_COMMON_HEADER Header;
EFI_GUID FileGuid; EFI_GUID FileGuid;
UINTN ImageRef; PHYSICAL_ADDRESS EntryPoint;
UINTN EntryPoint; PHYSICAL_ADDRESS ImageBase;
UINTN ImageBase; UINT64 ImageSize;
UINTN ImageSize; UINT32 ImageRef;
UINT16 PdbStringOffset; UINT16 PdbStringOffset;
UINT8 Reserved2[6]; UINT8 Reserved[2];
//CHAR8 PdbString[]; //CHAR8 PdbString[];
} SMM_CORE_IMAGE_DATABASE_STRUCTURE; } SMM_CORE_IMAGE_DATABASE_STRUCTURE;
@ -64,7 +63,7 @@ typedef enum {
// NULL // NULL
// Context for SmmCoreSmiHandlerCategoryHardwareHandler: // Context for SmmCoreSmiHandlerCategoryHardwareHandler:
// (NOTE: The context field should NOT include any data pointer.) // (NOTE: The context field should NOT include any data pointer.)
// gEfiSmmSwDispatch2ProtocolGuid: EFI_SMM_SW_REGISTER_CONTEXT // gEfiSmmSwDispatch2ProtocolGuid: (EFI_SMM_SW_REGISTER_CONTEXT => SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT)
// gEfiSmmSxDispatch2ProtocolGuid: EFI_SMM_SX_REGISTER_CONTEXT // gEfiSmmSxDispatch2ProtocolGuid: EFI_SMM_SX_REGISTER_CONTEXT
// gEfiSmmPowerButtonDispatch2ProtocolGuid: EFI_SMM_POWER_BUTTON_REGISTER_CONTEXT // gEfiSmmPowerButtonDispatch2ProtocolGuid: EFI_SMM_POWER_BUTTON_REGISTER_CONTEXT
// gEfiSmmStandbyButtonDispatch2ProtocolGuid: EFI_SMM_STANDBY_BUTTON_REGISTER_CONTEXT // gEfiSmmStandbyButtonDispatch2ProtocolGuid: EFI_SMM_STANDBY_BUTTON_REGISTER_CONTEXT
@ -80,22 +79,26 @@ typedef struct {
//UINT8 DevicePath[DevicePathSize]; //UINT8 DevicePath[DevicePathSize];
} SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT; } SMI_HANDLER_PROFILE_USB_REGISTER_CONTEXT;
typedef struct {
UINT64 SwSmiInputValue;
} SMI_HANDLER_PROFILE_SW_REGISTER_CONTEXT;
typedef struct { typedef struct {
UINT32 Length; UINT32 Length;
UINTN CallerAddr; UINT32 ImageRef;
UINTN Handler; PHYSICAL_ADDRESS CallerAddr;
UINTN ImageRef; PHYSICAL_ADDRESS Handler;
UINT16 ContextBufferOffset; UINT16 ContextBufferOffset;
UINT8 Reserved2[2]; UINT8 Reserved[2];
UINT32 ContextBufferSize; UINT32 ContextBufferSize;
//UINT8 ContextBuffer[]; //UINT8 ContextBuffer[];
} SMM_CORE_SMI_HANDLER_STRUCTURE; } SMM_CORE_SMI_HANDLER_STRUCTURE;
typedef struct { typedef struct {
SMM_CORE_DATABASE_COMMON_HEADER Header; SMM_CORE_DATABASE_COMMON_HEADER Header;
UINT32 HandlerCategory;
EFI_GUID HandlerType; EFI_GUID HandlerType;
UINTN HandlerCount; UINT32 HandlerCategory;
UINT32 HandlerCount;
//SMM_CORE_SMI_HANDLER_STRUCTURE Handler[HandlerCount]; //SMM_CORE_SMI_HANDLER_STRUCTURE Handler[HandlerCount];
} SMM_CORE_SMI_DATABASE_STRUCTURE; } SMM_CORE_SMI_DATABASE_STRUCTURE;
@ -144,8 +147,6 @@ typedef struct {
#define SMI_HANDLER_PROFILE_GUID {0x49174342, 0x7108, 0x409b, {0x8b, 0xbe, 0x65, 0xfd, 0xa8, 0x53, 0x89, 0xf5}} #define SMI_HANDLER_PROFILE_GUID {0x49174342, 0x7108, 0x409b, {0x8b, 0xbe, 0x65, 0xfd, 0xa8, 0x53, 0x89, 0xf5}}
#pragma pack()
extern EFI_GUID gSmiHandlerProfileGuid; extern EFI_GUID gSmiHandlerProfileGuid;
typedef struct _SMI_HANDLER_PROFILE_PROTOCOL SMI_HANDLER_PROFILE_PROTOCOL; typedef struct _SMI_HANDLER_PROFILE_PROTOCOL SMI_HANDLER_PROFILE_PROTOCOL;