Date: Fri, 16 Apr 2010 14:37:14 +0200 From: =?ISO-8859-1?Q?Fernando_Apestegu=EDa?= <fernando.apesteguia@gmail.com> To: John Baldwin <jhb@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: Understanding proc_rwmem Message-ID: <z2i1bd550a01004160537heaabda33t8bc50d6a4d8cc59e@mail.gmail.com> In-Reply-To: <201004160818.28944.jhb@freebsd.org> References: <x2l1bd550a01004141322m420065fbj742800c3e4a81927@mail.gmail.com> <201004141721.00254.jhb@freebsd.org> <r2u1bd550a01004160511t5886d215gb78e5556a755626d@mail.gmail.com> <201004160818.28944.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
2010/4/16 John Baldwin <jhb@freebsd.org>: > On Friday 16 April 2010 8:11:25 am Fernando Apestegu=EDa wrote: >> 2010/4/14 John Baldwin <jhb@freebsd.org>: >> > 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 ge= t >> >> 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_WAIT= OK); >> >> =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= you > are >> > reading from the current process instead of the target process I belie= ve. >> >> 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) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 sbuf_printf(sb, "proc_rwmem successfully exe= cuted: %d\n", ret_code); >> } else { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 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. > > No, functions like uiomove() modify the iovec structures. =A0Just use 'bu= ff' > instead of iov.iov_base. Ah! That was it! Thanks! > > -- > John Baldwin >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?z2i1bd550a01004160537heaabda33t8bc50d6a4d8cc59e>