xref: /xnu-11417.121.6/bsd/sys/shm_internal.h (revision a1e26a70f38d1d7daa7b49b258e2f8538ad81650)
1*a1e26a70SApple OSS Distributions /*
2*a1e26a70SApple OSS Distributions  * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3*a1e26a70SApple OSS Distributions  *
4*a1e26a70SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*a1e26a70SApple OSS Distributions  *
6*a1e26a70SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*a1e26a70SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*a1e26a70SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*a1e26a70SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*a1e26a70SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*a1e26a70SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*a1e26a70SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*a1e26a70SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*a1e26a70SApple OSS Distributions  *
15*a1e26a70SApple OSS Distributions  * Please obtain a copy of the License at
16*a1e26a70SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*a1e26a70SApple OSS Distributions  *
18*a1e26a70SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*a1e26a70SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*a1e26a70SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*a1e26a70SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*a1e26a70SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*a1e26a70SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*a1e26a70SApple OSS Distributions  * limitations under the License.
25*a1e26a70SApple OSS Distributions  *
26*a1e26a70SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*a1e26a70SApple OSS Distributions  */
28*a1e26a70SApple OSS Distributions /*	$NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $	*/
29*a1e26a70SApple OSS Distributions 
30*a1e26a70SApple OSS Distributions /*
31*a1e26a70SApple OSS Distributions  * Copyright (c) 1994 Adam Glass
32*a1e26a70SApple OSS Distributions  * All rights reserved.
33*a1e26a70SApple OSS Distributions  *
34*a1e26a70SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
35*a1e26a70SApple OSS Distributions  * modification, are permitted provided that the following conditions
36*a1e26a70SApple OSS Distributions  * are met:
37*a1e26a70SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
38*a1e26a70SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
39*a1e26a70SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
40*a1e26a70SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
41*a1e26a70SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
42*a1e26a70SApple OSS Distributions  * 3. All advertising materials mentioning features or use of this software
43*a1e26a70SApple OSS Distributions  *    must display the following acknowledgement:
44*a1e26a70SApple OSS Distributions  *      This product includes software developed by Adam Glass.
45*a1e26a70SApple OSS Distributions  * 4. The name of the author may not be used to endorse or promote products
46*a1e26a70SApple OSS Distributions  *    derived from this software without specific prior written permission
47*a1e26a70SApple OSS Distributions  *
48*a1e26a70SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
49*a1e26a70SApple OSS Distributions  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
50*a1e26a70SApple OSS Distributions  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51*a1e26a70SApple OSS Distributions  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
52*a1e26a70SApple OSS Distributions  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
53*a1e26a70SApple OSS Distributions  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54*a1e26a70SApple OSS Distributions  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55*a1e26a70SApple OSS Distributions  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56*a1e26a70SApple OSS Distributions  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
57*a1e26a70SApple OSS Distributions  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58*a1e26a70SApple OSS Distributions  */
59*a1e26a70SApple OSS Distributions /*
60*a1e26a70SApple OSS Distributions  * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
61*a1e26a70SApple OSS Distributions  * support for mandatory and extensible security protections.  This notice
62*a1e26a70SApple OSS Distributions  * is included in support of clause 2.2 (b) of the Apple Public License,
63*a1e26a70SApple OSS Distributions  * Version 2.0.
64*a1e26a70SApple OSS Distributions  */
65*a1e26a70SApple OSS Distributions 
66*a1e26a70SApple OSS Distributions /*
67*a1e26a70SApple OSS Distributions  * As defined+described in "X/Open System Interfaces and Headers"
68*a1e26a70SApple OSS Distributions  *                         Issue 4, p. XXX
69*a1e26a70SApple OSS Distributions  */
70*a1e26a70SApple OSS Distributions 
71*a1e26a70SApple OSS Distributions #ifndef _SYS_SHM_INTERNALH_
72*a1e26a70SApple OSS Distributions #define _SYS_SHM_INTERNALH_
73*a1e26a70SApple OSS Distributions 
74*a1e26a70SApple OSS Distributions #include <sys/shm.h>
75*a1e26a70SApple OSS Distributions #include <sys/cdefs.h>
76*a1e26a70SApple OSS Distributions 
77*a1e26a70SApple OSS Distributions #include <machine/types.h>
78*a1e26a70SApple OSS Distributions 
79*a1e26a70SApple OSS Distributions #pragma pack(4)
80*a1e26a70SApple OSS Distributions 
81*a1e26a70SApple OSS Distributions struct user_shmid_ds {
82*a1e26a70SApple OSS Distributions 	struct ipc_perm shm_perm;       /* operation permission structure */
83*a1e26a70SApple OSS Distributions 	user_size_t     shm_segsz;      /* size of segment in bytes */
84*a1e26a70SApple OSS Distributions 	pid_t           shm_lpid;       /* PID of last shared memory op */
85*a1e26a70SApple OSS Distributions 	pid_t           shm_cpid;       /* PID of creator */
86*a1e26a70SApple OSS Distributions 	short           shm_nattch;     /* number of current attaches */
87*a1e26a70SApple OSS Distributions 	user_time_t     shm_atime;      /* time of last shmat() */
88*a1e26a70SApple OSS Distributions 	user_time_t     shm_dtime;      /* time of last shmdt() */
89*a1e26a70SApple OSS Distributions 	user_time_t     shm_ctime;      /* time of last change by shmctl() */
90*a1e26a70SApple OSS Distributions 	user_addr_t     shm_internal;   /* reserved for kernel use */
91*a1e26a70SApple OSS Distributions };
92*a1e26a70SApple OSS Distributions 
93*a1e26a70SApple OSS Distributions struct user32_shmid_ds {
94*a1e26a70SApple OSS Distributions 	struct ipc_perm shm_perm;       /* operation permission structure */
95*a1e26a70SApple OSS Distributions 	uint32_t        shm_segsz;      /* size of segment in bytes */
96*a1e26a70SApple OSS Distributions 	pid_t           shm_lpid;       /* PID of last shared memory op */
97*a1e26a70SApple OSS Distributions 	pid_t           shm_cpid;       /* PID of creator */
98*a1e26a70SApple OSS Distributions 	short           shm_nattch;     /* number of current attaches */
99*a1e26a70SApple OSS Distributions 	uint32_t                shm_atime;      /* time of last shmat() */
100*a1e26a70SApple OSS Distributions 	uint32_t                shm_dtime;      /* time of last shmdt() */
101*a1e26a70SApple OSS Distributions 	uint32_t                shm_ctime;      /* time of last change by shmctl() */
102*a1e26a70SApple OSS Distributions 	user32_addr_t   shm_internal;   /* reserved for kernel use */
103*a1e26a70SApple OSS Distributions };
104*a1e26a70SApple OSS Distributions 
105*a1e26a70SApple OSS Distributions #pragma pack()
106*a1e26a70SApple OSS Distributions 
107*a1e26a70SApple OSS Distributions /*
108*a1e26a70SApple OSS Distributions  * System 5 style catch-all structure for shared memory constants that
109*a1e26a70SApple OSS Distributions  * might be of interest to user programs.  Also part of the ipcs interface.
110*a1e26a70SApple OSS Distributions  * Note: use of user_ssize_t intentional: permits 32 bit ipcs to provide
111*a1e26a70SApple OSS Distributions  * information about 64 bit programs shared segments.
112*a1e26a70SApple OSS Distributions  * Note 2: user_ssize_t is not that useful if it's not 64-bit,
113*a1e26a70SApple OSS Distributions  * so let's use int64_t explicitely...
114*a1e26a70SApple OSS Distributions  */
115*a1e26a70SApple OSS Distributions struct shminfo {
116*a1e26a70SApple OSS Distributions 	int64_t shmmax;         /* max shm segment size (bytes) */
117*a1e26a70SApple OSS Distributions 	int64_t shmmin;         /* min shm segment size (bytes) */
118*a1e26a70SApple OSS Distributions 	int64_t shmmni;         /* max number of shm identifiers */
119*a1e26a70SApple OSS Distributions 	int64_t shmseg;         /* max shm segments per process */
120*a1e26a70SApple OSS Distributions 	int64_t shmall;         /* max amount of shm (pages) */
121*a1e26a70SApple OSS Distributions };
122*a1e26a70SApple OSS Distributions 
123*a1e26a70SApple OSS Distributions #ifdef KERNEL
124*a1e26a70SApple OSS Distributions 
125*a1e26a70SApple OSS Distributions struct label;
126*a1e26a70SApple OSS Distributions 
127*a1e26a70SApple OSS Distributions /*
128*a1e26a70SApple OSS Distributions  * Add a kernel wrapper to the shmid_ds struct so that private info (like the
129*a1e26a70SApple OSS Distributions  * MAC label) can be added to it, without changing the user interface.
130*a1e26a70SApple OSS Distributions  */
131*a1e26a70SApple OSS Distributions struct shmid_kernel {
132*a1e26a70SApple OSS Distributions 	struct user_shmid_ds u;
133*a1e26a70SApple OSS Distributions 	struct label *label;    /* MAC label */
134*a1e26a70SApple OSS Distributions };
135*a1e26a70SApple OSS Distributions 
136*a1e26a70SApple OSS Distributions extern struct shminfo shminfo;
137*a1e26a70SApple OSS Distributions extern struct shmid_kernel *shmsegs;
138*a1e26a70SApple OSS Distributions 
139*a1e26a70SApple OSS Distributions struct proc;
140*a1e26a70SApple OSS Distributions 
141*a1e26a70SApple OSS Distributions __BEGIN_DECLS
142*a1e26a70SApple OSS Distributions 
143*a1e26a70SApple OSS Distributions void    shmexit(struct proc *);
144*a1e26a70SApple OSS Distributions int     shmfork(struct proc *, struct proc *);
145*a1e26a70SApple OSS Distributions __private_extern__ void shmexec(struct proc *);
146*a1e26a70SApple OSS Distributions 
147*a1e26a70SApple OSS Distributions __END_DECLS
148*a1e26a70SApple OSS Distributions 
149*a1e26a70SApple OSS Distributions #endif /* kernel */
150*a1e26a70SApple OSS Distributions 
151*a1e26a70SApple OSS Distributions #endif /* !_SYS_SHM_INTERNALH_ */
152