19454b2d8SWarner Losh /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 4df8bae1dSRodney W. Grimes * Copyright (c) 1989, 1993 52c255e9dSRobert Watson * The Regents of the University of California. 62c255e9dSRobert Watson * Copyright (c) 2005 Robert N. M. Watson 72c255e9dSRobert Watson * All rights reserved. 8df8bae1dSRodney W. Grimes * 9df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 10df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 11df8bae1dSRodney W. Grimes * are met: 12df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 13df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 14df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 15df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 16df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 1769a28758SEd Maste * 3. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes */ 33df8bae1dSRodney W. Grimes 34677b542eSDavid E. O'Brien #include <sys/cdefs.h> 35db6a20e2SGarrett Wollman #include "opt_ktrace.h" 36df8bae1dSRodney W. Grimes 37df8bae1dSRodney W. Grimes #include <sys/param.h> 384a144410SRobert Watson #include <sys/capsicum.h> 39f23b4c91SGarrett Wollman #include <sys/systm.h> 40ea3fc8e4SJohn Baldwin #include <sys/fcntl.h> 41ea3fc8e4SJohn Baldwin #include <sys/kernel.h> 42ea3fc8e4SJohn Baldwin #include <sys/kthread.h> 43fb919e4dSMark Murray #include <sys/lock.h> 44fb919e4dSMark Murray #include <sys/mutex.h> 45ea3fc8e4SJohn Baldwin #include <sys/malloc.h> 46033eb86eSJeff Roberson #include <sys/mount.h> 47df8bae1dSRodney W. Grimes #include <sys/namei.h> 48acd3428bSRobert Watson #include <sys/priv.h> 49ea3fc8e4SJohn Baldwin #include <sys/proc.h> 5002645b88SKonstantin Belousov #include <sys/resourcevar.h> 51ea3fc8e4SJohn Baldwin #include <sys/unistd.h> 52df8bae1dSRodney W. Grimes #include <sys/vnode.h> 5360e15db9SDag-Erling Smørgrav #include <sys/socket.h> 5460e15db9SDag-Erling Smørgrav #include <sys/stat.h> 55df8bae1dSRodney W. Grimes #include <sys/ktrace.h> 561005a129SJohn Baldwin #include <sys/sx.h> 57ea3fc8e4SJohn Baldwin #include <sys/sysctl.h> 587705d4b2SDmitry Chagin #include <sys/sysent.h> 59df8bae1dSRodney W. Grimes #include <sys/syslog.h> 60ea3fc8e4SJohn Baldwin #include <sys/sysproto.h> 61df8bae1dSRodney W. Grimes 62aed55708SRobert Watson #include <security/mac/mac_framework.h> 63aed55708SRobert Watson 642c255e9dSRobert Watson /* 652c255e9dSRobert Watson * The ktrace facility allows the tracing of certain key events in user space 662c255e9dSRobert Watson * processes, such as system calls, signal delivery, context switches, and 672c255e9dSRobert Watson * user generated events using utrace(2). It works by streaming event 682c255e9dSRobert Watson * records and data to a vnode associated with the process using the 692c255e9dSRobert Watson * ktrace(2) system call. In general, records can be written directly from 702c255e9dSRobert Watson * the context that generates the event. One important exception to this is 712c255e9dSRobert Watson * during a context switch, where sleeping is not permitted. To handle this 722c255e9dSRobert Watson * case, trace events are generated using in-kernel ktr_request records, and 732c255e9dSRobert Watson * then delivered to disk at a convenient moment -- either immediately, the 742c255e9dSRobert Watson * next traceable event, at system call return, or at process exit. 752c255e9dSRobert Watson * 762c255e9dSRobert Watson * When dealing with multiple threads or processes writing to the same event 772c255e9dSRobert Watson * log, ordering guarantees are weak: specifically, if an event has multiple 782c255e9dSRobert Watson * records (i.e., system call enter and return), they may be interlaced with 792c255e9dSRobert Watson * records from another event. Process and thread ID information is provided 802c255e9dSRobert Watson * in the record, and user applications can de-interlace events if required. 812c255e9dSRobert Watson */ 822c255e9dSRobert Watson 83a1c995b6SPoul-Henning Kamp static MALLOC_DEFINE(M_KTRACE, "KTRACE", "KTRACE"); 8455166637SPoul-Henning Kamp 85db6a20e2SGarrett Wollman #ifdef KTRACE 86ea3fc8e4SJohn Baldwin 87de5b1952SAlexander Leidinger FEATURE(ktrace, "Kernel support for system-call tracing"); 88de5b1952SAlexander Leidinger 89ea3fc8e4SJohn Baldwin #ifndef KTRACE_REQUEST_POOL 90ea3fc8e4SJohn Baldwin #define KTRACE_REQUEST_POOL 100 91ea3fc8e4SJohn Baldwin #endif 92ea3fc8e4SJohn Baldwin 93ea3fc8e4SJohn Baldwin struct ktr_request { 94ea3fc8e4SJohn Baldwin struct ktr_header ktr_header; 95d977a583SRobert Watson void *ktr_buffer; 96ea3fc8e4SJohn Baldwin union { 977705d4b2SDmitry Chagin struct ktr_proc_ctor ktr_proc_ctor; 98c601ad8eSDag-Erling Smørgrav struct ktr_cap_fail ktr_cap_fail; 99ea3fc8e4SJohn Baldwin struct ktr_syscall ktr_syscall; 100ea3fc8e4SJohn Baldwin struct ktr_sysret ktr_sysret; 101ea3fc8e4SJohn Baldwin struct ktr_genio ktr_genio; 102ea3fc8e4SJohn Baldwin struct ktr_psig ktr_psig; 103ea3fc8e4SJohn Baldwin struct ktr_csw ktr_csw; 10435818d2eSJohn Baldwin struct ktr_fault ktr_fault; 10535818d2eSJohn Baldwin struct ktr_faultend ktr_faultend; 106ffb66079SJohn Baldwin struct ktr_struct_array ktr_struct_array; 107ea3fc8e4SJohn Baldwin } ktr_data; 108ea3fc8e4SJohn Baldwin STAILQ_ENTRY(ktr_request) ktr_list; 109ea3fc8e4SJohn Baldwin }; 110ea3fc8e4SJohn Baldwin 1113080f82bSMark Johnston static const int data_lengths[] = { 112093e059cSJilles Tjoelker [KTR_SYSCALL] = offsetof(struct ktr_syscall, ktr_args), 113093e059cSJilles Tjoelker [KTR_SYSRET] = sizeof(struct ktr_sysret), 114093e059cSJilles Tjoelker [KTR_NAMEI] = 0, 115093e059cSJilles Tjoelker [KTR_GENIO] = sizeof(struct ktr_genio), 116093e059cSJilles Tjoelker [KTR_PSIG] = sizeof(struct ktr_psig), 117093e059cSJilles Tjoelker [KTR_CSW] = sizeof(struct ktr_csw), 118093e059cSJilles Tjoelker [KTR_USER] = 0, 119093e059cSJilles Tjoelker [KTR_STRUCT] = 0, 120093e059cSJilles Tjoelker [KTR_SYSCTL] = 0, 121093e059cSJilles Tjoelker [KTR_PROCCTOR] = sizeof(struct ktr_proc_ctor), 122093e059cSJilles Tjoelker [KTR_PROCDTOR] = 0, 123093e059cSJilles Tjoelker [KTR_CAPFAIL] = sizeof(struct ktr_cap_fail), 124093e059cSJilles Tjoelker [KTR_FAULT] = sizeof(struct ktr_fault), 125093e059cSJilles Tjoelker [KTR_FAULTEND] = sizeof(struct ktr_faultend), 126ffb66079SJohn Baldwin [KTR_STRUCT_ARRAY] = sizeof(struct ktr_struct_array), 127*65a4daeaSArtem Hevorhian [KTR_ARGS] = 0, 128*65a4daeaSArtem Hevorhian [KTR_ENVS] = 0, 129ea3fc8e4SJohn Baldwin }; 130ea3fc8e4SJohn Baldwin 131ea3fc8e4SJohn Baldwin static STAILQ_HEAD(, ktr_request) ktr_free; 132ea3fc8e4SJohn Baldwin 1337029da5cSPawel Biernacki static SYSCTL_NODE(_kern, OID_AUTO, ktrace, CTLFLAG_RD | CTLFLAG_MPSAFE, 0, 1347029da5cSPawel Biernacki "KTRACE options"); 13512301fc3SJohn Baldwin 1368b149b51SJohn Baldwin static u_int ktr_requestpool = KTRACE_REQUEST_POOL; 13712301fc3SJohn Baldwin TUNABLE_INT("kern.ktrace.request_pool", &ktr_requestpool); 13812301fc3SJohn Baldwin 1391e4296c9SKonstantin Belousov u_int ktr_geniosize = PAGE_SIZE; 140af3b2549SHans Petter Selasky SYSCTL_UINT(_kern_ktrace, OID_AUTO, genio_size, CTLFLAG_RWTUN, &ktr_geniosize, 14112301fc3SJohn Baldwin 0, "Maximum size of genio event payload"); 142ea3fc8e4SJohn Baldwin 143ea2b64c2SKonstantin Belousov /* 144ea2b64c2SKonstantin Belousov * Allow to not to send signal to traced process, in which context the 145ea2b64c2SKonstantin Belousov * ktr record is written. The limit is applied from the process that 146ea2b64c2SKonstantin Belousov * set up ktrace, so killing the traced process is not completely fair. 147ea2b64c2SKonstantin Belousov */ 148ea2b64c2SKonstantin Belousov int ktr_filesize_limit_signal = 0; 149ea2b64c2SKonstantin Belousov SYSCTL_INT(_kern_ktrace, OID_AUTO, filesize_limit_signal, CTLFLAG_RWTUN, 150ea2b64c2SKonstantin Belousov &ktr_filesize_limit_signal, 0, 151ea2b64c2SKonstantin Belousov "Send SIGXFSZ to the traced process when the log size limit is exceeded"); 152ea2b64c2SKonstantin Belousov 153ea3fc8e4SJohn Baldwin static int print_message = 1; 154d680caabSJohn Baldwin static struct mtx ktrace_mtx; 1552c255e9dSRobert Watson static struct sx ktrace_sx; 156ea3fc8e4SJohn Baldwin 1571762f674SKonstantin Belousov struct ktr_io_params { 1581762f674SKonstantin Belousov struct vnode *vp; 1591762f674SKonstantin Belousov struct ucred *cr; 16002645b88SKonstantin Belousov off_t lim; 1611762f674SKonstantin Belousov u_int refs; 1621762f674SKonstantin Belousov }; 1631762f674SKonstantin Belousov 164ea3fc8e4SJohn Baldwin static void ktrace_init(void *dummy); 165ea3fc8e4SJohn Baldwin static int sysctl_kern_ktrace_request_pool(SYSCTL_HANDLER_ARGS); 166b4c20e5eSDmitry Chagin static u_int ktrace_resize_pool(u_int oldsize, u_int newsize); 16722ec0406SDmitry Chagin static struct ktr_request *ktr_getrequest_entered(struct thread *td, int type); 168ea3fc8e4SJohn Baldwin static struct ktr_request *ktr_getrequest(int type); 1692c255e9dSRobert Watson static void ktr_submitrequest(struct thread *td, struct ktr_request *req); 1701762f674SKonstantin Belousov static struct ktr_io_params *ktr_freeproc(struct proc *p); 171ea3fc8e4SJohn Baldwin static void ktr_freerequest(struct ktr_request *req); 172d680caabSJohn Baldwin static void ktr_freerequest_locked(struct ktr_request *req); 1732c255e9dSRobert Watson static void ktr_writerequest(struct thread *td, struct ktr_request *req); 174a7ff7443SJohn Baldwin static int ktrcanset(struct thread *,struct proc *); 1751762f674SKonstantin Belousov static int ktrsetchildren(struct thread *, struct proc *, int, int, 1761762f674SKonstantin Belousov struct ktr_io_params *); 1771762f674SKonstantin Belousov static int ktrops(struct thread *, struct proc *, int, int, 1781762f674SKonstantin Belousov struct ktr_io_params *); 17922ec0406SDmitry Chagin static void ktrprocctor_entered(struct thread *, struct proc *); 18098d93822SBruce Evans 1812c255e9dSRobert Watson /* 1822c255e9dSRobert Watson * ktrace itself generates events, such as context switches, which we do not 1832c255e9dSRobert Watson * wish to trace. Maintain a flag, TDP_INKTRACE, on each thread to determine 1842c255e9dSRobert Watson * whether or not it is in a region where tracing of events should be 1852c255e9dSRobert Watson * suppressed. 1862c255e9dSRobert Watson */ 1872c255e9dSRobert Watson static void 1882c255e9dSRobert Watson ktrace_enter(struct thread *td) 1892c255e9dSRobert Watson { 1902c255e9dSRobert Watson 1912c255e9dSRobert Watson KASSERT(!(td->td_pflags & TDP_INKTRACE), ("ktrace_enter: flag set")); 1922c255e9dSRobert Watson td->td_pflags |= TDP_INKTRACE; 1932c255e9dSRobert Watson } 1942c255e9dSRobert Watson 1952c255e9dSRobert Watson static void 1962c255e9dSRobert Watson ktrace_exit(struct thread *td) 1972c255e9dSRobert Watson { 1982c255e9dSRobert Watson 1992c255e9dSRobert Watson KASSERT(td->td_pflags & TDP_INKTRACE, ("ktrace_exit: flag not set")); 2002c255e9dSRobert Watson td->td_pflags &= ~TDP_INKTRACE; 2012c255e9dSRobert Watson } 2022c255e9dSRobert Watson 2032c255e9dSRobert Watson static void 2042c255e9dSRobert Watson ktrace_assert(struct thread *td) 2052c255e9dSRobert Watson { 2062c255e9dSRobert Watson 2072c255e9dSRobert Watson KASSERT(td->td_pflags & TDP_INKTRACE, ("ktrace_assert: flag not set")); 2082c255e9dSRobert Watson } 2092c255e9dSRobert Watson 210ea3fc8e4SJohn Baldwin static void 211c6d31b83SKonstantin Belousov ast_ktrace(struct thread *td, int tda __unused) 212c6d31b83SKonstantin Belousov { 213c6d31b83SKonstantin Belousov KTRUSERRET(td); 214c6d31b83SKonstantin Belousov } 215c6d31b83SKonstantin Belousov 216c6d31b83SKonstantin Belousov static void 217ea3fc8e4SJohn Baldwin ktrace_init(void *dummy) 218df8bae1dSRodney W. Grimes { 219ea3fc8e4SJohn Baldwin struct ktr_request *req; 220ea3fc8e4SJohn Baldwin int i; 221df8bae1dSRodney W. Grimes 222ea3fc8e4SJohn Baldwin mtx_init(&ktrace_mtx, "ktrace", NULL, MTX_DEF | MTX_QUIET); 2232c255e9dSRobert Watson sx_init(&ktrace_sx, "ktrace_sx"); 224ea3fc8e4SJohn Baldwin STAILQ_INIT(&ktr_free); 225ea3fc8e4SJohn Baldwin for (i = 0; i < ktr_requestpool; i++) { 2265c18bf9dSMark Johnston req = malloc(sizeof(struct ktr_request), M_KTRACE, M_WAITOK | 2275c18bf9dSMark Johnston M_ZERO); 228ea3fc8e4SJohn Baldwin STAILQ_INSERT_HEAD(&ktr_free, req, ktr_list); 229ea3fc8e4SJohn Baldwin } 2304a662c90SKonstantin Belousov ast_register(TDA_KTRACE, ASTR_ASTF_REQUIRED, 0, ast_ktrace); 231ea3fc8e4SJohn Baldwin } 232ea3fc8e4SJohn Baldwin SYSINIT(ktrace_init, SI_SUB_KTRACE, SI_ORDER_ANY, ktrace_init, NULL); 233ea3fc8e4SJohn Baldwin 234ea3fc8e4SJohn Baldwin static int 235ea3fc8e4SJohn Baldwin sysctl_kern_ktrace_request_pool(SYSCTL_HANDLER_ARGS) 236ea3fc8e4SJohn Baldwin { 237ea3fc8e4SJohn Baldwin struct thread *td; 2388b149b51SJohn Baldwin u_int newsize, oldsize, wantsize; 239ea3fc8e4SJohn Baldwin int error; 240ea3fc8e4SJohn Baldwin 241ea3fc8e4SJohn Baldwin /* Handle easy read-only case first to avoid warnings from GCC. */ 242ea3fc8e4SJohn Baldwin if (!req->newptr) { 243ea3fc8e4SJohn Baldwin oldsize = ktr_requestpool; 2448b149b51SJohn Baldwin return (SYSCTL_OUT(req, &oldsize, sizeof(u_int))); 245ea3fc8e4SJohn Baldwin } 246ea3fc8e4SJohn Baldwin 2478b149b51SJohn Baldwin error = SYSCTL_IN(req, &wantsize, sizeof(u_int)); 248ea3fc8e4SJohn Baldwin if (error) 249ea3fc8e4SJohn Baldwin return (error); 250ea3fc8e4SJohn Baldwin td = curthread; 2512c255e9dSRobert Watson ktrace_enter(td); 252ea3fc8e4SJohn Baldwin oldsize = ktr_requestpool; 253b4c20e5eSDmitry Chagin newsize = ktrace_resize_pool(oldsize, wantsize); 2542c255e9dSRobert Watson ktrace_exit(td); 2558b149b51SJohn Baldwin error = SYSCTL_OUT(req, &oldsize, sizeof(u_int)); 256ea3fc8e4SJohn Baldwin if (error) 257ea3fc8e4SJohn Baldwin return (error); 258a5896914SJoseph Koshy if (wantsize > oldsize && newsize < wantsize) 259ea3fc8e4SJohn Baldwin return (ENOSPC); 260ea3fc8e4SJohn Baldwin return (0); 261ea3fc8e4SJohn Baldwin } 2627029da5cSPawel Biernacki SYSCTL_PROC(_kern_ktrace, OID_AUTO, request_pool, 2637029da5cSPawel Biernacki CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, &ktr_requestpool, 0, 2647029da5cSPawel Biernacki sysctl_kern_ktrace_request_pool, "IU", 265a0c87b74SGavin Atkinson "Pool buffer size for ktrace(1)"); 266ea3fc8e4SJohn Baldwin 2678b149b51SJohn Baldwin static u_int 268b4c20e5eSDmitry Chagin ktrace_resize_pool(u_int oldsize, u_int newsize) 269ea3fc8e4SJohn Baldwin { 270b4c20e5eSDmitry Chagin STAILQ_HEAD(, ktr_request) ktr_new; 271ea3fc8e4SJohn Baldwin struct ktr_request *req; 272a5896914SJoseph Koshy int bound; 273ea3fc8e4SJohn Baldwin 274ea3fc8e4SJohn Baldwin print_message = 1; 275b4c20e5eSDmitry Chagin bound = newsize - oldsize; 276a5896914SJoseph Koshy if (bound == 0) 277a5896914SJoseph Koshy return (ktr_requestpool); 278b4c20e5eSDmitry Chagin if (bound < 0) { 279b4c20e5eSDmitry Chagin mtx_lock(&ktrace_mtx); 280ea3fc8e4SJohn Baldwin /* Shrink pool down to newsize if possible. */ 281a5896914SJoseph Koshy while (bound++ < 0) { 282ea3fc8e4SJohn Baldwin req = STAILQ_FIRST(&ktr_free); 283ea3fc8e4SJohn Baldwin if (req == NULL) 284b4c20e5eSDmitry Chagin break; 285ea3fc8e4SJohn Baldwin STAILQ_REMOVE_HEAD(&ktr_free, ktr_list); 286ea3fc8e4SJohn Baldwin ktr_requestpool--; 287ea3fc8e4SJohn Baldwin free(req, M_KTRACE); 288ea3fc8e4SJohn Baldwin } 289b4c20e5eSDmitry Chagin } else { 290ea3fc8e4SJohn Baldwin /* Grow pool up to newsize. */ 291b4c20e5eSDmitry Chagin STAILQ_INIT(&ktr_new); 292a5896914SJoseph Koshy while (bound-- > 0) { 293ea3fc8e4SJohn Baldwin req = malloc(sizeof(struct ktr_request), M_KTRACE, 2945c18bf9dSMark Johnston M_WAITOK | M_ZERO); 295b4c20e5eSDmitry Chagin STAILQ_INSERT_HEAD(&ktr_new, req, ktr_list); 296ea3fc8e4SJohn Baldwin } 297b4c20e5eSDmitry Chagin mtx_lock(&ktrace_mtx); 298b4c20e5eSDmitry Chagin STAILQ_CONCAT(&ktr_free, &ktr_new); 299b4c20e5eSDmitry Chagin ktr_requestpool += (newsize - oldsize); 300b4c20e5eSDmitry Chagin } 301b4c20e5eSDmitry Chagin mtx_unlock(&ktrace_mtx); 302ea3fc8e4SJohn Baldwin return (ktr_requestpool); 303ea3fc8e4SJohn Baldwin } 304ea3fc8e4SJohn Baldwin 3055ca4819dSJohn Baldwin /* ktr_getrequest() assumes that ktr_comm[] is the same size as td_name[]. */ 3065ca4819dSJohn Baldwin CTASSERT(sizeof(((struct ktr_header *)NULL)->ktr_comm) == 3075ca4819dSJohn Baldwin (sizeof((struct thread *)NULL)->td_name)); 3085ca4819dSJohn Baldwin 309ea3fc8e4SJohn Baldwin static struct ktr_request * 31022ec0406SDmitry Chagin ktr_getrequest_entered(struct thread *td, int type) 311ea3fc8e4SJohn Baldwin { 312ea3fc8e4SJohn Baldwin struct ktr_request *req; 313ea3fc8e4SJohn Baldwin struct proc *p = td->td_proc; 314ea3fc8e4SJohn Baldwin int pm; 315ea3fc8e4SJohn Baldwin 316c5c9bd5bSRobert Watson mtx_lock(&ktrace_mtx); 317ea3fc8e4SJohn Baldwin if (!KTRCHECK(td, type)) { 318c5c9bd5bSRobert Watson mtx_unlock(&ktrace_mtx); 319ea3fc8e4SJohn Baldwin return (NULL); 320ea3fc8e4SJohn Baldwin } 321ea3fc8e4SJohn Baldwin req = STAILQ_FIRST(&ktr_free); 322ea3fc8e4SJohn Baldwin if (req != NULL) { 323ea3fc8e4SJohn Baldwin STAILQ_REMOVE_HEAD(&ktr_free, ktr_list); 324ea3fc8e4SJohn Baldwin req->ktr_header.ktr_type = type; 32575768576SJohn Baldwin if (p->p_traceflag & KTRFAC_DROP) { 32675768576SJohn Baldwin req->ktr_header.ktr_type |= KTR_DROP; 32775768576SJohn Baldwin p->p_traceflag &= ~KTRFAC_DROP; 32875768576SJohn Baldwin } 329c5c9bd5bSRobert Watson mtx_unlock(&ktrace_mtx); 330fc90f3a2SDmitry Chagin nanotime(&req->ktr_header.ktr_time); 331fc90f3a2SDmitry Chagin req->ktr_header.ktr_type |= KTR_VERSIONED; 332ea3fc8e4SJohn Baldwin req->ktr_header.ktr_pid = p->p_pid; 3332bdeb3f9SRobert Watson req->ktr_header.ktr_tid = td->td_tid; 334fc90f3a2SDmitry Chagin req->ktr_header.ktr_cpu = PCPU_GET(cpuid); 335fc90f3a2SDmitry Chagin req->ktr_header.ktr_version = KTR_VERSION1; 3365ca4819dSJohn Baldwin bcopy(td->td_name, req->ktr_header.ktr_comm, 3375ca4819dSJohn Baldwin sizeof(req->ktr_header.ktr_comm)); 338d977a583SRobert Watson req->ktr_buffer = NULL; 339ea3fc8e4SJohn Baldwin req->ktr_header.ktr_len = 0; 340ea3fc8e4SJohn Baldwin } else { 34175768576SJohn Baldwin p->p_traceflag |= KTRFAC_DROP; 342ea3fc8e4SJohn Baldwin pm = print_message; 343ea3fc8e4SJohn Baldwin print_message = 0; 344ea3fc8e4SJohn Baldwin mtx_unlock(&ktrace_mtx); 345ea3fc8e4SJohn Baldwin if (pm) 346ea3fc8e4SJohn Baldwin printf("Out of ktrace request objects.\n"); 347ea3fc8e4SJohn Baldwin } 348ea3fc8e4SJohn Baldwin return (req); 349ea3fc8e4SJohn Baldwin } 350ea3fc8e4SJohn Baldwin 3517705d4b2SDmitry Chagin static struct ktr_request * 3527705d4b2SDmitry Chagin ktr_getrequest(int type) 3537705d4b2SDmitry Chagin { 3547705d4b2SDmitry Chagin struct thread *td = curthread; 3557705d4b2SDmitry Chagin struct ktr_request *req; 3567705d4b2SDmitry Chagin 3577705d4b2SDmitry Chagin ktrace_enter(td); 35822ec0406SDmitry Chagin req = ktr_getrequest_entered(td, type); 3597705d4b2SDmitry Chagin if (req == NULL) 3607705d4b2SDmitry Chagin ktrace_exit(td); 3617705d4b2SDmitry Chagin 3627705d4b2SDmitry Chagin return (req); 3637705d4b2SDmitry Chagin } 3647705d4b2SDmitry Chagin 3652c255e9dSRobert Watson /* 3662c255e9dSRobert Watson * Some trace generation environments don't permit direct access to VFS, 3672c255e9dSRobert Watson * such as during a context switch where sleeping is not allowed. Under these 3682c255e9dSRobert Watson * circumstances, queue a request to the thread to be written asynchronously 3692c255e9dSRobert Watson * later. 3702c255e9dSRobert Watson */ 371ea3fc8e4SJohn Baldwin static void 3722c255e9dSRobert Watson ktr_enqueuerequest(struct thread *td, struct ktr_request *req) 373ea3fc8e4SJohn Baldwin { 374ea3fc8e4SJohn Baldwin 375ea3fc8e4SJohn Baldwin mtx_lock(&ktrace_mtx); 3762c255e9dSRobert Watson STAILQ_INSERT_TAIL(&td->td_proc->p_ktr, req, ktr_list); 377ea3fc8e4SJohn Baldwin mtx_unlock(&ktrace_mtx); 378c6d31b83SKonstantin Belousov ast_sched(td, TDA_KTRACE); 3792c255e9dSRobert Watson } 3802c255e9dSRobert Watson 3812c255e9dSRobert Watson /* 3822c255e9dSRobert Watson * Drain any pending ktrace records from the per-thread queue to disk. This 3832c255e9dSRobert Watson * is used both internally before committing other records, and also on 3842c255e9dSRobert Watson * system call return. We drain all the ones we can find at the time when 3852c255e9dSRobert Watson * drain is requested, but don't keep draining after that as those events 386a56be37eSJohn Baldwin * may be approximately "after" the current event. 3872c255e9dSRobert Watson */ 3882c255e9dSRobert Watson static void 3892c255e9dSRobert Watson ktr_drain(struct thread *td) 3902c255e9dSRobert Watson { 3912c255e9dSRobert Watson struct ktr_request *queued_req; 3922c255e9dSRobert Watson STAILQ_HEAD(, ktr_request) local_queue; 3932c255e9dSRobert Watson 3942c255e9dSRobert Watson ktrace_assert(td); 3952c255e9dSRobert Watson sx_assert(&ktrace_sx, SX_XLOCKED); 3962c255e9dSRobert Watson 3972b3fb615SJohn Baldwin STAILQ_INIT(&local_queue); 3982c255e9dSRobert Watson 3992c255e9dSRobert Watson if (!STAILQ_EMPTY(&td->td_proc->p_ktr)) { 4002c255e9dSRobert Watson mtx_lock(&ktrace_mtx); 4012c255e9dSRobert Watson STAILQ_CONCAT(&local_queue, &td->td_proc->p_ktr); 4022c255e9dSRobert Watson mtx_unlock(&ktrace_mtx); 4032c255e9dSRobert Watson 4042c255e9dSRobert Watson while ((queued_req = STAILQ_FIRST(&local_queue))) { 4052c255e9dSRobert Watson STAILQ_REMOVE_HEAD(&local_queue, ktr_list); 4062c255e9dSRobert Watson ktr_writerequest(td, queued_req); 4072c255e9dSRobert Watson ktr_freerequest(queued_req); 4082c255e9dSRobert Watson } 4092c255e9dSRobert Watson } 4102c255e9dSRobert Watson } 4112c255e9dSRobert Watson 4122c255e9dSRobert Watson /* 4132c255e9dSRobert Watson * Submit a trace record for immediate commit to disk -- to be used only 4142c255e9dSRobert Watson * where entering VFS is OK. First drain any pending records that may have 4152c255e9dSRobert Watson * been cached in the thread. 4162c255e9dSRobert Watson */ 4172c255e9dSRobert Watson static void 41822ec0406SDmitry Chagin ktr_submitrequest(struct thread *td, struct ktr_request *req) 4192c255e9dSRobert Watson { 4202c255e9dSRobert Watson 4212c255e9dSRobert Watson ktrace_assert(td); 4222c255e9dSRobert Watson 4232c255e9dSRobert Watson sx_xlock(&ktrace_sx); 4242c255e9dSRobert Watson ktr_drain(td); 4252c255e9dSRobert Watson ktr_writerequest(td, req); 4262c255e9dSRobert Watson ktr_freerequest(req); 4272c255e9dSRobert Watson sx_xunlock(&ktrace_sx); 4282c255e9dSRobert Watson ktrace_exit(td); 429ea3fc8e4SJohn Baldwin } 430ea3fc8e4SJohn Baldwin 431ea3fc8e4SJohn Baldwin static void 432ea3fc8e4SJohn Baldwin ktr_freerequest(struct ktr_request *req) 433ea3fc8e4SJohn Baldwin { 434ea3fc8e4SJohn Baldwin 435d680caabSJohn Baldwin mtx_lock(&ktrace_mtx); 436d680caabSJohn Baldwin ktr_freerequest_locked(req); 437d680caabSJohn Baldwin mtx_unlock(&ktrace_mtx); 438d680caabSJohn Baldwin } 439d680caabSJohn Baldwin 440d680caabSJohn Baldwin static void 441d680caabSJohn Baldwin ktr_freerequest_locked(struct ktr_request *req) 442d680caabSJohn Baldwin { 443d680caabSJohn Baldwin 444d680caabSJohn Baldwin mtx_assert(&ktrace_mtx, MA_OWNED); 445d977a583SRobert Watson if (req->ktr_buffer != NULL) 446d977a583SRobert Watson free(req->ktr_buffer, M_KTRACE); 447ea3fc8e4SJohn Baldwin STAILQ_INSERT_HEAD(&ktr_free, req, ktr_list); 448d680caabSJohn Baldwin } 449d680caabSJohn Baldwin 4501762f674SKonstantin Belousov static void 4511762f674SKonstantin Belousov ktr_io_params_ref(struct ktr_io_params *kiop) 4521762f674SKonstantin Belousov { 4531762f674SKonstantin Belousov mtx_assert(&ktrace_mtx, MA_OWNED); 4541762f674SKonstantin Belousov kiop->refs++; 4551762f674SKonstantin Belousov } 4561762f674SKonstantin Belousov 4571762f674SKonstantin Belousov static struct ktr_io_params * 4581762f674SKonstantin Belousov ktr_io_params_rele(struct ktr_io_params *kiop) 4591762f674SKonstantin Belousov { 4601762f674SKonstantin Belousov mtx_assert(&ktrace_mtx, MA_OWNED); 4611762f674SKonstantin Belousov if (kiop == NULL) 4621762f674SKonstantin Belousov return (NULL); 4631762f674SKonstantin Belousov KASSERT(kiop->refs > 0, ("kiop ref == 0 %p", kiop)); 4641762f674SKonstantin Belousov return (--(kiop->refs) == 0 ? kiop : NULL); 4651762f674SKonstantin Belousov } 4661762f674SKonstantin Belousov 4671762f674SKonstantin Belousov void 4681762f674SKonstantin Belousov ktr_io_params_free(struct ktr_io_params *kiop) 4691762f674SKonstantin Belousov { 4701762f674SKonstantin Belousov if (kiop == NULL) 4711762f674SKonstantin Belousov return; 4721762f674SKonstantin Belousov 4731762f674SKonstantin Belousov MPASS(kiop->refs == 0); 4741762f674SKonstantin Belousov vn_close(kiop->vp, FWRITE, kiop->cr, curthread); 4751762f674SKonstantin Belousov crfree(kiop->cr); 4761762f674SKonstantin Belousov free(kiop, M_KTRACE); 4771762f674SKonstantin Belousov } 4781762f674SKonstantin Belousov 4791762f674SKonstantin Belousov static struct ktr_io_params * 4801762f674SKonstantin Belousov ktr_io_params_alloc(struct thread *td, struct vnode *vp) 4811762f674SKonstantin Belousov { 4821762f674SKonstantin Belousov struct ktr_io_params *res; 4831762f674SKonstantin Belousov 4841762f674SKonstantin Belousov res = malloc(sizeof(struct ktr_io_params), M_KTRACE, M_WAITOK); 4851762f674SKonstantin Belousov res->vp = vp; 4861762f674SKonstantin Belousov res->cr = crhold(td->td_ucred); 48702645b88SKonstantin Belousov res->lim = lim_cur(td, RLIMIT_FSIZE); 4881762f674SKonstantin Belousov res->refs = 1; 4891762f674SKonstantin Belousov return (res); 4901762f674SKonstantin Belousov } 4911762f674SKonstantin Belousov 492d680caabSJohn Baldwin /* 493d680caabSJohn Baldwin * Disable tracing for a process and release all associated resources. 494d680caabSJohn Baldwin * The caller is responsible for releasing a reference on the returned 495d680caabSJohn Baldwin * vnode and credentials. 496d680caabSJohn Baldwin */ 4971762f674SKonstantin Belousov static struct ktr_io_params * 4981762f674SKonstantin Belousov ktr_freeproc(struct proc *p) 499d680caabSJohn Baldwin { 5001762f674SKonstantin Belousov struct ktr_io_params *kiop; 501d680caabSJohn Baldwin struct ktr_request *req; 502d680caabSJohn Baldwin 503d680caabSJohn Baldwin PROC_LOCK_ASSERT(p, MA_OWNED); 504d680caabSJohn Baldwin mtx_assert(&ktrace_mtx, MA_OWNED); 5051762f674SKonstantin Belousov kiop = ktr_io_params_rele(p->p_ktrioparms); 5061762f674SKonstantin Belousov p->p_ktrioparms = NULL; 507d680caabSJohn Baldwin p->p_traceflag = 0; 508d680caabSJohn Baldwin while ((req = STAILQ_FIRST(&p->p_ktr)) != NULL) { 509d680caabSJohn Baldwin STAILQ_REMOVE_HEAD(&p->p_ktr, ktr_list); 510d680caabSJohn Baldwin ktr_freerequest_locked(req); 511d680caabSJohn Baldwin } 5121762f674SKonstantin Belousov return (kiop); 5131762f674SKonstantin Belousov } 5141762f674SKonstantin Belousov 5151762f674SKonstantin Belousov struct vnode * 5161762f674SKonstantin Belousov ktr_get_tracevp(struct proc *p, bool ref) 5171762f674SKonstantin Belousov { 5181762f674SKonstantin Belousov struct vnode *vp; 5191762f674SKonstantin Belousov 5201762f674SKonstantin Belousov PROC_LOCK_ASSERT(p, MA_OWNED); 5211762f674SKonstantin Belousov 5221762f674SKonstantin Belousov if (p->p_ktrioparms != NULL) { 5231762f674SKonstantin Belousov vp = p->p_ktrioparms->vp; 5241762f674SKonstantin Belousov if (ref) 5251762f674SKonstantin Belousov vrefact(vp); 5261762f674SKonstantin Belousov } else { 5271762f674SKonstantin Belousov vp = NULL; 5281762f674SKonstantin Belousov } 5291762f674SKonstantin Belousov return (vp); 530ea3fc8e4SJohn Baldwin } 531ea3fc8e4SJohn Baldwin 53226f9a767SRodney W. Grimes void 533b1ad6a90SBrooks Davis ktrsyscall(int code, int narg, syscallarg_t args[]) 534df8bae1dSRodney W. Grimes { 535ea3fc8e4SJohn Baldwin struct ktr_request *req; 536df8bae1dSRodney W. Grimes struct ktr_syscall *ktp; 537ea3fc8e4SJohn Baldwin size_t buflen; 5384b3aac3dSJohn Baldwin char *buf = NULL; 539df8bae1dSRodney W. Grimes 540ad738f37SMatt Macy if (__predict_false(curthread->td_pflags & TDP_INKTRACE)) 541ad738f37SMatt Macy return; 542ad738f37SMatt Macy 5434b3aac3dSJohn Baldwin buflen = sizeof(register_t) * narg; 5444b3aac3dSJohn Baldwin if (buflen > 0) { 545a163d034SWarner Losh buf = malloc(buflen, M_KTRACE, M_WAITOK); 5464b3aac3dSJohn Baldwin bcopy(args, buf, buflen); 5474b3aac3dSJohn Baldwin } 548ea3fc8e4SJohn Baldwin req = ktr_getrequest(KTR_SYSCALL); 54950c22331SPoul-Henning Kamp if (req == NULL) { 55050c22331SPoul-Henning Kamp if (buf != NULL) 55150c22331SPoul-Henning Kamp free(buf, M_KTRACE); 552ea3fc8e4SJohn Baldwin return; 55350c22331SPoul-Henning Kamp } 554ea3fc8e4SJohn Baldwin ktp = &req->ktr_data.ktr_syscall; 555df8bae1dSRodney W. Grimes ktp->ktr_code = code; 556df8bae1dSRodney W. Grimes ktp->ktr_narg = narg; 557ea3fc8e4SJohn Baldwin if (buflen > 0) { 558ea3fc8e4SJohn Baldwin req->ktr_header.ktr_len = buflen; 559d977a583SRobert Watson req->ktr_buffer = buf; 560ea3fc8e4SJohn Baldwin } 5612c255e9dSRobert Watson ktr_submitrequest(curthread, req); 562df8bae1dSRodney W. Grimes } 563df8bae1dSRodney W. Grimes 56426f9a767SRodney W. Grimes void 565*65a4daeaSArtem Hevorhian ktrdata(int type, const void *data, size_t len) 566*65a4daeaSArtem Hevorhian { 567*65a4daeaSArtem Hevorhian struct ktr_request *req; 568*65a4daeaSArtem Hevorhian void *buf; 569*65a4daeaSArtem Hevorhian 570*65a4daeaSArtem Hevorhian if ((req = ktr_getrequest(type)) == NULL) 571*65a4daeaSArtem Hevorhian return; 572*65a4daeaSArtem Hevorhian buf = malloc(len, M_KTRACE, M_WAITOK); 573*65a4daeaSArtem Hevorhian bcopy(data, buf, len); 574*65a4daeaSArtem Hevorhian req->ktr_header.ktr_len = len; 575*65a4daeaSArtem Hevorhian req->ktr_buffer = buf; 576*65a4daeaSArtem Hevorhian ktr_submitrequest(curthread, req); 577*65a4daeaSArtem Hevorhian } 578*65a4daeaSArtem Hevorhian 579*65a4daeaSArtem Hevorhian void 580039644ecSEd Maste ktrsysret(int code, int error, register_t retval) 581df8bae1dSRodney W. Grimes { 582ea3fc8e4SJohn Baldwin struct ktr_request *req; 583ea3fc8e4SJohn Baldwin struct ktr_sysret *ktp; 584df8bae1dSRodney W. Grimes 585ad738f37SMatt Macy if (__predict_false(curthread->td_pflags & TDP_INKTRACE)) 586ad738f37SMatt Macy return; 587ad738f37SMatt Macy 588ea3fc8e4SJohn Baldwin req = ktr_getrequest(KTR_SYSRET); 589ea3fc8e4SJohn Baldwin if (req == NULL) 590ea3fc8e4SJohn Baldwin return; 591ea3fc8e4SJohn Baldwin ktp = &req->ktr_data.ktr_sysret; 592ea3fc8e4SJohn Baldwin ktp->ktr_code = code; 593ea3fc8e4SJohn Baldwin ktp->ktr_error = error; 5945a01b726SEitan Adler ktp->ktr_retval = ((error == 0) ? retval: 0); /* what about val2 ? */ 5952c255e9dSRobert Watson ktr_submitrequest(curthread, req); 5962c255e9dSRobert Watson } 5972c255e9dSRobert Watson 5982c255e9dSRobert Watson /* 599d680caabSJohn Baldwin * When a setuid process execs, disable tracing. 600d680caabSJohn Baldwin * 601d680caabSJohn Baldwin * XXX: We toss any pending asynchronous records. 602d680caabSJohn Baldwin */ 6031762f674SKonstantin Belousov struct ktr_io_params * 6041762f674SKonstantin Belousov ktrprocexec(struct proc *p) 605d680caabSJohn Baldwin { 6061762f674SKonstantin Belousov struct ktr_io_params *kiop; 607d680caabSJohn Baldwin 608d680caabSJohn Baldwin PROC_LOCK_ASSERT(p, MA_OWNED); 6091762f674SKonstantin Belousov 6101762f674SKonstantin Belousov kiop = p->p_ktrioparms; 611166b7573SMark Johnston if (kiop == NULL || priv_check_cred(kiop->cr, PRIV_DEBUG_DIFFCRED) == 0) 6121762f674SKonstantin Belousov return (NULL); 6131762f674SKonstantin Belousov 614d680caabSJohn Baldwin mtx_lock(&ktrace_mtx); 6151762f674SKonstantin Belousov kiop = ktr_freeproc(p); 616d680caabSJohn Baldwin mtx_unlock(&ktrace_mtx); 6171762f674SKonstantin Belousov return (kiop); 618d680caabSJohn Baldwin } 619d680caabSJohn Baldwin 620d680caabSJohn Baldwin /* 621d680caabSJohn Baldwin * When a process exits, drain per-process asynchronous trace records 622d680caabSJohn Baldwin * and disable tracing. 6232c255e9dSRobert Watson */ 6242c255e9dSRobert Watson void 6252c255e9dSRobert Watson ktrprocexit(struct thread *td) 6262c255e9dSRobert Watson { 6277705d4b2SDmitry Chagin struct ktr_request *req; 628d680caabSJohn Baldwin struct proc *p; 6291762f674SKonstantin Belousov struct ktr_io_params *kiop; 630d680caabSJohn Baldwin 631d680caabSJohn Baldwin p = td->td_proc; 632d680caabSJohn Baldwin if (p->p_traceflag == 0) 633d680caabSJohn Baldwin return; 6342c255e9dSRobert Watson 6352c255e9dSRobert Watson ktrace_enter(td); 63622ec0406SDmitry Chagin req = ktr_getrequest_entered(td, KTR_PROCDTOR); 63722ec0406SDmitry Chagin if (req != NULL) 63822ec0406SDmitry Chagin ktr_enqueuerequest(td, req); 6392c255e9dSRobert Watson sx_xlock(&ktrace_sx); 6402c255e9dSRobert Watson ktr_drain(td); 6412c255e9dSRobert Watson sx_xunlock(&ktrace_sx); 642d680caabSJohn Baldwin PROC_LOCK(p); 643d680caabSJohn Baldwin mtx_lock(&ktrace_mtx); 6441762f674SKonstantin Belousov kiop = ktr_freeproc(p); 645d680caabSJohn Baldwin mtx_unlock(&ktrace_mtx); 646d680caabSJohn Baldwin PROC_UNLOCK(p); 6471762f674SKonstantin Belousov ktr_io_params_free(kiop); 6482c255e9dSRobert Watson ktrace_exit(td); 6492c255e9dSRobert Watson } 6502c255e9dSRobert Watson 6517705d4b2SDmitry Chagin static void 65222ec0406SDmitry Chagin ktrprocctor_entered(struct thread *td, struct proc *p) 6537705d4b2SDmitry Chagin { 6547705d4b2SDmitry Chagin struct ktr_proc_ctor *ktp; 6557705d4b2SDmitry Chagin struct ktr_request *req; 656de60a5f3SDmitry Chagin struct thread *td2; 6577705d4b2SDmitry Chagin 6587705d4b2SDmitry Chagin ktrace_assert(td); 6597705d4b2SDmitry Chagin td2 = FIRST_THREAD_IN_PROC(p); 66022ec0406SDmitry Chagin req = ktr_getrequest_entered(td2, KTR_PROCCTOR); 6617705d4b2SDmitry Chagin if (req == NULL) 6627705d4b2SDmitry Chagin return; 6637705d4b2SDmitry Chagin ktp = &req->ktr_data.ktr_proc_ctor; 6647705d4b2SDmitry Chagin ktp->sv_flags = p->p_sysent->sv_flags; 66522ec0406SDmitry Chagin ktr_enqueuerequest(td2, req); 6667705d4b2SDmitry Chagin } 6677705d4b2SDmitry Chagin 6687705d4b2SDmitry Chagin void 6697705d4b2SDmitry Chagin ktrprocctor(struct proc *p) 6707705d4b2SDmitry Chagin { 6717705d4b2SDmitry Chagin struct thread *td = curthread; 6727705d4b2SDmitry Chagin 6737705d4b2SDmitry Chagin if ((p->p_traceflag & KTRFAC_MASK) == 0) 6747705d4b2SDmitry Chagin return; 6757705d4b2SDmitry Chagin 6767705d4b2SDmitry Chagin ktrace_enter(td); 67722ec0406SDmitry Chagin ktrprocctor_entered(td, p); 6787705d4b2SDmitry Chagin ktrace_exit(td); 6797705d4b2SDmitry Chagin } 6807705d4b2SDmitry Chagin 6812c255e9dSRobert Watson /* 682d680caabSJohn Baldwin * When a process forks, enable tracing in the new process if needed. 683d680caabSJohn Baldwin */ 684d680caabSJohn Baldwin void 685d680caabSJohn Baldwin ktrprocfork(struct proc *p1, struct proc *p2) 686d680caabSJohn Baldwin { 687d680caabSJohn Baldwin 6881762f674SKonstantin Belousov MPASS(p2->p_ktrioparms == NULL); 6897c34b35bSMateusz Guzik MPASS(p2->p_traceflag == 0); 6907c34b35bSMateusz Guzik 6917c34b35bSMateusz Guzik if (p1->p_traceflag == 0) 6927c34b35bSMateusz Guzik return; 6937c34b35bSMateusz Guzik 6947705d4b2SDmitry Chagin PROC_LOCK(p1); 695d680caabSJohn Baldwin mtx_lock(&ktrace_mtx); 696d680caabSJohn Baldwin if (p1->p_traceflag & KTRFAC_INHERIT) { 697d680caabSJohn Baldwin p2->p_traceflag = p1->p_traceflag; 6981762f674SKonstantin Belousov if ((p2->p_ktrioparms = p1->p_ktrioparms) != NULL) 6991762f674SKonstantin Belousov p1->p_ktrioparms->refs++; 700d680caabSJohn Baldwin } 701d680caabSJohn Baldwin mtx_unlock(&ktrace_mtx); 7027705d4b2SDmitry Chagin PROC_UNLOCK(p1); 7037705d4b2SDmitry Chagin 7047705d4b2SDmitry Chagin ktrprocctor(p2); 705d680caabSJohn Baldwin } 706d680caabSJohn Baldwin 707d680caabSJohn Baldwin /* 7082c255e9dSRobert Watson * When a thread returns, drain any asynchronous records generated by the 7092c255e9dSRobert Watson * system call. 7102c255e9dSRobert Watson */ 7112c255e9dSRobert Watson void 7122c255e9dSRobert Watson ktruserret(struct thread *td) 7132c255e9dSRobert Watson { 7142c255e9dSRobert Watson 7152c255e9dSRobert Watson ktrace_enter(td); 7162c255e9dSRobert Watson sx_xlock(&ktrace_sx); 7172c255e9dSRobert Watson ktr_drain(td); 7182c255e9dSRobert Watson sx_xunlock(&ktrace_sx); 7192c255e9dSRobert Watson ktrace_exit(td); 720df8bae1dSRodney W. Grimes } 721df8bae1dSRodney W. Grimes 72226f9a767SRodney W. Grimes void 723e4b16f2fSMark Johnston ktrnamei(const char *path) 724df8bae1dSRodney W. Grimes { 725ea3fc8e4SJohn Baldwin struct ktr_request *req; 726ea3fc8e4SJohn Baldwin int namelen; 7274b3aac3dSJohn Baldwin char *buf = NULL; 728df8bae1dSRodney W. Grimes 7294b3aac3dSJohn Baldwin namelen = strlen(path); 7304b3aac3dSJohn Baldwin if (namelen > 0) { 731a163d034SWarner Losh buf = malloc(namelen, M_KTRACE, M_WAITOK); 7324b3aac3dSJohn Baldwin bcopy(path, buf, namelen); 7334b3aac3dSJohn Baldwin } 734ea3fc8e4SJohn Baldwin req = ktr_getrequest(KTR_NAMEI); 73550c22331SPoul-Henning Kamp if (req == NULL) { 73650c22331SPoul-Henning Kamp if (buf != NULL) 73750c22331SPoul-Henning Kamp free(buf, M_KTRACE); 738ea3fc8e4SJohn Baldwin return; 73950c22331SPoul-Henning Kamp } 740ea3fc8e4SJohn Baldwin if (namelen > 0) { 741ea3fc8e4SJohn Baldwin req->ktr_header.ktr_len = namelen; 742d977a583SRobert Watson req->ktr_buffer = buf; 743ea3fc8e4SJohn Baldwin } 7442c255e9dSRobert Watson ktr_submitrequest(curthread, req); 745df8bae1dSRodney W. Grimes } 746df8bae1dSRodney W. Grimes 74726f9a767SRodney W. Grimes void 748039644ecSEd Maste ktrsysctl(int *name, u_int namelen) 749a56be37eSJohn Baldwin { 750a56be37eSJohn Baldwin struct ktr_request *req; 751a56be37eSJohn Baldwin u_int mib[CTL_MAXNAME + 2]; 752a56be37eSJohn Baldwin char *mibname; 753a56be37eSJohn Baldwin size_t mibnamelen; 754a56be37eSJohn Baldwin int error; 755a56be37eSJohn Baldwin 756a56be37eSJohn Baldwin /* Lookup name of mib. */ 757a56be37eSJohn Baldwin KASSERT(namelen <= CTL_MAXNAME, ("sysctl MIB too long")); 758a56be37eSJohn Baldwin mib[0] = 0; 759a56be37eSJohn Baldwin mib[1] = 1; 760a56be37eSJohn Baldwin bcopy(name, mib + 2, namelen * sizeof(*name)); 761a56be37eSJohn Baldwin mibnamelen = 128; 762a56be37eSJohn Baldwin mibname = malloc(mibnamelen, M_KTRACE, M_WAITOK); 763a56be37eSJohn Baldwin error = kernel_sysctl(curthread, mib, namelen + 2, mibname, &mibnamelen, 764a56be37eSJohn Baldwin NULL, 0, &mibnamelen, 0); 765a56be37eSJohn Baldwin if (error) { 766a56be37eSJohn Baldwin free(mibname, M_KTRACE); 767a56be37eSJohn Baldwin return; 768a56be37eSJohn Baldwin } 769a56be37eSJohn Baldwin req = ktr_getrequest(KTR_SYSCTL); 770a56be37eSJohn Baldwin if (req == NULL) { 771a56be37eSJohn Baldwin free(mibname, M_KTRACE); 772a56be37eSJohn Baldwin return; 773a56be37eSJohn Baldwin } 774a56be37eSJohn Baldwin req->ktr_header.ktr_len = mibnamelen; 775a56be37eSJohn Baldwin req->ktr_buffer = mibname; 776a56be37eSJohn Baldwin ktr_submitrequest(curthread, req); 777a56be37eSJohn Baldwin } 778a56be37eSJohn Baldwin 779a56be37eSJohn Baldwin void 780039644ecSEd Maste ktrgenio(int fd, enum uio_rw rw, struct uio *uio, int error) 781df8bae1dSRodney W. Grimes { 782ea3fc8e4SJohn Baldwin struct ktr_request *req; 783ea3fc8e4SJohn Baldwin struct ktr_genio *ktg; 784b92584a6SJohn Baldwin int datalen; 785b92584a6SJohn Baldwin char *buf; 786df8bae1dSRodney W. Grimes 78747ad4f2dSKyle Evans if (error != 0 && (rw == UIO_READ || error == EFAULT)) { 78861cc4830SAlfredo Mazzinghi freeuio(uio); 789df8bae1dSRodney W. Grimes return; 790552afd9cSPoul-Henning Kamp } 791b92584a6SJohn Baldwin uio->uio_offset = 0; 792b92584a6SJohn Baldwin uio->uio_rw = UIO_WRITE; 793526d0bd5SKonstantin Belousov datalen = MIN(uio->uio_resid, ktr_geniosize); 794a163d034SWarner Losh buf = malloc(datalen, M_KTRACE, M_WAITOK); 795552afd9cSPoul-Henning Kamp error = uiomove(buf, datalen, uio); 79661cc4830SAlfredo Mazzinghi freeuio(uio); 797552afd9cSPoul-Henning Kamp if (error) { 798b92584a6SJohn Baldwin free(buf, M_KTRACE); 799ea3fc8e4SJohn Baldwin return; 800b92584a6SJohn Baldwin } 801b92584a6SJohn Baldwin req = ktr_getrequest(KTR_GENIO); 802b92584a6SJohn Baldwin if (req == NULL) { 803b92584a6SJohn Baldwin free(buf, M_KTRACE); 804b92584a6SJohn Baldwin return; 805b92584a6SJohn Baldwin } 806ea3fc8e4SJohn Baldwin ktg = &req->ktr_data.ktr_genio; 807ea3fc8e4SJohn Baldwin ktg->ktr_fd = fd; 808ea3fc8e4SJohn Baldwin ktg->ktr_rw = rw; 809b92584a6SJohn Baldwin req->ktr_header.ktr_len = datalen; 810d977a583SRobert Watson req->ktr_buffer = buf; 8112c255e9dSRobert Watson ktr_submitrequest(curthread, req); 812df8bae1dSRodney W. Grimes } 813df8bae1dSRodney W. Grimes 81426f9a767SRodney W. Grimes void 815039644ecSEd Maste ktrpsig(int sig, sig_t action, sigset_t *mask, int code) 816df8bae1dSRodney W. Grimes { 81722ec0406SDmitry Chagin struct thread *td = curthread; 818ea3fc8e4SJohn Baldwin struct ktr_request *req; 819ea3fc8e4SJohn Baldwin struct ktr_psig *kp; 820df8bae1dSRodney W. Grimes 821ea3fc8e4SJohn Baldwin req = ktr_getrequest(KTR_PSIG); 822ea3fc8e4SJohn Baldwin if (req == NULL) 823ea3fc8e4SJohn Baldwin return; 824ea3fc8e4SJohn Baldwin kp = &req->ktr_data.ktr_psig; 825ea3fc8e4SJohn Baldwin kp->signo = (char)sig; 826ea3fc8e4SJohn Baldwin kp->action = action; 827ea3fc8e4SJohn Baldwin kp->mask = *mask; 828ea3fc8e4SJohn Baldwin kp->code = code; 82922ec0406SDmitry Chagin ktr_enqueuerequest(td, req); 83022ec0406SDmitry Chagin ktrace_exit(td); 831df8bae1dSRodney W. Grimes } 832df8bae1dSRodney W. Grimes 83326f9a767SRodney W. Grimes void 834039644ecSEd Maste ktrcsw(int out, int user, const char *wmesg) 835df8bae1dSRodney W. Grimes { 83622ec0406SDmitry Chagin struct thread *td = curthread; 837ea3fc8e4SJohn Baldwin struct ktr_request *req; 838ea3fc8e4SJohn Baldwin struct ktr_csw *kc; 839df8bae1dSRodney W. Grimes 840ad738f37SMatt Macy if (__predict_false(curthread->td_pflags & TDP_INKTRACE)) 841ad738f37SMatt Macy return; 842ad738f37SMatt Macy 843ea3fc8e4SJohn Baldwin req = ktr_getrequest(KTR_CSW); 844ea3fc8e4SJohn Baldwin if (req == NULL) 845ea3fc8e4SJohn Baldwin return; 846ea3fc8e4SJohn Baldwin kc = &req->ktr_data.ktr_csw; 847ea3fc8e4SJohn Baldwin kc->out = out; 848ea3fc8e4SJohn Baldwin kc->user = user; 84988bf5036SJohn Baldwin if (wmesg != NULL) 85088bf5036SJohn Baldwin strlcpy(kc->wmesg, wmesg, sizeof(kc->wmesg)); 85188bf5036SJohn Baldwin else 85288bf5036SJohn Baldwin bzero(kc->wmesg, sizeof(kc->wmesg)); 85322ec0406SDmitry Chagin ktr_enqueuerequest(td, req); 85422ec0406SDmitry Chagin ktrace_exit(td); 855df8bae1dSRodney W. Grimes } 85660e15db9SDag-Erling Smørgrav 85760e15db9SDag-Erling Smørgrav void 858ffb66079SJohn Baldwin ktrstruct(const char *name, const void *data, size_t datalen) 85960e15db9SDag-Erling Smørgrav { 86060e15db9SDag-Erling Smørgrav struct ktr_request *req; 8614dd3a21fSMateusz Guzik char *buf; 8624dd3a21fSMateusz Guzik size_t buflen, namelen; 86360e15db9SDag-Erling Smørgrav 864ad738f37SMatt Macy if (__predict_false(curthread->td_pflags & TDP_INKTRACE)) 865ad738f37SMatt Macy return; 866ad738f37SMatt Macy 8674dd3a21fSMateusz Guzik if (data == NULL) 86860e15db9SDag-Erling Smørgrav datalen = 0; 8694dd3a21fSMateusz Guzik namelen = strlen(name) + 1; 8704dd3a21fSMateusz Guzik buflen = namelen + datalen; 87160e15db9SDag-Erling Smørgrav buf = malloc(buflen, M_KTRACE, M_WAITOK); 872a3052d6eSJohn Baldwin strcpy(buf, name); 8734dd3a21fSMateusz Guzik bcopy(data, buf + namelen, datalen); 87460e15db9SDag-Erling Smørgrav if ((req = ktr_getrequest(KTR_STRUCT)) == NULL) { 87560e15db9SDag-Erling Smørgrav free(buf, M_KTRACE); 87660e15db9SDag-Erling Smørgrav return; 87760e15db9SDag-Erling Smørgrav } 87860e15db9SDag-Erling Smørgrav req->ktr_buffer = buf; 87960e15db9SDag-Erling Smørgrav req->ktr_header.ktr_len = buflen; 88060e15db9SDag-Erling Smørgrav ktr_submitrequest(curthread, req); 88160e15db9SDag-Erling Smørgrav } 882c601ad8eSDag-Erling Smørgrav 883c601ad8eSDag-Erling Smørgrav void 8840a1427c5SMateusz Guzik ktrstruct_error(const char *name, const void *data, size_t datalen, int error) 8850a1427c5SMateusz Guzik { 8860a1427c5SMateusz Guzik 8870a1427c5SMateusz Guzik if (error == 0) 8880a1427c5SMateusz Guzik ktrstruct(name, data, datalen); 8890a1427c5SMateusz Guzik } 8900a1427c5SMateusz Guzik 8910a1427c5SMateusz Guzik void 892ffb66079SJohn Baldwin ktrstructarray(const char *name, enum uio_seg seg, const void *data, 893ffb66079SJohn Baldwin int num_items, size_t struct_size) 894ffb66079SJohn Baldwin { 895ffb66079SJohn Baldwin struct ktr_request *req; 896ffb66079SJohn Baldwin struct ktr_struct_array *ksa; 897ffb66079SJohn Baldwin char *buf; 898ffb66079SJohn Baldwin size_t buflen, datalen, namelen; 899ffb66079SJohn Baldwin int max_items; 900ffb66079SJohn Baldwin 901ad738f37SMatt Macy if (__predict_false(curthread->td_pflags & TDP_INKTRACE)) 902ad738f37SMatt Macy return; 903f8851007SMark Johnston if (num_items < 0) 904f8851007SMark Johnston return; 905ad738f37SMatt Macy 906ffb66079SJohn Baldwin /* Trim array length to genio size. */ 907ffb66079SJohn Baldwin max_items = ktr_geniosize / struct_size; 908ffb66079SJohn Baldwin if (num_items > max_items) { 909ffb66079SJohn Baldwin if (max_items == 0) 910ffb66079SJohn Baldwin num_items = 1; 911ffb66079SJohn Baldwin else 912ffb66079SJohn Baldwin num_items = max_items; 913ffb66079SJohn Baldwin } 914ffb66079SJohn Baldwin datalen = num_items * struct_size; 915ffb66079SJohn Baldwin 916ffb66079SJohn Baldwin if (data == NULL) 917ffb66079SJohn Baldwin datalen = 0; 918ffb66079SJohn Baldwin 919ffb66079SJohn Baldwin namelen = strlen(name) + 1; 920ffb66079SJohn Baldwin buflen = namelen + datalen; 921ffb66079SJohn Baldwin buf = malloc(buflen, M_KTRACE, M_WAITOK); 922ffb66079SJohn Baldwin strcpy(buf, name); 923ffb66079SJohn Baldwin if (seg == UIO_SYSSPACE) 924ffb66079SJohn Baldwin bcopy(data, buf + namelen, datalen); 925ffb66079SJohn Baldwin else { 926ffb66079SJohn Baldwin if (copyin(data, buf + namelen, datalen) != 0) { 927ffb66079SJohn Baldwin free(buf, M_KTRACE); 928ffb66079SJohn Baldwin return; 929ffb66079SJohn Baldwin } 930ffb66079SJohn Baldwin } 931ffb66079SJohn Baldwin if ((req = ktr_getrequest(KTR_STRUCT_ARRAY)) == NULL) { 932ffb66079SJohn Baldwin free(buf, M_KTRACE); 933ffb66079SJohn Baldwin return; 934ffb66079SJohn Baldwin } 935ffb66079SJohn Baldwin ksa = &req->ktr_data.ktr_struct_array; 936ffb66079SJohn Baldwin ksa->struct_size = struct_size; 937ffb66079SJohn Baldwin req->ktr_buffer = buf; 938ffb66079SJohn Baldwin req->ktr_header.ktr_len = buflen; 939ffb66079SJohn Baldwin ktr_submitrequest(curthread, req); 940ffb66079SJohn Baldwin } 941ffb66079SJohn Baldwin 942ffb66079SJohn Baldwin void 9439bec8413SJake Freeland ktrcapfail(enum ktr_cap_violation type, const void *data) 944c601ad8eSDag-Erling Smørgrav { 945c601ad8eSDag-Erling Smørgrav struct thread *td = curthread; 946c601ad8eSDag-Erling Smørgrav struct ktr_request *req; 947c601ad8eSDag-Erling Smørgrav struct ktr_cap_fail *kcf; 9489bec8413SJake Freeland union ktr_cap_data *kcd; 949c601ad8eSDag-Erling Smørgrav 9509bec8413SJake Freeland if (__predict_false(td->td_pflags & TDP_INKTRACE)) 9519bec8413SJake Freeland return; 9529bec8413SJake Freeland if (type != CAPFAIL_SYSCALL && 9539bec8413SJake Freeland (td->td_sa.callp->sy_flags & SYF_CAPENABLED) == 0) 954ad738f37SMatt Macy return; 955ad738f37SMatt Macy 956c601ad8eSDag-Erling Smørgrav req = ktr_getrequest(KTR_CAPFAIL); 957c601ad8eSDag-Erling Smørgrav if (req == NULL) 958c601ad8eSDag-Erling Smørgrav return; 959c601ad8eSDag-Erling Smørgrav kcf = &req->ktr_data.ktr_cap_fail; 960e141be6fSDag-Erling Smørgrav kcf->cap_type = type; 9619bec8413SJake Freeland kcf->cap_code = td->td_sa.code; 9629bec8413SJake Freeland kcf->cap_svflags = td->td_proc->p_sysent->sv_flags; 9639bec8413SJake Freeland if (data != NULL) { 9649bec8413SJake Freeland kcd = &kcf->cap_data; 9659bec8413SJake Freeland switch (type) { 9669bec8413SJake Freeland case CAPFAIL_NOTCAPABLE: 9679bec8413SJake Freeland case CAPFAIL_INCREASE: 9689bec8413SJake Freeland kcd->cap_needed = *(const cap_rights_t *)data; 9699bec8413SJake Freeland kcd->cap_held = *((const cap_rights_t *)data + 1); 9709bec8413SJake Freeland break; 9719bec8413SJake Freeland case CAPFAIL_SYSCALL: 9729bec8413SJake Freeland case CAPFAIL_SIGNAL: 9739bec8413SJake Freeland case CAPFAIL_PROTO: 9749bec8413SJake Freeland kcd->cap_int = *(const int *)data; 9759bec8413SJake Freeland break; 9769bec8413SJake Freeland case CAPFAIL_SOCKADDR: 9779bec8413SJake Freeland kcd->cap_sockaddr = *(const struct sockaddr *)data; 9789bec8413SJake Freeland break; 9799bec8413SJake Freeland case CAPFAIL_NAMEI: 9809bec8413SJake Freeland strlcpy(kcd->cap_path, data, MAXPATHLEN); 9819bec8413SJake Freeland break; 9829bec8413SJake Freeland case CAPFAIL_CPUSET: 9839bec8413SJake Freeland default: 9849bec8413SJake Freeland break; 9859bec8413SJake Freeland } 9869bec8413SJake Freeland } 987c601ad8eSDag-Erling Smørgrav ktr_enqueuerequest(td, req); 988c601ad8eSDag-Erling Smørgrav ktrace_exit(td); 989c601ad8eSDag-Erling Smørgrav } 99035818d2eSJohn Baldwin 99135818d2eSJohn Baldwin void 992039644ecSEd Maste ktrfault(vm_offset_t vaddr, int type) 99335818d2eSJohn Baldwin { 99435818d2eSJohn Baldwin struct thread *td = curthread; 99535818d2eSJohn Baldwin struct ktr_request *req; 99635818d2eSJohn Baldwin struct ktr_fault *kf; 99735818d2eSJohn Baldwin 998ad738f37SMatt Macy if (__predict_false(curthread->td_pflags & TDP_INKTRACE)) 999ad738f37SMatt Macy return; 1000ad738f37SMatt Macy 100135818d2eSJohn Baldwin req = ktr_getrequest(KTR_FAULT); 100235818d2eSJohn Baldwin if (req == NULL) 100335818d2eSJohn Baldwin return; 100435818d2eSJohn Baldwin kf = &req->ktr_data.ktr_fault; 100535818d2eSJohn Baldwin kf->vaddr = vaddr; 100635818d2eSJohn Baldwin kf->type = type; 100735818d2eSJohn Baldwin ktr_enqueuerequest(td, req); 100835818d2eSJohn Baldwin ktrace_exit(td); 100935818d2eSJohn Baldwin } 101035818d2eSJohn Baldwin 101135818d2eSJohn Baldwin void 1012039644ecSEd Maste ktrfaultend(int result) 101335818d2eSJohn Baldwin { 101435818d2eSJohn Baldwin struct thread *td = curthread; 101535818d2eSJohn Baldwin struct ktr_request *req; 101635818d2eSJohn Baldwin struct ktr_faultend *kf; 101735818d2eSJohn Baldwin 1018ad738f37SMatt Macy if (__predict_false(curthread->td_pflags & TDP_INKTRACE)) 1019ad738f37SMatt Macy return; 1020ad738f37SMatt Macy 102135818d2eSJohn Baldwin req = ktr_getrequest(KTR_FAULTEND); 102235818d2eSJohn Baldwin if (req == NULL) 102335818d2eSJohn Baldwin return; 102435818d2eSJohn Baldwin kf = &req->ktr_data.ktr_faultend; 102535818d2eSJohn Baldwin kf->result = result; 102635818d2eSJohn Baldwin ktr_enqueuerequest(td, req); 102735818d2eSJohn Baldwin ktrace_exit(td); 102835818d2eSJohn Baldwin } 102964cc6a13SJohn Baldwin #endif /* KTRACE */ 1030df8bae1dSRodney W. Grimes 1031df8bae1dSRodney W. Grimes /* Interface and common routines */ 1032df8bae1dSRodney W. Grimes 1033d2d3e875SBruce Evans #ifndef _SYS_SYSPROTO_H_ 1034df8bae1dSRodney W. Grimes struct ktrace_args { 1035df8bae1dSRodney W. Grimes char *fname; 1036df8bae1dSRodney W. Grimes int ops; 1037df8bae1dSRodney W. Grimes int facs; 1038df8bae1dSRodney W. Grimes int pid; 1039df8bae1dSRodney W. Grimes }; 1040d2d3e875SBruce Evans #endif 1041df8bae1dSRodney W. Grimes /* ARGSUSED */ 104226f9a767SRodney W. Grimes int 1043039644ecSEd Maste sys_ktrace(struct thread *td, struct ktrace_args *uap) 1044df8bae1dSRodney W. Grimes { 1045db6a20e2SGarrett Wollman #ifdef KTRACE 1046039644ecSEd Maste struct vnode *vp = NULL; 1047039644ecSEd Maste struct proc *p; 1048df8bae1dSRodney W. Grimes struct pgrp *pg; 1049df8bae1dSRodney W. Grimes int facs = uap->facs & ~KTRFAC_ROOT; 1050df8bae1dSRodney W. Grimes int ops = KTROP(uap->ops); 1051df8bae1dSRodney W. Grimes int descend = uap->ops & KTRFLAG_DESCEND; 1052f3851b23SMark Johnston int ret = 0; 10535050aa86SKonstantin Belousov int flags, error = 0; 1054df8bae1dSRodney W. Grimes struct nameidata nd; 10551762f674SKonstantin Belousov struct ktr_io_params *kiop, *old_kiop; 1056df8bae1dSRodney W. Grimes 105764cc6a13SJohn Baldwin /* 105864cc6a13SJohn Baldwin * Need something to (un)trace. 105964cc6a13SJohn Baldwin */ 106064cc6a13SJohn Baldwin if (ops != KTROP_CLEARFILE && facs == 0) 106164cc6a13SJohn Baldwin return (EINVAL); 106264cc6a13SJohn Baldwin 10631762f674SKonstantin Belousov kiop = NULL; 1064df8bae1dSRodney W. Grimes if (ops != KTROP_CLEAR) { 1065df8bae1dSRodney W. Grimes /* 1066df8bae1dSRodney W. Grimes * an operation which requires a file argument. 1067df8bae1dSRodney W. Grimes */ 10687e1d3eefSMateusz Guzik NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->fname); 1069e6796b67SKirk McKusick flags = FREAD | FWRITE | O_NOFOLLOW; 10709e223287SKonstantin Belousov error = vn_open(&nd, &flags, 0, NULL); 1071e4b16f2fSMark Johnston if (error) 1072df8bae1dSRodney W. Grimes return (error); 1073bb92cd7bSMateusz Guzik NDFREE_PNBUF(&nd); 1074df8bae1dSRodney W. Grimes vp = nd.ni_vp; 1075b249ce48SMateusz Guzik VOP_UNLOCK(vp); 1076df8bae1dSRodney W. Grimes if (vp->v_type != VREG) { 1077a854ed98SJohn Baldwin (void)vn_close(vp, FREAD|FWRITE, td->td_ucred, td); 1078df8bae1dSRodney W. Grimes return (EACCES); 1079df8bae1dSRodney W. Grimes } 10801762f674SKonstantin Belousov kiop = ktr_io_params_alloc(td, vp); 1081df8bae1dSRodney W. Grimes } 1082e4b16f2fSMark Johnston 1083df8bae1dSRodney W. Grimes /* 108479deba82SMatthew Dillon * Clear all uses of the tracefile. 1085df8bae1dSRodney W. Grimes */ 1086e4b16f2fSMark Johnston ktrace_enter(td); 1087df8bae1dSRodney W. Grimes if (ops == KTROP_CLEARFILE) { 10881762f674SKonstantin Belousov restart: 10891005a129SJohn Baldwin sx_slock(&allproc_lock); 10904f506694SXin LI FOREACH_PROC_IN_SYSTEM(p) { 10911762f674SKonstantin Belousov old_kiop = NULL; 1092a7ff7443SJohn Baldwin PROC_LOCK(p); 10931762f674SKonstantin Belousov if (p->p_ktrioparms != NULL && 10941762f674SKonstantin Belousov p->p_ktrioparms->vp == vp) { 1095ea3fc8e4SJohn Baldwin if (ktrcanset(td, p)) { 1096ea3fc8e4SJohn Baldwin mtx_lock(&ktrace_mtx); 10971762f674SKonstantin Belousov old_kiop = ktr_freeproc(p); 1098ea3fc8e4SJohn Baldwin mtx_unlock(&ktrace_mtx); 109951fd6380SMike Pritchard } else 1100df8bae1dSRodney W. Grimes error = EPERM; 1101df8bae1dSRodney W. Grimes } 1102a7ff7443SJohn Baldwin PROC_UNLOCK(p); 11031762f674SKonstantin Belousov if (old_kiop != NULL) { 11041762f674SKonstantin Belousov sx_sunlock(&allproc_lock); 11051762f674SKonstantin Belousov ktr_io_params_free(old_kiop); 11061762f674SKonstantin Belousov goto restart; 11071762f674SKonstantin Belousov } 110879deba82SMatthew Dillon } 11091005a129SJohn Baldwin sx_sunlock(&allproc_lock); 1110df8bae1dSRodney W. Grimes goto done; 1111df8bae1dSRodney W. Grimes } 1112df8bae1dSRodney W. Grimes /* 1113df8bae1dSRodney W. Grimes * do it 1114df8bae1dSRodney W. Grimes */ 111564cc6a13SJohn Baldwin sx_slock(&proctree_lock); 1116df8bae1dSRodney W. Grimes if (uap->pid < 0) { 1117df8bae1dSRodney W. Grimes /* 1118df8bae1dSRodney W. Grimes * by process group 1119df8bae1dSRodney W. Grimes */ 1120df8bae1dSRodney W. Grimes pg = pgfind(-uap->pid); 1121df8bae1dSRodney W. Grimes if (pg == NULL) { 1122ba626c1dSJohn Baldwin sx_sunlock(&proctree_lock); 1123df8bae1dSRodney W. Grimes error = ESRCH; 1124df8bae1dSRodney W. Grimes goto done; 1125df8bae1dSRodney W. Grimes } 1126f3851b23SMark Johnston 1127f591779bSSeigo Tanimura /* 1128f591779bSSeigo Tanimura * ktrops() may call vrele(). Lock pg_members 1129ba626c1dSJohn Baldwin * by the proctree_lock rather than pg_mtx. 1130f591779bSSeigo Tanimura */ 1131f591779bSSeigo Tanimura PGRP_UNLOCK(pg); 1132f3851b23SMark Johnston if (LIST_EMPTY(&pg->pg_members)) { 1133f3851b23SMark Johnston sx_sunlock(&proctree_lock); 1134f3851b23SMark Johnston error = ESRCH; 1135f3851b23SMark Johnston goto done; 1136f3851b23SMark Johnston } 1137400a74bfSPawel Jakub Dawidek LIST_FOREACH(p, &pg->pg_members, p_pglist) { 1138400a74bfSPawel Jakub Dawidek PROC_LOCK(p); 1139df8bae1dSRodney W. Grimes if (descend) 11401762f674SKonstantin Belousov ret |= ktrsetchildren(td, p, ops, facs, kiop); 1141df8bae1dSRodney W. Grimes else 11421762f674SKonstantin Belousov ret |= ktrops(td, p, ops, facs, kiop); 1143400a74bfSPawel Jakub Dawidek } 1144df8bae1dSRodney W. Grimes } else { 1145df8bae1dSRodney W. Grimes /* 1146df8bae1dSRodney W. Grimes * by pid 1147df8bae1dSRodney W. Grimes */ 1148df8bae1dSRodney W. Grimes p = pfind(uap->pid); 1149f3851b23SMark Johnston if (p == NULL) { 1150df8bae1dSRodney W. Grimes error = ESRCH; 1151b0d9aeddSPawel Jakub Dawidek sx_sunlock(&proctree_lock); 11524eb7c9f6SPawel Jakub Dawidek goto done; 1153b0d9aeddSPawel Jakub Dawidek } 1154df8bae1dSRodney W. Grimes if (descend) 11551762f674SKonstantin Belousov ret |= ktrsetchildren(td, p, ops, facs, kiop); 1156df8bae1dSRodney W. Grimes else 11571762f674SKonstantin Belousov ret |= ktrops(td, p, ops, facs, kiop); 1158df8bae1dSRodney W. Grimes } 115964cc6a13SJohn Baldwin sx_sunlock(&proctree_lock); 1160df8bae1dSRodney W. Grimes if (!ret) 1161df8bae1dSRodney W. Grimes error = EPERM; 1162df8bae1dSRodney W. Grimes done: 11631762f674SKonstantin Belousov if (kiop != NULL) { 11641762f674SKonstantin Belousov mtx_lock(&ktrace_mtx); 11651762f674SKonstantin Belousov kiop = ktr_io_params_rele(kiop); 11661762f674SKonstantin Belousov mtx_unlock(&ktrace_mtx); 11671762f674SKonstantin Belousov ktr_io_params_free(kiop); 11681762f674SKonstantin Belousov } 11692c255e9dSRobert Watson ktrace_exit(td); 1170df8bae1dSRodney W. Grimes return (error); 117164cc6a13SJohn Baldwin #else /* !KTRACE */ 117264cc6a13SJohn Baldwin return (ENOSYS); 117364cc6a13SJohn Baldwin #endif /* KTRACE */ 1174df8bae1dSRodney W. Grimes } 1175df8bae1dSRodney W. Grimes 1176e6c4b9baSPoul-Henning Kamp /* ARGSUSED */ 1177e6c4b9baSPoul-Henning Kamp int 1178039644ecSEd Maste sys_utrace(struct thread *td, struct utrace_args *uap) 1179e6c4b9baSPoul-Henning Kamp { 1180b40ce416SJulian Elischer 1181e6c4b9baSPoul-Henning Kamp #ifdef KTRACE 1182ea3fc8e4SJohn Baldwin struct ktr_request *req; 11837f05b035SAlfred Perlstein void *cp; 1184c9e7d28eSJohn Baldwin int error; 1185e6c4b9baSPoul-Henning Kamp 1186c9e7d28eSJohn Baldwin if (!KTRPOINT(td, KTR_USER)) 1187c9e7d28eSJohn Baldwin return (0); 1188bdfa4f04SAlfred Perlstein if (uap->len > KTR_USER_MAXLEN) 11890bad156aSAlfred Perlstein return (EINVAL); 1190a163d034SWarner Losh cp = malloc(uap->len, M_KTRACE, M_WAITOK); 1191c9e7d28eSJohn Baldwin error = copyin(uap->addr, cp, uap->len); 119250c22331SPoul-Henning Kamp if (error) { 119350c22331SPoul-Henning Kamp free(cp, M_KTRACE); 1194c9e7d28eSJohn Baldwin return (error); 119550c22331SPoul-Henning Kamp } 1196ea3fc8e4SJohn Baldwin req = ktr_getrequest(KTR_USER); 119750c22331SPoul-Henning Kamp if (req == NULL) { 119850c22331SPoul-Henning Kamp free(cp, M_KTRACE); 1199b10221ffSJoseph Koshy return (ENOMEM); 120050c22331SPoul-Henning Kamp } 1201d977a583SRobert Watson req->ktr_buffer = cp; 1202ea3fc8e4SJohn Baldwin req->ktr_header.ktr_len = uap->len; 12032c255e9dSRobert Watson ktr_submitrequest(td, req); 1204e6c4b9baSPoul-Henning Kamp return (0); 120564cc6a13SJohn Baldwin #else /* !KTRACE */ 1206e6c4b9baSPoul-Henning Kamp return (ENOSYS); 120764cc6a13SJohn Baldwin #endif /* KTRACE */ 1208e6c4b9baSPoul-Henning Kamp } 1209e6c4b9baSPoul-Henning Kamp 1210db6a20e2SGarrett Wollman #ifdef KTRACE 121187b6de2bSPoul-Henning Kamp static int 12121762f674SKonstantin Belousov ktrops(struct thread *td, struct proc *p, int ops, int facs, 12131762f674SKonstantin Belousov struct ktr_io_params *new_kiop) 1214df8bae1dSRodney W. Grimes { 12151762f674SKonstantin Belousov struct ktr_io_params *old_kiop; 1216df8bae1dSRodney W. Grimes 1217fe41d17aSJohn Baldwin PROC_LOCK_ASSERT(p, MA_OWNED); 1218a7ff7443SJohn Baldwin if (!ktrcanset(td, p)) { 1219a7ff7443SJohn Baldwin PROC_UNLOCK(p); 1220df8bae1dSRodney W. Grimes return (0); 1221a7ff7443SJohn Baldwin } 1222283e60fbSMark Johnston if ((ops == KTROP_SET && p->p_state == PRS_NEW) || 1223283e60fbSMark Johnston p_cansee(td, p) != 0) { 1224f3851b23SMark Johnston /* 1225f3851b23SMark Johnston * Disallow setting trace points if the process is being born. 1226f3851b23SMark Johnston * This avoids races with trace point inheritance in 1227f3851b23SMark Johnston * ktrprocfork(). 1228f3851b23SMark Johnston */ 1229f3851b23SMark Johnston PROC_UNLOCK(p); 1230f3851b23SMark Johnston return (0); 1231f3851b23SMark Johnston } 1232f3851b23SMark Johnston if ((p->p_flag & P_WEXIT) != 0) { 1233f3851b23SMark Johnston /* 1234f3851b23SMark Johnston * There's nothing to do if the process is exiting, but avoid 1235f3851b23SMark Johnston * signaling an error. 1236f3851b23SMark Johnston */ 1237fe41d17aSJohn Baldwin PROC_UNLOCK(p); 1238fe41d17aSJohn Baldwin return (1); 1239fe41d17aSJohn Baldwin } 12401762f674SKonstantin Belousov old_kiop = NULL; 1241ea3fc8e4SJohn Baldwin mtx_lock(&ktrace_mtx); 1242df8bae1dSRodney W. Grimes if (ops == KTROP_SET) { 12431762f674SKonstantin Belousov if (p->p_ktrioparms != NULL && 12441762f674SKonstantin Belousov p->p_ktrioparms->vp != new_kiop->vp) { 12451762f674SKonstantin Belousov /* if trace file already in use, relinquish below */ 12461762f674SKonstantin Belousov old_kiop = ktr_io_params_rele(p->p_ktrioparms); 12471762f674SKonstantin Belousov p->p_ktrioparms = NULL; 1248a5881ea5SJohn Baldwin } 12491762f674SKonstantin Belousov if (p->p_ktrioparms == NULL) { 12501762f674SKonstantin Belousov p->p_ktrioparms = new_kiop; 12511762f674SKonstantin Belousov ktr_io_params_ref(new_kiop); 1252df8bae1dSRodney W. Grimes } 1253df8bae1dSRodney W. Grimes p->p_traceflag |= facs; 125432f9753cSRobert Watson if (priv_check(td, PRIV_KTRACE) == 0) 1255df8bae1dSRodney W. Grimes p->p_traceflag |= KTRFAC_ROOT; 1256df8bae1dSRodney W. Grimes } else { 1257df8bae1dSRodney W. Grimes /* KTROP_CLEAR */ 1258d680caabSJohn Baldwin if (((p->p_traceflag &= ~facs) & KTRFAC_MASK) == 0) 1259df8bae1dSRodney W. Grimes /* no more tracing */ 12601762f674SKonstantin Belousov old_kiop = ktr_freeproc(p); 1261a7ff7443SJohn Baldwin } 1262ea3fc8e4SJohn Baldwin mtx_unlock(&ktrace_mtx); 126322ec0406SDmitry Chagin if ((p->p_traceflag & KTRFAC_MASK) != 0) 126422ec0406SDmitry Chagin ktrprocctor_entered(td, p); 1265a7ff7443SJohn Baldwin PROC_UNLOCK(p); 12661762f674SKonstantin Belousov ktr_io_params_free(old_kiop); 1267df8bae1dSRodney W. Grimes 1268df8bae1dSRodney W. Grimes return (1); 1269df8bae1dSRodney W. Grimes } 1270df8bae1dSRodney W. Grimes 127187b6de2bSPoul-Henning Kamp static int 1272039644ecSEd Maste ktrsetchildren(struct thread *td, struct proc *top, int ops, int facs, 12731762f674SKonstantin Belousov struct ktr_io_params *new_kiop) 1274df8bae1dSRodney W. Grimes { 1275039644ecSEd Maste struct proc *p; 1276039644ecSEd Maste int ret = 0; 1277df8bae1dSRodney W. Grimes 1278df8bae1dSRodney W. Grimes p = top; 1279fe41d17aSJohn Baldwin PROC_LOCK_ASSERT(p, MA_OWNED); 128064cc6a13SJohn Baldwin sx_assert(&proctree_lock, SX_LOCKED); 1281df8bae1dSRodney W. Grimes for (;;) { 12821762f674SKonstantin Belousov ret |= ktrops(td, p, ops, facs, new_kiop); 1283df8bae1dSRodney W. Grimes /* 1284df8bae1dSRodney W. Grimes * If this process has children, descend to them next, 1285df8bae1dSRodney W. Grimes * otherwise do any siblings, and if done with this level, 1286df8bae1dSRodney W. Grimes * follow back up the tree (but not past top). 1287df8bae1dSRodney W. Grimes */ 12882e3c8fcbSPoul-Henning Kamp if (!LIST_EMPTY(&p->p_children)) 12892e3c8fcbSPoul-Henning Kamp p = LIST_FIRST(&p->p_children); 1290df8bae1dSRodney W. Grimes else for (;;) { 129164cc6a13SJohn Baldwin if (p == top) 1292df8bae1dSRodney W. Grimes return (ret); 12932e3c8fcbSPoul-Henning Kamp if (LIST_NEXT(p, p_sibling)) { 12942e3c8fcbSPoul-Henning Kamp p = LIST_NEXT(p, p_sibling); 1295df8bae1dSRodney W. Grimes break; 1296df8bae1dSRodney W. Grimes } 1297b75356e1SJeffrey Hsu p = p->p_pptr; 1298df8bae1dSRodney W. Grimes } 1299fe41d17aSJohn Baldwin PROC_LOCK(p); 1300df8bae1dSRodney W. Grimes } 1301df8bae1dSRodney W. Grimes /*NOTREACHED*/ 1302df8bae1dSRodney W. Grimes } 1303df8bae1dSRodney W. Grimes 130487b6de2bSPoul-Henning Kamp static void 13052c255e9dSRobert Watson ktr_writerequest(struct thread *td, struct ktr_request *req) 1306df8bae1dSRodney W. Grimes { 1307fc369a35SKonstantin Belousov struct ktr_io_params *kiop, *kiop1; 1308ea3fc8e4SJohn Baldwin struct ktr_header *kth; 1309ea3fc8e4SJohn Baldwin struct vnode *vp; 1310ea3fc8e4SJohn Baldwin struct proc *p; 1311ea3fc8e4SJohn Baldwin struct ucred *cred; 1312df8bae1dSRodney W. Grimes struct uio auio; 1313ea3fc8e4SJohn Baldwin struct iovec aiov[3]; 1314f2a2857bSKirk McKusick struct mount *mp; 131502645b88SKonstantin Belousov off_t lim; 1316a6144f71SKonstantin Belousov int datalen, buflen; 13175050aa86SKonstantin Belousov int error; 1318df8bae1dSRodney W. Grimes 13191762f674SKonstantin Belousov p = td->td_proc; 13201762f674SKonstantin Belousov 13212c255e9dSRobert Watson /* 1322fc369a35SKonstantin Belousov * We reference the kiop for use in I/O in case ktrace is 13232c255e9dSRobert Watson * disabled on the process as we write out the request. 13242c255e9dSRobert Watson */ 13252c255e9dSRobert Watson mtx_lock(&ktrace_mtx); 13261762f674SKonstantin Belousov kiop = p->p_ktrioparms; 13272c255e9dSRobert Watson 1328ea3fc8e4SJohn Baldwin /* 13291762f674SKonstantin Belousov * If kiop is NULL, it has been cleared out from under this 13301762f674SKonstantin Belousov * request, so just drop it. 1331ea3fc8e4SJohn Baldwin */ 13321762f674SKonstantin Belousov if (kiop == NULL) { 1333118258f5SBjoern A. Zeeb mtx_unlock(&ktrace_mtx); 1334df8bae1dSRodney W. Grimes return; 13352c255e9dSRobert Watson } 13361762f674SKonstantin Belousov 1337fc369a35SKonstantin Belousov ktr_io_params_ref(kiop); 13381762f674SKonstantin Belousov vp = kiop->vp; 13391762f674SKonstantin Belousov cred = kiop->cr; 134002645b88SKonstantin Belousov lim = kiop->lim; 13411762f674SKonstantin Belousov 13422c255e9dSRobert Watson KASSERT(cred != NULL, ("ktr_writerequest: cred == NULL")); 1343118258f5SBjoern A. Zeeb mtx_unlock(&ktrace_mtx); 13442c255e9dSRobert Watson 1345ea3fc8e4SJohn Baldwin kth = &req->ktr_header; 1346fc90f3a2SDmitry Chagin KASSERT(((u_short)kth->ktr_type & ~KTR_TYPE) < nitems(data_lengths), 1347a56be37eSJohn Baldwin ("data_lengths array overflow")); 1348fc90f3a2SDmitry Chagin datalen = data_lengths[(u_short)kth->ktr_type & ~KTR_TYPE]; 1349ea3fc8e4SJohn Baldwin buflen = kth->ktr_len; 1350df8bae1dSRodney W. Grimes auio.uio_iov = &aiov[0]; 1351df8bae1dSRodney W. Grimes auio.uio_offset = 0; 1352df8bae1dSRodney W. Grimes auio.uio_segflg = UIO_SYSSPACE; 1353df8bae1dSRodney W. Grimes auio.uio_rw = UIO_WRITE; 1354df8bae1dSRodney W. Grimes aiov[0].iov_base = (caddr_t)kth; 1355df8bae1dSRodney W. Grimes aiov[0].iov_len = sizeof(struct ktr_header); 1356df8bae1dSRodney W. Grimes auio.uio_resid = sizeof(struct ktr_header); 1357df8bae1dSRodney W. Grimes auio.uio_iovcnt = 1; 1358ea3fc8e4SJohn Baldwin auio.uio_td = td; 1359ea3fc8e4SJohn Baldwin if (datalen != 0) { 1360ea3fc8e4SJohn Baldwin aiov[1].iov_base = (caddr_t)&req->ktr_data; 1361ea3fc8e4SJohn Baldwin aiov[1].iov_len = datalen; 1362ea3fc8e4SJohn Baldwin auio.uio_resid += datalen; 1363df8bae1dSRodney W. Grimes auio.uio_iovcnt++; 1364ea3fc8e4SJohn Baldwin kth->ktr_len += datalen; 1365ea3fc8e4SJohn Baldwin } 1366ea3fc8e4SJohn Baldwin if (buflen != 0) { 1367d977a583SRobert Watson KASSERT(req->ktr_buffer != NULL, ("ktrace: nothing to write")); 1368d977a583SRobert Watson aiov[auio.uio_iovcnt].iov_base = req->ktr_buffer; 1369ea3fc8e4SJohn Baldwin aiov[auio.uio_iovcnt].iov_len = buflen; 1370ea3fc8e4SJohn Baldwin auio.uio_resid += buflen; 1371ea3fc8e4SJohn Baldwin auio.uio_iovcnt++; 1372b92584a6SJohn Baldwin } 13732c255e9dSRobert Watson 1374f2a2857bSKirk McKusick vn_start_write(vp, &mp, V_WAIT); 1375cb05b60aSAttilio Rao vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 137602645b88SKonstantin Belousov td->td_ktr_io_lim = lim; 1377467a273cSRobert Watson #ifdef MAC 137830d239bcSRobert Watson error = mac_vnode_check_write(cred, NOCRED, vp); 1379467a273cSRobert Watson if (error == 0) 1380467a273cSRobert Watson #endif 1381ea3fc8e4SJohn Baldwin error = VOP_WRITE(vp, &auio, IO_UNIT | IO_APPEND, cred); 1382b249ce48SMateusz Guzik VOP_UNLOCK(vp); 1383f2a2857bSKirk McKusick vn_finished_write(mp); 13841762f674SKonstantin Belousov if (error == 0) { 1385fc369a35SKonstantin Belousov mtx_lock(&ktrace_mtx); 1386fc369a35SKonstantin Belousov kiop = ktr_io_params_rele(kiop); 1387fc369a35SKonstantin Belousov mtx_unlock(&ktrace_mtx); 1388fc369a35SKonstantin Belousov ktr_io_params_free(kiop); 1389df8bae1dSRodney W. Grimes return; 1390118258f5SBjoern A. Zeeb } 1391118258f5SBjoern A. Zeeb 1392df8bae1dSRodney W. Grimes /* 1393a6144f71SKonstantin Belousov * If error encountered, give up tracing on this vnode on this 1394a6144f71SKonstantin Belousov * process. Other processes might still be suitable for 1395a6144f71SKonstantin Belousov * writes to this vnode. 1396df8bae1dSRodney W. Grimes */ 1397a6144f71SKonstantin Belousov log(LOG_NOTICE, 1398a6144f71SKonstantin Belousov "ktrace write failed, errno %d, tracing stopped for pid %d\n", 1399a6144f71SKonstantin Belousov error, p->p_pid); 14001762f674SKonstantin Belousov 1401fc369a35SKonstantin Belousov kiop1 = NULL; 1402ea3fc8e4SJohn Baldwin PROC_LOCK(p); 1403ea3fc8e4SJohn Baldwin mtx_lock(&ktrace_mtx); 14041762f674SKonstantin Belousov if (p->p_ktrioparms != NULL && p->p_ktrioparms->vp == vp) 1405fc369a35SKonstantin Belousov kiop1 = ktr_freeproc(p); 1406fc369a35SKonstantin Belousov kiop = ktr_io_params_rele(kiop); 1407ea3fc8e4SJohn Baldwin mtx_unlock(&ktrace_mtx); 1408ea3fc8e4SJohn Baldwin PROC_UNLOCK(p); 1409fc369a35SKonstantin Belousov ktr_io_params_free(kiop1); 14101762f674SKonstantin Belousov ktr_io_params_free(kiop); 1411df8bae1dSRodney W. Grimes } 1412df8bae1dSRodney W. Grimes 1413df8bae1dSRodney W. Grimes /* 1414df8bae1dSRodney W. Grimes * Return true if caller has permission to set the ktracing state 1415df8bae1dSRodney W. Grimes * of target. Essentially, the target can't possess any 1416df8bae1dSRodney W. Grimes * more permissions than the caller. KTRFAC_ROOT signifies that 1417df8bae1dSRodney W. Grimes * root previously set the tracing status on the target process, and 1418df8bae1dSRodney W. Grimes * so, only root may further change it. 1419df8bae1dSRodney W. Grimes */ 142087b6de2bSPoul-Henning Kamp static int 1421039644ecSEd Maste ktrcanset(struct thread *td, struct proc *targetp) 1422df8bae1dSRodney W. Grimes { 1423df8bae1dSRodney W. Grimes 1424a7ff7443SJohn Baldwin PROC_LOCK_ASSERT(targetp, MA_OWNED); 1425a0f75161SRobert Watson if (targetp->p_traceflag & KTRFAC_ROOT && 142632f9753cSRobert Watson priv_check(td, PRIV_KTRACE)) 142775c13541SPoul-Henning Kamp return (0); 1428a0f75161SRobert Watson 1429f44d9e24SJohn Baldwin if (p_candebug(td, targetp) != 0) 1430a0f75161SRobert Watson return (0); 1431a0f75161SRobert Watson 1432df8bae1dSRodney W. Grimes return (1); 1433df8bae1dSRodney W. Grimes } 1434df8bae1dSRodney W. Grimes 1435db6a20e2SGarrett Wollman #endif /* KTRACE */ 1436