From nobody Wed Jan 28 02:27:21 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4f15lF4lgWz6Q2ss for ; Wed, 28 Jan 2026 02:27:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4f15lF3KCtz3mHb for ; Wed, 28 Jan 2026 02:27:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769567241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gW5Wf65hkyCFRAKiJ8jAAXD3yowrwR2rLWS3L56EY7M=; b=pHsJdYTV3OHfdmFHyy9WwN6vo4mIq07w22wm5TlkX/Ob/rTN+j7S1jevNTlUKPY13VLsOu KYFsyT4gGQa30+jo8tizEcCzJpgr+AAgWpAlsMeRRtqvGL8KfDeDddGwzD4LCXj7qlj5Gd 3Get6Vob7M7VH4/HnV12liYmf/nwYKrrUd8BK+MOtACL58pbclIceUKva1gHpI57g5jdsk SLnEHxkJ468mfD1alemdmEjUe9orGMtxhNlLuZxuE6Bt0fXJXUbD3SGryIlURwCVxxtZQe ZGIYywAQ36fHnuAgsKywdEl+DL0kWQIgN9472t4A4Er0ZEjfWGwJ2iO20jdt0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1769567241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gW5Wf65hkyCFRAKiJ8jAAXD3yowrwR2rLWS3L56EY7M=; b=DNZHI0A5doMfsaNfC3mcBnTR+3islsfddv6iebeuZSosCDkKj/vjDLYl4c2U3MTIbxEiGI Lqpo8/ZBkmDs+NXoJ0YpRn6q8TuNrUlfQcD+ZMWtil4s416GSbFEku8MDejMv9KFK3onjc pSUVxAN9of3gYWXn18TcxmektV+yuvHGK+SJ2GU5FRX3Pjo3oN5TvkMHRoYa13pCSZR/Mk WaNRUuZiHaUIAU0DBVyxyYg/lDVjgFeQhabcoKQnpZdOuWroTOkSPj//LW7OZdf363xNbT KyfvU2NtxZETOXyaAZSXrESxrbYQltXeUCxrhwyoyYPua7C6cJeEgfrDV3nZCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1769567241; a=rsa-sha256; cv=none; b=dADn/RoT//jK3PTQxTGLA+djnBsEjnYMhcc70xJxFmB31600+UVHLniG1HASBkOR4Q7Nuj 9+edUya1Kvejy/XWlP1FkfcERx2iI+uVTUuAKyKXVVVaFvGGZskL1CEh65aa/C+jNIc5Wy 7RlZRU/XXdWMSodxKSNHMSavzhsWi9YxTkwjhPniMYl3qGhxvaImbVPRJMJSROAyEG0bOa EJ4h4w9nNrHTKpqIlRGyvj+w/An0V7mXiUS1yA3rm49eG7DzmZqHqDvxXSL1UEZFrsD0p7 nvtUzfwdhQTKPTbb5hc4jB9kjgDeyMl44ikUj/qc4XGlYY0dvUFegvTC8zWQsA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f15lF1wL4zZRX for ; Wed, 28 Jan 2026 02:27:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 26203 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 28 Jan 2026 02:27:21 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 4daf2d3e7db5 - main - posix_spawn: use rfork_thread on all arches List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4daf2d3e7db53a113108f9a02ceaf5051d416184 Auto-Submitted: auto-generated Date: Wed, 28 Jan 2026 02:27:21 +0000 Message-Id: <69797409.26203.3636e9cd@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4daf2d3e7db53a113108f9a02ceaf5051d416184 commit 4daf2d3e7db53a113108f9a02ceaf5051d416184 Author: Konstantin Belousov AuthorDate: 2026-01-26 16:09:18 +0000 Commit: Konstantin Belousov CommitDate: 2026-01-28 02:26:52 +0000 posix_spawn: use rfork_thread on all arches Do not allocate or switch to the custom stack on non-x86. Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D54898 --- lib/libc/gen/posix_spawn.c | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c index c64915078317..656c0f20f798 100644 --- a/lib/libc/gen/posix_spawn.c +++ b/lib/libc/gen/posix_spawn.c @@ -236,7 +236,6 @@ struct posix_spawn_args { #define PSPAWN_STACK_ALIGN(sz) \ (((sz) + PSPAWN_STACK_ALIGNBYTES) & ~PSPAWN_STACK_ALIGNBYTES) -#if defined(__i386__) || defined(__amd64__) /* * Below we'll assume that _RFORK_THREAD_STACK_SIZE is appropriately aligned for * the posix_spawn() case where we do not end up calling execvpe and won't ever @@ -245,7 +244,6 @@ struct posix_spawn_args { #define _RFORK_THREAD_STACK_SIZE 4096 _Static_assert((_RFORK_THREAD_STACK_SIZE % PSPAWN_STACK_ALIGNMENT) == 0, "Inappropriate stack size alignment"); -#endif static int _posix_spawn_thr(void *data) @@ -287,12 +285,14 @@ do_posix_spawn(pid_t *pid, const char *path, pid_t p; int pfd; bool do_pfd; -#ifdef _RFORK_THREAD_STACK_SIZE char *stack; - size_t cnt, stacksz; + size_t stacksz; +#if defined(__i386__) || defined(__amd64__) stacksz = _RFORK_THREAD_STACK_SIZE; if (use_env_path) { + size_t cnt; + /* * We need to make sure we have enough room on the stack for the * potential alloca() in execvPe if it gets kicked back an @@ -319,6 +319,9 @@ do_posix_spawn(pid_t *pid, const char *path, return (ENOMEM); stacksz = (((uintptr_t)stack + stacksz) & ~PSPAWN_STACK_ALIGNBYTES) - (uintptr_t)stack; +#else + stack = NULL; + stacksz = 0; #endif psa.path = path; psa.fa = fa; @@ -341,13 +344,16 @@ do_posix_spawn(pid_t *pid, const char *path, * a special property of the libthr rtld locks ensure that * rtld is operational in the child. In particular, libthr * rtld locks do not store owner' tid into the lock word. - */ -#ifdef _RFORK_THREAD_STACK_SIZE - /* - * x86 stores the return address on the stack, so rfork(2) cannot work - * as-is because the child would clobber the return address of the - * parent. Because of this, we must use rfork_thread instead while - * almost every other arch stores the return address in a register. + * + * x86 stores the return address on the stack, so rfork(2) + * cannot work as-is because the child would clobber the + * return address of the parent. Because of this, we must use + * rfork_thread instead. + * + * Every other architecture stores the return address in a + * register, the trivial rfork_thread() wrapper is provided + * for them. The only minor drawback is that the stack is + * temporarily allocated. */ if (do_pfd) { p = pdrfork_thread(&pfd, PD_CLOEXEC | (*sa)->sa_pdflags, @@ -357,16 +363,7 @@ do_posix_spawn(pid_t *pid, const char *path, &psa); } free(stack); -#else - if (do_pfd) { - p = pdrfork(&pfd, PD_CLOEXEC | (*sa)->sa_pdflags, RFSPAWN); - } else { - p = rfork(RFSPAWN); - } - if (p == 0) - /* _posix_spawn_thr does not return */ - _posix_spawn_thr(&psa); -#endif + /* * The above block should leave us in a state where we've either * succeeded and we're ready to process the results, or we need to