home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / sps / part1 / getupage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.9 KB  |  95 lines

  1. # include       "sps.h"
  2. # include       <h/vm.h>
  3. # ifdef BSD42
  4. # include    <machine/pte.h>
  5. # else
  6. # include       <h/pte.h>
  7. # endif
  8. # include       <stdio.h>
  9.  
  10. /*
  11. ** GETUPAGE - Reads the upage for the specified process as well as sufficient
  12. ** page tables entries for reading the command arguments. The pte's are read
  13. ** into the argument `ptetbl'. The upage is read into the external variable
  14. ** `User'. This procedure returns 1 if the upage was successfully read.
  15. */
  16.  
  17. # define        usrpt           (Info.i_usrpt)
  18.  
  19. getupage ( p, ptetbl )
  20.  
  21. register struct process         *p ;
  22. register struct pte             *ptetbl ;
  23.  
  24. {
  25.     register int            i ;
  26.     register int            ncl ;
  27.     struct pte              pte ;
  28.     extern struct info      Info ;
  29.     extern union userstate  User ;
  30.     extern int              Flmem, Flkmem, Flswap ;
  31.  
  32.     /* If the process is not loaded, look for the upage on the swap device*/
  33.     if ( !(p->pr_p.p_flag & SLOAD) )
  34.     {                               
  35. # ifdef BSD42
  36.         swseek( (long)dtob( p->pr_p.p_swaddr ) ) ;
  37. # else
  38.         swseek( (long)ctob( p->pr_p.p_swaddr ) ) ;
  39. # endif
  40. # ifdef SUN
  41.         if ( read( Flswap, (char*)&User.u_us, sizeof( union userstate ))
  42.         != sizeof( union userstate ) )
  43. # else
  44.         if ( read( Flswap, (char*)&User.u_us, sizeof( struct user ) )
  45.         != sizeof( struct user ) )
  46. # endif
  47.         {
  48.             fprintf( stderr,
  49.                 "sps - Can't read upage of process %d\n",
  50.                 p->pr_p.p_pid ) ;
  51.             return ( 0 ) ;
  52.         }
  53.         return ( 1 ) ;          
  54.     }                               
  55.     /* The process is loaded. Locate the process pte's by reading
  56.        the pte of their base address from system virtual address space. */
  57.     memseek( Flkmem, (long)&Info.i_usrptmap[ btokmx(p->pr_p.p_p0br)
  58.         + p->pr_p.p_szpt-1 ] ) ;
  59.     if ( read( Flkmem, (char*)&pte, sizeof( struct pte ) )
  60.     != sizeof( struct pte ) )
  61.     {
  62.         fprintf( stderr,
  63.               "sps - Can't read indir pte for upage of process %d\n",
  64.             p->pr_p.p_pid ) ;
  65.         return ( 0 ) ;
  66.     }                               
  67.     /* Now read the process' pte's from physical memory. We need to access
  68.        sufficient pte's for the upage and for the command arguments. */
  69.     memseek( Flmem, (long)ctob( pte.pg_pfnum+1 )
  70.         - (UPAGES+CLSIZE)*sizeof( struct pte ) ) ;
  71.     if ( read( Flmem, (char*)ptetbl, (UPAGES+CLSIZE)*sizeof( struct pte ) )
  72.     != (UPAGES+CLSIZE)*sizeof( struct pte ) )
  73.     {
  74.         fprintf( stderr, "sps - Can't read page table of process %d\n",
  75.             p->pr_p.p_pid ) ;
  76.         return ( 0 ) ;
  77.     }
  78.     /* Now we can read the pages belonging to the upage.
  79.        Here we read in an entire click at one go. */
  80.     ncl = (sizeof( struct user ) + NBPG*CLSIZE - 1) / (NBPG*CLSIZE) ;
  81.     while ( --ncl >= 0 )            
  82.     {                               
  83.         i = ncl * CLSIZE ;
  84.         memseek( Flmem, (long)ctob( ptetbl[ CLSIZE+i ].pg_pfnum ) ) ;
  85.         if ( read( Flmem, User.u_pg[i], CLSIZE*NBPG ) != CLSIZE*NBPG )
  86.         {
  87.             fprintf( stderr,
  88.                 "sps - Can't read page 0x%x of process %d\n",
  89.                 ptetbl[ CLSIZE+i ].pg_pfnum, p->pr_p.p_pid ) ;
  90.             return ( 0 ) ;
  91.         }
  92.     }
  93.     return ( 1 ) ;
  94. }
  95.