/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident	"$Header: shm.h 1.8 89/10/10 $"

#ifndef	_SYS_SHM_H_

/* $Log:	shm.h,v $
*/


/*
**	IPC Shared Memory Facility.
*/

/*
**	Implementation Constants.
*/

#define	SHMLBA	ctob(1)	/* segment low boundary address multiple */
			/* (SHMLBA must be a power of 2) */

/*
**	Permission Definitions.
*/

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

/*
**	ipc_perm Mode Definitions.
*/

#define	SHM_INIT	01000	/* grow segment on next attach */
#define	SHM_DEST	02000	/* destroy segment when # attached = 0 */

/*
**	Message Operation Flags.
*/

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

/*
**	Structure Definitions.
*/

/*
**	There is a shared mem id data structure for each segment in the system.
*/

#ifdef INKERNEL
struct shmid_ds {
	struct lshmid_ds {
		struct ipc_perm	lshm_perm;	/* operation permission struct*/
		int		lshm_segsz;	/* size of segment in bytes */
		/*
		 * lshm_perm.mode and lshm_segsz are mutexed by shm_sema,
		 * all others by shm_vnode.v_nodemutex
		 */
		int		*lshm_reg;	/* pad */
		char		pad[4];		/* pad */
		pid_t		lshm_lpid;	/* pid of last shmop */
		pid_t		lshm_cpid;	/* pid of creator */
		ushort		lshm_nattch;	/* used only for shminfo */
		ushort		lshm_cnattch;	/* used only for shminfo */
		time_t		lshm_atime;	/* last shmat time */
		time_t		lshm_dtime;	/* last shmdt time */
		time_t		lshm_ctime;	/* last change time */
	}	shmid_ic;
	struct vnode	shm_vnode;		/* associated vnode */
	struct dmap	shm_dmap;		/* swap space for segment */
	unsigned int	shm_blocks;		/* blocks "allocated" above */
	ulong		shm_handle;		/* handle to mmreg structure */
	unsigned int	shm_refcnt;		/* # attached to this shmid */
};

#define	shm_perm	shmid_ic.lshm_perm
#define	shm_segsz	shmid_ic.lshm_segsz
#define	shm_lpid	shmid_ic.lshm_lpid
#define	shm_cpid	shmid_ic.lshm_cpid
#define	shm_nattch	shmid_ic.lshm_nattch
#define	shm_cnattch	shmid_ic.lshm_cnattch
#define	shm_atime	shmid_ic.lshm_atime
#define	shm_dtime	shmid_ic.lshm_dtime
#define	shm_ctime	shmid_ic.lshm_ctime

#define	MTOV(SP)	((struct vnode *)&(SP)->shm_vnode)
#define	VTOM(VP)	((struct shmid_ds *)(VP)->v_data)

#else

struct shmid_ds {
	struct ipc_perm	shm_perm;	/* operation permission struct */
	int		shm_segsz;	/* size of segment in bytes */
	int		*shm_reg;	/* pad */
	char		pad[4];		/* pad */
	pid_t		shm_lpid;	/* pid of last shmop */
	pid_t		shm_cpid;	/* pid of creator */
	ushort		shm_nattch;	/* used only for shminfo */
	ushort		shm_cnattch;	/* used only for shminfo */
	time_t		shm_atime;	/* last shmat time */
	time_t		shm_dtime;	/* last shmdt time */
	time_t		shm_ctime;	/* last change time */
};
#endif /* INKERNEL */

struct	shminfo {
	int	shmmax,		/* max shared memory segment size */
		shmmin,		/* min shared memory segment size */
		shmmni,		/* # of shared memory identifiers */
		shmseg,		/* max attached shared memory	  */
				/* segments per process		  */
		shmall;		/* max total shared memory system */
				/* wide (in clicks)		  */
};


/*
 * Shared memory control operations
 */

#define SHM_LOCK	3	/* Lock segment in core */
#define SHM_UNLOCK	4	/* Unlock segment */

extern int shm_gap;

#define	_SYS_SHM_H_
#endif	/* _SYS_SHM_H_ */
