From patchwork Fri May 29 16:26:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 136094 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6A914BA23C9 for ; Fri, 29 May 2026 16:29:53 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by sourceware.org (Postfix) with ESMTPS id 853C24BA23ED for ; Fri, 29 May 2026 16:28:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 853C24BA23ED Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 853C24BA23ED Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::734 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072109; cv=none; b=NKfUqClDEQInd2k8A+0EOIqWW5k/K5cRVclCn6p18TdMRgePIblZjAdhvT/n7ZppRwbdetfIbaEYEFpAEKMD/B2uB5l2rol/Hom5lA5cGgu3gI6ntRBBDDEVanrKvOY5ErmsDLvZ0nfX5WEFbMDzXzlUtcTfy7ITrBdXmdS4Voo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072109; c=relaxed/simple; bh=X6KMJE46rgYQgBTzSOkXN51GI/BooovUc+nPfSrKT3w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Gjx+oMBZ76oQa2cVnHh86r7UwLLUYbesoXHHsKR+keyGOAqlOge6ETQH9ycxvOkeaPK142oGM71EmPI5FcI2MrI+zMp+IdZEYV0Hvfd7De93h8yLH4NMYM20va9VvMJc4OJNdKEmmG2S1vzB3M4/yI/553wR3WjgfPytIOI8diM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=qc9Ax1/W DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 853C24BA23ED Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=qc9Ax1/W Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-9153e2708aeso3200185a.0 for ; Fri, 29 May 2026 09:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780072107; x=1780676907; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x+N5FWmGCEbjdBGeeohgddaZelneea5lS6JCkWbcsdw=; b=qc9Ax1/Wu9QKB/NqJvw9KHwCf298o7nDnLvv5g182Jtnp5FZxFSSiHl9eDhndduw++ IPNc+XGmssZkp6QXvL87smMOsoebAZ4z4G7WRi8J0tZtwq0rtgXg9Q6dRdewLMgz0Ypp CwUoAF5ra9dWzk/VTM+jyjfEOH1Py0JWdQaMsQ4a98Zv0lcOzTgPWFwNPHMtmssy6nLG WInARUaHTOAytwsu1/KD0p9rpdjPnG3QPGf3AITnCZKQCoiguigboi8KPP7PVOgZpxT2 9tkYyL+i6yNVMUFOB5SdVqreNQLQvRguaQCa/h3pQ/5RWjhRtOr+sxk+8Ase3BuOiR8s aSuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780072107; x=1780676907; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to;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94:8e9 with SMTP id af79cd13be357-9153d99d55dmr69483885a.17.1780072107035; Fri, 29 May 2026 09:28:27 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:efc6:96e6:e80e:65cc:b3cd]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9153244c085sm234346985a.6.2026.05.29.09.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 09:28:26 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v9 1/5] nptl: Add __raise_direct Date: Fri, 29 May 2026 13:26:40 -0300 Message-ID: <20260529162818.3749464-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260529162818.3749464-1-adhemerval.zanella@linaro.org> References: <20260529162818.3749464-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The function sends a signal to current thread using raw syscalls. Reviewed-by: Florian Weimer --- include/signal.h | 3 +++ nptl/pthread_kill.c | 21 +++++++------------ sysdeps/posix/raise.c | 2 +- sysdeps/unix/sysv/linux/Makefile | 4 ++++ sysdeps/unix/sysv/linux/raise_direct.c | 29 ++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/raise_direct.c diff --git a/include/signal.h b/include/signal.h index 73f18dddd7f..099d7215146 100644 --- a/include/signal.h +++ b/include/signal.h @@ -65,6 +65,9 @@ extern int __xpg_sigpause (int sig); /* Allocate real-time signal with highest/lowest available priority. */ extern int __libc_allocate_rtsig (int __high); +/* Similar to raise, but does not set errno. */ +extern int __raise_direct (int signo) attribute_hidden; + # if IS_IN (rtld) extern __typeof (__sigaction) __sigaction attribute_hidden; extern __typeof (__libc_sigaction) __libc_sigaction attribute_hidden; diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c index 221689e36a9..bc038e9824c 100644 --- a/nptl/pthread_kill.c +++ b/nptl/pthread_kill.c @@ -29,20 +29,13 @@ __pthread_kill_implementation (pthread_t threadid, int signo, int no_tid) { struct pthread *pd = (struct pthread *) threadid; if (pd == THREAD_SELF) - { - /* Use the actual TID from the kernel, so that it refers to the - current thread even if called after vfork. There is no - signal blocking in this case, so that the signal is delivered - immediately, before __pthread_kill_internal returns: a signal - sent to the thread itself needs to be delivered - synchronously. (It is unclear if Linux guarantees the - delivery of all pending signals after unblocking in the code - below. POSIX only guarantees delivery of a single signal, - which may not be the right one.) */ - pid_t tid = INTERNAL_SYSCALL_CALL (gettid); - int ret = INTERNAL_SYSCALL_CALL (tgkill, __getpid (), tid, signo); - return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0; - } + /* There is no signal blocking in this case, so that the signal is + delivered immediately, before __pthread_kill_internal returns: a signal + sent to the thread itself needs to be delivered synchronously. (It is + unclear whether Linux guarantees the delivery of all pending signals + after unblocking in the code below. POSIX only guarantees delivery + of a single signal, which may not be the right one.) */ + return __raise_direct (signo); /* Block all signals, as required by pd->exit_lock. */ internal_sigset_t old_mask; diff --git a/sysdeps/posix/raise.c b/sysdeps/posix/raise.c index 8abe8d4cad4..cf0770f1c81 100644 --- a/sysdeps/posix/raise.c +++ b/sysdeps/posix/raise.c @@ -23,7 +23,7 @@ int raise (int sig) { - int ret = __pthread_kill (__pthread_self (), sig); + int ret = __raise_direct (sig); if (ret != 0) { __set_errno (ret); diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 63e7046cb3a..17f0c309a62 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -455,6 +455,10 @@ tests += \ endif ifeq ($(subdir),signal) +sysdep_routines += \ + raise_direct \ + # sysdep_routines + tests-special += \ $(objpfx)tst-signal-numbers.out \ # tests-special diff --git a/sysdeps/unix/sysv/linux/raise_direct.c b/sysdeps/unix/sysv/linux/raise_direct.c new file mode 100644 index 00000000000..d38bd10817a --- /dev/null +++ b/sysdeps/unix/sysv/linux/raise_direct.c @@ -0,0 +1,29 @@ +/* Internal function to send a signal to itself. Linux version. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +int +__raise_direct (int signo) +{ + pid_t tid = INTERNAL_SYSCALL_CALL (gettid); + int ret = INTERNAL_SYSCALL_CALL (tkill, tid, signo); + return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0; +}