1994-05-27 05:00:24 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1989, 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software developed by the Computer Systems
|
|
|
|
* Engineering group at Lawrence Berkeley Laboratory under DARPA contract
|
|
|
|
* BG 91-66 and contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1999-11-16 20:31:58 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
|
|
|
static char sccsid[] = "@(#)kvm_proc.c 8.3 (Berkeley) 9/23/93";
|
|
|
|
#endif /* LIBC_SCCS and not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Proc traversal interface for kvm. ps and w are (probably) the exclusive
|
|
|
|
* users of this code, so we've factored it out into a separate module.
|
|
|
|
* Thus, we keep this grunge out of the other kvm applications (i.e.,
|
|
|
|
* most other applications are interested only in open/close/read/nlist).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2001-05-01 09:24:15 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <sys/user.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/exec.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
1994-08-11 13:38:23 +00:00
|
|
|
#include <sys/file.h>
|
1996-07-12 18:57:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <kvm.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/swap_pager.h>
|
|
|
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
1995-12-09 04:42:51 +00:00
|
|
|
#include <memory.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <paths.h>
|
|
|
|
|
|
|
|
#include "kvm_private.h"
|
|
|
|
|
1996-07-12 18:57:58 +00:00
|
|
|
#if used
|
1994-05-27 05:00:24 +00:00
|
|
|
static char *
|
|
|
|
kvm_readswap(kd, p, va, cnt)
|
|
|
|
kvm_t *kd;
|
|
|
|
const struct proc *p;
|
|
|
|
u_long va;
|
|
|
|
u_long *cnt;
|
|
|
|
{
|
1994-05-28 05:48:30 +00:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
/* XXX Stubbed out, our vm system is differnet */
|
|
|
|
_kvm_err(kd, kd->program, "kvm_readswap not implemented");
|
|
|
|
return(0);
|
|
|
|
#endif /* __FreeBSD__ */
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
1996-07-12 18:57:58 +00:00
|
|
|
#endif
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
#define KREAD(kd, addr, obj) \
|
|
|
|
(kvm_read(kd, addr, (char *)(obj), sizeof(*obj)) != sizeof(*obj))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read proc's from memory file into buffer bp, which has space to hold
|
|
|
|
* at most maxcnt procs.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
kvm_proclist(kd, what, arg, p, bp, maxcnt)
|
|
|
|
kvm_t *kd;
|
|
|
|
int what, arg;
|
|
|
|
struct proc *p;
|
|
|
|
struct kinfo_proc *bp;
|
|
|
|
int maxcnt;
|
|
|
|
{
|
|
|
|
register int cnt = 0;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
struct kinfo_proc kinfo_proc, *kp;
|
1994-05-27 05:00:24 +00:00
|
|
|
struct pgrp pgrp;
|
|
|
|
struct session sess;
|
|
|
|
struct tty tty;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
struct vmspace vmspace;
|
|
|
|
struct procsig procsig;
|
|
|
|
struct pcred pcred;
|
|
|
|
struct pstats pstats;
|
|
|
|
struct ucred ucred;
|
1994-05-27 05:00:24 +00:00
|
|
|
struct proc proc;
|
1997-06-25 20:56:48 +00:00
|
|
|
struct proc pproc;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp = &kinfo_proc;
|
|
|
|
kp->ki_structsize = sizeof(kinfo_proc);
|
2000-12-30 21:52:34 +00:00
|
|
|
for (; cnt < maxcnt && p != NULL; p = LIST_NEXT(&proc, p_list)) {
|
1994-05-27 05:00:24 +00:00
|
|
|
if (KREAD(kd, (u_long)p, &proc)) {
|
|
|
|
_kvm_err(kd, kd->program, "can't read proc at %x", p);
|
|
|
|
return (-1);
|
|
|
|
}
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (KREAD(kd, (u_long)proc.p_cred, &pcred) == 0) {
|
|
|
|
kp->ki_ruid = pcred.p_ruid;
|
|
|
|
kp->ki_svuid = pcred.p_svuid;
|
|
|
|
kp->ki_rgid = pcred.p_rgid;
|
|
|
|
kp->ki_svgid = pcred.p_svgid;
|
|
|
|
(void)(KREAD(kd, (u_long)pcred.pc_ucred, &ucred));
|
|
|
|
kp->ki_ngroups = ucred.cr_ngroups;
|
|
|
|
bcopy(ucred.cr_groups, kp->ki_groups,
|
|
|
|
NGROUPS * sizeof(gid_t));
|
|
|
|
kp->ki_uid = ucred.cr_uid;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
switch(what) {
|
1995-05-30 05:51:47 +00:00
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
case KERN_PROC_PID:
|
|
|
|
if (proc.p_pid != (pid_t)arg)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KERN_PROC_UID:
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kp->ki_uid != (uid_t)arg)
|
1994-05-27 05:00:24 +00:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KERN_PROC_RUID:
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kp->ki_ruid != (uid_t)arg)
|
1994-05-27 05:00:24 +00:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We're going to add another proc to the set. If this
|
|
|
|
* will overflow the buffer, assume the reason is because
|
|
|
|
* nprocs (or the proc list) is corrupt and declare an error.
|
|
|
|
*/
|
|
|
|
if (cnt >= maxcnt) {
|
|
|
|
_kvm_err(kd, kd->program, "nprocs corrupt");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
/*
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
* gather kinfo_proc
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_paddr = p;
|
|
|
|
kp->ki_addr = proc.p_addr;
|
|
|
|
kp->ki_args = proc.p_args;
|
|
|
|
kp->ki_tracep = proc.p_tracep;
|
|
|
|
kp->ki_textvp = proc.p_textvp;
|
|
|
|
kp->ki_fd = proc.p_fd;
|
|
|
|
kp->ki_vmspace = proc.p_vmspace;
|
|
|
|
if (proc.p_procsig != NULL) {
|
|
|
|
if (KREAD(kd, (u_long)proc.p_procsig, &procsig)) {
|
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"can't read procsig at %x", proc.p_procsig);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
kp->ki_sigignore = procsig.ps_sigignore;
|
|
|
|
kp->ki_sigcatch = procsig.ps_sigcatch;
|
|
|
|
}
|
2001-01-24 12:49:52 +00:00
|
|
|
if ((proc.p_sflag & PS_INMEM) && proc.p_stats != NULL) {
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (KREAD(kd, (u_long)proc.p_stats, &pstats)) {
|
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"can't read stats at %x", proc.p_stats);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
kp->ki_start = pstats.p_start;
|
|
|
|
kp->ki_rusage = pstats.p_ru;
|
|
|
|
kp->ki_childtime.tv_sec = pstats.p_cru.ru_utime.tv_sec +
|
|
|
|
pstats.p_cru.ru_stime.tv_sec;
|
|
|
|
kp->ki_childtime.tv_usec =
|
|
|
|
pstats.p_cru.ru_utime.tv_usec +
|
|
|
|
pstats.p_cru.ru_stime.tv_usec;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
if (KREAD(kd, (u_long)proc.p_pgrp, &pgrp)) {
|
|
|
|
_kvm_err(kd, kd->program, "can't read pgrp at %x",
|
|
|
|
proc.p_pgrp);
|
|
|
|
return (-1);
|
|
|
|
}
|
1997-06-25 20:56:48 +00:00
|
|
|
if (proc.p_oppid)
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_ppid = proc.p_oppid;
|
1997-06-25 20:56:48 +00:00
|
|
|
else if (proc.p_pptr) {
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (KREAD(kd, (u_long)proc.p_pptr, &pproc)) {
|
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"can't read pproc at %x", proc.p_pptr);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
kp->ki_ppid = pproc.p_pid;
|
1997-06-25 20:56:48 +00:00
|
|
|
} else
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_ppid = 0;
|
|
|
|
kp->ki_pgid = pgrp.pg_id;
|
|
|
|
kp->ki_jobc = pgrp.pg_jobc;
|
1994-05-27 05:00:24 +00:00
|
|
|
if (KREAD(kd, (u_long)pgrp.pg_session, &sess)) {
|
1995-05-30 05:51:47 +00:00
|
|
|
_kvm_err(kd, kd->program, "can't read session at %x",
|
1994-05-27 05:00:24 +00:00
|
|
|
pgrp.pg_session);
|
|
|
|
return (-1);
|
|
|
|
}
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_sid = sess.s_sid;
|
|
|
|
(void)memcpy(kp->ki_login, sess.s_login,
|
|
|
|
sizeof(kp->ki_login));
|
|
|
|
kp->ki_kiflag = sess.s_ttyvp ? KI_CTTY : 0;
|
|
|
|
if (sess.s_leader == p)
|
|
|
|
kp->ki_kiflag |= KI_SLEADER;
|
1994-05-27 05:00:24 +00:00
|
|
|
if ((proc.p_flag & P_CONTROLT) && sess.s_ttyp != NULL) {
|
|
|
|
if (KREAD(kd, (u_long)sess.s_ttyp, &tty)) {
|
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"can't read tty at %x", sess.s_ttyp);
|
|
|
|
return (-1);
|
|
|
|
}
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_tdev = tty.t_dev;
|
1994-05-27 05:00:24 +00:00
|
|
|
if (tty.t_pgrp != NULL) {
|
|
|
|
if (KREAD(kd, (u_long)tty.t_pgrp, &pgrp)) {
|
|
|
|
_kvm_err(kd, kd->program,
|
1995-05-30 05:51:47 +00:00
|
|
|
"can't read tpgrp at &x",
|
1994-05-27 05:00:24 +00:00
|
|
|
tty.t_pgrp);
|
|
|
|
return (-1);
|
|
|
|
}
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_tpgid = pgrp.pg_id;
|
1994-05-27 05:00:24 +00:00
|
|
|
} else
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_tpgid = -1;
|
|
|
|
if (tty.t_session != NULL) {
|
|
|
|
if (KREAD(kd, (u_long)tty.t_session, &sess)) {
|
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"can't read session at %x",
|
|
|
|
tty.t_session);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
kp->ki_tsid = sess.s_sid;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
} else
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_tdev = NODEV;
|
1994-05-27 05:00:24 +00:00
|
|
|
if (proc.p_wmesg)
|
1995-05-30 05:51:47 +00:00
|
|
|
(void)kvm_read(kd, (u_long)proc.p_wmesg,
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_wmesg, WMESGLEN);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
#ifdef sparc
|
|
|
|
(void)kvm_read(kd, (u_long)&proc.p_vmspace->vm_rssize,
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
(char *)&kp->ki_rssize,
|
|
|
|
sizeof(kp->ki_rssize));
|
1994-05-27 05:00:24 +00:00
|
|
|
(void)kvm_read(kd, (u_long)&proc.p_vmspace->vm_tsize,
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
(char *)&kp->ki_tsize,
|
|
|
|
3 * sizeof(kp->ki_rssize)); /* XXX */
|
1994-05-27 05:00:24 +00:00
|
|
|
#else
|
|
|
|
(void)kvm_read(kd, (u_long)proc.p_vmspace,
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
(char *)&vmspace, sizeof(vmspace));
|
|
|
|
kp->ki_size = vmspace.vm_map.size;
|
|
|
|
kp->ki_rssize = vmspace.vm_swrss; /* XXX */
|
|
|
|
kp->ki_swrss = vmspace.vm_swrss;
|
|
|
|
kp->ki_tsize = vmspace.vm_tsize;
|
|
|
|
kp->ki_dsize = vmspace.vm_dsize;
|
|
|
|
kp->ki_ssize = vmspace.vm_ssize;
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (what) {
|
|
|
|
|
|
|
|
case KERN_PROC_PGRP:
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kp->ki_pgid != (pid_t)arg)
|
1994-05-27 05:00:24 +00:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KERN_PROC_TTY:
|
1995-05-30 05:51:47 +00:00
|
|
|
if ((proc.p_flag & P_CONTROLT) == 0 ||
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_tdev != (dev_t)arg)
|
1994-05-27 05:00:24 +00:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (proc.p_comm[0] != 0) {
|
|
|
|
strncpy(kp->ki_comm, proc.p_comm, MAXCOMLEN);
|
|
|
|
kp->ki_comm[MAXCOMLEN] = 0;
|
|
|
|
}
|
|
|
|
if (proc.p_blocked != 0) {
|
|
|
|
kp->ki_kiflag |= KI_MTXBLOCK;
|
|
|
|
if (proc.p_mtxname)
|
|
|
|
(void)kvm_read(kd, (u_long)proc.p_mtxname,
|
|
|
|
kp->ki_mtxname, MTXNAMELEN);
|
|
|
|
kp->ki_mtxname[MTXNAMELEN] = 0;
|
|
|
|
}
|
|
|
|
kp->ki_runtime = proc.p_runtime;
|
|
|
|
kp->ki_pid = proc.p_pid;
|
|
|
|
kp->ki_siglist = proc.p_siglist;
|
|
|
|
kp->ki_sigmask = proc.p_sigmask;
|
|
|
|
kp->ki_xstat = proc.p_xstat;
|
|
|
|
kp->ki_acflag = proc.p_acflag;
|
|
|
|
kp->ki_pctcpu = proc.p_pctcpu;
|
|
|
|
kp->ki_estcpu = proc.p_estcpu;
|
|
|
|
kp->ki_slptime = proc.p_slptime;
|
|
|
|
kp->ki_swtime = proc.p_swtime;
|
|
|
|
kp->ki_flag = proc.p_flag;
|
2001-01-24 12:49:52 +00:00
|
|
|
kp->ki_sflag = proc.p_sflag;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_wchan = proc.p_wchan;
|
|
|
|
kp->ki_traceflag = proc.p_traceflag;
|
|
|
|
kp->ki_stat = proc.p_stat;
|
2001-02-12 00:21:38 +00:00
|
|
|
kp->ki_pri = proc.p_pri;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kp->ki_nice = proc.p_nice;
|
|
|
|
kp->ki_lock = proc.p_lock;
|
|
|
|
kp->ki_rqindex = proc.p_rqindex;
|
|
|
|
kp->ki_oncpu = proc.p_oncpu;
|
|
|
|
kp->ki_lastcpu = proc.p_lastcpu;
|
|
|
|
bcopy(&kinfo_proc, bp, sizeof(kinfo_proc));
|
1994-05-27 05:00:24 +00:00
|
|
|
++bp;
|
|
|
|
++cnt;
|
|
|
|
}
|
|
|
|
return (cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build proc info array by reading in proc list from a crash dump.
|
|
|
|
* Return number of procs read. maxcnt is the max we will read.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
kvm_deadprocs(kd, what, arg, a_allproc, a_zombproc, maxcnt)
|
|
|
|
kvm_t *kd;
|
|
|
|
int what, arg;
|
|
|
|
u_long a_allproc;
|
|
|
|
u_long a_zombproc;
|
|
|
|
int maxcnt;
|
|
|
|
{
|
|
|
|
register struct kinfo_proc *bp = kd->procbase;
|
|
|
|
register int acnt, zcnt;
|
|
|
|
struct proc *p;
|
|
|
|
|
|
|
|
if (KREAD(kd, a_allproc, &p)) {
|
|
|
|
_kvm_err(kd, kd->program, "cannot read allproc");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
acnt = kvm_proclist(kd, what, arg, p, bp, maxcnt);
|
|
|
|
if (acnt < 0)
|
|
|
|
return (acnt);
|
|
|
|
|
|
|
|
if (KREAD(kd, a_zombproc, &p)) {
|
|
|
|
_kvm_err(kd, kd->program, "cannot read zombproc");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
zcnt = kvm_proclist(kd, what, arg, p, bp + acnt, maxcnt - acnt);
|
|
|
|
if (zcnt < 0)
|
|
|
|
zcnt = 0;
|
|
|
|
|
|
|
|
return (acnt + zcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct kinfo_proc *
|
|
|
|
kvm_getprocs(kd, op, arg, cnt)
|
|
|
|
kvm_t *kd;
|
|
|
|
int op, arg;
|
|
|
|
int *cnt;
|
|
|
|
{
|
1998-08-25 07:52:33 +00:00
|
|
|
int mib[4], st, nprocs;
|
|
|
|
size_t size;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
if (kd->procbase != 0) {
|
|
|
|
free((void *)kd->procbase);
|
1995-05-30 05:51:47 +00:00
|
|
|
/*
|
1994-05-27 05:00:24 +00:00
|
|
|
* Clear this pointer in case this call fails. Otherwise,
|
|
|
|
* kvm_close() will free it again.
|
|
|
|
*/
|
|
|
|
kd->procbase = 0;
|
|
|
|
}
|
|
|
|
if (ISALIVE(kd)) {
|
|
|
|
size = 0;
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_PROC;
|
|
|
|
mib[2] = op;
|
|
|
|
mib[3] = arg;
|
1996-06-06 17:16:52 +00:00
|
|
|
st = sysctl(mib, op == KERN_PROC_ALL ? 3 : 4, NULL, &size, NULL, 0);
|
1994-05-27 05:00:24 +00:00
|
|
|
if (st == -1) {
|
|
|
|
_kvm_syserr(kd, kd->program, "kvm_getprocs");
|
|
|
|
return (0);
|
|
|
|
}
|
1998-10-12 20:36:33 +00:00
|
|
|
do {
|
|
|
|
size += size / 10;
|
|
|
|
kd->procbase = (struct kinfo_proc *)
|
1998-12-16 18:31:51 +00:00
|
|
|
_kvm_realloc(kd, kd->procbase, size);
|
1998-10-12 20:36:33 +00:00
|
|
|
if (kd->procbase == 0)
|
|
|
|
return (0);
|
|
|
|
st = sysctl(mib, op == KERN_PROC_ALL ? 3 : 4,
|
1998-12-16 18:31:51 +00:00
|
|
|
kd->procbase, &size, NULL, 0);
|
1998-10-12 20:36:33 +00:00
|
|
|
} while (st == -1 && errno == ENOMEM);
|
1994-05-27 05:00:24 +00:00
|
|
|
if (st == -1) {
|
|
|
|
_kvm_syserr(kd, kd->program, "kvm_getprocs");
|
|
|
|
return (0);
|
|
|
|
}
|
2001-05-01 10:34:15 +00:00
|
|
|
if (size > 0 &&
|
|
|
|
kd->procbase->ki_structsize != sizeof(struct kinfo_proc)) {
|
1994-05-27 05:00:24 +00:00
|
|
|
_kvm_err(kd, kd->program,
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
"kinfo_proc size mismatch (expected %d, got %d)",
|
|
|
|
sizeof(struct kinfo_proc),
|
|
|
|
kd->procbase->ki_structsize);
|
1994-05-27 05:00:24 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2001-05-03 11:26:46 +00:00
|
|
|
nprocs = size == 0 ? 0 : size / kd->procbase->ki_structsize;
|
1994-05-27 05:00:24 +00:00
|
|
|
} else {
|
|
|
|
struct nlist nl[4], *p;
|
|
|
|
|
|
|
|
nl[0].n_name = "_nprocs";
|
|
|
|
nl[1].n_name = "_allproc";
|
|
|
|
nl[2].n_name = "_zombproc";
|
|
|
|
nl[3].n_name = 0;
|
|
|
|
|
|
|
|
if (kvm_nlist(kd, nl) != 0) {
|
|
|
|
for (p = nl; p->n_type != 0; ++p)
|
|
|
|
;
|
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"%s: no such symbol", p->n_name);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (KREAD(kd, nl[0].n_value, &nprocs)) {
|
|
|
|
_kvm_err(kd, kd->program, "can't read nprocs");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
size = nprocs * sizeof(struct kinfo_proc);
|
|
|
|
kd->procbase = (struct kinfo_proc *)_kvm_malloc(kd, size);
|
|
|
|
if (kd->procbase == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
nprocs = kvm_deadprocs(kd, op, arg, nl[1].n_value,
|
|
|
|
nl[2].n_value, nprocs);
|
|
|
|
#ifdef notdef
|
|
|
|
size = nprocs * sizeof(struct kinfo_proc);
|
|
|
|
(void)realloc(kd->procbase, size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
*cnt = nprocs;
|
|
|
|
return (kd->procbase);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_kvm_freeprocs(kd)
|
|
|
|
kvm_t *kd;
|
|
|
|
{
|
|
|
|
if (kd->procbase) {
|
|
|
|
free(kd->procbase);
|
|
|
|
kd->procbase = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
_kvm_realloc(kd, p, n)
|
|
|
|
kvm_t *kd;
|
|
|
|
void *p;
|
|
|
|
size_t n;
|
|
|
|
{
|
|
|
|
void *np = (void *)realloc(p, n);
|
|
|
|
|
1998-09-16 04:17:47 +00:00
|
|
|
if (np == 0) {
|
|
|
|
free(p);
|
1994-05-27 05:00:24 +00:00
|
|
|
_kvm_err(kd, kd->program, "out of memory");
|
1998-09-16 04:17:47 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
return (np);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
* Read in an argument vector from the user address space of process kp.
|
1995-12-09 04:42:51 +00:00
|
|
|
* addr if the user-space base address of narg null-terminated contiguous
|
1994-05-27 05:00:24 +00:00
|
|
|
* strings. This is used to read in both the command arguments and
|
|
|
|
* environment strings. Read at most maxcnt characters of strings.
|
|
|
|
*/
|
|
|
|
static char **
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kvm_argv(kd, kp, addr, narg, maxcnt)
|
1994-05-27 05:00:24 +00:00
|
|
|
kvm_t *kd;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
struct kinfo_proc *kp;
|
1994-05-27 05:00:24 +00:00
|
|
|
register u_long addr;
|
|
|
|
register int narg;
|
|
|
|
register int maxcnt;
|
|
|
|
{
|
1995-12-09 04:42:51 +00:00
|
|
|
register char *np, *cp, *ep, *ap;
|
|
|
|
register u_long oaddr = -1;
|
1994-05-27 05:00:24 +00:00
|
|
|
register int len, cc;
|
|
|
|
register char **argv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that there aren't an unreasonable number of agruments,
|
|
|
|
* and that the address is in user space.
|
|
|
|
*/
|
1995-12-16 09:25:17 +00:00
|
|
|
if (narg > 512 || addr < VM_MIN_ADDRESS || addr >= VM_MAXUSER_ADDRESS)
|
1994-05-27 05:00:24 +00:00
|
|
|
return (0);
|
|
|
|
|
1995-12-16 09:25:17 +00:00
|
|
|
/*
|
|
|
|
* kd->argv : work space for fetching the strings from the target
|
|
|
|
* process's space, and is converted for returning to caller
|
|
|
|
*/
|
1994-05-27 05:00:24 +00:00
|
|
|
if (kd->argv == 0) {
|
|
|
|
/*
|
|
|
|
* Try to avoid reallocs.
|
|
|
|
*/
|
|
|
|
kd->argc = MAX(narg + 1, 32);
|
1995-05-30 05:51:47 +00:00
|
|
|
kd->argv = (char **)_kvm_malloc(kd, kd->argc *
|
1994-05-27 05:00:24 +00:00
|
|
|
sizeof(*kd->argv));
|
|
|
|
if (kd->argv == 0)
|
|
|
|
return (0);
|
|
|
|
} else if (narg + 1 > kd->argc) {
|
|
|
|
kd->argc = MAX(2 * kd->argc, narg + 1);
|
1995-05-30 05:51:47 +00:00
|
|
|
kd->argv = (char **)_kvm_realloc(kd, kd->argv, kd->argc *
|
1994-05-27 05:00:24 +00:00
|
|
|
sizeof(*kd->argv));
|
|
|
|
if (kd->argv == 0)
|
|
|
|
return (0);
|
|
|
|
}
|
1995-12-16 09:25:17 +00:00
|
|
|
/*
|
|
|
|
* kd->argspc : returned to user, this is where the kd->argv
|
|
|
|
* arrays are left pointing to the collected strings.
|
|
|
|
*/
|
1994-05-27 05:00:24 +00:00
|
|
|
if (kd->argspc == 0) {
|
1996-05-02 09:23:36 +00:00
|
|
|
kd->argspc = (char *)_kvm_malloc(kd, PAGE_SIZE);
|
1994-05-27 05:00:24 +00:00
|
|
|
if (kd->argspc == 0)
|
|
|
|
return (0);
|
1996-05-02 09:23:36 +00:00
|
|
|
kd->arglen = PAGE_SIZE;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
1995-12-16 09:25:17 +00:00
|
|
|
/*
|
|
|
|
* kd->argbuf : used to pull in pages from the target process.
|
|
|
|
* the strings are copied out of here.
|
|
|
|
*/
|
1995-12-09 04:42:51 +00:00
|
|
|
if (kd->argbuf == 0) {
|
1996-05-02 09:23:36 +00:00
|
|
|
kd->argbuf = (char *)_kvm_malloc(kd, PAGE_SIZE);
|
1995-12-09 04:42:51 +00:00
|
|
|
if (kd->argbuf == 0)
|
|
|
|
return (0);
|
|
|
|
}
|
1995-12-16 09:25:17 +00:00
|
|
|
|
|
|
|
/* Pull in the target process'es argv vector */
|
1995-12-09 04:42:51 +00:00
|
|
|
cc = sizeof(char *) * narg;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kvm_uread(kd, kp, addr, (char *)kd->argv, cc) != cc)
|
1995-12-09 04:42:51 +00:00
|
|
|
return (0);
|
1995-12-16 09:25:17 +00:00
|
|
|
/*
|
|
|
|
* ap : saved start address of string we're working on in kd->argspc
|
|
|
|
* np : pointer to next place to write in kd->argspc
|
|
|
|
* len: length of data in kd->argspc
|
|
|
|
* argv: pointer to the argv vector that we are hunting around the
|
|
|
|
* target process space for, and converting to addresses in
|
|
|
|
* our address space (kd->argspc).
|
|
|
|
*/
|
1995-12-09 04:42:51 +00:00
|
|
|
ap = np = kd->argspc;
|
1994-05-27 05:00:24 +00:00
|
|
|
argv = kd->argv;
|
|
|
|
len = 0;
|
|
|
|
/*
|
|
|
|
* Loop over pages, filling in the argument vector.
|
1995-12-16 09:25:17 +00:00
|
|
|
* Note that the argv strings could be pointing *anywhere* in
|
|
|
|
* the user address space and are no longer contiguous.
|
|
|
|
* Note that *argv is modified when we are going to fetch a string
|
|
|
|
* that crosses a page boundary. We copy the next part of the string
|
|
|
|
* into to "np" and eventually convert the pointer.
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
1995-12-09 04:42:51 +00:00
|
|
|
while (argv < kd->argv + narg && *argv != 0) {
|
1995-12-16 09:25:17 +00:00
|
|
|
|
|
|
|
/* get the address that the current argv string is on */
|
1996-05-02 09:23:36 +00:00
|
|
|
addr = (u_long)*argv & ~(PAGE_SIZE - 1);
|
1995-12-16 09:25:17 +00:00
|
|
|
|
|
|
|
/* is it the same page as the last one? */
|
1995-12-09 04:42:51 +00:00
|
|
|
if (addr != oaddr) {
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kvm_uread(kd, kp, addr, kd->argbuf, PAGE_SIZE) !=
|
1996-05-02 09:23:36 +00:00
|
|
|
PAGE_SIZE)
|
1995-12-09 04:42:51 +00:00
|
|
|
return (0);
|
|
|
|
oaddr = addr;
|
|
|
|
}
|
1995-12-16 09:25:17 +00:00
|
|
|
|
|
|
|
/* offset within the page... kd->argbuf */
|
1996-05-02 09:23:36 +00:00
|
|
|
addr = (u_long)*argv & (PAGE_SIZE - 1);
|
1995-12-16 09:25:17 +00:00
|
|
|
|
|
|
|
/* cp = start of string, cc = count of chars in this chunk */
|
1995-12-09 04:42:51 +00:00
|
|
|
cp = kd->argbuf + addr;
|
1996-05-02 09:23:36 +00:00
|
|
|
cc = PAGE_SIZE - addr;
|
1995-12-16 09:25:17 +00:00
|
|
|
|
|
|
|
/* dont get more than asked for by user process */
|
1994-05-27 05:00:24 +00:00
|
|
|
if (maxcnt > 0 && cc > maxcnt - len)
|
1995-12-16 09:25:17 +00:00
|
|
|
cc = maxcnt - len;
|
|
|
|
|
|
|
|
/* pointer to end of string if we found it in this page */
|
1995-12-09 04:42:51 +00:00
|
|
|
ep = memchr(cp, '\0', cc);
|
|
|
|
if (ep != 0)
|
|
|
|
cc = ep - cp + 1;
|
1995-12-16 09:25:17 +00:00
|
|
|
/*
|
|
|
|
* at this point, cc is the count of the chars that we are
|
|
|
|
* going to retrieve this time. we may or may not have found
|
|
|
|
* the end of it. (ep points to the null if the end is known)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* will we exceed the malloc/realloced buffer? */
|
1994-05-27 05:00:24 +00:00
|
|
|
if (len + cc > kd->arglen) {
|
|
|
|
register int off;
|
|
|
|
register char **pp;
|
|
|
|
register char *op = kd->argspc;
|
|
|
|
|
|
|
|
kd->arglen *= 2;
|
|
|
|
kd->argspc = (char *)_kvm_realloc(kd, kd->argspc,
|
|
|
|
kd->arglen);
|
|
|
|
if (kd->argspc == 0)
|
|
|
|
return (0);
|
|
|
|
/*
|
|
|
|
* Adjust argv pointers in case realloc moved
|
|
|
|
* the string space.
|
|
|
|
*/
|
|
|
|
off = kd->argspc - op;
|
1995-12-09 04:42:51 +00:00
|
|
|
for (pp = kd->argv; pp < argv; pp++)
|
1994-05-27 05:00:24 +00:00
|
|
|
*pp += off;
|
1995-12-09 04:42:51 +00:00
|
|
|
ap += off;
|
|
|
|
np += off;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
1995-12-16 09:25:17 +00:00
|
|
|
/* np = where to put the next part of the string in kd->argspc*/
|
|
|
|
/* np is kinda redundant.. could use "kd->argspc + len" */
|
1995-12-09 04:42:51 +00:00
|
|
|
memcpy(np, cp, cc);
|
1995-12-16 09:25:17 +00:00
|
|
|
np += cc; /* inc counters */
|
1994-05-27 05:00:24 +00:00
|
|
|
len += cc;
|
1995-12-16 09:25:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if end of string found, set the *argv pointer to the
|
|
|
|
* saved beginning of string, and advance. argv points to
|
|
|
|
* somewhere in kd->argv.. This is initially relative
|
|
|
|
* to the target process, but when we close it off, we set
|
|
|
|
* it to point in our address space.
|
|
|
|
*/
|
1995-12-09 04:42:51 +00:00
|
|
|
if (ep != 0) {
|
|
|
|
*argv++ = ap;
|
|
|
|
ap = np;
|
1995-12-16 09:25:17 +00:00
|
|
|
} else {
|
|
|
|
/* update the address relative to the target process */
|
1995-12-09 04:42:51 +00:00
|
|
|
*argv += cc;
|
1995-12-16 09:25:17 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
if (maxcnt > 0 && len >= maxcnt) {
|
|
|
|
/*
|
|
|
|
* We're stopping prematurely. Terminate the
|
1995-12-09 04:42:51 +00:00
|
|
|
* current string.
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
1995-12-09 04:42:51 +00:00
|
|
|
if (ep == 0) {
|
|
|
|
*np = '\0';
|
|
|
|
*argv++ = ap;
|
1995-12-16 09:25:17 +00:00
|
|
|
}
|
1995-12-09 04:42:51 +00:00
|
|
|
break;
|
1995-12-16 09:25:17 +00:00
|
|
|
}
|
1995-12-09 04:42:51 +00:00
|
|
|
}
|
|
|
|
/* Make sure argv is terminated. */
|
|
|
|
*argv = 0;
|
|
|
|
return (kd->argv);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ps_str_a(p, addr, n)
|
|
|
|
struct ps_strings *p;
|
|
|
|
u_long *addr;
|
|
|
|
int *n;
|
|
|
|
{
|
|
|
|
*addr = (u_long)p->ps_argvstr;
|
|
|
|
*n = p->ps_nargvstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ps_str_e(p, addr, n)
|
|
|
|
struct ps_strings *p;
|
|
|
|
u_long *addr;
|
|
|
|
int *n;
|
|
|
|
{
|
|
|
|
*addr = (u_long)p->ps_envstr;
|
|
|
|
*n = p->ps_nenvstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine if the proc indicated by p is still active.
|
|
|
|
* This test is not 100% foolproof in theory, but chances of
|
|
|
|
* being wrong are very low.
|
|
|
|
*/
|
|
|
|
static int
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
proc_verify(curkp)
|
|
|
|
struct kinfo_proc *curkp;
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
struct kinfo_proc newkp;
|
1998-12-16 18:31:51 +00:00
|
|
|
int mib[4];
|
1998-08-25 07:52:33 +00:00
|
|
|
size_t len;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
1998-06-30 21:29:44 +00:00
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_PROC;
|
|
|
|
mib[2] = KERN_PROC_PID;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
mib[3] = curkp->ki_pid;
|
|
|
|
len = sizeof(newkp);
|
|
|
|
if (sysctl(mib, 4, &newkp, &len, NULL, 0) == -1)
|
1998-12-16 18:31:51 +00:00
|
|
|
return (0);
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
return (curkp->ki_pid == newkp.ki_pid &&
|
|
|
|
(newkp.ki_stat != SZOMB || curkp->ki_stat == SZOMB));
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char **
|
|
|
|
kvm_doargv(kd, kp, nchr, info)
|
|
|
|
kvm_t *kd;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
struct kinfo_proc *kp;
|
1994-05-27 05:00:24 +00:00
|
|
|
int nchr;
|
1995-12-09 04:42:51 +00:00
|
|
|
void (*info)(struct ps_strings *, u_long *, int *);
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
char **ap;
|
1994-05-27 05:00:24 +00:00
|
|
|
u_long addr;
|
|
|
|
int cnt;
|
1998-12-16 18:31:51 +00:00
|
|
|
static struct ps_strings arginfo;
|
|
|
|
static u_long ps_strings;
|
1996-02-24 14:37:30 +00:00
|
|
|
size_t len;
|
1998-06-30 21:29:44 +00:00
|
|
|
|
|
|
|
if (ps_strings == NULL) {
|
1998-12-16 18:31:51 +00:00
|
|
|
len = sizeof(ps_strings);
|
|
|
|
if (sysctlbyname("kern.ps_strings", &ps_strings, &len, NULL,
|
|
|
|
0) == -1)
|
1998-06-30 21:29:44 +00:00
|
|
|
ps_strings = PS_STRINGS;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pointers are stored at the top of the user stack.
|
|
|
|
*/
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kp->ki_stat == SZOMB ||
|
|
|
|
kvm_uread(kd, kp, ps_strings, (char *)&arginfo,
|
1995-12-09 04:42:51 +00:00
|
|
|
sizeof(arginfo)) != sizeof(arginfo))
|
1994-05-27 05:00:24 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
(*info)(&arginfo, &addr, &cnt);
|
1995-12-09 04:42:51 +00:00
|
|
|
if (cnt == 0)
|
|
|
|
return (0);
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
ap = kvm_argv(kd, kp, addr, cnt, nchr);
|
1994-05-27 05:00:24 +00:00
|
|
|
/*
|
|
|
|
* For live kernels, make sure this process didn't go away.
|
|
|
|
*/
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (ap != 0 && ISALIVE(kd) && !proc_verify(kp))
|
1994-05-27 05:00:24 +00:00
|
|
|
ap = 0;
|
|
|
|
return (ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the command args. This code is now machine independent.
|
|
|
|
*/
|
|
|
|
char **
|
|
|
|
kvm_getargv(kd, kp, nchr)
|
|
|
|
kvm_t *kd;
|
|
|
|
const struct kinfo_proc *kp;
|
|
|
|
int nchr;
|
|
|
|
{
|
1999-11-16 20:31:58 +00:00
|
|
|
int oid[4];
|
2000-03-27 00:33:45 +00:00
|
|
|
int i;
|
|
|
|
size_t bufsz;
|
1999-11-16 20:31:58 +00:00
|
|
|
static int buflen;
|
|
|
|
static char *buf, *p;
|
|
|
|
static char **bufp;
|
|
|
|
static int argc;
|
|
|
|
|
1999-12-27 07:14:58 +00:00
|
|
|
if (!ISALIVE(kd)) {
|
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"cannot read user space from dead kernel");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-11-16 20:31:58 +00:00
|
|
|
if (!buflen) {
|
2000-03-27 00:33:45 +00:00
|
|
|
bufsz = sizeof(buflen);
|
1999-11-16 20:31:58 +00:00
|
|
|
i = sysctlbyname("kern.ps_arg_cache_limit",
|
2000-03-27 00:33:45 +00:00
|
|
|
&buflen, &bufsz, NULL, 0);
|
1999-11-16 20:31:58 +00:00
|
|
|
if (i == -1) {
|
2000-03-27 00:33:45 +00:00
|
|
|
buflen = 0;
|
1999-11-16 20:31:58 +00:00
|
|
|
} else {
|
|
|
|
buf = malloc(buflen);
|
|
|
|
if (buf == NULL)
|
|
|
|
buflen = 0;
|
|
|
|
argc = 32;
|
|
|
|
bufp = malloc(sizeof(char *) * argc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (buf != NULL) {
|
|
|
|
oid[0] = CTL_KERN;
|
|
|
|
oid[1] = KERN_PROC;
|
|
|
|
oid[2] = KERN_PROC_ARGS;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
oid[3] = kp->ki_pid;
|
2000-03-27 00:33:45 +00:00
|
|
|
bufsz = buflen;
|
|
|
|
i = sysctl(oid, 4, buf, &bufsz, 0, 0);
|
|
|
|
if (i == 0 && bufsz > 0) {
|
1999-11-16 20:31:58 +00:00
|
|
|
i = 0;
|
|
|
|
p = buf;
|
|
|
|
do {
|
|
|
|
bufp[i++] = p;
|
|
|
|
p += strlen(p) + 1;
|
|
|
|
if (i >= argc) {
|
|
|
|
argc += argc;
|
|
|
|
bufp = realloc(bufp,
|
|
|
|
sizeof(char *) * argc);
|
|
|
|
}
|
2000-03-27 00:33:45 +00:00
|
|
|
} while (p < buf + bufsz);
|
1999-11-16 20:31:58 +00:00
|
|
|
bufp[i++] = 0;
|
|
|
|
return (bufp);
|
|
|
|
}
|
|
|
|
}
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (kp->ki_flag & P_SYSTEM)
|
1999-11-16 20:31:58 +00:00
|
|
|
return (NULL);
|
1994-05-27 05:00:24 +00:00
|
|
|
return (kvm_doargv(kd, kp, nchr, ps_str_a));
|
|
|
|
}
|
|
|
|
|
|
|
|
char **
|
|
|
|
kvm_getenvv(kd, kp, nchr)
|
|
|
|
kvm_t *kd;
|
|
|
|
const struct kinfo_proc *kp;
|
|
|
|
int nchr;
|
|
|
|
{
|
|
|
|
return (kvm_doargv(kd, kp, nchr, ps_str_e));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read from user space. The user context is given by p.
|
|
|
|
*/
|
|
|
|
ssize_t
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
kvm_uread(kd, kp, uva, buf, len)
|
1994-05-27 05:00:24 +00:00
|
|
|
kvm_t *kd;
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
struct kinfo_proc *kp;
|
1994-05-27 05:00:24 +00:00
|
|
|
register u_long uva;
|
|
|
|
register char *buf;
|
|
|
|
register size_t len;
|
|
|
|
{
|
|
|
|
register char *cp;
|
1994-08-11 13:38:23 +00:00
|
|
|
char procfile[MAXPATHLEN];
|
|
|
|
ssize_t amount;
|
|
|
|
int fd;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
1996-02-24 14:37:30 +00:00
|
|
|
if (!ISALIVE(kd)) {
|
1998-01-16 16:45:05 +00:00
|
|
|
_kvm_err(kd, kd->program,
|
|
|
|
"cannot read user space from dead kernel");
|
|
|
|
return (0);
|
1996-02-24 14:37:30 +00:00
|
|
|
}
|
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
sprintf(procfile, "/proc/%d/mem", kp->ki_pid);
|
1994-08-11 13:38:23 +00:00
|
|
|
fd = open(procfile, O_RDONLY, 0);
|
|
|
|
if (fd < 0) {
|
|
|
|
_kvm_err(kd, kd->program, "cannot open %s", procfile);
|
|
|
|
close(fd);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-01-16 16:45:05 +00:00
|
|
|
cp = buf;
|
1994-05-27 05:00:24 +00:00
|
|
|
while (len > 0) {
|
1998-01-16 16:45:05 +00:00
|
|
|
errno = 0;
|
1995-03-19 13:33:05 +00:00
|
|
|
if (lseek(fd, (off_t)uva, 0) == -1 && errno != 0) {
|
1998-01-16 16:45:05 +00:00
|
|
|
_kvm_err(kd, kd->program, "invalid address (%x) in %s",
|
|
|
|
uva, procfile);
|
1994-08-11 13:38:23 +00:00
|
|
|
break;
|
|
|
|
}
|
1994-11-02 16:38:51 +00:00
|
|
|
amount = read(fd, cp, len);
|
1994-08-11 13:38:23 +00:00
|
|
|
if (amount < 0) {
|
1998-01-16 16:45:05 +00:00
|
|
|
_kvm_syserr(kd, kd->program, "error reading %s",
|
|
|
|
procfile);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (amount == 0) {
|
|
|
|
_kvm_err(kd, kd->program, "EOF reading %s", procfile);
|
1994-05-27 05:00:24 +00:00
|
|
|
break;
|
1994-08-11 13:38:23 +00:00
|
|
|
}
|
|
|
|
cp += amount;
|
|
|
|
uva += amount;
|
|
|
|
len -= amount;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
1994-08-11 13:38:23 +00:00
|
|
|
|
|
|
|
close(fd);
|
1998-01-16 16:45:05 +00:00
|
|
|
return ((ssize_t)(cp - buf));
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|