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