From 6ff344d7c63ff49ce25100b2c43d43a4ca023f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Sat, 16 Jan 2021 16:50:28 +0000 Subject: [PATCH] Revert "kernel/thread: restore signal mask just before returning to userland" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 837f4f48db2f543c730f30d374ec65c7d44c9644. Reason for revert: breaks DNS resolution Change-Id: If6f2a0f60dbfb24121616a9f3879ce226ea4a09a Reviewed-on: https://review.haiku-os.org/c/haiku/+/3519 Reviewed-by: Jérôme Duval --- headers/private/kernel/thread_types.h | 6 ------ src/system/kernel/thread.cpp | 14 -------------- src/system/kernel/wait_for_objects.cpp | 25 ++++++++++++++----------- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/headers/private/kernel/thread_types.h b/headers/private/kernel/thread_types.h index 6ac2bcbcef..926baafcf1 100644 --- a/headers/private/kernel/thread_types.h +++ b/headers/private/kernel/thread_types.h @@ -455,10 +455,6 @@ struct Thread : TeamThreadIteratorEntry, 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 @@ -848,7 +844,5 @@ 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 */ diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index cc103c2db9..fdab209879 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -1938,16 +1938,6 @@ dump_thread_list(int argc, char **argv) } -static void -update_thread_sigmask_on_exit(Thread* thread) -{ - if ((thread->flags & THREAD_FLAGS_OLD_SIGMASK) != 0) { - thread->flags &= ~THREAD_FLAGS_OLD_SIGMASK; - sigprocmask(SIG_SETMASK, &thread->old_sig_block_mask, NULL); - } -} - - // #pragma mark - private kernel API @@ -2328,8 +2318,6 @@ thread_at_kernel_exit(void) disable_interrupts(); - update_thread_sigmask_on_exit(thread); - // track kernel time bigtime_t now = system_time(); SpinLocker threadTimeLocker(thread->time_lock); @@ -2351,8 +2339,6 @@ thread_at_kernel_exit_no_signals(void) TRACE(("thread_at_kernel_exit_no_signals: exit thread %" B_PRId32 "\n", thread->id)); - update_thread_sigmask_on_exit(thread); - // track kernel time bigtime_t now = system_time(); SpinLocker threadTimeLocker(thread->time_lock); diff --git a/src/system/kernel/wait_for_objects.cpp b/src/system/kernel/wait_for_objects.cpp index 50ce435ac2..1461e1e149 100644 --- a/src/system/kernel/wait_for_objects.cpp +++ b/src/system/kernel/wait_for_objects.cpp @@ -475,21 +475,15 @@ common_select(int numFDs, fd_set *readSet, fd_set *writeSet, fd_set *errorSet, // set new signal mask sigset_t oldSigMask; - if (sigMask != NULL) { + if (sigMask != NULL) sigprocmask(SIG_SETMASK, sigMask, &oldSigMask); - if (!kernel) { - Thread *thread = thread_get_current_thread(); - thread->old_sig_block_mask = oldSigMask; - thread->flags |= THREAD_FLAGS_OLD_SIGMASK; - } - } // wait for something to happen status = acquire_sem_etc(sync->sem, 1, B_CAN_INTERRUPT | (timeout >= 0 ? B_ABSOLUTE_TIMEOUT : 0), timeout); // restore the old signal mask - if (sigMask != NULL && kernel) + if (sigMask != NULL) sigprocmask(SIG_SETMASK, &oldSigMask, NULL); PRINT(("common_select(): acquire_sem_etc() returned: %lx\n", status)); @@ -933,6 +927,8 @@ _user_select(int numFDs, fd_set *userReadSet, fd_set *userWriteSet, sigset_t sigMask; int result; + syscall_restart_handle_timeout_pre(timeout); + if (numFDs < 0 || !check_max_fds(numFDs)) return B_BAD_VALUE; @@ -998,7 +994,8 @@ _user_select(int numFDs, fd_set *userReadSet, fd_set *userWriteSet, || (errorSet != NULL && user_memcpy(userErrorSet, errorSet, bytes) < B_OK))) { result = B_BAD_ADDRESS; - } + } else + syscall_restart_handle_timeout_post(result, timeout); err: free(readSet); @@ -1016,12 +1013,16 @@ _user_poll(struct pollfd *userfds, int numFDs, bigtime_t timeout) size_t bytes; int result; + syscall_restart_handle_timeout_pre(timeout); + if (numFDs < 0) return B_BAD_VALUE; if (numFDs == 0) { // special case: no FDs - return common_poll(NULL, 0, timeout, false); + result = common_poll(NULL, 0, timeout, false); + return result < 0 + ? syscall_restart_handle_timeout_post(result, timeout) : result; } if (!check_max_fds(numFDs)) @@ -1046,7 +1047,9 @@ _user_poll(struct pollfd *userfds, int numFDs, bigtime_t timeout) if (numFDs > 0 && user_memcpy(userfds, fds, bytes) != 0) { if (result >= 0) result = B_BAD_ADDRESS; - } + } else + syscall_restart_handle_timeout_post(result, timeout); + err: free(fds);