From 34775633b23e79c3d99196ef84575d3e5f463640 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 17 Jan 2025 16:11:13 +0200 Subject: [PATCH] Kernel: Clear DF on every interrupt handler I was missing this and it lead to UB with my new mem* functions that were implemented with `rep` --- kernel/arch/i686/Syscall.S | 1 + kernel/arch/i686/interrupts.S | 5 +++++ kernel/arch/x86_64/Syscall.S | 1 + kernel/arch/x86_64/interrupts.S | 6 +++++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/arch/i686/Syscall.S b/kernel/arch/i686/Syscall.S index 4edf07cc..6cf888d2 100644 --- a/kernel/arch/i686/Syscall.S +++ b/kernel/arch/i686/Syscall.S @@ -14,6 +14,7 @@ asm_syscall_handler: pushl %edi pushl %esi pushl %ebp + cld # align stack movl %esp, %ebp diff --git a/kernel/arch/i686/interrupts.S b/kernel/arch/i686/interrupts.S index 3f2b6bb7..c0b9089d 100644 --- a/kernel/arch/i686/interrupts.S +++ b/kernel/arch/i686/interrupts.S @@ -27,6 +27,7 @@ isr_stub: push_userspace load_kernel_segments + cld movl %cr0, %eax; pushl %eax movl %cr2, %eax; pushl %eax @@ -58,6 +59,7 @@ isr_stub: irq_stub: push_userspace load_kernel_segments + cld movl 40(%esp), %eax # interrupt number @@ -79,6 +81,7 @@ irq_stub: asm_yield_handler: # This can only be called from kernel, so no segment saving is needed pushal + cld movl %esp, %eax # interrupt registers ptr leal 32(%esp), %ebx # interrupt stack ptr @@ -101,6 +104,7 @@ asm_yield_handler: asm_ipi_handler: push_userspace load_kernel_segments + cld movl %esp, %ebp subl $15, %esp @@ -118,6 +122,7 @@ asm_ipi_handler: asm_timer_handler: push_userspace load_kernel_segments + cld movl %esp, %ebp subl $15, %esp diff --git a/kernel/arch/x86_64/Syscall.S b/kernel/arch/x86_64/Syscall.S index 878e24c6..ac447607 100644 --- a/kernel/arch/x86_64/Syscall.S +++ b/kernel/arch/x86_64/Syscall.S @@ -16,6 +16,7 @@ asm_syscall_handler: pushq %r13 pushq %r14 pushq %r15 + cld movq %rsi, %r8 movq %rdi, %r9 diff --git a/kernel/arch/x86_64/interrupts.S b/kernel/arch/x86_64/interrupts.S index c394d5c0..8f6effb2 100644 --- a/kernel/arch/x86_64/interrupts.S +++ b/kernel/arch/x86_64/interrupts.S @@ -36,7 +36,7 @@ isr_stub: pushaq - + cld movq %cr0, %rax; pushq %rax movq %cr2, %rax; pushq %rax movq %cr3, %rax; pushq %rax @@ -55,6 +55,7 @@ isr_stub: irq_stub: pushaq + cld movq 120(%rsp), %rdi # irq number call cpp_irq_handler popaq @@ -64,6 +65,7 @@ irq_stub: .global asm_yield_handler asm_yield_handler: pushaq + cld leaq 120(%rsp), %rdi # interrupt stack ptr movq %rsp, %rsi # interrupt register ptr call cpp_yield_handler @@ -73,6 +75,7 @@ asm_yield_handler: .global asm_ipi_handler asm_ipi_handler: pushaq + cld call cpp_ipi_handler popaq iretq @@ -80,6 +83,7 @@ asm_ipi_handler: .global asm_timer_handler asm_timer_handler: pushaq + cld call cpp_timer_handler popaq iretq