/* Frees a buffer that was previously allocated at runtime phase. */
VOID RuntimeFreeMem(IN VOID *Buffer)
/* Frees a buffer that was previously allocated at runtime phase. */
VOID RuntimeFreeMem(IN VOID *Buffer)
{
  UINTN  StartOffset;
  UINTN  StartPageIndex;
  StartOffset    = (UINTN)Buffer - (UINTN)mRTPageTable->DataAreaBase;
  StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->Pages[RT_SIZE_TO_PAGES (StartOffset)].StartPageOffset);
  while (StartPageIndex < mRTPageTable->PageCount) {
    if (((mRTPageTable->Pages[StartPageIndex].PageFlag & RT_PAGE_USED) != 0) &&
        (mRTPageTable->Pages[StartPageIndex].StartPageOffset == StartOffset))
    {
      mRTPageTable->Pages[StartPageIndex].PageFlag       &= ~RT_PAGE_USED;
      mRTPageTable->Pages[StartPageIndex].PageFlag       |= RT_PAGE_FREE;
      mRTPageTable->Pages[StartPageIndex].StartPageOffset = 0;
      StartPageIndex++;
    } else {
      break;
    }
  }
  return;
}