*BSD News Article 2337


Return to BSD News archive

Newsgroups: comp.unix.bsd
Path: sserve!manuel!munnari.oz.au!uunet!mcsun!sun4nl!eur.nl!pk
From: pk@cs.few.eur.nl (Paul Kranenburg)
Subject: kvm.c patch
Message-ID: <1992Jul23.173624.11010@cs.few.eur.nl>
Keywords: ps
Sender: news@cs.few.eur.nl
Reply-To: pk@cs.few.eur.nl
Organization: Erasmus University Rotterdam
Date: Thu, 23 Jul 1992 17:36:24 GMT
Lines: 182


The following patch to ./src/lib/libutil/kvm.c makes commands such as ps(1)
agree with the kernel as to the place in user memory where to the command
arguments can be found. This change has become necessary because the way
the arguments are copied at exec time has changed in the 0.1 kern_execve.c.

Remake libutil.a, run ranlib and recompile and install ps.

-pk.

------- kvm.c -------
*** /tmp/da28640	Thu Jul 23 18:48:25 1992
--- kvm.c	Thu Jul 23 18:48:01 1992
***************
*** 634,639 ****
--- 634,644 ----
  	}
  }
  
+ #ifdef i386
+ /* See also ./sys/kern/kern_execve.c */
+ #define ARGSIZE		(roundup(ARG_MAX, NBPG))
+ #endif
+ 
  #ifdef NEWVM
  struct user *
  kvm_getu(p)
***************
*** 691,713 ****
  #endif
  
  #ifdef i386
!       if (kp->kp_eproc.e_vm.vm_pmap.pm_pdir) {
!               struct pde pde;
  
!               klseek(kmem,
!                       (long)(kp->kp_eproc.e_vm.vm_pmap.pm_pdir + UPTDI), 0);
!               if (read(kmem, (char *)&pde, sizeof pde) == sizeof pde &&
!                       pde.pd_v) {
  
!                       struct pte pte;
  
!                       lseek(mem, (long)ctob(pde.pd_pfnum) +
!                               (ptei(USRSTACK-CLBYTES) * sizeof pte), 0);
!                       if (read(mem, (char *)&pte, sizeof pte) == sizeof pte && +                               pte.pg_v) {
!                               argaddr1 = (long)ctob(pte.pg_pfnum);
!                       }
!               }
!       }
  #endif
  	return(&user.user);
  }
--- 696,727 ----
  #endif
  
  #ifdef i386
! 	if (kp->kp_eproc.e_vm.vm_pmap.pm_pdir) {
! 		struct pde pde;
! 		u_int vaddr = USRSTACK-ARGSIZE;
  
! 		if ((u_int)kp->kp_eproc.e_vm.vm_maxsaddr + MAXSSIZ < USRSTACK)
! 			vaddr -= MAXSSIZ;
! #if 0
! 		klseek(kmem,
! 			(long)(kp->kp_eproc.e_vm.vm_pmap.pm_pdir + UPTDI), 0);
! #else
! 		klseek(kmem,
! 		(long)(&kp->kp_eproc.e_vm.vm_pmap.pm_pdir[pdei(vaddr)]), 0);
! #endif
! 		if (read(kmem, (char *)&pde, sizeof pde) == sizeof pde
! 				&& pde.pd_v) {
  
! 			struct pte pte;
  
! 			lseek(mem, (long)ctob(pde.pd_pfnum) +
! 				(ptei(vaddr) * sizeof pte), 0);
! 			if (read(mem, (char *)&pte, sizeof pte) == sizeof pte
! 					&& pte.pg_v) {
! 				argaddr1 = (long)ctob(pte.pg_pfnum);
! 			}
! 		}
! 	}
  #endif
  	return(&user.user);
  }
***************
*** 786,796 ****
--- 800,819 ----
  	const struct proc *p;
  	const struct user *up;
  {
+ #ifdef i386
+ 	/* See also ./sys/kern/kern_execve.c */
+ 	static char cmdbuf[ARGSIZE];
+ 	static union {
+ 		char	argc[ARGSIZE];
+ 		int	argi[ARGSIZE/sizeof (int)];
+ 	} argspac;
+ #else
  	static char cmdbuf[CLBYTES*2];
  	static union {
  		char	argc[CLBYTES*2];
  		int	argi[CLBYTES*2/sizeof (int)];
  	} argspac;
+ #endif
  	register char *cp;
  	register int *ip;
  	char c;
***************
*** 824,829 ****
--- 847,857 ----
  		file = swapf;
  #endif
  	} else {
+ #ifdef i386
+ 		lseek(mem, (long)argaddr1, 0);
+ 		if (read(mem, &argspac.argc[0], ARGSIZE) != ARGSIZE)
+ 			goto bad;
+ #else
  		if (argaddr0) {
  			lseek(mem, (long)argaddr0, 0);
  			if (read(mem, (char *)&argspac, CLBYTES) != CLBYTES)
***************
*** 833,842 ****
  		lseek(mem, (long)argaddr1, 0);
  		if (read(mem, &argspac.argc[CLBYTES], CLBYTES) != CLBYTES)
  			goto bad;
  		file = (char *) memf;
  	}
  #ifdef i386
! 	ip = &argspac.argi[(CLBYTES + CLBYTES/2)/sizeof (int)];
  #else
  	ip = &argspac.argi[CLBYTES*2/sizeof (int)];
  	ip -= 2;                /* last arg word and .long 0 */
--- 861,873 ----
  		lseek(mem, (long)argaddr1, 0);
  		if (read(mem, &argspac.argc[CLBYTES], CLBYTES) != CLBYTES)
  			goto bad;
+ #endif
  		file = (char *) memf;
  	}
  #ifdef i386
! 	ip = &argspac.argi[(ARGSIZE-ARG_MAX)/sizeof (int)];
! 
! 	for (cp = (char *)ip; cp < &argspac.argc[ARGSIZE-stkoff]; cp++) {
  #else
  	ip = &argspac.argi[CLBYTES*2/sizeof (int)];
  	ip -= 2;                /* last arg word and .long 0 */
***************
*** 848,855 ****
  	*(char *)ip = ' ';
  	ip++;
  	nbad = 0;
! #endif
  	for (cp = (char *)ip; cp < &argspac.argc[CLBYTES*2-stkoff]; cp++) {
  		c = *cp & 0177;
  		if (c == 0)
  			*cp = ' ';
--- 879,887 ----
  	*(char *)ip = ' ';
  	ip++;
  	nbad = 0;
! 
  	for (cp = (char *)ip; cp < &argspac.argc[CLBYTES*2-stkoff]; cp++) {
+ #endif
  		c = *cp & 0177;
  		if (c == 0)
  			*cp = ' ';
***************
*** 870,876 ****
--- 902,912 ----
  	while (*--cp == ' ')
  		*cp = 0;
  	cp = (char *)ip;
+ #ifdef i386
+ 	(void) strncpy(cmdbuf, cp, &argspac.argc[ARGSIZE*2] - cp);
+ #else
  	(void) strncpy(cmdbuf, cp, &argspac.argc[CLBYTES*2] - cp);
+ #endif
  	if (cp[0] == '-' || cp[0] == '?' || cp[0] <= ' ') {
  		(void) strcat(cmdbuf, " (");
  		(void) strncat(cmdbuf, p->p_comm, sizeof(p->p_comm));