xref: /netbsd/sys/sys/ipc.h (revision 143e6033)
1 /*	$NetBSD: ipc.h,v 1.31 2009/01/19 19:39:41 christos 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 	uint64_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 /* Common access type bits, used with ipcperm(). */
122 #define	IPC_R		000400	/* read permission */
123 #define	IPC_W		000200	/* write/alter permission */
124 #define	IPC_M		010000	/* permission to change control info */
125 
126 /* X/Open required constants (same values as system 5) */
127 #define	IPC_CREAT	001000	/* create entry if key does not exist */
128 #define	IPC_EXCL	002000	/* fail if key exists */
129 #define	IPC_NOWAIT	004000	/* error if request must wait */
130 
131 #define	IPC_PRIVATE	(key_t)0 /* private key */
132 
133 #define	IPC_RMID	0	/* remove identifier */
134 #define	IPC_SET		1	/* set options */
135 #define	IPC_STAT	2	/* get options */
136 
137 /*
138  * Macros to convert between ipc ids and array indices or sequence ids.
139  * The first of these is used by ipcs(1), and so is defined outside the
140  * kernel as well.
141  */
142 #if defined(_NETBSD_SOURCE)
143 #define	IXSEQ_TO_IPCID(ix,perm)	(((perm._seq) << 16) | (ix & 0xffff))
144 #endif
145 
146 #ifdef _KERNEL
147 #define	IPCID_TO_IX(id)		((id) & 0xffff)
148 #define	IPCID_TO_SEQ(id)	(((id) >> 16) & 0xffff)
149 
150 struct kauth_cred;
151 int	ipcperm(struct kauth_cred *, struct ipc_perm *, int);
152 
153 /*
154  * sysctl helper routine for kern.ipc.sysvipc_info subtree.
155  */
156 
157 #define SYSCTL_FILL_PERM(src, dst) do { \
158 	(dst)._key = (src)._key; \
159 	(dst).uid = (src).uid; \
160 	(dst).gid = (src).gid; \
161 	(dst).cuid = (src).cuid; \
162 	(dst).cgid = (src).cgid; \
163 	(dst).mode = (src).mode; \
164 	(dst)._seq = (src)._seq; \
165 } while (/*CONSTCOND*/ 0);
166 
167 #endif /* _KERNEL */
168 
169 #ifndef _KERNEL
170 #include <sys/cdefs.h>
171 
172 __BEGIN_DECLS
173 key_t	ftok(const char *, int);
174 __END_DECLS
175 #endif
176 #endif /* !_SYS_IPC_H_ */
177