From nobody@FreeBSD.org  Wed Feb 20 05:42:29 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 6862916A404
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Feb 2008 05:42:29 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 4234313C4F5
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Feb 2008 05:42:29 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m1K5dvaj086507
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 20 Feb 2008 05:39:57 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m1K5dv0f086506;
	Wed, 20 Feb 2008 05:39:57 GMT
	(envelope-from nobody)
Message-Id: <200802200539.m1K5dv0f086506@www.freebsd.org>
Date: Wed, 20 Feb 2008 05:39:57 GMT
From: Yuri <yuri@tsoft.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: truss shows 'pipe' system call as having 6 arguments when it only has one
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         120870
>Category:       bin
>Synopsis:       [patch] truss(1) shows 'pipe' system call as having 6 arguments when it only has one
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 20 05:50:02 UTC 2008
>Closed-Date:    Sun Nov 27 11:32:14 UTC 2011
>Last-Modified:  Sun Nov 27 11:32:14 UTC 2011
>Originator:     Yuri
>Release:        7.0-PRERELEASE FreeBSD 7.0-PRERELEASE #4: Tue Feb 19 08:18:11 PST 2008
>Organization:
n/a
>Environment:
>Description:
When I run a program under truss I see output lines like this:
pipe(0xbfbfd92c,0x28077200,0x0,0x1,0x0,0xbfbfd9a4) = 6 (0x6)

And it should be something like this:
pipe([6,7]) = 0

truss source code processes 'pipe' as special case. But somehow this code
doesn't work as intended.

>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: Yuri <yuri@tsoft.com>
To: bug-followup@FreeBSD.org, yuri@tsoft.com
Cc:  
Subject: Re: bin/120870: truss(1) shows 'pipe' system call as having 6 arguments
 when it only has one
Date: Wed, 20 Feb 2008 11:23:46 -0800

 Same problem also for getpid, it's shown as
 getpid(0x0,0x0,0x0,0x0,0x0,0x0)                  = 34728 (0x87a8)
 

From: Jaakko Heinonen <jh@saunalahti.fi>
To: bug-followup@FreeBSD.org, yuri@tsoft.com
Cc: alfred@FreeBSD.org
Subject: Re: bin/120870: truss(1) shows 'pipe' system call as having 6
	arguments when it only has one
