From: Eli Zaretskii Date: Thu, 3 Jul 2025 13:19:09 +0000 (+0300) Subject: Avoid segfaults due to C-g when a thread does GC X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ccc0fa28a846bbc9123004d6c38fdae2bfc2bec4;p=emacs.git Avoid segfaults due to C-g when a thread does GC * src/keyboard.c (handle_interrupt): Don't forcibly switch threads if a non-main thread was in GC when the signal handler was called. (cherry picked from commit 205d69e7e64cf23df0bc7a52b1149f6130c117b5) --- diff --git a/src/keyboard.c b/src/keyboard.c index d7f15aeb4e1..fa0a5fbdd1a 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -12350,7 +12350,15 @@ handle_interrupt (bool in_signal_handler) thread, see deliver_process_signal. So we must make sure the main thread holds the global lock. */ if (in_signal_handler) - maybe_reacquire_global_lock (); + { + /* But if the signal handler was called when a non-main thread was + in GC, just return, since switching threads by force-taking the + global lock will confuse the heck out of GC, and will most + likely segfault. */ + if (!main_thread_p (current_thread) && gc_in_progress) + return; + maybe_reacquire_global_lock (); + } #endif if (waiting_for_input && !echoing) quit_throw_to_read_char (in_signal_handler);