6bbb proc_rwmem help - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > FreeBSD Development

FreeBSD Development Kernel development, writing drivers, coding, and questions regarding FreeBSD internals.

Reply
 
Thread Tools Display Modes
  #1  
Old April 7th, 2010, 19:25
fernape fernape is offline
Junior Member
 
Join Date: Feb 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default proc_rwmem help

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:


Code:
	char *buff;
	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);

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 17:31.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0