From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 16 12:22:27 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10812106566C for ; Fri, 16 Apr 2010 12:22:27 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id D41618FC19 for ; Fri, 16 Apr 2010 12:22:26 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 84ED146B94; Fri, 16 Apr 2010 08:22:26 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPA id B29A58A021; Fri, 16 Apr 2010 08:22:25 -0400 (EDT) From: John Baldwin To: Fernando =?iso-8859-1?q?Apestegu=EDa?= Date: Fri, 16 Apr 2010 08:18:28 -0400 User-Agent: KMail/1.12.1 (FreeBSD/7.3-CBSD-20100217; KDE/4.3.1; amd64; ; ) References: <201004141721.00254.jhb@freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <201004160818.28944.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Fri, 16 Apr 2010 08:22:25 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: freebsd-hackers@freebsd.org Subject: Re: Understanding proc_rwmem X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Apr 2010 12:22:27 -0000 On Friday 16 April 2010 8:11:25 am Fernando Apestegu=EDa wrote: > 2010/4/14 John Baldwin : > > On Wednesday 14 April 2010 4:22:56 pm Fernando Apestegu=EDa wrote: > >> Hi all, > >> > >> I'm trying to read process memory other than the current process in > >> kernel. I was told to use the proc_rwmem function, however I can't get > >> it working properly. At first, I'm trying to read how many elements > >> the environment variables vector has. To do this I tried this from a > >> linprocfs filler function: > >> > >> > >> struct iovec iov; > >> struct uio tmp_uio; > >> struct ps_strings *pss; > >> int ret_code; > >> > >> buff =3D malloc(sizeof(struct ps_strings), M_TEMP, M_WAITOK); > >> memset(buff, 0, sizeof(struct ps_strings)); > >> > >> PROC_LOCK_ASSERT(td->td_proc, MA_NOTOWNED); > >> iov.iov_base =3D (caddr_t) buff; > >> iov.iov_len =3D sizeof(struct ps_strings); > >> tmp_uio.uio_iov =3D &iov; > >> tmp_uio.uio_iovcnt =3D 1; > >> tmp_uio.uio_offset =3D (off_t)(p->p_sysent->sv_psstrings); > >> tmp_uio.uio_resid =3D sizeof(struct ps_strings); > >> tmp_uio.uio_segflg =3D UIO_USERSPACE; > >> tmp_uio.uio_rw =3D UIO_READ; > >> tmp_uio.uio_td =3D td; > >> ret_code =3D proc_rwmem(td->td_proc, &tmp_uio); > > > > I think you want to use 'p' instead of 'td->td_proc' here. As it is yo= u=20 are > > reading from the current process instead of the target process I believ= e. >=20 > Thank you. You are right. >=20 > I made the changes suggested by both you and Kostik. I still have > random data when reading. > I'm trying to to the same thing using kern/sys_generic.c::read and > kern/sys_process.c::kern_ptrace > as examples, but I'm missing something... > After reading with proc_rwmem, is it possible to do something like the > following? >=20 > if (ret_code =3D=3D 0) { > sbuf_printf(sb, "proc_rwmem successfully executed: %d\n", ret_code); > } else { > sbuf_printf(sb, "Error in proc_rwmem: %d\n", ret_code); > } >=20 > pss =3D (struct ps_strings *)(iov.iov_base); > sbuf_printf(sb, "ps_nargvstr =3D %d\nps_nenvstr =3D %d\n", > pss->ps_nargvstr, pss->ps_nenvstr); >=20 > Thanks in advance. No, functions like uiomove() modify the iovec structures. Just use 'buff'= =20 instead of iov.iov_base. =2D-=20 John Baldwin