From owner-svn-src-all@FreeBSD.ORG Thu Apr 24 14:12:35 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CA4068C7; Thu, 24 Apr 2014 14:12:35 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B626C1D2B; Thu, 24 Apr 2014 14:12:35 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3OECZ7H064851; Thu, 24 Apr 2014 14:12:35 GMT (envelope-from smh@svn.freebsd.org) Received: (from smh@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3OECZSX064849; Thu, 24 Apr 2014 14:12:35 GMT (envelope-from smh@svn.freebsd.org) Message-Id: <201404241412.s3OECZSX064849@svn.freebsd.org> From: Steven Hartland Date: Thu, 24 Apr 2014 14:12:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264881 - head/usr.bin/truss X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Apr 2014 14:12:36 -0000 Author: smh Date: Thu Apr 24 14:12:35 2014 New Revision: 264881 URL: http://svnweb.freebsd.org/changeset/base/264881 Log: Add Linux socket call decoding to truss MFC after: 1 month Modified: head/usr.bin/truss/syscall.h head/usr.bin/truss/syscalls.c Modified: head/usr.bin/truss/syscall.h ============================================================================== --- head/usr.bin/truss/syscall.h Thu Apr 24 12:54:35 2014 (r264880) +++ head/usr.bin/truss/syscall.h Thu Apr 24 14:12:35 2014 (r264881) @@ -39,7 +39,8 @@ enum Argtype { None = 1, Hex, Octal, Int Fd_set, Sigaction, Fcntl, Mprot, Mmapflags, Whence, Readlinkres, Sigset, Sigprocmask, Kevent, Sockdomain, Socktype, Open, Fcntlflag, Rusage, BinString, Shutdown, Resource, Rlimit, Timeval2, - Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype, Procctl }; + Pathconf, Rforkflags, ExitStatus, Waitoptions, Idtype, Procctl, + LinuxSockArgs }; #define ARG_MASK 0xff #define OUT 0x100 @@ -63,6 +64,47 @@ struct syscall { struct syscall *get_syscall(const char*); char *print_arg(struct syscall_args *, unsigned long*, long, struct trussinfo *); + +/* + * Linux Socket defines + */ +#define LINUX_SOCKET 1 +#define LINUX_BIND 2 +#define LINUX_CONNECT 3 +#define LINUX_LISTEN 4 +#define LINUX_ACCEPT 5 +#define LINUX_GETSOCKNAME 6 +#define LINUX_GETPEERNAME 7 +#define LINUX_SOCKETPAIR 8 +#define LINUX_SEND 9 +#define LINUX_RECV 10 +#define LINUX_SENDTO 11 +#define LINUX_RECVFROM 12 +#define LINUX_SHUTDOWN 13 +#define LINUX_SETSOCKOPT 14 +#define LINUX_GETSOCKOPT 15 +#define LINUX_SENDMSG 16 +#define LINUX_RECVMSG 17 + +#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ + 0 : sizeof(register_t) - sizeof(t)) + +#if BYTE_ORDER == LITTLE_ENDIAN +#define PADL_(t) 0 +#define PADR_(t) PAD_(t) +#else +#define PADL_(t) PAD_(t) +#define PADR_(t) 0 +#endif + +typedef int l_int; +typedef uint32_t l_ulong; + +struct linux_socketcall_args { + char what_l_[PADL_(l_int)]; l_int what; char what_r_[PADR_(l_int)]; + char args_l_[PADL_(l_ulong)]; l_ulong args; char args_r_[PADR_(l_ulong)]; +}; + void print_syscall(struct trussinfo *, const char *, int, char **); void print_syscall_ret(struct trussinfo *, const char *, int, char **, int, long, struct syscall *); Modified: head/usr.bin/truss/syscalls.c ============================================================================== --- head/usr.bin/truss/syscalls.c Thu Apr 24 12:54:35 2014 (r264880) +++ head/usr.bin/truss/syscalls.c Thu Apr 24 14:12:35 2014 (r264881) @@ -100,6 +100,10 @@ static struct syscall syscalls[] = { .args = { { Rforkflags, 0 } } }, { .name = "getegid", .ret_type = 1, .nargs = 0 }, { .name = "geteuid", .ret_type = 1, .nargs = 0 }, + { .name = "linux_readlink", .ret_type = 1, .nargs = 3, + .args = { { Name, 0 } , { Name | OUT, 1 }, { Int, 2 }}}, + { .name = "linux_socketcall", .ret_type = 1, .nargs = 2, + .args = { { Int, 0 } , { LinuxSockArgs, 1 }}}, { .name = "getgid", .ret_type = 1, .nargs = 0 }, { .name = "getpid", .ret_type = 1, .nargs = 0 }, { .name = "getpgid", .ret_type = 1, .nargs = 1, @@ -117,6 +121,8 @@ static struct syscall syscalls[] = { .args = { { Int, 0 }, { Int, 1 }, { Whence, 2 } } }, { .name = "mmap", .ret_type = 2, .nargs = 6, .args = { { Ptr, 0 }, { Int, 1 }, { Mprot, 2 }, { Mmapflags, 3 }, { Int, 4 }, { Quad, 5 + QUAD_ALIGN } } }, + { .name = "linux_mkdir", .ret_type = 1, .nargs = 2, + .args = { { Name | IN, 0} , {Int, 1}}}, { .name = "mprotect", .ret_type = 1, .nargs = 3, .args = { { Ptr, 0 }, { Int, 1 }, { Mprot, 2 } } }, { .name = "open", .ret_type = 1, .nargs = 3, @@ -141,6 +147,8 @@ static struct syscall syscalls[] = { .args = { { Name, 0 }, { Octal, 1 } } }, { .name = "chown", .ret_type = 0, .nargs = 3, .args = { { Name, 0 }, { Int, 1 }, { Int, 2 } } }, + { .name = "linux_stat64", .ret_type = 1, .nargs = 3, + .args = { { Name | IN, 0 }, { Ptr | OUT, 1 }, { Ptr | IN, 1 }}}, { .name = "mount", .ret_type = 0, .nargs = 4, .args = { { Name, 0 }, { Name, 1 }, { Int, 2 }, { Ptr, 3 } } }, { .name = "umount", .ret_type = 0, .nargs = 2, @@ -153,6 +161,8 @@ static struct syscall syscalls[] = { .args = { { Name | IN, 0 }, { Stat | OUT, 1 } } }, { .name = "linux_newstat", .ret_type = 1, .nargs = 2, .args = { { Name | IN, 0 }, { Ptr | OUT, 1 } } }, + { .name = "linux_access", .ret_type = 1, .nargs = 2, + .args = { { Name, 0 }, { Int, 1 }}}, { .name = "linux_newfstat", .ret_type = 1, .nargs = 2, .args = { { Int, 0 }, { Ptr | OUT, 1 } } }, { .name = "write", .ret_type = 1, .nargs = 3, @@ -763,6 +773,76 @@ print_arg(struct syscall_args *sc, unsig asprintf(&tmp, "0x%lx", args[sc->offset]); break; } + case LinuxSockArgs: + { + struct linux_socketcall_args largs; + if (get_struct(pid, (void *)args[sc->offset], (void *)&largs, + sizeof(largs)) == -1) { + err(1, "get_struct %p", (void *)args[sc->offset]); + } + const char *what; + char buf[30]; + + switch (largs.what) { + case LINUX_SOCKET: + what = "LINUX_SOCKET"; + break; + case LINUX_BIND: + what = "LINUX_BIND"; + break; + case LINUX_CONNECT: + what = "LINUX_CONNECT"; + break; + case LINUX_LISTEN: + what = "LINUX_LISTEN"; + break; + case LINUX_ACCEPT: + what = "LINUX_ACCEPT"; + break; + case LINUX_GETSOCKNAME: + what = "LINUX_GETSOCKNAME"; + break; + case LINUX_GETPEERNAME: + what = "LINUX_GETPEERNAME"; + break; + case LINUX_SOCKETPAIR: + what = "LINUX_SOCKETPAIR"; + break; + case LINUX_SEND: + what = "LINUX_SEND"; + break; + case LINUX_RECV: + what = "LINUX_RECV"; + break; + case LINUX_SENDTO: + what = "LINUX_SENDTO"; + break; + case LINUX_RECVFROM: + what = "LINUX_RECVFROM"; + break; + case LINUX_SHUTDOWN: + what = "LINUX_SHUTDOWN"; + break; + case LINUX_SETSOCKOPT: + what = "LINUX_SETSOCKOPT"; + break; + case LINUX_GETSOCKOPT: + what = "LINUX_GETSOCKOPT"; + break; + case LINUX_SENDMSG: + what = "LINUX_SENDMSG"; + break; + case LINUX_RECVMSG: + what = "LINUX_RECVMSG"; + break; + default: + sprintf(buf, "%d", largs.what); + what = buf; + break; + } + asprintf(&tmp, "(0x%lx)%s, 0x%lx", args[sc->offset], what, (long unsigned int)largs.args); + break; + } case Pollfd: { /* * XXX: A Pollfd argument expects the /next/ syscall argument