system call, exception, divided by 0, etc they all have the same vector entry in linux. If in x86, it is 0x80, right ? So what about signal ? Does OS also use int 0x80 for signal to a process ? if yes, who calls it ? We know if you want trap in kernel, you have to call int 0x80 or its wrapper like system call, but for the case of signal, who calls 0x80 ?
preguntado el 02 de febrero de 12 a las 10:02
First of all,. int 0x80 is not used by modern OS on modern Intel CPUs for a long time now. the sysenter instruction is typically used noways (see: http://siyobik.info/main/reference/instruction/SYSENTER).
As for signals, you have two cases -
If the target of the signal is NOT running on the CPU when the signal is sent, then sending a signal is nothing more then marking a bit in a kernel data structure that indicated to the kernel that when it schedules that process back into the CPU to put the program counter to the signal handling routine rather then the original PC.
If however the program you send the signal to is running on a CPU when a signal is sent, the signal is triggered as an interrupt - if the signal is synchronous (such as divide by zero exception), the interrupt is the exception interrupt that is generated from the CPU core. If the signal is async (such as another process running on another core sending a signal), the interrupt is the inter processor interrupt sent from that other core.
So, no int 0x80 anywhere then :-)
Basically signals are not like interrupts. The user-level process is periodically interrupted by kernel. When it is about to send a signal to the user-level process, the kernel just makes the instruction pointer of the user-level process to point to the signal handler code before scheduling it again. It also sets the stacks and other registers accordingly.
Cuando llamas a un
syscall, tu usas
However, when you receive a signal, whether from another process or
SIGFPE, no tienes que llamar
int 0x80 para conseguirlo.
What happens is that the timer interrupt that handles calling
sched_tick also checks if there is a signal pending before returning control to the user-space process, and if one exists (and the signal mask allows it), calls the appropriate signal handler.