SysCall: Split SMEP and SMAP initialization.

This commit is contained in:
Mikhail Krichanov 2024-09-09 08:56:05 +03:00
parent 94be39d0c5
commit 5515e17ae8
2 changed files with 22 additions and 4 deletions

View File

@ -29,10 +29,19 @@ InitializeMsr (
// Forbid supervisor-mode accesses to any user-mode pages.
//
AsmCpuidEx (0x07, 0x0, NULL, &Ebx, NULL, NULL);
if (((Ebx & BIT20) != 0) && ((Ebx & BIT7) != 0)) {
if ((Ebx & BIT7) != 0) {
Cr4.UintN = AsmReadCr4 ();
Cr4.Bits.SMEP = 1;
AsmWriteCr4 (Cr4.UintN);
Eflags.UintN = AsmReadEflags ();
Eflags.Bits.AC = 0;
AsmWriteEflags (Eflags.UintN);
}
if ((Ebx & BIT20) != 0) {
Cr4.UintN = AsmReadCr4 ();
Cr4.Bits.SMAP = 1;
Cr4.Bits.SMEP = 1;
AsmWriteCr4 (Cr4.UintN);
Eflags.UintN = AsmReadEflags ();

View File

@ -30,10 +30,19 @@ InitializeMsr (
// Forbid supervisor-mode accesses to any user-mode pages.
//
AsmCpuidEx (0x07, 0x0, NULL, &Ebx, NULL, NULL);
if (((Ebx & BIT20) != 0) && ((Ebx & BIT7) != 0)) {
if ((Ebx & BIT7) != 0) {
Cr4.UintN = AsmReadCr4 ();
Cr4.Bits.SMEP = 1;
AsmWriteCr4 (Cr4.UintN);
Eflags.UintN = AsmReadEflags ();
Eflags.Bits.AC = 0;
AsmWriteEflags (Eflags.UintN);
}
if ((Ebx & BIT20) != 0) {
Cr4.UintN = AsmReadCr4 ();
Cr4.Bits.SMAP = 1;
Cr4.Bits.SMEP = 1;
AsmWriteCr4 (Cr4.UintN);
Eflags.UintN = AsmReadEflags ();