]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/shm.h
MFV r328323,328324:
[FreeBSD/FreeBSD.git] / sys / sys / shm.h
1 /* $FreeBSD$ */
2 /*      $NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $     */
3
4 /*-
5  * SPDX-License-Identifier: BSD-4-Clause
6  *
7  * Copyright (c) 1994 Adam Glass
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by Adam Glass.
21  * 4. The name of the author may not be used to endorse or promote products
22  *    derived from this software without specific prior written permission
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 /*
37  * As defined+described in "X/Open System Interfaces and Headers"
38  *                         Issue 4, p. XXX
39  */
40
41 #ifndef _SYS_SHM_H_
42 #define _SYS_SHM_H_
43
44 #include <sys/cdefs.h>
45 #include <sys/ipc.h>
46 #include <sys/_types.h>
47
48 #include <machine/param.h>
49
50 #define SHM_RDONLY  010000  /* Attach read-only (else read-write) */
51 #define SHM_RND     020000  /* Round attach address to SHMLBA */
52 #define SHMLBA      PAGE_SIZE /* Segment low boundary address multiple */
53
54 /* "official" access mode definitions; somewhat braindead since you have
55    to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */
56 #define SHM_R       (IPC_R)
57 #define SHM_W       (IPC_W)
58
59 /* predefine tbd *LOCK shmctl commands */
60 #define SHM_LOCK        11
61 #define SHM_UNLOCK      12
62
63 /* ipcs shmctl commands for Linux compatibility */
64 #define SHM_STAT        13
65 #define SHM_INFO        14
66
67 #ifndef _PID_T_DECLARED
68 typedef __pid_t         pid_t;
69 #define _PID_T_DECLARED
70 #endif
71
72 #ifndef _TIME_T_DECLARED
73 typedef __time_t        time_t;
74 #define _TIME_T_DECLARED
75 #endif
76
77 #ifndef _SIZE_T_DECLARED
78 typedef __size_t        size_t;
79 #define _SIZE_T_DECLARED
80 #endif
81
82 #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
83     defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
84 struct shmid_ds_old {
85         struct ipc_perm_old shm_perm;   /* operation permission structure */
86         int             shm_segsz;      /* size of segment in bytes */
87         pid_t           shm_lpid;   /* process ID of last shared memory op */
88         pid_t           shm_cpid;       /* process ID of creator */
89         short           shm_nattch;     /* number of current attaches */
90         time_t          shm_atime;      /* time of last shmat() */
91         time_t          shm_dtime;      /* time of last shmdt() */
92         time_t          shm_ctime;      /* time of last change by shmctl() */
93         void           *shm_internal;   /* sysv stupidity */
94 };
95 #endif
96
97 typedef unsigned int shmatt_t;
98
99 struct shmid_ds {
100         struct ipc_perm shm_perm;       /* operation permission structure */
101         size_t          shm_segsz;      /* size of segment in bytes */
102         pid_t           shm_lpid;   /* process ID of last shared memory op */
103         pid_t           shm_cpid;       /* process ID of creator */
104         shmatt_t        shm_nattch;     /* number of current attaches */
105         time_t          shm_atime;      /* time of last shmat() */
106         time_t          shm_dtime;      /* time of last shmdt() */
107         time_t          shm_ctime;      /* time of last change by shmctl() */
108 };
109
110 #ifdef _KERNEL
111 #include <vm/vm.h>
112
113 /*
114  * System 5 style catch-all structure for shared memory constants that
115  * might be of interest to user programs.  Do we really want/need this?
116  */
117 struct shminfo {
118         u_long  shmmax;         /* max shared memory segment size (bytes) */
119         u_long  shmmin;         /* max shared memory segment size (bytes) */
120         u_long  shmmni;         /* max number of shared memory identifiers */
121         u_long  shmseg;         /* max shared memory segments per process */
122         u_long  shmall;         /* max amount of shared memory (pages) */
123 };
124
125 /* 
126  * Add a kernel wrapper to the shmid_ds struct so that private info (like the
127  * MAC label) can be added to it, without changing the user interface.
128  */
129 struct shmid_kernel {
130         struct shmid_ds u;
131         vm_object_t object;
132         struct label *label;    /* MAC label */
133         struct ucred *cred;     /* creator's credendials */
134 };
135
136 extern struct shminfo   shminfo;
137
138 struct shm_info {
139         int used_ids;
140         unsigned long shm_tot;
141         unsigned long shm_rss;
142         unsigned long shm_swp;
143         unsigned long swap_attempts;
144         unsigned long swap_successes;
145 };
146
147 struct thread;
148 struct proc;
149 struct vmspace;
150
151 void    shmexit(struct vmspace *);
152 void    shmfork(struct proc *, struct proc *);
153 #endif /* _KERNEL */
154
155 #if !defined(_KERNEL) || defined(_WANT_SHM_PROTOTYPES)
156 #include <sys/cdefs.h>
157
158 #ifndef _SIZE_T_DECLARED
159 typedef __size_t        size_t;
160 #define _SIZE_T_DECLARED
161 #endif
162
163 __BEGIN_DECLS
164 #if __BSD_VISIBLE
165 int shmsys(int, ...);
166 #endif
167 void *shmat(int, const void *, int);
168 int shmget(key_t, size_t, int);
169 int shmctl(int, int, struct shmid_ds *);
170 int shmdt(const void *);
171 __END_DECLS
172
173 #endif /* _KERNEL || _WANT_SHM_PROTOTYPES */
174
175 #endif /* !_SYS_SHM_H_ */