The proc struct in ULTRIX kernel

Matt Thomas thomas at mipsbx.nac.dec.com
Wed Jun 27 13:28:16 AEST 1990


This what I use in my port of the fstat program to ULTRIX (V4 or V3).
If NPROC is defined, this it's V4 otherwise V3.  Standard disclaimers
about not being supported and may change at any moment, etc.

static
getu()
{
	register struct pte *pteaddr;
	struct pte apte, arguutl[CLSIZE+HIGHPAGES];
	register int i;
        struct dmap l_dmap;
	int ncl, size, ublkno;

	size = sflg ? ctob(UPAGES) : sizeof (struct user);
	if ((mproc->p_sched & SLOAD) == 0) {
		if (swap < 0)
			return(0);
#ifdef NPROC
		kread(mproc->p_smap, &l_dmap, sizeof(struct dmap));
		kread(l_dmap.dm_ptdaddr, &ublkno, sizeof(int));
		(void) lseek(swap, (long)dtob(ublkno), 0);
#else
		(void) lseek(swap, (long)dtob(mproc->p_swaddr), 0);
#endif
		if (read(swap, (char *)&user.user, size) != size) {
			fprintf(stderr, "%s: cant read u for pid %d from %s\n",
			    pname, mproc->p_pid, swapfile);
			return (0);
		}
		return(1);
	}
#ifdef vax
	pteaddr = &Usrptma[btokmx(mproc->p_p0br) + mproc->p_szpt - 1];
#endif vax
#ifdef mips
	pteaddr = &Usrptma[btokmx(mproc->p_stakbr) + mproc->p_stakpt - 1];
#endif mips
	if (kread((ls_t)pteaddr, (char *)&apte, sizeof(apte)) != sizeof(apte)) {
		(void) printf(
		  "%s: can't read indir pte to get u for pid %d from %s\n",
		  pname, mproc->p_pid, swapfile);
		return(0);
	}
#ifdef vax
	(void)lseek(mem, (ls_t)(ctob(apte.pg_pfnum+1) - (HIGHPAGES+CLSIZE)
	    * sizeof(struct pte)), L_SET);
	if (read(mem, (char *)arguutl, sizeof(arguutl)) != sizeof(arguutl)) {
#endif vax
#ifdef mips
	if (mproc->p_type & SSYS)
		goto read_ptes;
	(void)lseek(mem, (ls_t)(ctob(apte.pg_pfnum) + NBPG
	   - (HIGHPAGES+1) * sizeof(struct pte)), L_SET);
	if (read(mem, (char *)arguutl, CLSIZE*sizeof(struct pte))
	   != CLSIZE*sizeof(struct pte)) {
#endif mips
		(void) printf(
		  "%s: can't read page table for u of pid %d from %s\n",
		  pname, mproc->p_pid, kmemfile);
		return(0);
	}
#ifdef mips
read_ptes:
	if (kread((ls_t)mproc->p_addr, (char *)&arguutl[CLSIZE],
	   UPAGES*sizeof(struct pte)) != UPAGES*sizeof(struct pte)) {
		(void) printf(
		  "%s: can't read (user) page table for u of pid %d from %s\n",
		  pname, mproc->p_pid, kmemfile);
		return (0);
	}
#endif mips

	ncl = (sizeof(struct user) + NBPG*CLSIZE - 1) / (NBPG*CLSIZE);
#if defined(vax) && defined(NPROC)
	for (pteaddr = &arguutl[UPAGES + ncl*CLSIZE];
	    pteaddr > &arguutl[UPAGES];
	    pteaddr -= CLSIZE) {
		(void)lseek(mem, (ls_t)ctob(pteaddr->pg_pfnum), L_SET);
		if (read(mem, user.upages[pteaddr - &arguutl[CLSIZE + UPAGES]],
CLSIZE*NBPG) != CLSIZE*NBPG) {
			(void) printf(
			  "%s: can't read page %u of u of pid %d from %s\n",
			  pname,
			pteaddr->pg_pfnum, mproc->p_pid, corefile);
			return(0);
		}
	}
#endif
#if defined(mips) || !defined(NPROC)
	while (--ncl >= 0) {
		i = ncl * CLSIZE;
		(void)lseek(mem, (ls_t)ctob(arguutl[CLSIZE+i].pg_pfnum), L_SET);
		if (read(mem, user.upages[i], CLSIZE*NBPG) != CLSIZE*NBPG) {
			(void) printf(
			  "%s: can't read page %u of u of pid %d from %s\n",
			  pname,
			  arguutl[CLSIZE+i].pg_pfnum, mproc->p_pid, corefile);
			return(0);
		}
	}
#endif
	return(1);
}

-- 
Matt Thomas                     Internet:   thomas at wrl.dec.com
DECnet-ULTRIX Development       UUCP:       ...!decwrl!thomas
Digital Equipment Corporation   Disclaimer: This message reflects my own
Littleton, MA                               warped views, etc.



More information about the Comp.unix.ultrix mailing list