finding the u structure in /dev/mem on SYSV (how ?)

Brian Bebeau brianb at marque.mu.edu
Tue Aug 9 06:14:43 AEST 1988


In article <1240 at holos0.UUCP> fsg at holos0.UUCP (Frank Glass) writes:
>I am writing a routine to list UNIX processes and their respective ages.
>I need for the source to be reasonably portable across System V (or at
>least USG) breeds of machines.  
>The next problem is getting to the u structure in /dev/mem.
>I can't seem to find a _consistent_ macro to relate the pointer or click
>number in the proc structure to the offset into /dev/mem.  I am using
>AT&T 3b2, NCR Tower 32 and a Xenix 286 machine.  I have solved the problem
>on two of the three, but there seems not to be a common solution and I have
>many machines to go.
>
>Frank Glass
and fox at marlow.uucp (Paul Fox) writes...
>I am trying to write/port the BSD 'top' utility
>posted to usenet sometime ago, to Unix V.3. 
>
>I've successfully managed to port it to SunOS 4 after a lot of changes,
>but am having problems with the u-area.
>
>Given that we start from the struct proc of a process, how
>do we get to the u-area, if (a) the process/u-area is in memory,
>and (b) the process/u-area is swapped out.

I've written a program that reads the process struct and u area to get
other useful info that ps doesn't tell you, and I've run into this so
I thought I'd post my experiences. Following are some code fragments
that show just how un-portable any scheme can be. These are from a 
3b15, a 3b5, and a 3b2. Each requires something different, yet they're
all the same processor! I'd hate to change processors much less vendors.
In fact, I've been working on the 6386 version, and that's much worse,
involving reading the U area page table, then reading in pages of the 
U area, or something like that. It's been a pain so far. Note the 
BSHIFT variable. Brandon Allberry's utree program notes he had to 
hard-code an 11 instead to get it to work on his Pyramid.

======================================================================
/* read user area on 3b15 */
	if (mproc.p_flag & SLOAD) {
		lseek(mem, (long)(ctob(mproc.p_addr)) & ~MAINSTORE, 0)
	}
	else {
		lseek(swap, (long)(swplo + mproc.p_region->p_regva), 0)
	}
======================================================================
/* read user area on 3b2 */
	if (mproc.p_flag & SLOAD) {
		lseek(mem, (long)(ctob(mproc.p_addr)) & ~MAINSTORE, 0)
	}
	else {
		lseek(swap, (swplo + mproc.p_swaddr + ctod(mproc.p_swsize -
				USIZE - mproc.p_ssize)) << BSHIFT, 0) 
	}
======================================================================
/* read user area on 3b5 */
	if (mproc.p_flag & SLOAD) {
		lseek(mem, (long)(ctob(mproc.p_addr)) & ~VUSER, 0)
	}
	else {
		lseek(swap, (swplo + mproc.p_swaddr + ctod(mproc.p_swsize -
				USIZE)) << BSHIFT, 0) == -1L)
	}
======================================================================
---------------------------------------------------------------------------
Brian Bebeau				 Marquette University		

DOMAIN:  brianb at marque.mu.edu 
  UUCP:  {uwvax,rutgers,uunet}!marque!brianb
  ARPA:  brianb%marque.uucp at csd1.milw.wisc.edu     BITNET:  6877BEBE at MUCSD
---------------------------------------------------------------------------



More information about the Comp.unix.wizards mailing list