home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
sps3
/
part02
/
getupage.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-08
|
5KB
|
175 lines
# ifndef lint
static char SccsId[] = "@(#)getupage.c 1.6\t12/4/91" ;
# endif
# include "sps.h"
# ifdef KVM
# include <kvm.h>
# else
# include <h/vm.h>
# ifdef BSD42
# include <machine/pte.h>
# else
# include <h/pte.h>
# endif
# endif
# include <stdio.h>
/*
** GETUPAGE - Reads the upage for the specified process as well as sufficient
** page tables entries for reading the command arguments. The pte's are read
** into the argument `ptetbl'. The upage is read into the external variable
** `User'. This procedure returns 1 if the upage was successfully read.
*/
# ifndef KVM
# define usrpt (Info.i_usrpt)
getupage ( p, ptetbl )
register struct process *p ;
register struct pte *ptetbl ;
{
register int i ;
register int ncl ;
struct pte pte ;
extern struct info Info ;
extern union userstate User ;
extern int Flmem, Flkmem, Flswap ;
/* If the process is not loaded, look for the upage on the swap device*/
# ifdef ULTRIX40
if ( !(p->pr_p.p_sched & SLOAD) )
{
struct dmap l_dmap ;
int ublkno ;
int swap ;
memseek( Flkmem, (long)p->pr_p.p_smap ) ;
if ( read( Flkmem, (char*)&l_dmap, sizeof( struct dmap ) )
!= sizeof( struct dmap ) )
{
fprintf( stderr,
"sps - Can't read data segment map of process %d\n",
p->pr_p.p_pid ) ;
return ( 0 ) ;
}
memseek( Flkmem, (long)l_dmap.dm_ptdaddr ) ;
if ( read( Flkmem, (char*)&ublkno, sizeof( ublkno ) )
!= sizeof( ublkno ) )
{
fprintf( stderr,
"sps - Can't read user block numer of process %d\n",
p->pr_p.p_pid ) ;
return ( 0 ) ;
}
swseek( (long)dtob( ublkno ) ) ;
# else ULTRIX40
if ( !(p->pr_p.p_flag & SLOAD) )
{
# ifdef BSD42
swseek( (long)dtob( p->pr_p.p_swaddr ) ) ;
# else BSD42
swseek( (long)ctob( p->pr_p.p_swaddr ) ) ;
# endif BSD42
# endif ULTRIX40
# ifdef SUN
if ( read( Flswap, (char*)&User.u_us, sizeof( union userstate ))
!= sizeof( union userstate ) )
# else SUN
if ( read( Flswap, (char*)&User.u_us, sizeof( struct user ) )
!= sizeof( struct user ) )
# endif SUN
{
fprintf( stderr,
"sps - Can't read upage of process %d\n",
p->pr_p.p_pid ) ;
return ( 0 ) ;
}
return ( 1 ) ;
}
/* The process is loaded. Locate the process pte's by reading
the pte of their base address from system virtual address space. */
# ifdef ULTRIX40
/* This method of accessing the upage suffices on the DEC Station
but only provides sufficient pte's to read the upage, leaving the
command arguments inaccessible. */
memseek( Flkmem, (long)p->pr_p.p_addr ) ;
if ( read( Flkmem, (char*)ptetbl, (UPAGES+CLSIZE)*sizeof( struct pte ) )
!= (UPAGES+CLSIZE)*sizeof( struct pte ) )
{
fprintf( stderr, "sps - Can't read page table of process %d\n",
p->pr_p.p_pid ) ;
return ( 0 ) ;
}
# else ULTRIX40
memseek( Flkmem, (long)&Info.i_usrptmap[ btokmx(p->pr_p.p_p0br)
+ p->pr_p.p_szpt-1 ] ) ;
if ( read( Flkmem, (char*)&pte, sizeof( struct pte ) )
!= sizeof( struct pte ) )
{
fprintf( stderr,
"sps - Can't read indir pte for upage of process %d\n",
p->pr_p.p_pid ) ;
return ( 0 ) ;
}
/* Now read the process' pte's from physical memory. We need to access
sufficient pte's for the upage and for the command arguments. */
memseek( Flmem, (long)ctob( pte.pg_pfnum+1 )
- (UPAGES+CLSIZE)*sizeof( struct pte ) ) ;
if ( read( Flmem, (char*)ptetbl, (UPAGES+CLSIZE)*sizeof( struct pte ) )
!= (UPAGES+CLSIZE)*sizeof( struct pte ) )
{
fprintf( stderr, "sps - Can't read page table of process %d\n",
p->pr_p.p_pid ) ;
return ( 0 ) ;
}
# endif ULTRIX40
/* Now we can read the pages belonging to the upage.
Here we read in an entire click at one go. */
ncl = (sizeof( struct user ) + NBPG*CLSIZE - 1) / (NBPG*CLSIZE) ;
while ( --ncl >= 0 )
{
i = ncl * CLSIZE ;
# ifdef ULTRIX40
memseek( Flmem, (long)ctob( ptetbl[ i ].pg_pfnum ) ) ;
# else ULTRIX40
memseek( Flmem, (long)ctob( ptetbl[ CLSIZE+i ].pg_pfnum ) ) ;
# endif ULTRIX40
if ( read( Flmem, User.u_pg[i], CLSIZE*NBPG ) != CLSIZE*NBPG )
{
fprintf( stderr,
"sps - Can't read page 0x%x of process %d\n",
ptetbl[ CLSIZE+i ].pg_pfnum, p->pr_p.p_pid ) ;
return ( 0 ) ;
}
}
return ( 1 ) ;
}
# else KVM
getupage ( p )
register struct process *p ;
{
struct user *upage ;
extern union userstate User ;
extern kvm_t *Flkvm ;
if (upage = kvm_getu( Flkvm, &p->pr_p ) )
{
bcopy( (char *)upage, User.u_pg[0], sizeof( struct user ) ) ;
return ( 1 ) ;
}
fprintf( stderr, "sps - Can't read upage of process %d\n",
p->pr_p.p_pid ) ;
return ( 0 ) ;
}
# endif KVM