xref: /netbsd/sys/compat/linux/common/linux_sem.h (revision f036aca9)
1 /*	$NetBSD: linux_sem.h,v 1.11 2021/09/23 06:56:27 ryo Exp $	*/
2 
3 /*-
4  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Frank van der Linden and Eric Haszlakiewicz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LINUX_SEM_H
33 #define _LINUX_SEM_H
34 
35 #include <sys/sem.h>
36 
37 /*
38  * Operations for semctl(2), in addition to IPC_STAT and IPC_SET
39  */
40 #define LINUX_GETPID  11
41 #define LINUX_GETVAL  12
42 #define LINUX_GETALL  13
43 #define LINUX_GETNCNT 14
44 #define LINUX_GETZCNT 15
45 #define LINUX_SETVAL  16
46 #define LINUX_SETALL  17
47 
48 /*
49  * Linux semid_ds structure. Internally used pointer fields are not
50  * important to us and have been changed to void *
51  */
52 
53 struct linux_semid_ds {
54 	struct linux_ipc_perm	 l_sem_perm;
55 	linux_time_t		 l_sem_otime;
56 	linux_time_t		 l_sem_ctime;
57 	void 			*l_sem_base;
58 	void			*l_eventn;
59 	void			*l_eventz;
60 	void			*l_undo;
61 	ushort			 l_sem_nsems;
62 };
63 
64 struct linux_semid64_ds {
65 	struct linux_ipc64_perm	 l_sem_perm;
66 	linux_time_t		 l_sem_otime;
67 	unsigned long		 l___unused1;
68 	linux_time_t		 l_sem_ctime;
69 	unsigned long		 l___unused2;
70 	unsigned long		 l_sem_nsems;
71 	unsigned long		 l___unused3;
72 	unsigned long		 l___unused4;
73 };
74 
75 union linux_semun {
76 	int			 l_val;
77 	struct linux_semid_ds	*l_buf;
78 	ushort			*l_array;
79 	void			*l___buf;	/* For unsupported IPC_INFO */
80 	void			*l___pad;
81 };
82 
83 /* Pretend the sys_semctl syscall is defined */
84 #if !defined(__aarch64__) && !defined(__amd64__)
85 struct linux_sys_semctl_args {
86 	syscallarg(int) semid;
87 	syscallarg(int) semnum;
88 	syscallarg(int) cmd;
89 	syscallarg(union linux_semun) arg;
90 };
91 int linux_sys_semctl(struct lwp *, const struct linux_sys_semctl_args *, register_t *);
92 #endif
93 
94 
95 #ifdef SYSVSEM
96 #ifdef _KERNEL
97 __BEGIN_DECLS
98 void bsd_to_linux_semid_ds(struct semid_ds *, struct linux_semid_ds *);
99 void bsd_to_linux_semid64_ds(struct semid_ds *, struct linux_semid64_ds *);
100 void linux_to_bsd_semid_ds(struct linux_semid_ds *, struct semid_ds *);
101 void linux_to_bsd_semid64_ds(struct linux_semid64_ds *, struct semid_ds *);
102 __END_DECLS
103 #endif	/* !_KERNEL */
104 #endif	/* !SYSVSEM */
105 
106 #endif /* !_LINUX_SEM_H */
107