From owner-freebsd-hackers@FreeBSD.ORG Fri Apr 16 12:11: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 9B9AD106566C; Fri, 16 Apr 2010 12:11:27 +0000 (UTC) (envelope-from fernando.apesteguia@gmail.com) Received: from mail-ew0-f224.google.com (mail-ew0-f224.google.com [209.85.219.224]) by mx1.freebsd.org (Postfix) with ESMTP id D878C8FC0C; Fri, 16 Apr 2010 12:11:26 +0000 (UTC) Received: by ewy24 with SMTP id 24so781706ewy.33 for ; Fri, 16 Apr 2010 05:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=KirGyqtLk+GCUA7jRrUfjipRZp4P6i2CBbO0iLvIdOA=; b=HObJVWfkgAJO1w32qHSmJMTQ6ocCiqfrWs8/03K1kAnWgmZXjcPKqJPyIS9BhSIOrv wauiD5UFEPDCSUp6ues9BU3/lHQ8sFuHqMEeV5CamEFsuN3bRlxL5Iw5zPq6NbZbZ4oQ Oahvkgjvth0VeFkvtb5clxKjAjQq2uck3TY/s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=tVi3SnNHEdlUUB7rMzCAvluYw1f5FOIRwdPZEc274zzy18H4sqK5f5nE7ygO2jpxpZ G55LItt81ULnbavIk1ncywLY4zquignG/bN/XLnJMi7A1OMivFMtNX/Fc+WM2PpcbwXN /R/c6mR1qNLWbfY05OsDJamDd/8cyjku0vbcQ= MIME-Version: 1.0 Received: by 10.213.9.134 with HTTP; Fri, 16 Apr 2010 05:11:25 -0700 (PDT) In-Reply-To: <201004141721.00254.jhb@freebsd.org> References: <201004141721.00254.jhb@freebsd.org> Date: Fri, 16 Apr 2010 14:11:25 +0200 Received: by 10.213.52.195 with SMTP id j3mr753530ebg.33.1271419885613; Fri, 16 Apr 2010 05:11:25 -0700 (PDT) Message-ID: From: =?ISO-8859-1?Q?Fernando_Apestegu=EDa?= To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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:11:27 -0000 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: >> >> >> =A0 =A0 =A0 =A0 struct iovec iov; >> =A0 =A0 =A0 struct uio tmp_uio; >> =A0 =A0 =A0 struct ps_strings *pss; >> =A0 =A0 =A0 int ret_code; >> >> =A0 =A0 =A0 buff =3D malloc(sizeof(struct ps_strings), M_TEMP, M_WAITOK)= ; >> =A0 =A0 =A0 memset(buff, 0, sizeof(struct ps_strings)); >> >> =A0 =A0 =A0 PROC_LOCK_ASSERT(td->td_proc, MA_NOTOWNED); >> =A0 =A0 =A0 iov.iov_base =3D (caddr_t) buff; >> =A0 =A0 =A0 iov.iov_len =3D sizeof(struct ps_strings); >> =A0 =A0 =A0 tmp_uio.uio_iov =3D &iov; >> =A0 =A0 =A0 tmp_uio.uio_iovcnt =3D 1; >> =A0 =A0 =A0 tmp_uio.uio_offset =3D (off_t)(p->p_sysent->sv_psstrings); >> =A0 =A0 =A0 tmp_uio.uio_resid =3D sizeof(struct ps_strings); >> =A0 =A0 =A0 tmp_uio.uio_segflg =3D UIO_USERSPACE; >> =A0 =A0 =A0 tmp_uio.uio_rw =3D UIO_READ; >> =A0 =A0 =A0 tmp_uio.uio_td =3D td; >> =A0 =A0 =A0 ret_code =3D proc_rwmem(td->td_proc, &tmp_uio); > > I think you want to use 'p' instead of 'td->td_proc' here. =A0As it is yo= u are > reading from the current process instead of the target process I believe. Thank you. You are right. 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? 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); } 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); Thanks in advance. > > -- > John Baldwin >