x86_64: pmap: enable kernel-mode write-protection
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
#ifndef ARCH_PAGING_H_
|
#ifndef ARCH_PAGING_H_
|
||||||
#define ARCH_PAGING_H_
|
#define ARCH_PAGING_H_
|
||||||
|
|
||||||
#include <kernel/types.h>
|
|
||||||
#include <kernel/compiler.h>
|
#include <kernel/compiler.h>
|
||||||
|
#include <kernel/types.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -55,6 +55,7 @@ enum page_size {
|
|||||||
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);
|
extern int enable_nx(void);
|
||||||
|
extern int enable_wp(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,6 +351,8 @@ void pmap_bootstrap(void)
|
|||||||
can_use_gbpages == 1 ? "en" : "dis");
|
can_use_gbpages == 1 ? "en" : "dis");
|
||||||
enable_nx();
|
enable_nx();
|
||||||
printk("pmap: NX protection enabled");
|
printk("pmap: NX protection enabled");
|
||||||
|
enable_wp();
|
||||||
|
printk("pmap: kernel-mode write protection enabled");
|
||||||
|
|
||||||
enum page_size hugepage = PS_2M;
|
enum page_size hugepage = PS_2M;
|
||||||
if (can_use_gbpages) {
|
if (can_use_gbpages) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ gigabyte_pages:
|
|||||||
pop %rbp
|
pop %rbp
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
.global enable_nx
|
.global enable_nx
|
||||||
.type enable_nx, @function
|
.type enable_nx, @function
|
||||||
|
|
||||||
@@ -40,3 +41,14 @@ enable_nx:
|
|||||||
wrmsr
|
wrmsr
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
.global enable_wp
|
||||||
|
.type enable_wp, @function
|
||||||
|
|
||||||
|
enable_wp:
|
||||||
|
mov %cr0, %rax
|
||||||
|
or $0x10000, %rax
|
||||||
|
mov %rax, %cr0
|
||||||
|
|
||||||
|
ret
|
||||||
|
|||||||
Reference in New Issue
Block a user