1101282Smdodd/*
2204977Simp * Copyright 2001 Jamey Wood
3101282Smdodd *
4101282Smdodd * Redistribution and use in source and binary forms, with or without
5101282Smdodd * modification, are permitted provided that the following conditions
6101282Smdodd * are met:
7101282Smdodd * 1. Redistributions of source code must retain the above copyright
8101282Smdodd *    notice, this list of conditions and the following disclaimer.
9101282Smdodd * 2. Redistributions in binary form must reproduce the above copyright
10101282Smdodd *    notice, this list of conditions and the following disclaimer in the
11101282Smdodd *    documentation and/or other materials provided with the distribution.
12101282Smdodd *
13101282Smdodd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14101282Smdodd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15101282Smdodd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16101282Smdodd * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17101282Smdodd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18101282Smdodd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19101282Smdodd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20101282Smdodd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21101282Smdodd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22101282Smdodd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23101282Smdodd * SUCH DAMAGE.
24101282Smdodd *
25101282Smdodd * $FreeBSD: releng/11.0/usr.bin/truss/truss.h 296571 2016-03-09 18:45:41Z jhb $
26101282Smdodd */
27101282Smdodd
28288424Sjhb#include <sys/linker_set.h>
29168569Sdelphij#include <sys/queue.h>
30168569Sdelphij
31240005Szont#define	FOLLOWFORKS		0x00000001
32240005Szont#define	RELATIVETIMESTAMPS	0x00000002
33240005Szont#define	ABSOLUTETIMESTAMPS	0x00000004
34240005Szont#define	NOSIGS			0x00000008
35240005Szont#define	EXECVEARGS		0x00000010
36240005Szont#define	EXECVEENVS		0x00000020
37240005Szont#define	COUNTONLY		0x00000040
38295930Sjhb#define	DISPLAYTIDS		0x00000080
39101282Smdodd
40288424Sjhbstruct procinfo;
41288424Sjhbstruct trussinfo;
42288424Sjhb
43288424Sjhbstruct procabi {
44288424Sjhb	const char *type;
45294849Sjhb	enum sysdecode_abi abi;
46288424Sjhb	int (*fetch_args)(struct trussinfo *, u_int);
47288424Sjhb	int (*fetch_retval)(struct trussinfo *, long *, int *);
48288424Sjhb};
49288424Sjhb
50288424Sjhb#define	PROCABI(abi)	DATA_SET(procabi, abi)
51288424Sjhb
52288424Sjhb/*
53288424Sjhb * This is confusingly named.  It holds per-thread state about the
54288997Sbdrewery * currently executing system call.  syscall.h defines a struct
55288424Sjhb * syscall that holds metadata used to format system call arguments.
56288424Sjhb *
57288424Sjhb * NB: args[] stores the raw argument values (e.g. from registers)
58288424Sjhb * passed to the system call.  s_args[] stores a string representation
59288424Sjhb * of a system call's arguments.  These do not necessarily map one to
60288424Sjhb * one.  A system call description may omit individual arguments
61288424Sjhb * (padding) or combine adjacent arguments (e.g. when passing an off_t
62288424Sjhb * argument on a 32-bit system).  The nargs member contains the count
63288424Sjhb * of valid pointers in s_args[], not args[].
64288424Sjhb */
65288424Sjhbstruct current_syscall {
66288424Sjhb	struct syscall *sc;
67288424Sjhb	const char *name;
68288424Sjhb	int number;
69288424Sjhb	unsigned long args[10];
70288424Sjhb	unsigned int nargs;
71288424Sjhb	char *s_args[10];	/* the printable arguments */
72288424Sjhb};
73288424Sjhb
74168569Sdelphijstruct threadinfo
75168569Sdelphij{
76296571Sjhb	LIST_ENTRY(threadinfo) entries;
77288424Sjhb	struct procinfo *proc;
78168569Sdelphij	lwpid_t tid;
79168569Sdelphij	int in_syscall;
80288424Sjhb	struct current_syscall cs;
81240562Szont	struct timespec before;
82240562Szont	struct timespec after;
83168569Sdelphij};
84168569Sdelphij
85288424Sjhbstruct procinfo {
86288424Sjhb	LIST_ENTRY(procinfo) entries;
87288424Sjhb	pid_t pid;
88288424Sjhb	struct procabi *abi;
89288424Sjhb
90296571Sjhb	LIST_HEAD(, threadinfo) threadlist;
91288424Sjhb};
92288424Sjhb
93101282Smdoddstruct trussinfo
94101282Smdodd{
95101282Smdodd	int flags;
96153963Sbrian	int strsize;
97101282Smdodd	FILE *outfile;
98101285Smdodd
99101373Smdodd	struct timespec start_time;
100168569Sdelphij
101168569Sdelphij	struct threadinfo *curthread;
102240005Szont
103288424Sjhb	LIST_HEAD(, procinfo) proclist;
104101282Smdodd};
105158630Spav
106247338Sdelphij#define	timespecsubt(tvp, uvp, vvp)					\
107158630Spav	do {								\
108158630Spav		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
109158630Spav		(vvp)->tv_nsec = (tvp)->tv_nsec - (uvp)->tv_nsec;	\
110158630Spav		if ((vvp)->tv_nsec < 0) {				\
111158630Spav			(vvp)->tv_sec--;				\
112158630Spav			(vvp)->tv_nsec += 1000000000;			\
113158630Spav		}							\
114158630Spav	} while (0)
115168569Sdelphij
116247338Sdelphij#define	timespecadd(tvp, uvp, vvp)					\
117192025Sdds	do {								\
118192025Sdds		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
119192025Sdds		(vvp)->tv_nsec = (tvp)->tv_nsec + (uvp)->tv_nsec;	\
120192025Sdds		if ((vvp)->tv_nsec > 1000000000) {				\
121192025Sdds			(vvp)->tv_sec++;				\
122192025Sdds			(vvp)->tv_nsec -= 1000000000;			\
123192025Sdds		}							\
124192025Sdds	} while (0)
125