]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/truss/syscall.h
cdn-patch: offer option to mount /etc/keys before attaching geli devices
[FreeBSD/FreeBSD.git] / usr.bin / truss / syscall.h
1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright 1997 Sean Eric Fagan
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Sean Eric Fagan
17  * 4. Neither the name of the author may be used to endorse or promote
18  *    products derived from this software without specific prior written
19  *    permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $FreeBSD$
34  */
35
36 /*
37  * System call arguments come in several flavours:
38  * Hex -- values that should be printed in hex (addresses)
39  * Octal -- Same as above, but octal
40  * Int -- normal integer values (file descriptors, for example)
41  * LongHex -- long value that should be printed in hex
42  * Name -- pointer to a NULL-terminated string.
43  * BinString -- pointer to an array of chars, printed via strvisx().
44  * Ptr -- pointer to some unspecified structure.  Just print as hex for now.
45  * Stat -- a pointer to a stat buffer.  Prints a couple fields.
46  * Stat11 -- a pointer to a freebsd 11 stat buffer.  Prints a couple fields.
47  * StatFs -- a pointer to a statfs buffer.  Prints a few fields.
48  * Ioctl -- an ioctl command.  Woefully limited.
49  * Quad -- a double-word value.  e.g., lseek(int, offset_t, int)
50  * Signal -- a signal number.  Prints the signal name (SIGxxx)
51  * Sockaddr -- a pointer to a struct sockaddr.  Prints symbolic AF, and IP:Port
52  * StringArray -- a pointer to an array of string pointers.
53  * Timespec -- a pointer to a struct timespec.  Prints both elements.
54  * Timeval -- a pointer to a struct timeval.  Prints both elements.
55  * Timeval2 -- a pointer to two struct timevals.  Prints both elements of both.
56  * Itimerval -- a pointer to a struct itimerval.  Prints all elements.
57  * Pollfd -- a pointer to an array of struct pollfd.  Prints .fd and .events.
58  * Fd_set -- a pointer to an array of fd_set.  Prints the fds that are set.
59  * Sigaction -- a pointer to a struct sigaction.  Prints all elements.
60  * Sigset -- a pointer to a sigset_t.  Prints the signals that are set.
61  * Sigprocmask -- the first argument to sigprocmask().  Prints the name.
62  * Kevent -- a pointer to an array of struct kevents.  Prints all elements.
63  * Pathconf -- the 2nd argument of pathconf().
64  * Utrace -- utrace(2) buffer.
65  * CapRights -- a pointer to a cap_rights_t.  Prints all set capabilities.
66  *
67  * In addition, the pointer types (String, Ptr) may have OUT masked in --
68  * this means that the data is set on *return* from the system call -- or
69  * IN (meaning that the data is passed *into* the system call).
70  */
71
72 enum Argtype {
73         None = 1,
74
75         /* Scalar integers. */
76         Socklent,
77         Octal,
78         Int,
79         UInt,
80         Hex,
81         Long,
82         LongHex,
83         Sizet,
84         Quad,
85         QuadHex,
86
87         /* Encoded scalar values. */
88         Accessmode,
89         Acltype,
90         Atfd,
91         Atflags,
92         CapFcntlRights,
93         Extattrnamespace,
94         Fadvice,
95         Fcntl,
96         Fcntlflag,
97         FileFlags,
98         Flockop,
99         Getfsstatmode,
100         Idtype,
101         Ioctl,
102         Kldsymcmd,
103         Kldunloadflags,
104         Madvice,
105         Minherit,
106         Msgflags,
107         Mlockall,
108         Mmapflags,
109         Mountflags,
110         Mprot,
111         Msync,
112         Open,
113         Pathconf,
114         Pipe2,
115         Procctl,
116         Priowhich,
117         Ptraceop,
118         Quotactlcmd,
119         Reboothowto,
120         Resource,
121         Rforkflags,
122         Rtpriofunc,
123         RusageWho,
124         Schedpolicy,
125         Shutdown,
126         Signal,
127         Sigprocmask,
128         Sockdomain,
129         Sockoptlevel,
130         Sockoptname,
131         Sockprotocol,
132         Socktype,
133         Sysarch,
134         Umtxop,
135         Waitoptions,
136         Whence,
137
138         /* Pointers to non-structures. */
139         Ptr,
140         BinString,
141         CapRights,
142         ExecArgs,
143         ExecEnv,
144         ExitStatus,
145         Fd_set,
146         IntArray,
147         Iovec,
148         Name,
149         PipeFds,
150         PSig,
151         PQuadHex,
152         PUInt,
153         Readlinkres,
154         StringArray,
155
156         /* Pointers to structures. */
157         Itimerval,
158         Kevent,
159         Kevent11,
160         LinuxSockArgs,
161         Msghdr,
162         Pollfd,
163         Rlimit,
164         Rusage,
165         Schedparam,
166         Sctpsndrcvinfo,
167         Sigaction,
168         Siginfo,
169         Sigset,
170         Sockaddr,
171         Stat,
172         Stat11,
173         StatFs,
174         Timespec,
175         Timespec2,
176         Timeval,
177         Timeval2,
178         Utrace,
179
180         CloudABIAdvice,
181         CloudABIClockID,
182         CloudABIFDSFlags,
183         CloudABIFDStat,
184         CloudABIFileStat,
185         CloudABIFileType,
186         CloudABIFSFlags,
187         CloudABILookup,
188         CloudABIMFlags,
189         CloudABIMProt,
190         CloudABIMSFlags,
191         CloudABIOFlags,
192         CloudABISDFlags,
193         CloudABISignal,
194         CloudABISockStat,
195         CloudABISSFlags,
196         CloudABITimestamp,
197         CloudABIULFlags,
198         CloudABIWhence,
199
200         MAX_ARG_TYPE,
201 };
202
203 #define ARG_MASK        0xff
204 #define OUT     0x100
205 #define IN      /*0x20*/0
206
207 _Static_assert(ARG_MASK > MAX_ARG_TYPE,
208     "ARG_MASK overlaps with Argtype values");
209
210 struct syscall_args {
211         enum Argtype type;
212         int offset;
213 };
214
215 struct syscall {
216         STAILQ_ENTRY(syscall) entries;
217         const char *name;
218         u_int ret_type; /* 0, 1, or 2 return values */
219         u_int nargs;    /* actual number of meaningful arguments */
220                         /* Hopefully, no syscalls with > 10 args */
221         struct syscall_args args[10];
222         struct timespec time; /* Time spent for this call */
223         int ncalls;     /* Number of calls */
224         int nerror;     /* Number of calls that returned with error */
225         bool unknown;   /* Unknown system call */
226 };
227
228 struct syscall *get_syscall(struct threadinfo *, u_int, u_int);
229 char *print_arg(struct syscall_args *, unsigned long*, long *, struct trussinfo *);
230
231 /*
232  * Linux Socket defines
233  */
234 #define LINUX_SOCKET            1
235 #define LINUX_BIND              2
236 #define LINUX_CONNECT           3
237 #define LINUX_LISTEN            4
238 #define LINUX_ACCEPT            5
239 #define LINUX_GETSOCKNAME       6
240 #define LINUX_GETPEERNAME       7
241 #define LINUX_SOCKETPAIR        8
242 #define LINUX_SEND              9
243 #define LINUX_RECV              10
244 #define LINUX_SENDTO            11
245 #define LINUX_RECVFROM          12
246 #define LINUX_SHUTDOWN          13
247 #define LINUX_SETSOCKOPT        14
248 #define LINUX_GETSOCKOPT        15
249 #define LINUX_SENDMSG           16
250 #define LINUX_RECVMSG           17
251
252 #define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \
253     0 : sizeof(register_t) - sizeof(t))
254
255 #if BYTE_ORDER == LITTLE_ENDIAN
256 #define PADL_(t)        0
257 #define PADR_(t)        PAD_(t)
258 #else
259 #define PADL_(t)        PAD_(t)
260 #define PADR_(t)        0
261 #endif
262
263 typedef int     l_int;
264 typedef uint32_t    l_ulong;
265
266 struct linux_socketcall_args {
267     char what_l_[PADL_(l_int)]; l_int what; char what_r_[PADR_(l_int)];
268     char args_l_[PADL_(l_ulong)]; l_ulong args; char args_r_[PADR_(l_ulong)];
269 };
270
271 void init_syscalls(void);
272 void print_syscall(struct trussinfo *);
273 void print_syscall_ret(struct trussinfo *, int, long *);
274 void print_summary(struct trussinfo *trussinfo);