xref: /f-stack/freebsd/sys/ipc.h (revision 22ce4aff)
1a9643ea8Slogwang /*-
2*22ce4affSfengbojiang  * SPDX-License-Identifier: BSD-3-Clause
3*22ce4affSfengbojiang  *
4a9643ea8Slogwang  * Copyright (c) 1988 University of Utah.
5a9643ea8Slogwang  * Copyright (c) 1990, 1993
6a9643ea8Slogwang  *	The Regents of the University of California.  All rights reserved.
7a9643ea8Slogwang  * (c) UNIX System Laboratories, Inc.
8a9643ea8Slogwang  * All or some portions of this file are derived from material licensed
9a9643ea8Slogwang  * to the University of California by American Telephone and Telegraph
10a9643ea8Slogwang  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11a9643ea8Slogwang  * the permission of UNIX System Laboratories, Inc.
12a9643ea8Slogwang  *
13a9643ea8Slogwang  * This code is derived from software contributed to Berkeley by
14a9643ea8Slogwang  * the Systems Programming Group of the University of Utah Computer
15a9643ea8Slogwang  * Science Department.
16a9643ea8Slogwang  *
17a9643ea8Slogwang  * Redistribution and use in source and binary forms, with or without
18a9643ea8Slogwang  * modification, are permitted provided that the following conditions
19a9643ea8Slogwang  * are met:
20a9643ea8Slogwang  * 1. Redistributions of source code must retain the above copyright
21a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer.
22a9643ea8Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
23a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer in the
24a9643ea8Slogwang  *    documentation and/or other materials provided with the distribution.
25*22ce4affSfengbojiang  * 3. Neither the name of the University nor the names of its contributors
26a9643ea8Slogwang  *    may be used to endorse or promote products derived from this software
27a9643ea8Slogwang  *    without specific prior written permission.
28a9643ea8Slogwang  *
29a9643ea8Slogwang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30a9643ea8Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31a9643ea8Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32a9643ea8Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33a9643ea8Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34a9643ea8Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35a9643ea8Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36a9643ea8Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37a9643ea8Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38a9643ea8Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39a9643ea8Slogwang  * SUCH DAMAGE.
40a9643ea8Slogwang  *
41a9643ea8Slogwang  *	@(#)ipc.h	8.4 (Berkeley) 2/19/95
42a9643ea8Slogwang  * $FreeBSD$
43a9643ea8Slogwang  */
44a9643ea8Slogwang 
45a9643ea8Slogwang /*
46a9643ea8Slogwang  * SVID compatible ipc.h file
47a9643ea8Slogwang  */
48a9643ea8Slogwang #ifndef _SYS_IPC_H_
49a9643ea8Slogwang #define _SYS_IPC_H_
50a9643ea8Slogwang 
51a9643ea8Slogwang #include <sys/cdefs.h>
52a9643ea8Slogwang #include <sys/_types.h>
53a9643ea8Slogwang 
54a9643ea8Slogwang #ifndef _GID_T_DECLARED
55a9643ea8Slogwang typedef	__gid_t		gid_t;
56a9643ea8Slogwang #define	_GID_T_DECLARED
57a9643ea8Slogwang #endif
58a9643ea8Slogwang 
59a9643ea8Slogwang #ifndef _KEY_T_DECLARED
60a9643ea8Slogwang typedef	__key_t		key_t;
61a9643ea8Slogwang #define	_KEY_T_DECLARED
62a9643ea8Slogwang #endif
63a9643ea8Slogwang 
64a9643ea8Slogwang #ifndef _MODE_T_DECLARED
65a9643ea8Slogwang typedef	__mode_t	mode_t;
66a9643ea8Slogwang #define	_MODE_T_DECLARED
67a9643ea8Slogwang #endif
68a9643ea8Slogwang 
69a9643ea8Slogwang #ifndef _UID_T_DECLARED
70a9643ea8Slogwang typedef	__uid_t		uid_t;
71a9643ea8Slogwang #define	_UID_T_DECLARED
72a9643ea8Slogwang #endif
73a9643ea8Slogwang 
74a9643ea8Slogwang #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
75a9643ea8Slogwang     defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) || \
76a9643ea8Slogwang     defined(COMPAT_43)
77a9643ea8Slogwang struct ipc_perm_old {
78a9643ea8Slogwang 	unsigned short	cuid;	/* creator user id */
79a9643ea8Slogwang 	unsigned short	cgid;	/* creator group id */
80a9643ea8Slogwang 	unsigned short	uid;	/* user id */
81a9643ea8Slogwang 	unsigned short	gid;	/* group id */
82a9643ea8Slogwang 	unsigned short	mode;	/* r/w permission */
83a9643ea8Slogwang 	unsigned short	seq;	/* sequence # (to generate unique ipcid) */
84a9643ea8Slogwang 	key_t		key;	/* user specified msg/sem/shm key */
85a9643ea8Slogwang };
86a9643ea8Slogwang #endif
87a9643ea8Slogwang 
88a9643ea8Slogwang struct ipc_perm {
89a9643ea8Slogwang 	uid_t		cuid;	/* creator user id */
90a9643ea8Slogwang 	gid_t		cgid;	/* creator group id */
91a9643ea8Slogwang 	uid_t		uid;	/* user id */
92a9643ea8Slogwang 	gid_t		gid;	/* group id */
93a9643ea8Slogwang 	mode_t		mode;	/* r/w permission */
94a9643ea8Slogwang 	unsigned short	seq;	/* sequence # (to generate unique ipcid) */
95a9643ea8Slogwang 	key_t		key;	/* user specified msg/sem/shm key */
96a9643ea8Slogwang };
97a9643ea8Slogwang 
98a9643ea8Slogwang #if __BSD_VISIBLE
99a9643ea8Slogwang /* common mode bits */
100a9643ea8Slogwang #define	IPC_R		000400	/* read permission */
101a9643ea8Slogwang #define	IPC_W		000200	/* write/alter permission */
102a9643ea8Slogwang #define	IPC_M		010000	/* permission to change control info */
103a9643ea8Slogwang #endif
104a9643ea8Slogwang 
105a9643ea8Slogwang /* SVID required constants (same values as system 5) */
106a9643ea8Slogwang #define	IPC_CREAT	001000	/* create entry if key does not exist */
107a9643ea8Slogwang #define	IPC_EXCL	002000	/* fail if key exists */
108a9643ea8Slogwang #define	IPC_NOWAIT	004000	/* error if request must wait */
109a9643ea8Slogwang 
110a9643ea8Slogwang #define	IPC_PRIVATE	(key_t)0 /* private key */
111a9643ea8Slogwang 
112a9643ea8Slogwang #define	IPC_RMID	0	/* remove identifier */
113a9643ea8Slogwang #define	IPC_SET		1	/* set options */
114a9643ea8Slogwang #define	IPC_STAT	2	/* get options */
115a9643ea8Slogwang #if __BSD_VISIBLE
116a9643ea8Slogwang /*
117a9643ea8Slogwang  * For Linux compatibility.
118a9643ea8Slogwang  */
119a9643ea8Slogwang #define	IPC_INFO	3	/* get info */
120a9643ea8Slogwang #endif
121a9643ea8Slogwang 
122*22ce4affSfengbojiang #if defined(_KERNEL) || defined(_WANT_SYSVIPC_INTERNALS)
123a9643ea8Slogwang /* Macros to convert between ipc ids and array indices or sequence ids */
124a9643ea8Slogwang #define	IPCID_TO_IX(id)		((id) & 0xffff)
125a9643ea8Slogwang #define	IPCID_TO_SEQ(id)	(((id) >> 16) & 0xffff)
126a9643ea8Slogwang #define	IXSEQ_TO_IPCID(ix,perm)	(((perm.seq) << 16) | (ix & 0xffff))
127*22ce4affSfengbojiang #endif
128a9643ea8Slogwang 
129*22ce4affSfengbojiang #ifdef _KERNEL
130a9643ea8Slogwang struct thread;
131a9643ea8Slogwang struct proc;
132a9643ea8Slogwang struct vmspace;
133a9643ea8Slogwang 
134a9643ea8Slogwang #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
135a9643ea8Slogwang     defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
136a9643ea8Slogwang void	ipcperm_old2new(struct ipc_perm_old *, struct ipc_perm *);
137a9643ea8Slogwang void	ipcperm_new2old(struct ipc_perm *, struct ipc_perm_old *);
138a9643ea8Slogwang #endif
139a9643ea8Slogwang 
140a9643ea8Slogwang int	ipcperm(struct thread *, struct ipc_perm *, int);
141a9643ea8Slogwang extern void (*shmfork_hook)(struct proc *, struct proc *);
142a9643ea8Slogwang extern void (*shmexit_hook)(struct vmspace *);
143a9643ea8Slogwang 
144a9643ea8Slogwang #else /* ! _KERNEL */
145a9643ea8Slogwang 
146a9643ea8Slogwang __BEGIN_DECLS
147a9643ea8Slogwang key_t	ftok(const char *, int);
148a9643ea8Slogwang __END_DECLS
149a9643ea8Slogwang 
150a9643ea8Slogwang #endif /* _KERNEL */
151a9643ea8Slogwang 
152a9643ea8Slogwang #endif /* !_SYS_IPC_H_ */
153