3

If the OS wants to deliver a signal to a process, it calls a function from the process, the signal handler. Will the signal handler later return to kernel code, which will return to the instruction it interrupted when delivering the signal, or will the signal handler return to the normal execution of the process itself?

  • Is this just curiosity, or do you think it makes a difference in your application? – Barmar Jul 21 '22 at 14:48
  • @Barmar: I think yes (and so I think I can guess an answer which I don't known). On second case signal will be re-entrant (a signal could be called during a signal), and one could do a longjump without problems (but being re-entrant). On the first case only one signal at a time. Plus there may be larger delay between signal and outer code. So https://stackoverflow.com/questions/1715413/longjmp-from-signal-handler may provide the answer – Giacomo Catenazzi Jul 21 '22 at 14:56
  • 4
    Effectively, the signal handler is called from the kernel, but not as a normal function call. It just manipulates the stack so that the signal handler is entered when the task returns from kernel mode to user mode, and so that when the signal handler function returns normally, it returns to a bit of code that invokes the `sigreturn` or `rt_sigreturn` system call to complete the handling of the signal. Part of that completion is the restoration of the task's stack so that it can return from the original system call or interrupt handling that caused it to enter kernel mode in the first place. – Ian Abbott Jul 21 '22 at 18:29

0 Answers0