]> granicus.if.org Git - strace/blob - ipc_sem.c
xlat: provide fallback definitions for XDP_FLAGS_* constants
[strace] / ipc_sem.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-2019 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_SEM_H
18 # include <sys/sem.h>
19 #elif defined HAVE_LINUX_SEM_H
20 # include <linux/sem.h>
21 #endif
22
23 #include "xlat/semctl_flags.h"
24 #include "xlat/semop_flags.h"
25
26 #if defined HAVE_SYS_SEM_H || defined HAVE_LINUX_SEM_H
27 static bool
28 print_sembuf(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
29 {
30         const struct sembuf *sb = elem_buf;
31
32         tprintf("{%u, %d, ", sb->sem_num, sb->sem_op);
33         printflags(semop_flags, (unsigned short) sb->sem_flg, "SEM_???");
34         tprints("}");
35
36         return true;
37 }
38 #endif
39
40 static void
41 tprint_sembuf_array(struct tcb *const tcp, const kernel_ulong_t addr,
42                     const unsigned int count)
43 {
44 #if defined HAVE_SYS_SEM_H || defined HAVE_LINUX_SEM_H
45         struct sembuf sb;
46         print_array(tcp, addr, count, &sb, sizeof(sb),
47                     tfetch_mem, print_sembuf, 0);
48 #else
49         printaddr(addr);
50 #endif
51         tprintf(", %u", count);
52 }
53
54 SYS_FUNC(semop)
55 {
56         tprintf("%d, ", (int) tcp->u_arg[0]);
57         if (indirect_ipccall(tcp)) {
58                 tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]);
59         } else {
60                 tprint_sembuf_array(tcp, tcp->u_arg[1], tcp->u_arg[2]);
61         }
62         return RVAL_DECODED;
63 }
64
65 static int
66 do_semtimedop(struct tcb *const tcp, const print_obj_by_addr_fn print_ts)
67 {
68         tprintf("%d, ", (int) tcp->u_arg[0]);
69         if (indirect_ipccall(tcp)) {
70                 tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]);
71                 tprints(", ");
72 #if defined(S390) || defined(S390X)
73                 print_ts(tcp, tcp->u_arg[2]);
74 #else
75                 print_ts(tcp, tcp->u_arg[4]);
76 #endif
77         } else {
78                 tprint_sembuf_array(tcp, tcp->u_arg[1], tcp->u_arg[2]);
79                 tprints(", ");
80                 print_ts(tcp, tcp->u_arg[3]);
81         }
82         return RVAL_DECODED;
83 }
84
85 #if HAVE_ARCH_TIME32_SYSCALLS
86 SYS_FUNC(semtimedop_time32)
87 {
88         return do_semtimedop(tcp, print_timespec32);
89 }
90 #endif
91
92 SYS_FUNC(semtimedop_time64)
93 {
94         return do_semtimedop(tcp, print_timespec64);
95 }
96
97 SYS_FUNC(semget)
98 {
99         printxval(ipc_private, (unsigned int) tcp->u_arg[0], NULL);
100         tprintf(", %d, ", (int) tcp->u_arg[1]);
101         if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
102                 tprints("|");
103         print_numeric_umode_t(tcp->u_arg[2] & 0777);
104         return RVAL_DECODED;
105 }
106
107 SYS_FUNC(semctl)
108 {
109         tprintf("%d, %d, ", (int) tcp->u_arg[0], (int) tcp->u_arg[1]);
110         PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
111         tprints(", ");
112         if (indirect_ipccall(tcp)
113 #ifdef SPARC64
114             && current_personality != 0
115 #endif
116            ) {
117                 printnum_ptr(tcp, tcp->u_arg[3]);
118         } else {
119                 printaddr(tcp->u_arg[3]);
120         }
121         return RVAL_DECODED;
122 }