From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 14 20:22:57 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 83C21106564A for ; Wed, 14 Apr 2010 20:22:57 +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 1B5A98FC1D for ; Wed, 14 Apr 2010 20:22:56 +0000 (UTC) Received: by ewy24 with SMTP id 24so272296ewy.33 for ; Wed, 14 Apr 2010 13:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:received:message-id :subject:from:to:content-type; bh=rJcubCDcBakpgxYoBNlrHRaTtO4OeLv3X/1GFbxCo3Y=; b=RD5EdcTbwerVL78Yyi/QiIMOD/ifJu68qnG9oKh1ii1HhAy6cDxcZOU71uenq+5Nga +o5OhbCK4wux2G50n/T1xxqRVw3VMJdFMtoxVkf3DAN2/1DJvqA4s8xohJA30vC6g0qQ XsKMl4K4WAGZBcijBL2KCvHNYBbbY2Yw53LdA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=rbF9pJtxJAfbiu9+WH8/qOpij7NLtpwxeeL+073XXUuYh/sb4PW0qf852r5f8Y6rhm e1UMBNbwBzChHdRSR62yvo7+mectjTg9gVlQ7E3oJRbppH44ANjq5a9Kpwbs2XzVdIde I/6AbtH0phOZC+7TJDZ8SsYuO8ApuwKTiRHKk= MIME-Version: 1.0 Received: by 10.213.9.134 with HTTP; Wed, 14 Apr 2010 13:22:56 -0700 (PDT) Date: Wed, 14 Apr 2010 22:22:56 +0200 Received: by 10.213.65.202 with SMTP id k10mr4363547ebi.63.1271276576056; Wed, 14 Apr 2010 13:22:56 -0700 (PDT) Message-ID: From: =?ISO-8859-1?Q?Fernando_Apestegu=EDa?= To: FreeBSD Hackers Content-Type: text/plain; charset=ISO-8859-1 Subject: 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: Wed, 14 Apr 2010 20:22:57 -0000 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 = 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 = (caddr_t) buff; iov.iov_len = sizeof(struct ps_strings); tmp_uio.uio_iov = &iov; tmp_uio.uio_iovcnt = 1; tmp_uio.uio_offset = (off_t)(p->p_sysent->sv_psstrings); tmp_uio.uio_resid = sizeof(struct ps_strings); tmp_uio.uio_segflg = UIO_USERSPACE; tmp_uio.uio_rw = UIO_READ; tmp_uio.uio_td = td; ret_code = proc_rwmem(td->td_proc, &tmp_uio); if (ret_code == 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 = (struct ps_strings *)(iov.iov_base); sbuf_printf(sb, "ps_nargvstr = %d\nps_nenvstr = %d\n", pss->ps_nargvstr, pss->ps_nenvstr); free(buff, M_TEMP); Considering I left security and error handling aside, what is wrong with the code above? proc_rwmem returns 0 indicating no failure, but when I try to print the result, I get random stuff. I thought maybe the problem is in the uio_offset field, but p->p_sysent->sv_psstrings is a vm_offset_t. Is the offset properly specified? If not, what else could be the problem? Thanks in advance. PS: I posted a similar question at forums.freebsd.org but got no answer, that is why I ask here.