X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=ipc.c;h=dd5358e930e95f581e37847d2753650713478ffb;hb=090bd651d3b8ae02241006bb3f725600d61e480f;hp=f01a9a911419bfc6254fe2f5ff77d65c4a52fcce;hpb=76baf7c9f6dd61a15524ad43c1b690c252cf5b7c;p=strace diff --git a/ipc.c b/ipc.c index f01a9a91..dd5358e9 100644 --- a/ipc.c +++ b/ipc.c @@ -1,7 +1,6 @@ /* - * Copyright (c) 1993 Ulrich Pegelow - * Copyright (c) 1993 Branko Lankester - * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey + * Copyright (c) 2016 Dmitry V. Levin + * Copyright (c) 1999-2018 The strace developers. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,330 +24,25 @@ * 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" +#include "xlat/ipccalls.h" -#if defined(LINUX) || defined(SUNOS4) - -#include -#include -#include -#include - -#ifndef MSG_STAT -#define MSG_STAT 11 -#endif -#ifndef MSG_INFO -#define MSG_INFO 12 -#endif -#ifndef SHM_STAT -#define SHM_STAT 13 -#endif -#ifndef SHM_INFO -#define SHM_INFO 14 -#endif -#ifndef SEM_STAT -#define SEM_STAT 18 -#endif -#ifndef SEM_INFO -#define SEM_INFO 19 -#endif - -static 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 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 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 */ - { SHM_LOCK, "SHM_LOCK" }, - { SHM_UNLOCK, "SHM_UNLOCK" }, - { 0, NULL }, -}; - -static struct xlat resource_flags[] = { - { IPC_CREAT, "IPC_CREAT" }, - { IPC_EXCL, "IPC_EXCL" }, - { IPC_NOWAIT, "IPC_NOWAIT" }, - { 0, NULL }, -}; - -static struct xlat shm_flags[] = { -#ifdef LINUX - { SHM_REMAP, "SHM_REMAP" }, -#endif /* LINUX */ - { SHM_RDONLY, "SHM_RDONLY" }, - { SHM_RND, "SHM_RND" }, - { 0, NULL }, -}; - -static struct xlat msg_flags[] = { - { MSG_NOERROR, "MSG_NOERROR" }, -#ifdef LINUX - { MSG_EXCEPT, "MSG_EXCEPT" }, -#endif /* LINUX */ - { IPC_NOWAIT, "IPC_NOWAIT" }, - { 0, NULL }, -}; - -int sys_msgget(tcp) -struct tcb *tcp; -{ - if (entering(tcp)) { - if (tcp->u_arg[0]) - tprintf("%lu", tcp->u_arg[0]); - else - tprintf("IPC_PRIVATE"); - tprintf(", "); - if (printflags(resource_flags, tcp->u_arg[1]) != 0) - tprintf("|"); - tprintf("%#lo", tcp->u_arg[1] & 0666); - } - return 0; -} - -int sys_msgctl(tcp) -struct tcb *tcp; -{ - char *cmd = xlookup(msgctl_flags, tcp->u_arg[1]); - - if (entering(tcp)) { - tprintf("%lu", tcp->u_arg[0]); - tprintf(", %s", cmd == NULL ? "MSG_???" : cmd); -#ifdef LINUX - tprintf(", %#lx", tcp->u_arg[3]); -#else /* !LINUX */ - tprintf(", %#lx", tcp->u_arg[2]); -#endif /* !LINUX */ - } - return 0; -} - -int sys_msgsnd(tcp) -struct tcb *tcp; -{ - long mtype; - - if (entering(tcp)) { - tprintf("%lu", tcp->u_arg[0]); -#ifdef LINUX - umove(tcp, tcp->u_arg[3], &mtype); - tprintf(", {%lu, ", mtype); - printstr(tcp, tcp->u_arg[3] + sizeof(long), - tcp->u_arg[1]); - tprintf("}, %lu", tcp->u_arg[1]); - tprintf(", "); - if (printflags(msg_flags, tcp->u_arg[2]) == 0) - tprintf("0"); -#else /* !LINUX */ - umove(tcp, tcp->u_arg[1], &mtype); - tprintf(", {%lu, ", mtype); - printstr(tcp, tcp->u_arg[1] + sizeof(long), - tcp->u_arg[2]); - tprintf("}, %lu", tcp->u_arg[2]); - tprintf(", "); - if (printflags(msg_flags, tcp->u_arg[3]) == 0) - tprintf("0"); -#endif /* !LINUX */ - } - return 0; -} - -int sys_msgrcv(tcp) -struct tcb *tcp; +SYS_FUNC(ipc) { - long mtype; -#ifdef LINUX - struct ipc_wrapper { - struct msgbuf *msgp; - long msgtyp; - } tmp; -#endif + unsigned int call = tcp->u_arg[0]; + unsigned int version = call >> 16; + call &= 0xffff; + if (version) + tprintf("%u<<16|", version); - if (exiting(tcp)) { - tprintf("%lu", tcp->u_arg[0]); -#ifdef LINUX - umove(tcp, tcp->u_arg[3], &tmp); - umove(tcp, (long) tmp.msgp, &mtype); - tprintf(", {%lu, ", mtype); - printstr(tcp, (long) (tmp.msgp) + sizeof(long), - tcp->u_arg[1]); - tprintf("}, %lu", tcp->u_arg[1]); - tprintf(", %ld", tmp.msgtyp); - tprintf(", "); - if (printflags(msg_flags, tcp->u_arg[2]) == 0) - tprintf("0"); -#else /* !LINUX */ - umove(tcp, tcp->u_arg[1], &mtype); - tprintf(", {%lu, ", mtype); - printstr(tcp, tcp->u_arg[1] + sizeof(long), - tcp->u_arg[2]); - tprintf("}, %lu", tcp->u_arg[2]); - tprintf(", %ld", tcp->u_arg[3]); - tprintf(", "); - if (printflags(msg_flags, tcp->u_arg[4]) == 0) - tprintf("0"); -#endif /* !LINUX */ - } - return 0; -} + printxval_u(ipccalls, call, NULL); -int sys_semop(tcp) -struct tcb *tcp; -{ - if (entering(tcp)) { - tprintf("%lu", tcp->u_arg[0]); -#ifdef LINUX - tprintf(", %#lx", tcp->u_arg[3]); - tprintf(", %lu", tcp->u_arg[1]); -#else /* !LINUX */ - tprintf(", %#lx", tcp->u_arg[1]); - tprintf(", %lu", tcp->u_arg[2]); -#endif /* !LINUX */ - } - return 0; -} + unsigned int i; + for (i = 1; i < tcp->s_ent->nargs; ++i) + tprintf(", %#" PRI_klx, tcp->u_arg[i]); -int sys_semget(tcp) -struct tcb *tcp; -{ - if (entering(tcp)) { - if (tcp->u_arg[0]) - tprintf("%lu", tcp->u_arg[0]); - else - tprintf("IPC_PRIVATE"); - tprintf(", %lu", tcp->u_arg[1]); - tprintf(", "); - if (printflags(resource_flags, tcp->u_arg[2]) != 0) - tprintf("|"); - tprintf("%#lo", tcp->u_arg[2] & 0666); - } - return 0; + return RVAL_DECODED; } - -int sys_semctl(tcp) -struct tcb *tcp; -{ - if (entering(tcp)) { - tprintf("%lu", tcp->u_arg[0]); - tprintf(", %lu, ", tcp->u_arg[1]); - printxval(semctl_flags, tcp->u_arg[2], "SEM_???"); - tprintf(", %#lx", tcp->u_arg[3]); - } - return 0; -} - -int sys_shmget(tcp) -struct tcb *tcp; -{ - if (entering(tcp)) { - if (tcp->u_arg[0]) - tprintf("%lu", tcp->u_arg[0]); - else - tprintf("IPC_PRIVATE"); - tprintf(", %lu", tcp->u_arg[1]); - tprintf(", "); - if (printflags(resource_flags, tcp->u_arg[2]) != 0) - tprintf("|"); - tprintf("%#lo", tcp->u_arg[2] & 0666); - } - return 0; -} - -int sys_shmctl(tcp) -struct tcb *tcp; -{ - if (entering(tcp)) { - tprintf("%lu, ", tcp->u_arg[0]); - printxval(shmctl_flags, tcp->u_arg[1], "SHM_???"); -#ifdef LINUX - tprintf(", %#lx", tcp->u_arg[3]); -#else /* !LINUX */ - tprintf(", %#lx", tcp->u_arg[2]); -#endif /* !LINUX */ - } - return 0; -} - -int sys_shmat(tcp) -struct tcb *tcp; -{ -#ifdef LINUX - unsigned long raddr; -#endif /* LINUX */ - - if (exiting(tcp)) { - tprintf("%lu", tcp->u_arg[0]); -#ifdef LINUX - tprintf(", %#lx", tcp->u_arg[3]); - tprintf(", "); - if (printflags(shm_flags, tcp->u_arg[1]) == 0) - tprintf("0"); -#else /* !LINUX */ - tprintf(", %#lx", tcp->u_arg[1]); - tprintf(", "); - if (printflags(shm_flags, tcp->u_arg[2]) == 0) - tprintf("0"); -#endif /* !LINUX */ - if (syserror(tcp)) - return 0; -#ifdef LINUX - if (umove(tcp, tcp->u_arg[2], &raddr) < 0) - return RVAL_NONE; - tcp->u_rval = raddr; -#endif /* LINUX */ - return RVAL_HEX; - } - return 0; -} - -int sys_shmdt(tcp) -struct tcb *tcp; -{ - if (entering(tcp)) -#ifdef LINUX - tprintf("%#lx", tcp->u_arg[3]); -#else /* !LINUX */ - tprintf("%#lx", tcp->u_arg[0]); -#endif /* !LINUX */ - return 0; -} - -#endif /* defined(LINUX) || defined(SUNOS4) */