NetBSD Problem Report #59307

From www@netbsd.org  Thu Apr 17 05:21:51 2025
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id DE7F61A9239
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 17 Apr 2025 05:21:51 +0000 (UTC)
Message-Id: <20250417052150.2E3391A923D@mollari.NetBSD.org>
Date: Thu, 17 Apr 2025 05:21:50 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: kernel longjmp(9) fails to make setjmp(9) return 1
X-Send-Pr-Version: www-1.0

>Number:         59307
>Category:       port-sparc
>Synopsis:       kernel longjmp(9) fails to make setjmp(9) return 1
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-sparc-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 17 05:25:00 +0000 2025
>Last-Modified:  Tue Apr 29 14:55:00 +0000 2025
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
I jumped because it sparced when I put a fork in the outlet Foundation
>Environment:
>Description:
Kernel longjmp(9) is supposed to make setjmp(9) return 1 -- it doesn't
take a second argument for the return value.  But the sparc code does
this:

   6044 ENTRY(longjmp)
   6045 	addcc	%o1, %g0, %g6	! compute v ? v : 1 in a global register
   6046 	be,a	0f
   6047 	 mov	1, %g6
   6048 0:

https://nxr.netbsd.org/xref/src/sys/arch/sparc/sparc/locore.s?r=1.285#6044

Here, because we have not executed `save' to cycle the register
windows, %o0 is the first argument (label_t pointer), and %o1 --
normally the second argument register -- is garbage because longjmp(9)
doesn't have a second argument.  Strictly speaking we have not
documented that longjmp(9) make setjmp(9) return _exactly_ 1 -- it
just has to return nonzero.  But, it's pretty weird to return register
garbage!  So I think this should be changed to return exactly 1,
unconditionally.

sparc64 has some similar logic, but with a conditional move instead,
and after a `save' instruction so the second argument register is %i1
rather than %o1:

   7750 	movrz	%i1, %i1, %i2	! compute v ? v : 1

https://nxr.netbsd.org/xref/src/sys/arch/sparc64/sparc64/locore.s#7750
>How-To-Repeat:
code inspection
mess with ddb, probably
>Fix:
sparc: Change everything before the 0 label to: mov 1, %g6
sparc64: Change the movrz to: mov 1, %i2

>Release-Note:

>Audit-Trail:

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59307 CVS commit: src/tests/kernel
Date: Tue, 29 Apr 2025 04:53:46 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Apr 29 04:53:46 UTC 2025

 Modified Files:
 	src/tests/kernel: t_setjmp.sh

 Log Message:
 PR port-sparc/59307 does not apply to sparc64


 To generate a diff of this commit:
 cvs rdiff -u -r1.2 -r1.3 src/tests/kernel/t_setjmp.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59307 CVS commit: src/sys/arch/sparc/sparc
Date: Tue, 29 Apr 2025 09:55:14 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Apr 29 09:55:14 UTC 2025

 Modified Files:
 	src/sys/arch/sparc/sparc: locore.s

 Log Message:
 PR port-sparc/59307: kernel longjmp(9) only gets a single argument,
 make setjmp(9) always return 1 via longjmp(9).


 To generate a diff of this commit:
 cvs rdiff -u -r1.285 -r1.286 src/sys/arch/sparc/sparc/locore.s

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59307 CVS commit: src/tests/kernel
Date: Tue, 29 Apr 2025 09:55:59 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Apr 29 09:55:59 UTC 2025

 Modified Files:
 	src/tests/kernel: t_setjmp.sh

 Log Message:
 PR port-sparc/59307 has been fixed, remove expected failure


 To generate a diff of this commit:
 cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/t_setjmp.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59307 CVS commit: src/sys/arch/sparc64/sparc64
Date: Tue, 29 Apr 2025 14:53:54 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Apr 29 14:53:54 UTC 2025

 Modified Files:
 	src/sys/arch/sparc64/sparc64: locore.s

 Log Message:
 PR 59307: fix longjmp(9) for sparc64 too (there is only a single arg,
 return value from setjmp is always 1).


 To generate a diff of this commit:
 cvs rdiff -u -r1.434 -r1.435 src/sys/arch/sparc64/sparc64/locore.s

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.