Interrupts seem to invalidate stack
Posted: Sat Aug 13, 2022 5:12 am
I have an issue where my interrupt code seems to be corrupting the stack, which in very specific cases causes a page fault.
This is such a case:
When the return address is the first instruction a page fault is thrown at the second instruction which complains that the address 0x0 is unmapped. These page faults are thrown whenever this pattern occurs in the interrupted code.
My assembly interrupt code:
(I know not all these registers have to be stored I just did to make sure. Also, I normally use a common stub which is why the stack pointer is incremented by 8 in the beginning.)
And the called C++ code:
The page faults also occurs for keyboard and PIT interrupts, I'm just using the mouse for convenience's sake. I can also post the disassembled interrupted code if necessary.
I have been stuck on this for a while now so it would be really awesome if this issue were finally resolved, thanks in advance.
This is such a case:
Code: Select all
0xffffff8000011fce: mov -0x8(%rbp),%rax
0xffffff8000011fd2: movb $0x0,(%rax)
My assembly interrupt code:
Code: Select all
mouse_asm:
cli
sub rsp, 8
push rax
push rbx
push rcx
push rdx
push rsp
push rbp
push rsi
push rdi
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
mov ax, ds
push rax
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call _ZN11MouseDriver15HandleInterruptE9int_frame
pop rax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rdi
pop rsi
pop rbp
pop rsp
pop rdx
pop rcx
pop rbx
pop rax
add rsp, 8
sti
iretq
And the called C++ code:
Code: Select all
void MouseDriver::HandleInterrupt(int_frame frame){
while(IO::In(0x64) & 0x1) IO::In(0x60);
IO::Out(PIC1_COMMAND_PORT, 0x20);
IO::Out(PIC2_COMMAND_PORT, 0x20);
return;
}
I have been stuck on this for a while now so it would be really awesome if this issue were finally resolved, thanks in advance.