xref: /netbsd-src/sys/sys/ipc.h (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: ipc.h,v 1.26 2003/08/07 16:34:05 agc Exp $	*/
2 
3 /*
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * This code is derived from software contributed to Berkeley by
13  * the Systems Programming Group of the University of Utah Computer
14  * Science Department.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *	@(#)ipc.h	8.4 (Berkeley) 2/19/95
41  */
42 
43 /*
44  * Copyright (c) 1988 University of Utah.
45  *
46  * This code is derived from software contributed to Berkeley by
47  * the Systems Programming Group of the University of Utah Computer
48  * Science Department.
49  *
50  * Redistribution and use in source and binary forms, with or without
51  * modification, are permitted provided that the following conditions
52  * are met:
53  * 1. Redistributions of source code must retain the above copyright
54  *    notice, this list of conditions and the following disclaimer.
55  * 2. Redistributions in binary form must reproduce the above copyright
56  *    notice, this list of conditions and the following disclaimer in the
57  *    documentation and/or other materials provided with the distribution.
58  * 3. All advertising materials mentioning features or use of this software
59  *    must display the following acknowledgement:
60  *	This product includes software developed by the University of
61  *	California, Berkeley and its contributors.
62  * 4. Neither the name of the University nor the names of its contributors
63  *    may be used to endorse or promote products derived from this software
64  *    without specific prior written permission.
65  *
66  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
67  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
69  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
70  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
72  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
73  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
74  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
75  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
76  * SUCH DAMAGE.
77  *
78  *	@(#)ipc.h	8.4 (Berkeley) 2/19/95
79  */
80 
81 /*
82  * SVID compatible ipc.h file
83  */
84 
85 #ifndef _SYS_IPC_H_
86 #define _SYS_IPC_H_
87 
88 #include <sys/featuretest.h>
89 #include <sys/types.h>
90 
91 struct ipc_perm {
92 	uid_t		uid;	/* user id */
93 	gid_t		gid;	/* group id */
94 	uid_t		cuid;	/* creator user id */
95 	gid_t		cgid;	/* creator group id */
96 	mode_t		mode;	/* r/w permission */
97 
98 	/*
99 	 * These members are private and used only in the internal
100 	 * implementation of this interface.
101 	 */
102 	unsigned short	_seq;	/* sequence # (to generate unique
103 				   msg/sem/shm id) */
104 	key_t		_key;	/* user specified msg/sem/shm key */
105 };
106 
107 #if defined(_NETBSD_SOURCE)
108 /* Warning: 64-bit structure padding is needed here */
109 struct ipc_perm_sysctl {
110 	u_int64_t	_key;
111 	uid_t		uid;
112 	gid_t		gid;
113 	uid_t		cuid;
114 	gid_t		cgid;
115 	mode_t		mode;
116 	int16_t		_seq;
117 	int16_t		pad;
118 };
119 #endif /* _NETBSD_SOURCE */
120 
121 #ifdef _KERNEL
122 /*
123  * Old IPC permission structure used before NetBSD 1.5.
124  */
125 struct ipc_perm14 {
126 	unsigned short	cuid;	/* creator user id */
127 	unsigned short	cgid;	/* creator group id */
128 	unsigned short	uid;	/* user id */
129 	unsigned short	gid;	/* group id */
130 	unsigned short	mode;	/* r/w permission */
131 	unsigned short	seq;	/* sequence # (to generate unique
132 				   msg/sem/shm id) */
133 	key_t	key;		/* user specified msg/sem/shm key */
134 };
135 #endif /* _KERNEL */
136 
137 /* Common access type bits, used with ipcperm(). */
138 #define	IPC_R		000400	/* read permission */
139 #define	IPC_W		000200	/* write/alter permission */
140 #define	IPC_M		010000	/* permission to change control info */
141 
142 /* X/Open required constants (same values as system 5) */
143 #define	IPC_CREAT	001000	/* create entry if key does not exist */
144 #define	IPC_EXCL	002000	/* fail if key exists */
145 #define	IPC_NOWAIT	004000	/* error if request must wait */
146 
147 #define	IPC_PRIVATE	(key_t)0 /* private key */
148 
149 #define	IPC_RMID	0	/* remove identifier */
150 #define	IPC_SET		1	/* set options */
151 #define	IPC_STAT	2	/* get options */
152 
153 /*
154  * Macros to convert between ipc ids and array indices or sequence ids.
155  * The first of these is used by ipcs(1), and so is defined outside the
156  * kernel as well.
157  */
158 #if defined(_NETBSD_SOURCE)
159 #define	IXSEQ_TO_IPCID(ix,perm)	(((perm._seq) << 16) | (ix & 0xffff))
160 #endif
161 
162 #ifdef _KERNEL
163 #define	IPCID_TO_IX(id)		((id) & 0xffff)
164 #define	IPCID_TO_SEQ(id)	(((id) >> 16) & 0xffff)
165 
166 int	ipcperm __P((struct ucred *, struct ipc_perm *, int));
167 
168 void	ipc_perm14_to_native __P((struct ipc_perm14 *, struct ipc_perm *));
169 void	native_to_ipc_perm14 __P((struct ipc_perm *, struct ipc_perm14 *));
170 #endif /* _KERNEL */
171 
172 #ifndef _KERNEL
173 #include <sys/cdefs.h>
174 
175 __BEGIN_DECLS
176 key_t	ftok __P((const char *, int));
177 __END_DECLS
178 #endif
179 #endif /* !_SYS_IPC_H_ */
180