From: Elvira Khabirova Date: Wed, 19 Aug 2015 02:06:26 +0000 (+0300) Subject: ipc.c: split into separate files X-Git-Tag: v4.11~264 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c01ad06002f6c15fd0c8807e38e452bb240a1f92;p=strace ipc.c: split into separate files In preparation for upcoming mpers-related changes, split ipc.c into independent groups of parsers. * ipc_defs.h: New file. * ipc_msg.c: Likewise. * ipc_msgctl.c: Likewise. * ipc_sem.c: Likewise. * ipc_shm.c: Likewise. * ipc_shmctl.c: Likewise. * mq.c: Likewise. * print_mq_attr.c: Likewise. * print_msgbuf.c: Likewise. * ipc.c: Remove. (sys_mq_open, sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr): Move to mq.c. (sys_msgget, tprint_msgsnd, sys_msgsnd, tprint_msgrcv, sys_msgrcv): Move to ipc_msg.c. (sys_msgctl): Move to ipc_msgctl.c. (tprint_sembuf, tprint_sembuf_array, sys_semop, sys_semtimedop, sys_semget, syssemctl): Move to ipc_sem.c. (sys_shmget, sys_shmat, sys_shmdt): Move to ipc_shm.c. (sys_shmctl): Move to ipc_shmctl.c. (printmqattr): Move to print_mq_attr.c. (tprint_msgbuf): Move to print_msgbuf.c. (IPC_64, PRINTCTL): Move to ipc_defs.h. * defs.h (struct xlat resource_flags): New prototype. * Makefile.am (strace_SOURCES): Remove ipc.c. Add ipc_defs.h, mq.c, ipc_msg.c, ipc_msgctl.c, ipc_sem.c, ipc_shm.c, ipc_shmctl.c, print_mq_attr.c, and print_msgbuf.c. --- diff --git a/Makefile.am b/Makefile.am index 4ceba9d9..f70f6d2b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -62,7 +62,12 @@ strace_SOURCES = \ io.c \ ioctl.c \ ioprio.c \ - ipc.c \ + ipc_defs.h \ + ipc_msg.c \ + ipc_msgctl.c \ + ipc_sem.c \ + ipc_shm.c \ + ipc_shmctl.c \ kexec.c \ keyctl.c \ ldt.c \ @@ -73,6 +78,7 @@ strace_SOURCES = \ memfd_create.c \ mknod.c \ mount.c \ + mq.c \ mtd.c \ net.c \ open.c \ @@ -82,6 +88,8 @@ strace_SOURCES = \ personality.c \ poll.c \ prctl.c \ + print_mq_attr.c \ + print_msgbuf.c \ printmode.c \ printrusage.c \ printsiginfo.c \ diff --git a/defs.h b/defs.h index e8a2a0da..9059026c 100644 --- a/defs.h +++ b/defs.h @@ -348,6 +348,7 @@ extern const struct xlat addrfams[]; extern const struct xlat at_flags[]; extern const struct xlat open_access_modes[]; extern const struct xlat open_mode_flags[]; +extern const struct xlat resource_flags[]; extern const struct xlat whence_codes[]; /* Format of syscall return values */ @@ -383,6 +384,8 @@ extern const struct xlat whence_codes[]; #define STACKTRACE_CAPTURE_ON_ENTER 01000 /* Capture stacktrace on "entering" stage */ #define TRACE_INDIRECT_SUBCALL 02000 /* Syscall is an indirect socket/ipc subcall. */ +#define indirect_ipccall(tcp) (tcp->s_ent->sys_flags & TRACE_INDIRECT_SUBCALL) + #if defined(ARM) || defined(AARCH64) \ || defined(I386) || defined(X32) || defined(X86_64) \ || defined(IA64) \ @@ -579,6 +582,7 @@ extern void printtv_bitness(struct tcb *, long, enum bitness_t, int); extern char *sprinttv(char *, struct tcb *, long, enum bitness_t, int special); extern void print_timespec(struct tcb *, long); extern void sprint_timespec(char *, struct tcb *, long); +extern void printsigevent(struct tcb *tcp, long arg); extern void printsiginfo_at(struct tcb *tcp, long addr); extern void printfd(struct tcb *, int); extern bool print_sockaddr_by_inode(const unsigned long, const char *); diff --git a/ipc.c b/ipc.c deleted file mode 100644 index ec491eb4..00000000 --- a/ipc.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (c) 1993 Ulrich Pegelow - * Copyright (c) 1993 Branko Lankester - * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey - * Copyright (c) 1996-1999 Wichert Akkerman - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "defs.h" -#ifdef HAVE_MQUEUE_H -# include -#endif -#include -#include -#include -#include -#include - -#if !defined IPC_64 -# define IPC_64 0x100 -#endif - -extern void printsigevent(struct tcb *tcp, long arg); - -#include "xlat/msgctl_flags.h" -#include "xlat/semctl_flags.h" -#include "xlat/shmctl_flags.h" -#include "xlat/resource_flags.h" -#include "xlat/shm_resource_flags.h" -#include "xlat/shm_flags.h" -#include "xlat/ipc_msg_flags.h" -#include "xlat/semop_flags.h" - -SYS_FUNC(msgget) -{ - if (tcp->u_arg[0]) - tprintf("%#lx, ", tcp->u_arg[0]); - else - tprints("IPC_PRIVATE, "); - if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0) - tprints("|"); - tprintf("%#lo", tcp->u_arg[1] & 0777); - return RVAL_DECODED; -} - -#define PRINTCTL(flagset, arg, dflt) \ - if ((arg) & IPC_64) tprints("IPC_64|"); \ - printxval((flagset), (arg) &~ IPC_64, dflt) - -static int -indirect_ipccall(struct tcb *tcp) -{ - return tcp->s_ent->sys_flags & TRACE_INDIRECT_SUBCALL; -} - -SYS_FUNC(msgctl) -{ - tprintf("%lu, ", tcp->u_arg[0]); - PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???"); - tprints(", "); - printaddr(tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]); - return RVAL_DECODED; -} - -static void -tprint_msgbuf(struct tcb *tcp, const long addr, const unsigned long count) -{ - long mtype; - - if (!umove_or_printaddr(tcp, addr, &mtype)) { - tprintf("{%lu, ", mtype); - printstr(tcp, addr + sizeof(mtype), count); - tprints("}"); - } - tprintf(", %lu, ", count); -} - -static void -tprint_msgsnd(struct tcb *tcp, const long addr, const unsigned long count, - const unsigned long flags) -{ - tprint_msgbuf(tcp, addr, count); - printflags(ipc_msg_flags, flags, "MSG_???"); -} - -SYS_FUNC(msgsnd) -{ - tprintf("%d, ", (int) tcp->u_arg[0]); - if (indirect_ipccall(tcp)) { - tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1], - tcp->u_arg[2]); - } else { - tprint_msgsnd(tcp, tcp->u_arg[1], tcp->u_arg[2], - tcp->u_arg[3]); - } - return RVAL_DECODED; -} - -static void -tprint_msgrcv(struct tcb *tcp, const long addr, const unsigned long count, - const long msgtyp) -{ - tprint_msgbuf(tcp, addr, count); - tprintf("%ld, ", msgtyp); -} - -SYS_FUNC(msgrcv) -{ - if (entering(tcp)) { - tprintf("%d, ", (int) tcp->u_arg[0]); - } else { - if (indirect_ipccall(tcp)) { - struct ipc_wrapper { - struct msgbuf *msgp; - long msgtyp; - } tmp; - - if (umove_or_printaddr(tcp, tcp->u_arg[3], &tmp)) - tprintf(", %lu, ", tcp->u_arg[1]); - else - tprint_msgrcv(tcp, (long) tmp.msgp, - tcp->u_arg[1], tmp.msgtyp); - printflags(ipc_msg_flags, tcp->u_arg[2], "MSG_???"); - } else { - tprint_msgrcv(tcp, tcp->u_arg[1], - tcp->u_arg[2], tcp->u_arg[3]); - printflags(ipc_msg_flags, tcp->u_arg[4], "MSG_???"); - } - } - return 0; -} - -static void -tprint_sembuf(const struct sembuf *sb) -{ - tprintf("{%u, %d, ", sb->sem_num, sb->sem_op); - printflags(semop_flags, sb->sem_flg, "SEM_???"); - tprints("}"); -} - -static void -tprint_sembuf_array(struct tcb *tcp, const long addr, const unsigned long count) -{ - unsigned long max_count; - struct sembuf sb; - - if (abbrev(tcp)) - max_count = (max_strlen < count) ? max_strlen : count; - else - max_count = count; - - if (!max_count) - printaddr(addr); - else if (!umove_or_printaddr(tcp, addr, &sb)) { - unsigned long i; - - tprints("["); - tprint_sembuf(&sb); - - for (i = 1; i < max_count; ++i) { - tprints(", "); - if (umove_or_printaddr(tcp, addr + i * sizeof(sb), &sb)) - break; - else - tprint_sembuf(&sb); - } - - if (i < max_count || max_count < count) - tprints(", ..."); - - tprints("]"); - } - tprintf(", %lu", count); -} - -SYS_FUNC(semop) -{ - tprintf("%lu, ", tcp->u_arg[0]); - if (indirect_ipccall(tcp)) { - tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]); - } else { - tprint_sembuf_array(tcp, tcp->u_arg[1], tcp->u_arg[2]); - } - return RVAL_DECODED; -} - -SYS_FUNC(semtimedop) -{ - tprintf("%lu, ", tcp->u_arg[0]); - if (indirect_ipccall(tcp)) { - tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]); - tprints(", "); -#if defined(S390) || defined(S390X) - printtv(tcp, tcp->u_arg[2]); -#else - printtv(tcp, tcp->u_arg[4]); -#endif - } else { - tprint_sembuf_array(tcp, tcp->u_arg[1], tcp->u_arg[2]); - tprints(", "); - printtv(tcp, tcp->u_arg[3]); - } - return RVAL_DECODED; -} - -SYS_FUNC(semget) -{ - if (tcp->u_arg[0]) - tprintf("%#lx", tcp->u_arg[0]); - else - tprints("IPC_PRIVATE"); - tprintf(", %lu, ", tcp->u_arg[1]); - if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0) - tprints("|"); - tprintf("%#lo", tcp->u_arg[2] & 0777); - return RVAL_DECODED; -} - -SYS_FUNC(semctl) -{ - tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]); - PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???"); - tprints(", "); - if (indirect_ipccall(tcp)) { - printnum_ptr(tcp, tcp->u_arg[3]); - } else { - tprintf("%#lx", tcp->u_arg[3]); - } - return RVAL_DECODED; -} - -SYS_FUNC(shmget) -{ - if (tcp->u_arg[0]) - tprintf("%#lx", tcp->u_arg[0]); - else - tprints("IPC_PRIVATE"); - tprintf(", %lu, ", tcp->u_arg[1]); - if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0) - tprints("|"); - tprintf("%#lo", tcp->u_arg[2] & 0777); - return RVAL_DECODED; -} - -SYS_FUNC(shmctl) -{ - tprintf("%lu, ", tcp->u_arg[0]); - PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???"); - tprints(", "); - printaddr(tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]); - return RVAL_DECODED; -} - -SYS_FUNC(shmat) -{ - if (entering(tcp)) { - tprintf("%lu, ", tcp->u_arg[0]); - if (indirect_ipccall(tcp)) { - printaddr(tcp->u_arg[3]); - tprints(", "); - printflags(shm_flags, tcp->u_arg[1], "SHM_???"); - } else { - printaddr(tcp->u_arg[1]); - tprints(", "); - printflags(shm_flags, tcp->u_arg[2], "SHM_???"); - } - return 0; - } else { - if (syserror(tcp)) - return 0; - if (indirect_ipccall(tcp)) { - unsigned long raddr; - if (umove(tcp, tcp->u_arg[2], &raddr) < 0) - return RVAL_NONE; - tcp->u_rval = raddr; - } - return RVAL_HEX; - } -} - -SYS_FUNC(shmdt) -{ - printaddr(tcp->u_arg[indirect_ipccall(tcp) ? 3 : 0]); - return RVAL_DECODED; -} - -SYS_FUNC(mq_open) -{ - printpath(tcp, tcp->u_arg[0]); - tprints(", "); - /* flags */ - tprint_open_modes(tcp->u_arg[1]); - if (tcp->u_arg[1] & O_CREAT) { - /* mode */ - tprintf(", %#lo, ", tcp->u_arg[2]); -# ifndef HAVE_MQUEUE_H - printaddr(tcp->u_arg[3]); -# else - struct mq_attr attr; - - if (!umove_or_printaddr(tcp, tcp->u_arg[3], &attr)) - tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}", - (long) attr.mq_maxmsg, - (long) attr.mq_msgsize); -# endif - } - return RVAL_DECODED; -} - -SYS_FUNC(mq_timedsend) -{ - tprintf("%ld, ", tcp->u_arg[0]); - printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); - tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]); - printtv(tcp, tcp->u_arg[4]); - return RVAL_DECODED; -} - -SYS_FUNC(mq_timedreceive) -{ - if (entering(tcp)) - tprintf("%ld, ", tcp->u_arg[0]); - else { - printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); - tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]); - printtv(tcp, tcp->u_arg[4]); - } - return 0; -} - -SYS_FUNC(mq_notify) -{ - tprintf("%ld, ", tcp->u_arg[0]); - printsigevent(tcp, tcp->u_arg[1]); - return RVAL_DECODED; -} - -static void -printmqattr(struct tcb *tcp, const long addr) -{ -# ifndef HAVE_MQUEUE_H - printaddr(addr); -# else - struct mq_attr attr; - if (umove_or_printaddr(tcp, addr, &attr)) - return; - tprints("{mq_flags="); - tprint_open_modes(attr.mq_flags); - tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}", - (long) attr.mq_maxmsg, (long) attr.mq_msgsize, - (long) attr.mq_curmsgs); -# endif -} - -SYS_FUNC(mq_getsetattr) -{ - if (entering(tcp)) { - tprintf("%ld, ", tcp->u_arg[0]); - printmqattr(tcp, tcp->u_arg[1]); - tprints(", "); - } else - printmqattr(tcp, tcp->u_arg[2]); - return 0; -} diff --git a/ipc_defs.h b/ipc_defs.h new file mode 100644 index 00000000..31f7ab31 --- /dev/null +++ b/ipc_defs.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2003 Roland McGrath + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#if !defined IPC_64 +# define IPC_64 0x100 +#endif + +#define PRINTCTL(flagset, arg, dflt) \ + if ((arg) & IPC_64) tprints("IPC_64|"); \ + printxval((flagset), (arg) &~ IPC_64, dflt) diff --git a/ipc_msg.c b/ipc_msg.c new file mode 100644 index 00000000..fb126f53 --- /dev/null +++ b/ipc_msg.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) 1993 Ulrich Pegelow + * Copyright (c) 1993 Branko Lankester + * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey + * Copyright (c) 1996-1999 Wichert Akkerman + * Copyright (c) 2003-2006 Roland McGrath + * Copyright (c) 2006-2015 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" + +#include +#include + +#include "xlat/ipc_msg_flags.h" +#include "xlat/resource_flags.h" + +extern void tprint_msgbuf(struct tcb *tcp, const long addr, const unsigned long count); + +SYS_FUNC(msgget) +{ + if (tcp->u_arg[0]) + tprintf("%#lx, ", tcp->u_arg[0]); + else + tprints("IPC_PRIVATE, "); + if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0) + tprints("|"); + tprintf("%#lo", tcp->u_arg[1] & 0777); + return RVAL_DECODED; +} + +static void +tprint_msgsnd(struct tcb *tcp, const long addr, const unsigned long count, + const unsigned long flags) +{ + tprint_msgbuf(tcp, addr, count); + printflags(ipc_msg_flags, flags, "MSG_???"); +} + +SYS_FUNC(msgsnd) +{ + tprintf("%d, ", (int) tcp->u_arg[0]); + if (indirect_ipccall(tcp)) { + tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1], + tcp->u_arg[2]); + } else { + tprint_msgsnd(tcp, tcp->u_arg[1], tcp->u_arg[2], + tcp->u_arg[3]); + } + return RVAL_DECODED; +} + +static void +tprint_msgrcv(struct tcb *tcp, const long addr, const unsigned long count, + const long msgtyp) +{ + tprint_msgbuf(tcp, addr, count); + tprintf("%ld, ", msgtyp); +} + +SYS_FUNC(msgrcv) +{ + if (entering(tcp)) { + tprintf("%d, ", (int) tcp->u_arg[0]); + } else { + if (indirect_ipccall(tcp)) { + struct ipc_wrapper { + struct msgbuf *msgp; + long msgtyp; + } tmp; + + if (umove_or_printaddr(tcp, tcp->u_arg[3], &tmp)) + tprintf(", %lu, ", tcp->u_arg[1]); + else + tprint_msgrcv(tcp, (long) tmp.msgp, + tcp->u_arg[1], tmp.msgtyp); + printflags(ipc_msg_flags, tcp->u_arg[2], "MSG_???"); + } else { + tprint_msgrcv(tcp, tcp->u_arg[1], + tcp->u_arg[2], tcp->u_arg[3]); + printflags(ipc_msg_flags, tcp->u_arg[4], "MSG_???"); + } + } + return 0; +} diff --git a/ipc_msgctl.c b/ipc_msgctl.c new file mode 100644 index 00000000..35d00baf --- /dev/null +++ b/ipc_msgctl.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1993 Ulrich Pegelow + * Copyright (c) 1993 Branko Lankester + * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey + * Copyright (c) 1996-1999 Wichert Akkerman + * Copyright (c) 2003-2006 Roland McGrath + * Copyright (c) 2006-2015 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" +#include "ipc_defs.h" + +#include + +#include "xlat/msgctl_flags.h" + +SYS_FUNC(msgctl) +{ + tprintf("%lu, ", tcp->u_arg[0]); + PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???"); + tprints(", "); + printaddr(tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]); + return RVAL_DECODED; +} diff --git a/ipc_sem.c b/ipc_sem.c new file mode 100644 index 00000000..82d47623 --- /dev/null +++ b/ipc_sem.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 1993 Ulrich Pegelow + * Copyright (c) 1993 Branko Lankester + * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey + * Copyright (c) 1996-1999 Wichert Akkerman + * Copyright (c) 2003-2006 Roland McGrath + * Copyright (c) 2006-2015 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" +#include "ipc_defs.h" + +#include + +#include "xlat/semctl_flags.h" +#include "xlat/semop_flags.h" + +static void +tprint_sembuf(const struct sembuf *sb) +{ + tprintf("{%u, %d, ", sb->sem_num, sb->sem_op); + printflags(semop_flags, sb->sem_flg, "SEM_???"); + tprints("}"); +} + +static void +tprint_sembuf_array(struct tcb *tcp, const long addr, const unsigned long count) +{ + unsigned long max_count; + struct sembuf sb; + + if (abbrev(tcp)) + max_count = (max_strlen < count) ? max_strlen : count; + else + max_count = count; + + if (!max_count) + printaddr(addr); + else if (!umove_or_printaddr(tcp, addr, &sb)) { + unsigned long i; + + tprints("["); + tprint_sembuf(&sb); + + for (i = 1; i < max_count; ++i) { + tprints(", "); + if (umove_or_printaddr(tcp, addr + i * sizeof(sb), &sb)) + break; + else + tprint_sembuf(&sb); + } + + if (i < max_count || max_count < count) + tprints(", ..."); + + tprints("]"); + } + tprintf(", %lu", count); +} + +SYS_FUNC(semop) +{ + tprintf("%lu, ", tcp->u_arg[0]); + if (indirect_ipccall(tcp)) { + tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]); + } else { + tprint_sembuf_array(tcp, tcp->u_arg[1], tcp->u_arg[2]); + } + return RVAL_DECODED; +} + +SYS_FUNC(semtimedop) +{ + tprintf("%lu, ", tcp->u_arg[0]); + if (indirect_ipccall(tcp)) { + tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]); + tprints(", "); +#if defined(S390) || defined(S390X) + printtv(tcp, tcp->u_arg[2]); +#else + printtv(tcp, tcp->u_arg[4]); +#endif + } else { + tprint_sembuf_array(tcp, tcp->u_arg[1], tcp->u_arg[2]); + tprints(", "); + printtv(tcp, tcp->u_arg[3]); + } + return RVAL_DECODED; +} + +SYS_FUNC(semget) +{ + if (tcp->u_arg[0]) + tprintf("%#lx", tcp->u_arg[0]); + else + tprints("IPC_PRIVATE"); + tprintf(", %lu, ", tcp->u_arg[1]); + if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0) + tprints("|"); + tprintf("%#lo", tcp->u_arg[2] & 0777); + return RVAL_DECODED; +} + +SYS_FUNC(semctl) +{ + tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]); + PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???"); + tprints(", "); + if (indirect_ipccall(tcp)) { + printnum_ptr(tcp, tcp->u_arg[3]); + } else { + tprintf("%#lx", tcp->u_arg[3]); + } + return RVAL_DECODED; +} diff --git a/ipc_shm.c b/ipc_shm.c new file mode 100644 index 00000000..4a41690a --- /dev/null +++ b/ipc_shm.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 1993 Ulrich Pegelow + * Copyright (c) 1993 Branko Lankester + * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey + * Copyright (c) 1996-1999 Wichert Akkerman + * Copyright (c) 2003-2006 Roland McGrath + * Copyright (c) 2006-2015 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" + +#include + +#include "xlat/shm_resource_flags.h" +#include "xlat/shm_flags.h" + +SYS_FUNC(shmget) +{ + if (tcp->u_arg[0]) + tprintf("%#lx", tcp->u_arg[0]); + else + tprints("IPC_PRIVATE"); + tprintf(", %lu, ", tcp->u_arg[1]); + if (printflags(shm_resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0) + tprints("|"); + tprintf("%#lo", tcp->u_arg[2] & 0777); + return RVAL_DECODED; +} + +SYS_FUNC(shmat) +{ + if (entering(tcp)) { + tprintf("%lu, ", tcp->u_arg[0]); + if (indirect_ipccall(tcp)) { + printaddr(tcp->u_arg[3]); + tprints(", "); + printflags(shm_flags, tcp->u_arg[1], "SHM_???"); + } else { + printaddr(tcp->u_arg[1]); + tprints(", "); + printflags(shm_flags, tcp->u_arg[2], "SHM_???"); + } + return 0; + } else { + if (syserror(tcp)) + return 0; + if (indirect_ipccall(tcp)) { + unsigned long raddr; + if (umove(tcp, tcp->u_arg[2], &raddr) < 0) + return RVAL_NONE; + tcp->u_rval = raddr; + } + return RVAL_HEX; + } +} + +SYS_FUNC(shmdt) +{ + printaddr(tcp->u_arg[indirect_ipccall(tcp) ? 3 : 0]); + return RVAL_DECODED; +} diff --git a/ipc_shmctl.c b/ipc_shmctl.c new file mode 100644 index 00000000..6bb468f0 --- /dev/null +++ b/ipc_shmctl.c @@ -0,0 +1,47 @@ +/* + * Copyright (c) 1993 Ulrich Pegelow + * Copyright (c) 1993 Branko Lankester + * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey + * Copyright (c) 1996-1999 Wichert Akkerman + * Copyright (c) 2003-2006 Roland McGrath + * Copyright (c) 2006-2015 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" +#include "ipc_defs.h" + +#include + +#include "xlat/shmctl_flags.h" + +SYS_FUNC(shmctl) +{ + tprintf("%lu, ", tcp->u_arg[0]); + PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???"); + tprints(", "); + printaddr(tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]); + return RVAL_DECODED; +} diff --git a/mq.c b/mq.c new file mode 100644 index 00000000..a6d7512d --- /dev/null +++ b/mq.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2004 Ulrich Drepper + * Copyright (c) 2005-2015 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" +#include + +#ifdef HAVE_MQUEUE_H +# include +#endif + +extern void printmqattr(struct tcb *tcp, const long addr); + +SYS_FUNC(mq_open) +{ + printpath(tcp, tcp->u_arg[0]); + tprints(", "); + /* flags */ + tprint_open_modes(tcp->u_arg[1]); + if (tcp->u_arg[1] & O_CREAT) { + /* mode */ + tprintf(", %#lo, ", tcp->u_arg[2]); +# ifndef HAVE_MQUEUE_H + printaddr(tcp->u_arg[3]); +# else + struct mq_attr attr; + + if (!umove_or_printaddr(tcp, tcp->u_arg[3], &attr)) + tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}", + (long) attr.mq_maxmsg, + (long) attr.mq_msgsize); +# endif + } + return RVAL_DECODED; +} + +SYS_FUNC(mq_timedsend) +{ + tprintf("%ld, ", tcp->u_arg[0]); + printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); + tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]); + printtv(tcp, tcp->u_arg[4]); + return RVAL_DECODED; +} + +SYS_FUNC(mq_timedreceive) +{ + if (entering(tcp)) + tprintf("%ld, ", tcp->u_arg[0]); + else { + printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); + tprintf(", %lu, %ld, ", tcp->u_arg[2], tcp->u_arg[3]); + printtv(tcp, tcp->u_arg[4]); + } + return 0; +} + +SYS_FUNC(mq_notify) +{ + tprintf("%ld, ", tcp->u_arg[0]); + printsigevent(tcp, tcp->u_arg[1]); + return RVAL_DECODED; +} + +SYS_FUNC(mq_getsetattr) +{ + if (entering(tcp)) { + tprintf("%ld, ", tcp->u_arg[0]); + printmqattr(tcp, tcp->u_arg[1]); + tprints(", "); + } else + printmqattr(tcp, tcp->u_arg[2]); + return 0; +} diff --git a/print_mq_attr.c b/print_mq_attr.c new file mode 100644 index 00000000..184fff1c --- /dev/null +++ b/print_mq_attr.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2004 Ulrich Drepper + * Copyright (c) 2005-2015 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" + +#ifdef HAVE_MQUEUE_H +# include +#endif + +void +printmqattr(struct tcb *tcp, const long addr) +{ +# ifndef HAVE_MQUEUE_H + printaddr(addr); +# else + struct mq_attr attr; + if (umove_or_printaddr(tcp, addr, &attr)) + return; + tprints("{mq_flags="); + tprint_open_modes(attr.mq_flags); + tprintf(", mq_maxmsg=%ld, mq_msgsize=%ld, mq_curmsg=%ld}", + (long) attr.mq_maxmsg, (long) attr.mq_msgsize, + (long) attr.mq_curmsgs); +# endif +} diff --git a/print_msgbuf.c b/print_msgbuf.c new file mode 100644 index 00000000..ac3dab09 --- /dev/null +++ b/print_msgbuf.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 1993 Ulrich Pegelow + * Copyright (c) 1993 Branko Lankester + * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey + * Copyright (c) 1996-1999 Wichert Akkerman + * Copyright (c) 2003-2006 Roland McGrath + * Copyright (c) 2006-2015 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" + +void +tprint_msgbuf(struct tcb *tcp, const long addr, const unsigned long count) +{ + long mtype; + + if (!umove_or_printaddr(tcp, addr, &mtype)) { + tprintf("{%lu, ", mtype); + printstr(tcp, addr + sizeof(mtype), count); + tprints("}"); + } + tprintf(", %lu, ", count); +}