NetBSD Problem Report #59285

From www@netbsd.org  Sat Apr 12 18:30:24 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)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id D4FE11A923F
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 12 Apr 2025 18:30:23 +0000 (UTC)
Message-Id: <20250412183022.BDD671A9241@mollari.NetBSD.org>
Date: Sat, 12 Apr 2025 18:30:22 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: _longjmp(..., 0) makes setjmp return 0, not 1
X-Send-Pr-Version: www-1.0

>Number:         59285
>Category:       port-mips
>Synopsis:       _longjmp(..., 0) makes setjmp return 0, not 1
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-mips-maintainer
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 12 18:35:01 +0000 2025
>Closed-Date:    
>Last-Modified:  Thu Apr 24 12:55:01 +0000 2025
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, ...
>Organization:
The MipsBSD _Longjmpzero
>Environment:
>Description:
Test case: lib/libc/setjmp/t_setjmp/_longjmp_zero

Duration: 1.332031 seconds
Termination reason

FAILED: setjmp returned zero after longjmp

https://releng.netbsd.org/b5reports/pmax/2025/2025.04.11.04.54.02/test.html#lib_libc_setjmp_t_setjmp__longjmp_zero

Only happens with _longjmp, not the other versions.

Cursory examination of _setjmp.S shows that nothing is done to map 0 to 1 before passing it as the return value -- though curiously the argument a1 is both _stored_ in the jmp_buf _and moved_ to the return value register v0, when I would expect only the latter is necessary:

    119 LEAF(_longjmp)
...
    130 	REG_S		a1, _SC_REGS_V0(a0)	# save return value
...
    178 	j	ra
    179 	 move	v0, a1			# get return value in 1st arg

https://nxr.netbsd.org/xref/src/lib/libc/arch/mips/gen/_setjmp.S?r=1.26#119

There are some other instructions in the middle that use v0 as a temporary (for restoring the floating-point control and status register), but that doesn't seem to touch a1.
>How-To-Repeat:
cd /usr/tests/lib/libc/setjmp
atf-run t_setjmp | atf-report
>Fix:
Yes, please!

>Release-Note:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59285 CVS commit: src/tests/lib/libc/setjmp
Date: Tue, 22 Apr 2025 13:12:11 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Apr 22 13:12:11 UTC 2025

 Modified Files:
 	src/tests/lib/libc/setjmp: t_setjmp.c

 Log Message:
 t_setjmp: Mark _longjmp_zero xfail on mips.

 PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1


 To generate a diff of this commit:
 cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/setjmp/t_setjmp.c

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

