From nobody Mon Aug 24 05:04:54 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1779486775; cv=none; d=zohomail.com; s=zohoarc; b=G9kUe3ZPNgSF+16AwY5ch8MZab8mc61Dhgsk4D+Cdy9xd3DI4+NT4jsxF/vxRVA6LpdBputkJW8UlABm0tmK8FQcfevKrwHSdRB2YE4WgqLC+4fLJMd+XELfP3la4LMaeAMJuI4/1L3qRT/3FkWhx8KcwVozt+Q47CxD6U/YjTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779486775; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=igYk+RnP6x3JcHiyNljucBdqob3C4uW/Z65VjdfCls0=; b=LUfSow930iZgK23vhVEwJlUSgXwxfKlAetlDCIZSza3bEnvjCvkt4FA26lqczFv+fsVKWHbifkxooJWVFr756wRlPsu/Mp8bgkPNB+tGEITXiFI4I7nURD775tUiGTSegFXZurdzO4mU9tVGdJ97/kQLrJBWU86FhdZdYcc6kBw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779486775743971.9693627260384; Fri, 22 May 2026 14:52:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQXnC-0005yg-T5; Fri, 22 May 2026 17:52:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQXn9-0005cc-Ae; Fri, 22 May 2026 17:52:27 -0400 Received: from isrv.corpit.ru ([212.248.84.144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQXn7-0004Zq-Fj; Fri, 22 May 2026 17:52:26 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 5770A1AFB7C; Sat, 23 May 2026 00:49:21 +0300 (MSK) Received: from think4mjt.tls.msk.ru (mjtthink.wg.tls.msk.ru [192.168.177.146]) by tsrv.corpit.ru (Postfix) with ESMTP id 7D6D03B71CB; Sat, 23 May 2026 00:49:25 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tls.msk.ru; s=202602; t=1779486561; bh=jjsX3vuFG5pdqzcPcvEy5TDx1NFhTrvU0iAbRklyfh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ev+RC5LoNYD3Z9o1HsiOPfPuMY4h0ACCH6bwwFmbmBxjprj1AJLCA+DzRn6Z03z/D DFtqih/yI8stpQ7G8RqgBWFoCvrng4PTJeE0BA/gV7bFP59ZDEDFBuwF3grUUknodM MNySFqlUxxyOJdAaje4S7U//FJ2Y57Z/vdiZqlTEMkq8Z4/lNFtY69JtuxSALFtWNH ZPEYp3QYcTcO+cvXBdHiEglrwenQItuX3FE2rnCoIX/hTdkPSqIaKrr0tKBMRpetsh ZLJpssXtZnJtYATkosEuw5ypZCyJdJTjElEg6/3OgPZKQiEVhkqk+Rj6xDb2WTUZml HiRIpeUnWsJtw== From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Matt Turner , Richard Henderson , Helge Deller , Michael Tokarev Subject: [Stable-10.2.3 134/149] linux-user/sh4: Fix target_ucontext tuc_link field type Date: Sat, 23 May 2026 00:49:06 +0300 Message-ID: <20260522214923.807017-35-mjt@tls.msk.ru> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=212.248.84.144; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @tls.msk.ru) X-ZM-MESSAGEID: 1779486775973158500 Content-Type: text/plain; charset="utf-8" From: Matt Turner tuc_link is declared as 'struct target_ucontext *', which is a HOST pointer. On a 64-bit host running a 32-bit SH4 target, this is 8 bytes instead of the 4 bytes the target expects, padding pushes tuc_mcontext 8 bytes past its correct offset. When a signal handler receives ucontext_t *, every field accessed through uc_mcontext (gregs[], pc, pr, ...) is read from the wrong address. In particular the saved PC comes back as a garbage stack value, which breaks any code that initialises a libunwind cursor from the signal context. Fix it by using abi_ulong, which is always sized to the target ABI (4 bytes for SH4), matching the layout the kernel and glibc agree on. This is the same pattern used by arm/signal.c. Also remove the (unsigned long *) cast from the __put_user that zeros tuc_link. The cast was harmless when tuc_link was pointer-sized (8 bytes matching unsigned long on a 64-bit host), but after the type change __put_user's sizeof dispatch would select stq_le_p (8-byte write) for a now-4-byte field, silently overwriting the start of tuc_stack. Neither this fix nor the companion setup_sigtramp fix is independently sufficient: this fix corrects register values read from the signal context but libunwind still cannot detect the frame without the correct trampoline pattern; that fix makes the frame detectable but register reads remain garbage without the correct ucontext layout. Together they fix the following libunwind tests on a 64-bit host: Gtest-sig-context, Gtest-trace, Ltest-init-local-signal, Ltest-sig-context, Ltest-trace Signed-off-by: Matt Turner Cc: qemu-stable@nongnu.org Reviewed-by: Richard Henderson Signed-off-by: Helge Deller (cherry picked from commit c3176e645774fcb795bf99c1c6c40c67432232db) Signed-off-by: Michael Tokarev diff --git a/linux-user/sh4/signal.c b/linux-user/sh4/signal.c index 9ecc026fae..20d2bc8b2c 100644 --- a/linux-user/sh4/signal.c +++ b/linux-user/sh4/signal.c @@ -57,7 +57,7 @@ struct target_sigframe =20 struct target_ucontext { target_ulong tuc_flags; - struct target_ucontext *tuc_link; + abi_ulong tuc_link; target_stack_t tuc_stack; struct target_sigcontext tuc_mcontext; target_sigset_t tuc_sigmask; /* mask last for extensibility */ @@ -237,7 +237,7 @@ void setup_rt_frame(int sig, struct target_sigaction *k= a, =20 /* Create the ucontext. */ __put_user(0, &frame->uc.tuc_flags); - __put_user(0, (unsigned long *)&frame->uc.tuc_link); + __put_user(0, &frame->uc.tuc_link); target_save_altstack(&frame->uc.tuc_stack, regs); setup_sigcontext(&frame->uc.tuc_mcontext, regs, set->sig[0]); --=20 2.47.3