From patchwork Tue Jun 23 12:47:42 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: 137634 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 459BC4BA798D for ; Tue, 23 Jun 2026 12:49:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 459BC4BA798D 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=Zxhciswt X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1232.google.com (mail-dl1-x1232.google.com [IPv6:2607:f8b0:4864:20::1232]) by sourceware.org (Postfix) with ESMTPS id C5C004BA2E2A for ; Tue, 23 Jun 2026 12:48:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5C004BA2E2A 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 C5C004BA2E2A Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218917; cv=none; b=OzRMmgBJZEk71DXeJngajmd4ZJBJCQhjOrtrVKJrfoXDOywy5pGy8lcHM40FS6yLNjVGzSXeoaYsdSIdwePZp6PD+2jdjLb+U3IT98fad86NeUwK5I6fhxXtDpsOlr8euRXUMTQaJMLPCg1QstuBNP/Vp/1OXQw0hAZR929LoJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218917; c=relaxed/simple; bh=SyZ2zDOketYtpMiiA32zWC2oubF4VgVzpiRxk63k5do=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hEdKpl0mTKhSmQSm47ru2mfOSf5xzk+u2Szs7mlE0m2XbmCgZ9ontfwYzlJpVAEu0SZ+J2FzQhJs9apenSaRbEupE1bhBRyaU02dF1QlN9jUFQ/QHoFCC7xw0UsZqAn4GXRDKfIM6Dhnif70XkN+3AttoNqx9brqON8aGsCozsg= 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=Zxhciswt DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5C004BA2E2A Received: by mail-dl1-x1232.google.com with SMTP id a92af1059eb24-139a71baa35so9221121c88.0 for ; Tue, 23 Jun 2026 05:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782218917; x=1782823717; 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=WTX2e9yg9actFMk6XuJ9vEmo66cTr5pSRt5HJGKPSOA=; b=ZxhciswtKjo8wQjupCQ7sLrDRxy/vwtaF7r9J2n0/ReqTCspuKzs2wD9azvhqkO8t0 BajUyAeAcshnSjVnX3tcB3BxsBvHA7kmpD5hHbQaSF3lALpbeWqWF+lEN3xp/rtjQgFq kW1g1+wZyxqCM0pB4KJfmY1iEuIS5EHk7gh+b2DszsGOnMTyzgofyCHT/Xp5M//wdiKN fGEdto9/WyCld9MGwmaKLasqwBGLdSKQMvAwRC/l/D6tk067Rrfr/KkhDf/hkUgE0agC 1o+cfCFNiG9Sk7X7bJ/xFbk4OuT3au3IGfT8jTwSBNGfpAa5pQU2XrqbTGZ8ekpH8BFJ NQjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782218917; x=1782823717; 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; bh=WTX2e9yg9actFMk6XuJ9vEmo66cTr5pSRt5HJGKPSOA=; b=p3Zjd5YR9PRiuw6KshLB9fZmZ/dpOnrTB/su3p/HmJLUR5rxdESb9xfeybpOw0Xf4Z 0ALUX1tPCVjhQXRmkKqdJOJEQ+32oUyrgXDbPiCBpVuGTYuYnh9cQpVL5wPOT05MsCOh OalnLL4yJL/aS89FF8LJSdPRSTibVjBp7cPQWFLE3LaoA3h3hTr/yptoBv75TbdamcjJ 4UjCLbCaTJyWoX+LWetfpW53C2idOizi0uEjwIJ5f+oRniVACICgslSm6zi1nL6ZiAFH a6AsDic+b5OGXGLkzW2RRewVqQX1iULN9RpXKNIWFMaqCOtjEcWgeONgV74lNdmdaKgZ cIZw== X-Gm-Message-State: AOJu0YwbffxUnBFJ2TIO9JLlvnJaR+7KptZCEqvZJMUlvl5LbFZSn74A ayJN3Lgz9DfExwQK9sOGYQ4G3a2C0S0pGqWIE2+6GkYCD9qAtF/9vOWOpS/5Ldyzvfk1n+fS+En 8JEnI X-Gm-Gg: AfdE7cl52MXiY8RAjVKub/1nW+4Yi81Ew5gMLqAPBy8cn/StyVPisBsAVv36bRGTTAG 5MPUQhtK9lqzrObsGeVNW9AswbQwwfwSQusNbpcwIi9r2g+1vU3J4ROXM/YRT/+3PrzgpTxE1Nn LkWRi8GbWHnHvMMLZhFL2tyN5B3mw7As1zy7OrXna+8f0M5JTa2uKFVLHqR4TvAONFGpsY7nFuf nh3DD2gMEL/cOyo1gmDCS+PHVlHrWWzQ4wmsC4ReK2nH7iUG7k6KXm/2YzGub8Jmw579S9DaVRj bGfnoC/KLvBmHKTbxoQ36jM0Qd0B+cXfyAYl+GiRCbbCE9E9nWZgsJ/ogXs0/S3iK49Khjpt5Rs YOq+DnIUbcP7r7Y0Vk9eP8ISs+eKFF0Td8CbnDvMWkkcrsc5gewoPIi/EG5kQ5mHylV2UnuWije eIwCWfSiecQVriJeLNvbfeRVif X-Received: by 2002:a05:7022:7a6:b0:139:cca6:54e1 with SMTP id a92af1059eb24-139cca65507mr309877c88.8.1782218916377; Tue, 23 Jun 2026 05:48:36 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d170:82d3:e54e:278a:ac84]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-139adca1b18sm12183777c88.3.2026.06.23.05.48.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 05:48:35 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v10 1/5] nptl: Add __raise_direct Date: Tue, 23 Jun 2026 09:47:42 -0300 Message-ID: <20260623124831.2165041-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260623124831.2165041-1-adhemerval.zanella@linaro.org> References: <20260623124831.2165041-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_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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. --- 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 a048dbc7323..5b11fd105fd 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; +}