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