Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

task gate, interrupt gate, call gate

I have been trying to read more about different gates in x86 architecture. If I understand correctly then interrupt and trap gate are used for hw and sw interrupt handling respectively. Whereas CALL gate is probably no more used, as ppl prefer replaced by SYSENTER and SYSEXIT.

I was wondering how task gates are used (I know they are used for hw task switch). What does that exactly mean? Does hw task refer to OS task/process. Or is it more like switching between two different instances of operating system. (May be on servers.)?

On a side note, can it happen that some of the interrupts are handled in the user mode. (Can we handle divide by zero interrupt in the user mode. If it can be then does that mean IDT handler entry for divide by zero contains address from the user space?)

Thanks

like image 288
agent.smith Avatar asked Jul 13 '11 17:07

agent.smith


1 Answers

Everything you might want to know about interrupts and gates is in the Intel developer manual, volume 3. In short:

  • Task gates were originally designed as a CPU-mediated method of performing task switching; the CPU can automatically record the state of the process during the task switching operation. These are not typically used in modern operating systems; the OS usually does the state-saving operations on its own.
  • At least in Linux, all interrupt handlers are in kernel space and execute at ring 0. If you want to handle a divide-by-zero exception, you register a userspace signal handler for SIGFPE; the kernel-space interrupt handler raises the SIGFPE signal, indirectly triggering the userspace handler code (the userspace code is executed after returning from the interrupt handler).
like image 103
bdonlan Avatar answered Jan 03 '23 06:01

bdonlan