131567Ssef/*
231899Ssef * See i386-fbsd.c for copyright and license terms.
331899Ssef *
431567Ssef * System call arguments come in several flavours:
531567Ssef * Hex -- values that should be printed in hex (addresses)
631567Ssef * Octal -- Same as above, but octal
731567Ssef * Int -- normal integer values (file descriptors, for example)
8275843Sjhb * LongHex -- long value that should be printed in hex
9158630Spav * Name -- pointer to a NULL-terminated string.
10158630Spav * BinString -- pointer to an array of chars, printed via strvisx().
11158630Spav * Ptr -- pointer to some unspecified structure.  Just print as hex for now.
12158630Spav * Stat -- a pointer to a stat buffer.  Prints a couple fields.
13290052Sjhb * StatFs -- a pointer to a statfs buffer.  Prints a few fields.
1431571Ssef * Ioctl -- an ioctl command.  Woefully limited.
15127332Sdwmalone * Quad -- a double-word value.  e.g., lseek(int, offset_t, int)
16127332Sdwmalone * Signal -- a signal number.  Prints the signal name (SIGxxx)
17127332Sdwmalone * Sockaddr -- a pointer to a struct sockaddr.  Prints symbolic AF, and IP:Port
18127332Sdwmalone * StringArray -- a pointer to an array of string pointers.
19127332Sdwmalone * Timespec -- a pointer to a struct timespec.  Prints both elements.
20127332Sdwmalone * Timeval -- a pointer to a struct timeval.  Prints both elements.
21158630Spav * Timeval2 -- a pointer to two struct timevals.  Prints both elements of both.
22127332Sdwmalone * Itimerval -- a pointer to a struct itimerval.  Prints all elements.
23127332Sdwmalone * Pollfd -- a pointer to an array of struct pollfd.  Prints .fd and .events.
24127332Sdwmalone * Fd_set -- a pointer to an array of fd_set.  Prints the fds that are set.
25127332Sdwmalone * Sigaction -- a pointer to a struct sigaction.  Prints all elements.
26158630Spav * Umtx -- a pointer to a struct umtx.  Prints the value of owner.
27158630Spav * Sigset -- a pointer to a sigset_t.  Prints the signals that are set.
28158630Spav * Sigprocmask -- the first argument to sigprocmask().  Prints the name.
29158630Spav * Kevent -- a pointer to an array of struct kevents.  Prints all elements.
30181061Sdes * Pathconf -- the 2nd argument of pathconf().
3131567Ssef *
3231567Ssef * In addition, the pointer types (String, Ptr) may have OUT masked in --
3331567Ssef * this means that the data is set on *return* from the system call -- or
3431567Ssef * IN (meaning that the data is passed *into* the system call).
3531567Ssef */
3631567Ssef/*
3750477Speter * $FreeBSD$
3831567Ssef */
3931567Ssef
40275843Sjhbenum Argtype { None = 1, Hex, Octal, Int, LongHex, Name, Ptr, Stat, Ioctl, Quad,
41158630Spav	Signal, Sockaddr, StringArray, Timespec, Timeval, Itimerval, Pollfd,
42158630Spav	Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence, Readlinkres,
43290052Sjhb	Umtx, Sigset, Sigprocmask, StatFs, Kevent, Sockdomain, Socktype, Open,
44158630Spav	Fcntlflag, Rusage, BinString, Shutdown, Resource, Rlimit, Timeval2,
45266719Ssmh	Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype, Procctl,
46294033Sjhb	LinuxSockArgs, Umtxop, Atfd, Atflags, Timespec2, Accessmode, Long,
47290052Sjhb	Sysarch, ExecArgs, ExecEnv, PipeFds, QuadHex };
4831567Ssef
49240005Szont#define	ARG_MASK	0xff
50240005Szont#define	OUT	0x100
51240005Szont#define	IN	/*0x20*/0
5231567Ssef
5331567Ssefstruct syscall_args {
5431567Ssef	enum Argtype type;
5531567Ssef	int offset;
5631567Ssef};
5731567Ssef
5831567Ssefstruct syscall {
59290052Sjhb	STAILQ_ENTRY(syscall) entries;
6087703Smarkm	const char *name;
61290052Sjhb	u_int ret_type;	/* 0, 1, or 2 return values */
62290052Sjhb	u_int nargs;	/* actual number of meaningful arguments */
6331567Ssef			/* Hopefully, no syscalls with > 10 args */
6431567Ssef	struct syscall_args args[10];
65192025Sdds	struct timespec time; /* Time spent for this call */
66192025Sdds	int ncalls;	/* Number of calls */
67192025Sdds	int nerror;	/* Number of calls that returned with error */
6831567Ssef};
6931567Ssef
70290052Sjhbstruct syscall *get_syscall(const char *, int nargs);
71290052Sjhbchar *print_arg(struct syscall_args *, unsigned long*, long *, struct trussinfo *);
72266719Ssmh
73266719Ssmh/*
74266719Ssmh * Linux Socket defines
75266719Ssmh */
76266719Ssmh#define LINUX_SOCKET		1
77266719Ssmh#define LINUX_BIND		2
78266719Ssmh#define LINUX_CONNECT		3
79266719Ssmh#define LINUX_LISTEN		4
80266719Ssmh#define LINUX_ACCEPT		5
81266719Ssmh#define LINUX_GETSOCKNAME	6
82266719Ssmh#define LINUX_GETPEERNAME	7
83266719Ssmh#define LINUX_SOCKETPAIR	8
84266719Ssmh#define LINUX_SEND		9
85266719Ssmh#define LINUX_RECV		10
86266719Ssmh#define LINUX_SENDTO		11
87266719Ssmh#define LINUX_RECVFROM		12
88266719Ssmh#define LINUX_SHUTDOWN		13
89266719Ssmh#define LINUX_SETSOCKOPT	14
90266719Ssmh#define LINUX_GETSOCKOPT	15
91266719Ssmh#define LINUX_SENDMSG		16
92290052Sjhb#define LINUX_RECVMSG		17
93266719Ssmh
94266719Ssmh#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \
95266719Ssmh    0 : sizeof(register_t) - sizeof(t))
96290052Sjhb
97266719Ssmh#if BYTE_ORDER == LITTLE_ENDIAN
98266719Ssmh#define PADL_(t)	0
99266719Ssmh#define PADR_(t)	PAD_(t)
100266719Ssmh#else
101266719Ssmh#define PADL_(t)	PAD_(t)
102266719Ssmh#define PADR_(t)	0
103266719Ssmh#endif
104266719Ssmh
105266719Ssmhtypedef int     l_int;
106266719Ssmhtypedef uint32_t    l_ulong;
107266719Ssmh
108266719Ssmhstruct linux_socketcall_args {
109266719Ssmh    char what_l_[PADL_(l_int)]; l_int what; char what_r_[PADR_(l_int)];
110266719Ssmh    char args_l_[PADL_(l_ulong)]; l_ulong args; char args_r_[PADR_(l_ulong)];
111266719Ssmh};
112266719Ssmh
113290052Sjhbvoid init_syscalls(void);
114298410Sjhbvoid print_syscall(struct trussinfo *);
115298410Sjhbvoid print_syscall_ret(struct trussinfo *, int, long *);
116192025Sddsvoid print_summary(struct trussinfo *trussinfo);
117