1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1984 AT&T */ 28 /* All Rights Reserved */ 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * IPC Shared Memory Facility. 34 */ 35 36 #ifndef _sys_shm_h 37 #define _sys_shm_h 38 39 #include <sys/param.h> 40 /* #include <machine/mmu.h> */ 41 42 /* 43 * Shared Memory Operation Flags. 44 */ 45 46 #define SHM_RDONLY 010000 /* attach read-only (else read-write) */ 47 #define SHM_RND 020000 /* round attach address to SHMLBA */ 48 49 /* 50 * Shmctl Command Definitions. 51 */ 52 53 #define SHM_LOCK 3 /* Lock segment in core */ 54 #define SHM_UNLOCK 4 /* Unlock segment */ 55 56 /* 57 * Implementation Constants. 58 */ 59 #define SHMLBA PAGESIZE /* segment low boundary address multiple */ 60 /* (SHMLBA must be a power of 2) */ 61 62 /* 63 * Structure Definitions. 64 */ 65 66 /* 67 * There is a shared mem id data structure for each segment in the system. 68 */ 69 70 struct shmid_ds { 71 struct ipc_perm shm_perm; /* operation permission struct */ 72 uint shm_segsz; /* size of segment in bytes */ 73 ushort shm_lpid; /* pid of last shmop */ 74 ushort shm_cpid; /* pid of creator */ 75 ushort shm_nattch; /* number of current attaches */ 76 time_t shm_atime; /* last shmat time */ 77 time_t shm_dtime; /* last shmdt time */ 78 time_t shm_ctime; /* last change time */ 79 struct anon_map *shm_amp; /* segment anon_map pointer */ 80 }; 81 82 83 84 #ifdef KERNEL 85 /* 86 * Permission Definitions. 87 */ 88 89 #define SHM_W 0200 /* write permission */ 90 #define SHM_R 0400 /* read permission */ 91 92 /* 93 * ipc_perm Mode Definitions. 94 */ 95 96 #define SHM_INIT 001000 /* segment not yet initialized */ 97 #define SHM_LOCKED 004000 /* shmid locked */ 98 #define SHM_LOCKWAIT 010000 /* shmid wanted */ 99 100 #define PSHM (PZERO + 1) /* sleep priority */ 101 102 /* define resource locking macros */ 103 #define SHMLOCK(sp) { \ 104 while ((sp)->shm_perm.mode & SHM_LOCKED) { \ 105 (sp)->shm_perm.mode |= SHM_LOCKWAIT; \ 106 (void) sleep((caddr_t)(sp), PSHM); \ 107 } \ 108 (sp)->shm_perm.mode |= SHM_LOCKED; \ 109 } 110 111 #define SHMUNLOCK(sp) { \ 112 (sp)->shm_perm.mode &= ~SHM_LOCKED; \ 113 if ((sp)->shm_perm.mode & SHM_LOCKWAIT) { \ 114 (sp)->shm_perm.mode &= ~SHM_LOCKWAIT; \ 115 curpri = PSHM; \ 116 wakeup((caddr_t)(sp)); \ 117 } \ 118 } 119 120 /* 121 * Shared Memory information structure 122 */ 123 struct shminfo { 124 int shmmax, /* max shared memory segment size */ 125 shmmin, /* min shared memory segment size */ 126 shmmni, /* # of shared memory identifiers */ 127 shmseg, /* (obsolete) */ 128 shmall; /* (obsolete) */ 129 }; 130 struct shminfo shminfo; /* configuration parameters */ 131 132 /* 133 * Configuration Parameters 134 * These parameters are tuned by editing the system configuration file. 135 * The following lines establish the default values. 136 */ 137 #ifndef SHMSIZE 138 #define SHMSIZE 1024 /* maximum shared memory segment size (in Kbytes) */ 139 #endif 140 #ifndef SHMMNI 141 #define SHMMNI 100 /* # of shared memory identifiers */ 142 #endif 143 144 /* The following parameters are assumed not to require tuning */ 145 #define SHMMIN 1 /* min shared memory segment size */ 146 #define SHMMAX (SHMSIZE * 1024) /* max shared memory segment size */ 147 148 149 /* 150 * Structures allocated in machdep.c 151 */ 152 struct shmid_ds *shmem; /* shared memory id pool */ 153 154 #endif KERNEL 155 156 #endif /*!_sys_shm_h*/ 157