kernel/thread: restore signal mask just before returning to userland

* otherwise the signal to be handled might be blocked. fixes #15193
* also remove automatic syscall restart on _kern_select, to match Linux and
BSDs behavior: this fixes parallel build with newer gnu make, which happens
to use pselect.
* also remove automatic syscall restart on _kern_poll.

from https://man7.org/linux/man-pages/man7/signal.7.html
"The following interfaces are never restarted after being
       interrupted by a signal handler, regardless of the use of
       SA_RESTART; they always fail with the error EINTR when
       interrupted by a signal handler: ...
	select(2), and pselect(2)."
from https://notes.shichao.io/unp/ch6/
"Berkeley-derived kernels never automatically restart select."

Change-Id: I7f86d221eae1ad93d8a308a75581d2c30a369c9e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3627
Reviewed-by: Adrien Destugues <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Jérôme Duval
2021-01-15 17:41:33 +00:00
parent 4d0b11bd22
commit 837f4f48db
3 changed files with 31 additions and 14 deletions
+6
View File
@@ -455,6 +455,10 @@ struct Thread : TeamThreadIteratorEntry<thread_id>, KernelReferenceable {
// non-0 after a return from _user_sigsuspend(), containing the inverted
// original signal mask, reset in handle_signals(); only accessed by
// this thread
sigset_t old_sig_block_mask;
// the old sig_block_mask to be restored when returning to userland
// when THREAD_FLAGS_OLD_SIGMASK is set
ucontext_t* user_signal_context; // only accessed by this thread
addr_t signal_stack_base; // only accessed by this thread
size_t signal_stack_size; // only accessed by this thread
@@ -844,5 +848,7 @@ using BKernel::ProcessGroupList;
#define THREAD_FLAGS_COMPAT_MODE 0x2000
// the thread runs a compatibility mode (for instance IA32 on x86_64).
#endif
#define THREAD_FLAGS_OLD_SIGMASK 0x4000
// the thread has an old sigmask to be restored
#endif /* _KERNEL_THREAD_TYPES_H */