[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
The following issue has a resolution that has been APPLIED. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: Applied Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text:See https://austingroupbugs.net/view.php?id=1731#c6327. Resolution: Accepted As Marked Fixed in Version: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-08-17 11:01 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 2023-05-31 19:50 kreNote Added: 0006296 2023-06-06 15:50 geoffclare Note Added: 0006312 2023-06-06 19:24 kreNote Added: 0006313 2023-06-07 09:44 geoffclare Note Added: 0006314 2023-06-09 11:24 kreNote Added: 0006316 2023-06-12 08:55 geoffclare Note Added: 0006319 2023-06-12 09:08 geoffclare Note Edited: 0006319 2023-06-12 13:08 kreNote Added: 0006320 2023-06-12 13:13 kreNote Edited: 0006320 2023-06-12 14:38 geoffclare Note Edited: 0006319 2023-06-12 22:18 kreNote Added: 0006325 2023-06-12 22:21 kreNote Edited: 0006325 2023-06-13 09:09 dannyniu Issue Monitored: dannyniu 2023-06-13 09:29 geoffclare Note Added: 0006326 2023-06-13 09:47 geoffclare Note Added: 0006327 2023-07-31 15:38 Don Cragun Final Accepted Text => See https://austingroupbugs.net/view.php?id=1731#c6327. 2023-07-31 15:38 Don Cragun Status New => Resolved 2023-07-31 15:38 Don Cragun Resolution Open => Accepted As Marked 2023-07-31 15:39 Don Cragun Tag Attached: tc3-2008 2023-08-17 11:01 geoffclare Status Resolved => Applied ==
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
The following issue has been RESOLVED. == https://www.austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: Resolved Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text:See https://www.austingroupbugs.net/view.php?id=1731#c6327. Resolution: Accepted As Marked Fixed in Version: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-07-31 15:38 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 2023-05-31 19:50 kreNote Added: 0006296 2023-06-06 15:50 geoffclare Note Added: 0006312 2023-06-06 19:24 kreNote Added: 0006313 2023-06-07 09:44 geoffclare Note Added: 0006314 2023-06-09 11:24 kreNote Added: 0006316 2023-06-12 08:55 geoffclare Note Added: 0006319 2023-06-12 09:08 geoffclare Note Edited: 0006319 2023-06-12 13:08 kreNote Added: 0006320 2023-06-12 13:13 kreNote Edited: 0006320 2023-06-12 14:38 geoffclare Note Edited: 0006319 2023-06-12 22:18 kreNote Added: 0006325 2023-06-12 22:21 kreNote Edited: 0006325 2023-06-13 09:09 dannyniu Issue Monitored: dannyniu 2023-06-13 09:29 geoffclare Note Added: 0006326 2023-06-13 09:47 geoffclare Note Added: 0006327 2023-07-31 15:38 Don Cragun Final Accepted Text => See https://www.austingroupbugs.net/view.php?id=1731#c6327. 2023-07-31 15:38 Don Cragun Status New => Resolved 2023-07-31 15:38 Don Cragun Resolution Open => Accepted As Marked ==
Re: [1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
Date:Wed, 14 Jun 2023 12:56:16 -0500 From:"G. Branden Robinson via austin-group-l at The Open Group" Message-ID: <20230614175616.ilqpqzpbeiipu7s7@illithid> | The question is, did thread A receive SIGINT or not? No, that isn't the question at all. That's a simple race, and irrelevant to the current discussion. | Is the current draft language therefore redundant? Can lines 59787-8 be | deleted without damaging anything? Those line numbers in which draft? In the current draft (the most recent available one, Issue 8 draft 3) those are the (whole) DESCRIPTION section of pthread_setspecific() - and something tells me that's not what you're proposing removing. In e-mail, it is generally better to quote the lines, than line numbers, that's something everyone can understand, and can know exactly which text is in question - at the minute I'm not sure what you're referring to. For large sections, unless some specific wording therein is important, it's OK to just quote the first part and the ending, we can find the whole thing in the draft that way. But do always make it clear which section (for XSH 3 and XCU 3 give the function/utility name, elsewhere the section number, and ideally its title, as numbers sometimes alter). | Thanks for emphasizing the narrow scope. I've tried to direct my reply | accordingly. Except the narrow scope related to what happens when the signal mask is changed to unblock signals that were blocked, and in particular, when one (or more) of those signals are pending. You concentrated on the exact opposite case, when blocking a signal, which has no particular issues at all. The issue here is that the current standard contains language which while clear enough about its intent, is logically absurd (it requires something to be done after, and at the same time before, something else). We could just leave it alone - no-one is going to doubt what it means. But fixing it would be better - and we now have language that does that which works. Beyond that, an APPLICATION USAGE section is being added (technically, it is already there, but just says "None" - that "None" is being replaced by other text) to explain to application writers what can happen, to avoid misunderstandings. The wording of that is the most recent topic of discussion, but that's settled now too. In both cases, naturally, unless someone else sees a problem with them. There never really was anything substantive here, it is all just wording things properly. kre
Re: [1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
At 2023-06-14T06:00:51+0700, Robert Elz via austin-group-l at The Open Group wrote: > Date:Tue, 13 Jun 2023 16:38:54 -0500 > From:"G. Branden Robinson via austin-group-l at The Open Group" > > Message-ID: <20230613213854.hk3z6zzpkhdiunsk@illithid> > > | I apologize for the possibly academic recapitulation of multitasking, > | but the key point is that the foregoing model does not require the > | process to "enter the kernel" to service the signal. > > "enter" was perhaps a poor choice of words, for the general case, "be > in" might be better. Okay. I prefer to think of user-space code as clients that are either running or a kernel service (possibly a message passed from another user thread)...but I've spent some time working with a microkernel so my perspective may be a little unorthodox. :) > But Geoff's message, to which I was replying, said: > > is currently running, and is executing user code. > > A process in that state was the one to which I was referring. Such > a process must actually enter the kernel (since it is not there at the > time) in order for the kernel to deliver a signal to it. I think the foregoing would be a misleading characterization of the preëmption model I described, but that doesn't have to concern POSIX. [...] > The issue was that even in that case, the signal is pending for some > period (usually a very short period, perhaps just a few microseconds, > but also possibly longer). I agree that there is a finite time between the kernel electing, or being directed to, preëmpt a user thread, and that preëmption taking place. [...] > [when returning from a signal handler] - that's true in most cases, but > not if the signal handler blocked signals as part of its invocation. > In that case, some kind of call to the kernel is needed to return the > signal mask to its state before the handler was invoked. Yes--I elided too much context in my original reply. > | I guess the question from the POSIX perspective is whether a > | signal can be pending if a process cannot observe it to be. > > I don't think that matters. The notion is used as a mechanism to > allow the existence of signals which do not get immediately delivered > to the process. No, you're right--I think your comment #6320 on Mantis captured the practical importance of getting the wording right: "Anything that arrives at the same time as the call is being processed is just in a race to see which of those two cases it is considered equivalent to." I will recapitulate in an effort to verify my understanding (and perhaps others'). 1. Thread A calls pthread_sigmask to block SIGINT. 2. Something with permission to signal thread A calls kill(..., SIGINT). 3. Thread A returns from pthread_sigmask. The question is, did thread A receive SIGINT or not? It of course depends. There is no guarantee that pthread_sigmask will run atomically; it has to validate its parameters, it might be part of a user-mode threading implementation (e.g., "green threads" or something similar to the Ada tasking model [as long as it uses POSIX threads underneath]). Moreover, pthread_sigmask does not impose a lock on the rest of the system while it operates. So just like hardware getting a spurious interrupt (by the time the CPU goes to service the interrupt, the device has stopped asserting it), a thread may receive a blocked signal in a small window of time "after" calling pthread_sigmask() to block that very signal. Isn't this one of the things that signal-masking programs simply have to be prepared for? It looks to me like lines 44125-38 (under "kill" in XSH) in Issue 8 draft 2.1 address this issue. And the "RATIONALE" of pthread_sigmask() already refers to it (line 59867). Is the current draft language therefore redundant? Can lines 59787-8 be deleted without damaging anything? > The recent discussion has been entirely about how to write down the > notion that a signal might be delivered to a process while it is > executing the function that unblocks (other) signals. Thanks for emphasizing the narrow scope. I've tried to direct my reply accordingly. > ps: SIGQUIT is not an "un-handleable signal" - the only signals that > cannot be caught, are SIGKILL and SIGSTOP. There's nothing > particularly special about SIGQUIT at all. Yes, you are right; I had a brain fart that I really should not have had given the number of times I've typed "trap ... HUP INT QUIT TERM" in shell scripts. Regards, Branden signature.asc Description: PGP signature
Re: [1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
On Wed, Jun 14, 2023 at 02:36:03AM +0700, Robert Elz via austin-group-l at The Open Group wrote: > Date:Tue, 13 Jun 2023 09:29:52 + > From:Austin Group Bug Tracker > Message-ID: <[email protected]> > > | Then there is > | nothing to delay the delivery - it can happen immediately after > generation, > > No, it can't in that case, it needs to wait until the process enters the > kernel for some reason. Typically if a signal is delivered to a process > while it is in application mode, it will be the result of a kill() from I suspect that it would be more likely to be an external interrupt (timer (e.g. timeslice), I/O device, etc) that interrupts the target process than a third-party signal. scott
Re: [1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
Date:Tue, 13 Jun 2023 16:38:54 -0500 From:"G. Branden Robinson via austin-group-l at The Open Group" Message-ID: <20230613213854.hk3z6zzpkhdiunsk@illithid> | I apologize for the possibly academic recapitulation of multitasking, | but the key point is that the foregoing model does not require the | process to "enter the kernel" to service the signal. "enter" was perhaps a poor choice of words, for the general case, "be in" might be better. But Geoff's message, to which I was replying, said: is currently running, and is executing user code. A process in that state was the one to which I was referring. Such a process must actually enter the kernel (since it is not there at the time) in order for the kernel to deliver a signal to it. And yes, there is something about kernel design being assumed here, but that's not particularly important to anything. The issue was that even in that case, the signal is pending for some period (usually a very short period, perhaps just a few microseconds, but also possibly longer). It is never true, even in the simplest case: kill(getpid(), SIGwhatever) that the signal is not pending for some period. Even when that system call results in no context switch, and "immediately" invokes the application's SIGwhatever handler, there is a brief period, between when the signal is posted, and the handler is invoked. During that period, the signal is pending, as that is defined. This one, on a fast processor, may be for considerably less than a microsecond, but it is never zero. | There's arguably not much difference between your presentation and mine; | in mine, something special and kernelly _might_ need to happen when | returning from the signal handler, returning from the signal handler isn't the issue, it is calling it in the first place. Signals are kernel events, for the application handler to be invoked (in application space, running application code) the kernel needs to be running, to set up the application environment. While the application could have something resembling signal handlers which operate entirely without kernel assistance, those would not be actual signal handlers. | No mode switch is necessary. [when returning from a signal handler] - that's true in most cases, but not if the signal handler blocked signals as part of its invocation. In that case, some kind of call to the kernel is needed to return the signal mask to its state before the handler was invoked. | I guess the question from the POSIX perspective is whether a signal can | be pending if a process cannot observe it to be. I don't think that matters. The notion is used as a mechanism to allow the existence of signals which do not get immediately delivered to the process. | That's good. I surmise, then, that "signal | pendingness" is not a trait that POSIX needs to define, or even employ. Perhaps not, but it does. | The standard should avoid the term if using it--even just for expository | purposes--is going to provoke controversy among highly seasoned Unix | kernel engineers who are accustomed to using it with a more | implementation-specific meaning. No, there has been no controversy here about what that means (with the slight glitch when I didn't bother to look at the POSIX definition, and thought that possibly only unblocked signals were considered pending, but that was just my laziness coming through). The recent discussion has been entirely about how to write down the notion that a signal might be delivered to a process while it is executing the function that unblocks (other) signals. kre ps: SIGQUIT is not an "un-handleable signal" - the only signals that cannot be caught, are SIGKILL and SIGSTOP. There's nothing particularly special about SIGQUIT at all.
Re: [1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
At 2023-06-14T02:36:03+0700, Robert Elz via austin-group-l at The Open Group wrote: > Date:Tue, 13 Jun 2023 09:29:52 + > From:Austin Group Bug Tracker > Message-ID: <[email protected]> > > | You don't seem to have considered the case where the thread that > | receives the signal is currently running, and is executing user > | code. > > No, that's one of the shortish pending cases. > > | Then there is nothing to delay the delivery - it can happen > | immediately after generation, > > No, it can't in that case, it needs to wait until the process enters > the kernel for some reason. Typically if a signal is delivered to a > process while it is in application mode, it will be the result of a > kill() from another process running on a different CPU (anything the > process does to itself, including traps, result in the process being > in the kernel when the signal is delivered - the kernel side of the > process is posting the signal to itself). When that happens, the > other CPU (the one running the application) needs to be notified that > there's an event it needs to process, which will result in that > process being (temporarily) suspended and the kernel taking over. This seems to me to assume too much about kernel design. A process could be preempted (signalled) by being frozen as-is: its memory image, stack(s), and registers saved. If the kernel elected to revive it for signal delivery--it would not for un-handleable signals like POSIX KILL or QUIT--then the kernel could start it up again, possibly on a different core, with its memory image and stacks restored, a new stack frame (possibly on an alternate stack) holding the former register values (possibly with other housekeeping information), and the program counter set to the entry point for the appropriate signal handler (possibly with supplemental information about the signal's cause or process state at interruption in registers). I apologize for the possibly academic recapitulation of multitasking, but the key point is that the foregoing model does not require the process to "enter the kernel" to service the signal. There's arguably not much difference between your presentation and mine; in mine, something special and kernelly _might_ need to happen when returning from the signal handler, but off the top of my head that doesn't need to be done in kernel mode either; your program runtime support library can have a helper procedure that resets the registers (including the program counter) from the temporary stack frame mentioned above. All the signal handler has to do is jump to this helper. No mode switch is necessary. > When that is done (which may be immediate, or may be later if the cpu > in consideration switches to some other process) and the kernel is > returning control to the application, is when the signal is delivered. > In the interim period (which may be very short, or may be lengthy (in > computer terms anyway)) the signal is pending. But not blocked. (Of > course, that is assuming it wasn't being blocked). I guess the question from the POSIX perspective is whether a signal can be pending if a process cannot observe it to be. In the scenario I present above, I don't think it is. Checking the 2.1 draft of Issue 8, the "ps" command admits a "status" field for process state but prescribes no values. That's good. I surmise, then, that "signal pendingness" is not a trait that POSIX needs to define, or even employ. The standard should avoid the term if using it--even just for expository purposes--is going to provoke controversy among highly seasoned Unix kernel engineers who are accustomed to using it with a more implementation-specific meaning. Apologies in advance if I said something stupid. Regards, Branden signature.asc Description: PGP signature
Re: [1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
Date:Tue, 13 Jun 2023 09:29:52 + From:Austin Group Bug Tracker Message-ID: <[email protected]> | You don't seem to have considered the case where the thread that receives | the signal is currently running, and is executing user code. No, that's one of the shortish pending cases. | Then there is | nothing to delay the delivery - it can happen immediately after generation, No, it can't in that case, it needs to wait until the process enters the kernel for some reason. Typically if a signal is delivered to a process while it is in application mode, it will be the result of a kill() from another process running on a different CPU (anything the process does to itself, including traps, result in the process being in the kernel when the signal is delivered - the kernel side of the process is posting the signal to itself). When that happens, the other CPU (the one running the application) needs to be notified that there's an event it needs to process, which will result in that process being (temporarily) suspended and the kernel taking over. When that is done (which may be immediate, or may be later if the cpu in consideration switches to some other process) and the kernel is returning control to the application, is when the signal is delivered. In the interim period (which may be very short, or may be lengthy (in computer terms anyway)) the signal is pending. But not blocked. (Of course, that is assuming it wasn't being blocked). | Having said that, it would make sense to reword to avoid any subtle | distinctions about exactly when a signal becomes pending. I will try to | come up with something that merges parts of your suggestion with parts of | my previous attempt. Your new version looks OK to me. Still not sure the APPLICATION USAGE section is needed however. kre
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-06-13 09:47 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006327) geoffclare (manager) - 2023-06-13 09:47 https://austingroupbugs.net/view.php?id=1731#c6327 -- New suggested resolution ... After applying bug 1636, change:If there are any pending unblocked signals after the call to pthread_sigmask(), at least one of those signals shall be delivered before the call to pthread_sigmask() returns.to:If the argument set is not a null pointer, after pthread_sigmask() changes the currently blocked set of signals it shall determine whether there are any pending unblocked signals; if there are any, then at least one of those signals shall be delivered before the call to pthread_sigmask() returns. On page 1736 line 56316 section pthread_sigmask(), change APPLICATION USAGE from:None.to:Although pthread_sigmask() has to deliver at least one of any pending unblocked signals that exist after it has changed the currently blocked set of signals, there is no requirement that the delivered signal(s) include any that were unblocked by the change. If one or more signals that were already unblocked become pending (see [xref to 2.4.1]) during the period the pthread_setmask() call is executing, the signal(s) delivered before the call returns might include only those signals. Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 2023-05-31 19:50 kreNote Added: 0006296 2023-06-06 15:50 geoffclare Note Added: 0006312 2023-06-06 19:24 kreNote Added: 0006313 2023-06-07 09:44 geoffclare Note Added: 0006314 2023-06-09 11:24 kreNote Added: 0006316 2023-06-12 08:55 geoffclare Note Added: 0006319 2023-06-12 09:08 geoffclare Note Edited: 0006319 2023-06-12 13:08 kreNote Added: 0006320 2023-06-12 13:13 kreNote Edited: 0006320 2023-06-12 14:38 geoffclare Note Edited: 0006319 2023-06-12 22:18 kreNote Added: 0006325 2023-06-12 22:21 kreNote Edited: 0006325 2023-06-13 09:09 dannyniu Issue Monitored: dannyniu 2023-06-13 09:29 geoffclare Note Added: 0006326
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-06-13 09:29 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006326) geoffclare (manager) - 2023-06-13 09:29 https://austingroupbugs.net/view.php?id=1731#c6326 -- Re https://austingroupbugs.net/view.php?id=1731#c6325 > all signals become pending when generated (for a short while at least, > sometimes very short) all being blocked does is prevent them from being > delivered for longer (until they are unblocked) - but they are always > pending from the instant they are generated, until the system has an > opportunity to resume execution of the process (or thread) next You don't seem to have considered the case where the thread that receives the signal is currently running, and is executing user code. Then there is nothing to delay the delivery - it can happen immediately after generation, if the signal is not being blocked; it only becomes pending if it is being blocked. Having said that, it would make sense to reword to avoid any subtle distinctions about exactly when a signal becomes pending. I will try to come up with something that merges parts of your suggestion with parts of my previous attempt. Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 2023-05-31 19:50 kreNote Added: 0006296 2023-06-06 15:50 geoffclare Note Added: 0006312 2023-06-06 19:24 kreNote Added: 0006313 2023-06-07 09:44 geoffclare Note Added: 0006314 2023-06-09 11:24 kreNote Added: 0006316 2023-06-12 08:55 geoffclare Note Added: 0006319 2023-06-12 09:08 geoffclare Note Edited: 0006319 2023-06-12 13:08 kreNote Added: 0006320 2023-06-12 13:13 kreNote Edited: 0006320 2023-06-12 14:38 geoffclare Note Edited: 0006319 2023-06-12 22:18 kreNote Added: 0006325 2023-06-12 22:21 kreNote Edited: 0006325 2023-06-13 09:09 dannyniu Issue Monitored: dannyniu 2023-06-13 09:29 geoffclare Note Added: 0006326 ==
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-06-12 22:18 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006325) kre (reporter) - 2023-06-12 22:18 https://austingroupbugs.net/view.php?id=1731#c6325 -- wrt the updated https://austingroupbugs.net/view.php?id=1731#c6319 I'd simply delete the whole sentence starting "In particular..." and replace it with something more like It is possible that an unrelated signal (or signals) become pending [xref] during the period the pthread_setmask() call is executing. One (or more) of those signals may be delivered to the application instead of, or in addition to, any previously blocked pending signals that were unblocked by the pthread_setmask() call. Or something along those lines, but ideally briefer. The new wording "when a signal is generated it can become pending for reasons other than being blocked" is no better than the previous attempt, all signals become pending when generated (for a short while at least, sometimes very short) all being blocked does is prevent them from being delivered for longer (until they are unblocked) - but they are always pending from the instant they are generated, until the system has an opportunity to resume execution of the process (or thread) next - in the simplest case (a system call results in a signal being posted to the invoking process) that is at least for whatever time remains during the processing/cleanup of the system call in question. In other cases (a signal delivered to a process that is swapped out) the delay before it can be resumed can be considerable - that could even happen during a pthread_sigmask() call, if the scheduler decides to run a higher priority process instead of the caller, which is then blocked waiting upon a suitable CPU, and could get swapped out while it is waiting. Unlikely perhaps on modern systems, but on some ancient systems, that kind of thing happened all the time, and is still possible. Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 2023-05-31 19:50 kreNote Added: 0006296 2023-06-06 15:50 geoffclare Note Added: 0006312 2023-06-06 19:24 kreNote Added: 0006313 2023-06-07 09:44 geoffclare Note Added: 0006314 2023-06-09 11:24 kreNote Added: 0006316 2023-06-12 08:55 geoffclare Note Added: 0006319
Re: [1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
Date:Mon, 12 Jun 2023 15:36:31 +0100 From:"Geoff Clare via austin-group-l at The Open Group" Message-ID: | Yes, I assumed some context rather than stating it. I should have | said "In particular, when a signal is generated it can become pending | for reasons other than being blocked". That's no better, particularly in light of your explanation of what "pending" means in the standard (which I was too lazy to go and check). Signals never become pending because they're blocked, nor do they become pending upon being unblocked. | I'll edit the note to make that change. Please make a somewhat different change, which just makes it clear that some other signal may have become pending while this function is running, and omit mentions of being blocked, which seem to be confusing things. That, or don't add the application usage text at all. Maybe something like "An unrelated signal may have become pending while..." kre
Re: [1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
Austin Group Bug Tracker wrote, on 12 Jun 2023: > > -- > (0006320) kre (reporter) - 2023-06-12 13:08 > https://austingroupbugs.net/view.php?id=1731#c6320 > -- > wrt https://austingroupbugs.net/view.php?id=1731#c6319 > [...] > > In particular, signals can become pending for reasons other than > being blocked > > makes no sense, being blocked never makes a signal become pending. Yes, I assumed some context rather than stating it. I should have said "In particular, when a signal is generated it can become pending for reasons other than being blocked". I'll edit the note to make that change. > Being unblocked is what does that... No. Signals can be in the pending state independently of whether they are currently blocked or unblocked. That's why the normative text says "any pending unblocked signals" - the "unblocked" there is necessary. XSH 2.4.1 describes what "pending" means in the standard: During the time between the generation of a signal and its delivery or acceptance, the signal is said to be "pending". -- Geoff Clare The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-06-12 13:08 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006320) kre (reporter) - 2023-06-12 13:08 https://austingroupbugs.net/view.php?id=1731#c6320 -- wrt https://austingroupbugs.net/view.php?id=1731#c6319 The substantive change looks fine to me - I have no problem with the "If the argument set is not a null pointer" qualification, as in that case (whether or not this function is implemented as a system call in that case) no pending signals can have been unblocked - if anything unblocked had been posted earlier, it would have already been delivered. Anything that arrives just after the call will be delivered when it arrives. Anything that arrives at the same time as the call is being processed is just in a race to see which of those two cases it is considered equivalent to. Beyond that, I'd have no objection if this function were to have this whole paragraph deleted, and not say anything about signal delivery - though it is probably better that it remain. [Note: we do not say in write() that if there are any pending unblocked signals when it is about to return, that they be delivered before write returns - but if the write caused a SIGPIPE that is what happens. It just doesn't need explicit mention there. It isn't really required here either - just this is a somewhat odd case, where it probably helps.] However, assuming that we really need that APPLICATION USAGE text at all, which I doubt, it needs a wording change. In particular, signals can become pending for reasons other than being blocked makes no sense, being blocked never makes a signal become pending. Being unblocked is what does that...I know what you intended to say (or at least I can guess), which would have been fine, but those words are not it. I suspect something more like In particular, signals may have become pending for reasons other than having previously been posted, but blocked, and unblocked by this call. The delivered signal(s) could be ones that just became pending during the pthread_sigmask() call. (something like that, perhaps a little briefer). Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 2023-05-31 19:50 kreNote Added: 0006296 2023-06-06 15:50 geoffclare Note Added: 0006312 2023-06-06 19:24 kreNote Added: 0006313 2023-06-07 09:44 geoffclare
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-06-12 08:55 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006319) geoffclare (manager) - 2023-06-12 08:55 https://austingroupbugs.net/view.php?id=1731#c6319 -- Here's an attempt at wording that uses "any pending unblocked signals" and has no timing issues. I have kept the "set is not a null pointer" condition from the desired action in order to be able to refer to the signal mask change as a timing point. A side-effect of this is that if pthread_sigmask() is used just to obtain the current mask, there is no requirement on delivery of pending unblocked signals. This seems okay to me as an implementation might be able to satisfy an enquiry for the current mask without making a system call. After applying bug 1636, change:If there are any pending unblocked signals after the call to pthread_sigmask(), at least one of those signals shall be delivered before the call to pthread_sigmask() returns.to:If the argument set is not a null pointer, after pthread_sigmask() changes the currently blocked set of signals it shall determine whether there are any pending unblocked signals; if there are any, then at least one of those signals shall be delivered before the call to pthread_sigmask() returns. Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 2023-05-31 19:50 kreNote Added: 0006296 2023-06-06 15:50 geoffclare Note Added: 0006312 2023-06-06 19:24 kreNote Added: 0006313 2023-06-07 09:44 geoffclare Note Added: 0006314 2023-06-09 11:24 kreNote Added: 0006316 2023-06-12 08:55 geoffclare Note Added: 0006319 ==
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-06-09 11:24 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006316) kre (reporter) - 2023-06-09 11:24 https://austingroupbugs.net/view.php?id=1731#c6316 -- Re https://austingroupbugs.net/view.php?id=1731#c6314 First, I don't think I've ever had a problem with the suggestions I have made for wording being improved, in fact, I usually expect that, as wordsmithing isn't really my thing - and certainly if anything I have suggested adds some unwanted requirement, that should certainly be removed. In this case, I don't see much real difference between what is in the standard now, and my suggestion (except the time paradox is gone), but as we're trying to improve that language, by all means, improve it. However wrt: Extrapolating, it effectively would require that all pending unblocked signals are delivered before pthread_sigmask() returns. That's actually what happens, in most systems anyway, though the mechanism (and precise details of how) may tend to vary. In general an application should never be running user code with a pending unblocked signal. Any signals that arrive should be processed (either cause the process to exit, or call an application signal handler (or do nothing of course)) as soon as possible. That means now (when the signal is generated) for signals that are not blocked, or as soon as the signal is unblocked for those which are. In the case of the example, when there are two pending signals when a system call returns, typically implementations behave in one of two ways. First they pick a signal that is pending to deliver (this is usually done in a deterministic way, but need not be) and set up the application state to reflect the first instruction of the user's handler routine is the next to execute, and the return address is that of the current location in the pthread_setmask() routine (immediately after the system call invoking instruction, or however the architecture makes that happen). Part of that process is applying the mask from the struct sigaction for the signal to the current signal mask - once that's done there might be no more pending unblocked signals, control returns to the application, and the handler is executed. When it completes, it notifies the system it has done so, any signals that were blocked by its sigaction become unblocked, and if there now are any pending unblocked signals, the whole process repeats, with the next pending signal (which at this stage could even be the same one for which the handler was just invoked - which can happen if the handler changes the disposition of the signal (usually) and then raises the signal again). In the case that the handler's mask did not block all the signals, and another signal remained pending and unblocked, then before resuming user mode, that signal is usually taken - which will result in things appearing to the application, if it were to look, as if the handler for the first signal invoked was interrupted immediately by the second signal - the handler for the second signal delivered runs first, then when it completes, the handler for the first signal is still waiting to executed. That might look like a strange thing to have happen, but is really no different than if the handler for the first signal selected had just started running in application mode (perhaps executed just a single machine instruction) and then the second signal arrives. Since that second signal is not blocked (that is an assumption being made here) its handler runs immediately. The effect of all of this is that yes,
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-06-07 09:44 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006314) geoffclare (manager) - 2023-06-07 09:44 https://austingroupbugs.net/view.php?id=1731#c6314 -- Re https://austingroupbugs.net/view.php?id=1731#c6313 I should have waited before posting my previous comment, as I woke up in the night thinking much the same as what you have pointed out. The t_sig_check flag must be getting set somehow when a signal is generated during any one of the many system calls that don't change the mask, and that mechanism would take care of the SIG_BLOCK case for pthread_sigmask/sigprocmask. You suggested looking at the kill() system call, but I couldn't find that (there is no kill.c in the same directory as sigprocmask.c). However, there are various places in the sig.c file (that contains sigcheck() - see link in my previous note) which could be doing it. E.g. eat_signal() sets it, and that is called from sigtoproc() which has the comment "Post a signal. If a non-null thread pointer is passed, then post the signal to the thread/lwp, otherwise post the signal to the process." Anyway, you have convinced me that my alternative wording suggestion in the desired action is wrong and the standard should stick with saying "any pending unblocked signals". Unfortunately, your suggested wording has a different time-related problem: Before the pthread_sigmask() call returns, if there are any pending unblocked signals, at least one of those shall be delivered. Taking your example of there being a SIGINT and SIGTSTP that both qualify as a "pending unblocked signal", suppose pthread_sigmask() identifies those two and chooses to deliver the SIGTSTP before returning. Let's examine the new situation immediately after this delivery: Is "before the pthread_sigmask() call returns" true? Yes. Is "there are any pending unblocked signals" true? Yes (SIGINT is). Your wording now requires that the SIGINT is delivered before pthread_sigmask() returns. Extrapolating, it effectively would require that all pending unblocked signals are delivered before pthread_sigmask() returns. I think finding some wording that doesn't have a timing issue is not going to be simple. Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 2023-05-31 19:50 kreNote Added: 0006296 2023-06-06 15:50 geoffclare Note Added: 0006312 2023-06-06 19:24 kreNote
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-06-06 19:24 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006313) kre (reporter) - 2023-06-06 19:24 https://austingroupbugs.net/view.php?id=1731#c6313 -- Re https://austingroupbugs.net/view.php?id=1731#c6312 First, I am not proposing any requirement, just to leave the requirement in this function the same as it has always been, your change was to add a new requirement (that the signal delivered be one that was just unblocked, rather than simply any pending deliverable signal). If my wording seemed to be adding something new, then use some other wording which does not. I certainly did not intend to alter anything, except to avoid the before/after issue. I see nothing in the description of the Illuminos code that you included (I am one of those "some people" though I have no idea what kind of licence Illuminos has on its code) which is different in any material way from the BSD code fragments I posted (BSD code these days is licensed mostly with a "don't sue anyone" type licence, if it matters to anyone). This doesn't mean there isn't one - just that your note did not mention it. The t_sig_check field looks like a different (and perhaps better) optimisation than what the CURSIG() macro in BSD provides; as you describe it, it merely encompasses the idea that there cannot be a signal pending unless someone has delivered one (or unblocked one) - and hence it is pointless to test whether one might now be pending (whereas the BSD code tests every time, but tries to make that test as cheap as possible). [ While it seems "obvious" it is a better way, it isn't necessarily - setting the field needs to be protected by a lock to guard against it simultaneously being cleared - that might be more costly than is warranted - or might be zero if the relevant code is already running holding a suitable lock for the purpose. And that is an extra field which makes the structure bigger, which also has costs - on fork, there is more to copy, for example, and more memory is consumed. So, this way might be improvement, or might not be, much benchmarking would be required for a definitive answer - and that might vary from system to system. ] t_sig_check doesn't need to be set in the SIG_BLOCK case, as that cannot be allowing any signals that were pending to be delivered, and it is not sending a signal of its own. I would assume that all code which sends a signal, in addition to that code which unblocks pending signals, sets t_sig_check. Check their code for the kill() system call and verify that also sets that field (on the process/thread being sent the signal of course, not the one sending it, unless they are the same), and if you feel inclined, the code that sends SIGCHLD when a child exits, which should do the same (if the signal is actually sent. or SIGALRM if a timer expires). Traps which send signals should do the same - though one of those should not normally happen to a process running inside a system call. Nothing you described has any bearing upon what signal gets delivered to the process when the sigprocmask() system all is done - whether it is one that was just unblocked, or another that happened to arrive while that system call was running. You would need to look deeper into what the post_syscall() function you mention does in that case that t_sig_check is set, to discover if it somehow makes a distinction between a signal that has been pending, and is now unblocked, and one which was never blocked, but just arrived while the system call was running (a child exiting that was running
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-06-06 15:50 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006312) geoffclare (manager) - 2023-06-06 15:50 https://austingroupbugs.net/view.php?id=1731#c6312 -- Re https://austingroupbugs.net/view.php?id=1731#c6296 I poked around in the Illumos code on github and I think I have found the equivalents of most of the code you examined for BSD 4.4_lite. There is a major difference that affects the behaviour we are discussing. I won't post the code here as I know some people make a point not to look at code with certain licences, but will give links and try to describe what I'm seeing. The sigprocmask() code is in https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/syscall/sigprocmask.c It calls lwp_sigmask() to do the signal mask change. The code in there is very similar to the BSD sigprocmask() code, but in the switch it has a difference in behaviour between the cases. For SIG_UNBLOCK and SIG_SETMASK it has some code which sets the t_sig_check flag for the thread if a call to sigcheck() returns true. It does not do this for SIG_BLOCK. The code for sigcheck() is in https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/os/sig.c but everything you need to know about it is in the comment before the function definition: "Return non-zero if curthread->t_sig_check should be set to 1, that is, if there are any signals the thread might take on return from the kernel." The t_sig_check flag is used in the post_syscall() function in https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/sparc/os/syscall.c The code there only checks for pending signals if either t_astflag or t_sig_check is set for the thread, and has this comment: "All code that sets signals and makes ISSIG_PENDING evaluate true must set t_sig_check afterwards." Since t_sig_check isn't set by sigprocmask() when called with SIG_BLOCK, it looks like Illumos might not conform to the requirement you are proposing. Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 2023-05-31 19:50 kreNote Added: 0006296 2023-06-06 15:50 geoffclare Note Added: 0006312 ==
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue.
==
https://austingroupbugs.net/view.php?id=1731
==
Reported By:geoffclare
Assigned To:
==
Project:1003.1(2016/18)/Issue7+TC2
Issue ID: 1731
Category: System Interfaces
Type: Clarification Requested
Severity: Objection
Priority: normal
Status: New
Name: Geoff Clare
Organization: The Open Group
User Reference:
Section:pthread_sigmask()
Page Number:1734
Line Number:56243
Interp Status: ---
Final Accepted Text:
==
Date Submitted: 2023-05-23 09:43 UTC
Last Modified: 2023-05-31 19:50 UTC
==
Summary:pthread_sigmask() pending signal requirement time
paradox
==
--
(0006296) kre (reporter) - 2023-05-31 19:50
https://austingroupbugs.net/view.php?id=1731#c6296
--
Re https://austingroupbugs.net/view.php?id=1731#c6294
we should probably also look at a version of BSD from before it started
to
diverge into different variants.
That's easy, this is the implementation of the system call in 4.4_lite
(or something around that time - from the final CSRG SCCS files).
/*
* Manipulate signal mask.
* Note that we receive new mask, not pointer,
* and return old mask as return value;
* the library stub does the rest.
*/
int
sigprocmask(p, uap, retval)
register struct proc *p;
struct sigprocmask_args /* {
syscallarg(int) how;
syscallarg(sigset_t) mask;
} */ *uap;
register_t *retval;
{
int error = 0;
*retval = p->p_sigmask;
(void) splhigh();
switch (SCARG(uap, how)) {
case SIG_BLOCK:
p->p_sigmask |= SCARG(uap, mask) &~ sigcantmask;
break;
case SIG_UNBLOCK:
p->p_sigmask &= ~SCARG(uap, mask);
break;
case SIG_SETMASK:
p->p_sigmask = SCARG(uap, mask) &~ sigcantmask;
break;
default:
error = EINVAL;
break;
}
(void) spl0();
return (error);
}
That's it, There are also compat sys calls, for the earlier
implementation where there were separate sys calls for the functions,
rather than one with an arg saying what to do (as above).
int
compat_43_sigblock(p, uap, retval)
register struct proc *p;
struct compat_43_sigblock_args /* {
syscallarg(int) mask;
} */ *uap;
register_t *retval;
{
(void) splhigh();
*retval = p->p_sigmask;
p->p_sigmask |= SCARG(uap, mask) &~ sigcantmask;
(void) spl0();
return (0);
}
int
compat_43_sigsetmask(p, uap, retval)
struct proc *p;
struct compat_43_sigsetmask_args /* {
syscallarg(int) mask;
} */ *uap;
register_t *retval;
{
(void) splhigh();
*retval = p->p_sigmask;
p->p_sigmask = SCARG(uap, mask) &~ sigcantmask;
(void) spl0();
return (0);
}
The latter was used to accomplish unblock (generally by setting the
mask to what was returned by sigblock()).
These are called from machine depenendent code (since the way sys calls
are encoded and their args passed, varies from architecture to
architecture).
Taking the vax as the original, and oldest, sys calls ar handled (big
surprise)
by the syscall() function ... I'm not going to include all of the code for
that,
it is fairly long, and most of what it is doing isn't relevant, but ...
It starts with code that checks the syscall() call orjginated in user mode
(if already in the kernel, it panics), then it works out what the PC was
(the length of the instr) which varies depending upon the sys call number
(how many bytes it takes to represent that) - deals with syscall(0) (the
indirect sys call) and then checks the sys call number is in range. Once
that is known, it can copy in the expected args (from the sys call table,
which says how many there should be) after which (ignoring some ktrace
noise)
it does:
rval[0] = 0;
rval[1] = locr0[R1];
error = (*callp->sy_call)(u.u_procp, &args,
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-05-30 11:14 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006294) geoffclare (manager) - 2023-05-30 11:14 https://austingroupbugs.net/view.php?id=1731#c6294 -- When I submitted this bug I had no expectation that it would be in any way controversial. I thought it was just another "everyone knows" type of bug, i.e. a class of bug that comes up from time to time whereby readers' prior knowledge of what a function does causes them not to notice that the wording in the standard does not correctly describe its behaviour, even (as in this case) if there is an error that's glaringly obvious once it has been pointed out. The time paradox in the wording here dates back to the sigprocmask() description in the original POSIX.1-1988 standard. The wording I suggested in the desired action was, I thought, a good way to describe how "everyone knows" pthread_sigmask() behaves. The subtle difference in required behaviour that it would introduce had not occurred to me until kre pointed it out. I agree with kre that we need to find out how implementations behave, and that it would be impractical to try and test it, so the best way to find out is to examine their source code. For historical perspective, since signal masks originated in BSD, we should probably also look at a version of BSD from before it started to diverge into different variants. Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 2023-05-30 11:14 geoffclare Note Added: 0006294 ==
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-05-25 18:44 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006293) kre (reporter) - 2023-05-25 18:44 https://austingroupbugs.net/view.php?id=1731#c6293 -- I should also say, that testing what happens in this scenario is very hard - it is not easy to arrange for some other signal to arrive right at the precise time that it matters (not easy to prevent either). What that means is that 99.9% (nb: that is not a measured statistic) of the time, the only pending unblocked signals after this system call will be ones that it unblocked (since it does not otherwise generate signals). Some other signal, if it arrived just before the system call would have already been delivered. If it arrives just after, then one of the newly unblocked signals would have already been delivered. Arranging for things to happen so that the difference in behaviour being discussed is apparent is not at all easy. The only really sane way to investigate this is to read the code for various systems, and ask "what if?" several times. Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 2023-05-25 18:26 kreNote Added: 0006292 2023-05-25 18:32 kreNote Edited: 0006292 2023-05-25 18:44 kreNote Added: 0006293 ==
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-05-25 18:26 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006292) kre (reporter) - 2023-05-25 18:26 https://austingroupbugs.net/view.php?id=1731#c6292 -- Re https://austingroupbugs.net/view.php?id=1731#c6288 There are two important general comments relevant here, before getting to the details of the specific issue: First: how people expect implementations to behave is not, or should not be, relevant here. What matters is how implementations do behave, not how someone would like them to. And even more important: Yes, there is a subtle difference in the new wording If that was intentional, and not just a poor choice of replacement text, then we have real problems. Attempting to insert changes in the way that the specification is written, via underhand mechanisms like that, is totally unacceptable. If the real reason for this defect report, is to make a change in the way that implementations are required to behave, then the description of the problem should have been clear about that - not just hiding things as if it were just some minor grammatical error that should be fixed, which was how it was presented. While the grammar of the current standard could be improved, to avoid the issue mentioned in the description, there is no real need to do so from the point of view of the standard itself. What is required is clear, only someone looking at it from a peculiar language perspective would even notice the problem. My "alternative suggestion" is simply restating what the standard currently says, in a way that avoids the problematic language. I'm sure there are other ways that would work as well, if you don't like my suggested wording. That is, which would work without changing the standard. As to how implementations work - it has been a while since I got down and dirty at the syscall interface, but the way all this used to work (and probably still does, since I cannot imagine much reason for changing it) is that signals cannot be delivered to an application while the kernel is currently executing code on behalf of the application (ie: when it is running the code of a system call). But signals can arrive during that period - either as a result of the system call itself, or simply by chance (sent from some other process, perhaps a child exiting causing SIGCHLD, or from another thread of this process perhaps). So the general method was, just as the system call is ending, and control is about to be returned to the user, the kernel checks to see if there are any pending unblocked signals - anything that would already have been delivered, had we not been in a system call. At this point, the code often barely knows (perhaps doesn't know at all) what system call is ending, and certainly has no idea what signals that are pending might have been generated or unmasked, by this system call. All it knows is that there is a pending signal, and that signal can now be delivered, so it is made to happen. Do you have some evidence that there are systems that behave differently than that, or do you just thing there ought to be? Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section =>
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-05-25 08:40 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006288) geoffclare (manager) - 2023-05-25 08:40 https://austingroupbugs.net/view.php?id=1731#c6288 -- Yes, there is a subtle difference in the new wording, but I believe it better matches how people expect implementations to behave and I would be very surprised if any implementation exists that does not behave that way. Your alternative suggestion would allow an implementation to get away with not delivering any of the pending signals that the mask change unblocks if a signal that is not blocked happens to be delivered before pthread_sigmask() returns and is generated a second time during execution of a signal catching function for that signal. Why should that be allowed? Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 2023-05-25 08:40 geoffclare Note Added: 0006288 ==
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
A NOTE has been added to this issue. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-05-23 21:08 UTC == Summary:pthread_sigmask() pending signal requirement time paradox == -- (0006287) kre (reporter) - 2023-05-23 21:08 https://austingroupbugs.net/view.php?id=1731#c6287 -- I believe the proposed wording in the desired action adds an unintended subtle difference to how this is intended to work. Previously, setting aside the temporal distortion, which I agree should be fixed, the intent was that if there are *any* unblocked signals, one of them gets delivered. The proposed wording requires that one of the signals that became unblocked by the call be delivered. This makes a difference if some other (unblocked) signal just happened to arrive during the system call, which unblocks some other signal, the system is not permitted to deliver the newly arrived signal, but must deliver one of the ones that had been blocked. I don't think that change is really intended. I'd keep it simpler, something like Before the pthread_sigmask() call returns, if there are any pending unblocked signals, at least one of those shall be delivered. Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- 2023-05-23 21:08 kreNote Added: 0006287 ==
[1003.1(2016/18)/Issue7+TC2 0001731]: pthread_sigmask() pending signal requirement time paradox
The following issue has been SUBMITTED. == https://austingroupbugs.net/view.php?id=1731 == Reported By:geoffclare Assigned To: == Project:1003.1(2016/18)/Issue7+TC2 Issue ID: 1731 Category: System Interfaces Type: Clarification Requested Severity: Objection Priority: normal Status: New Name: Geoff Clare Organization: The Open Group User Reference: Section:pthread_sigmask() Page Number:1734 Line Number:56243 Interp Status: --- Final Accepted Text: == Date Submitted: 2023-05-23 09:43 UTC Last Modified: 2023-05-23 09:43 UTC == Summary:pthread_sigmask() pending signal requirement time paradox Description: In this statement:If there are any pending unblocked signals after the call to sigprocmask(), at least one of those signals shall be delivered before the call to sigprocmask() returns.the normal interpretation of "after the call" would be after the call returns, but that obviously can't be what is intended here because it states an action to be performed before the call returns, which would result in a time paradox. Desired Action: After applying bug 1636, change:If there are any pending unblocked signals after the call to pthread_sigmask(), at least one of those signals shall be delivered before the call to pthread_sigmask() returns.to:If the argument set is not a null pointer and the change made to the currently blocked set of signals causes any pending signals to become unblocked, at least one of those signals shall be delivered before the call to pthread_sigmask() returns. == Issue History Date ModifiedUsername FieldChange == 2023-05-23 09:43 geoffclare New Issue 2023-05-23 09:43 geoffclare Name => Geoff Clare 2023-05-23 09:43 geoffclare Organization => The Open Group 2023-05-23 09:43 geoffclare Section => pthread_sigmask() 2023-05-23 09:43 geoffclare Page Number => 1734 2023-05-23 09:43 geoffclare Line Number => 56243 2023-05-23 09:43 geoffclare Interp Status => --- ==
