From nobody Sat Feb 7 09:12:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628000799394399.4782089293475; Tue, 3 Aug 2021 07:26:39 -0700 (PDT) Received: from localhost ([::1]:55850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAvNO-0001wi-5t for importer@patchew.org; Tue, 03 Aug 2021 10:26:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAvM1-0007W5-Uu for qemu-devel@nongnu.org; Tue, 03 Aug 2021 10:25:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAvLz-00018k-RT for qemu-devel@nongnu.org; Tue, 03 Aug 2021 10:25:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-98-p5ZJLppuNVKL0kLxHV-aHg-1; Tue, 03 Aug 2021 10:25:09 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8092F107ACF5; Tue, 3 Aug 2021 14:25:08 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id C987B19C44; Tue, 3 Aug 2021 14:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628000711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h/Sv1V243bpQ+RTIttD2wBJ7Rno5NPyWfMsFHgL8vEc=; b=f8C2e0HNPBQpha/ftBR93esxKzFOsBoCghdyLxZa/ppOJ2u93W1Iesu+XnfIqCIXfZfFln Tl3c9ZzM4pZcOOqrKUJE0VAcN4+aQOE99mZQENeNxxNntOEIzDN1crRJDm9TC+9imfv0yp YlHmg9VinPGiOC6+8evbKgOfFIOyzjc= X-MC-Unique: p5ZJLppuNVKL0kLxHV-aHg-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 1/3] target/s390x: Fix SIGILL and SIGFPE psw.addr reporting Date: Tue, 3 Aug 2021 16:24:53 +0200 Message-Id: <20210803142455.89123-2-thuth@redhat.com> In-Reply-To: <20210803142455.89123-1-thuth@redhat.com> References: <20210803142455.89123-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, Cornelia Huck , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628000800239100001 Content-Type: text/plain; charset="utf-8" From: Ilya Leoshkevich For SIGILL, SIGFPE and SIGTRAP the PSW must point after the instruction, and at the instruction for other signals. Currently under qemu-user for SIGFILL and SIGFPE it points at the instruction. Fix by advancing psw.addr for these signals. Co-developed-by: Ulrich Weigand Signed-off-by: Ilya Leoshkevich Reviewed-by: David Hildenbrand Buglink: https://gitlab.com/qemu-project/qemu/-/issues/319 Message-Id: <20210705210434.45824-2-iii@linux.ibm.com> Signed-off-by: Thomas Huth --- linux-user/s390x/cpu_loop.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c index f2d1215fb1..22f2e89c62 100644 --- a/linux-user/s390x/cpu_loop.c +++ b/linux-user/s390x/cpu_loop.c @@ -64,7 +64,13 @@ void cpu_loop(CPUS390XState *env) case EXCP_DEBUG: sig =3D TARGET_SIGTRAP; n =3D TARGET_TRAP_BRKPT; - goto do_signal_pc; + /* + * For SIGTRAP the PSW must point after the instruction, which= it + * already does thanks to s390x_tr_tb_stop(). si_addr doesn't = need + * to be filled. + */ + addr =3D 0; + goto do_signal; case EXCP_PGM: n =3D env->int_pgm_code; switch (n) { @@ -132,6 +138,10 @@ void cpu_loop(CPUS390XState *env) =20 do_signal_pc: addr =3D env->psw.addr; + /* + * For SIGILL and SIGFPE the PSW must point after the instruct= ion. + */ + env->psw.addr +=3D env->int_pgm_ilen; do_signal: info.si_signo =3D sig; info.si_errno =3D 0; --=20 2.27.0 From nobody Sat Feb 7 09:12:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628000803193315.7127271732321; Tue, 3 Aug 2021 07:26:43 -0700 (PDT) Received: from localhost ([::1]:56204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAvNS-0002BE-5C for importer@patchew.org; Tue, 03 Aug 2021 10:26:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAvM6-0007j9-N8 for qemu-devel@nongnu.org; Tue, 03 Aug 2021 10:25:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56338) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAvM5-0001DK-5T for qemu-devel@nongnu.org; Tue, 03 Aug 2021 10:25:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-RKtdI89yP_WhaYSHtud9JA-1; Tue, 03 Aug 2021 10:25:11 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 575F31853028; Tue, 3 Aug 2021 14:25:10 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0E8C19C44; Tue, 3 Aug 2021 14:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628000716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ugd0zwEwz2Nbp9/hIOj5FCBI/JITLW9dOIXoDgUY2/Y=; b=isH5KzVWr98fkxeFeAk3WI9CsRrLbV5wke2pEUj0ctQuXs2uW/fjjT1De62ns2syw6bNbw /nveuqsi7l0rmIF1Oeqz8+dn0oBxPIWNnZXU2Pj+lIb5sdq/Nag5RFvdSrMslaFSrRnK8j Opwhqj3XQlc/PysdIeOw6W+gBZkZlAM= X-MC-Unique: RKtdI89yP_WhaYSHtud9JA-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 2/3] linux-user/s390x: signal with SIGFPE on compare-and-trap Date: Tue, 3 Aug 2021 16:24:54 +0200 Message-Id: <20210803142455.89123-3-thuth@redhat.com> In-Reply-To: <20210803142455.89123-1-thuth@redhat.com> References: <20210803142455.89123-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, Cornelia Huck , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628000804602100003 Content-Type: text/plain; charset="utf-8" From: Jonathan Albrecht Currently when a compare-and-trap instruction is executed, qemu will always raise a SIGILL signal. On real hardware, a SIGFPE is raised. Change the PGM_DATA case in cpu_loop to follow the behavior in linux kernel /arch/s390/kernel/traps.c. * Only raise SIGILL if DXC =3D=3D 0 * If DXC matches a non-simulated IEEE exception, raise SIGFPE with correct si_code * Raise SIGFPE with si_code =3D=3D 0 for everything else When applied on 20210705210434.45824-2-iii@linux.ibm.com, this fixes crashes in the java jdk such as the linked bug. Signed-off-by: Jonathan Albrecht Reviewed-by: Richard Henderson Buglink: https://bugs.launchpad.net/qemu/+bug/1920913 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/319 Message-Id: <20210709160459.4962-2-jonathan.albrecht@linux.vnet.ibm.com> Signed-off-by: Thomas Huth --- linux-user/s390x/cpu_loop.c | 54 +++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c index 22f2e89c62..6a69a6dd26 100644 --- a/linux-user/s390x/cpu_loop.c +++ b/linux-user/s390x/cpu_loop.c @@ -25,6 +25,35 @@ /* s390x masks the fault address it reports in si_addr for SIGSEGV and SIG= BUS */ #define S390X_FAIL_ADDR_MASK -4096LL =20 +static int get_pgm_data_si_code(int dxc_code) +{ + switch (dxc_code) { + /* Non-simulated IEEE exceptions */ + case 0x80: + return TARGET_FPE_FLTINV; + case 0x40: + return TARGET_FPE_FLTDIV; + case 0x20: + case 0x28: + case 0x2c: + return TARGET_FPE_FLTOVF; + case 0x10: + case 0x18: + case 0x1c: + return TARGET_FPE_FLTUND; + case 0x08: + case 0x0c: + return TARGET_FPE_FLTRES; + } + /* + * Non-IEEE and simulated IEEE: + * Includes compare-and-trap, quantum exception, etc. + * Simulated IEEE are included here to match current + * s390x linux kernel. + */ + return 0; +} + void cpu_loop(CPUS390XState *env) { CPUState *cs =3D env_cpu(env); @@ -106,29 +135,14 @@ void cpu_loop(CPUS390XState *env) =20 case PGM_DATA: n =3D (env->fpc >> 8) & 0xff; - if (n =3D=3D 0xff) { - /* compare-and-trap */ + if (n =3D=3D 0) { goto do_sigill_opn; - } else { - /* An IEEE exception, simulated or otherwise. */ - if (n & 0x80) { - n =3D TARGET_FPE_FLTINV; - } else if (n & 0x40) { - n =3D TARGET_FPE_FLTDIV; - } else if (n & 0x20) { - n =3D TARGET_FPE_FLTOVF; - } else if (n & 0x10) { - n =3D TARGET_FPE_FLTUND; - } else if (n & 0x08) { - n =3D TARGET_FPE_FLTRES; - } else { - /* ??? Quantum exception; BFP, DFP error. */ - goto do_sigill_opn; - } - sig =3D TARGET_SIGFPE; - goto do_signal_pc; } =20 + sig =3D TARGET_SIGFPE; + n =3D get_pgm_data_si_code(n); + goto do_signal_pc; + default: fprintf(stderr, "Unhandled program exception: %#x\n", n); cpu_dump_state(cs, stderr, 0); --=20 2.27.0 From nobody Sat Feb 7 09:12:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628000801506606.1543760058088; Tue, 3 Aug 2021 07:26:41 -0700 (PDT) Received: from localhost ([::1]:55996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAvNQ-00023Q-6g for importer@patchew.org; Tue, 03 Aug 2021 10:26:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAvM5-0007fk-7D for qemu-devel@nongnu.org; Tue, 03 Aug 2021 10:25:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35015) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAvM3-0001BV-Iv for qemu-devel@nongnu.org; Tue, 03 Aug 2021 10:25:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-296-zG-rCUJxNmemm15laK-18w-1; Tue, 03 Aug 2021 10:25:13 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 336011853024; Tue, 3 Aug 2021 14:25:12 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id B406F19C44; Tue, 3 Aug 2021 14:25:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628000715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=szQs0x7Z8Z5OtOpqoWrJLc2bfaEiBx+Rzk3dJk7MMYA=; b=fgdhbDO8sNiS+fRUoLQKhFpXKwJ6w5HXugjw+/opvczmDYJFYKel/dSOfDvVWumkJNpJCp B3InRs0SbgvVc8k+8Q6MD8wKQNgiskXpV2ySpziLAk1ZmHJoj1+eDxXp8YJ6WjOfJss0/n cDntVRLeNkkZQig0amya9c05UDcLVLs= X-MC-Unique: zG-rCUJxNmemm15laK-18w-1 From: Thomas Huth To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 3/3] tests/tcg: Test that compare-and-trap raises SIGFPE Date: Tue, 3 Aug 2021 16:24:55 +0200 Message-Id: <20210803142455.89123-4-thuth@redhat.com> In-Reply-To: <20210803142455.89123-1-thuth@redhat.com> References: <20210803142455.89123-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=thuth@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-s390x@nongnu.org, Cornelia Huck , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628000802585100001 Content-Type: text/plain; charset="utf-8" From: Jonathan Albrecht Signed-off-by: Jonathan Albrecht Message-Id: <20210709160459.4962-3-jonathan.albrecht@linux.vnet.ibm.com> Signed-off-by: Thomas Huth --- tests/tcg/s390x/Makefile.target | 2 +- tests/tcg/s390x/trap.c | 102 ++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/s390x/trap.c diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.tar= get index 5d3de1b27a..bd084c7840 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -8,4 +8,4 @@ TESTS+=3Dexrl-trtr TESTS+=3Dpack TESTS+=3Dmvo TESTS+=3Dmvc - +TESTS+=3Dtrap diff --git a/tests/tcg/s390x/trap.c b/tests/tcg/s390x/trap.c new file mode 100644 index 0000000000..d4c61c7f52 --- /dev/null +++ b/tests/tcg/s390x/trap.c @@ -0,0 +1,102 @@ +/* + * Copyright 2021 IBM Corp. + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static void error1(const char *filename, int line, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + fprintf(stderr, "%s:%d: ", filename, line); + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + va_end(ap); + exit(1); +} + +static int __chk_error(const char *filename, int line, int ret) +{ + if (ret < 0) { + error1(filename, line, "%m (ret=3D%d, errno=3D%d/%s)", + ret, errno, strerror(errno)); + } + return ret; +} + +#define error(fmt, ...) error1(__FILE__, __LINE__, fmt, ## __VA_ARGS__) + +#define chk_error(ret) __chk_error(__FILE__, __LINE__, (ret)) + +int sigfpe_count; +int sigill_count; + +static void sig_handler(int sig, siginfo_t *si, void *puc) +{ + if (sig =3D=3D SIGFPE) { + if (si->si_code !=3D 0) { + error("unexpected si_code: 0x%x !=3D 0", si->si_code); + } + ++sigfpe_count; + return; + } + + if (sig =3D=3D SIGILL) { + ++sigill_count; + return; + } + + error("unexpected signal 0x%x\n", sig); +} + +int main(int argc, char **argv) +{ + sigfpe_count =3D sigill_count =3D 0; + + struct sigaction act; + + /* Set up SIG handler */ + act.sa_sigaction =3D sig_handler; + sigemptyset(&act.sa_mask); + act.sa_flags =3D SA_SIGINFO; + chk_error(sigaction(SIGFPE, &act, NULL)); + chk_error(sigaction(SIGILL, &act, NULL)); + + uint64_t z =3D 0x0ull; + uint64_t lz =3D 0xffffffffffffffffull; + asm volatile ( + "lg %%r13,%[lz]\n" + "cgitne %%r13,0\n" /* SIGFPE */ + "lg %%r13,%[z]\n" + "cgitne %%r13,0\n" /* no trap */ + "nopr\n" + "lg %%r13,%[lz]\n" + "citne %%r13,0\n" /* SIGFPE */ + "lg %%r13,%[z]\n" + "citne %%r13,0\n" /* no trap */ + "nopr\n" + : + : [z] "m" (z), [lz] "m" (lz) + : "memory", "r13"); + + if (sigfpe_count !=3D 2) { + error("unexpected SIGFPE count: %d !=3D 2", sigfpe_count); + } + if (sigill_count !=3D 0) { + error("unexpected SIGILL count: %d !=3D 0", sigill_count); + } + + printf("PASS\n"); + return 0; +} --=20 2.27.0