/*	@(#)shm.h	13.4 (RC International) 91/10/09	*/

#ifndef _SHM_H
#define _SHM_H

/*	IPC Shared Memory Facility	*/

#include <rc/param.h>

/*	Implementation Constants	*/

#define SHMLBA	CLBYTES		/* segment low boundary address multiple */


/*	Permission Definitions	*/

#define	SHM_R	0400		/* read permission */
#define	SHM_W	0200		/* write permission */

/*	ipc_perm Mode Definitions	*/

#define	SHM_SEMA	04000	/* Special semaphore memory requested */

/*	Message Operation Flags	*/

#define	SHM_RDONLY	010000	/* attach read-only (else read-write) */
#define	SHM_RND		020000	/* round attach address to SHMBLA */

/*
 * Structure Definitions
 */


/*
 * The shared memory id data structure-
 * There is on of these for every possible shared memory segment
 * in the system.
 */
	
struct	shmid_ds	/* shared memory data structure */
{
    struct ipc_perm shm_perm;		/* operation permission struct
					 * MUST BE FIRST -- GROT XXXX */
    pid_t		shm_cpid;	/* creator pid */
    pid_t		shm_lpid;	/* pid of last operation */
    time_t	shm_atime;	/* last attach time */
    time_t	shm_dtime;	/* last detach time */
    time_t	shm_ctime;	/* last change time */
				/* Times measured in secs since */
				/* 00:00:00 GMT, Jan. 1, 1970 */
    int		shm_segsz;	/* size of segment (bytes) */
    u_short	shm_nattch;	/* number of attaches */
};


/*	Define shared memory limits structure	*/

struct shminfo
{
    int	shmmax;	/* max shared memory segment size */
    int	shmmin;	/* min shared memory segment size */
    int	shmmni;	/* # of shared memory identifiers */
    int	shmseg;	/* max attached shared memory segments per process */
		/* NOTE: must not exceed U_MAXSHM in user.h */
    int	shmbrk;	/* gap (in clicks) used between data and shared memory */
};

/*	Shared memory accounting structure	*/

struct	shmstat
{
    int	shmsegtot;	/* total # shm segments in use */
    int	shmswpo;	/* # of shm segment swap outs */
    int	shmswpi;	/* # of shm segment swap ins */
};

/*
 * The following manifest constants define the parameters
 * for the ipc shared memory subsystem
 */

#define	SHMMAX	1024*NBPG	/* max shared memory seg size (bytes) =4Mb */
#define	SHMMIN	4		/* min shared memory seg size (bytes) */
#define	SHMMNI	30		/* max # shared memory segs system wide */
#define	SHMSEG	16		/* max # attached shared memory segs/proc */
				/* SHMSEG MUST NOT EXCEED U_MAXSHM in user.h */
#define	SHMBRK	8192*CLSIZE	/* default # pages between end of ds
				 * and start of shm region.
				 */
#define SHMSTK	NPTEPG*CLSIZE	/* # pages between end of shm region and 
				 * top of ss, to prevent sharing of page
				 * table pages between stack and shm region.
				 */


#if defined(__STDC__)

extern int shmctl(int, int, ...);
extern int shmget(key_t, int, int);
extern char *shmat(int, void *, int);
extern int shmdt(void *);

#else /* Not __STDC__ */

extern int shmctl(), shmdt(), shmget();
extern char *shmat();

#endif /* __STDC__ */


#endif /* _SHM_H */
