/* Prevent the memory pages used for SMM page table from been overwritten.  */
VOID EnablePageTableProtection(VOID)
/* Prevent the memory pages used for SMM page table from been overwritten.  */
VOID EnablePageTableProtection(VOID)
{
  PAGE_TABLE_POOL       *HeadPool;
  PAGE_TABLE_POOL       *Pool;
  UINT64                PoolSize;
  EFI_PHYSICAL_ADDRESS  Address;
  UINTN                 PageTableBase;
  if (mPageTablePool == NULL) {
    return;
  }
  PageTableBase = AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64;
  HeadPool = mPageTablePool;
  Pool     = HeadPool;
  do {
    Address  = (EFI_PHYSICAL_ADDRESS)(UINTN)Pool;
    PoolSize = Pool->Offset + EFI_PAGES_TO_SIZE (Pool->FreePages);
    ConvertMemoryPageAttributes (PageTableBase, mPagingMode, Address, PoolSize, EFI_MEMORY_RO, TRUE, NULL);
    Pool = Pool->NextPool;
  } while (Pool != HeadPool);
}