# include <linux/perf_event.h>
#endif
-static const struct xlat fcntlcmds[] = {
- XLAT(F_DUPFD),
- XLAT(F_GETFD),
- XLAT(F_SETFD),
- XLAT(F_GETFL),
- XLAT(F_SETFL),
- XLAT(F_GETLK),
- XLAT(F_SETLK),
- XLAT(F_SETLKW),
- XLAT(F_GETOWN),
- XLAT(F_SETOWN),
-#ifdef F_RSETLK
- XLAT(F_RSETLK),
-#endif
-#ifdef F_RSETLKW
- XLAT(F_RSETLKW),
-#endif
-#ifdef F_RGETLK
- XLAT(F_RGETLK),
-#endif
-#ifdef F_CNVT
- XLAT(F_CNVT),
-#endif
-#ifdef F_SETSIG
- XLAT(F_SETSIG),
-#endif
-#ifdef F_GETSIG
- XLAT(F_GETSIG),
-#endif
-#ifdef F_CHKFL
- XLAT(F_CHKFL),
-#endif
-#ifdef F_DUP2FD
- XLAT(F_DUP2FD),
-#endif
-#ifdef F_ALLOCSP
- XLAT(F_ALLOCSP),
-#endif
-#ifdef F_ISSTREAM
- XLAT(F_ISSTREAM),
-#endif
-#ifdef F_PRIV
- XLAT(F_PRIV),
-#endif
-#ifdef F_NPRIV
- XLAT(F_NPRIV),
-#endif
-#ifdef F_QUOTACL
- XLAT(F_QUOTACL),
-#endif
-#ifdef F_BLOCKS
- XLAT(F_BLOCKS),
-#endif
-#ifdef F_BLKSIZE
- XLAT(F_BLKSIZE),
-#endif
-#ifdef F_GETOWN
- XLAT(F_GETOWN),
-#endif
-#ifdef F_SETOWN
- XLAT(F_SETOWN),
-#endif
-#ifdef F_REVOKE
- XLAT(F_REVOKE),
-#endif
-#ifdef F_SETLK
- XLAT(F_SETLK),
-#endif
-#ifdef F_SETLKW
- XLAT(F_SETLKW),
-#endif
-#ifdef F_FREESP
- XLAT(F_FREESP),
-#endif
-#ifdef F_GETLK
- XLAT(F_GETLK),
-#endif
-#ifdef F_SETLK64
- XLAT(F_SETLK64),
-#endif
-#ifdef F_SETLKW64
- XLAT(F_SETLKW64),
-#endif
-#ifdef F_FREESP64
- XLAT(F_FREESP64),
-#endif
-#ifdef F_GETLK64
- XLAT(F_GETLK64),
-#endif
-#ifdef F_SHARE
- XLAT(F_SHARE),
-#endif
-#ifdef F_UNSHARE
- XLAT(F_UNSHARE),
-#endif
-#ifdef F_SETLEASE
- XLAT(F_SETLEASE),
-#endif
-#ifdef F_GETLEASE
- XLAT(F_GETLEASE),
-#endif
-#ifdef F_NOTIFY
- XLAT(F_NOTIFY),
-#endif
-#ifdef F_DUPFD_CLOEXEC
- XLAT(F_DUPFD_CLOEXEC),
-#endif
- XLAT_END
-};
-
-static const struct xlat fdflags[] = {
-#ifdef FD_CLOEXEC
- XLAT(FD_CLOEXEC),
-#endif
- XLAT_END
-};
-
-#ifdef LOCK_SH
-
-static const struct xlat flockcmds[] = {
- XLAT(LOCK_SH),
- XLAT(LOCK_EX),
- XLAT(LOCK_NB),
- XLAT(LOCK_UN),
- XLAT_END
-};
-
-#endif /* LOCK_SH */
-
-static const struct xlat lockfcmds[] = {
- XLAT(F_RDLCK),
- XLAT(F_WRLCK),
- XLAT(F_UNLCK),
-#ifdef F_EXLCK
- XLAT(F_EXLCK),
-#endif
-#ifdef F_SHLCK
- XLAT(F_SHLCK),
-#endif
- XLAT_END
-};
-
-#ifdef F_NOTIFY
-static const struct xlat notifyflags[] = {
-#ifdef DN_ACCESS
- XLAT(DN_ACCESS),
-#endif
-#ifdef DN_MODIFY
- XLAT(DN_MODIFY),
-#endif
-#ifdef DN_CREATE
- XLAT(DN_CREATE),
-#endif
-#ifdef DN_DELETE
- XLAT(DN_DELETE),
-#endif
-#ifdef DN_RENAME
- XLAT(DN_RENAME),
-#endif
-#ifdef DN_ATTRIB
- XLAT(DN_ATTRIB),
-#endif
-#ifdef DN_MULTISHOT
- XLAT(DN_MULTISHOT),
-#endif
- XLAT_END
-};
-#endif
-
-static const struct xlat perf_event_open_flags[] = {
-#ifdef PERF_FLAG_FD_NO_GROUP
- XLAT(PERF_FLAG_FD_NO_GROUP),
-#endif
-#ifdef PERF_FLAG_FD_OUTPUT
- XLAT(PERF_FLAG_FD_OUTPUT),
-#endif
-#ifdef PERF_FLAG_PID_CGROUP
- XLAT(PERF_FLAG_PID_CGROUP),
-#endif
- XLAT_END
-};
+#include "xlat/fcntlcmds.h"
+#include "xlat/fdflags.h"
+#include "xlat/flockcmds.h"
+#include "xlat/lockfcmds.h"
+#include "xlat/notifyflags.h"
+#include "xlat/perf_event_open_flags.h"
+/*
+ * Assume that F_SETLK64, F_SETLKW64, and F_GETLK64 are either defined
+ * or not defined altogether.
+ */
#if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
-# define HAVE_F_SETLK64 1
-#else
-# define HAVE_F_SETLK64 0
-#endif
-
-#if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
-# define HAVE_F_SETLKW64 1
-#else
-# define HAVE_F_SETLKW64 0
-#endif
-
-#if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
-# define HAVE_F_GETLK64 1
+# define USE_PRINTFLOCK64 1
#else
-# define HAVE_F_GETLK64 0
+# define USE_PRINTFLOCK64 0
#endif
-#if defined(X32) || defined(F_FREESP64) || \
- HAVE_F_SETLK64 || HAVE_F_SETLKW64 || HAVE_F_GETLK64
+#if USE_PRINTFLOCK64
-#ifndef HAVE_STRUCT_FLOCK64
+# ifndef HAVE_STRUCT_FLOCK64
struct flock64 {
short int l_type, l_whence;
int64_t l_start, l_len;
int l_pid;
};
-#endif
+# endif
-/* fcntl/lockf */
static void
printflock64(struct tcb *tcp, long addr, int getlk)
{
else
tprints("}");
}
-#endif
+#endif /* USE_PRINTFLOCK64 */
-/* fcntl/lockf */
static void
printflock(struct tcb *tcp, long addr, int getlk)
{
struct flock fl;
+ int r;
#if SUPPORTED_PERSONALITIES > 1
-# ifdef X32
- if (current_personality == 0) {
- printflock64(tcp, addr, getlk);
- return;
- }
-# endif
- if (current_wordsize != sizeof(fl.l_start)) {
+ if (
+# if SIZEOF_OFF_T > SIZEOF_LONG
+ current_personality > 0 &&
+#endif
+ current_wordsize != sizeof(fl.l_start)) {
if (current_wordsize == 4) {
/* 32-bit x86 app on x86_64 and similar cases */
struct {
int32_t l_len; /* off_t */
int32_t l_pid; /* pid_t */
} fl32;
- if (umove(tcp, addr, &fl32) < 0) {
- tprints("{...}");
- return;
+ r = umove(tcp, addr, &fl32);
+ if (r >= 0) {
+ fl.l_type = fl32.l_type;
+ fl.l_whence = fl32.l_whence;
+ fl.l_start = fl32.l_start;
+ fl.l_len = fl32.l_len;
+ fl.l_pid = fl32.l_pid;
}
- fl.l_type = fl32.l_type;
- fl.l_whence = fl32.l_whence;
- fl.l_start = fl32.l_start;
- fl.l_len = fl32.l_len;
- fl.l_pid = fl32.l_pid;
} else {
/* let people know we have a problem here */
tprintf("<decode error: unsupported wordsize %d>",
} else
#endif
{
- if (umove(tcp, addr, &fl) < 0) {
- tprints("{...}");
- return;
- }
+ r = umove(tcp, addr, &fl);
+ }
+ if (r < 0) {
+ tprints("{...}");
+ return;
}
tprints("{type=");
printxval(lockfcmds, fl.l_type, "F_???");
tprints(", whence=");
printxval(whence_codes, fl.l_whence, "SEEK_???");
-#ifdef X32
+#if SIZEOF_OFF_T > SIZEOF_LONG
tprintf(", start=%lld, len=%lld", fl.l_start, fl.l_len);
#else
tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
tprints("}");
}
-int
-sys_fcntl(struct tcb *tcp)
+SYS_FUNC(fcntl)
{
if (entering(tcp)) {
printfd(tcp, tcp->u_arg[0]);
tprint_open_modes(tcp->u_arg[2]);
break;
case F_SETLK: case F_SETLKW:
-#ifdef F_FREESP
- case F_FREESP:
-#endif
tprints(", ");
printflock(tcp, tcp->u_arg[2], 0);
break;
-#if defined(F_FREESP64) || HAVE_F_SETLK64 || HAVE_F_SETLKW64
-#ifdef F_FREESP64
- case F_FREESP64:
-#endif
- /* Linux glibc defines SETLK64 as SETLK,
- even though the kernel has different values - as does Solaris. */
-#if HAVE_F_SETLK64
- case F_SETLK64:
-#endif
-#if HAVE_F_SETLKW64
- case F_SETLKW64:
-#endif
+#if USE_PRINTFLOCK64
+ case F_SETLK64: case F_SETLKW64:
tprints(", ");
printflock64(tcp, tcp->u_arg[2], 0);
break;
-#endif /* defined(F_FREESP64) || HAVE_F_SETLK64 || HAVE_F_SETLKW64 */
+#endif /* USE_PRINTFLOCK64 */
#ifdef F_NOTIFY
case F_NOTIFY:
tprints(", ");
tprints(", ");
printflock(tcp, tcp->u_arg[2], 1);
break;
-#if HAVE_F_GETLK64
+#if USE_PRINTFLOCK64
case F_GETLK64:
tprints(", ");
printflock64(tcp, tcp->u_arg[2], 1);
#ifdef LOCK_SH
-int
-sys_flock(struct tcb *tcp)
+SYS_FUNC(flock)
{
if (entering(tcp)) {
printfd(tcp, tcp->u_arg[0]);
}
#endif /* LOCK_SH */
-int
-sys_close(struct tcb *tcp)
+SYS_FUNC(close)
{
if (entering(tcp)) {
printfd(tcp, tcp->u_arg[0]);
return 0;
}
+SYS_FUNC(dup)
+{
+ if (entering(tcp)) {
+ printfd(tcp, tcp->u_arg[0]);
+ }
+ return RVAL_FD;
+}
+
static int
do_dup2(struct tcb *tcp, int flags_arg)
{
printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
}
}
- return 0;
+ return RVAL_FD;
}
-int
-sys_dup2(struct tcb *tcp)
+SYS_FUNC(dup2)
{
return do_dup2(tcp, -1);
}
-int
-sys_dup3(struct tcb *tcp)
+SYS_FUNC(dup3)
{
return do_dup2(tcp, 2);
}
#if defined(ALPHA)
-int
-sys_getdtablesize(struct tcb *tcp)
+SYS_FUNC(getdtablesize)
{
return 0;
}
{
int i, j;
int nfds, fdsize;
- fd_set *fds;
+ fd_set *fds = NULL;
const char *sep;
long arg;
nfds = (int) args[0];
/* Kernel rejects negative nfds, so we don't parse it either. */
- if (nfds < 0) {
+ if (nfds < 0)
nfds = 0;
- fds = NULL;
- }
+
/* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
if (nfds > 1024*1024)
nfds = 1024*1024;
if (entering(tcp)) {
tprintf("%d", (int) args[0]);
- if (fdsize > 0) {
- fds = malloc(fdsize);
- if (!fds)
- die_out_of_memory();
- }
+ if (verbose(tcp) && fdsize > 0)
+ fds = xmalloc(fdsize);
for (i = 0; i < 3; i++) {
arg = args[i+1];
if (arg == 0) {
tprints(", NULL");
continue;
}
- if (!verbose(tcp) || !fds) {
+ if (!fds) {
tprintf(", %#lx", arg);
continue;
}
- if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
+ if (umoven(tcp, arg, fdsize, fds) < 0) {
tprints(", [?]");
continue;
}
return RVAL_STR;
}
- fds = malloc(fdsize);
- if (!fds)
- die_out_of_memory();
+ fds = xmalloc(fdsize);
outptr = outstr;
sep = "";
int first = 1;
arg = args[i+1];
- if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
+ if (!arg || umoven(tcp, arg, fdsize, fds) < 0)
continue;
for (j = 0;; j++) {
j = next_set_bit(fds, j, nfds);
return 0;
}
-int
-sys_oldselect(struct tcb *tcp)
+SYS_FUNC(oldselect)
{
long args[5];
- if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
+ if (umoven(tcp, tcp->u_arg[0], sizeof args, args) < 0) {
tprints("[...]");
return 0;
}
}
#ifdef ALPHA
-int
-sys_osf_select(struct tcb *tcp)
+SYS_FUNC(osf_select)
{
long *args = tcp->u_arg;
return decode_select(tcp, args, BITNESS_32);
}
#endif
-static const struct xlat epollctls[] = {
-#ifdef EPOLL_CTL_ADD
- XLAT(EPOLL_CTL_ADD),
-#endif
-#ifdef EPOLL_CTL_MOD
- XLAT(EPOLL_CTL_MOD),
-#endif
-#ifdef EPOLL_CTL_DEL
- XLAT(EPOLL_CTL_DEL),
-#endif
- XLAT_END
-};
-
-static const struct xlat epollevents[] = {
-#ifdef EPOLLIN
- XLAT(EPOLLIN),
-#endif
-#ifdef EPOLLPRI
- XLAT(EPOLLPRI),
-#endif
-#ifdef EPOLLOUT
- XLAT(EPOLLOUT),
-#endif
-#ifdef EPOLLRDNORM
- XLAT(EPOLLRDNORM),
-#endif
-#ifdef EPOLLRDBAND
- XLAT(EPOLLRDBAND),
-#endif
-#ifdef EPOLLWRNORM
- XLAT(EPOLLWRNORM),
-#endif
-#ifdef EPOLLWRBAND
- XLAT(EPOLLWRBAND),
-#endif
-#ifdef EPOLLMSG
- XLAT(EPOLLMSG),
-#endif
-#ifdef EPOLLERR
- XLAT(EPOLLERR),
-#endif
-#ifdef EPOLLHUP
- XLAT(EPOLLHUP),
-#endif
-#ifdef EPOLLRDHUP
- XLAT(EPOLLRDHUP),
-#endif
-#ifdef EPOLLONESHOT
- XLAT(EPOLLONESHOT),
-#endif
-#ifdef EPOLLET
- XLAT(EPOLLET),
-#endif
- XLAT_END
-};
+#include "xlat/epollctls.h"
+#include "xlat/epollevents.h"
+#include "xlat/epollflags.h"
/* Not aliased to printargs_ld: we want it to have a distinct address */
-int
-sys_epoll_create(struct tcb *tcp)
+SYS_FUNC(epoll_create)
{
return printargs_ld(tcp);
}
-static const struct xlat epollflags[] = {
-#ifdef EPOLL_CLOEXEC
- XLAT(EPOLL_CLOEXEC),
-#endif
-#ifdef EPOLL_NONBLOCK
- XLAT(EPOLL_NONBLOCK),
-#endif
- XLAT_END
-};
-
-int
-sys_epoll_create1(struct tcb *tcp)
+SYS_FUNC(epoll_create1)
{
if (entering(tcp))
printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
}
#endif
-int
-sys_epoll_ctl(struct tcb *tcp)
+SYS_FUNC(epoll_ctl)
{
if (entering(tcp)) {
printfd(tcp, tcp->u_arg[0]);
else {
#ifdef HAVE_SYS_EPOLL_H
struct epoll_event ev;
- if (umove(tcp, tcp->u_arg[3], &ev) == 0)
+ if (
+#ifdef EPOLL_CTL_DEL
+ (tcp->u_arg[1] != EPOLL_CTL_DEL) &&
+#endif
+ umove(tcp, tcp->u_arg[3], &ev) == 0)
print_epoll_event(&ev);
else
#endif
- tprints("{...}");
+ tprintf("%lx", tcp->u_arg[3]);
}
}
return 0;
}
}
-int
-sys_epoll_wait(struct tcb *tcp)
+SYS_FUNC(epoll_wait)
{
epoll_wait_common(tcp);
return 0;
}
-int
-sys_epoll_pwait(struct tcb *tcp)
+SYS_FUNC(epoll_pwait)
{
epoll_wait_common(tcp);
if (exiting(tcp)) {
return 0;
}
-int
-sys_select(struct tcb *tcp)
+SYS_FUNC(select)
{
return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
}
-int
-sys_pselect6(struct tcb *tcp)
+SYS_FUNC(pselect6)
{
int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
if (entering(tcp)) {
return 0;
}
-int
-sys_eventfd(struct tcb *tcp)
+SYS_FUNC(eventfd)
{
return do_eventfd(tcp, -1);
}
-int
-sys_eventfd2(struct tcb *tcp)
+SYS_FUNC(eventfd2)
{
return do_eventfd(tcp, 1);
}
-int
-sys_perf_event_open(struct tcb *tcp)
+SYS_FUNC(perf_event_open)
{
if (entering(tcp)) {
tprintf("%#lx, %d, %d, %d, ",