]> granicus.if.org Git - strace/blobdiff - ipc.c
Filter out redundant ioctl entries early
[strace] / ipc.c
diff --git a/ipc.c b/ipc.c
index bac99380e6e00bebad6bd06b303c5884f0cb08ee..e04a6189c1c227e55d885af01d2db1a0aa5ab2f3 100644 (file)
--- a/ipc.c
+++ b/ipc.c
  * 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.
- *
- *     $Id$
  */
 
 #include "defs.h"
-
-#if defined(LINUX) || defined(SUNOS4) || defined(FREEBSD)
-
-# ifdef HAVE_MQUEUE_H
-#  include <mqueue.h>
-# endif
-
+#ifdef HAVE_MQUEUE_H
+# include <mqueue.h>
+#endif
 #include <fcntl.h>
 #include <sys/ipc.h>
 #include <sys/sem.h>
 #define SEM_INFO 19
 #endif
 
-#if defined LINUX && !defined IPC_64
+#if !defined IPC_64
 # define IPC_64 0x100
 #endif
 
 extern void printsigevent(struct tcb *tcp, long arg);
 
-static const struct xlat msgctl_flags[] = {
-       { IPC_RMID,     "IPC_RMID"      },
-       { IPC_SET,      "IPC_SET"       },
-       { IPC_STAT,     "IPC_STAT"      },
-#ifdef LINUX
-       { IPC_INFO,     "IPC_INFO"      },
-       { MSG_STAT,     "MSG_STAT"      },
-       { MSG_INFO,     "MSG_INFO"      },
-#endif /* LINUX */
-       { 0,            NULL            },
-};
-
-static const struct xlat semctl_flags[] = {
-       { IPC_RMID,     "IPC_RMID"      },
-       { IPC_SET,      "IPC_SET"       },
-       { IPC_STAT,     "IPC_STAT"      },
-#ifdef LINUX
-       { IPC_INFO,     "IPC_INFO"      },
-       { SEM_STAT,     "SEM_STAT"      },
-       { SEM_INFO,     "SEM_INFO"      },
-#endif /* LINUX */
-       { GETPID,       "GETPID"        },
-       { GETVAL,       "GETVAL"        },
-       { GETALL,       "GETALL"        },
-       { GETNCNT,      "GETNCNT"       },
-       { GETZCNT,      "GETZCNT"       },
-       { SETVAL,       "SETVAL"        },
-       { SETALL,       "SETALL"        },
-       { 0,            NULL            },
-};
-
-static const struct xlat shmctl_flags[] = {
-       { IPC_RMID,     "IPC_RMID"      },
-       { IPC_SET,      "IPC_SET"       },
-       { IPC_STAT,     "IPC_STAT"      },
-#ifdef LINUX
-       { IPC_INFO,     "IPC_INFO"      },
-       { SHM_STAT,     "SHM_STAT"      },
-       { SHM_INFO,     "SHM_INFO"      },
-#endif /* LINUX */
-#ifdef SHM_LOCK
-       { SHM_LOCK,     "SHM_LOCK"      },
-#endif
-#ifdef SHM_UNLOCK
-       { SHM_UNLOCK,   "SHM_UNLOCK"    },
-#endif
-       { 0,            NULL            },
-};
-
-static const struct xlat resource_flags[] = {
-       { IPC_CREAT,    "IPC_CREAT"     },
-       { IPC_EXCL,     "IPC_EXCL"      },
-       { IPC_NOWAIT,   "IPC_NOWAIT"    },
-       { 0,            NULL            },
-};
-
-static const struct xlat shm_resource_flags[] = {
-       { IPC_CREAT,    "IPC_CREAT"     },
-       { IPC_EXCL,     "IPC_EXCL"      },
-#ifdef SHM_HUGETLB
-       { SHM_HUGETLB,  "SHM_HUGETLB"   },
-#endif
-       { 0,            NULL            },
-};
-
-static const struct xlat shm_flags[] = {
-#ifdef LINUX
-       { SHM_REMAP,    "SHM_REMAP"     },
-#endif /* LINUX */
-       { SHM_RDONLY,   "SHM_RDONLY"    },
-       { SHM_RND,      "SHM_RND"       },
-       { 0,            NULL            },
-};
-
-static const struct xlat msg_flags[] = {
-       { MSG_NOERROR,  "MSG_NOERROR"   },
-#ifdef LINUX
-       { MSG_EXCEPT,   "MSG_EXCEPT"    },
-#endif /* LINUX */
-       { IPC_NOWAIT,   "IPC_NOWAIT"    },
-       { 0,            NULL            },
-};
-
-static const struct xlat semop_flags[] = {
-       { SEM_UNDO,     "SEM_UNDO"      },
-       { IPC_NOWAIT,   "IPC_NOWAIT"    },
-       { 0,            NULL            },
-};
+#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"
 
 int sys_msgget(struct tcb *tcp)
 {
        if (entering(tcp)) {
                if (tcp->u_arg[0])
-                       tprintf("%#lx", tcp->u_arg[0]);
+                       tprintf("%#lx", tcp->u_arg[0]);
                else
-                       tprints("IPC_PRIVATE");
-               tprints(", ");
+                       tprints("IPC_PRIVATE, ");
                if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0)
                        tprints("|");
                tprintf("%#lo", tcp->u_arg[1] & 0777);
@@ -184,18 +97,16 @@ int sys_msgget(struct tcb *tcp)
 static int
 indirect_ipccall(struct tcb *tcp)
 {
-#ifdef LINUX
 #ifdef X86_64
-       return current_personality > 0;
+       return current_personality == 1;
 #endif
 #if defined IA64
        return tcp->scno < 1024; /* ia32 emulation syscalls are low */
 #endif
-#if !defined MIPS && !defined HPPA
-       return 1;
-#endif
-#endif /* LINUX */
+#if defined(ALPHA) || defined(MIPS) || defined(HPPA) || defined(__ARM_EABI__) || defined(AARCH64)
        return 0;
+#endif
+       return 1;
 }
 
 int sys_msgctl(struct tcb *tcp)
@@ -222,7 +133,7 @@ tprint_msgsnd(struct tcb *tcp, long addr, unsigned long count,
                tprints("}");
        }
        tprintf(", %lu, ", count);
-       printflags(msg_flags, flags, "MSG_???");
+       printflags(ipc_msg_flags, flags, "MSG_???");
 }
 
 int sys_msgsnd(struct tcb *tcp)
