x86-64: enable smep and smap

This commit is contained in:
Matheus
2026-04-23 15:29:43 -03:00
parent b0542a165c
commit 71dd6d1125
9 changed files with 100 additions and 4 deletions
+2
View File
@@ -67,6 +67,8 @@ extern size_t arch_xsave_size;
#define CTX_ARG1(x) (x)->rsi
#define CTX_ARG2(x) (x)->rdx
#define ARCH_CONTEXT_RFLAGS_AC (1 << 18)
#define PRINT_CTX(x) { \
printf("cr2: %016lx gs: %04x\nrax: %016lx fs: %04x\nrbx: %016lx es: %04x\nrcx: %016lx ds: %04x\nrdx: %016lx cs: %04x\n r8: %016lx ss: %04x\n r9: %016lx r10: %016lx\nr11: %016lx r12: %016lx\nr13: %016lx r14: %016lx\nr15: %016lx rdi: %016lx\nrsi: %016lx rbp: %016lx\nrip: %016lx rsp: %016lx\nerr: %016lx rfl: %016lx\n", \
x->cr2, x->gs, x->rax, x->fs, x->rbx, x->es, x->rcx, x->ds, x->rdx, x->cs, x->r8, x->ss, x->r9, x->r10, x->r11, x->r12, x->r13, x->r14, x->r15, x->rdi, x->rsi, x->rbp, x->rip, x->rsp, x->error, x->rflags); \
+2
View File
@@ -114,6 +114,8 @@ static inline uint16_t be_to_cpu_w(uint16_t w) {
}
cpu_t *get_bsp(void);
void arch_cpu_user_access_begin(void);
void arch_cpu_user_access_end(void);
static inline thread_t *current_thread(void) {
thread_t *thread;
+2
View File
@@ -20,6 +20,8 @@ typedef struct {
#define CPUID_LEAF_0x80000001_EDX_SYSCALL (1 << 11)
#define CPUID_LEAF_1_EDX_TSC (1 << 4)
#define CPUID_LEAF_1_EDX_HTT (1 << 28)
#define CPUID_LEAF_7_EBX_SMEP (1 << 7)
#define CPUID_LEAF_7_EBX_SMAP (1 << 20)
static inline void cpuid_with_ecx(uint32_t leaf, uint32_t ecx, cpuid_results_t *cpuid_results) {
asm volatile ("cpuid"