]> granicus.if.org Git - strace/blob - ipc_msg.c
Fix preprocessor indentation
[strace] / ipc_msg.c
1 /*
2  * Copyright (c) 1993 Ulrich Pegelow <pegelow@moorea.uni-muenster.de>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * Copyright (c) 2003-2006 Roland McGrath <roland@redhat.com>
7  * Copyright (c) 2006-2015 Dmitry V. Levin <ldv@altlinux.org>
8  * Copyright (c) 2015-2018 The strace developers.
9  * All rights reserved.
10  *
11  * SPDX-License-Identifier: LGPL-2.1-or-later
12  */
13
14 #include "defs.h"
15 #include "ipc_defs.h"
16
17 #ifdef HAVE_SYS_MSG_H
18 # include <sys/msg.h>
19 #elif defined HAVE_LINUX_MSG_H
20 # include <linux/msg.h>
21 #endif
22
23 #include "xlat/ipc_msg_flags.h"
24 #include "xlat/ipc_private.h"
25 #include "xlat/resource_flags.h"
26
27 SYS_FUNC(msgget)
28 {
29         printxval(ipc_private, (unsigned int) tcp->u_arg[0], NULL);
30         tprints(", ");
31         if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0)
32                 tprints("|");
33         print_numeric_umode_t(tcp->u_arg[1] & 0777);
34         return RVAL_DECODED;
35 }
36
37 static void
38 tprint_msgsnd(struct tcb *const tcp, const kernel_ulong_t addr,
39               const kernel_ulong_t count, const unsigned int flags)
40 {
41         tprint_msgbuf(tcp, addr, count);
42         printflags(ipc_msg_flags, flags, "MSG_???");
43 }
44
45 SYS_FUNC(msgsnd)
46 {
47         tprintf("%d, ", (int) tcp->u_arg[0]);
48         if (indirect_ipccall(tcp)) {
49                 tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1],
50                               tcp->u_arg[2]);
51         } else {
52                 tprint_msgsnd(tcp, tcp->u_arg[1], tcp->u_arg[2],
53                               tcp->u_arg[3]);
54         }
55         return RVAL_DECODED;
56 }
57
58 static void
59 tprint_msgrcv(struct tcb *const tcp, const kernel_ulong_t addr,
60               const kernel_ulong_t count, const kernel_ulong_t msgtyp)
61 {
62         tprint_msgbuf(tcp, addr, count);
63         tprintf("%" PRI_kld ", ", msgtyp);
64 }
65
66 static int
67 fetch_msgrcv_args(struct tcb *const tcp, const kernel_ulong_t addr,
68                   kernel_ulong_t *const pair)
69 {
70         if (current_wordsize == sizeof(*pair)) {
71                 if (umoven_or_printaddr(tcp, addr, 2 * sizeof(*pair), pair))
72                         return -1;
73         } else {
74                 unsigned int tmp[2];
75
76                 if (umove_or_printaddr(tcp, addr, &tmp))
77                         return -1;
78                 pair[0] = tmp[0];
79                 pair[1] = (int) tmp[1];
80         }
81         return 0;
82 }
83
84 SYS_FUNC(msgrcv)
85 {
86         if (entering(tcp)) {
87                 tprintf("%d, ", (int) tcp->u_arg[0]);
88         } else {
89                 if (indirect_ipccall(tcp)) {
90                         const bool direct =
91 #ifdef SPARC64
92                                 current_wordsize == 8 ||
93 #endif
94                                 get_tcb_priv_ulong(tcp) != 0;
95                         if (direct) {
96                                 tprint_msgrcv(tcp, tcp->u_arg[3],
97                                               tcp->u_arg[1], tcp->u_arg[4]);
98                         } else {
99                                 kernel_ulong_t pair[2];
100
101                                 if (fetch_msgrcv_args(tcp, tcp->u_arg[3], pair))
102                                         tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
103                                 else
104                                         tprint_msgrcv(tcp, pair[0],
105                                                       tcp->u_arg[1], pair[1]);
106                         }
107                         printflags(ipc_msg_flags, tcp->u_arg[2], "MSG_???");
108                 } else {
109                         tprint_msgrcv(tcp, tcp->u_arg[1],
110                                 tcp->u_arg[2], tcp->u_arg[3]);
111                         printflags(ipc_msg_flags, tcp->u_arg[4], "MSG_???");
112                 }
113         }
114         return 0;
115 }