x86_64: pmap: enable NX protection during bootstrap

This commit is contained in:
2023-02-09 21:38:06 +00:00
parent ddb00acd31
commit d960909d1b
3 changed files with 14 additions and 0 deletions

View File

@@ -50,5 +50,6 @@ typedef enum page_size {
/* returns 1 if gigabyte pages are supported by the CPU, 0 otherwise. /* returns 1 if gigabyte pages are supported by the CPU, 0 otherwise.
defined in pmap_ctrl.S */ defined in pmap_ctrl.S */
extern int gigabyte_pages(void); extern int gigabyte_pages(void);
extern int enable_nx(void);
#endif #endif

View File

@@ -226,6 +226,8 @@ void pmap_bootstrap(void)
{ {
can_use_gbpages = gigabyte_pages(); can_use_gbpages = gigabyte_pages();
printk("pmap: gigabyte pages %sabled", can_use_gbpages == 1 ? "en" : "dis"); printk("pmap: gigabyte pages %sabled", can_use_gbpages == 1 ? "en" : "dis");
enable_nx();
printk("pmap: NX protection enabled");
page_size_t hugepage = PS_2M; page_size_t hugepage = PS_2M;
if (can_use_gbpages) { if (can_use_gbpages) {

View File

@@ -29,3 +29,14 @@ gigabyte_pages:
3: pop %rbx 3: pop %rbx
pop %rbp pop %rbp
ret ret
.global enable_nx
.type enable_nx, @function
enable_nx:
mov $0xC0000080, %ecx
rdmsr
or $0x800, %eax
wrmsr
ret