NetBSD Problem Report #43655

From riastradh@smalltalk.ath.cx  Thu Jul 22 22:08:58 2010
Return-Path: <riastradh@smalltalk.ath.cx>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id E96C363BAE7
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 22 Jul 2010 22:08:57 +0000 (UTC)
Message-Id: <20100722220827.8584781@smalltalk.ath.cx>
Date: Thu, 22 Jul 2010 22:08:27 +0000 (UTC)
From: Taylor R Campbell <campbell+netbsd@mumble.net>
Reply-To: Taylor R Campbell <campbell+netbsd@mumble.net>
To: gnats-bugs@gnats.NetBSD.org
Subject: integer division by zero delivers SIGFPE with wrong siginfo code
X-Send-Pr-Version: 3.95

>Number:         43655
>Category:       port-i386
>Synopsis:       integer division by zero delivers SIGFPE with wrong siginfo code on i386
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-i386-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 22 22:10:01 +0000 2010
>Closed-Date:    Tue Dec 13 08:50:15 +0000 2011
>Last-Modified:  Tue Dec 13 08:50:15 +0000 2011
>Originator:     Taylor R Campbell <campbell+netbsd@mumble.net>
>Release:        NetBSD 5.1_RC2
>Organization:
>Environment:
System: NetBSD ... 5.1_RC2 NetBSD 5.1_RC2 (RIAGATE) #0: Mon Jun 21 22:23:02 UTC 2010 root@.../obj/sys/arch/i386/compile/RIAGATE i386
Architecture: i386
Machine: i386
>Description:

	When the processor traps integer division by zero, NetBSD
	delivers SIGFPE with a siginfo code of FPE_FLTDIV, whereas the
	siginfo code should be FPE_INTDIV.

>How-To-Repeat:

	If the following source code is stored in lose.c, I observe

		% make lose
		cc -O2   -o lose lose.c
		% ./lose 0
		3

	The number 3 is the value of FPE_FLTDIV, as defined in
	<sys/siginfo.h>.  The output should be 1, FPE_INTDIV.  By
	contrast, the same program under Linux, for example, gives 1
	(which is the value of FPE_INTDIV on Linux too).

#include <signal.h>
#include <stdio.h>
#include <unistd.h>

static void
handler (int signal_number, siginfo_t *info, void *context)
{
  int code = (info -> si_code);
  char buffer [1024];
  (void) write (1, buffer, (snprintf (buffer, (sizeof buffer), "%d\n", code)));
  _exit (1);
}

int
main (int argc, char *argv [])
{
  int d = 0;
  static const struct sigaction zero_sa;
  struct sigaction sa_storage = zero_sa, *sa = (&sa_storage);
  (sa -> sa_sigaction) = (&handler);
  (sa -> sa_flags) = SA_SIGINFO;
  (void) sigaction (SIGFPE, sa, 0);
  if (argc < 2) return (1);
  (void) sscanf ((argv [1]), "%d", (&d));
  (void) printf (";%d\n", (1 / d));
  return 0;
}


>Fix:

	Yes, please!

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: kern-bug-people->port-i386-maintainer
Responsible-Changed-By: martin@NetBSD.org
Responsible-Changed-When: Fri, 23 Jul 2010 07:44:38 +0000
Responsible-Changed-Why:
arch specific problem


From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: port-i386/43655 (integer division by zero delivers SIGFPE with wrong siginfo code on i386)
Date: Fri, 23 Jul 2010 09:47:14 +0200

 Hmm, didn't we have a test program that checks various combinations of
 errors and siginfo? Somebody (tm) please find it and add this case.

 Martin

From: Taylor R Campbell <campbell+netbsd@mumble.net>
To: gnats-bugs@NetBSD.org
Cc: port-i386-maintainer@netbsd.org, kern-bug-people@netbsd.org,
	netbsd-bugs@netbsd.org, gnats-admin@netbsd.org,
	martin@NetBSD.org
