From owner-freebsd-current@FreeBSD.ORG Sun Nov 28 02:04:21 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8CF6616A4CE for ; Sun, 28 Nov 2004 02:04:21 +0000 (GMT) Received: from rwcrmhc11.comcast.net (rwcrmhc11.comcast.net [204.127.198.35]) by mx1.FreeBSD.org (Postfix) with ESMTP id 419C543D46 for ; Sun, 28 Nov 2004 02:04:21 +0000 (GMT) (envelope-from rodrigc@crodrigues.org) Received: from h00609772adf0.ne.client2.attbi.com ([66.30.114.143]) by comcast.net (rwcrmhc11) with ESMTP id <2004112802042001300l316re>; Sun, 28 Nov 2004 02:04:20 +0000 Received: from h00609772adf0.ne.client2.attbi.com (localhost [127.0.0.1]) iAS24Hqg001465; Sat, 27 Nov 2004 21:04:17 -0500 (EST) (envelope-from rodrigc@h00609772adf0.ne.client2.attbi.com) Received: (from rodrigc@localhost)iAS24BOd001464; Sat, 27 Nov 2004 21:04:11 -0500 (EST) (envelope-from rodrigc) Date: Sat, 27 Nov 2004 21:04:11 -0500 From: Craig Rodrigues To: Vladimir Grebenschikov Message-ID: <20041128020411.GA1436@crodrigues.org> References: <1101492325.996.54.camel@localhost> <20041128003036.GA883@crodrigues.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041128003036.GA883@crodrigues.org> User-Agent: Mutt/1.4.1i cc: "current@freebsd.org" Subject: Re: ptrace broken on latest CURRENT ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Nov 2004 02:04:21 -0000 On Sat, Nov 27, 2004 at 07:30:36PM -0500, Craig Rodrigues wrote: > --- sys_generic.c.orig Sat Nov 27 19:14:39 2004 > +++ sys_generic.c Sat Nov 27 19:17:09 2004 > @@ -503,7 +503,7 @@ > if ((size > IOCPARM_MAX) || > ((com & (IOC_VOID | IOC_IN | IOC_OUT)) == 0) || > ((com & IOC_VOID) && size > 0) || > - ((com & (IOC_IN | IOC_OUT)) && size == 0)) { > + ((com & IOC_OUT) && size == 0)) { > fdrop(fp, td); > return (ENOTTY); > } Hi, If we leave the define of PIOCBIS as: # define PIOCBIS _IOC(IOC_IN, 'p', 1, 0) then the length of this ioctl is going to be 0 (from IOCPARM_LEN). I'm not sure if that is a good thing. This is what tripped up the original ioctl() code in sys_generic.c. If we don't change sys_generic.c, then the other approach to this problem is to fix the ioctl() calls in the procfs. Any comments on this? Index: sys/fs/procfs/procfs_ioctl.c =================================================================== RCS file: /home/ncvs/src/sys/fs/procfs/procfs_ioctl.c,v retrieving revision 1.10 diff -u -r1.10 procfs_ioctl.c --- sys/fs/procfs/procfs_ioctl.c 7 Dec 2003 17:40:00 -0000 1.10 +++ sys/fs/procfs/procfs_ioctl.c 28 Nov 2004 01:58:38 -0000 @@ -46,8 +46,8 @@ procfs_ioctl(PFS_IOCTL_ARGS) { struct procfs_status *ps; - int error, flags, sig; - + int error; + unsigned int flags, sig; PROC_LOCK(p); error = 0; switch (cmd) { Index: sys/sys/pioctl.h =================================================================== RCS file: /home/ncvs/src/sys/sys/pioctl.h,v retrieving revision 1.12 diff -u -r1.12 pioctl.h --- sys/sys/pioctl.h 4 Aug 2002 01:06:58 -0000 1.12 +++ sys/sys/pioctl.h 28 Nov 2004 01:58:40 -0000 @@ -49,12 +49,12 @@ unsigned long val; /* Any extra data */ }; -# define PIOCBIS _IOC(IOC_IN, 'p', 1, 0) /* Set event flag */ -# define PIOCBIC _IOC(IOC_IN, 'p', 2, 0) /* Clear event flag */ -# define PIOCSFL _IOC(IOC_IN, 'p', 3, 0) /* Set flags */ +# define PIOCBIS _IOW('p', 1, unsigned int) /* Set event flag */ +# define PIOCBIC _IOW('p', 2, unsigned int) /* Clear event flag */ +# define PIOCSFL _IOW('p', 3, unsigned int) /* Set flags */ /* wait for proc to stop */ # define PIOCWAIT _IOR('p', 4, struct procfs_status) -# define PIOCCONT _IOC(IOC_IN, 'p', 5, 0) /* Continue a process */ +# define PIOCCONT _IOW('p', 5, unsigned int) /* Continue a process */ /* Get proc status */ # define PIOCSTATUS _IOR('p', 6, struct procfs_status) # define PIOCGFL _IOR('p', 7, unsigned int) /* Get flags */ Index: usr.bin/truss/extern.h =================================================================== RCS file: /home/ncvs/src/usr.bin/truss/extern.h,v retrieving revision 1.9 diff -u -r1.9 extern.h --- usr.bin/truss/extern.h 17 Jul 2004 19:19:36 -0000 1.9 +++ usr.bin/truss/extern.h 28 Nov 2004 01:58:40 -0000 @@ -32,7 +32,7 @@ */ extern int setup_and_wait(char **); -extern int start_tracing(int, int, int); +extern int start_tracing(int, unsigned int, int); extern void restore_proc(int); extern const char *ioctlname(register_t val); extern char *strsig(int sig); Index: usr.bin/truss/main.c =================================================================== RCS file: /home/ncvs/src/usr.bin/truss/main.c,v retrieving revision 1.38 diff -u -r1.38 main.c --- usr.bin/truss/main.c 17 Jul 2004 19:19:36 -0000 1.38 +++ usr.bin/truss/main.c 28 Nov 2004 01:58:42 -0000 @@ -322,7 +322,7 @@ break; } } - if (ioctl(Procfd, PIOCCONT, val) == -1) { + if (ioctl(Procfd, PIOCCONT, &val) == -1) { if (kill(trussinfo->pid, 0) == -1 && errno == ESRCH) break; else Index: usr.bin/truss/setup.c =================================================================== RCS file: /home/ncvs/src/usr.bin/truss/setup.c,v retrieving revision 1.19 diff -u -r1.19 setup.c --- usr.bin/truss/setup.c 7 Jan 2004 14:29:45 -0000 1.19 +++ usr.bin/truss/setup.c 28 Nov 2004 01:58:42 -0000 @@ -54,7 +54,7 @@ #include "truss.h" #include "extern.h" -static int evflags = 0; +static unsigned int evflags = 0; /* * setup_and_wait() is called to start a process. All it really does @@ -69,19 +69,19 @@ char buf[32]; int fd; int pid; - int flags; + unsigned int flags; pid = fork(); if (pid == -1) { err(1, "fork failed"); } if (pid == 0) { /* Child */ - int mask = S_EXEC | S_EXIT; + unsigned int mask = S_EXEC | S_EXIT; fd = open("/proc/curproc/mem", O_WRONLY); if (fd == -1) err(2, "cannot open /proc/curproc/mem"); fcntl(fd, F_SETFD, 1); - if (ioctl(fd, PIOCBIS, mask) == -1) + if (ioctl(fd, PIOCBIS, &mask) == -1) err(3, "PIOCBIS"); flags = PF_LINGER; /* @@ -89,11 +89,11 @@ * process on last close; normally, this is the behaviour * we want. */ - if (ioctl(fd, PIOCSFL, flags) == -1) + if (ioctl(fd, PIOCSFL, &flags) == -1) warn("cannot set PF_LINGER"); execvp(command[0], command); mask = ~0; - ioctl(fd, PIOCBIC, ~0); + ioctl(fd, PIOCBIC, &mask); err(4, "execvp %s", command[0]); } /* Only in the parent here */ @@ -128,7 +128,7 @@ */ int -start_tracing(int pid, int eventflags, int flags) { +start_tracing(int pid, unsigned int eventflags, int flags) { int fd; char buf[32]; struct procfs_status tmp; @@ -151,7 +151,7 @@ } evflags = tmp.events; - if (ioctl(fd, PIOCBIS, eventflags) == -1) + if (ioctl(fd, PIOCBIS, &eventflags) == -1) err(9, "cannot set procfs event bit mask"); /* @@ -160,7 +160,7 @@ * needs to be woken up via procctl. */ - if (ioctl(fd, PIOCSFL, flags) == -1) + if (ioctl(fd, PIOCSFL, &flags) == -1) warn("cannot clear PF_LINGER"); return fd; @@ -174,9 +174,9 @@ */ void restore_proc(int signo __unused) { - - ioctl(Procfd, PIOCBIC, ~0); + unsigned int flags = ~0; + ioctl(Procfd, PIOCBIC, &flags); if (evflags) - ioctl(Procfd, PIOCBIS, evflags); + ioctl(Procfd, PIOCBIS, &evflags); exit(0); } -- Craig Rodrigues http://crodrigues.org rodrigc@crodrigues.org