shm.h revision 189814
1/* $FreeBSD: head/sys/sys/shm.h 189814 2009-03-14 19:06:52Z das $ */ 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#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ 47#define SHM_RND 020000 /* Round attach address to SHMLBA */ 48#define SHMLBA PAGE_SIZE /* Segment low boundary address multiple */ 49 50/* "official" access mode definitions; somewhat braindead since you have 51 to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */ 52#define SHM_R (IPC_R) 53#define SHM_W (IPC_W) 54 55/* predefine tbd *LOCK shmctl commands */ 56#define SHM_LOCK 11 57#define SHM_UNLOCK 12 58 59/* ipcs shmctl commands for Linux compatability */ 60#define SHM_STAT 13 61#define SHM_INFO 14 62 63#ifndef _PID_T_DECLARED 64typedef __pid_t pid_t; 65#define _PID_T_DECLARED 66#endif 67 68#ifndef _TIME_T_DECLARED 69typedef __time_t time_t; 70#define _TIME_T_DECLARED 71#endif 72 73#ifndef _SIZE_T_DECLARED 74typedef __size_t size_t; 75#define _SIZE_T_DECLARED 76#endif 77 78struct shmid_ds { 79 struct ipc_perm shm_perm; /* operation permission structure */ 80 int shm_segsz; /* size of segment in bytes */ 81 pid_t shm_lpid; /* process ID of last shared memory op */ 82 pid_t shm_cpid; /* process ID of creator */ 83 short shm_nattch; /* number of current attaches */ 84 time_t shm_atime; /* time of last shmat() */ 85 time_t shm_dtime; /* time of last shmdt() */ 86 time_t shm_ctime; /* time of last change by shmctl() */ 87 void *shm_internal; /* sysv stupidity */ 88}; 89 90#ifdef _KERNEL 91 92/* 93 * System 5 style catch-all structure for shared memory constants that 94 * might be of interest to user programs. Do we really want/need this? 95 */ 96struct shminfo { 97 u_long shmmax; /* max shared memory segment size (bytes) */ 98 u_long shmmin; /* max shared memory segment size (bytes) */ 99 u_long shmmni; /* max number of shared memory identifiers */ 100 u_long shmseg; /* max shared memory segments per process */ 101 u_long shmall; /* max amount of shared memory (pages) */ 102}; 103 104/* 105 * Add a kernel wrapper to the shmid_ds struct so that private info (like the 106 * MAC label) can be added to it, without changing the user interface. 107 */ 108struct shmid_kernel { 109 struct shmid_ds u; 110 struct label *label; /* MAC label */ 111 size_t shm_bsegsz; 112}; 113 114extern struct shminfo shminfo; 115 116struct shm_info { 117 int used_ids; 118 unsigned long shm_tot; 119 unsigned long shm_rss; 120 unsigned long shm_swp; 121 unsigned long swap_attempts; 122 unsigned long swap_successes; 123}; 124 125struct thread; 126struct proc; 127struct vmspace; 128 129void shmexit(struct vmspace *); 130void shmfork(struct proc *, struct proc *); 131#else /* !_KERNEL */ 132 133#include <sys/cdefs.h> 134 135#ifndef _SIZE_T_DECLARED 136typedef __size_t size_t; 137#define _SIZE_T_DECLARED 138#endif 139 140__BEGIN_DECLS 141#ifdef __BSD_VISIBLE 142int shmsys(int, ...); 143#endif 144void *shmat(int, const void *, int); 145int shmget(key_t, size_t, int); 146int shmctl(int, int, struct shmid_ds *); 147int shmdt(const void *); 148__END_DECLS 149 150#endif /* !_KERNEL */ 151 152#endif /* !_SYS_SHM_H_ */ 153