Bug 255320 - Wrong setjmp return value in FreeBSD 13 (at least on aarch64)
Summary: Wrong setjmp return value in FreeBSD 13 (at least on aarch64)
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-22 08:21 UTC by Philipp
Modified: 2021-04-22 08:21 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp 2021-04-22 08:21:17 UTC
I noticed some programs failing on my Raspi 4 on FreeBSD 13, and tracked the issue down to setjmp behaviour.

Apparently setjmp returns 0 when it should return 1.

The FreeBSD man page for setjmp / longjmp does _not_ state that setjmp should return 1 on a longjmp with argument 0. But it states that the functions are conforming to the ISO C90 standard. All C standards, including ISO C90 mandate that setjmp should return 1 on a longjmp with argument 0.

I don't know if this is an issue specific to aarch64, or just some generic FreeBSD issue, as the Raspi is my only FreeBSD system.

I created a small test program to reproduce the issue; it fails on the Raspi, but passes on Debian GNU/Linux on amd64:

I compile using cc test.c, execute via ./a.out.

#include <setjmp.h>
#include <assert.h>

jmp_buf buf;

void g(void)
{
	// When called with an argument of 0, longjmp() should make setjmp() return 1 instead.
	longjmp(buf, 0);
	g();
}

void f1(void)
{
	static int i;
	int j;
	i = 0;
	j = setjmp(buf);
	assert(i == j);
	i++;
	if(!j)
		g();
}

int main(void)
{
	f1();	
	return 0;
}