williamr@2: /* $FreeBSD: src/sys/sys/shm.h,v 1.23 2005/04/02 12:33:36 das Exp $ */ williamr@2: /* $NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $ */ williamr@2: williamr@2: /*- williamr@2: * Copyright (c) 1994 Adam Glass williamr@2: *© Portions copyright (c) 2006 Nokia Corporation. All rights reserved. williamr@2: *© Portions copyright (c) 2006 Symbian Software Ltd. All rights reserved. williamr@2: * All rights reserved. williamr@2: * williamr@2: * Redistribution and use in source and binary forms, with or without williamr@2: * modification, are permitted provided that the following conditions williamr@2: * are met: williamr@2: * 1. Redistributions of source code must retain the above copyright williamr@2: * notice, this list of conditions and the following disclaimer. williamr@2: * 2. Redistributions in binary form must reproduce the above copyright williamr@2: * notice, this list of conditions and the following disclaimer in the williamr@2: * documentation and/or other materials provided with the distribution. williamr@2: * 4. The name of the author may not be used to endorse or promote products williamr@2: * derived from this software without specific prior written permission williamr@2: * williamr@2: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR williamr@2: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES williamr@2: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. williamr@2: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, williamr@2: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT williamr@2: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, williamr@2: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY williamr@2: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT williamr@2: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF williamr@2: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. williamr@2: */ williamr@2: williamr@2: /* williamr@2: * As defined+described in "X/Open System Interfaces and Headers" williamr@2: * Issue 4, p. XXX williamr@2: */ williamr@2: williamr@2: #ifndef _SYS_SHM_H_ williamr@2: #define _SYS_SHM_H_ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: #define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ williamr@2: #define SHM_RND 020000 /* Round attach address to SHMLBA */ williamr@2: #define SHMLBA PAGE_SIZE /* Segment low boundary address multiple */ williamr@2: williamr@2: /* "official" access mode definitions; somewhat braindead since you have williamr@2: to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */ williamr@2: #define SHM_R (IPC_R) williamr@2: #define SHM_W (IPC_W) williamr@2: williamr@2: /* predefine tbd *LOCK shmctl commands */ williamr@2: #define SHM_LOCK 11 williamr@2: #define SHM_UNLOCK 12 williamr@2: williamr@2: /* ipcs shmctl commands */ williamr@2: #define SHM_STAT 13 williamr@2: #define SHM_INFO 14 williamr@2: williamr@2: #ifndef _PID_T_DECLARED williamr@2: typedef __pid_t pid_t; williamr@2: #define _PID_T_DECLARED williamr@2: #endif williamr@2: williamr@2: #ifndef _TIME_T_DECLARED williamr@2: typedef __time_t time_t; williamr@2: #define _TIME_T_DECLARED williamr@2: #endif williamr@2: williamr@2: #ifndef _SIZE_T_DECLARED williamr@2: typedef __size_t size_t; williamr@2: #define _SIZE_T_DECLARED williamr@2: #endif williamr@2: williamr@2: struct shmid_ds { williamr@2: struct ipc_perm shm_perm; /* operation permission structure */ williamr@2: int shm_segsz; /* size of segment in bytes */ williamr@2: pid_t shm_lpid; /* process ID of last shared memory op */ williamr@2: pid_t shm_cpid; /* process ID of creator */ williamr@2: short shm_nattch; /* number of current attaches */ williamr@2: time_t shm_atime; /* time of last shmat() */ williamr@2: time_t shm_dtime; /* time of last shmdt() */ williamr@2: time_t shm_ctime; /* time of last change by shmctl() */ williamr@2: void *shm_internal; /* sysv stupidity */ williamr@2: }; williamr@2: williamr@2: #ifdef _KERNEL williamr@2: williamr@2: /* williamr@2: * System 5 style catch-all structure for shared memory constants that williamr@2: * might be of interest to user programs. Do we really want/need this? williamr@2: */ williamr@2: struct shminfo { williamr@2: int shmmax, /* max shared memory segment size (bytes) */ williamr@2: shmmin, /* min shared memory segment size (bytes) */ williamr@2: shmmni, /* max number of shared memory identifiers */ williamr@2: shmseg, /* max shared memory segments per process */ williamr@2: shmall; /* max amount of shared memory (pages) */ williamr@2: }; williamr@2: williamr@2: /* williamr@2: * Add a kernel wrapper to the shmid_ds struct so that private info (like the williamr@2: * MAC label) can be added to it, without changing the user interface. williamr@2: */ williamr@2: struct shmid_kernel { williamr@2: struct shmid_ds u; williamr@2: struct label *label; /* MAC label */ williamr@2: }; williamr@2: williamr@2: extern struct shminfo shminfo; williamr@2: williamr@2: struct shm_info { williamr@2: int used_ids; williamr@2: unsigned long shm_tot; williamr@2: unsigned long shm_rss; williamr@2: unsigned long shm_swp; williamr@2: unsigned long swap_attempts; williamr@2: unsigned long swap_successes; williamr@2: }; williamr@2: williamr@2: struct thread; williamr@2: struct proc; williamr@2: struct vmspace; williamr@2: williamr@2: #else /* !_KERNEL */ williamr@2: williamr@2: #include williamr@2: williamr@2: #ifndef _SIZE_T_DECLARED williamr@2: typedef __size_t size_t; williamr@2: #define _SIZE_T_DECLARED williamr@2: #endif williamr@2: williamr@2: // FUNCTION PROTOTYPES williamr@2: williamr@2: williamr@2: // FORWARD DECLARATIONS williamr@2: williamr@2: williamr@2: // CLASS/STRUCT/FUNCTION DECLARATION williamr@2: __BEGIN_DECLS williamr@2: /* williamr@2: * Get shared memory identifier using the IPC key generated by ftok. williamr@2: */ williamr@2: williamr@2: IMPORT_C int shmget(key_t key, int size, int shmflg); williamr@2: williamr@2: williamr@2: /* williamr@2: * Attaches the shared memory segment associated with the shared memory identifier williamr@2: * specified by shmid to the address space of the calling process. williamr@2: */ williamr@2: williamr@2: IMPORT_C void* shmat(int shmid, const void *shmaddr, int shmflg); williamr@2: williamr@2: williamr@2: /* williamr@2: * Detaches the shared memory segment located at the address specified by shmaddr williamr@2: * from the address space of the calling process. williamr@2: */ williamr@2: williamr@2: IMPORT_C int shmdt(const void *shmaddr); williamr@2: williamr@2: williamr@2: /* williamr@2: * Provides a variety of shared memory control operations as specified by cmd. williamr@2: */ williamr@2: williamr@2: IMPORT_C int shmctl(int shmid, int cmd, struct shmid_ds *buf); williamr@2: williamr@2: williamr@2: __END_DECLS williamr@2: williamr@2: #endif /* !_KERNEL */ williamr@2: williamr@2: #endif // SHM_H williamr@2: williamr@2: // End of File