svn commit: r228030 - head/sys/kern
Mikolaj Golub
trociny at FreeBSD.org
Sun Nov 27 17:05:27 UTC 2011
Author: trociny
Date: Sun Nov 27 17:05:26 2011
New Revision: 228030
URL: http://svn.freebsd.org/changeset/base/228030
Log:
Add sysctl to retrieve ps_strings structure location of another process.
Suggested by: kib
Reviewed by: kib
Modified:
head/sys/kern/kern_proc.c
Modified: head/sys/kern/kern_proc.c
==============================================================================
--- head/sys/kern/kern_proc.c Sun Nov 27 16:56:01 2011 (r228029)
+++ head/sys/kern/kern_proc.c Sun Nov 27 17:05:26 2011 (r228030)
@@ -2434,6 +2434,59 @@ sysctl_kern_proc_rlimit(SYSCTL_HANDLER_A
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
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");
More information about the svn-src-head
mailing list