home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume23 / sps2 / part02 / getupage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-08  |  4.1 KB  |  146 lines

  1. # ifndef lint
  2. static char SccsId[] =  "@(#)getupage.c    1.3\t8/2/90" ;
  3. # endif
  4.  
  5. # include       "sps.h"
  6. # ifdef KVM
  7. #  include      <kvm.h>
  8. # else
  9. #  include      <h/vm.h>
  10. #  ifdef BSD42
  11. #  include    <machine/pte.h>
  12. #  else
  13. #  include      <h/pte.h>
  14. #  endif
  15. # endif
  16. # include       <stdio.h>
  17.  
  18. /*
  19. ** GETUPAGE - Reads the upage for the specified process as well as sufficient
  20. ** page tables entries for reading the command arguments. The pte's are read
  21. ** into the argument `ptetbl'. The upage is read into the external variable
  22. ** `User'. This procedure returns 1 if the upage was successfully read.
  23. */
  24.  
  25. # ifndef KVM
  26.  
  27. # define        usrpt           (Info.i_usrpt)
  28.  
  29. getupage ( p, ptetbl )
  30.  
  31. register struct process         *p ;
  32. register struct pte             *ptetbl ;
  33.  
  34. {
  35.     register int            i ;
  36.     register int            ncl ;
  37.     struct pte              pte ;
  38.     extern struct info      Info ;
  39.     extern union userstate  User ;
  40.     extern int              Flmem, Flkmem, Flswap ;
  41.  
  42.     /* If the process is not loaded, look for the upage on the swap device*/
  43.     if ( !(p->pr_p.p_flag & SLOAD) )
  44.     {                               
  45. # ifdef BSD42
  46.         swseek( (long)dtob( p->pr_p.p_swaddr ) ) ;
  47. # else BSD42
  48.         swseek( (long)ctob( p->pr_p.p_swaddr ) ) ;
  49. # endif BSD42
  50. # ifdef SUN
  51.         if ( read( Flswap, (char*)&User.u_us, sizeof( union userstate ))
  52.         != sizeof( union userstate ) )
  53. # else SUN
  54.         if ( read( Flswap, (char*)&User.u_us, sizeof( struct user ) )
  55.         != sizeof( struct user ) )
  56. # endif SUN
  57.         {
  58.             fprintf( stderr,
  59.                 "sps - Can't read upage of process %d\n",
  60.                 p->pr_p.p_pid ) ;
  61.             return ( 0 ) ;
  62.         }
  63.         return ( 1 ) ;          
  64.     }                               
  65.     /* The process is loaded. Locate the process pte's by reading
  66.        the pte of their base address from system virtual address space. */
  67. # ifdef DEC3100
  68.     /* This method of accessing the upage suffices on the DEC Station
  69.        but only provides sufficient pte's to read the upage, leaving the
  70.        command arguments inaccessible. */
  71.     memseek( Flkmem, (long)p->pr_p.p_addr ) ;
  72.     if ( read( Flkmem, (char*)ptetbl, (UPAGES+CLSIZE)*sizeof( struct pte ) )
  73.     != (UPAGES+CLSIZE)*sizeof( struct pte ) )
  74.     {
  75.         fprintf( stderr, "sps - Can't read page table of process %d\n",
  76.             p->pr_p.p_pid ) ;
  77.         return ( 0 ) ;
  78.     }
  79. # else DEC3100
  80.     memseek( Flkmem, (long)&Info.i_usrptmap[ btokmx(p->pr_p.p_p0br)
  81.         + p->pr_p.p_szpt-1 ] ) ;
  82.     if ( read( Flkmem, (char*)&pte, sizeof( struct pte ) )
  83.     != sizeof( struct pte ) )
  84.     {
  85.         fprintf( stderr,
  86.               "sps - Can't read indir pte for upage of process %d\n",
  87.             p->pr_p.p_pid ) ;
  88.         return ( 0 ) ;
  89.     }                               
  90.     /* Now read the process' pte's from physical memory. We need to access
  91.        sufficient pte's for the upage and for the command arguments. */
  92.     memseek( Flmem, (long)ctob( pte.pg_pfnum+1 )
  93.         - (UPAGES+CLSIZE)*sizeof( struct pte ) ) ;
  94.     if ( read( Flmem, (char*)ptetbl, (UPAGES+CLSIZE)*sizeof( struct pte ) )
  95.     != (UPAGES+CLSIZE)*sizeof( struct pte ) )
  96.     {
  97.         fprintf( stderr, "sps - Can't read page table of process %d\n",
  98.             p->pr_p.p_pid ) ;
  99.         return ( 0 ) ;
  100.     }
  101. # endif DEC3100
  102.     /* Now we can read the pages belonging to the upage.
  103.        Here we read in an entire click at one go. */
  104.     ncl = (sizeof( struct user ) + NBPG*CLSIZE - 1) / (NBPG*CLSIZE) ;
  105.     while ( --ncl >= 0 )            
  106.     {                               
  107.         i = ncl * CLSIZE ;
  108. # ifdef DEC3100
  109.         memseek( Flmem, (long)ctob( ptetbl[ i ].pg_pfnum ) ) ;
  110. # else DEC3100
  111.         memseek( Flmem, (long)ctob( ptetbl[ CLSIZE+i ].pg_pfnum ) ) ;
  112. # endif DEC3100
  113.         if ( read( Flmem, User.u_pg[i], CLSIZE*NBPG ) != CLSIZE*NBPG )
  114.         {
  115.             fprintf( stderr,
  116.                 "sps - Can't read page 0x%x of process %d\n",
  117.                 ptetbl[ CLSIZE+i ].pg_pfnum, p->pr_p.p_pid ) ;
  118.             return ( 0 ) ;
  119.         }
  120.     }
  121.     return ( 1 ) ;
  122. }
  123.  
  124. # else KVM
  125.  
  126. getupage ( p )
  127.  
  128. register struct process         *p ;
  129.  
  130. {
  131.         struct user            *upage ;
  132.     extern union userstate  User ;
  133.     extern kvm_t           *Flkvm ;
  134.  
  135.     if (upage = kvm_getu( Flkvm, &p->pr_p ) )
  136.     {
  137.             bcopy( (char *)upage, User.u_pg[0], sizeof( struct user ) ) ;
  138.         return ( 1 ) ;
  139.     }
  140.     fprintf( stderr, "sps - Can't read upage of process %d\n",
  141.         p->pr_p.p_pid ) ;
  142.     return ( 0 ) ;
  143. }
  144.  
  145. # endif KVM
  146.