From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10650a,a21070f1116c19a9,start X-Google-Attributes: gid10650a,public X-Google-Thread: fee84,a21070f1116c19a9,start X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-11-17 03:36:53 PST Newsgroups: comp.unix.internals,comp.unix.osf.osf1 Path: nntp.gmd.de!xlink.net!howland.reston.ans.net!EU.net!julienas!ubu!soft208!ram From: ram@soft208.acri.fr (Raphael Manfredi) Subject: Playing with sendsig() and sigreturn() in DEC OSF/1 Message-ID: <1994Nov17.093835.13744@acri.fr> Keywords: signal handling Sender: news@acri.fr (News Admin) Organization: A.C.R.I. Date: Thu, 17 Nov 1994 09:38:35 GMT Xref: nntp.gmd.de comp.unix.internals:4330 comp.unix.osf.osf1:6508 I have stumbled over what I believe is an interesting challenge, related to signal handling in the DEC OSF/1 kernel. We, at ACRI in the OS team, are porting DEC OSF/1 on our hardware. The kernel runs on what we call the CU (the Control Unit) but may receive errors (via interrupts) from other processors, the Stream Units (SU), which are really co-processors with a separate context. Whenever an SU detects something "bad" is happening (invalid opcode), it sends an interrupt to the CU for the kernel to handle and signal the user process by sending it an illegal instruction signal (SIGILL). This is where things are hotting up: the user process is free to catch the SIGILL, in which case three things may happen in the signal handler: + it issues a longjmp() to somewhere else. + it just returns to sigtramp(), the signal trampoline code in the libc that sensig() dispatched, where a sigreturn() is issued. (Those two cases are mostly identical since longjmp() issues a sigreturn() anyway.) + it prints an error message and exits(). End of the story. The problem arises only in the second case: the signal handler may issue some code on the CU itself, or on the SU, whose context has been fully saved anyway before calling sendsig(). However, when returning in sigreturn(), we need to re-instantiate the previous SU context before resuming, at which time the SIGILL will be sent again of course. When I have two simultaneous error conditions sent by two distinct co-processors (say a SIGILL and a SIGFPE), what will happen? As far as I understand it, the trap() handler will do something like if (issig()) psig() And in turn psig() performs something like: do { ... sendsig(); ... } while ISSIG(p); /* p is the proc */ Correct me if I am wrong, but sendsig() merely plays with the process's user stack by faking an exception frame as-if we were coming from sigtramp(), hence effectively resuming there when leaving the kernel and returning to user mode (sigtramp() being responsible for calling the user handler and performing a sigreturn() to trap again into the kernel at the end). So if two or more signals are pending simultaneously, I am stacking two "handlers", returning to user mode, jumping into the first handler, returning to kernel via sigreturn(), returning to user where the second handler is called and back to the kernel via a second sigreturn(). At which point I need to perform the restore of the previous SU context and resume. The question is: How do I know all the signals have been processed when I am in sigreturn() with little information about what's going on, so that I may (and only now) restore the SU context. Bonus question: what happens to my second handler on the stack if the first handler issues a longjmp() to transfer control elsewhere? That second stack frame should be ignored? In which case the second signal is lost? Or what? -- Raphael Manfredi Advanced Computer Research Institute 1, boulevard Marius Vivier-Merle / Tel +33 72-35-80-55 \ 69443 Lyon Cedex 03, FRANCE \ Fax +33 72-35-84-10 /