150477Speter/* $FreeBSD: stable/11/sys/sys/shm.h 347995 2019-05-20 16:31:45Z kib $ */ 22729Sdfr/* $NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $ */ 32729Sdfr 4139825Simp/*- 52729Sdfr * Copyright (c) 1994 Adam Glass 62729Sdfr * All rights reserved. 72729Sdfr * 82729Sdfr * Redistribution and use in source and binary forms, with or without 92729Sdfr * modification, are permitted provided that the following conditions 102729Sdfr * are met: 112729Sdfr * 1. Redistributions of source code must retain the above copyright 122729Sdfr * notice, this list of conditions and the following disclaimer. 132729Sdfr * 2. Redistributions in binary form must reproduce the above copyright 142729Sdfr * notice, this list of conditions and the following disclaimer in the 152729Sdfr * documentation and/or other materials provided with the distribution. 162729Sdfr * 3. All advertising materials mentioning features or use of this software 172729Sdfr * must display the following acknowledgement: 182729Sdfr * This product includes software developed by Adam Glass. 192729Sdfr * 4. The name of the author may not be used to endorse or promote products 202729Sdfr * derived from this software without specific prior written permission 212729Sdfr * 222729Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 232729Sdfr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 242729Sdfr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 252729Sdfr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 262729Sdfr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 272729Sdfr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 282729Sdfr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 292729Sdfr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 302729Sdfr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 312729Sdfr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 322729Sdfr */ 332729Sdfr 342729Sdfr/* 352729Sdfr * As defined+described in "X/Open System Interfaces and Headers" 362729Sdfr * Issue 4, p. XXX 372729Sdfr */ 382729Sdfr 392729Sdfr#ifndef _SYS_SHM_H_ 402729Sdfr#define _SYS_SHM_H_ 412729Sdfr 42144532Sdas#include <sys/cdefs.h> 43347995Skib#ifdef _WANT_SYSVSHM_INTERNALS 44347995Skib#define _WANT_SYSVIPC_INTERNALS 45347995Skib#endif 462729Sdfr#include <sys/ipc.h> 47144532Sdas#include <sys/_types.h> 482729Sdfr 49301074Sed#include <machine/param.h> 50301074Sed 512729Sdfr#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ 522729Sdfr#define SHM_RND 020000 /* Round attach address to SHMLBA */ 53343426Skib#define SHM_REMAP 030000 /* Unmap before mapping */ 5415543Sphk#define SHMLBA PAGE_SIZE /* Segment low boundary address multiple */ 552729Sdfr 569444Sjoerg/* "official" access mode definitions; somewhat braindead since you have 579444Sjoerg to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */ 589444Sjoerg#define SHM_R (IPC_R) 599444Sjoerg#define SHM_W (IPC_W) 609444Sjoerg 6185623Smr/* predefine tbd *LOCK shmctl commands */ 6285623Smr#define SHM_LOCK 11 6385623Smr#define SHM_UNLOCK 12 649444Sjoerg 65298981Spfg/* ipcs shmctl commands for Linux compatibility */ 6685623Smr#define SHM_STAT 13 6785623Smr#define SHM_INFO 14 6885623Smr 69144532Sdas#ifndef _PID_T_DECLARED 70144532Sdastypedef __pid_t pid_t; 71144532Sdas#define _PID_T_DECLARED 72144532Sdas#endif 73144532Sdas 74144532Sdas#ifndef _TIME_T_DECLARED 75144532Sdastypedef __time_t time_t; 76144532Sdas#define _TIME_T_DECLARED 77144532Sdas#endif 78144532Sdas 79144532Sdas#ifndef _SIZE_T_DECLARED 80144532Sdastypedef __size_t size_t; 81144532Sdas#define _SIZE_T_DECLARED 82144532Sdas#endif 83144532Sdas 84194910Sjhb#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ 85194910Sjhb defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) 86194910Sjhbstruct shmid_ds_old { 87194910Sjhb struct ipc_perm_old shm_perm; /* operation permission structure */ 882729Sdfr int shm_segsz; /* size of segment in bytes */ 892729Sdfr pid_t shm_lpid; /* process ID of last shared memory op */ 902729Sdfr pid_t shm_cpid; /* process ID of creator */ 912729Sdfr short shm_nattch; /* number of current attaches */ 922729Sdfr time_t shm_atime; /* time of last shmat() */ 932729Sdfr time_t shm_dtime; /* time of last shmdt() */ 942729Sdfr time_t shm_ctime; /* time of last change by shmctl() */ 952729Sdfr void *shm_internal; /* sysv stupidity */ 962729Sdfr}; 97194910Sjhb#endif 982729Sdfr 99194910Sjhbstruct shmid_ds { 100194910Sjhb struct ipc_perm shm_perm; /* operation permission structure */ 101194910Sjhb size_t shm_segsz; /* size of segment in bytes */ 102194910Sjhb pid_t shm_lpid; /* process ID of last shared memory op */ 103194910Sjhb pid_t shm_cpid; /* process ID of creator */ 104194910Sjhb int shm_nattch; /* number of current attaches */ 105194910Sjhb time_t shm_atime; /* time of last shmat() */ 106194910Sjhb time_t shm_dtime; /* time of last shmdt() */ 107194910Sjhb time_t shm_ctime; /* time of last change by shmctl() */ 108194910Sjhb}; 109194910Sjhb 110347995Skib#if defined(_KERNEL) || defined(_WANT_SYSVSHM_INTERNALS) 1112729Sdfr/* 1122729Sdfr * System 5 style catch-all structure for shared memory constants that 1132729Sdfr * might be of interest to user programs. Do we really want/need this? 1142729Sdfr */ 1152729Sdfrstruct shminfo { 116148782Scsjp u_long shmmax; /* max shared memory segment size (bytes) */ 117148782Scsjp u_long shmmin; /* max shared memory segment size (bytes) */ 118148782Scsjp u_long shmmni; /* max number of shared memory identifiers */ 119148782Scsjp u_long shmseg; /* max shared memory segments per process */ 120148782Scsjp u_long shmall; /* max amount of shared memory (pages) */ 1212729Sdfr}; 122137611Srwatson 123347995Skibstruct vm_object; 124347995Skib 125137611Srwatson/* 126137611Srwatson * Add a kernel wrapper to the shmid_ds struct so that private info (like the 127137611Srwatson * MAC label) can be added to it, without changing the user interface. 128137611Srwatson */ 129137611Srwatsonstruct shmid_kernel { 130137611Srwatson struct shmid_ds u; 131347995Skib struct vm_object *object; 132137816Srwatson struct label *label; /* MAC label */ 133220388Strasz struct ucred *cred; /* creator's credendials */ 134137611Srwatson}; 135347995Skib#endif 136137611Srwatson 13785623Smrstruct shm_info { 13885623Smr int used_ids; 13985623Smr unsigned long shm_tot; 14085623Smr unsigned long shm_rss; 14185623Smr unsigned long shm_swp; 14285623Smr unsigned long swap_attempts; 14385623Smr unsigned long swap_successes; 14485623Smr}; 14585623Smr 146347995Skib#ifdef _KERNEL 14732995Sbdestruct proc; 148109205Sdillonstruct vmspace; 14932995Sbde 150347995Skibextern struct shminfo shminfo; 151347995Skib 152109205Sdillonvoid shmexit(struct vmspace *); 15392719Salfredvoid shmfork(struct proc *, struct proc *); 1542729Sdfr 155347995Skib#else /* !_KERNEL */ 156347995Skib 1572729Sdfr#include <sys/cdefs.h> 1582729Sdfr 159109831Salfred#ifndef _SIZE_T_DECLARED 160109831Salfredtypedef __size_t size_t; 161109831Salfred#define _SIZE_T_DECLARED 162109831Salfred#endif 163109831Salfred 1642729Sdfr__BEGIN_DECLS 165328294Sjhb#if __BSD_VISIBLE 16692719Salfredint shmsys(int, ...); 167189814Sdas#endif 168109831Salfredvoid *shmat(int, const void *, int); 169109831Salfredint shmget(key_t, size_t, int); 17092719Salfredint shmctl(int, int, struct shmid_ds *); 171109831Salfredint shmdt(const void *); 1722729Sdfr__END_DECLS 1732729Sdfr 174347995Skib#endif /* _KERNEL */ 1752729Sdfr 1762729Sdfr#endif /* !_SYS_SHM_H_ */ 177