/* @(#) ipc.h $Date: 2004/08/05 11:40:57 $Revision: i380/5 PATCH_11.23 (PHKL_31500) */
/* 
 * (C) Copyright 1996-2004 Hewlett-Packard Development Company, LP
 */

/*
  * @(#)
  * Common interprocess communication (IPC) access structure definition,
  * used by the three IPC mechanisms: messages, semaphores and shared
  * memory.
  */

#ifndef _SYS_IPC_INCLUDED
#define _SYS_IPC_INCLUDED

#include <sys/stdsyms.h>
#include <sys/types.h>

#ifdef _INCLUDE_XOPEN_SOURCE

  /* Needed types and structures */

   /* Common IPC Access Structure */
   struct ipc_perm {
#    ifdef _CLASSIC_ID_TYPES
	unsigned short  filler_uid;
	unsigned short  uid;    /* owner's user id */
	unsigned short  filler_gid;
	unsigned short  gid;    /* owner's group id */
	unsigned short  filler_cuid;
	unsigned short  cuid;   /* creator's user id */
	unsigned short  filler_cgid;
	unsigned short  cgid;   /* creator's group id */
#    else
        uid_t        	uid;    /* owner's user id */
        gid_t	        gid;    /* owner's group id */
        uid_t	        cuid;   /* creator's user id */
        gid_t	        cgid;   /* creator's group id */
#    endif /* not _CLASSIC_ID_TYPES */

	mode_t		mode;	/* access modes */
	unsigned short	__seq16;/* OLD slot usage sequence number */
	key_t		key;	/* key */

	unsigned short	__ndx;	/* NOT USED; was ndx of proc who has lock */
	unsigned short	__wait;	/* waits, wanted, lock bits; reserved for 
				   specific ipc facilities */

	unsigned int	seq;	/* slot usage sequence number */
#    ifdef _INCLUDE_HPUX_SOURCE
	cid_t		cid;	/* Compartment ID */
#    else
	int		__cpad;	/* pad for non-hp code */
#    endif /* _INCLUDE_HPUX_SOURCE */
	char		pad[12];/* room for future expansion */
   };
#  define _IPCPERM_T

/*
 * Message queue size fields have been changed from short to long.  This
 * allows queues to now exceed old 64Kbytes limits.  However, in order
 * to preserve compatibility, queue limits will continue to default to
 * 64Kbytes until a future release.  If >64Kbytes is desired, programs
 * using a common queue can be recompiled with -D__BIGMSGQUEUE_ENABLED.
 * Also, the administrator must increase the appropriate kernel tunables.
 */
#if defined(__BIGMSGQUEUE_ENABLED)
#  define  __IPC16_CREAT  0001000
#  define  IPC_CREAT	  0040000
#else
#  define  IPC_CREAT	  0001000	/* create entry if key doesn't exist */
#endif
#  define  IPC_EXCL	  0002000	/* fail if key exists */
#  define  IPC_NOWAIT	  0004000	/* error if request must wait */

#  define  IPC_SHARE32	  0010000	/* allocate in 32-bit addr space */
					/* Used for sharing with 64 bit apps.*/
#  define  IPC_GLOBAL	0020000 	/* Create shared memory segment so
					 * that it can be shared across memory
					 * windows.
					 */
/* 
 * These flags only matter on ccNUMA machines.  These flags allow the
 * caller to specify where physical memory comes from for the pages
 * mapped by a call to shmget().  For each flag, physical memory will
 * come from: 
 */
#  define  IPC_MEM_LOCAL	 0100000 /* the current locality domain */
#  define  IPC_MEM_INTERLEAVED	 0200000 /* interleaved memory */         
#  define  IPC_MEM_FIRST_TOUCH	 0400000 /* the touching locality domain */
#  define  IPC_MEM_STRIPED	01000000 /* striped amongst localities HINT */

/* 
 * This hint is used for a performance enhancement in the case where there
 * are many shared memory segments being accessed by a process. Setting 
 * this hint "may" reuse protection id across all shared memory segments 
 * created by the process using this hint.
 */
#  define  IPC_RELAXED_ISOLATION 02000000 

   /* Keys. */
#  define  IPC_PRIVATE	(key_t)0	/* private key */

   /* Control Commands. */
#  define	IPC_RMID	0	/* remove identifier */
#ifdef _KERNEL
#  define	__IPC16_SET	1	/* pre-11.11 "ds" struct */
#endif
#  define	IPC_SET		11	/* set options */
#  define	IPC_STAT	2	/* get options */

#endif /* _INCLUDE_XOPEN_SOURCE */

#ifdef _INCLUDE_XOPEN_SOURCE_EXTENDED 

/* Function prototype for ftok() */

#ifndef _NO_USER_PROTOS
#  ifdef __cplusplus
      extern "C" {
#  endif /* __cplusplus */

#  if defined(__ia64) && !defined(_LIBC)  
    /* pragmas needed to support -B protected */  
#    pragma extern ftok
#  endif /* __ia64 && ! _LIBC */ 

#    ifdef _PROTOTYPES
       extern key_t ftok(const char *, int);
#    else /* not _PROTOTYPES */
       extern key_t ftok();
#    endif /* not _PROTOTYPES */

#  ifdef __cplusplus
      }
#  endif /* __cplusplus */
#endif /* not _NO_USER_PROTOS */

#endif /* _INCLUDE_XOPEN_SOURCE_EXTENDED */


#ifdef _INCLUDE_HPUX_SOURCE

   /* Common IPC Definitions. */
   /* Mode bits. */
#  define	IPC_ALLOC	0100000		/* entry currently allocated */
#  define	IPC_LOCKED	0040000		/* structure is locked */
#  define	IPC_WANTED	0004000		/* process waiting for lock */

   /*
   ** Struct oipc_perm is the obsolete version of struct ipc_perm.
   ** It was used before release A.08.00.
   ** Object code compatibility is supported for old a.out files
   ** that were compiled with this version.  However, old .o files
   ** should be recompiled with the new struct ipc_perm if they are
   ** to be linked with the C library made for release A.08.00 or
   ** later releases.
   **/
   struct oipc_perm {
	unsigned short	uid;	/* owner's user id */
	unsigned short	gid;	/* owner's group id */
	unsigned short	cuid;	/* creator's user id */
	unsigned short	cgid;	/* creator's group id */
	unsigned short	mode;	/* access modes */
	unsigned short	seq;	/* slot usage sequence number */
	key_t		key;	/* key */
	unsigned short	ndx;	/* ndx of proc who has lock */
	unsigned short	wait;	/* waits, wanted, lock bits; reserved for 
				   specific ipc facilities */
   };

   struct ipcmap {
	unsigned int	m_size;
	unsigned int	m_addr;
   };

#  define _IPCMAP_T

#    define	ipcmapstart(X)		(&(X)[1])
#    define	ipcmapwant(X)		((X)[0].m_addr)
#    define	ipcmapsize(X)		((X)[0].m_size)
#    define	ipcmapdata(X)		{(X)-2, 0} , {0, 0}
#    define	ipcmapinit(X, Y)	((X)[0].m_size = (Y)-2)

/*
 * Define MAXUSHORT based on the MAXINT style which exists in param.h .
 * While at it, define our own IPC 'min()/max()' functions.
 */
#ifdef _KERNEL
#	define MAXUSHORT	0xffff
#	define IPCMIN(a,b)	( ((a)<(b)) ? (a) : (b) )
#	define IPCMAX(a,b)	( ((a)>(b)) ? (a) : (b) )
#endif

#endif /* _INCLUDE_HPUX_SOURCE */

#endif /* _SYS_IPC_INCLUDED */
