Hack Facilito
Hack Facilito

Reputation: 71

In a system call are hardware and software context saved?

Who saves the hardware and software context before the system call routine? Is it the processor itself or the software handler?

Thanks.

Upvotes: 1

Views: 328

Answers (2)

Tony Tannous
Tony Tannous

Reputation: 14863

Each system call has a wrapper function as already mentioned, each wrapper function triggers interrupt 128, int 0x80, which automatically saves on kernel stack the registers eip, esp, cs, ss, eflags. In the handling function a SAVE_ALL macro is invoked and it will push the rest of the registers on stack, when the system call is served, the values are poped to restore previous state. A iret command is invoked and the CPU pops the 5 registers it saved previously.

Upvotes: 1

user3344003
user3344003

Reputation: 21667

Usually, the way things work is that each system service has a wrapper function. That wrapper takes arguments in using the normal calling convention for the system. That wrapper unpacks the arguments and sets up the registers. Then it triggers the exception to enter kernel mode.

The kernel mode exception handler for the system service has to save registers it modifies (beyond those used for return values) and restore them upon exit.

The wrapper function take any values returned by the system service in registers and puts them into the parameters using the normal function calling convention.

Upvotes: 0

Related Questions