sl@0: /* $FreeBSD: src/sys/sys/msg.h,v 1.20 2005/01/07 02:29:23 imp Exp $ */
sl@0: /*	$NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $	*/
sl@0: 
sl@0: /*-
sl@0:  * SVID compatible msg.h file
sl@0:  *
sl@0:  * Author:  Daniel Boulet
sl@0:  *
sl@0:  *© Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
sl@0:  * Copyright 1993 Daniel Boulet and RTMX Inc.
sl@0:  *
sl@0:  * This system call was implemented by Daniel Boulet under contract from RTMX.
sl@0:  *
sl@0:  * Redistribution and use in source forms, with and without modification,
sl@0:  * are permitted provided that this entire comment appears intact.
sl@0:  *
sl@0:  * Redistribution in binary form may occur without any restrictions.
sl@0:  * Obviously, it would be nice if you gave credit where credit is due
sl@0:  * but requiring it would be too onerous.
sl@0:  *
sl@0:  * This software is provided ``AS IS'' without any warranties of any kind.
sl@0:  */
sl@0: 
sl@0: #ifndef _SYS_MSG_H_
sl@0: #define _SYS_MSG_H_
sl@0: 
sl@0: #include <sys/cdefs.h>
sl@0: #include <sys/_types.h>
sl@0: #include <sys/ipc.h>
sl@0: 
sl@0: /*
sl@0:  * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
sl@0:  * are as defined by the SV API Intel 386 Processor Supplement.
sl@0:  */
sl@0: 
sl@0: #define MSG_NOERROR	010000		/* don't complain about too long msgs */
sl@0: 
sl@0: typedef	unsigned long	msglen_t;
sl@0: typedef	unsigned long	msgqnum_t;
sl@0: 
sl@0: #ifndef _PID_T_DECLARED
sl@0: typedef	__pid_t		pid_t;
sl@0: #define	_PID_T_DECLARED
sl@0: #endif
sl@0: 
sl@0: #ifndef _SIZE_T_DECLARED
sl@0: typedef	__size_t	size_t;
sl@0: #define	_SIZE_T_DECLARED
sl@0: #endif
sl@0: 
sl@0: #ifndef _SSIZE_T_DECLARED
sl@0: typedef	__ssize_t	ssize_t;
sl@0: #define	_SSIZE_T_DECLARED
sl@0: #endif
sl@0: 
sl@0: #ifndef _TIME_T_DECLARED
sl@0: typedef	__time_t	time_t;
sl@0: #define	_TIME_T_DECLARED
sl@0: #endif
sl@0: 
sl@0: /*
sl@0:  * XXX there seems to be no prefix reserved for this header, so the name
sl@0:  * "msg" in "struct msg" and the names of all of the nonstandard members
sl@0:  * (mainly "msg_pad*) are namespace pollution.
sl@0:  */
sl@0: 
sl@0: struct msqid_ds {
sl@0: 	struct	ipc_perm msg_perm;	/* msg queue permission bits */
sl@0: 	struct	msg *msg_first;	/* first message in the queue */
sl@0: 	struct	msg *msg_last;	/* last message in the queue */
sl@0: 	msglen_t msg_cbytes;	/* number of bytes in use on the queue */
sl@0: 	msgqnum_t msg_qnum;	/* number of msgs in the queue */
sl@0: 	msglen_t msg_qbytes;	/* max # of bytes on the queue */
sl@0: 	pid_t	msg_lspid;	/* pid of last msgsnd() */
sl@0: 	pid_t	msg_lrpid;	/* pid of last msgrcv() */
sl@0: 	time_t	msg_stime;	/* time of last msgsnd() */
sl@0: 	long	msg_pad1;
sl@0: 	time_t	msg_rtime;	/* time of last msgrcv() */
sl@0: 	long	msg_pad2;
sl@0: 	time_t	msg_ctime;	/* time of last msgctl() */
sl@0: 	long	msg_pad3;
sl@0: 	long	msg_pad4[4];
sl@0: };
sl@0: 
sl@0: #if __BSD_VISIBLE
sl@0: /*
sl@0:  * Structure describing a message.  The SVID doesn't suggest any
sl@0:  * particular name for this structure.  There is a reference in the
sl@0:  * msgop man page that reads "The structure mymsg is an example of what
sl@0:  * this user defined buffer might look like, and includes the following
sl@0:  * members:".  This sentence is followed by two lines equivalent
sl@0:  * to the mtype and mtext field declarations below.  It isn't clear
sl@0:  * if "mymsg" refers to the name of the structure type or the name of an
sl@0:  * instance of the structure...
sl@0:  */
sl@0: struct mymsg {
sl@0: 	long	mtype;		/* message type (+ve integer) */
sl@0: 	char	mtext[1];	/* message body */
sl@0: };
sl@0: #endif
sl@0: 
sl@0: #ifdef _KERNEL
sl@0: 
sl@0: struct msg {
sl@0: 	struct	msg *msg_next;  /* next msg in the chain */
sl@0: 	long	msg_type; 	/* type of this message */
sl@0: 				/* >0 -> type of this message */
sl@0: 				/* 0 -> free header */
sl@0: 	u_short	msg_ts;		/* size of this message */
sl@0: 	short	msg_spot;	/* location of start of msg in buffer */
sl@0: 	struct	label *label;	/* MAC Framework label */
sl@0: };
sl@0: 
sl@0: /*
sl@0:  * Based on the configuration parameters described in an SVR2 (yes, two)
sl@0:  * config(1m) man page.
sl@0:  *
sl@0:  * Each message is broken up and stored in segments that are msgssz bytes
sl@0:  * long.  For efficiency reasons, this should be a power of two.  Also,
sl@0:  * it doesn't make sense if it is less than 8 or greater than about 256.
sl@0:  * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
sl@0:  * two between 8 and 1024 inclusive (and panic's if it isn't).
sl@0:  */
sl@0: struct msginfo {
sl@0: 	int	msgmax,		/* max chars in a message */
sl@0: 		msgmni,		/* max message queue identifiers */
sl@0: 		msgmnb,		/* max chars in a queue */
sl@0: 		msgtql,		/* max messages in system */
sl@0: 		msgssz,		/* size of a message segment (see notes above) */
sl@0: 		msgseg;		/* number of message segments */
sl@0: };
sl@0: extern struct msginfo	msginfo;
sl@0: 
sl@0: /*
sl@0:  * Kernel wrapper for the user-level structure.
sl@0:  */
sl@0: struct msqid_kernel {
sl@0: 	/*
sl@0: 	 * Data structure exposed to user space.
sl@0: 	 */
sl@0: 	struct	msqid_ds u;
sl@0: 
sl@0: 	/*
sl@0: 	 * Kernel-private components of the message queue.
sl@0: 	 */
sl@0: 	struct	label *label;	/* MAC label */
sl@0: };
sl@0: 
sl@0: #else /* !_KERNEL */
sl@0: 
sl@0: /* Template for struct to be used as argument for `msgsnd' and `msgrcv'.  */
sl@0: struct msgbuf
sl@0:   {
sl@0:     long int mtype;     /* type of received/sent message */
sl@0:     char mtext[1];      /* text of the message */
sl@0:   };
sl@0: 
sl@0: // FUNCTION PROTOTYPES
sl@0: 
sl@0: 
sl@0: // FORWARD DECLARATIONS
sl@0: 
sl@0: 
sl@0: // CLASS/STRUCT/FUNCTION DECLARATION
sl@0: __BEGIN_DECLS
sl@0: 
sl@0: /*
sl@0: * Get the message queue identifier using the IPC key generated by ftok.
sl@0: */
sl@0: 
sl@0: IMPORT_C int msgget(key_t key, int msgflg);
sl@0: 
sl@0: /*
sl@0: * Used to send a message to the queue associated with the message identifier specified by msqid.
sl@0: */
sl@0: 
sl@0: IMPORT_C int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
sl@0: 
sl@0: /*
sl@0: * Reads a message from the queue associated with the message queue identifier.
sl@0: */
sl@0: 
sl@0: IMPORT_C ssize_t msgrcv(int msqid, void* msgp, size_t msgsz, long msgtyp, int msgflg);
sl@0: 
sl@0: /*
sl@0: * Provides an interface to control message queue and control operations as specified by cmd.
sl@0: */
sl@0: 
sl@0: IMPORT_C int msgctl(int msqid, int cmd, struct msqid_ds* buf);
sl@0: 
sl@0: 
sl@0: __END_DECLS
sl@0: 
sl@0: #endif /* !_KERNEL */
sl@0: 
sl@0: #endif // _SYS_MSG_H_
sl@0: 
sl@0: //  End of File