xref: /third_party/ltp/include/lapi/sembuf.h (revision f08c3bdf)
1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) 2020 Linaro Limited. All rights reserved.
4f08c3bdfSopenharmony_ci * Author: Viresh Kumar <viresh.kumar@linaro.org>
5f08c3bdfSopenharmony_ci */
6f08c3bdfSopenharmony_ci
7f08c3bdfSopenharmony_ci#ifndef LAPI_SEMBUF_H__
8f08c3bdfSopenharmony_ci#define LAPI_SEMBUF_H__
9f08c3bdfSopenharmony_ci
10f08c3bdfSopenharmony_ci#include "lapi/posix_types.h"
11f08c3bdfSopenharmony_ci#include <sys/sem.h>
12f08c3bdfSopenharmony_ci#include "tst_timer.h"
13f08c3bdfSopenharmony_ci#include "ipcbuf.h"
14f08c3bdfSopenharmony_ci
15f08c3bdfSopenharmony_ci#ifndef HAVE_SEMID64_DS
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ci#if defined(__mips__)
18f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS
19f08c3bdfSopenharmony_ci/*
20f08c3bdfSopenharmony_ci * The semid64_ds structure for the MIPS architecture.
21f08c3bdfSopenharmony_ci * Note extra padding because this structure is passed back and forth
22f08c3bdfSopenharmony_ci * between kernel and user space.
23f08c3bdfSopenharmony_ci *
24f08c3bdfSopenharmony_ci * Pad space is left for 2 miscellaneous 64-bit values on mips64,
25f08c3bdfSopenharmony_ci * but used for the upper 32 bit of the time values on mips32.
26f08c3bdfSopenharmony_ci */
27f08c3bdfSopenharmony_ci#if __BITS_PER_LONG == 64
28f08c3bdfSopenharmony_cistruct semid64_ds {
29f08c3bdfSopenharmony_ci	struct ipc64_perm sem_perm;		/* permissions .. see ipc.h */
30f08c3bdfSopenharmony_ci	long		 sem_otime;		/* last semop time */
31f08c3bdfSopenharmony_ci	long		 sem_ctime;		/* last change time */
32f08c3bdfSopenharmony_ci	unsigned long	sem_nsems;		/* no. of semaphores in array */
33f08c3bdfSopenharmony_ci	unsigned long	__unused1;
34f08c3bdfSopenharmony_ci	unsigned long	__unused2;
35f08c3bdfSopenharmony_ci};
36f08c3bdfSopenharmony_ci#else
37f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS_TIME_HIGH
38f08c3bdfSopenharmony_cistruct semid64_ds {
39f08c3bdfSopenharmony_ci	struct ipc64_perm sem_perm;		/* permissions .. see ipc.h */
40f08c3bdfSopenharmony_ci	unsigned long   sem_otime;		/* last semop time */
41f08c3bdfSopenharmony_ci	unsigned long   sem_ctime;		/* last change time */
42f08c3bdfSopenharmony_ci	unsigned long	sem_nsems;		/* no. of semaphores in array */
43f08c3bdfSopenharmony_ci	unsigned long	sem_otime_high;
44f08c3bdfSopenharmony_ci	unsigned long	sem_ctime_high;
45f08c3bdfSopenharmony_ci};
46f08c3bdfSopenharmony_ci#endif
47f08c3bdfSopenharmony_ci#endif /* __mips__ */
48f08c3bdfSopenharmony_ci
49f08c3bdfSopenharmony_ci#if defined(__hppa__)
50f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS
51f08c3bdfSopenharmony_ci/*
52f08c3bdfSopenharmony_ci * The semid64_ds structure for parisc architecture.
53f08c3bdfSopenharmony_ci * Note extra padding because this structure is passed back and forth
54f08c3bdfSopenharmony_ci * between kernel and user space.
55f08c3bdfSopenharmony_ci *
56f08c3bdfSopenharmony_ci * Pad space is left for:
57f08c3bdfSopenharmony_ci * - 2 miscellaneous 32-bit values
58f08c3bdfSopenharmony_ci */
59f08c3bdfSopenharmony_cistruct semid64_ds {
60f08c3bdfSopenharmony_ci	struct ipc64_perm sem_perm;		/* permissions .. see ipc.h */
61f08c3bdfSopenharmony_ci#if __BITS_PER_LONG == 64
62f08c3bdfSopenharmony_ci	long		sem_otime;		/* last semop time */
63f08c3bdfSopenharmony_ci	long		sem_ctime;		/* last change time */
64f08c3bdfSopenharmony_ci#else
65f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS_TIME_HIGH
66f08c3bdfSopenharmony_ci	unsigned long	sem_otime_high;
67f08c3bdfSopenharmony_ci	unsigned long	sem_otime;		/* last semop time */
68f08c3bdfSopenharmony_ci	unsigned long	sem_ctime_high;
69f08c3bdfSopenharmony_ci	unsigned long	sem_ctime;		/* last change time */
70f08c3bdfSopenharmony_ci#endif
71f08c3bdfSopenharmony_ci	unsigned long	sem_nsems;		/* no. of semaphores in array */
72f08c3bdfSopenharmony_ci	unsigned long	__unused1;
73f08c3bdfSopenharmony_ci	unsigned long	__unused2;
74f08c3bdfSopenharmony_ci};
75f08c3bdfSopenharmony_ci#endif /* __hppa__ */
76f08c3bdfSopenharmony_ci
77f08c3bdfSopenharmony_ci#if defined(__powerpc__) || defined(__powerpc64__)
78f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS
79f08c3bdfSopenharmony_ci/*
80f08c3bdfSopenharmony_ci * The semid64_ds structure for PPC architecture.
81f08c3bdfSopenharmony_ci * Note extra padding because this structure is passed back and forth
82f08c3bdfSopenharmony_ci * between kernel and user space.
83f08c3bdfSopenharmony_ci *
84f08c3bdfSopenharmony_ci * Pad space is left for:
85f08c3bdfSopenharmony_ci * - 2 miscellaneous 32/64-bit values
86f08c3bdfSopenharmony_ci */
87f08c3bdfSopenharmony_ci
88f08c3bdfSopenharmony_cistruct semid64_ds {
89f08c3bdfSopenharmony_ci	struct ipc64_perm sem_perm;	/* permissions .. see ipc.h */
90f08c3bdfSopenharmony_ci#ifndef __powerpc64__
91f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS_TIME_HIGH
92f08c3bdfSopenharmony_ci	unsigned long	sem_otime_high;
93f08c3bdfSopenharmony_ci	unsigned long	sem_otime;	/* last semop time */
94f08c3bdfSopenharmony_ci	unsigned long	sem_ctime_high;
95f08c3bdfSopenharmony_ci	unsigned long	sem_ctime;	/* last change time */
96f08c3bdfSopenharmony_ci#else
97f08c3bdfSopenharmony_ci	long		sem_otime;	/* last semop time */
98f08c3bdfSopenharmony_ci	long		sem_ctime;	/* last change time */
99f08c3bdfSopenharmony_ci#endif
100f08c3bdfSopenharmony_ci	unsigned long	sem_nsems;	/* no. of semaphores in array */
101f08c3bdfSopenharmony_ci	unsigned long	__unused3;
102f08c3bdfSopenharmony_ci	unsigned long	__unused4;
103f08c3bdfSopenharmony_ci};
104f08c3bdfSopenharmony_ci#endif /* defined(__powerpc__) || defined(__powerpc64__) */
105f08c3bdfSopenharmony_ci
106f08c3bdfSopenharmony_ci#if defined(__sparc__)
107f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS
108f08c3bdfSopenharmony_ci/*
109f08c3bdfSopenharmony_ci * The semid64_ds structure for sparc architecture.
110f08c3bdfSopenharmony_ci * Note extra padding because this structure is passed back and forth
111f08c3bdfSopenharmony_ci * between kernel and user space.
112f08c3bdfSopenharmony_ci *
113f08c3bdfSopenharmony_ci * Pad space is left for:
114f08c3bdfSopenharmony_ci * - 2 miscellaneous 32-bit values
115f08c3bdfSopenharmony_ci */
116f08c3bdfSopenharmony_ci
117f08c3bdfSopenharmony_cistruct semid64_ds {
118f08c3bdfSopenharmony_ci	struct ipc64_perm sem_perm;		/* permissions .. see ipc.h */
119f08c3bdfSopenharmony_ci#if defined(__arch64__)
120f08c3bdfSopenharmony_ci	long		sem_otime;		/* last semop time */
121f08c3bdfSopenharmony_ci	long		sem_ctime;		/* last change time */
122f08c3bdfSopenharmony_ci#else
123f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS_TIME_HIGH
124f08c3bdfSopenharmony_ci	unsigned long	sem_otime_high;
125f08c3bdfSopenharmony_ci	unsigned long	sem_otime;		/* last semop time */
126f08c3bdfSopenharmony_ci	unsigned long	sem_ctime_high;
127f08c3bdfSopenharmony_ci	unsigned long	sem_ctime;		/* last change time */
128f08c3bdfSopenharmony_ci#endif
129f08c3bdfSopenharmony_ci	unsigned long	sem_nsems;		/* no. of semaphores in array */
130f08c3bdfSopenharmony_ci	unsigned long	__unused1;
131f08c3bdfSopenharmony_ci	unsigned long	__unused2;
132f08c3bdfSopenharmony_ci};
133f08c3bdfSopenharmony_ci#endif /* __sparc__ */
134f08c3bdfSopenharmony_ci
135f08c3bdfSopenharmony_ci#if defined(__x86_64__)
136f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS
137f08c3bdfSopenharmony_ci/*
138f08c3bdfSopenharmony_ci * The semid64_ds structure for x86 architecture.
139f08c3bdfSopenharmony_ci * Note extra padding because this structure is passed back and forth
140f08c3bdfSopenharmony_ci * between kernel and user space.
141f08c3bdfSopenharmony_ci *
142f08c3bdfSopenharmony_ci * Pad space is left for:
143f08c3bdfSopenharmony_ci * - 2 miscellaneous 32-bit values
144f08c3bdfSopenharmony_ci *
145f08c3bdfSopenharmony_ci * x86_64 and x32 incorrectly added padding here, so the structures
146f08c3bdfSopenharmony_ci * are still incompatible with the padding on x86.
147f08c3bdfSopenharmony_ci */
148f08c3bdfSopenharmony_cistruct semid64_ds {
149f08c3bdfSopenharmony_ci	struct ipc64_perm sem_perm;	/* permissions .. see ipc.h */
150f08c3bdfSopenharmony_ci#ifdef __i386__
151f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS_TIME_HIGH
152f08c3bdfSopenharmony_ci	unsigned long	sem_otime;	/* last semop time */
153f08c3bdfSopenharmony_ci	unsigned long	sem_otime_high;
154f08c3bdfSopenharmony_ci	unsigned long	sem_ctime;	/* last change time */
155f08c3bdfSopenharmony_ci	unsigned long	sem_ctime_high;
156f08c3bdfSopenharmony_ci#else
157f08c3bdfSopenharmony_ci	__kernel_long_t sem_otime;	/* last semop time */
158f08c3bdfSopenharmony_ci	__kernel_ulong_t __unused1;
159f08c3bdfSopenharmony_ci	__kernel_long_t sem_ctime;	/* last change time */
160f08c3bdfSopenharmony_ci	__kernel_ulong_t __unused2;
161f08c3bdfSopenharmony_ci#endif
162f08c3bdfSopenharmony_ci	__kernel_ulong_t sem_nsems;	/* no. of semaphores in array */
163f08c3bdfSopenharmony_ci	__kernel_ulong_t __unused3;
164f08c3bdfSopenharmony_ci	__kernel_ulong_t __unused4;
165f08c3bdfSopenharmony_ci};
166f08c3bdfSopenharmony_ci#endif /* defined(__x86_64__) */
167f08c3bdfSopenharmony_ci
168f08c3bdfSopenharmony_ci#if defined(__xtensa__)
169f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS
170f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS_TIME_HIGH
171f08c3bdfSopenharmony_ci
172f08c3bdfSopenharmony_cistruct semid64_ds {
173f08c3bdfSopenharmony_ci	struct ipc64_perm sem_perm;		/* permissions .. see ipc.h */
174f08c3bdfSopenharmony_ci#ifdef __XTENSA_EL__
175f08c3bdfSopenharmony_ci	unsigned long	sem_otime;		/* last semop time */
176f08c3bdfSopenharmony_ci	unsigned long	sem_otime_high;
177f08c3bdfSopenharmony_ci	unsigned long	sem_ctime;		/* last change time */
178f08c3bdfSopenharmony_ci	unsigned long	sem_ctime_high;
179f08c3bdfSopenharmony_ci#else
180f08c3bdfSopenharmony_ci	unsigned long	sem_otime_high;
181f08c3bdfSopenharmony_ci	unsigned long	sem_otime;		/* last semop time */
182f08c3bdfSopenharmony_ci	unsigned long	sem_ctime_high;
183f08c3bdfSopenharmony_ci	unsigned long	sem_ctime;		/* last change time */
184f08c3bdfSopenharmony_ci#endif
185f08c3bdfSopenharmony_ci	unsigned long	sem_nsems;		/* no. of semaphores in array */
186f08c3bdfSopenharmony_ci	unsigned long	__unused3;
187f08c3bdfSopenharmony_ci	unsigned long	__unused4;
188f08c3bdfSopenharmony_ci};
189f08c3bdfSopenharmony_ci
190f08c3bdfSopenharmony_ci#endif /* __xtensa__ */
191f08c3bdfSopenharmony_ci
192f08c3bdfSopenharmony_ci#ifndef HAVE_SEMID64_DS
193f08c3bdfSopenharmony_ci/*
194f08c3bdfSopenharmony_ci * The semid64_ds structure for most architectures (though it came
195f08c3bdfSopenharmony_ci * from x86_32 originally). Note extra padding because this structure
196f08c3bdfSopenharmony_ci * is passed back and forth between kernel and user space.
197f08c3bdfSopenharmony_ci *
198f08c3bdfSopenharmony_ci * semid64_ds was originally meant to be architecture specific, but
199f08c3bdfSopenharmony_ci * everyone just ended up making identical copies without specific
200f08c3bdfSopenharmony_ci * optimizations, so we may just as well all use the same one.
201f08c3bdfSopenharmony_ci *
202f08c3bdfSopenharmony_ci * 64 bit architectures use a 64-bit long time field here, while
203f08c3bdfSopenharmony_ci * 32 bit architectures have a pair of unsigned long values.
204f08c3bdfSopenharmony_ci *
205f08c3bdfSopenharmony_ci * On big-endian systems, the padding is in the wrong place for
206f08c3bdfSopenharmony_ci * historic reasons, so user space has to reconstruct a time_t
207f08c3bdfSopenharmony_ci * value using
208f08c3bdfSopenharmony_ci *
209f08c3bdfSopenharmony_ci * user_semid_ds.sem_otime = kernel_semid64_ds.sem_otime +
210f08c3bdfSopenharmony_ci *		((long long)kernel_semid64_ds.sem_otime_high << 32)
211f08c3bdfSopenharmony_ci *
212f08c3bdfSopenharmony_ci * Pad space is left for 2 miscellaneous 32-bit values
213f08c3bdfSopenharmony_ci */
214f08c3bdfSopenharmony_cistruct semid64_ds {
215f08c3bdfSopenharmony_ci	struct ipc64_perm sem_perm;	/* permissions .. see ipc.h */
216f08c3bdfSopenharmony_ci#if __BITS_PER_LONG == 64
217f08c3bdfSopenharmony_ci	long		sem_otime;	/* last semop time */
218f08c3bdfSopenharmony_ci	long		sem_ctime;	/* last change time */
219f08c3bdfSopenharmony_ci#else
220f08c3bdfSopenharmony_ci#define HAVE_SEMID64_DS_TIME_HIGH
221f08c3bdfSopenharmony_ci	unsigned long	sem_otime;	/* last semop time */
222f08c3bdfSopenharmony_ci	unsigned long	sem_otime_high;
223f08c3bdfSopenharmony_ci	unsigned long	sem_ctime;	/* last change time */
224f08c3bdfSopenharmony_ci	unsigned long	sem_ctime_high;
225f08c3bdfSopenharmony_ci#endif
226f08c3bdfSopenharmony_ci	unsigned long	sem_nsems;	/* no. of semaphores in array */
227f08c3bdfSopenharmony_ci	unsigned long	__unused3;
228f08c3bdfSopenharmony_ci	unsigned long	__unused4;
229f08c3bdfSopenharmony_ci};
230f08c3bdfSopenharmony_ci#endif /* semid64_ds */
231f08c3bdfSopenharmony_ci
232f08c3bdfSopenharmony_ci#endif /* HAVE_SEMID64_DS */
233f08c3bdfSopenharmony_ci
234f08c3bdfSopenharmony_ci#endif /* LAPI_SEMBUF_H__ */
235