xref: /freebsd/usr.bin/truss/syscall.h (revision ca987d4641cdcd7f27e153db17c5bf064934faf5)
1 /*
2  * See i386-fbsd.c for copyright and license terms.
3  *
4  * System call arguments come in several flavours:
5  * Hex -- values that should be printed in hex (addresses)
6  * Octal -- Same as above, but octal
7  * Int -- normal integer values (file descriptors, for example)
8  * LongHex -- long value that should be printed in hex
9  * Name -- pointer to a NULL-terminated string.
10  * BinString -- pointer to an array of chars, printed via strvisx().
11  * Ptr -- pointer to some unspecified structure.  Just print as hex for now.
12  * Stat -- a pointer to a stat buffer.  Prints a couple fields.
13  * Stat11 -- a pointer to a freebsd 11 stat buffer.  Prints a couple fields.
14  * StatFs -- a pointer to a statfs buffer.  Prints a few fields.
15  * Ioctl -- an ioctl command.  Woefully limited.
16  * Quad -- a double-word value.  e.g., lseek(int, offset_t, int)
17  * Signal -- a signal number.  Prints the signal name (SIGxxx)
18  * Sockaddr -- a pointer to a struct sockaddr.  Prints symbolic AF, and IP:Port
19  * StringArray -- a pointer to an array of string pointers.
20  * Timespec -- a pointer to a struct timespec.  Prints both elements.
21  * Timeval -- a pointer to a struct timeval.  Prints both elements.
22  * Timeval2 -- a pointer to two struct timevals.  Prints both elements of both.
23  * Itimerval -- a pointer to a struct itimerval.  Prints all elements.
24  * Pollfd -- a pointer to an array of struct pollfd.  Prints .fd and .events.
25  * Fd_set -- a pointer to an array of fd_set.  Prints the fds that are set.
26  * Sigaction -- a pointer to a struct sigaction.  Prints all elements.
27  * Sigset -- a pointer to a sigset_t.  Prints the signals that are set.
28  * Sigprocmask -- the first argument to sigprocmask().  Prints the name.
29  * Kevent -- a pointer to an array of struct kevents.  Prints all elements.
30  * Pathconf -- the 2nd argument of pathconf().
31  * Utrace -- utrace(2) buffer.
32  * CapRights -- a pointer to a cap_rights_t.  Prints all set capabilities.
33  *
34  * In addition, the pointer types (String, Ptr) may have OUT masked in --
35  * this means that the data is set on *return* from the system call -- or
36  * IN (meaning that the data is passed *into* the system call).
37  */
38 /*
39  * $FreeBSD$
40  */
41 
42 enum Argtype { None = 1, Hex, Octal, Int, UInt, LongHex, Name, Ptr, Stat, Stat11, Ioctl,
43 	Quad, Signal, Sockaddr, StringArray, Timespec, Timeval, Itimerval,
44 	Pollfd, Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence, Readlinkres,
45 	Sigset, Sigprocmask, StatFs, Kevent, Sockdomain, Socktype, Open,
46 	Fcntlflag, Rusage, RusageWho, BinString, Shutdown, Resource, Rlimit,
47 	Timeval2, Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype, Procctl,
48 	LinuxSockArgs, Umtxop, Atfd, Atflags, Timespec2, Accessmode, Long,
49 	Sysarch, ExecArgs, ExecEnv, PipeFds, QuadHex, Utrace, IntArray, Pipe2,
50 	CapFcntlRights, Fadvice, FileFlags, Flockop, Getfsstatmode, Kldsymcmd,
51 	Kldunloadflags, Sizet, Madvice, Socklent, Sockprotocol, Sockoptlevel,
52 	Sockoptname, Msgflags, CapRights, PUInt, PQuadHex, Acltype,
53 	Extattrnamespace, Minherit, Mlockall, Mountflags, Msync, Priowhich,
54 	Ptraceop, Quotactlcmd, Reboothowto, Rtpriofunc, Schedpolicy, Schedparam,
55 	PSig, Siginfo,
56 
57 	CloudABIAdvice, CloudABIClockID, ClouduABIFDSFlags,
58 	CloudABIFDStat, CloudABIFileStat, CloudABIFileType,
59 	CloudABIFSFlags, CloudABILookup, CloudABIMFlags, CloudABIMProt,
60 	CloudABIMSFlags, CloudABIOFlags, CloudABISDFlags,
61 	CloudABISignal, CloudABISockStat, CloudABISSFlags,
62 	CloudABITimestamp, CloudABIULFlags, CloudABIWhence };
63 
64 #define	ARG_MASK	0xff
65 #define	OUT	0x100
66 #define	IN	/*0x20*/0
67 
68 struct syscall_args {
69 	enum Argtype type;
70 	int offset;
71 };
72 
73 struct syscall {
74 	STAILQ_ENTRY(syscall) entries;
75 	const char *name;
76 	u_int ret_type;	/* 0, 1, or 2 return values */
77 	u_int nargs;	/* actual number of meaningful arguments */
78 			/* Hopefully, no syscalls with > 10 args */
79 	struct syscall_args args[10];
80 	struct timespec time; /* Time spent for this call */
81 	int ncalls;	/* Number of calls */
82 	int nerror;	/* Number of calls that returned with error */
83 	bool unknown;	/* Unknown system call */
84 };
85 
86 struct syscall *get_syscall(struct threadinfo *, u_int, u_int);
87 char *print_arg(struct syscall_args *, unsigned long*, long *, struct trussinfo *);
88 
89 /*
90  * Linux Socket defines
91  */
92 #define LINUX_SOCKET		1
93 #define LINUX_BIND		2
94 #define LINUX_CONNECT		3
95 #define LINUX_LISTEN		4
96 #define LINUX_ACCEPT		5
97 #define LINUX_GETSOCKNAME	6
98 #define LINUX_GETPEERNAME	7
99 #define LINUX_SOCKETPAIR	8
100 #define LINUX_SEND		9
101 #define LINUX_RECV		10
102 #define LINUX_SENDTO		11
103 #define LINUX_RECVFROM		12
104 #define LINUX_SHUTDOWN		13
105 #define LINUX_SETSOCKOPT	14
106 #define LINUX_GETSOCKOPT	15
107 #define LINUX_SENDMSG		16
108 #define LINUX_RECVMSG		17
109 
110 #define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \
111     0 : sizeof(register_t) - sizeof(t))
112 
113 #if BYTE_ORDER == LITTLE_ENDIAN
114 #define PADL_(t)	0
115 #define PADR_(t)	PAD_(t)
116 #else
117 #define PADL_(t)	PAD_(t)
118 #define PADR_(t)	0
119 #endif
120 
121 typedef int     l_int;
122 typedef uint32_t    l_ulong;
123 
124 struct linux_socketcall_args {
125     char what_l_[PADL_(l_int)]; l_int what; char what_r_[PADR_(l_int)];
126     char args_l_[PADL_(l_ulong)]; l_ulong args; char args_r_[PADR_(l_ulong)];
127 };
128 
129 void init_syscalls(void);
130 void print_syscall(struct trussinfo *);
131 void print_syscall_ret(struct trussinfo *, int, long *);
132 void print_summary(struct trussinfo *trussinfo);
133