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