Subject: Re: port-i386/43655 (integer division by zero delivers SIGFPE with wrong siginfo code on i386)
Date: Fri, 23 Jul 2010 15:12:23 +0000

    Date: Fri, 23 Jul 2010 07:44:39 +0000 (UTC)
    From: martin@NetBSD.org

    arch specific problem

 I'm cc'ing port-i386-maintainer because it looks like amd64 has the
 same problem, from this snippet in amd64/amd64/trap.c:

                 case T_DIVIDE|T_USER:
                         ksi.ksi_code = FPE_FLTDIV;

 T_DIVIDE is the code delivered by trap 0 in amd64/amd64/vector.S,
 which is the trap for integer division by zero.  I think changing that
 and the analogous line in i386/i386/trap.c to use FPE_INTDIV should
 fix the problem, but I haven't tested to confirm this.  FPE_FLTDIV is
 delivered for floating-point division by zero separately, in
 i386/isa/npx.c for i386 and in amd64/amd64/fpu.c for amd64.

 Nearby in both trap.c files is FPE_FLTOVF for integer overflow (traps
 4 and 5), and, in i386/i386/trap.c, FPE_INTOVF for FPU exceptions
 (trap #x10, in what seems to be an unusual case, when NNPX = 0).  This
 code needs to exchange some INTs and FLTs, methinks.

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, port-i386-maintainer@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, 
	Taylor R Campbell <campbell+netbsd@mumble.net>
Cc: 
Subject: Re: port-i386/43655 (integer division by zero delivers SIGFPE with wrong siginfo code on i386)
Date: Sat, 24 Jul 2010 11:34:15 -0400

 On Jul 23,  3:15pm, campbell+netbsd@mumble.net (Taylor R Campbell) wrote:
 -- Subject: Re: port-i386/43655 (integer division by zero delivers SIGFPE wit

 |  I'm cc'ing port-i386-maintainer because it looks like amd64 has the
 |  same problem, from this snippet in amd64/amd64/trap.c:
 |  
 |                  case T_DIVIDE|T_USER:
 |                          ksi.ksi_code = FPE_FLTDIV;
 |  
 |  T_DIVIDE is the code delivered by trap 0 in amd64/amd64/vector.S,
 |  which is the trap for integer division by zero.  I think changing that
 |  and the analogous line in i386/i386/trap.c to use FPE_INTDIV should
 |  fix the problem, but I haven't tested to confirm this.  FPE_FLTDIV is
 |  delivered for floating-point division by zero separately, in
 |  i386/isa/npx.c for i386 and in amd64/amd64/fpu.c for amd64.
 |  
 |  Nearby in both trap.c files is FPE_FLTOVF for integer overflow (traps
 |  4 and 5), and, in i386/i386/trap.c, FPE_INTOVF for FPU exceptions
 |  (trap #x10, in what seems to be an unusual case, when NNPX = 0).  This
 |  code needs to exchange some INTs and FLTs, methinks.

 I am on it.

 christos

From: Christos Zoulas <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/43655 CVS commit: src/sys/arch/i386/i386
Date: Sun, 25 Jul 2010 15:19:07 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Sun Jul 25 19:19:06 UTC 2010

 Modified Files:
 	src/sys/arch/i386/i386: trap.c

 Log Message:
 PR/43655: Taylor R Campbell: Incorrect siginfo code's for integer zero
 divide and overflow.


 To generate a diff of this commit:
 cvs rdiff -u -r1.257 -r1.258 src/sys/arch/i386/i386/trap.c

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

From: Taylor R Campbell <campbell+netbsd@mumble.net>
To: christos@zoulas.com (Christos Zoulas)
Cc: gnats-bugs@NetBSD.org, port-i386-maintainer@netbsd.org,
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: port-i386/43655 (integer division by zero delivers SIGFPE with wrong siginfo code on i386)
Date: Mon, 26 Jul 2010 01:37:03 +0000

    Date: Sat, 24 Jul 2010 11:34:15 -0400
    From: christos@zoulas.com (Christos Zoulas)

    I am on it.

 Thanks.  While you're at it, perhaps you could address the curious
 situation of `floating poing operations' in the siginfo(2) man page.
 I don't know what a poing is, but I'd be happier knowing there aren't
 any floating around me, especially not when they're invalid.

From: christos@zoulas.com (Christos Zoulas)
To: Taylor R Campbell <campbell+netbsd@mumble.net>
Cc: gnats-bugs@NetBSD.org, port-i386-maintainer@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: port-i386/43655 (integer division by zero delivers SIGFPE with wrong siginfo code on i386)
Date: Sun, 25 Jul 2010 22:15:31 -0400

 On Jul 26,  1:37am, campbell+netbsd@mumble.net (Taylor R Campbell) wrote:
 -- Subject: Re: port-i386/43655 (integer division by zero delivers SIGFPE wit

 | Thanks.  While you're at it, perhaps you could address the curious
 | situation of `floating poing operations' in the siginfo(2) man page.
 | I don't know what a poing is, but I'd be happier knowing there aren't
 | any floating around me, especially not when they're invalid.

 Well, it means usually invalid operand to the floating operation requested.
 I don't really want to rename it, or make it more specific, what would you
 like to see instead?

 christos

 PS: I will fix amd64 soon, I have the code written but not tested/committed.

From: Taylor R Campbell <campbell+netbsd@mumble.net>
To: christos@zoulas.com (Christos Zoulas)
Cc: gnats-bugs@NetBSD.org, port-i386-maintainer@netbsd.org,
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: port-i386/43655 (integer division by zero delivers SIGFPE with wrong siginfo code on i386)
Date: Mon, 26 Jul 2010 17:41:53 +0000

    Date: Sun, 25 Jul 2010 22:15:31 -0400
    From: christos@zoulas.com (Christos Zoulas)

    On Jul 26,  1:37am, campbell+netbsd@mumble.net (Taylor R Campbell) wrote:
    -- Subject: Re: port-i386/43655 (integer division by zero delivers SIGFP=
 E wit

    | Thanks.  While you're at it, perhaps you could address the curious
    | situation of `floating poing operations' in the siginfo(2) man page.
    | I don't know what a poing is, but I'd be happier knowing there aren't
    | any floating around me, especially not when they're invalid.

    Well, it means usually invalid operand to the floating operation request=
 ed.
    I don't really want to rename it, or make it more specific, what would y=
 ou
    like to see instead?

 Sorry, I guess my joke wasn't clear enough -- there's just a typo,
 `poing' for `point' in the name of FPE_FLTINV.

From: Paul Goyette <paul@whooppee.com>
To: gnats-bugs@netbsd.org
Cc: Martin Husemann <martin@duskware.de>
Subject: RE: port-i386/43655 (integer division by zero delivers SIGFPE with
 wrong siginfo code on i386)
Date: Fri, 24 Dec 2010 14:48:21 -0800 (PST)

 BTW, there was a request to update the current regression test to cover 
 this situation.  I am working on it during my conversion of the test 
 from the old src/regress format to src/tests


From: "Paul Goyette" <pgoyette@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/43655 CVS commit: src
Date: Sat, 25 Dec 2010 01:04:28 +0000

 Module Name:	src
 Committed By:	pgoyette
 Date:		Sat Dec 25 01:04:27 UTC 2010

 Modified Files:
 	src/distrib/sets/lists/tests: mi
 	src/tests/lib/libc/gen: Makefile
 Added Files:
 	src/tests/lib/libc/gen: t_siginfo.c

 Log Message:
 Move the siginfo tests from regress to atf.  While here, add a new test
 for PR/43655.

 XXX The sigchild_dump test currently fails when execute under atf-run.
 XXX It does not fail when executed directly from the shell, so there's
 XXX something in atf that prevents the child process from dumping.


 To generate a diff of this commit:
 cvs rdiff -u -r1.188 -r1.189 src/distrib/sets/lists/tests/mi
 cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/gen/Makefile
 cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/gen/t_siginfo.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->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 13 Dec 2011 08:50:15 +0000
State-Changed-Why:
All fixed last year.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.