AsmWriteMsr64 (0xC0000080, MsrRegisters);\r
}\r
\r
+/**\r
+ The function will check if page table entry should be splitted to smaller\r
+ granularity.\r
+\r
+ @retval TRUE Page table should be split.\r
+ @retval FALSE Page table should not be split.\r
+**/\r
+BOOLEAN\r
+ToSplitPageTable (\r
+ IN EFI_PHYSICAL_ADDRESS Address,\r
+ IN UINTN Size,\r
+ IN EFI_PHYSICAL_ADDRESS StackBase,\r
+ IN UINTN StackSize\r
+ )\r
+{\r
+ if (IsNullDetectionEnabled () && Address == 0) {\r
+ return TRUE;\r
+ }\r
+\r
+ if (PcdGetBool (PcdCpuStackGuard)) {\r
+ if (StackBase >= Address && StackBase < (Address + Size)) {\r
+ return TRUE;\r
+ }\r
+ }\r
+\r
+ if (PcdGetBool (PcdSetNxForStack)) {\r
+ if ((Address < StackBase + StackSize) && ((Address + Size) > StackBase)) {\r
+ return TRUE;\r
+ }\r
+ }\r
+\r
+ return FALSE;\r
+}\r
/**\r
Split 2M page to 4K.\r
\r
PageTableEntry->Uint64 = (UINT64) PhysicalAddress4K | AddressEncMask;\r
PageTableEntry->Bits.ReadWrite = 1;\r
\r
- if (IsNullDetectionEnabled () && PhysicalAddress4K == 0) {\r
+ if ((IsNullDetectionEnabled () && PhysicalAddress4K == 0) ||\r
+ (PcdGetBool (PcdCpuStackGuard) && PhysicalAddress4K == StackBase)) {\r
PageTableEntry->Bits.Present = 0;\r
} else {\r
PageTableEntry->Bits.Present = 1;\r
\r
PhysicalAddress2M = PhysicalAddress;\r
for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PhysicalAddress2M += SIZE_2MB) {\r
- if ((IsNullDetectionEnabled () && PhysicalAddress2M == 0)\r
- || (PcdGetBool (PcdSetNxForStack)\r
- && (PhysicalAddress2M < StackBase + StackSize)\r
- && ((PhysicalAddress2M + SIZE_2MB) > StackBase))) {\r
+ if (ToSplitPageTable (PhysicalAddress2M, SIZE_2MB, StackBase, StackSize)) {\r
//\r
// Need to split this 2M page that covers NULL or stack range.\r
//\r
PageDirectory1GEntry = (VOID *) PageDirectoryPointerEntry;\r
\r
for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress += SIZE_1GB) {\r
- if ((IsNullDetectionEnabled () && PageAddress == 0)\r
- || (PcdGetBool (PcdSetNxForStack)\r
- && (PageAddress < StackBase + StackSize)\r
- && ((PageAddress + SIZE_1GB) > StackBase))) {\r
+ if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSize)) {\r
Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry, StackBase, StackSize);\r
} else {\r
//\r
PageDirectoryPointerEntry->Bits.Present = 1;\r
\r
for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress += SIZE_2MB) {\r
- if ((IsNullDetectionEnabled () && PageAddress == 0)\r
- || (PcdGetBool (PcdSetNxForStack)\r
- && (PageAddress < StackBase + StackSize)\r
- && ((PageAddress + SIZE_2MB) > StackBase))) {\r
+ if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackSize)) {\r
//\r
// Need to split this 2M page that covers NULL or stack range.\r
//\r