The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/ktrace.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: ktrace.h,v 1.57 2011/04/27 00:00:46 joerg Exp $        */
    2 
    3 /*
    4  * Copyright (c) 1988, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   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  * 3. 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.
   18  *
   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
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)ktrace.h    8.2 (Berkeley) 2/19/95
   32  */
   33 
   34 #ifndef _SYS_KTRACE_H_
   35 #define _SYS_KTRACE_H_
   36 
   37 #include <sys/mutex.h>
   38 
   39 /*
   40  * operations to ktrace system call  (KTROP(op))
   41  */
   42 #define KTROP_SET               0       /* set trace points */
   43 #define KTROP_CLEAR             1       /* clear trace points */
   44 #define KTROP_CLEARFILE         2       /* stop all tracing to file */
   45 #define KTROP_MASK              0x3
   46 #define KTROP(o)                ((o)&KTROP_MASK) /* macro to extract operation */
   47 /*
   48  * flags (ORed in with operation)
   49  */
   50 #define KTRFLAG_DESCEND         4       /* perform op on all children too */
   51 
   52 /*
   53  * ktrace record header
   54  */
   55 struct ktr_header {
   56         int     ktr_len;                /* length of record minus length of old header */
   57 #if BYTE_ORDER == LITTLE_ENDIAN
   58         short   ktr_type;               /* trace record type */
   59         short   ktr_version;            /* trace record version */
   60 #else
   61         short   ktr_version;            /* trace record version */
   62         short   ktr_type;               /* trace record type */
   63 #endif
   64         pid_t   ktr_pid;                /* process id */
   65         char    ktr_comm[MAXCOMLEN+1];  /* command name */
   66         union {
   67                 struct { /* v0 */
   68                         struct {
   69                                 int32_t tv_sec;
   70                                 long tv_usec;
   71                         } _tv;
   72                         const void *_buf;
   73                 } _v0;
   74                 struct { /* v1 */
   75                         struct {
   76                                 int32_t tv_sec;
   77                                 long tv_nsec;
   78                         } _ts;
   79                         lwpid_t _lid;
   80                 } _v1;
   81                 struct { /* v2 */
   82                         struct timespec _ts;
   83                         lwpid_t _lid;
   84                 } _v2;
   85         } _v;
   86 };
   87 
   88 #define ktr_lid         _v._v2._lid
   89 #define ktr_olid        _v._v1._lid
   90 #define ktr_time        _v._v2._ts
   91 #define ktr_otv         _v._v0._tv
   92 #define ktr_ots         _v._v1._ts
   93 #define ktr_ts          _v._v2._ts
   94 #define ktr_unused      _v._v0._buf
   95 
   96 #define KTR_SHIMLEN     offsetof(struct ktr_header, ktr_pid)
   97 
   98 /*
   99  * Test for kernel trace point
  100  */
  101 #define KTRPOINT(p, type)       \
  102         (((p)->p_traceflag & (1<<(type))) != 0)
  103 
  104 /*
  105  * ktrace record types
  106  */
  107 
  108 /*
  109  * KTR_SYSCALL - system call record
  110  */
  111 #define KTR_SYSCALL     1
  112 struct ktr_syscall {
  113         int     ktr_code;               /* syscall number */
  114         int     ktr_argsize;            /* size of arguments */
  115         /*
  116          * followed by ktr_argsize/sizeof(register_t) "register_t"s
  117          */
  118 };
  119 
  120 /*
  121  * KTR_SYSRET - return from system call record
  122  */
  123 #define KTR_SYSRET      2
  124 struct ktr_sysret {
  125         short   ktr_code;
  126         short   ktr_eosys;              /* XXX unused */
  127         int     ktr_error;
  128         register_t ktr_retval;
  129         register_t ktr_retval_1;
  130 };
  131 
  132 /*
  133  * KTR_NAMEI - namei record
  134  */
  135 #define KTR_NAMEI       3
  136         /* record contains pathname */
  137 
  138 /*
  139  * KTR_GENIO - trace generic process i/o
  140  */
  141 #define KTR_GENIO       4
  142 struct ktr_genio {
  143         int     ktr_fd;
  144         enum    uio_rw ktr_rw;
  145         /*
  146          * followed by data successfully read/written
  147          */
  148 };
  149 
  150 /*
  151  * KTR_PSIG - trace processed signal
  152  */
  153 #define KTR_PSIG        5
  154 struct ktr_psig {
  155         int     signo;
  156         sig_t   action;
  157         sigset_t mask;
  158         int     code;
  159         /*
  160          * followed by optional siginfo_t
  161          */
  162 };
  163 
  164 /*
  165  * KTR_CSW - trace context switches
  166  */
  167 #define KTR_CSW         6
  168 struct ktr_csw {
  169         int     out;    /* 1 if switch out, 0 if switch in */
  170         int     user;   /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */
  171 };
  172 
  173 /*
  174  * KTR_EMUL - emulation change
  175  */
  176 #define KTR_EMUL        7
  177         /* record contains emulation name */
  178 
  179 /*
  180  * KTR_USER - user record
  181  */
  182 #define KTR_USER        8
  183 #define KTR_USER_MAXIDLEN       20
  184 #define KTR_USER_MAXLEN         2048    /* maximum length of passed data */
  185 struct ktr_user {
  186         char    ktr_id[KTR_USER_MAXIDLEN];      /* string id of caller */
  187         /*
  188          * Followed by ktr_len - sizeof(struct ktr_user) of user data.
  189          */
  190 };
  191 
  192 /*
  193  * KTR_EXEC_ARG, KTR_EXEC_ENV - Arguments and environment from exec
  194  */
  195 #define KTR_EXEC_ARG            10
  196 #define KTR_EXEC_ENV            11
  197         /* record contains arg/env string */
  198 
  199 /*
  200  * KTR_SAUPCALL - scheduler activated upcall.
  201  */
  202 #define KTR_SAUPCALL    13
  203 struct ktr_saupcall {
  204         int ktr_type;
  205         int ktr_nevent;
  206         int ktr_nint;
  207         void *ktr_sas;
  208         void *ktr_ap;
  209         /*
  210          * followed by nevent sa_t's from sas[]
  211          */
  212 };
  213 
  214 /*
  215  * KTR_MIB - MIB name and data
  216  */
  217 #define KTR_MIB         14
  218         /* Record contains MIB name */
  219 
  220 
  221 /*
  222  * kernel trace points (in p_traceflag)
  223  */
  224 #define KTRFAC_MASK     0x00ffffff
  225 #define KTRFAC_SYSCALL  (1<<KTR_SYSCALL)
  226 #define KTRFAC_SYSRET   (1<<KTR_SYSRET)
  227 #define KTRFAC_NAMEI    (1<<KTR_NAMEI)
  228 #define KTRFAC_GENIO    (1<<KTR_GENIO)
  229 #define KTRFAC_PSIG     (1<<KTR_PSIG)
  230 #define KTRFAC_CSW      (1<<KTR_CSW)
  231 #define KTRFAC_EMUL     (1<<KTR_EMUL)
  232 #define KTRFAC_USER     (1<<KTR_USER)
  233 #define KTRFAC_EXEC_ARG (1<<KTR_EXEC_ARG)
  234 #define KTRFAC_EXEC_ENV (1<<KTR_EXEC_ENV)
  235 #define KTRFAC_SAUPCALL (1<<KTR_SAUPCALL)
  236 #define KTRFAC_MIB      (1<<KTR_MIB)
  237 /*
  238  * trace flags (also in p_traceflags)
  239  */
  240 #define KTRFAC_PERSISTENT       0x80000000      /* persistent trace across sugid
  241                                                    exec (exclusive) */
  242 #define KTRFAC_INHERIT  0x40000000      /* pass trace flags to children */
  243 #define KTRFAC_TRC_EMUL 0x10000000      /* ktrace KTR_EMUL before next trace */
  244 #define KTRFAC_VER_MASK 0x0f000000      /* record version mask */
  245 #define KTRFAC_VER_SHIFT        24      /* record version shift */
  246 
  247 #define KTRFAC_VERSION(tf)      (((tf) & KTRFAC_VER_MASK) >> KTRFAC_VER_SHIFT)
  248 
  249 #define KTRFACv0        (0 << KTRFAC_VER_SHIFT)
  250 #define KTRFACv1        (1 << KTRFAC_VER_SHIFT)
  251 #define KTRFACv2        (2 << KTRFAC_VER_SHIFT)
  252 
  253 #ifndef _KERNEL
  254 
  255 #include <sys/cdefs.h>
  256 
  257 __BEGIN_DECLS
  258 int     ktrace(const char *, int, int, pid_t);
  259 int     fktrace(int, int, int, pid_t);
  260 int     utrace(const char *, void *, size_t);
  261 __END_DECLS
  262 
  263 #else
  264 
  265 void ktrinit(void);
  266 void ktrderef(struct proc *);
  267 void ktradref(struct proc *);
  268 
  269 extern kmutex_t ktrace_lock;
  270 extern int ktrace_on;
  271 
  272 int ktruser(const char *, void *, size_t, int);
  273 bool ktr_point(int);
  274 
  275 void ktr_csw(int, int);
  276 void ktr_emul(void);
  277 void ktr_geniov(int, enum uio_rw, struct iovec *, size_t, int);
  278 void ktr_genio(int, enum uio_rw, const void *, size_t, int);
  279 void ktr_mibio(int, enum uio_rw, const void *, size_t, int);
  280 void ktr_namei(const char *, size_t);
  281 void ktr_namei2(const char *, size_t, const char *, size_t);
  282 void ktr_psig(int, sig_t, const sigset_t *, const ksiginfo_t *);
  283 void ktr_syscall(register_t, const register_t [], int);
  284 void ktr_sysret(register_t, int, register_t *);
  285 void ktr_kuser(const char *, void *, size_t);
  286 void ktr_mib(const int *a , u_int b);
  287 void ktr_execarg(const void *, size_t);
  288 void ktr_execenv(const void *, size_t);
  289 void ktr_saupcall(struct lwp *, int, int, int, void *, void *, void *);
  290 
  291 static inline bool
  292 ktrpoint(int fac)
  293 {
  294     return __predict_false(ktrace_on) && __predict_false(ktr_point(1 << fac));
  295 }
  296 
  297 static inline void
  298 ktrcsw(int a, int b)
  299 {
  300         if (__predict_false(ktrace_on))
  301                 ktr_csw(a, b);
  302 }
  303 
  304 static inline void
  305 ktremul(void)
  306 {
  307         if (__predict_false(ktrace_on))
  308                 ktr_emul();
  309 }
  310 
  311 static inline void
  312 ktrgenio(int a, enum uio_rw b, const void *c, size_t d, int e)
  313 {
  314         if (__predict_false(ktrace_on))
  315                 ktr_genio(a, b, c, d, e);
  316 }
  317 
  318 static inline void
  319 ktrgeniov(int a, enum uio_rw b, struct iovec *c, int d, int e)
  320 {
  321         if (__predict_false(ktrace_on))
  322                 ktr_geniov(a, b, c, d, e);
  323 }
  324 
  325 static inline void
  326 ktrmibio(int a, enum uio_rw b, const void *c, size_t d, int e)
  327 {
  328         if (__predict_false(ktrace_on))
  329                 ktr_mibio(a, b, c, d, e);
  330 }
  331 
  332 static inline void
  333 ktrnamei(const char *a, size_t b)
  334 {
  335         if (__predict_false(ktrace_on))
  336                 ktr_namei(a, b);
  337 }
  338 
  339 static inline void
  340 ktrnamei2(const char *a, size_t b, const char *c, size_t d)
  341 {
  342         if (__predict_false(ktrace_on))
  343                 ktr_namei2(a, b, c, d);
  344 }
  345 
  346 static inline void
  347 ktrpsig(int a, sig_t b, const sigset_t *c, const ksiginfo_t * d)
  348 {
  349         if (__predict_false(ktrace_on))
  350                 ktr_psig(a, b, c, d);
  351 }
  352 
  353 static inline void
  354 ktrsyscall(register_t code, const register_t args[], int narg)
  355 {
  356         if (__predict_false(ktrace_on))
  357                 ktr_syscall(code, args, narg);
  358 }
  359 
  360 static inline void
  361 ktrsysret(register_t a, int b, register_t *c)
  362 {
  363         if (__predict_false(ktrace_on))
  364                 ktr_sysret(a, b, c);
  365 }
  366 
  367 static inline void
  368 ktrkuser(const char *a, void *b, size_t c)
  369 {
  370         if (__predict_false(ktrace_on))
  371                 ktr_kuser(a, b, c);
  372 }
  373 
  374 static inline void
  375 ktrmib(const int *a , u_int b)
  376 {
  377         if (__predict_false(ktrace_on))
  378                 ktr_mib(a, b);
  379 }
  380 
  381 static inline void
  382 ktrexecarg(const void *a, size_t b)
  383 {
  384         if (__predict_false(ktrace_on))
  385                 ktr_execarg(a, b);
  386 }
  387 
  388 static inline void
  389 ktrexecenv(const void *a, size_t b)
  390 {
  391         if (__predict_false(ktrace_on))
  392                 ktr_execenv(a, b);
  393 }
  394 
  395 static inline void
  396 ktrsaupcall(struct lwp *a, int b, int c, int d, void *e, void *f, void *g)
  397 {
  398         if (__predict_false(ktrace_on))
  399                 ktr_saupcall(a, b, c, d, e, f, g);
  400 }
  401 
  402 #endif  /* !_KERNEL */
  403 
  404 #endif /* _SYS_KTRACE_H_ */

Cache object: 17a042847ed5e92f213258dc8ee643f6


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.