Page 1 of 1
problems with getting eip in an exception
Posted: Wed Mar 23, 2005 8:49 am
by Poseidon
I'm currently working on an exception handler which gives some more info than only the name of the exception ;D. My only problem is that I can't get the eip value from the stack. This is what I have currently (I've tried loads of other ways before):
Code: Select all
movl %esp, %ebp
addl $0x8, %ebp
movl (%ebp), %eax
movl %eax, (eip) // eip is here no register, but a double word from my c code.
but this crashes my whole system. Anyone ideas?
Thanks.
Re:problems with getting eip in an exception
Posted: Wed Mar 23, 2005 8:51 am
by Pype.Clicker
does this appear right in your ASM stub ?
maybe you'd like to ensure DS register has a valid value before you blindly mov things to memory
Re:problems with getting eip in an exception
Posted: Wed Mar 23, 2005 9:05 am
by Poseidon
it works now... i forgot to pop ebp from the stack :-[
i didn't really understand you pype. what value should ds have then?
Re:problems with getting eip in an exception
Posted: Wed Mar 23, 2005 9:53 pm
by AR
He's probably referring to making sure DS has a valid Kernel space segment so you aren't using the user space segment in the kernel (if that's even allowed).
Re:problems with getting eip in an exception
Posted: Thu Mar 24, 2005 3:06 am
by Pype.Clicker
Poseidon wrote:
it works now... i forgot to pop ebp from the stack :-[
hehe ... stack garbage ... the usual assembly error.
that being said, keep in mind that some exceptions (notably GPF) push an error code on the stack, and that some other don't.
i didn't really understand you pype. what value should ds have then?
AR got me right. If the exception comes from loading an invalid DS segment, or if it comes from userland, you'll be in trouble when trying to use DS. so it'd be wise to have something like
Code: Select all
exception__x:
push ebp
mov ebp, esp
pushad ;; just to make sure
push ds
push es
mov ax, KERNEL_SEGMENT
mov ds,ax
mov es,ax
__handle your exception here__
pop es
pop ds
popad
pop ebp
__add esp,4 if some error code was pushed__
iret