ktrace.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* $OpenBSD: ktrace.h,v 1.23 2015/07/28 05:50:41 guenther Exp $ */
  2. /* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */
  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.1 (Berkeley) 6/2/93
  32. */
  33. #include <sys/uio.h>
  34. /*
  35. * operations to ktrace system call (KTROP(op))
  36. */
  37. #define KTROP_SET 0 /* set trace points */
  38. #define KTROP_CLEAR 1 /* clear trace points */
  39. #define KTROP_CLEARFILE 2 /* stop all tracing to file */
  40. #define KTROP(o) ((o)&3) /* macro to extract operation */
  41. /*
  42. * flags (ORed in with operation)
  43. */
  44. #define KTRFLAG_DESCEND 4 /* perform op on all children too */
  45. /*
  46. * ktrace record header
  47. */
  48. struct ktr_header {
  49. uint ktr_type; /* trace record type */
  50. pid_t ktr_pid; /* process id */
  51. pid_t ktr_tid; /* thread id */
  52. struct timespec ktr_time; /* timestamp */
  53. char ktr_comm[MAXCOMLEN+1]; /* command name */
  54. size_t ktr_len; /* length of buf */
  55. };
  56. /*
  57. * Test for kernel trace point
  58. */
  59. #define KTRPOINT(p, type) \
  60. ((p)->p_p->ps_traceflag & (1<<(type)) && ((p)->p_flag & P_INKTR) == 0)
  61. /*
  62. * ktrace record types
  63. */
  64. /*
  65. * KTR_START - start of trace record, one per ktrace(KTROP_SET) syscall
  66. */
  67. #define KTR_START 0x4b545200 /* "KTR" */
  68. /*
  69. * KTR_SYSCALL - system call record
  70. */
  71. #define KTR_SYSCALL 1
  72. struct ktr_syscall {
  73. int ktr_code; /* syscall number */
  74. int ktr_argsize; /* size of arguments */
  75. /*
  76. * followed by ktr_argsize/sizeof(register_t) "register_t"s
  77. */
  78. };
  79. /*
  80. * KTR_SYSRET - return from system call record
  81. */
  82. #define KTR_SYSRET 2
  83. struct ktr_sysret {
  84. int ktr_code;
  85. int ktr_error;
  86. /*
  87. * If ktr_error is zero, then followed by retval: register_t for
  88. * all syscalls except lseek(), which uses long long
  89. */
  90. };
  91. /*
  92. * KTR_NAMEI - namei record
  93. */
  94. #define KTR_NAMEI 3
  95. /* record contains pathname */
  96. /*
  97. * KTR_GENIO - trace generic process i/o
  98. */
  99. #define KTR_GENIO 4
  100. struct ktr_genio {
  101. int ktr_fd;
  102. enum uio_rw ktr_rw;
  103. /*
  104. * followed by data successfully read/written
  105. */
  106. };
  107. /*
  108. * KTR_PSIG - trace processed signal
  109. */
  110. #define KTR_PSIG 5
  111. struct ktr_psig {
  112. int signo;
  113. sig_t action;
  114. int mask;
  115. int code;
  116. siginfo_t si;
  117. };
  118. /*
  119. * KTR_CSW - trace context switches
  120. */
  121. #define KTR_CSW 6
  122. struct ktr_csw {
  123. int out; /* 1 if switch out, 0 if switch in */
  124. int user; /* 1 if usermode (ivcsw), 0 if kernel (vcsw) */
  125. };
  126. /*
  127. * KTR_EMUL - emulation change
  128. */
  129. #define KTR_EMUL 7
  130. /* record contains emulation name */
  131. /*
  132. * KTR_STRUCT - misc. structs
  133. */
  134. #define KTR_STRUCT 8
  135. /*
  136. * record contains null-terminated struct name followed by
  137. * struct contents
  138. */
  139. struct sockaddr;
  140. struct stat;
  141. /*
  142. * KTR_USER - user record
  143. */
  144. #define KTR_USER 9
  145. #define KTR_USER_MAXIDLEN 20
  146. #define KTR_USER_MAXLEN 2048 /* maximum length of passed data */
  147. struct ktr_user {
  148. char ktr_id[KTR_USER_MAXIDLEN]; /* string id of caller */
  149. /*
  150. * Followed by ktr_len - sizeof(struct ktr_user) of user data.
  151. */
  152. };
  153. /*
  154. * kernel trace points (in p_traceflag)
  155. */
  156. #define KTRFAC_MASK 0x00ffffff
  157. #define KTRFAC_SYSCALL (1<<KTR_SYSCALL)
  158. #define KTRFAC_SYSRET (1<<KTR_SYSRET)
  159. #define KTRFAC_NAMEI (1<<KTR_NAMEI)
  160. #define KTRFAC_GENIO (1<<KTR_GENIO)
  161. #define KTRFAC_PSIG (1<<KTR_PSIG)
  162. #define KTRFAC_CSW (1<<KTR_CSW)
  163. #define KTRFAC_EMUL (1<<KTR_EMUL)
  164. #define KTRFAC_STRUCT (1<<KTR_STRUCT)
  165. #define KTRFAC_USER (1<<KTR_USER)
  166. /*
  167. * trace flags (also in p_traceflags)
  168. */
  169. #define KTRFAC_ROOT 0x80000000 /* root set this trace */
  170. #define KTRFAC_INHERIT 0x40000000 /* pass trace flags to children */
  171. #ifndef _KERNEL
  172. #include <sys/cdefs.h>
  173. __BEGIN_DECLS
  174. int ktrace(const char *, int, int, pid_t);
  175. int utrace(const char *, const void *, size_t);
  176. __END_DECLS
  177. #else
  178. void ktrcsw(struct proc *, int, int);
  179. void ktremul(struct proc *);
  180. void ktrgenio(struct proc *, int, enum uio_rw, struct iovec *, ssize_t);
  181. void ktrnamei(struct proc *, char *);
  182. void ktrpsig(struct proc *, int, sig_t, int, int, siginfo_t *);
  183. void ktrsyscall(struct proc *, register_t, size_t, register_t []);
  184. void ktrsysret(struct proc *, register_t, int, const register_t [2]);
  185. void ktr_kuser(const char *, void *, size_t);
  186. int ktruser(struct proc *, const char *, const void *, size_t);
  187. void ktrcleartrace(struct process *);
  188. void ktrsettrace(struct process *, int, struct vnode *, struct ucred *);
  189. void ktrstruct(struct proc *, const char *, const void *, size_t);
  190. #define ktrsockaddr(p, s, l) \
  191. ktrstruct((p), "sockaddr", (s), (l))
  192. #define ktrstat(p, s) \
  193. ktrstruct((p), "stat", (s), sizeof(struct stat))
  194. #define ktrabstimespec(p, s) \
  195. ktrstruct((p), "abstimespec", (s), sizeof(struct timespec))
  196. #define ktrreltimespec(p, s) \
  197. ktrstruct((p), "reltimespec", (s), sizeof(struct timespec))
  198. #define ktrabstimeval(p, s) \
  199. ktrstruct((p), "abstimeval", (s), sizeof(struct timeval))
  200. #define ktrreltimeval(p, s) \
  201. ktrstruct((p), "reltimeval", (s), sizeof(struct timeval))
  202. #define ktrsigaction(p, s) \
  203. ktrstruct((p), "sigaction", (s), sizeof(struct sigaction))
  204. #define ktrrlimit(p, s) \
  205. ktrstruct((p), "rlimit", (s), sizeof(struct rlimit))
  206. #define ktrrusage(p, s) \
  207. ktrstruct((p), "rusage", (s), sizeof(struct rusage))
  208. #define ktrfdset(p, s, l) \
  209. ktrstruct((p), "fdset", (s), l)
  210. #define ktrquota(p, s) \
  211. ktrstruct((p), "quota", (s), sizeof(struct dqblk))
  212. #define ktrmsghdr(p, s) \
  213. ktrstruct(p, "msghdr", s, sizeof(struct msghdr))
  214. #define ktriovec(p, s, count) \
  215. ktrstruct(p, "iovec", s, (count) * sizeof(struct iovec))
  216. #define ktrcmsghdr(p, c, len) \
  217. ktrstruct(p, "cmsghdr", c, len)
  218. #endif /* !_KERNEL */