150477Speter/* $FreeBSD: stable/10/sys/sys/shm.h 328294 2018-01-23 18:22:41Z jhb $ */ 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> 432729Sdfr#include <sys/ipc.h> 44144532Sdas#include <sys/_types.h> 452729Sdfr 462729Sdfr#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ 472729Sdfr#define SHM_RND 020000 /* Round attach address to SHMLBA */ 4815543Sphk#define SHMLBA PAGE_SIZE /* Segment low boundary address multiple */ 492729Sdfr 509444Sjoerg/* "official" access mode definitions; somewhat braindead since you have 519444Sjoerg to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */ 529444Sjoerg#define SHM_R (IPC_R) 539444Sjoerg#define SHM_W (IPC_W) 549444Sjoerg 5585623Smr/* predefine tbd *LOCK shmctl commands */ 5685623Smr#define SHM_LOCK 11 5785623Smr#define SHM_UNLOCK 12 589444Sjoerg 59300060Spfg/* ipcs shmctl commands for Linux compatibility */ 6085623Smr#define SHM_STAT 13 6185623Smr#define SHM_INFO 14 6285623Smr 63144532Sdas#ifndef _PID_T_DECLARED 64144532Sdastypedef __pid_t pid_t; 65144532Sdas#define _PID_T_DECLARED 66144532Sdas#endif 67144532Sdas 68144532Sdas#ifndef _TIME_T_DECLARED 69144532Sdastypedef __time_t time_t; 70144532Sdas#define _TIME_T_DECLARED 71144532Sdas#endif 72144532Sdas 73144532Sdas#ifndef _SIZE_T_DECLARED 74144532Sdastypedef __size_t size_t; 75144532Sdas#define _SIZE_T_DECLARED 76144532Sdas#endif 77144532Sdas 78194910Sjhb#if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \ 79194910Sjhb defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7) 80194910Sjhbstruct shmid_ds_old { 81194910Sjhb struct ipc_perm_old shm_perm; /* operation permission structure */ 822729Sdfr int shm_segsz; /* size of segment in bytes */ 832729Sdfr pid_t shm_lpid; /* process ID of last shared memory op */ 842729Sdfr pid_t shm_cpid; /* process ID of creator */ 852729Sdfr short shm_nattch; /* number of current attaches */ 862729Sdfr time_t shm_atime; /* time of last shmat() */ 872729Sdfr time_t shm_dtime; /* time of last shmdt() */ 882729Sdfr time_t shm_ctime; /* time of last change by shmctl() */ 892729Sdfr void *shm_internal; /* sysv stupidity */ 902729Sdfr}; 91194910Sjhb#endif 922729Sdfr 93194910Sjhbstruct shmid_ds { 94194910Sjhb struct ipc_perm shm_perm; /* operation permission structure */ 95194910Sjhb size_t shm_segsz; /* size of segment in bytes */ 96194910Sjhb pid_t shm_lpid; /* process ID of last shared memory op */ 97194910Sjhb pid_t shm_cpid; /* process ID of creator */ 98194910Sjhb int shm_nattch; /* number of current attaches */ 99194910Sjhb time_t shm_atime; /* time of last shmat() */ 100194910Sjhb time_t shm_dtime; /* time of last shmdt() */ 101194910Sjhb time_t shm_ctime; /* time of last change by shmctl() */ 102194910Sjhb}; 103194910Sjhb 10455205Speter#ifdef _KERNEL 105194910Sjhb#include <vm/vm.h> 1062729Sdfr 1072729Sdfr/* 1082729Sdfr * System 5 style catch-all structure for shared memory constants that 1092729Sdfr * might be of interest to user programs. Do we really want/need this? 1102729Sdfr */ 1112729Sdfrstruct shminfo { 112148782Scsjp u_long shmmax; /* max shared memory segment size (bytes) */ 113148782Scsjp u_long shmmin; /* max shared memory segment size (bytes) */ 114148782Scsjp u_long shmmni; /* max number of shared memory identifiers */ 115148782Scsjp u_long shmseg; /* max shared memory segments per process */ 116148782Scsjp u_long shmall; /* max amount of shared memory (pages) */ 1172729Sdfr}; 118137611Srwatson 119137611Srwatson/* 120137611Srwatson * Add a kernel wrapper to the shmid_ds struct so that private info (like the 121137611Srwatson * MAC label) can be added to it, without changing the user interface. 122137611Srwatson */ 123137611Srwatsonstruct shmid_kernel { 124137611Srwatson struct shmid_ds u; 125194910Sjhb vm_object_t object; 126137816Srwatson struct label *label; /* MAC label */ 127220388Strasz struct ucred *cred; /* creator's credendials */ 128137611Srwatson}; 129137611Srwatson 1302836Sdgextern struct shminfo shminfo; 1312729Sdfr 13285623Smrstruct shm_info { 13385623Smr int used_ids; 13485623Smr unsigned long shm_tot; 13585623Smr unsigned long shm_rss; 13685623Smr unsigned long shm_swp; 13785623Smr unsigned long swap_attempts; 13885623Smr unsigned long swap_successes; 13985623Smr}; 14085623Smr 14183366Sjulianstruct thread; 14232995Sbdestruct proc; 143109205Sdillonstruct vmspace; 14432995Sbde 145109205Sdillonvoid shmexit(struct vmspace *); 14692719Salfredvoid shmfork(struct proc *, struct proc *); 14755205Speter#else /* !_KERNEL */ 1482729Sdfr 1492729Sdfr#include <sys/cdefs.h> 1502729Sdfr 151109831Salfred#ifndef _SIZE_T_DECLARED 152109831Salfredtypedef __size_t size_t; 153109831Salfred#define _SIZE_T_DECLARED 154109831Salfred#endif 155109831Salfred 1562729Sdfr__BEGIN_DECLS 157328294Sjhb#if __BSD_VISIBLE 15892719Salfredint shmsys(int, ...); 159189814Sdas#endif 160109831Salfredvoid *shmat(int, const void *, int); 161109831Salfredint shmget(key_t, size_t, int); 16292719Salfredint shmctl(int, int, struct shmid_ds *); 163109831Salfredint shmdt(const void *); 1642729Sdfr__END_DECLS 1652729Sdfr 16655205Speter#endif /* !_KERNEL */ 1672729Sdfr 1682729Sdfr#endif /* !_SYS_SHM_H_ */ 169