/* This means that SetMemorySpaceAttributes() has chance to run in SMM mode. This will cause incorrect result because SMM mode always loads its own page tables, which are usually different from DXE. This function can be used to detect such situation and help to avoid further misoperations. */
BOOLEAN IsInSmm(VOID)
/* This means that SetMemorySpaceAttributes() has chance to run in SMM mode. This will cause incorrect result because SMM mode always loads its own page tables, which are usually different from DXE. This function can be used to detect such situation and help to avoid further misoperations. */
BOOLEAN IsInSmm(VOID)
{
  BOOLEAN  InSmm;
  InSmm = FALSE;
  if (mSmmBase2 == NULL) {
    gBS->LocateProtocol (&gEfiSmmBase2ProtocolGuid, NULL, (VOID **)&mSmmBase2);
  }
  if (mSmmBase2 != NULL) {
    mSmmBase2->InSmm (mSmmBase2, &InSmm);
  }
  return (InSmm &&
          mPagingContext.ContextData.X64.PageTableBase != (UINT64)AsmReadCr3 ());
}