1c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova/*
2c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * Copyright (c) 1993 Ulrich Pegelow <pegelow@moorea.uni-muenster.de>
3c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * Copyright (c) 2003-2006 Roland McGrath <roland@redhat.com>
7c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * Copyright (c) 2006-2015 Dmitry V. Levin <ldv@altlinux.org>
8c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * All rights reserved.
9c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova *
10c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * Redistribution and use in source and binary forms, with or without
11c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * modification, are permitted provided that the following conditions
12c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * are met:
13c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * 1. Redistributions of source code must retain the above copyright
14c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova *    notice, this list of conditions and the following disclaimer.
15c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * 2. Redistributions in binary form must reproduce the above copyright
16c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova *    notice, this list of conditions and the following disclaimer in the
17c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova *    documentation and/or other materials provided with the distribution.
18c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * 3. The name of the author may not be used to endorse or promote products
19c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova *    derived from this software without specific prior written permission.
20c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova *
21c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova */
32c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
33c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova#include "defs.h"
34c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova#include "ipc_defs.h"
35c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
36ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger#ifdef HAVE_SYS_SEM_H
37ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger# include <sys/sem.h>
38ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger#elif defined HAVE_LINUX_SEM_H
39ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger# include <linux/sem.h>
40ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger#endif
41c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
42c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova#include "xlat/semctl_flags.h"
43c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova#include "xlat/semop_flags.h"
44c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
45ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger#if defined HAVE_SYS_SEM_H || defined HAVE_LINUX_SEM_H
46c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirovastatic void
47c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirovatprint_sembuf(const struct sembuf *sb)
48c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova{
49c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	tprintf("{%u, %d, ", sb->sem_num, sb->sem_op);
50c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	printflags(semop_flags, sb->sem_flg, "SEM_???");
51c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	tprints("}");
52c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova}
53ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger#endif
54c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
55c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirovastatic void
56c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirovatprint_sembuf_array(struct tcb *tcp, const long addr, const unsigned long count)
57c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova{
58ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger#if defined HAVE_SYS_SEM_H || defined HAVE_LINUX_SEM_H
59c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	unsigned long max_count;
60c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	struct sembuf sb;
61c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
62c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	if (abbrev(tcp))
63c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		max_count = (max_strlen < count) ? max_strlen : count;
64c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	else
65c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		max_count = count;
66c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
67c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	if (!max_count)
68c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		printaddr(addr);
69c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	else if (!umove_or_printaddr(tcp, addr, &sb)) {
70c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		unsigned long i;
71c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
72c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprints("[");
73c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprint_sembuf(&sb);
74c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
75c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		for (i = 1; i < max_count; ++i) {
76c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova			tprints(", ");
77c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova			if (umove_or_printaddr(tcp, addr + i * sizeof(sb), &sb))
78c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova				break;
79c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova			else
80c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova				tprint_sembuf(&sb);
81c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		}
82c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
83c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		if (i < max_count || max_count < count)
84c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova			tprints(", ...");
85c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
86c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprints("]");
87c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	}
88ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger#else
89ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger	printaddr(addr);
90ba10a421b85b7f622975f2e9f92249cfe3dcfcbdMike Frysinger#endif
91c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	tprintf(", %lu", count);
92c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova}
93c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
94c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira KhabirovaSYS_FUNC(semop)
95c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova{
96c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	tprintf("%lu, ", tcp->u_arg[0]);
97c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	if (indirect_ipccall(tcp)) {
98c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]);
99c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	} else {
100c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprint_sembuf_array(tcp, tcp->u_arg[1], tcp->u_arg[2]);
101c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	}
102c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	return RVAL_DECODED;
103c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova}
104c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
105c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira KhabirovaSYS_FUNC(semtimedop)
106c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova{
107c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	tprintf("%lu, ", tcp->u_arg[0]);
108c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	if (indirect_ipccall(tcp)) {
109c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprint_sembuf_array(tcp, tcp->u_arg[3], tcp->u_arg[1]);
110c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprints(", ");
111c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova#if defined(S390) || defined(S390X)
1125938526c818336357b97caa8fd89d58a12987b02Dmitry V. Levin		print_timespec(tcp, tcp->u_arg[2]);
113c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova#else
1145938526c818336357b97caa8fd89d58a12987b02Dmitry V. Levin		print_timespec(tcp, tcp->u_arg[4]);
115c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova#endif
116c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	} else {
117c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprint_sembuf_array(tcp, tcp->u_arg[1], tcp->u_arg[2]);
118c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprints(", ");
1195938526c818336357b97caa8fd89d58a12987b02Dmitry V. Levin		print_timespec(tcp, tcp->u_arg[3]);
120c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	}
121c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	return RVAL_DECODED;
122c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova}
123c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
124c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira KhabirovaSYS_FUNC(semget)
125c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova{
126c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	if (tcp->u_arg[0])
127c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprintf("%#lx", tcp->u_arg[0]);
128c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	else
129c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprints("IPC_PRIVATE");
130c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	tprintf(", %lu, ", tcp->u_arg[1]);
131c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	if (printflags(resource_flags, tcp->u_arg[2] & ~0777, NULL) != 0)
132c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprints("|");
133c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	tprintf("%#lo", tcp->u_arg[2] & 0777);
134c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	return RVAL_DECODED;
135c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova}
136c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova
137c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira KhabirovaSYS_FUNC(semctl)
138c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova{
139c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
140c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	PRINTCTL(semctl_flags, tcp->u_arg[2], "SEM_???");
141c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	tprints(", ");
142c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	if (indirect_ipccall(tcp)) {
143c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		printnum_ptr(tcp, tcp->u_arg[3]);
144c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	} else {
145c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova		tprintf("%#lx", tcp->u_arg[3]);
146c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	}
147c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova	return RVAL_DECODED;
148c01ad06002f6c15fd0c8807e38e452bb240a1f92Elvira Khabirova}
149