xref: /freebsd/usr.bin/truss/truss.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
11de7b4b8SPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
40a6c71f8SWarner Losh  * Copyright 2001 Jamey Wood
5ec0bed25SMatthew N. Dodd  *
6ec0bed25SMatthew N. Dodd  * Redistribution and use in source and binary forms, with or without
7ec0bed25SMatthew N. Dodd  * modification, are permitted provided that the following conditions
8ec0bed25SMatthew N. Dodd  * are met:
9ec0bed25SMatthew N. Dodd  * 1. Redistributions of source code must retain the above copyright
10ec0bed25SMatthew N. Dodd  *    notice, this list of conditions and the following disclaimer.
11ec0bed25SMatthew N. Dodd  * 2. Redistributions in binary form must reproduce the above copyright
12ec0bed25SMatthew N. Dodd  *    notice, this list of conditions and the following disclaimer in the
13ec0bed25SMatthew N. Dodd  *    documentation and/or other materials provided with the distribution.
14ec0bed25SMatthew N. Dodd  *
15ec0bed25SMatthew N. Dodd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16ec0bed25SMatthew N. Dodd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17ec0bed25SMatthew N. Dodd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ec0bed25SMatthew N. Dodd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19ec0bed25SMatthew N. Dodd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20ec0bed25SMatthew N. Dodd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21ec0bed25SMatthew N. Dodd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22ec0bed25SMatthew N. Dodd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23ec0bed25SMatthew N. Dodd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24ec0bed25SMatthew N. Dodd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25ec0bed25SMatthew N. Dodd  * SUCH DAMAGE.
26ec0bed25SMatthew N. Dodd  */
27ec0bed25SMatthew N. Dodd 
285d2d083cSXin LI #include <sys/queue.h>
295d2d083cSXin LI 
30c03bfcc8SMatthew N. Dodd #define	FOLLOWFORKS		0x00000001
310d0bd00eSMatthew N. Dodd #define	RELATIVETIMESTAMPS	0x00000002
320d0bd00eSMatthew N. Dodd #define	ABSOLUTETIMESTAMPS	0x00000004
33ec0bed25SMatthew N. Dodd #define	NOSIGS			0x00000008
349897b203SMatthew N. Dodd #define	EXECVEARGS		0x00000010
359897b203SMatthew N. Dodd #define	EXECVEENVS		0x00000020
36ee3b0f6eSDiomidis Spinellis #define	COUNTONLY		0x00000040
37d70876fdSJohn Baldwin #define	DISPLAYTIDS		0x00000080
38ec0bed25SMatthew N. Dodd 
392b75c8adSJohn Baldwin struct procinfo;
401175b23fSJohn Baldwin struct syscall;
412b75c8adSJohn Baldwin struct trussinfo;
422b75c8adSJohn Baldwin 
431175b23fSJohn Baldwin /*
441175b23fSJohn Baldwin  * The lookup of normal system calls are optimized by using a fixed
451175b23fSJohn Baldwin  * array for the first 1024 system calls that can be indexed directly.
461175b23fSJohn Baldwin  * Unknown system calls with other IDs are stored in a linked list.
471175b23fSJohn Baldwin  */
481175b23fSJohn Baldwin #define	SYSCALL_NORMAL_COUNT	1024
491175b23fSJohn Baldwin 
501175b23fSJohn Baldwin struct extra_syscall {
511175b23fSJohn Baldwin 	STAILQ_ENTRY(extra_syscall) entries;
521175b23fSJohn Baldwin 	struct syscall *sc;
531175b23fSJohn Baldwin 	u_int number;
541175b23fSJohn Baldwin };
551175b23fSJohn Baldwin 
562b75c8adSJohn Baldwin struct procabi {
572b75c8adSJohn Baldwin 	const char *type;
58a5f14abfSJohn Baldwin 	enum sysdecode_abi abi;
597daca4e2SAlex Richardson 	size_t pointer_size;
607daca4e2SAlex Richardson 	const char *compat_prefix;
611175b23fSJohn Baldwin 	STAILQ_HEAD(, extra_syscall) extra_syscalls;
621175b23fSJohn Baldwin 	struct syscall *syscalls[SYSCALL_NORMAL_COUNT];
632b75c8adSJohn Baldwin };
642b75c8adSJohn Baldwin 
652b75c8adSJohn Baldwin /*
662b75c8adSJohn Baldwin  * This is confusingly named.  It holds per-thread state about the
6704a97800SBryan Drewery  * currently executing system call.  syscall.h defines a struct
682b75c8adSJohn Baldwin  * syscall that holds metadata used to format system call arguments.
692b75c8adSJohn Baldwin  *
702b75c8adSJohn Baldwin  * NB: args[] stores the raw argument values (e.g. from registers)
712b75c8adSJohn Baldwin  * passed to the system call.  s_args[] stores a string representation
722b75c8adSJohn Baldwin  * of a system call's arguments.  These do not necessarily map one to
732b75c8adSJohn Baldwin  * one.  A system call description may omit individual arguments
742b75c8adSJohn Baldwin  * (padding) or combine adjacent arguments (e.g. when passing an off_t
752b75c8adSJohn Baldwin  * argument on a 32-bit system).  The nargs member contains the count
762b75c8adSJohn Baldwin  * of valid pointers in s_args[], not args[].
772b75c8adSJohn Baldwin  */
782b75c8adSJohn Baldwin struct current_syscall {
792b75c8adSJohn Baldwin 	struct syscall *sc;
801175b23fSJohn Baldwin 	unsigned int number;
812b75c8adSJohn Baldwin 	unsigned int nargs;
82b1ad6a90SBrooks Davis 	syscallarg_t args[10];
832b75c8adSJohn Baldwin 	char *s_args[10];	/* the printable arguments */
842b75c8adSJohn Baldwin };
852b75c8adSJohn Baldwin 
865d2d083cSXin LI struct threadinfo
875d2d083cSXin LI {
88b9befd33SJohn Baldwin 	LIST_ENTRY(threadinfo) entries;
892b75c8adSJohn Baldwin 	struct procinfo *proc;
905d2d083cSXin LI 	lwpid_t tid;
915d2d083cSXin LI 	int in_syscall;
922b75c8adSJohn Baldwin 	struct current_syscall cs;
935695afdeSAndrey Zonov 	struct timespec before;
945695afdeSAndrey Zonov 	struct timespec after;
955d2d083cSXin LI };
965d2d083cSXin LI 
972b75c8adSJohn Baldwin struct procinfo {
982b75c8adSJohn Baldwin 	LIST_ENTRY(procinfo) entries;
992b75c8adSJohn Baldwin 	pid_t pid;
1002b75c8adSJohn Baldwin 	struct procabi *abi;
1012b75c8adSJohn Baldwin 
102b9befd33SJohn Baldwin 	LIST_HEAD(, threadinfo) threadlist;
1032b75c8adSJohn Baldwin };
1042b75c8adSJohn Baldwin 
105ec0bed25SMatthew N. Dodd struct trussinfo
106ec0bed25SMatthew N. Dodd {
107ec0bed25SMatthew N. Dodd 	int flags;
1080cf21b4fSBrian Somers 	int strsize;
109ec0bed25SMatthew N. Dodd 	FILE *outfile;
1100d0bd00eSMatthew N. Dodd 
111203098d8SMatthew N. Dodd 	struct timespec start_time;
1125d2d083cSXin LI 
1135d2d083cSXin LI 	struct threadinfo *curthread;
1145d2d083cSXin LI 
1152b75c8adSJohn Baldwin 	LIST_HEAD(, procinfo) proclist;
116ec0bed25SMatthew N. Dodd };
117