xref: /netbsd/sys/sys/shm.h (revision bf9ec67e)
1 /*	$NetBSD: shm.h,v 1.30 2002/04/03 11:50:51 fvdl Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the NetBSD
22  *	Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 /*
41  * Copyright (c) 1994 Adam Glass
42  * All rights reserved.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *      This product includes software developed by Adam Glass.
55  * 4. The name of the author may not be used to endorse or promote products
56  *    derived from this software without specific prior written permission
57  *
58  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68  */
69 
70 /*
71  * As defined+described in "X/Open System Interfaces and Headers"
72  *                         Issue 4, p. XXX
73  */
74 
75 #ifndef _SYS_SHM_H_
76 #define _SYS_SHM_H_
77 
78 #include <sys/featuretest.h>
79 
80 #include <sys/ipc.h>
81 
82 #define	SHM_RDONLY	010000	/* Attach read-only (else read-write) */
83 #define	SHM_RND		020000	/* Round attach address to SHMLBA */
84 /* Segment low boundry address multiple */
85 #if defined(_KERNEL) || defined(_STANDALONE) || defined(_LKM)
86 #define	SHMLBA		PAGE_SIZE
87 #else
88 /* Use libc's internal __sysconf() to retrieve the machine's page size */
89 long			__sysconf __P((int));
90 #define	SHMLBA		(__sysconf(_SC_PAGESIZE))
91 #endif
92 
93 typedef unsigned int	shmatt_t;
94 
95 struct shmid_ds {
96 	struct ipc_perm	shm_perm;	/* operation permission structure */
97 	size_t		shm_segsz;	/* size of segment in bytes */
98 	pid_t		shm_lpid;	/* process ID of last shm operation */
99 	pid_t		shm_cpid;	/* process ID of creator */
100 	shmatt_t	shm_nattch;	/* number of current attaches */
101 	time_t		shm_atime;	/* time of last shmat() */
102 	time_t		shm_dtime;	/* time of last shmdt() */
103 	time_t		shm_ctime;	/* time of last change by shmctl() */
104 
105 	/*
106 	 * These members are private and used only in the internal
107 	 * implementation of this interface.
108 	 */
109 	void		*_shm_internal;
110 };
111 
112 #ifdef _KERNEL
113 struct shmid_ds14 {
114 	struct ipc_perm14 shm_perm;	/* operation permission structure */
115 	int		shm_segsz;	/* size of segment in bytes */
116 	pid_t		shm_lpid;	/* process ID of last shm op */
117 	pid_t		shm_cpid;	/* process ID of creator */
118 	short		shm_nattch;	/* number of current attaches */
119 	time_t		shm_atime;	/* time of last shmat() */
120 	time_t		shm_dtime;	/* time of last shmdt() */
121 	time_t		shm_ctime;	/* time of last change by shmctl() */
122 	void		*shm_internal;	/* sysv stupidity */
123 };
124 #endif /* _KERNEL */
125 
126 #if !defined(_XOPEN_SOURCE)
127 /*
128  * Some systems (e.g. HP-UX) take these as the second (cmd) arg to shmctl().
129  * XXX Currently not implemented.
130  */
131 #define	SHM_LOCK	3	/* Lock segment in memory. */
132 #define	SHM_UNLOCK	4	/* Unlock a segment locked by SHM_LOCK. */
133 #endif /* _XOPEN_SOURCE */
134 
135 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
136 /*
137  * Permission definitions used in shmflag arguments to shmat(2) and shmget(2).
138  * Provided for source compatibility only; do not use in new code!
139  */
140 #define	SHM_R		0000400	/* S_IRUSR, R for owner */
141 #define	SHM_W		0000200	/* S_IWUSR, W for owner */
142 
143 /*
144  * System 5 style catch-all structure for shared memory constants that
145  * might be of interest to user programs.  Do we really want/need this?
146  */
147 struct shminfo {
148 	int32_t	shmmax;		/* max shared memory segment size (bytes) */
149 	int32_t	shmmin;		/* min shared memory segment size (bytes) */
150 	int32_t	shmmni;		/* max number of shared memory identifiers */
151 	int32_t	shmseg;		/* max shared memory segments per process */
152 	int32_t	shmall;		/* max amount of shared memory (pages) */
153 };
154 
155 /* Warning: 64-bit structure padding is needed here */
156 struct shmid_ds_sysctl {
157 	struct		ipc_perm_sysctl shm_perm;
158 	u_int64_t	shm_segsz;
159 	pid_t		shm_lpid;
160 	pid_t		shm_cpid;
161 	time_t		shm_atime;
162 	time_t		shm_dtime;
163 	time_t		shm_ctime;
164 	u_int32_t	shm_nattch;
165 };
166 struct shm_sysctl_info {
167 	struct	shminfo shminfo;
168 	int32_t	pad;	/* shminfo not a multiple of 64 bits */
169 	struct	shmid_ds_sysctl shmids[1];
170 };
171 #endif /* !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
172 
173 #ifdef _KERNEL
174 extern struct shminfo shminfo;
175 extern struct shmid_ds *shmsegs;
176 
177 struct vmspace;
178 
179 void	shminit __P((void));
180 void	shmfork __P((struct vmspace *, struct vmspace *));
181 void	shmexit __P((struct vmspace *));
182 int	shmctl1 __P((struct proc *, int, int, struct shmid_ds *));
183 int	shmat1 __P((struct proc *, int, const void *, int, vaddr_t *, int));
184 #else /* !_KERNEL */
185 
186 #include <sys/cdefs.h>
187 
188 __BEGIN_DECLS
189 void	*shmat __P((int, const void *, int));
190 int	shmctl __P((int, int, struct shmid_ds *)) __RENAME(__shmctl13);
191 int	shmdt __P((const void *));
192 int	shmget __P((key_t, size_t, int));
193 __END_DECLS
194 
195 #endif /* !_KERNEL */
196 
197 #endif /* !_SYS_SHM_H_ */
198