Date: Sat, 23 Feb 2008 14:12:23 +0200

 --BOKacYhQ+x31HxR3
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 
 Hi,
 
 The following patch fixes truss output for geteuid, getpid, getuid and
 pipe system calls for me. (Tested on i386 only.) The pipe case probably
 needs a better fix because the special case is handled only in
 i386-fbsd.c.
 
 (alfred@ cc'd because you are listed in src/MAINTAINERS for truss.)
 
 -- 
 Jaakko
 
 --BOKacYhQ+x31HxR3
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="truss-arguments.diff"
 
 Index: i386-fbsd.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/truss/i386-fbsd.c,v
 retrieving revision 1.29
 diff -u -r1.29 i386-fbsd.c
 --- i386-fbsd.c	28 Jul 2007 23:15:04 -0000	1.29
 +++ i386-fbsd.c	23 Feb 2008 12:05:34 -0000
 @@ -309,10 +309,8 @@
    /*
     * The pipe syscall returns its fds in two registers and has assembly glue
     * to provide the libc API, so it cannot be handled like regular syscalls.
 -   * The nargs check is so we don't have to do yet another strcmp on every
 -   * syscall.
     */
 -  if (!errorp && fsc.nargs == 0 && fsc.name && strcmp(fsc.name, "pipe") == 0) {
 +  if (!errorp && fsc.name && strcmp(fsc.name, "pipe") == 0) {
        fsc.nargs = 1;
        fsc.s_args = malloc((1+fsc.nargs) * sizeof(char*));
        asprintf(&fsc.s_args[0], "[%d,%d]", (int)retval, regs.r_edx);
 Index: syscalls.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/truss/syscalls.c,v
 retrieving revision 1.56
 diff -u -r1.56 syscalls.c
 --- syscalls.c	3 Jan 2008 00:18:03 -0000	1.56
 +++ syscalls.c	23 Feb 2008 12:05:35 -0000
 @@ -93,6 +93,12 @@
  struct syscall syscalls[] = {
  	{ "fcntl", 1, 3,
  	  { { Int, 0 } , { Fcntl, 1 }, { Fcntlflag | OUT, 2 }}},
 +	{ "geteuid", 1, 0,
 +	  { { None, 0 }}},
 +	{ "getpid", 1, 0,
 +	  { { None, 0 }}},
 +	{ "getuid", 1, 0,
 +	  { { None, 0 }}},
  	{ "readlink", 1, 3,
  	  { { Name, 0 } , { Readlinkres | OUT, 1 }, { Int, 2 }}},
  	{ "lseek", 2, 3,
 
 --BOKacYhQ+x31HxR3--
Responsible-Changed-From-To: freebsd-bugs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Mon Dec 21 17:30:46 UTC 2009 
Responsible-Changed-Why:  
Take. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/120870: commit references a PR
Date: Mon, 21 Dec 2009 17:38:29 +0000 (UTC)

 Author: jh
 Date: Mon Dec 21 17:38:13 2009
 New Revision: 200780
 URL: http://svn.freebsd.org/changeset/base/200780
 
 Log:
   Remove non-working special case for pipe(2) from amd64-fbsd32.c and
   i386-fbsd.c. Add pipe(2) to syscall table to decode it's pointer
   argument properly and re-add special handling for pipe(2) return value
   to print_syscall_ret().
   
   PR:		bin/120870
   Approved by:	trasz (mentor)
 
 Modified:
   head/usr.bin/truss/amd64-fbsd32.c
   head/usr.bin/truss/i386-fbsd.c
   head/usr.bin/truss/syscalls.c
 
 Modified: head/usr.bin/truss/amd64-fbsd32.c
 ==============================================================================
 --- head/usr.bin/truss/amd64-fbsd32.c	Mon Dec 21 17:23:04 2009	(r200779)
 +++ head/usr.bin/truss/amd64-fbsd32.c	Mon Dec 21 17:38:13 2009	(r200780)
 @@ -315,19 +315,6 @@ amd64_fbsd32_syscall_exit(struct trussin
      }
    }
  
 -  /*
 -   * The pipe syscall returns its fds in two registers and has assembly glue
 -   * to provide the libc API, so it cannot be handled like regular syscalls.
 -   * The nargs check is so we don't have to do yet another strcmp on every
 -   * syscall.
 -   */
 -  if (!errorp && fsc.nargs == 0 && fsc.name && strcmp(fsc.name, "pipe") == 0) {
 -      fsc.nargs = 1;
 -      fsc.s_args = malloc((1+fsc.nargs) * sizeof(char*));
 -      asprintf(&fsc.s_args[0], "[%d,%d]", (int)retval, (int)regs.r_rdx);
 -      retval = 0;
 -  }
 -
    if (fsc.name != NULL &&
        (!strcmp(fsc.name, "freebsd32_execve") || !strcmp(fsc.name, "exit"))) {
  	trussinfo->curthread->in_syscall = 1;
 
 Modified: head/usr.bin/truss/i386-fbsd.c
 ==============================================================================
 --- head/usr.bin/truss/i386-fbsd.c	Mon Dec 21 17:23:04 2009	(r200779)
 +++ head/usr.bin/truss/i386-fbsd.c	Mon Dec 21 17:38:13 2009	(r200780)
 @@ -305,19 +305,6 @@ i386_syscall_exit(struct trussinfo *trus
      }
    }
  
 -  /*
 -   * The pipe syscall returns its fds in two registers and has assembly glue
 -   * to provide the libc API, so it cannot be handled like regular syscalls.
 -   * The nargs check is so we don't have to do yet another strcmp on every
 -   * syscall.
 -   */
 -  if (!errorp && fsc.nargs == 0 && fsc.name && strcmp(fsc.name, "pipe") == 0) {
 -      fsc.nargs = 1;
 -      fsc.s_args = malloc((1+fsc.nargs) * sizeof(char*));
 -      asprintf(&fsc.s_args[0], "[%d,%d]", (int)retval, regs.r_edx);
 -      retval = 0;
 -  }
 -
    if (fsc.name != NULL &&
        (!strcmp(fsc.name, "execve") || !strcmp(fsc.name, "exit"))) {
  	trussinfo->curthread->in_syscall = 1;
 
 Modified: head/usr.bin/truss/syscalls.c
 ==============================================================================
 --- head/usr.bin/truss/syscalls.c	Mon Dec 21 17:23:04 2009	(r200779)
 +++ head/usr.bin/truss/syscalls.c	Mon Dec 21 17:38:13 2009	(r200780)
 @@ -242,6 +242,8 @@ struct syscall syscalls[] = {
  	  .args = { { Name | IN, 0 }, { Hex, 1 } } },
  	{ .name = "pathconf", .ret_type = 1, .nargs = 2,
  	  .args = { { Name | IN, 0 }, { Pathconf, 1 } } },
 +	{ .name = "pipe", .ret_type = 1, .nargs = 1,
 +	  .args = { { Ptr, 0 } } },
  	{ .name = "truncate", .ret_type = 1, .nargs = 3,
  	  .args = { { Name | IN, 0 }, { Int | IN, 1 }, { Quad | IN, 2 } } },
  	{ .name = "ftruncate", .ret_type = 1, .nargs = 3,
 @@ -1137,6 +1139,12 @@ print_syscall_ret(struct trussinfo *trus
  	if (errorp) {
  		fprintf(trussinfo->outfile, " ERR#%ld '%s'\n", retval, strerror(retval));
  	} else {
 +		/*
 +		 * Because pipe(2) has a special assembly glue to provide the
 +		 * libc API, we have to adjust retval.
 +		 */
 +		if (name != NULL && !strcmp(name, "pipe"))
 +			retval = 0;
  		fprintf(trussinfo->outfile, " = %ld (0x%lx)\n", retval, retval);
  	}
  }
 _______________________________________________
 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"
 
State-Changed-From-To: open->patched 
State-Changed-By: jh 
State-Changed-When: Mon Dec 21 18:13:23 UTC 2009 
State-Changed-Why:  
getpid(2) and pipe(2) decoding has been patched in head by revisions 
200751 and 200780. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/120870: commit references a PR
Date: Mon,  8 Feb 2010 15:53:42 +0000 (UTC)

 Author: jh
 Date: Mon Feb  8 15:53:28 2010
 New Revision: 203668
 URL: http://svn.freebsd.org/changeset/base/203668
 
 Log:
   MFC r200780:
   
   Remove non-working special case for pipe(2) from amd64-fbsd32.c and
   i386-fbsd.c. Add pipe(2) to syscall table to decode it's pointer
   argument properly and re-add special handling for pipe(2) return value
   to print_syscall_ret().
   
   PR:		bin/120870
 
 Modified:
   stable/8/usr.bin/truss/amd64-fbsd32.c
   stable/8/usr.bin/truss/i386-fbsd.c
   stable/8/usr.bin/truss/syscalls.c
 Directory Properties:
   stable/8/usr.bin/truss/   (props changed)
 
 Modified: stable/8/usr.bin/truss/amd64-fbsd32.c
 ==============================================================================
 --- stable/8/usr.bin/truss/amd64-fbsd32.c	Mon Feb  8 15:50:51 2010	(r203667)
 +++ stable/8/usr.bin/truss/amd64-fbsd32.c	Mon Feb  8 15:53:28 2010	(r203668)
 @@ -315,19 +315,6 @@ amd64_fbsd32_syscall_exit(struct trussin
      }
    }
  
 -  /*
 -   * The pipe syscall returns its fds in two registers and has assembly glue
 -   * to provide the libc API, so it cannot be handled like regular syscalls.
 -   * The nargs check is so we don't have to do yet another strcmp on every
 -   * syscall.
 -   */
 -  if (!errorp && fsc.nargs == 0 && fsc.name && strcmp(fsc.name, "pipe") == 0) {
 -      fsc.nargs = 1;
 -      fsc.s_args = malloc((1+fsc.nargs) * sizeof(char*));
 -      asprintf(&fsc.s_args[0], "[%d,%d]", (int)retval, (int)regs.r_rdx);
 -      retval = 0;
 -  }
 -
    if (fsc.name != NULL &&
        (!strcmp(fsc.name, "freebsd32_execve") || !strcmp(fsc.name, "exit"))) {
  	trussinfo->curthread->in_syscall = 1;
 
 Modified: stable/8/usr.bin/truss/i386-fbsd.c
 ==============================================================================
 --- stable/8/usr.bin/truss/i386-fbsd.c	Mon Feb  8 15:50:51 2010	(r203667)
 +++ stable/8/usr.bin/truss/i386-fbsd.c	Mon Feb  8 15:53:28 2010	(r203668)
 @@ -305,19 +305,6 @@ i386_syscall_exit(struct trussinfo *trus
      }
    }
  
 -  /*
 -   * The pipe syscall returns its fds in two registers and has assembly glue
 -   * to provide the libc API, so it cannot be handled like regular syscalls.
 -   * The nargs check is so we don't have to do yet another strcmp on every
 -   * syscall.
 -   */
 -  if (!errorp && fsc.nargs == 0 && fsc.name && strcmp(fsc.name, "pipe") == 0) {
 -      fsc.nargs = 1;
 -      fsc.s_args = malloc((1+fsc.nargs) * sizeof(char*));
 -      asprintf(&fsc.s_args[0], "[%d,%d]", (int)retval, regs.r_edx);
 -      retval = 0;
 -  }
 -
    if (fsc.name != NULL &&
        (!strcmp(fsc.name, "execve") || !strcmp(fsc.name, "exit"))) {
  	trussinfo->curthread->in_syscall = 1;
 
 Modified: stable/8/usr.bin/truss/syscalls.c
 ==============================================================================
 --- stable/8/usr.bin/truss/syscalls.c	Mon Feb  8 15:50:51 2010	(r203667)
 +++ stable/8/usr.bin/truss/syscalls.c	Mon Feb  8 15:53:28 2010	(r203668)
 @@ -242,6 +242,8 @@ struct syscall syscalls[] = {
  	  .args = { { Name | IN, 0 }, { Hex, 1 } } },
  	{ .name = "pathconf", .ret_type = 1, .nargs = 2,
  	  .args = { { Name | IN, 0 }, { Pathconf, 1 } } },
 +	{ .name = "pipe", .ret_type = 1, .nargs = 1,
 +	  .args = { { Ptr, 0 } } },
  	{ .name = "truncate", .ret_type = 1, .nargs = 3,
  	  .args = { { Name | IN, 0 }, { Int | IN, 1 }, { Quad | IN, 2 } } },
  	{ .name = "ftruncate", .ret_type = 1, .nargs = 3,
 @@ -1137,6 +1139,12 @@ print_syscall_ret(struct trussinfo *trus
  	if (errorp) {
  		fprintf(trussinfo->outfile, " ERR#%ld '%s'\n", retval, strerror(retval));
  	} else {
 +		/*
 +		 * Because pipe(2) has a special assembly glue to provide the
 +		 * libc API, we have to adjust retval.
 +		 */
 +		if (name != NULL && !strcmp(name, "pipe"))
 +			retval = 0;
  		fprintf(trussinfo->outfile, " = %ld (0x%lx)\n", retval, retval);
  	}
  }
 _______________________________________________
 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"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jh 
State-Changed-When: Sun Nov 27 11:32:13 UTC 2011 
State-Changed-Why:  
Fixed in head, stable/9 and stable/8. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120870 
>Unformatted:
