diff mbox

[1/5] linux-user: add socketcall() strace

Message ID 1465417472-11359-2-git-send-email-laurent@vivier.eu (mailing list archive)
State New, archived
Headers show

Commit Message

Laurent Vivier June 8, 2016, 8:24 p.m. UTC
From: Laurent Vivier <Laurent@Vivier.EU>

Signed-off-by: Laurent Vivier <Laurent@Vivier.EU>
---
 include/exec/user/abitypes.h |  23 ++
 linux-user/strace.c          | 550 +++++++++++++++++++++++++++++++++++++++++++
 linux-user/strace.list       |   2 +-
 linux-user/syscall_defs.h    |  22 +-
 4 files changed, 592 insertions(+), 5 deletions(-)

Comments

Peter Maydell June 10, 2016, 12:51 p.m. UTC | #1
On 8 June 2016 at 21:24, Laurent Vivier <laurent@vivier.eu> wrote:
> From: Laurent Vivier <Laurent@Vivier.EU>
>
> Signed-off-by: Laurent Vivier <Laurent@Vivier.EU>
> ---
>  include/exec/user/abitypes.h |  23 ++
>  linux-user/strace.c          | 550 +++++++++++++++++++++++++++++++++++++++++++
>  linux-user/strace.list       |   2 +-
>  linux-user/syscall_defs.h    |  22 +-
>  4 files changed, 592 insertions(+), 5 deletions(-)

I have a few comments, but this mostly looks good.

> diff --git a/include/exec/user/abitypes.h b/include/exec/user/abitypes.h
> index 80eedac..e33b1f8 100644
> --- a/include/exec/user/abitypes.h
> +++ b/include/exec/user/abitypes.h
> @@ -46,6 +46,15 @@ static inline abi_ulong tswapal(abi_ulong v)
>      return tswap32(v);
>  }
>
> +static inline abi_ulong abi_ntohl(abi_ulong v)
> +{
> +#if defined(HOST_BIG_ENDIAN)
> +    return v;
> +#else
> +    return bswap_32(v);
> +#endif
> +}
> +
>  #else
>  typedef target_ulong abi_ulong __attribute__((aligned(ABI_LONG_ALIGNMENT)));
>  typedef target_long abi_long __attribute__((aligned(ABI_LONG_ALIGNMENT)));
> @@ -62,5 +71,19 @@ static inline abi_ulong tswapal(abi_ulong v)
>      return tswapl(v);
>  }
>
> +static inline abi_ulong abi_ntohl(abi_ulong v)
> +{
> +#if defined(HOST_BIG_ENDIAN)
> +    return v;
> +#else
> +#if TARGET_LONG_SIZE == 4
> +    return bswap_32(v);
> +#else
> +    return bswap_64(v);
> +#endif
> +#endif
> +}
> +
> +
>  #endif
>  #endif

I suspect we don't actually need an abi_ntohl() -- see below.

> @@ -1004,6 +1221,339 @@ print__llseek(const struct syscallname *name,
>  }
>  #endif
>
> +#if defined(TARGET_NR_socketcall)
> +static void
> +print_socketcall(const struct syscallname *name,
> +                 abi_long arg0, abi_long arg1, abi_long arg2,
> +                 abi_long arg3, abi_long arg4, abi_long arg5)
> +{
> +    const int n = sizeof(abi_ulong);

This is a kind of confusing variable name for this.

(Should we use the same code that do_socketcall in syscall.c
does to read the right number of arguments into an array
of abi_ulongs ?)

> +    const char *socketcallname;
> +
> +    switch (arg0) {
> +    case SOCKOP_bind: {
> +        abi_ulong sockfd, addr, addrlen;
> +
> +        socketcallname = "bind";
> +
> +print_sockaddr:
> +        get_user_ual(sockfd, arg1);
> +        get_user_ual(addr, arg1 + n);
> +        get_user_ual(addrlen, arg1 + 2 * n);
> +
> +        gemu_log("%s(", socketcallname);
> +        print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
> +        print_sockaddr(addr, addrlen);
> +        gemu_log(")");
> +        break;

I think a helper function so you just say
do_print_sockaddr("bind", arg1);
would be nicer than these gotos. Similarly with the other code
like this below.

> +    }
> +    case SOCKOP_connect:
> +        socketcallname = "connect";
> +        goto print_sockaddr;
> +    case SOCKOP_accept:
> +        socketcallname = "accept";
> +        goto print_sockaddr;
> +    case SOCKOP_getsockname:
> +        socketcallname = "getsockname";
> +        goto print_sockaddr;
> +    case SOCKOP_getpeername:
> +        socketcallname = "getpeername";
> +        goto print_sockaddr;
> +    case SOCKOP_socket: {
> +        abi_ulong domain, type, protocol;
> +
> +        get_user_ual(domain, arg1);
> +        get_user_ual(type, arg1 + n);
> +        get_user_ual(protocol, arg1 + 2 * n);
> +        gemu_log("socket(");
> +        print_socket_domain(domain);
> +        gemu_log(",");
> +        print_socket_type(type);
> +        gemu_log(",");
> +        if (domain == AF_PACKET ||
> +            type == TARGET_SOCK_PACKET) {
> +            protocol = tswapal(protocol); /* restore network endian long */
> +            protocol = abi_ntohl(protocol); /* a host endian long */

This doesn't seem to match the kind of byteswapping we do in the
syscall.c code, which just does a tswap16().

> +        }
> +        print_socket_protocol(domain, type, protocol);
> +        gemu_log(")");
> +        break;
> +    }

thanks
-- PMM
diff mbox

Patch

diff --git a/include/exec/user/abitypes.h b/include/exec/user/abitypes.h
index 80eedac..e33b1f8 100644
--- a/include/exec/user/abitypes.h
+++ b/include/exec/user/abitypes.h
@@ -46,6 +46,15 @@  static inline abi_ulong tswapal(abi_ulong v)
     return tswap32(v);
 }
 
+static inline abi_ulong abi_ntohl(abi_ulong v)
+{
+#if defined(HOST_BIG_ENDIAN)
+    return v;
+#else
+    return bswap_32(v);
+#endif
+}
+
 #else
 typedef target_ulong abi_ulong __attribute__((aligned(ABI_LONG_ALIGNMENT)));
 typedef target_long abi_long __attribute__((aligned(ABI_LONG_ALIGNMENT)));
@@ -62,5 +71,19 @@  static inline abi_ulong tswapal(abi_ulong v)
     return tswapl(v);
 }
 
+static inline abi_ulong abi_ntohl(abi_ulong v)
+{
+#if defined(HOST_BIG_ENDIAN)
+    return v;
+#else
+#if TARGET_LONG_SIZE == 4
+    return bswap_32(v);
+#else
+    return bswap_64(v);
+#endif
+#endif
+}
+
+
 #endif
 #endif
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 0810c85..a7b24e2 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -6,6 +6,9 @@ 
 #include <sys/select.h>
 #include <sys/mount.h>
 #include <sys/mman.h>
+#include <arpa/inet.h>
+#include <netinet/tcp.h>
+#include <linux/if_packet.h>
 #include <sched.h>
 #include "qemu.h"
 
@@ -58,10 +61,15 @@  UNUSED static void print_open_flags(abi_long, int);
 UNUSED static void print_syscall_prologue(const struct syscallname *);
 UNUSED static void print_syscall_epilogue(const struct syscallname *);
 UNUSED static void print_string(abi_long, int);
+UNUSED static void print_buf(abi_long addr, abi_long len, int last);
 UNUSED static void print_raw_param(const char *, abi_long, int);
 UNUSED static void print_timeval(abi_ulong, int);
 UNUSED static void print_number(abi_long, int);
 UNUSED static void print_signal(abi_ulong, int);
+UNUSED static void print_sockaddr(abi_ulong addr, abi_long addrlen);
+UNUSED static void print_socket_domain(int domain);
+UNUSED static void print_socket_type(int type);
+UNUSED static void print_socket_protocol(int domain, int type, int protocol);
 
 /*
  * Utility functions
@@ -147,6 +155,165 @@  print_signal(abi_ulong arg, int last)
     gemu_log("%s%s", signal_name, get_comma(last));
 }
 
+static void
+print_sockaddr(abi_ulong addr, abi_long addrlen)
+{
+    struct target_sockaddr *sa;
+    int i;
+    int sa_family;
+
+    sa = lock_user(VERIFY_READ, addr, addrlen, 1);
+    if (sa) {
+        sa_family = tswap16(sa->sa_family);
+        switch (sa_family) {
+        case AF_UNIX: {
+            struct target_sockaddr_un *un = (struct target_sockaddr_un *)sa;
+            int i;
+            gemu_log("{sun_family=AF_UNIX,sun_path=\"");
+            for (i = 0; i < addrlen -
+                            offsetof(struct target_sockaddr_un, sun_path) &&
+                 un->sun_path[i]; i++) {
+                gemu_log("%c", un->sun_path[i]);
+            }
+            gemu_log("\"}");
+            break;
+        }
+        case AF_INET: {
+            struct target_sockaddr_in *in = (struct target_sockaddr_in *)sa;
+            uint8_t *c = (uint8_t *)&in->sin_addr.s_addr;
+            gemu_log("{sin_family=AF_INET,sin_port=htons(%d),",
+                     ntohs(in->sin_port));
+            gemu_log("sin_addr=inet_addr(\"%d.%d.%d.%d\")",
+                     c[0], c[1], c[2], c[3]);
+            gemu_log("}");
+            break;
+        }
+        case AF_PACKET: {
+            struct target_sockaddr_ll *ll = (struct target_sockaddr_ll *)sa;
+            uint8_t *c = (uint8_t *)&ll->sll_addr;
+            gemu_log("{sll_family=AF_PACKET,"
+                     "sll_protocol=htons(0x%04x),if%d,pkttype=",
+                     ntohs(ll->sll_protocol), ll->sll_ifindex);
+            switch (ll->sll_pkttype) {
+            case PACKET_HOST:
+                gemu_log("PACKET_HOST");
+                break;
+            case PACKET_BROADCAST:
+                gemu_log("PACKET_BROADCAST");
+                break;
+            case PACKET_MULTICAST:
+                gemu_log("PACKET_MULTICAST");
+                break;
+            case PACKET_OTHERHOST:
+                gemu_log("PACKET_OTHERHOST");
+                break;
+            case PACKET_OUTGOING:
+                gemu_log("PACKET_OUTGOING");
+                break;
+            default:
+                gemu_log("%d", ll->sll_pkttype);
+                break;
+            }
+            gemu_log(",sll_addr=%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
+                     c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
+            gemu_log("}");
+            break;
+        }
+        default:
+            gemu_log("{sa_family=%d, sa_data={", sa->sa_family);
+            for (i = 0; i < 13; i++) {
+                gemu_log("%02x, ", sa->sa_data[i]);
+            }
+            gemu_log("%02x}", sa->sa_data[i]);
+            gemu_log("}");
+            break;
+        }
+        unlock_user(sa, addr, 0);
+    } else {
+        print_raw_param("0x"TARGET_ABI_FMT_lx, addr, 0);
+    }
+    gemu_log(", "TARGET_ABI_FMT_ld, addrlen);
+}
+
+static void
+print_socket_domain(int domain)
+{
+    switch (domain) {
+    case PF_UNIX:
+        gemu_log("PF_UNIX");
+        break;
+    case PF_INET:
+        gemu_log("PF_INET");
+        break;
+    case PF_PACKET:
+        gemu_log("PF_PACKET");
+        break;
+    default:
+        gemu_log("%d", domain);
+        break;
+    }
+}
+
+static void
+print_socket_type(int type)
+{
+    switch (type) {
+    case TARGET_SOCK_DGRAM:
+        gemu_log("SOCK_DGRAM");
+        break;
+    case TARGET_SOCK_STREAM:
+        gemu_log("SOCK_STREAM");
+        break;
+    case TARGET_SOCK_RAW:
+        gemu_log("SOCK_RAW");
+        break;
+    case TARGET_SOCK_RDM:
+        gemu_log("SOCK_RDM");
+        break;
+    case TARGET_SOCK_SEQPACKET:
+        gemu_log("SOCK_SEQPACKET");
+        break;
+    case TARGET_SOCK_PACKET:
+        gemu_log("SOCK_PACKET");
+        break;
+    }
+}
+
+static void
+print_socket_protocol(int domain, int type, int protocol)
+{
+    if (domain == AF_PACKET ||
+        type == TARGET_SOCK_PACKET) {
+        switch (protocol) {
+        case 0x0003:
+            gemu_log("ETH_P_ALL");
+            break;
+        default:
+            gemu_log("%d", protocol);
+        }
+        return;
+    }
+
+    switch (protocol) {
+    case IPPROTO_IP:
+        gemu_log("IPPROTO_IP");
+        break;
+    case IPPROTO_TCP:
+        gemu_log("IPPROTO_TCP");
+        break;
+    case IPPROTO_UDP:
+        gemu_log("IPPROTO_UDP");
+        break;
+    case IPPROTO_RAW:
+        gemu_log("IPPROTO_RAW");
+        break;
+    default:
+        gemu_log("%d", protocol);
+        break;
+    }
+}
+
+
 #ifdef TARGET_NR__newselect
 static void
 print_fdset(int n, abi_ulong target_fds_addr)
@@ -498,6 +665,26 @@  UNUSED static struct flags clone_flags[] = {
     FLAG_END,
 };
 
+UNUSED static struct flags msg_flags[] = {
+    /* send */
+    FLAG_GENERIC(MSG_CONFIRM),
+    FLAG_GENERIC(MSG_DONTROUTE),
+    FLAG_GENERIC(MSG_DONTWAIT),
+    FLAG_GENERIC(MSG_EOR),
+    FLAG_GENERIC(MSG_MORE),
+    FLAG_GENERIC(MSG_NOSIGNAL),
+    FLAG_GENERIC(MSG_OOB),
+    /* recv */
+    FLAG_GENERIC(MSG_CMSG_CLOEXEC),
+    FLAG_GENERIC(MSG_ERRQUEUE),
+    FLAG_GENERIC(MSG_PEEK),
+    FLAG_GENERIC(MSG_TRUNC),
+    FLAG_GENERIC(MSG_WAITALL),
+    /* recvmsg */
+    FLAG_GENERIC(MSG_CTRUNC),
+    FLAG_END,
+};
+
 /*
  * print_xxx utility functions.  These are used to print syscall
  * parameters in certain format.  All of these have parameter
@@ -619,6 +806,36 @@  print_string(abi_long addr, int last)
     }
 }
 
+#define MAX_PRINT_BUF 40
+static void
+print_buf(abi_long addr, abi_long len, int last)
+{
+    uint8_t *s;
+    int i;
+
+    s = lock_user(VERIFY_READ, addr, len, 1);
+    if (s) {
+        gemu_log("\"");
+        for (i = 0; i < MAX_PRINT_BUF && i < len; i++) {
+            if (isprint(s[i])) {
+                gemu_log("%c", s[i]);
+            } else {
+                gemu_log("\\%o", s[i]);
+            }
+        }
+        gemu_log("\"");
+        if (i != len) {
+            gemu_log("...");
+        }
+        if (!last) {
+            gemu_log(",");
+        }
+        unlock_user(s, addr, 0);
+    } else {
+        print_pointer(addr, last);
+    }
+}
+
 /*
  * Prints out raw parameter using given format.  Caller needs
  * to do byte swapping if needed.
@@ -1004,6 +1221,339 @@  print__llseek(const struct syscallname *name,
 }
 #endif
 
+#if defined(TARGET_NR_socketcall)
+static void
+print_socketcall(const struct syscallname *name,
+                 abi_long arg0, abi_long arg1, abi_long arg2,
+                 abi_long arg3, abi_long arg4, abi_long arg5)
+{
+    const int n = sizeof(abi_ulong);
+    const char *socketcallname;
+
+    switch (arg0) {
+    case SOCKOP_bind: {
+        abi_ulong sockfd, addr, addrlen;
+
+        socketcallname = "bind";
+
+print_sockaddr:
+        get_user_ual(sockfd, arg1);
+        get_user_ual(addr, arg1 + n);
+        get_user_ual(addrlen, arg1 + 2 * n);
+
+        gemu_log("%s(", socketcallname);
+        print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
+        print_sockaddr(addr, addrlen);
+        gemu_log(")");
+        break;
+    }
+    case SOCKOP_connect:
+        socketcallname = "connect";
+        goto print_sockaddr;
+    case SOCKOP_accept:
+        socketcallname = "accept";
+        goto print_sockaddr;
+    case SOCKOP_getsockname:
+        socketcallname = "getsockname";
+        goto print_sockaddr;
+    case SOCKOP_getpeername:
+        socketcallname = "getpeername";
+        goto print_sockaddr;
+    case SOCKOP_socket: {
+        abi_ulong domain, type, protocol;
+
+        get_user_ual(domain, arg1);
+        get_user_ual(type, arg1 + n);
+        get_user_ual(protocol, arg1 + 2 * n);
+        gemu_log("socket(");
+        print_socket_domain(domain);
+        gemu_log(",");
+        print_socket_type(type);
+        gemu_log(",");
+        if (domain == AF_PACKET ||
+            type == TARGET_SOCK_PACKET) {
+            protocol = tswapal(protocol); /* restore network endian long */
+            protocol = abi_ntohl(protocol); /* a host endian long */
+        }
+        print_socket_protocol(domain, type, protocol);
+        gemu_log(")");
+        break;
+    }
+    case SOCKOP_listen: {
+        abi_ulong sockfd, backlog;
+
+        get_user_ual(sockfd, arg1);
+        get_user_ual(backlog, arg1 + n);
+
+        gemu_log("listen(");
+        print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
+        print_raw_param(TARGET_ABI_FMT_ld, backlog, 1);
+        gemu_log(")");
+        break;
+    }
+    case SOCKOP_socketpair: {
+        abi_ulong domain, type, protocol, tab;
+
+        get_user_ual(domain, arg1);
+        get_user_ual(type, arg1 + n);
+        get_user_ual(protocol, arg1 + 2 * n);
+        get_user_ual(tab, arg1 + 3 * n);
+
+        gemu_log("socketpair(");
+        print_socket_domain(domain);
+        gemu_log(",");
+        print_socket_type(type);
+        gemu_log(",");
+        print_socket_protocol(domain, type, protocol);
+        gemu_log(",");
+        print_raw_param(TARGET_ABI_FMT_lx, tab, 1);
+        gemu_log(")");
+        break;
+    }
+    case SOCKOP_send: {
+        abi_ulong sockfd, msg, len, flags;
+
+        socketcallname = "send";
+
+print_sock:
+        get_user_ual(sockfd, arg1);
+        get_user_ual(msg, arg1 + n);
+        get_user_ual(len, arg1 + 2 * n);
+        get_user_ual(flags, arg1 + 3 * n);
+
+        gemu_log("%s(", socketcallname);
+        print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
+        print_buf(msg, len, 0);
+        print_raw_param(TARGET_ABI_FMT_ld, len, 0);
+        print_flags(msg_flags, flags, 1);
+        gemu_log(")");
+        break;
+    }
+    case SOCKOP_recv:
+        socketcallname = "recv";
+        goto print_sock;
+    case SOCKOP_sendto: {
+        abi_ulong sockfd, msg, len, flags, addr, addrlen;
+
+        socketcallname = "sendto";
+
+print_msgaddr:
+        get_user_ual(sockfd, arg1);
+        get_user_ual(msg, arg1 + n);
+        get_user_ual(len, arg1 + 2 * n);
+        get_user_ual(flags, arg1 + 3 * n);
+        get_user_ual(addr, arg1 + 4 * n);
+        get_user_ual(addrlen, arg1 + 5 * n);
+
+        gemu_log("%s(", socketcallname);
+        print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
+        print_buf(msg, len, 0);
+        print_raw_param(TARGET_ABI_FMT_ld, len, 0);
+        print_flags(msg_flags, flags, 0);
+        print_sockaddr(addr, addrlen);
+        gemu_log(")");
+        break;
+    }
+    case SOCKOP_recvfrom:
+        socketcallname = "recvfrom";
+        goto print_msgaddr;
+    case SOCKOP_shutdown: {
+        abi_ulong sockfd, how;
+
+        get_user_ual(sockfd, arg1);
+        get_user_ual(how, arg1 + n);
+
+        gemu_log("shutdown(");
+        print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
+        switch (how) {
+        case SHUT_RD:
+            gemu_log("SHUT_RD");
+            break;
+        case SHUT_WR:
+            gemu_log("SHUT_WR");
+            break;
+        case SHUT_RDWR:
+            gemu_log("SHUT_RDWR");
+            break;
+        default:
+            print_raw_param(TARGET_ABI_FMT_ld, how, 1);
+            break;
+        }
+        gemu_log(")");
+        break;
+    }
+    case SOCKOP_sendmsg: {
+        abi_ulong sockfd, msg, flags;
+
+        socketcallname = "sendmsg";
+print_msg:
+        get_user_ual(sockfd, arg1);
+        get_user_ual(msg, arg1 + n);
+        get_user_ual(flags, arg1 + 2 * n);
+
+        gemu_log("%s(", socketcallname);
+        print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
+        print_pointer(msg, 0);
+        print_flags(msg_flags, flags, 1);
+        gemu_log(")");
+        break;
+    }
+    case SOCKOP_recvmsg:
+        socketcallname = "recvmsg";
+        goto print_msg;
+    case SOCKOP_setsockopt: {
+        abi_ulong sockfd, level, optname, optval, optlen;
+
+        socketcallname = "setsockopt";
+
+print_sockopt:
+        get_user_ual(sockfd, arg1);
+        get_user_ual(level, arg1 + n);
+        get_user_ual(optname, arg1 + 2 * n);
+        get_user_ual(optval, arg1 + 3 * n);
+        get_user_ual(optlen, arg1 + 4 * n);
+
+        gemu_log("%s(", socketcallname);
+        print_raw_param(TARGET_ABI_FMT_ld, sockfd, 0);
+        switch (level) {
+        case SOL_TCP:
+            gemu_log("SOL_TCP,");
+            print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
+            print_pointer(optval, 0);
+            break;
+        case SOL_IP:
+            gemu_log("SOL_IP,");
+            print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
+            print_pointer(optval, 0);
+            break;
+        case SOL_RAW:
+            gemu_log("SOL_RAW,");
+            print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
+            print_pointer(optval, 0);
+            break;
+        case TARGET_SOL_SOCKET:
+            gemu_log("SOL_SOCKET,");
+            switch (optname) {
+            case TARGET_SO_DEBUG:
+                gemu_log("SO_DEBUG,");
+print_optint:
+                print_number(optval, 0);
+                break;
+            case TARGET_SO_REUSEADDR:
+                gemu_log("SO_REUSEADDR,");
+                goto print_optint;
+            case TARGET_SO_TYPE:
+                gemu_log("SO_TYPE,");
+                goto print_optint;
+            case TARGET_SO_ERROR:
+                gemu_log("SO_ERROR,");
+                goto print_optint;
+            case TARGET_SO_DONTROUTE:
+                gemu_log("SO_DONTROUTE,");
+                goto print_optint;
+            case TARGET_SO_BROADCAST:
+                gemu_log("SO_BROADCAST,");
+                goto print_optint;
+            case TARGET_SO_SNDBUF:
+                gemu_log("SO_SNDBUF,");
+                goto print_optint;
+            case TARGET_SO_RCVBUF:
+                gemu_log("SO_RCVBUF,");
+                goto print_optint;
+            case TARGET_SO_KEEPALIVE:
+                gemu_log("SO_KEEPALIVE,");
+                goto print_optint;
+            case TARGET_SO_OOBINLINE:
+                gemu_log("SO_OOBINLINE,");
+                goto print_optint;
+            case TARGET_SO_NO_CHECK:
+                gemu_log("SO_NO_CHECK,");
+                goto print_optint;
+            case TARGET_SO_PRIORITY:
+                gemu_log("SO_PRIORITY,");
+                goto print_optint;
+            case TARGET_SO_BSDCOMPAT:
+                gemu_log("SO_BSDCOMPAT,");
+                goto print_optint;
+            case TARGET_SO_PASSCRED:
+                gemu_log("SO_PASSCRED,");
+                goto print_optint;
+            case TARGET_SO_TIMESTAMP:
+                gemu_log("SO_TIMESTAMP,");
+                goto print_optint;
+            case TARGET_SO_RCVLOWAT:
+                gemu_log("SO_RCVLOWAT,");
+                goto print_optint;
+            case TARGET_SO_RCVTIMEO:
+                gemu_log("SO_RCVTIMEO,");
+                goto print_optint;
+            case TARGET_SO_SNDTIMEO:
+                gemu_log("SO_SNDTIMEO,");
+                goto print_optint;
+            case TARGET_SO_ATTACH_FILTER: {
+                struct target_sock_fprog *fprog;
+
+                gemu_log("SO_ATTACH_FILTER,");
+
+                if (lock_user_struct(VERIFY_READ, fprog, optval,  0)) {
+                    struct target_sock_filter *filter;
+                    gemu_log("{");
+                    if (lock_user_struct(VERIFY_READ, filter,
+                                         tswapal(fprog->filter),  0)) {
+                        int i;
+                        for (i = 0; i < tswap16(fprog->len) - 1; i++) {
+                            gemu_log("[%d]{0x%x,%d,%d,0x%x},",
+                                     i, tswap16(filter[i].code),
+                                     filter[i].jt, filter[i].jf,
+                                     tswap32(filter[i].k));
+                        }
+                        gemu_log("[%d]{0x%x,%d,%d,0x%x}",
+                                 i, tswap16(filter[i].code),
+                                 filter[i].jt, filter[i].jf,
+                                 tswap32(filter[i].k));
+                    } else {
+                        gemu_log(TARGET_ABI_FMT_lx, tswapal(fprog->filter));
+                    }
+                    gemu_log(",%d},", tswap16(fprog->len));
+                    unlock_user(fprog, optval, 0);
+                } else {
+                    print_pointer(optval, 0);
+                }
+                break;
+            }
+            default:
+                print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
+                print_pointer(optval, 0);
+                break;
+            }
+            break;
+        default:
+            print_raw_param(TARGET_ABI_FMT_ld, level, 0);
+            print_raw_param(TARGET_ABI_FMT_ld, optname, 0);
+            print_pointer(optval, 0);
+            break;
+        }
+        print_raw_param(TARGET_ABI_FMT_ld, optlen, 1);
+        gemu_log(")");
+        break;
+    }
+    case SOCKOP_getsockopt:
+        socketcallname = "getsockopt";
+        goto print_sockopt;
+    default:
+        print_syscall_prologue(name);
+        print_raw_param(TARGET_ABI_FMT_ld, arg0, 0);
+        print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
+        print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
+        print_raw_param(TARGET_ABI_FMT_ld, arg3, 0);
+        print_raw_param(TARGET_ABI_FMT_ld, arg4, 0);
+        print_raw_param(TARGET_ABI_FMT_ld, arg5, 0);
+        print_syscall_epilogue(name);
+        break;
+    }
+}
+#endif
+
 #if defined(TARGET_NR_stat) || defined(TARGET_NR_stat64) || \
     defined(TARGET_NR_lstat) || defined(TARGET_NR_lstat64)
 static void
