Page 1 of 1

Return from callgate function

Posted: Thu Apr 28, 2005 11:00 pm
by jj
Hi

I'm newbit on OS kernel dev. I'm studying about callgate on ia32 protected mode.

Af far as I know, When user mode process call kernel mode module via callgate like following.

user_process:
...
call CALLGATE1_SELECTOR:0
...

then, eip, cs, arguments(if any), esp, ss are pushed automatically, and control goes to callgate function. (to CALLGATE1_SELECTOR:offset)

My question:

in the callgate function, after performing proper work, I used instruction RET to return to user process. but, RET in callgate function POPed and restored only EIP. So cs, esp, ss of user mode process weren't restored.

Is there any other process that I miss about return processes of callgate? Is there any other specific instruction than RET instruction for returning of callgate?

Re: Return from callgate function

Posted: Tue May 03, 2005 11:00 pm
by ManOfSteel
Hello,
It seems you're talking about an inter-privilege-level switch so you need a far return (retf), AFAIK.

Re: Return from callgate function

Posted: Sun May 29, 2005 11:00 pm
by frizzz
ManOfSteel is right...
A call-gate-descriptor is meant to allow control over FAR-calls on the lowest level in the CPU (priviledge-level-control).
In fact you do not need a call-gate-descriptor, if want to call FAR (using the same priviledge level!). You only need the fitting selector and (of course) the fitting offset-adress of the procedure to call. In both cases you return in the same way : retf