From nobody@FreeBSD.org  Sat Jan 21 20:26:42 2006
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 3A3D116A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 21 Jan 2006 20:26:42 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 0022143D45
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 21 Jan 2006 20:26:41 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k0LKQfwG097827
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 21 Jan 2006 20:26:41 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id k0LKQfk1097826;
	Sat, 21 Jan 2006 20:26:41 GMT
	(envelope-from nobody)
Message-Id: <200601212026.k0LKQfk1097826@www.freebsd.org>
Date: Sat, 21 Jan 2006 20:26:41 GMT
From: Tanaka Akira <akr@m17n.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: setcontext restore the carry flag
X-Send-Pr-Version: www-2.3

>Number:         92110
>Category:       kern
>Synopsis:       setcontext restore the carry flag
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    davidxu
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan 21 20:30:03 GMT 2006
>Closed-Date:    Tue Apr 25 11:16:19 GMT 2006
>Last-Modified:  Wed Apr 21 11:20:02 UTC 2010
>Originator:     Tanaka Akira
>Release:        FreeBSD 5.4
>Organization:
AIST
>Environment:
FreeBSD freebsd54.vmw 5.4-RELEASE FreeBSD 5.4-RELEASE #0: Sun May  8 10:21:06 UTC 2005     root@harlow.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

>Description:
On Pentium, getcontext saves EFLAGS and setcontext restores it.
When CF is set in EFLAGS, setcontext treats it as an system call error.

>How-To-Repeat:
% cat t.c
#include <stdlib.h>
#include <stdio.h>
#include <ucontext.h>

ucontext_t c;
int first;

volatile int carry_set;

int main()
{
  first = 1;

  carry_set = ~0;
  carry_set += 1;
  if (getcontext(&c) != 0) {
    perror("getcontext");
    exit(1);
  }

  printf("first:%d\n", first);

  if (first == 0)
    exit(0);

  first = 0;

  if (setcontext(&c) != 0) {
    perror("setcontext");
    exit(1);
  }

  printf("setcontext returns\n");
  exit(1);
}

% gcc -march=pentium4 t.c      
% ./a.out 
first:1
setcontext: Unknown error: 0

If "carry_set += 1" is changed to "carry_set -= 1", it works fine:

% ./a.out 
first:1
first:0

>Fix:
              
>Release-Note:
>Audit-Trail:

From: David Xu <davidxu@freebsd.org>
To: bug-followup@freebsd.org, akr@m17n.org
Cc:  
Subject: Re: misc/92110: setcontext restore the carry flag
Date: Fri, 03 Feb 2006 10:35:58 +0800

 I have committed a fix in -HEAD,  please try it
 if you have time.
 
 David Xu
 
State-Changed-From-To: open->patched 
State-Changed-By: linimon 
State-Changed-When: Fri Feb 3 04:48:54 UTC 2006 
State-Changed-Why:  
Set as MFC reminder. 


Responsible-Changed-From-To: freebsd-bugs->davidxu 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Feb 3 04:48:54 UTC 2006 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=92110 
State-Changed-From-To: patched->closed 
State-Changed-By: davidxu 
State-Changed-When: Tue Apr 25 11:13:38 UTC 2006 
State-Changed-Why:  
Fixed in RELENG_5, RELENG_6 and HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=92110 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/92110: commit references a PR
Date: Wed, 21 Apr 2010 11:17:30 +0000 (UTC)

 Author: kib
 Date: Wed Apr 21 11:17:16 2010
 New Revision: 206992
 URL: http://svn.freebsd.org/changeset/base/206992
 
 Log:
   As was done in r155238 for i386 and in r155239 for amd64, clear the carry
   flag for ia32 binary executed on amd64 host in get_mcontext().
   
   PR:	kern/92110 (one more time)
   Reported by:	stas
   MFC after:	1 week
 
 Modified:
   head/sys/amd64/ia32/ia32_signal.c
 
 Modified: head/sys/amd64/ia32/ia32_signal.c
 ==============================================================================
 --- head/sys/amd64/ia32/ia32_signal.c	Wed Apr 21 11:11:11 2010	(r206991)
 +++ head/sys/amd64/ia32/ia32_signal.c	Wed Apr 21 11:17:16 2010	(r206992)
 @@ -141,9 +141,11 @@ ia32_get_mcontext(struct thread *td, str
  	mcp->mc_esi = tp->tf_rsi;
  	mcp->mc_ebp = tp->tf_rbp;
  	mcp->mc_isp = tp->tf_rsp;
 +	mcp->mc_eflags = tp->tf_rflags;
  	if (flags & GET_MC_CLEAR_RET) {
  		mcp->mc_eax = 0;
  		mcp->mc_edx = 0;
 +		mcp->mc_eflags &= ~PSL_C;
  	} else {
  		mcp->mc_eax = tp->tf_rax;
  		mcp->mc_edx = tp->tf_rdx;
 @@ -152,7 +154,6 @@ ia32_get_mcontext(struct thread *td, str
  	mcp->mc_ecx = tp->tf_rcx;
  	mcp->mc_eip = tp->tf_rip;
  	mcp->mc_cs = tp->tf_cs;
 -	mcp->mc_eflags = tp->tf_rflags;
  	mcp->mc_esp = tp->tf_rsp;
  	mcp->mc_ss = tp->tf_ss;
  	mcp->mc_len = sizeof(*mcp);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
