Return to BSD News archive
Path: sserve!manuel!munnari.oz.au!spool.mu.edu!yale.edu!yale!gumby!wupost!uwm.edu!rutgers!concert!epa-rtp!bizarre.rtpnc.epa.gov!fty
From: fty@bizarre.rtpnc.epa.gov (Frank Terhaar-Yonkers)
Newsgroups: comp.unix.bsd
Subject: Re: kvm.c patch
Keywords: ps new_patch kvm.c
Message-ID: <1992Aug7.134552.973@rtpnc.epa.gov>
Date: 7 Aug 92 13:45:52 GMT
Article-I.D.: rtpnc.1992Aug7.134552.973
References: <1992Jul23.173624.11010@cs.few.eur.nl>
Sender: usenet@rtpnc.epa.gov
Organization: United States Environmental Protection Agency
Lines: 177
Nntp-Posting-Host: bizarre.rtpnc.epa.gov
In article <1992Jul23.173624.11010@cs.few.eur.nl>, pk@cs.few.eur.nl (Paul Kranenburg) writes:
>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.
The patch didn`t agree with my out-of-the-box-0.1 kvm.c (1 chunk failed)
so I put in the changes by hand and regenerated the patch (it follows).
Warning! I haven't compiled and tested this yet, just regenerated the
patch.
- Frank
============= cut here for updated patch ================
*** kvm.c.386 Fri Aug 7 08:36:22 1992
--- kvm.c Fri Aug 7 09:34:38 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)
***************
*** 693,709 ****
#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);
}
}
--- 698,723 ----
#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);
}
}
***************
*** 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));