1/* $OpenBSD: shm.h,v 1.30 2021/03/10 10:21:47 jsg Exp $ */ 2/* $NetBSD: shm.h,v 1.20 1996/04/09 20:55:35 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#ifndef _SYS_IPC_H_ 43#include <sys/ipc.h> 44#endif 45 46#if __BSD_VISIBLE 47 48/* shm-specific sysctl variables corresponding to members of struct shminfo */ 49#define KERN_SHMINFO_SHMMAX 1 /* int: max shm segment size (bytes) */ 50#define KERN_SHMINFO_SHMMIN 2 /* int: min shm segment size (bytes) */ 51#define KERN_SHMINFO_SHMMNI 3 /* int: max number of shm identifiers */ 52#define KERN_SHMINFO_SHMSEG 4 /* int: max shm segments per process */ 53#define KERN_SHMINFO_SHMALL 5 /* int: max amount of shm (pages) */ 54#define KERN_SHMINFO_MAXID 6 /* number of valid shared memory ids */ 55 56#define CTL_KERN_SHMINFO_NAMES { \ 57 { 0, 0 }, \ 58 { "shmmax", CTLTYPE_INT }, \ 59 { "shmmin", CTLTYPE_INT }, \ 60 { "shmmni", CTLTYPE_INT }, \ 61 { "shmseg", CTLTYPE_INT }, \ 62 { "shmall", CTLTYPE_INT }, \ 63} 64 65/* 66 * Old (deprecated) access mode definitions--do not use. 67 * Provided for compatibility with old code only. 68 */ 69#define SHM_R IPC_R 70#define SHM_W IPC_W 71 72#endif /* __BSD_VISIBLE */ 73 74/* 75 * Shared memory operation flags for shmat(2). 76 */ 77#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ 78#define SHM_RND 020000 /* Round attach address to SHMLBA */ 79 80/* 81 * Shared memory specific control commands for shmctl(). 82 * We accept but ignore these (XXX). 83 */ 84#define SHM_LOCK 3 /* Lock segment in memory. */ 85#define SHM_UNLOCK 4 /* Unlock a segment locked by SHM_LOCK. */ 86 87/* 88 * Segment low boundary address multiple 89 */ 90#define SHMLBA (1U << _MAX_PAGE_SHIFT) 91 92typedef short shmatt_t; 93 94struct shmid_ds { 95 struct ipc_perm shm_perm; /* operation permission structure */ 96 int shm_segsz; /* size of segment in bytes */ 97 pid_t shm_lpid; /* process ID of last shm op */ 98 pid_t shm_cpid; /* process ID of creator */ 99 shmatt_t shm_nattch; /* number of current attaches */ 100 time_t shm_atime; /* time of last shmat() */ 101 long __shm_atimensec; 102 time_t shm_dtime; /* time of last shmdt() */ 103 long __shm_dtimensec; 104 time_t shm_ctime; /* time of last change by shmctl() */ 105 long __shm_ctimensec; 106 void *shm_internal; /* implementation specific data */ 107}; 108 109#if __BSD_VISIBLE 110/* 111 * System V style catch-all structure for shared memory constants that 112 * might be of interest to user programs. Do we really want/need this? 113 */ 114struct shminfo { 115 int shmmax; /* max shared memory segment size (bytes) */ 116 int shmmin; /* min shared memory segment size (bytes) */ 117 int shmmni; /* max number of shared memory identifiers */ 118 int shmseg; /* max shared memory segments per process */ 119 int shmall; /* max amount of shared memory (pages) */ 120}; 121 122struct shm_sysctl_info { 123 struct shminfo shminfo; 124 struct shmid_ds shmids[1]; 125}; 126#endif /* __BSD_VISIBLE */ 127 128#ifdef _KERNEL 129extern struct shminfo shminfo; 130extern struct shmid_ds **shmsegs; 131 132struct proc; 133struct vmspace; 134 135void shminit(void); 136void shmfork(struct vmspace *, struct vmspace *); 137void shmexit(struct vmspace *); 138int sysctl_sysvshm(int *, u_int, void *, size_t *, void *, size_t); 139 140#else /* !_KERNEL */ 141 142__BEGIN_DECLS 143void *shmat(int, const void *, int); 144int shmctl(int, int, struct shmid_ds *); 145int shmdt(const void *); 146int shmget(key_t, size_t, int); 147__END_DECLS 148 149#endif /* !_KERNEL */ 150 151#endif /* !_SYS_SHM_H_ */ 152