diff --git a/linux-user/strace.list b/linux-user/strace.list
index aa0cd73..b379497 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -1294,7 +1294,7 @@ 
 { TARGET_NR_socket, "socket" , NULL, NULL, NULL },
 #endif
 #ifdef TARGET_NR_socketcall
-{ TARGET_NR_socketcall, "socketcall" , NULL, NULL, NULL },
+{ TARGET_NR_socketcall, "socketcall" , NULL, print_socketcall, NULL },
 #endif
 #ifdef TARGET_NR_socketpair
 { TARGET_NR_socketpair, "socketpair" , NULL, NULL, NULL },
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 34af15a..6270f79 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -135,6 +135,24 @@  struct target_sockaddr_ll {
     uint8_t  sll_addr[8];  /* Physical layer address */
 };
 
+struct target_sockaddr_un {
+    uint16_t su_family;
+    uint8_t sun_path[108];
+};
+
+struct target_in_addr {
+    uint32_t s_addr; /* big endian */
+};
+
+struct target_sockaddr_in {
+  uint16_t sin_family;
+  int16_t sin_port; /* big endian */
+  struct target_in_addr sin_addr;
+  uint8_t __pad[sizeof(struct target_sockaddr) -
+                sizeof(uint16_t) - sizeof(int16_t) -
+                sizeof(struct target_in_addr)];
+};
+
 struct target_sock_filter {
     abi_ushort code;
     uint8_t jt;
@@ -147,10 +165,6 @@  struct target_sock_fprog {
     abi_ulong filter;
 };
 
-struct target_in_addr {
-    uint32_t s_addr; /* big endian */
-};
-
 struct target_ip_mreq {
     struct target_in_addr imr_multiaddr;
     struct target_in_addr imr_address;