00001 /* $FreeBSD: src/sys/sys/shm.h,v 1.23 2005/04/02 12:33:36 das Exp $ */ 00002 /* $NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $ */ 00003 00004 /*- 00005 * Copyright (c) 1994 Adam Glass 00006 *© Portions copyright (c) 2006 Nokia Corporation. All rights reserved. 00007 *© Portions copyright (c) 2006 Symbian Software Ltd. All rights reserved. 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 1. Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 3. All advertising materials mentioning features or use of this software 00019 * must display the following acknowledgement: 00020 * This product includes software developed by Adam Glass. 00021 * 4. The name of the author may not be used to endorse or promote products 00022 * derived from this software without specific prior written permission 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00025 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00026 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00027 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00029 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00031 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00033 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 00036 /* 00037 * As defined+described in "X/Open System Interfaces and Headers" 00038 * Issue 4, p. XXX 00039 */ 00040 00041 #ifndef _SYS_SHM_H_ 00042 #define _SYS_SHM_H_ 00043 00044 #include <sys/cdefs.h> 00045 #include <sys/ipc.h> 00046 #include <sys/_types.h> 00047 00048 #define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ 00049 #define SHM_RND 020000 /* Round attach address to SHMLBA */ 00050 #define SHMLBA PAGE_SIZE /* Segment low boundary address multiple */ 00051 00052 /* "official" access mode definitions; somewhat braindead since you have 00053 to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */ 00054 #define SHM_R (IPC_R) 00055 #define SHM_W (IPC_W) 00056 00057 /* predefine tbd *LOCK shmctl commands */ 00058 #define SHM_LOCK 11 00059 #define SHM_UNLOCK 12 00060 00061 /* ipcs shmctl commands */ 00062 #define SHM_STAT 13 00063 #define SHM_INFO 14 00064 00065 #ifndef _PID_T_DECLARED 00066 typedef __pid_t pid_t; 00067 #define _PID_T_DECLARED 00068 #endif 00069 00070 #ifndef _TIME_T_DECLARED 00071 typedef __time_t time_t; 00072 #define _TIME_T_DECLARED 00073 #endif 00074 00075 #ifndef _SIZE_T_DECLARED 00076 typedef __size_t size_t; 00077 #define _SIZE_T_DECLARED 00078 #endif 00079 00080 struct shmid_ds { 00081 struct ipc_perm shm_perm; /* operation permission structure */ 00082 int shm_segsz; /* size of segment in bytes */ 00083 pid_t shm_lpid; /* process ID of last shared memory op */ 00084 pid_t shm_cpid; /* process ID of creator */ 00085 short shm_nattch; /* number of current attaches */ 00086 time_t shm_atime; /* time of last shmat() */ 00087 time_t shm_dtime; /* time of last shmdt() */ 00088 time_t shm_ctime; /* time of last change by shmctl() */ 00089 void *shm_internal; /* sysv stupidity */ 00090 }; 00091 00092 #ifdef _KERNEL 00093 00094 /* 00095 * System 5 style catch-all structure for shared memory constants that 00096 * might be of interest to user programs. Do we really want/need this? 00097 */ 00098 struct shminfo { 00099 int shmmax, /* max shared memory segment size (bytes) */ 00100 shmmin, /* min shared memory segment size (bytes) */ 00101 shmmni, /* max number of shared memory identifiers */ 00102 shmseg, /* max shared memory segments per process */ 00103 shmall; /* max amount of shared memory (pages) */ 00104 }; 00105 00106 /* 00107 * Add a kernel wrapper to the shmid_ds struct so that private info (like the 00108 * MAC label) can be added to it, without changing the user interface. 00109 */ 00110 struct shmid_kernel { 00111 struct shmid_ds u; 00112 struct label *label; /* MAC label */ 00113 }; 00114 00115 extern struct shminfo shminfo; 00116 00117 struct shm_info { 00118 int used_ids; 00119 unsigned long shm_tot; 00120 unsigned long shm_rss; 00121 unsigned long shm_swp; 00122 unsigned long swap_attempts; 00123 unsigned long swap_successes; 00124 }; 00125 00126 struct thread; 00127 struct proc; 00128 struct vmspace; 00129 00130 #else /* !_KERNEL */ 00131 00132 #include <sys/cdefs.h> 00133 00134 #ifndef _SIZE_T_DECLARED 00135 typedef __size_t size_t; 00136 #define _SIZE_T_DECLARED 00137 #endif 00138 00139 // FUNCTION PROTOTYPES 00140 00141 00142 // FORWARD DECLARATIONS 00143 00144 00145 // CLASS/STRUCT/FUNCTION DECLARATION 00146 __BEGIN_DECLS 00147 /* 00148 * Get shared memory identifier using the IPC key generated by ftok. 00149 */ 00150 00151 IMPORT_C int shmget(key_t key, int size, int shmflg); 00152 00153 00154 /* 00155 * Attaches the shared memory segment associated with the shared memory identifier 00156 * specified by shmid to the address space of the calling process. 00157 */ 00158 00159 IMPORT_C void* shmat(int shmid, const void *shmaddr, int shmflg); 00160 00161 00162 /* 00163 * Detaches the shared memory segment located at the address specified by shmaddr 00164 * from the address space of the calling process. 00165 */ 00166 00167 IMPORT_C int shmdt(const void *shmaddr); 00168 00169 00170 /* 00171 * Provides a variety of shared memory control operations as specified by cmd. 00172 */ 00173 00174 IMPORT_C int shmctl(int shmid, int cmd, struct shmid_ds *buf); 00175 00176 00177 __END_DECLS 00178 00179 #endif /* !_KERNEL */ 00180 00181 // SHM_H 00182 #endif 00183 00184 // End of File