State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 22 Apr 2025 17:01:51 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-10 and pullup-9


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59285 CVS commit: src
Date: Tue, 22 Apr 2025 17:01:31 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Tue Apr 22 17:01:31 UTC 2025

 Modified Files:
 	src/lib/libc/arch/mips/gen: _setjmp.S
 	src/tests/lib/libc/setjmp: t_setjmp.c

 Log Message:
 mips: Fix _longjmp(..., 0) so _setjmp returns 1 as intended.

 _setjmp (like setjmp and sigsetjmp) is only permitted to return 0 the
 first time around.

 PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1


 To generate a diff of this commit:
 cvs rdiff -u -r1.26 -r1.27 src/lib/libc/arch/mips/gen/_setjmp.S
 cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/setjmp/t_setjmp.c

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

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59285 CVS commit: src/tests/lib/libc/setjmp
Date: Thu, 24 Apr 2025 01:41:01 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Thu Apr 24 01:41:01 UTC 2025

 Modified Files:
 	src/tests/lib/libc/setjmp: t_setjmp.c

 Log Message:
 t_setjmp: Tidy up.

 - KNF.
 - Nix trailing whitespace.
 - Use RL from h_macros.h.
 - Use enum and case.

 No functional change intended.

 Preparation for extending these tests to the compat13 functions,
 prompted by:

 PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1
 PR port-mips/59342: compat_setjmp.S is confused about delay slots
 PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64


 To generate a diff of this commit:
 cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/setjmp/t_setjmp.c

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

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59285 CVS commit: src
Date: Thu, 24 Apr 2025 01:43:21 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Thu Apr 24 01:43:20 UTC 2025

 Modified Files:
 	src/lib/libc/compat/arch/mips/gen: compat_setjmp.S
 	src/tests/lib/libc/setjmp: t_setjmp.c t_sigstack.c

 Log Message:
 mips/compat_longjmp: Make sure compat13 setjmp returns nonzero.

 PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1


 To generate a diff of this commit:
 cvs rdiff -u -r1.6 -r1.7 src/lib/libc/compat/arch/mips/gen/compat_setjmp.S
 cvs rdiff -u -r1.9 -r1.10 src/tests/lib/libc/setjmp/t_setjmp.c
 cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libc/setjmp/t_sigstack.c

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

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59285 CVS commit: src/sys/arch/mips/mips
Date: Thu, 24 Apr 2025 12:54:43 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Thu Apr 24 12:54:43 UTC 2025

 Modified Files:
 	src/sys/arch/mips/mips: compat_13_machdep.c

 Log Message:
 mips: Fix compat_13_sys_sigreturn locking.

 This had been broken back in rev. 1.13.20.1 (on the newlock2 branch,
 merged into HEAD as 1.14) in 2007.

 Should fix:

    lib/libc/setjmp/t_setjmp (261/985): 10 test cases
        _longjmp_zero: [0.078125s] Passed.
        _setjmp: [0.093750s] Passed.
        compat13_longjmp_zero: [ 7875.3945352] panic: kernel diagnostic assertion "mutex_owned(l->l_proc->p_lock)" failed: file "/tmp/build/2025.04.24.01.52.38-pmax/src/sys/kern/sys_sig.c", line 590
    [ 7875.3984415] cpu0: Begin traceback...
    [ 7875.4062540] pid -2135532376 not found
    [ 7875.4140665] cpu0: End traceback...
    [ 7875.6093790] 0x80b65c90: cpu_reboot+0x3c (0x80b64000,0,0x866e5400,0x805b6440) ra 0x803197c0 sz 24
    [ 7875.7109415] 0x80b65ca8: kern_reboot+0xb0 (0x80b64000,0,0x866e5400,0x805b6440) ra 0x80369c80 sz 40
    [ 7875.7109415] 0x80b65cd0: vpanic+0x1dc (0x80b64000,0,0x866e5400,0x805b6440) ra 0x804c085c sz 48
    [ 7875.7109415] 0x80b65d00: kern_assert+0x3c (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x8038df4c sz 32
    [ 7875.7265665] 0x80b65d20: sigprocmask1+0x224 (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x800616f0 sz 48
    [ 7875.7265665] 0x80b65d50: compat_13_sys_sigreturn+0x1f0 (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x80055178 sz 376
    [ 7875.7265665] 0x80b65ec8: syscall+0x158 (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x800450ac sz 128
    [ 7875.7265665] 0x80b65f48: mips1_systemcall+0xec (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0x7923d090 sz 0
    [ 7875.7265665] PC 0x7923d090: not in kernel space
    [ 7875.7265665] 0x80b65f48: 0+0x7923d090 (0x80b64000,0x804e6a3c,0x8051f7a8,0x8052e330) ra 0 sz 0
    [ 7875.7265665] User-level: pid 17290.17290

 https://releng.netbsd.org/b5reports/pmax/2025/2025.04.24.01.52.38/test.log

 (Probably won't do anything about `pid -2135532376 not found',
 though!)

 Prompted by adding tests for compat13 for:

 PR port-mips/59285: _longjmp(..., 0) makes setjmp return 0, not 1
 PR port-mips/59342: compat_setjmp.S is confused about delay slots
 PR port-mips/59343: compat_sigsetjmp.S: missing RESTORE_GP64


 To generate a diff of this commit:
 cvs rdiff -u -r1.22 -r1.23 src/sys/arch/mips/mips/compat_13_machdep.c

 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.