diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-08-27 03:55:12 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-08-27 03:55:12 +0200 |
commit | 1e773c97e79d74983edd9b46694956f76b0c7fd5 (patch) | |
tree | 11ca8f835528c02337e7d376916ef3dabf1050e2 /sys/src/9/pc/devarch.c | |
parent | 49411b2ca15b94b6631fd54d2576c5aeff63eb67 (diff) |
pc64: implement NX bit discovery, map kernel mappings no-execute
Diffstat (limited to 'sys/src/9/pc/devarch.c')
-rw-r--r-- | sys/src/9/pc/devarch.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/sys/src/9/pc/devarch.c b/sys/src/9/pc/devarch.c index 2037f7b5b..2da6f5d55 100644 --- a/sys/src/9/pc/devarch.c +++ b/sys/src/9/pc/devarch.c @@ -899,10 +899,26 @@ cpuidentify(void) else hwrandbuf = nil; - /* 8-byte watchpoints are supported in Long Mode */ - if(sizeof(uintptr) == 8) + if(sizeof(uintptr) == 8) { + /* 8-byte watchpoints are supported in Long Mode */ m->havewatchpt8 = 1; - else if(strcmp(m->cpuidid, "GenuineIntel") == 0){ + + /* check and enable NX bit */ + cpuid(Highextfunc, regs); + if(regs[0] >= Procextfeat){ + cpuid(Procextfeat, regs); + if((regs[3] & (1<<20)) != 0){ + vlong efer; + + /* enable no-execute feature */ + if(rdmsr(Efer, &efer) != -1){ + efer |= 1ull<<11; + if(wrmsr(Efer, efer) != -1) + m->havenx = 1; + } + } + } + } else if(strcmp(m->cpuidid, "GenuineIntel") == 0){ /* some random CPUs that support 8-byte watchpoints */ if(family == 15 && (model == 3 || model == 4 || model == 6) || family == 6 && (model == 15 || model == 23 || model == 28)) |