summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2013-11-11 12:50:47 +0100
committerDenys Vlasenko <dvlasenk@redhat.com>2013-11-11 12:50:47 +0100
commit2df03c494eb3c36c4178eba35c374831031d1a58 (patch)
tree340af7d369a85a376004614db80e66a380081dfa
parentabd2fda38003f61f50e5b4ed4f77f7997d7172ac (diff)
downloadstrace-2df03c494eb3c36c4178eba35c374831031d1a58.tar.gz
strace-2df03c494eb3c36c4178eba35c374831031d1a58.tar.bz2
strace-2df03c494eb3c36c4178eba35c374831031d1a58.tar.xz
Stop using external libaio.h.
This change incorporates a partial copy instead of using external libaio.h. Why? Because we want to properly decode 32-bit aio calls by 64-bit strace. For that, we need more definitions than libaio.h provides. (These defs are not done yet, but will eventually be done). Keeping our local 32-bit compat defs in sync with libaio.h _without seeing libaio structs_ is hard/more bug prone. A smaller benefit is that we don't need libaio installed. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--configure.ac5
-rw-r--r--desc.c143
2 files changed, 124 insertions, 24 deletions
diff --git a/configure.ac b/configure.ac
index aa4923a..5b4c38e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -309,11 +309,6 @@ AC_CHECK_SIZEOF([long])
AC_CHECK_SIZEOF([long long])
AC_CHECK_SIZEOF([rlim_t],,[#include <sys/resource.h>])
-AC_CHECK_HEADERS([libaio.h], [
- AC_CHECK_MEMBERS([struct iocb.u.c.flags],,, [#include <libaio.h>])
- AC_CHECK_DECLS([IO_CMD_PWRITE, IO_CMD_PWRITEV],,, [#include <libaio.h>])
-])
-
AC_PATH_PROG([PERL], [perl])
AC_CONFIG_FILES([Makefile tests/Makefile])
diff --git a/desc.c b/desc.c
index dff3846..053a3d0 100644
--- a/desc.c
+++ b/desc.c
@@ -34,13 +34,133 @@
#ifdef HAVE_SYS_EPOLL_H
# include <sys/epoll.h>
#endif
-#ifdef HAVE_LIBAIO_H
-# include <libaio.h>
-#endif
#ifdef HAVE_LINUX_PERF_EVENT_H
# include <linux/perf_event.h>
#endif
+/* --- Copied from libaio-0.3.109/src/libaio.h ---
+ * Why keep a copy instead of using external libaio.h?
+ * Because we want to properly decode 32-bit aio calls
+ * by 64-bit strace. For that, we need more definitions than
+ * libaio.h provides. (TODO).
+ * Keeping our local 32-bit compat defs in sync with libaio.h
+ * _without seeing libaio structs_ is hard/more bug-prone.
+ * A smaller benefit is that we don't need libaio installed.
+ */
+#define HAVE_LIBAIO_H 1
+typedef enum io_iocb_cmd {
+ IO_CMD_PREAD = 0,
+ IO_CMD_PWRITE = 1,
+
+ IO_CMD_FSYNC = 2,
+ IO_CMD_FDSYNC = 3,
+
+ IO_CMD_POLL = 5, /* Never implemented in mainline, see io_prep_poll */
+ IO_CMD_NOOP = 6,
+ IO_CMD_PREADV = 7,
+ IO_CMD_PWRITEV = 8,
+} io_iocb_cmd_t;
+
+#if defined(__i386__) /* little endian, 32 bits */
+#define PADDED(x, y) x; unsigned y
+#define PADDEDptr(x, y) x; unsigned y
+#define PADDEDul(x, y) unsigned long x; unsigned y
+#elif defined(__ia64__) || defined(__x86_64__) || defined(__alpha__)
+#define PADDED(x, y) x, y
+#define PADDEDptr(x, y) x
+#define PADDEDul(x, y) unsigned long x
+#elif defined(__powerpc64__) /* big endian, 64 bits */
+#define PADDED(x, y) unsigned y; x
+#define PADDEDptr(x,y) x
+#define PADDEDul(x, y) unsigned long x
+#elif defined(__PPC__) /* big endian, 32 bits */
+#define PADDED(x, y) unsigned y; x
+#define PADDEDptr(x, y) unsigned y; x
+#define PADDEDul(x, y) unsigned y; unsigned long x
+#elif defined(__s390x__) /* big endian, 64 bits */
+#define PADDED(x, y) unsigned y; x
+#define PADDEDptr(x,y) x
+#define PADDEDul(x, y) unsigned long x
+#elif defined(__s390__) /* big endian, 32 bits */
+#define PADDED(x, y) unsigned y; x
+#define PADDEDptr(x, y) unsigned y; x
+#define PADDEDul(x, y) unsigned y; unsigned long x
+#elif defined(__arm__)
+# if defined (__ARMEB__) /* big endian, 32 bits */
+#define PADDED(x, y) unsigned y; x
+#define PADDEDptr(x, y) unsigned y; x
+#define PADDEDul(x, y) unsigned y; unsigned long x
+# else /* little endian, 32 bits */
+#define PADDED(x, y) x; unsigned y
+#define PADDEDptr(x, y) x; unsigned y
+#define PADDEDul(x, y) unsigned long x; unsigned y
+# endif
+#else
+# warning No AIO definitions for this architecture => no io_submit decoding
+# undef HAVE_LIBAIO_H
+#endif
+
+#ifdef HAVE_LIBAIO_H
+struct io_iocb_poll {
+ PADDED(int events, __pad1);
+}; /* result code is the set of result flags or -'ve errno */
+
+struct io_iocb_sockaddr {
+ struct sockaddr *addr;
+ int len;
+}; /* result code is the length of the sockaddr, or -'ve errno */
+
+struct io_iocb_common {
+ PADDEDptr(void *buf, __pad1);
+ PADDEDul(nbytes, __pad2);
+ long long offset;
+ long long __pad3;
+ unsigned flags;
+ unsigned resfd;
+}; /* result code is the amount read or -'ve errno */
+
+struct io_iocb_vector {
+ const struct iovec *vec;
+ int nr;
+ long long offset;
+}; /* result code is the amount read or -'ve errno */
+
+struct iocb {
+ PADDEDptr(void *data, __pad1); /* Return in the io completion event */
+ PADDED(unsigned key, __pad2); /* For use in identifying io requests */
+
+ short aio_lio_opcode;
+ short aio_reqprio;
+ int aio_fildes;
+
+ union {
+ struct io_iocb_common c;
+ struct io_iocb_vector v;
+ struct io_iocb_poll poll;
+ struct io_iocb_sockaddr saddr;
+ } u;
+};
+
+struct io_event {
+ PADDEDptr(void *data, __pad1);
+ PADDEDptr(struct iocb *obj, __pad2);
+ PADDEDul(res, __pad3);
+ PADDEDul(res2, __pad4);
+};
+
+#undef PADDED
+#undef PADDEDptr
+#undef PADDEDul
+
+#endif /* HAVE_LIBAIO_H */
+
+/* --- End of a chunk of libaio.h --- */
+/* Not defined in libaio.h */
+#ifndef IOCB_RESFD
+# define IOCB_RESFD (1 << 0)
+#endif
+
+
static const struct xlat fcntlcmds[] = {
{ F_DUPFD, "F_DUPFD" },
{ F_GETFD, "F_GETFD" },
@@ -869,22 +989,13 @@ tprint_lio_opcode(unsigned cmd)
return SUB_NONE;
}
-/* Not defined in libaio.h */
-#ifndef IOCB_RESFD
-# define IOCB_RESFD (1 << 0)
-#endif
-
static void
print_common_flags(struct iocb *iocb)
{
-#if HAVE_STRUCT_IOCB_U_C_FLAGS
if (iocb->u.c.flags & IOCB_RESFD)
tprintf(", resfd=%d", iocb->u.c.resfd);
if (iocb->u.c.flags & ~IOCB_RESFD)
tprintf(", flags=%x", iocb->u.c.flags);
-#else
-# warning "libaio.h is too old => limited io_submit decoding"
-#endif
}
#endif /* HAVE_LIBAIO_H */
@@ -900,6 +1011,7 @@ sys_io_submit(struct tcb *tcp)
{
long i;
struct iocb **iocbs = (void *)tcp->u_arg[2];
+//FIXME: decoding of 32-bit call by 64-bit strace
for (i = 0; i < nr; i++, iocbs++) {
enum iocb_sub sub;
@@ -929,13 +1041,11 @@ sys_io_submit(struct tcb *tcp)
tprintf(", filedes:%d", iocb.aio_fildes);
switch (sub) {
case SUB_COMMON:
-#if HAVE_DECL_IO_CMD_PWRITE
if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
tprints(", str:");
printstr(tcp, (unsigned long)iocb.u.c.buf,
iocb.u.c.nbytes);
} else
-#endif
tprintf(", buf:%p", iocb.u.c.buf);
tprintf(", nbytes:%lu, offset:%lld",
iocb.u.c.nbytes,
@@ -948,11 +1058,7 @@ sys_io_submit(struct tcb *tcp)
tprints(", ");
tprint_iov(tcp, iocb.u.v.nr,
(unsigned long)iocb.u.v.vec,
-#if HAVE_DECL_IO_CMD_PWRITEV
iocb.aio_lio_opcode == IO_CMD_PWRITEV
-#else
- 0
-#endif
);
break;
case SUB_POLL:
@@ -966,7 +1072,6 @@ sys_io_submit(struct tcb *tcp)
}
tprints("}");
#else
-#warning "libaio.h is not available => no io_submit decoding"
tprintf("%lu, %ld, %#lx", tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
#endif
}