@@ -273,11 +184,11 @@ int sys_msgrcv(struct tcb *tcp)
                                tprint_msgrcv(tcp, (long) tmp.msgp,
                                        tcp->u_arg[1], tmp.msgtyp);
                        }
-                       printflags(msg_flags, tcp->u_arg[2], "MSG_???");
+                       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(msg_flags, tcp->u_arg[4], "MSG_???");
+                       printflags(ipc_msg_flags, tcp->u_arg[4], "MSG_???");
                }
        }
        return 0;
@@ -338,7 +249,6 @@ int sys_semop(struct tcb *tcp)
        return 0;
 }
 
-#ifdef LINUX
 int sys_semtimedop(struct tcb *tcp)
 {
        if (entering(tcp)) {
@@ -346,10 +256,10 @@ int sys_semtimedop(struct tcb *tcp)
                if (indirect_ipccall(tcp)) {
                        tprint_sembuf(tcp, tcp->u_arg[3], tcp->u_arg[1]);
                        tprints(", ");
-#if defined(S390)
+#if defined(S390) || defined(S390X)
                        printtv(tcp, tcp->u_arg[2]);
 #else
-                       printtv(tcp, tcp->u_arg[5]);
+                       printtv(tcp, tcp->u_arg[4]);
 #endif
                } else {
                        tprint_sembuf(tcp, tcp->u_arg[1], tcp->u_arg[2]);
@@ -359,7 +269,6 @@ int sys_semtimedop(struct tcb *tcp)
        }
        return 0;
 }
-#endif
 
 int sys_semget(struct tcb *tcp)
 {
@@ -368,8 +277,7 @@ int sys_semget(struct tcb *tcp)
                        tprintf("%#lx", tcp->u_arg[0]);
                else
                        tprints("IPC_PRIVATE");
-               tprintf(", %lu", tcp->u_arg[1]);
-               tprints(", ");
+               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);
@@ -380,8 +288,7 @@ int sys_semget(struct tcb *tcp)
 int sys_semctl(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%lu", tcp->u_arg[0]);
-               tprintf(", %lu, ", tcp->u_arg[1]);
+               tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
                PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
                tprintf(", %#lx", tcp->u_arg[3]);
        }
@@ -395,8 +302,7 @@ int sys_shmget(struct tcb *tcp)
                        tprintf("%#lx", tcp->u_arg[0]);
                else
                        tprints("IPC_PRIVATE");
-               tprintf(", %lu", tcp->u_arg[1]);
-               tprints(", ");
+               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);
@@ -420,29 +326,23 @@ int sys_shmctl(struct tcb *tcp)
 
 int sys_shmat(struct tcb *tcp)
 {
-#ifdef LINUX
-       unsigned long raddr;
-#endif /* LINUX */
-
        if (exiting(tcp)) {
                tprintf("%lu", tcp->u_arg[0]);
                if (indirect_ipccall(tcp)) {
-                       tprintf(", %#lx", tcp->u_arg[3]);
-                       tprints(", ");
+                       tprintf(", %#lx, ", tcp->u_arg[3]);
                        printflags(shm_flags, tcp->u_arg[1], "SHM_???");
                } else {
-                       tprintf(", %#lx", tcp->u_arg[1]);
-                       tprints(", ");
+                       tprintf(", %#lx, ", tcp->u_arg[1]);
                        printflags(shm_flags, tcp->u_arg[2], "SHM_???");
                }
                if (syserror(tcp))
                        return 0;
-/* HPPA does not use an IPC multiplexer on Linux.  */
-#if defined(LINUX) && !defined(HPPA)
-               if (umove(tcp, tcp->u_arg[2], &raddr) < 0)
-                       return RVAL_NONE;
-               tcp->u_rval = raddr;
-#endif /* LINUX */
+               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;
        }
        return 0;
@@ -460,9 +360,6 @@ int sys_shmdt(struct tcb *tcp)
        return 0;
 }
 
-#endif /* defined(LINUX) || defined(SUNOS4) || defined(FREEBSD) */
-
-#ifdef LINUX
 int
 sys_mq_open(struct tcb *tcp)
 {
@@ -479,7 +376,7 @@ sys_mq_open(struct tcb *tcp)
                        /* mode */
                        tprintf(", %#lo, ", tcp->u_arg[2]);
                        if (umove(tcp, tcp->u_arg[3], &attr) < 0)
-                               tprints("{ ??? }");
+                               tprints("{???}");
                        else
                                tprintf("{mq_maxmsg=%ld, mq_msgsize=%ld}",
                                        (long) attr.mq_maxmsg,
@@ -559,4 +456,9 @@ sys_mq_getsetattr(struct tcb *tcp)
                printmqattr(tcp, tcp->u_arg[2]);
        return 0;
 }
-#endif
+
+int
+sys_ipc(struct tcb *tcp)
+{
+       return printargs(tcp);
+}