IRET Clarification

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

IRET Clarification

Post by Nessphoro »

I just want to clarify something.

When IRET returns it pops EIP , and all the general purpose registers off the stack? So if I change the EIP and some other stuff - I should technically "return" to the different place and start executing from there?
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Re: IRET Clarification

Post by jnc100 »

IRET pops EIP, CS and EFLAGS from the stack in protected mode. In other modes it pops these +/- extra stuff e.g. SS and the other segment selectors (see the Intel docs). It never pops all the general purpose registers (you have to save and restore them yourself within the interrupt handler). The ability to change the EIP value stored on the stack prior to IRET is one of the most important parts in most x86 task switchers.

Regards,
John.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: IRET Clarification

Post by bluemoon »

The behavior of IRET is well documented on the manual:

Code: Select all

PROTECTED-MODE:
IF OperandSize 32 THEN
    IF top 12 bytes of stack not within stack limits THEN
        #SS(0);
    FI;
    tempEIP <- Pop();
    tempCS <- Pop();
    tempEFLAGS <- Pop();
Which part confused you?
User avatar
Nessphoro
Member
Member
Posts: 308
Joined: Sat Apr 30, 2011 12:50 am

Re: IRET Clarification

Post by Nessphoro »

Alright thanks
Post Reply