summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_proc.c
diff options
context:
space:
mode:
authortrociny <trociny@FreeBSD.org>2011-11-27 17:05:26 +0000
committertrociny <trociny@FreeBSD.org>2011-11-27 17:05:26 +0000
commita95ae73e491d638c5ce6606f81e8a9ec30059dc5 (patch)
treed363d3d7bbda6c9f2a525d2baa16b1ac12722e70 /sys/kern/kern_proc.c
parentc4d555a3170897e61aee7f924742bf2e4e05bffb (diff)
downloadFreeBSD-src-a95ae73e491d638c5ce6606f81e8a9ec30059dc5.zip
FreeBSD-src-a95ae73e491d638c5ce6606f81e8a9ec30059dc5.tar.gz
Add sysctl to retrieve ps_strings structure location of another process.
Suggested by: kib Reviewed by: kib
Diffstat (limited to 'sys/kern/kern_proc.c')
-rw-r--r--sys/kern/kern_proc.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index c54908e..0edcc25 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -2434,6 +2434,59 @@ sysctl_kern_proc_rlimit(SYSCTL_HANDLER_ARGS)
return (error);
}
+/*
+ * This sysctl allows a process to retrieve ps_strings structure location of
+ * another process.
+ */
+static int
+sysctl_kern_proc_ps_strings(SYSCTL_HANDLER_ARGS)
+{
+ int *name = (int*) arg1;
+ u_int namelen = arg2;
+ struct proc *p;
+ vm_offset_t ps_strings;
+ int error;
+#ifdef COMPAT_FREEBSD32
+ uint32_t ps_strings32;
+#endif
+
+ if (namelen != 1)
+ return (EINVAL);
+
+ p = pfind((pid_t)name[0]);
+ if (p == NULL)
+ return (ESRCH);
+ if (p->p_flag & P_WEXIT) {
+ PROC_UNLOCK(p);
+ return (ESRCH);
+ }
+ if ((error = p_cansee(curthread, p)) != 0) {
+ PROC_UNLOCK(p);
+ return (error);
+ }
+ if ((p->p_flag & P_SYSTEM) != 0) {
+ PROC_UNLOCK(p);
+ return (0);
+ }
+#ifdef COMPAT_FREEBSD32
+ if ((req->flags & SCTL_MASK32) != 0) {
+ /*
+ * We return 0 if the 32 bit emulation request is for a 64 bit
+ * process.
+ */
+ ps_strings32 = SV_PROC_FLAG(p, SV_ILP32) != 0 ?
+ PTROUT(p->p_sysent->sv_psstrings) : 0;
+ PROC_UNLOCK(p);
+ error = SYSCTL_OUT(req, &ps_strings32, sizeof(ps_strings32));
+ return (error);
+ }
+#endif
+ ps_strings = p->p_sysent->sv_psstrings;
+ PROC_UNLOCK(p);
+ error = SYSCTL_OUT(req, &ps_strings, sizeof(ps_strings));
+ return (error);
+}
+
SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD, 0, "Process table");
SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all, CTLFLAG_RD|CTLTYPE_STRUCT|
@@ -2532,3 +2585,7 @@ static SYSCTL_NODE(_kern_proc, KERN_PROC_GROUPS, groups, CTLFLAG_RD |
static SYSCTL_NODE(_kern_proc, KERN_PROC_RLIMIT, rlimit, CTLFLAG_RD |
CTLFLAG_MPSAFE, sysctl_kern_proc_rlimit, "Process resource limits");
+
+static SYSCTL_NODE(_kern_proc, KERN_PROC_PS_STRINGS, ps_strings,
+ CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE,
+ sysctl_kern_proc_ps_strings, "Process ps_strings location");
OpenPOWER on IntegriCloud