2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California.
4 * Copyright (c) 2005 Robert N. M. Watson
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 4. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)kern_ktrace.c 8.2 (Berkeley) 9/23/93
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include "opt_ktrace.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/fcntl.h>
43 #include <sys/kernel.h>
44 #include <sys/kthread.h>
46 #include <sys/mutex.h>
48 #include <sys/malloc.h>
49 #include <sys/namei.h>
51 #include <sys/unistd.h>
52 #include <sys/vnode.h>
53 #include <sys/ktrace.h>
55 #include <sys/sysctl.h>
56 #include <sys/syslog.h>
57 #include <sys/sysproto.h>
60 * The ktrace facility allows the tracing of certain key events in user space
61 * processes, such as system calls, signal delivery, context switches, and
62 * user generated events using utrace(2). It works by streaming event
63 * records and data to a vnode associated with the process using the
64 * ktrace(2) system call. In general, records can be written directly from
65 * the context that generates the event. One important exception to this is
66 * during a context switch, where sleeping is not permitted. To handle this
67 * case, trace events are generated using in-kernel ktr_request records, and
68 * then delivered to disk at a convenient moment -- either immediately, the
69 * next traceable event, at system call return, or at process exit.
71 * When dealing with multiple threads or processes writing to the same event
72 * log, ordering guarantees are weak: specifically, if an event has multiple
73 * records (i.e., system call enter and return), they may be interlaced with
74 * records from another event. Process and thread ID information is provided
75 * in the record, and user applications can de-interlace events if required.
78 static MALLOC_DEFINE(M_KTRACE, "KTRACE", "KTRACE");
82 #ifndef KTRACE_REQUEST_POOL
83 #define KTRACE_REQUEST_POOL 100
87 struct ktr_header ktr_header;
90 struct ktr_syscall ktr_syscall;
91 struct ktr_sysret ktr_sysret;
92 struct ktr_genio ktr_genio;
93 struct ktr_psig ktr_psig;
94 struct ktr_csw ktr_csw;
96 STAILQ_ENTRY(ktr_request) ktr_list;
99 static int data_lengths[] = {
101 offsetof(struct ktr_syscall, ktr_args), /* KTR_SYSCALL */
102 sizeof(struct ktr_sysret), /* KTR_SYSRET */
104 sizeof(struct ktr_genio), /* KTR_GENIO */
105 sizeof(struct ktr_psig), /* KTR_PSIG */
106 sizeof(struct ktr_csw), /* KTR_CSW */
110 static STAILQ_HEAD(, ktr_request) ktr_free;
112 static SYSCTL_NODE(_kern, OID_AUTO, ktrace, CTLFLAG_RD, 0, "KTRACE options");
114 static u_int ktr_requestpool = KTRACE_REQUEST_POOL;
115 TUNABLE_INT("kern.ktrace.request_pool", &ktr_requestpool);
117 static u_int ktr_geniosize = PAGE_SIZE;
118 TUNABLE_INT("kern.ktrace.genio_size", &ktr_geniosize);
119 SYSCTL_UINT(_kern_ktrace, OID_AUTO, genio_size, CTLFLAG_RW, &ktr_geniosize,
120 0, "Maximum size of genio event payload");
122 static int print_message = 1;
123 struct mtx ktrace_mtx;
124 static struct cv ktrace_cv;
125 static struct sx ktrace_sx;
127 static void ktrace_init(void *dummy);
128 static int sysctl_kern_ktrace_request_pool(SYSCTL_HANDLER_ARGS);
129 static u_int ktrace_resize_pool(u_int newsize);
130 static struct ktr_request *ktr_getrequest(int type);
131 static void ktr_submitrequest(struct thread *td, struct ktr_request *req);
132 static void ktr_freerequest(struct ktr_request *req);
133 static void ktr_writerequest(struct thread *td, struct ktr_request *req);
134 static int ktrcanset(struct thread *,struct proc *);
135 static int ktrsetchildren(struct thread *,struct proc *,int,int,struct vnode *);
136 static int ktrops(struct thread *,struct proc *,int,int,struct vnode *);
139 * ktrace itself generates events, such as context switches, which we do not
140 * wish to trace. Maintain a flag, TDP_INKTRACE, on each thread to determine
141 * whether or not it is in a region where tracing of events should be
145 ktrace_enter(struct thread *td)
148 KASSERT(!(td->td_pflags & TDP_INKTRACE), ("ktrace_enter: flag set"));
149 td->td_pflags |= TDP_INKTRACE;
153 ktrace_exit(struct thread *td)
156 KASSERT(td->td_pflags & TDP_INKTRACE, ("ktrace_exit: flag not set"));
157 td->td_pflags &= ~TDP_INKTRACE;
161 ktrace_assert(struct thread *td)
164 KASSERT(td->td_pflags & TDP_INKTRACE, ("ktrace_assert: flag not set"));
168 ktrace_init(void *dummy)
170 struct ktr_request *req;
173 mtx_init(&ktrace_mtx, "ktrace", NULL, MTX_DEF | MTX_QUIET);
174 sx_init(&ktrace_sx, "ktrace_sx");
175 cv_init(&ktrace_cv, "ktrace");
176 STAILQ_INIT(&ktr_free);
177 for (i = 0; i < ktr_requestpool; i++) {
178 req = malloc(sizeof(struct ktr_request), M_KTRACE, M_WAITOK);
179 STAILQ_INSERT_HEAD(&ktr_free, req, ktr_list);
182 SYSINIT(ktrace_init, SI_SUB_KTRACE, SI_ORDER_ANY, ktrace_init, NULL);
185 sysctl_kern_ktrace_request_pool(SYSCTL_HANDLER_ARGS)
188 u_int newsize, oldsize, wantsize;
191 /* Handle easy read-only case first to avoid warnings from GCC. */
193 mtx_lock(&ktrace_mtx);
194 oldsize = ktr_requestpool;
195 mtx_unlock(&ktrace_mtx);
196 return (SYSCTL_OUT(req, &oldsize, sizeof(u_int)));
199 error = SYSCTL_IN(req, &wantsize, sizeof(u_int));
204 mtx_lock(&ktrace_mtx);
205 oldsize = ktr_requestpool;
206 newsize = ktrace_resize_pool(wantsize);
207 mtx_unlock(&ktrace_mtx);
209 error = SYSCTL_OUT(req, &oldsize, sizeof(u_int));
212 if (wantsize > oldsize && newsize < wantsize)
216 SYSCTL_PROC(_kern_ktrace, OID_AUTO, request_pool, CTLTYPE_UINT|CTLFLAG_RW,
217 &ktr_requestpool, 0, sysctl_kern_ktrace_request_pool, "IU", "");
220 ktrace_resize_pool(u_int newsize)
222 struct ktr_request *req;
225 mtx_assert(&ktrace_mtx, MA_OWNED);
227 bound = newsize - ktr_requestpool;
229 return (ktr_requestpool);
231 /* Shrink pool down to newsize if possible. */
232 while (bound++ < 0) {
233 req = STAILQ_FIRST(&ktr_free);
235 return (ktr_requestpool);
236 STAILQ_REMOVE_HEAD(&ktr_free, ktr_list);
238 mtx_unlock(&ktrace_mtx);
240 mtx_lock(&ktrace_mtx);
243 /* Grow pool up to newsize. */
244 while (bound-- > 0) {
245 mtx_unlock(&ktrace_mtx);
246 req = malloc(sizeof(struct ktr_request), M_KTRACE,
248 mtx_lock(&ktrace_mtx);
249 STAILQ_INSERT_HEAD(&ktr_free, req, ktr_list);
252 return (ktr_requestpool);
255 static struct ktr_request *
256 ktr_getrequest(int type)
258 struct ktr_request *req;
259 struct thread *td = curthread;
260 struct proc *p = td->td_proc;
263 ktrace_enter(td); /* XXX: In caller instead? */
264 mtx_lock(&ktrace_mtx);
265 if (!KTRCHECK(td, type)) {
266 mtx_unlock(&ktrace_mtx);
270 req = STAILQ_FIRST(&ktr_free);
272 STAILQ_REMOVE_HEAD(&ktr_free, ktr_list);
273 req->ktr_header.ktr_type = type;
274 if (p->p_traceflag & KTRFAC_DROP) {
275 req->ktr_header.ktr_type |= KTR_DROP;
276 p->p_traceflag &= ~KTRFAC_DROP;
278 mtx_unlock(&ktrace_mtx);
279 microtime(&req->ktr_header.ktr_time);
280 req->ktr_header.ktr_pid = p->p_pid;
281 req->ktr_header.ktr_tid = td->td_tid;
282 bcopy(p->p_comm, req->ktr_header.ktr_comm, MAXCOMLEN + 1);
283 req->ktr_buffer = NULL;
284 req->ktr_header.ktr_len = 0;
286 p->p_traceflag |= KTRFAC_DROP;
289 mtx_unlock(&ktrace_mtx);
291 printf("Out of ktrace request objects.\n");
298 * Some trace generation environments don't permit direct access to VFS,
299 * such as during a context switch where sleeping is not allowed. Under these
300 * circumstances, queue a request to the thread to be written asynchronously
304 ktr_enqueuerequest(struct thread *td, struct ktr_request *req)
307 mtx_lock(&ktrace_mtx);
308 STAILQ_INSERT_TAIL(&td->td_proc->p_ktr, req, ktr_list);
309 mtx_unlock(&ktrace_mtx);
314 * Drain any pending ktrace records from the per-thread queue to disk. This
315 * is used both internally before committing other records, and also on
316 * system call return. We drain all the ones we can find at the time when
317 * drain is requested, but don't keep draining after that as those events
318 * may me approximately "after" the current event.
321 ktr_drain(struct thread *td)
323 struct ktr_request *queued_req;
324 STAILQ_HEAD(, ktr_request) local_queue;
327 sx_assert(&ktrace_sx, SX_XLOCKED);
329 STAILQ_INIT(&local_queue); /* XXXRW: needed? */
331 if (!STAILQ_EMPTY(&td->td_proc->p_ktr)) {
332 mtx_lock(&ktrace_mtx);
333 STAILQ_CONCAT(&local_queue, &td->td_proc->p_ktr);
334 mtx_unlock(&ktrace_mtx);
336 while ((queued_req = STAILQ_FIRST(&local_queue))) {
337 STAILQ_REMOVE_HEAD(&local_queue, ktr_list);
338 ktr_writerequest(td, queued_req);
339 ktr_freerequest(queued_req);
345 * Submit a trace record for immediate commit to disk -- to be used only
346 * where entering VFS is OK. First drain any pending records that may have
347 * been cached in the thread.
350 ktr_submitrequest(struct thread *td, struct ktr_request *req)
355 sx_xlock(&ktrace_sx);
357 ktr_writerequest(td, req);
358 ktr_freerequest(req);
359 sx_xunlock(&ktrace_sx);
365 ktr_freerequest(struct ktr_request *req)
368 if (req->ktr_buffer != NULL)
369 free(req->ktr_buffer, M_KTRACE);
370 mtx_lock(&ktrace_mtx);
371 STAILQ_INSERT_HEAD(&ktr_free, req, ktr_list);
372 mtx_unlock(&ktrace_mtx);
379 ktrsyscall(code, narg, args)
383 struct ktr_request *req;
384 struct ktr_syscall *ktp;
388 buflen = sizeof(register_t) * narg;
390 buf = malloc(buflen, M_KTRACE, M_WAITOK);
391 bcopy(args, buf, buflen);
393 req = ktr_getrequest(KTR_SYSCALL);
399 ktp = &req->ktr_data.ktr_syscall;
400 ktp->ktr_code = code;
401 ktp->ktr_narg = narg;
403 req->ktr_header.ktr_len = buflen;
404 req->ktr_buffer = buf;
406 ktr_submitrequest(curthread, req);
413 ktrsysret(code, error, retval)
417 struct ktr_request *req;
418 struct ktr_sysret *ktp;
420 req = ktr_getrequest(KTR_SYSRET);
423 ktp = &req->ktr_data.ktr_sysret;
424 ktp->ktr_code = code;
425 ktp->ktr_error = error;
426 ktp->ktr_retval = retval; /* what about val2 ? */
427 ktr_submitrequest(curthread, req);
431 * When a process exits, drain per-process asynchronous trace records.
434 ktrprocexit(struct thread *td)
438 sx_xlock(&ktrace_sx);
440 sx_xunlock(&ktrace_sx);
445 * When a thread returns, drain any asynchronous records generated by the
449 ktruserret(struct thread *td)
453 sx_xlock(&ktrace_sx);
455 sx_xunlock(&ktrace_sx);
463 struct ktr_request *req;
467 namelen = strlen(path);
469 buf = malloc(namelen, M_KTRACE, M_WAITOK);
470 bcopy(path, buf, namelen);
472 req = ktr_getrequest(KTR_NAMEI);
479 req->ktr_header.ktr_len = namelen;
480 req->ktr_buffer = buf;
482 ktr_submitrequest(curthread, req);
486 * Since the uio may not stay valid, we can not hand off this request to
487 * the thread and need to process it synchronously. However, we wish to
488 * keep the relative order of records in a trace file correct, so we
489 * do put this request on the queue (if it isn't empty) and then block.
490 * The ktrace thread waks us back up when it is time for this event to
491 * be posted and blocks until we have completed writing out the event
492 * and woken it back up.
495 ktrgenio(fd, rw, uio, error)
501 struct ktr_request *req;
502 struct ktr_genio *ktg;
511 uio->uio_rw = UIO_WRITE;
512 datalen = imin(uio->uio_resid, ktr_geniosize);
513 buf = malloc(datalen, M_KTRACE, M_WAITOK);
514 error = uiomove(buf, datalen, uio);
520 req = ktr_getrequest(KTR_GENIO);
525 ktg = &req->ktr_data.ktr_genio;
528 req->ktr_header.ktr_len = datalen;
529 req->ktr_buffer = buf;
530 ktr_submitrequest(curthread, req);
534 ktrpsig(sig, action, mask, code)
540 struct ktr_request *req;
543 req = ktr_getrequest(KTR_PSIG);
546 kp = &req->ktr_data.ktr_psig;
547 kp->signo = (char)sig;
551 ktr_enqueuerequest(curthread, req);
558 struct ktr_request *req;
561 req = ktr_getrequest(KTR_CSW);
564 kc = &req->ktr_data.ktr_csw;
567 ktr_enqueuerequest(curthread, req);
571 /* Interface and common routines */
578 #ifndef _SYS_SYSPROTO_H_
590 register struct ktrace_args *uap;
593 register struct vnode *vp = NULL;
594 register struct proc *p;
596 int facs = uap->facs & ~KTRFAC_ROOT;
597 int ops = KTROP(uap->ops);
598 int descend = uap->ops & KTRFLAG_DESCEND;
600 int flags, error = 0;
605 * Need something to (un)trace.
607 if (ops != KTROP_CLEARFILE && facs == 0)
611 if (ops != KTROP_CLEAR) {
613 * an operation which requires a file argument.
615 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->fname, td);
616 flags = FREAD | FWRITE | O_NOFOLLOW;
618 error = vn_open(&nd, &flags, 0, -1);
624 NDFREE(&nd, NDF_ONLY_PNBUF);
626 VOP_UNLOCK(vp, 0, td);
627 if (vp->v_type != VREG) {
628 (void) vn_close(vp, FREAD|FWRITE, td->td_ucred, td);
636 * Clear all uses of the tracefile.
638 if (ops == KTROP_CLEARFILE) {
639 sx_slock(&allproc_lock);
640 LIST_FOREACH(p, &allproc, p_list) {
642 if (p->p_tracevp == vp) {
643 if (ktrcanset(td, p)) {
644 mtx_lock(&ktrace_mtx);
645 cred = p->p_tracecred;
646 p->p_tracecred = NULL;
649 mtx_unlock(&ktrace_mtx);
652 (void) vn_close(vp, FREAD|FWRITE,
663 sx_sunlock(&allproc_lock);
669 sx_slock(&proctree_lock);
674 pg = pgfind(-uap->pid);
676 sx_sunlock(&proctree_lock);
681 * ktrops() may call vrele(). Lock pg_members
682 * by the proctree_lock rather than pg_mtx.
686 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
688 if (p_cansee(td, p) != 0) {
695 ret |= ktrsetchildren(td, p, ops, facs, vp);
697 ret |= ktrops(td, p, ops, facs, vp);
700 sx_sunlock(&proctree_lock);
710 sx_sunlock(&proctree_lock);
714 error = p_cansee(td, p);
716 * The slock of the proctree lock will keep this process
717 * from going away, so unlocking the proc here is ok.
721 sx_sunlock(&proctree_lock);
725 ret |= ktrsetchildren(td, p, ops, facs, vp);
727 ret |= ktrops(td, p, ops, facs, vp);
729 sx_sunlock(&proctree_lock);
735 (void) vn_close(vp, FWRITE, td->td_ucred, td);
754 register struct utrace_args *uap;
758 struct ktr_request *req;
762 if (!KTRPOINT(td, KTR_USER))
764 if (uap->len > KTR_USER_MAXLEN)
766 cp = malloc(uap->len, M_KTRACE, M_WAITOK);
767 error = copyin(uap->addr, cp, uap->len);
772 req = ktr_getrequest(KTR_USER);
777 req->ktr_buffer = cp;
778 req->ktr_header.ktr_len = uap->len;
779 ktr_submitrequest(td, req);
788 ktrops(td, p, ops, facs, vp)
794 struct vnode *tracevp = NULL;
795 struct ucred *tracecred = NULL;
798 if (!ktrcanset(td, p)) {
802 mtx_lock(&ktrace_mtx);
803 if (ops == KTROP_SET) {
804 if (p->p_tracevp != vp) {
806 * if trace file already in use, relinquish below
808 tracevp = p->p_tracevp;
812 if (p->p_tracecred != td->td_ucred) {
813 tracecred = p->p_tracecred;
814 p->p_tracecred = crhold(td->td_ucred);
816 p->p_traceflag |= facs;
817 if (td->td_ucred->cr_uid == 0)
818 p->p_traceflag |= KTRFAC_ROOT;
821 if (((p->p_traceflag &= ~facs) & KTRFAC_MASK) == 0) {
822 /* no more tracing */
824 tracevp = p->p_tracevp;
826 tracecred = p->p_tracecred;
827 p->p_tracecred = NULL;
830 mtx_unlock(&ktrace_mtx);
832 if (tracevp != NULL) {
837 if (tracecred != NULL)
844 ktrsetchildren(td, top, ops, facs, vp)
850 register struct proc *p;
851 register int ret = 0;
854 sx_assert(&proctree_lock, SX_LOCKED);
856 ret |= ktrops(td, p, ops, facs, vp);
858 * If this process has children, descend to them next,
859 * otherwise do any siblings, and if done with this level,
860 * follow back up the tree (but not past top).
862 if (!LIST_EMPTY(&p->p_children))
863 p = LIST_FIRST(&p->p_children);
867 if (LIST_NEXT(p, p_sibling)) {
868 p = LIST_NEXT(p, p_sibling);
878 ktr_writerequest(struct thread *td, struct ktr_request *req)
880 struct ktr_header *kth;
885 struct iovec aiov[3];
887 int datalen, buflen, vrele_count;
891 * We hold the vnode and credential for use in I/O in case ktrace is
892 * disabled on the process as we write out the request.
894 * XXXRW: This is not ideal: we could end up performing a write after
895 * the vnode has been closed.
897 mtx_lock(&ktrace_mtx);
898 vp = td->td_proc->p_tracevp;
901 cred = td->td_proc->p_tracecred;
904 mtx_unlock(&ktrace_mtx);
907 * If vp is NULL, the vp has been cleared out from under this
908 * request, so just drop it. Make sure the credential and vnode are
909 * in sync: we should have both or neither.
912 KASSERT(cred == NULL, ("ktr_writerequest: cred != NULL"));
915 KASSERT(cred != NULL, ("ktr_writerequest: cred == NULL"));
917 kth = &req->ktr_header;
918 datalen = data_lengths[(u_short)kth->ktr_type & ~KTR_DROP];
919 buflen = kth->ktr_len;
920 auio.uio_iov = &aiov[0];
922 auio.uio_segflg = UIO_SYSSPACE;
923 auio.uio_rw = UIO_WRITE;
924 aiov[0].iov_base = (caddr_t)kth;
925 aiov[0].iov_len = sizeof(struct ktr_header);
926 auio.uio_resid = sizeof(struct ktr_header);
930 aiov[1].iov_base = (caddr_t)&req->ktr_data;
931 aiov[1].iov_len = datalen;
932 auio.uio_resid += datalen;
934 kth->ktr_len += datalen;
937 KASSERT(req->ktr_buffer != NULL, ("ktrace: nothing to write"));
938 aiov[auio.uio_iovcnt].iov_base = req->ktr_buffer;
939 aiov[auio.uio_iovcnt].iov_len = buflen;
940 auio.uio_resid += buflen;
945 vn_start_write(vp, &mp, V_WAIT);
946 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
947 (void)VOP_LEASE(vp, td, cred, LEASE_WRITE);
949 error = mac_check_vnode_write(cred, NOCRED, vp);
952 error = VOP_WRITE(vp, &auio, IO_UNIT | IO_APPEND, cred);
953 VOP_UNLOCK(vp, 0, td);
954 vn_finished_write(mp);
959 * If error encountered, give up tracing on this vnode. We defer
960 * all the vrele()'s on the vnode until after we are finished walking
961 * the various lists to avoid needlessly holding locks.
963 log(LOG_NOTICE, "ktrace write failed, errno %d, tracing stopped\n",
967 * First, clear this vnode from being used by any processes in the
969 * XXX - If one process gets an EPERM writing to the vnode, should
970 * we really do this? Other processes might have suitable
971 * credentials for the operation.
974 sx_slock(&allproc_lock);
975 LIST_FOREACH(p, &allproc, p_list) {
977 if (p->p_tracevp == vp) {
978 mtx_lock(&ktrace_mtx);
981 cred = p->p_tracecred;
982 p->p_tracecred = NULL;
983 mtx_unlock(&ktrace_mtx);
992 sx_sunlock(&allproc_lock);
995 * We can't clear any pending requests in threads that have cached
996 * them but not yet committed them, as those are per-thread. The
997 * thread will have to clear it itself on system call return.
1000 while (vrele_count-- > 0)
1006 * Return true if caller has permission to set the ktracing state
1007 * of target. Essentially, the target can't possess any
1008 * more permissions than the caller. KTRFAC_ROOT signifies that
1009 * root previously set the tracing status on the target process, and
1010 * so, only root may further change it.
1013 ktrcanset(td, targetp)
1015 struct proc *targetp;
1018 PROC_LOCK_ASSERT(targetp, MA_OWNED);
1019 if (targetp->p_traceflag & KTRFAC_ROOT &&
1020 suser_cred(td->td_ucred, SUSER_ALLOWJAIL))
1023 if (p_candebug(td, targetp) != 0)