summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2000-12-12 07:25:57 +0000
committermckusick <mckusick@FreeBSD.org>2000-12-12 07:25:57 +0000
commitcba301121bc106aaff382428a55f31fef30844e6 (patch)
tree910e5652e5d16d5d0d4e8480f7e386aaf0ca310e /sys
parentd577ae457b219ac16b4e152a40ae4d7474c4622f (diff)
downloadFreeBSD-src-cba301121bc106aaff382428a55f31fef30844e6.zip
FreeBSD-src-cba301121bc106aaff382428a55f31fef30844e6.tar.gz
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/imgact_aout.c3
-rw-r--r--sys/kern/kern_proc.c152
-rw-r--r--sys/kern/sys_process.c8
-rw-r--r--sys/sys/user.h114
4 files changed, 192 insertions, 85 deletions
diff --git a/sys/kern/imgact_aout.c b/sys/kern/imgact_aout.c
index e27a80c..6e0edde 100644
--- a/sys/kern/imgact_aout.c
+++ b/sys/kern/imgact_aout.c
@@ -254,8 +254,7 @@ aout_coredump(p, vp, limit)
if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >= limit)
return (EFAULT);
- bcopy(p, &p->p_addr->u_kproc.kp_proc, sizeof(struct proc));
- fill_eproc(p, &p->p_addr->u_kproc.kp_eproc);
+ fill_kinfo_proc(p, &p->p_addr->u_kproc);
error = cpu_coredump(p, vp, cred);
if (error == 0)
error = vn_rdwr(UIO_WRITE, vp, vm->vm_daddr,
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 4c66e50..793c068 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -90,6 +90,13 @@ procinit()
pgrphashtbl = hashinit(maxproc / 4, M_PROC, &pgrphash);
proc_zone = zinit("PROC", sizeof (struct proc), 0, 0, 5);
uihashinit();
+ /*
+ * This should really be a compile time warning, but I do
+ * not know of any way to do that...
+ */
+ if (sizeof(struct kinfo_proc) != KINFO_PROC_SIZE)
+ printf("WARNING: size of kinfo_proc (%d) should be %d!!!\n",
+ sizeof(struct kinfo_proc), KINFO_PROC_SIZE);
}
/*
@@ -352,64 +359,118 @@ DB_SHOW_COMMAND(pgrpdump, pgrpdump)
#endif /* DDB */
/*
- * Fill in an eproc structure for the specified process.
+ * Fill in an kinfo_proc structure for the specified process.
*/
void
-fill_eproc(p, ep)
- register struct proc *p;
- register struct eproc *ep;
+fill_kinfo_proc(p, kp)
+ struct proc *p;
+ struct kinfo_proc *kp;
{
- register struct tty *tp;
-
- bzero(ep, sizeof(*ep));
-
- ep->e_paddr = p;
+ struct tty *tp;
+ struct session *sp;
+
+ bzero(kp, sizeof(*kp));
+
+ kp->ki_structsize = sizeof(*kp);
+ kp->ki_paddr = p;
+ kp->ki_addr = p->p_addr;
+ kp->ki_args = p->p_args;
+ kp->ki_tracep = p->p_tracep;
+ kp->ki_textvp = p->p_textvp;
+ kp->ki_fd = p->p_fd;
+ kp->ki_vmspace = p->p_vmspace;
if (p->p_cred) {
- ep->e_pcred = *p->p_cred;
- if (p->p_ucred)
- ep->e_ucred = *p->p_ucred;
+ kp->ki_uid = p->p_cred->pc_ucred->cr_uid;
+ kp->ki_ruid = p->p_cred->p_ruid;
+ kp->ki_svuid = p->p_cred->p_svuid;
+ kp->ki_ngroups = p->p_cred->pc_ucred->cr_ngroups;
+ bcopy(p->p_cred->pc_ucred->cr_groups, kp->ki_groups,
+ NGROUPS * sizeof(gid_t));
+ kp->ki_rgid = p->p_cred->p_rgid;
+ kp->ki_svgid = p->p_cred->p_svgid;
}
if (p->p_procsig) {
- ep->e_procsig = *p->p_procsig;
+ kp->ki_sigignore = p->p_procsig->ps_sigignore;
+ kp->ki_sigcatch = p->p_procsig->ps_sigcatch;
}
if (p->p_stat != SIDL && p->p_stat != SZOMB && p->p_vmspace != NULL) {
- register struct vmspace *vm = p->p_vmspace;
- ep->e_vm = *vm;
- ep->e_vm.vm_rssize = vmspace_resident_count(vm); /*XXX*/
+ struct vmspace *vm = p->p_vmspace;
+
+ kp->ki_size = vm->vm_map.size;
+ kp->ki_rssize = vmspace_resident_count(vm); /*XXX*/
+ kp->ki_swrss = vm->vm_swrss;
+ kp->ki_tsize = vm->vm_tsize;
+ kp->ki_dsize = vm->vm_dsize;
+ kp->ki_ssize = vm->vm_ssize;
+ }
+ if ((p->p_flag & P_INMEM) && p->p_stats) {
+ kp->ki_start = p->p_stats->p_start;
+ kp->ki_rusage = p->p_stats->p_ru;
+ kp->ki_childtime.tv_sec = p->p_stats->p_cru.ru_utime.tv_sec +
+ p->p_stats->p_cru.ru_stime.tv_sec;
+ kp->ki_childtime.tv_usec = p->p_stats->p_cru.ru_utime.tv_usec +
+ p->p_stats->p_cru.ru_stime.tv_usec;
}
- if ((p->p_flag & P_INMEM) && p->p_stats)
- ep->e_stats = *p->p_stats;
+ kp->ki_rtprio = p->p_rtprio;
+ kp->ki_runtime = p->p_runtime;
+ kp->ki_pid = p->p_pid;
if (p->p_pptr)
- ep->e_ppid = p->p_pptr->p_pid;
+ kp->ki_ppid = p->p_pptr->p_pid;
+ sp = NULL;
if (p->p_pgrp) {
- ep->e_pgid = p->p_pgrp->pg_id;
- ep->e_jobc = p->p_pgrp->pg_jobc;
- ep->e_sess = p->p_pgrp->pg_session;
-
- if (ep->e_sess) {
- bcopy(ep->e_sess->s_login, ep->e_login, sizeof(ep->e_login));
- if (ep->e_sess->s_ttyvp)
- ep->e_flag = EPROC_CTTY;
- if (p->p_session && SESS_LEADER(p))
- ep->e_flag |= EPROC_SLEADER;
+ kp->ki_pgid = p->p_pgrp->pg_id;
+ kp->ki_jobc = p->p_pgrp->pg_jobc;
+ sp = p->p_pgrp->pg_session;
+
+ if (sp != NULL) {
+ kp->ki_sid = sp->s_sid;
+ bcopy(sp->s_login, kp->ki_login, sizeof(kp->ki_login));
+ if (sp->s_ttyvp)
+ kp->ki_kiflag = KI_CTTY;
+ if (SESS_LEADER(p))
+ kp->ki_kiflag |= KI_SLEADER;
}
}
- if ((p->p_flag & P_CONTROLT) &&
- (ep->e_sess != NULL) &&
- ((tp = ep->e_sess->s_ttyp) != NULL)) {
- ep->e_tdev = dev2udev(tp->t_dev);
- ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
- ep->e_tsess = tp->t_session;
+ if ((p->p_flag & P_CONTROLT) && sp && ((tp = sp->s_ttyp) != NULL)) {
+ kp->ki_tdev = dev2udev(tp->t_dev);
+ kp->ki_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
+ if (tp->t_session)
+ kp->ki_tsid = tp->t_session->s_sid;
} else
- ep->e_tdev = NOUDEV;
+ kp->ki_tdev = NOUDEV;
if (p->p_wmesg) {
- strncpy(ep->e_wmesg, p->p_wmesg, WMESGLEN);
- ep->e_wmesg[WMESGLEN] = 0;
+ strncpy(kp->ki_wmesg, p->p_wmesg, WMESGLEN);
+ kp->ki_wmesg[WMESGLEN] = 0;
+ }
+ if (p->p_comm[0] != 0) {
+ strncpy(kp->ki_comm, p->p_comm, MAXCOMLEN);
+ kp->ki_comm[MAXCOMLEN] = 0;
}
- if (p->p_mtxname) {
- strncpy(ep->e_mtxname, p->p_mtxname, MTXNAMELEN);
- ep->e_mtxname[MTXNAMELEN] = 0;
+ if (p->p_blocked != 0) {
+ kp->ki_kiflag |= KI_MTXBLOCK;
+ strncpy(kp->ki_mtxname, p->p_mtxname, MTXNAMELEN);
+ kp->ki_wmesg[MTXNAMELEN] = 0;
}
+ kp->ki_siglist = p->p_siglist;
+ kp->ki_sigmask = p->p_sigmask;
+ kp->ki_xstat = p->p_xstat;
+ kp->ki_acflag = p->p_acflag;
+ kp->ki_pctcpu = p->p_pctcpu;
+ kp->ki_estcpu = p->p_estcpu;
+ kp->ki_slptime = p->p_slptime;
+ kp->ki_swtime = p->p_swtime;
+ kp->ki_flag = p->p_flag;
+ kp->ki_wchan = p->p_wchan;
+ kp->ki_traceflag = p->p_traceflag;
+ kp->ki_priority = p->p_priority;
+ kp->ki_usrpri = p->p_usrpri;
+ kp->ki_nativepri = p->p_nativepri;
+ kp->ki_stat = p->p_stat;
+ kp->ki_nice = p->p_nice;
+ kp->ki_lock = p->p_lock;
+ kp->ki_rqindex = p->p_rqindex;
+ kp->ki_oncpu = p->p_oncpu;
+ kp->ki_lastcpu = p->p_lastcpu;
}
static struct proc *
@@ -427,15 +488,12 @@ zpfind(pid_t pid)
static int
sysctl_out_proc(struct proc *p, struct sysctl_req *req, int doingzomb)
{
- struct eproc eproc;
+ struct kinfo_proc kinfo_proc;
int error;
pid_t pid = p->p_pid;
- fill_eproc(p, &eproc);
- error = SYSCTL_OUT(req,(caddr_t)p, sizeof(struct proc));
- if (error)
- return (error);
- error = SYSCTL_OUT(req,(caddr_t)&eproc, sizeof(eproc));
+ fill_kinfo_proc(p, &kinfo_proc);
+ error = SYSCTL_OUT(req, (caddr_t)&kinfo_proc, sizeof(kinfo_proc));
if (error)
return (error);
if (!doingzomb && pid && (pfind(pid) != p))
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index c9abad4..5bdeb78 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -339,7 +339,7 @@ ptrace(curp, uap)
}
if (uap->addr != (caddr_t)1) {
- fill_eproc (p, &p->p_addr->u_kproc.kp_eproc);
+ fill_kinfo_proc (p, &p->p_addr->u_kproc);
if ((error = ptrace_set_pc (p,
(u_long)(uintfptr_t)uap->addr))) {
PRELE(p);
@@ -428,8 +428,7 @@ ptrace(curp, uap)
error = 0;
PHOLD(p); /* user had damn well better be incore! */
if (p->p_flag & P_INMEM) {
- p->p_addr->u_kproc.kp_proc = *p;
- fill_eproc (p, &p->p_addr->u_kproc.kp_eproc);
+ fill_kinfo_proc (p, &p->p_addr->u_kproc);
curp->p_retval[0] = *(int *)
((uintptr_t)p->p_addr + (uintptr_t)uap->addr);
} else {
@@ -442,8 +441,7 @@ ptrace(curp, uap)
case PT_WRITE_U:
PHOLD(p); /* user had damn well better be incore! */
if (p->p_flag & P_INMEM) {
- p->p_addr->u_kproc.kp_proc = *p;
- fill_eproc (p, &p->p_addr->u_kproc.kp_eproc);
+ fill_kinfo_proc (p, &p->p_addr->u_kproc);
error = ptrace_write_u(p, (vm_offset_t)uap->addr, uap->data);
} else {
error = EFAULT;
diff --git a/sys/sys/user.h b/sys/sys/user.h
index fd5924a..e2ce5f8 100644
--- a/sys/sys/user.h
+++ b/sys/sys/user.h
@@ -60,41 +60,93 @@
#endif
/*
- * KERN_PROC subtype ops return arrays of augmented proc structures:
+ * KERN_PROC subtype ops return arrays of selected proc structure entries:
+ *
+ * When adding new fields to this structure, ALWAYS add them at the end
+ * and decrease the size of the spare field by the amount of space that
+ * you are adding. Byte aligned data should be added to the ki_sparestring
+ * space; other entries should be added to the ki_spare space. Always
+ * verify that sizeof(struct kinfo_proc) == KINFO_PROC_SIZE when you are
+ * done. If you change the size of this structure, many programs will stop
+ * working! Once you have added the new field, you will need to add code
+ * to initialize it in two places: kern/kern_proc.c in the function
+ * fill_kinfo_proc and in lib/libkvm/kvm_proc.c in the function kvm_proclist.
*/
+#define KINFO_PROC_SIZE 640 /* the correct size for kinfo_proc */
+#define WMESGLEN 8 /* size of returned wchan message */
+#define MTXNAMELEN 8 /* size of returned mutex name */
+
struct kinfo_proc {
- struct proc kp_proc; /* proc structure */
- struct eproc {
- struct proc *e_paddr; /* address of proc */
- struct session *e_sess; /* session pointer */
- struct pcred e_pcred; /* process credentials */
- struct ucred e_ucred; /* current credentials */
- struct procsig e_procsig; /* shared signal structure */
- struct vmspace e_vm; /* address space */
- struct pstats e_stats; /* process stats */
- pid_t e_ppid; /* parent process id */
- pid_t e_pgid; /* process group id */
- short e_jobc; /* job control counter */
- udev_t e_tdev; /* controlling tty dev */
- pid_t e_tpgid; /* tty process group id */
- struct session *e_tsess; /* tty session pointer */
-#define WMESGLEN 7
- char e_wmesg[WMESGLEN+1]; /* wchan message */
-#define MTXNAMELEN 7
- char e_mtxname[MTXNAMELEN+1];/* blocked mutex */
- segsz_t e_xsize; /* text size */
- short e_xrssize; /* text rss */
- short e_xccount; /* text references */
- short e_xswrss;
- long e_flag;
-#define EPROC_CTTY 0x01 /* controlling tty vnode active */
-#define EPROC_SLEADER 0x02 /* session leader */
- char e_login[roundup(MAXLOGNAME, sizeof(long))]; /* setlogin() name */
- long e_spare[2];
- } kp_eproc;
+ int ki_structsize; /* size of this structure */
+ struct pargs *ki_args; /* address of command arguments */
+ struct proc *ki_paddr; /* address of proc */
+ struct user *ki_addr; /* kernel virtual addr of u-area */
+ struct vnode *ki_tracep; /* pointer to trace file */
+ struct vnode *ki_textvp; /* pointer to executable file */
+ struct filedesc *ki_fd; /* pointer to open file info */
+ struct vmspace *ki_vmspace; /* pointer to kernel vmspace struct */
+ void *ki_wchan; /* sleep address */
+ pid_t ki_pid; /* Process identifier */
+ pid_t ki_ppid; /* parent process id */
+ pid_t ki_pgid; /* process group id */
+ pid_t ki_tpgid; /* tty process group id */
+ pid_t ki_sid; /* Process session ID */
+ pid_t ki_tsid; /* Terminal session ID */
+ short ki_jobc; /* job control counter */
+ udev_t ki_tdev; /* controlling tty dev */
+ sigset_t ki_siglist; /* Signals arrived but not delivered */
+ sigset_t ki_sigmask; /* Current signal mask */
+ sigset_t ki_sigignore; /* Signals being ignored */
+ sigset_t ki_sigcatch; /* Signals being caught by user */
+ uid_t ki_uid; /* effective user id */
+ uid_t ki_ruid; /* Real user id */
+ uid_t ki_svuid; /* Saved effective user id */
+ gid_t ki_rgid; /* Real group id */
+ gid_t ki_svgid; /* Saved effective group id */
+ short ki_ngroups; /* number of groups */
+ gid_t ki_groups[NGROUPS]; /* groups */
+ vm_size_t ki_size; /* virtual size */
+ segsz_t ki_rssize; /* current resident set size in pages */
+ segsz_t ki_swrss; /* resident set size before last swap */
+ segsz_t ki_tsize; /* text size (pages) XXX */
+ segsz_t ki_dsize; /* data size (pages) XXX */
+ segsz_t ki_ssize; /* stack size (pages) */
+ u_short ki_xstat; /* Exit status for wait & stop signal */
+ u_short ki_acflag; /* Accounting flags */
+ fixpt_t ki_pctcpu; /* %cpu for process during ki_swtime */
+ u_int ki_estcpu; /* Time averaged value of ki_cpticks */
+ u_int ki_slptime; /* Time since last blocked */
+ u_int ki_swtime; /* Time swapped in or out */
+ u_int64_t ki_runtime; /* Real time in microsec */
+ struct timeval ki_start; /* starting time */
+ struct timeval ki_childtime; /* time used by process children */
+ long ki_flag; /* P_* flags */
+ long ki_kiflag; /* KI_* flags (below) */
+ int ki_traceflag; /* Kernel trace points */
+ u_char ki_priority; /* Process priority */
+ u_char ki_usrpri; /* User-priority based on p_cpu */
+ u_char ki_nativepri; /* Priority before propogation */
+ char ki_stat; /* S* process status */
+ char ki_nice; /* Process "nice" value */
+ char ki_lock; /* Process lock (prevent swap) count */
+ char ki_rqindex; /* Run queue index */
+ u_char ki_oncpu; /* Which cpu we are on */
+ u_char ki_lastcpu; /* Last cpu we were on */
+ char ki_comm[MAXCOMLEN+1]; /* command name */
+ char ki_wmesg[WMESGLEN+1]; /* wchan message */
+ char ki_login[MAXLOGNAME+1]; /* setlogin name */
+ char ki_mtxname[MTXNAMELEN+1]; /* mutex name */
+ char ki_sparestrings[102]; /* spare string space */
+ struct rtprio ki_rtprio; /* Realtime priority */
+ struct rusage ki_rusage; /* process rusage statistics */
+ long ki_spare[25]; /* spare constants */
};
-void fill_eproc __P((struct proc *, struct eproc *));
+void fill_kinfo_proc __P((struct proc *, struct kinfo_proc *));
+/* ki_sessflag values */
+#define KI_CTTY 0x00000001 /* controlling tty vnode active */
+#define KI_SLEADER 0x00000002 /* session leader */
+#define KI_MTXBLOCK 0x00000004 /* proc blocked on mutex ki_mtxname */
/*
* Per process structure containing data that isn't needed in core
OpenPOWER on IntegriCloud