xref: /f-stack/freebsd/sys/msg.h (revision 22ce4aff)
1a9643ea8Slogwang /* $FreeBSD$ */
2a9643ea8Slogwang /*	$NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $	*/
3a9643ea8Slogwang 
4a9643ea8Slogwang /*-
5a9643ea8Slogwang  * SVID compatible msg.h file
6a9643ea8Slogwang  *
7a9643ea8Slogwang  * Author:  Daniel Boulet
8a9643ea8Slogwang  *
9a9643ea8Slogwang  * Copyright 1993 Daniel Boulet and RTMX Inc.
10a9643ea8Slogwang  *
11a9643ea8Slogwang  * This system call was implemented by Daniel Boulet under contract from RTMX.
12a9643ea8Slogwang  *
13a9643ea8Slogwang  * Redistribution and use in source forms, with and without modification,
14a9643ea8Slogwang  * are permitted provided that this entire comment appears intact.
15a9643ea8Slogwang  *
16a9643ea8Slogwang  * Redistribution in binary form may occur without any restrictions.
17a9643ea8Slogwang  * Obviously, it would be nice if you gave credit where credit is due
18a9643ea8Slogwang  * but requiring it would be too onerous.
19a9643ea8Slogwang  *
20a9643ea8Slogwang  * This software is provided ``AS IS'' without any warranties of any kind.
21a9643ea8Slogwang  */
22a9643ea8Slogwang 
23a9643ea8Slogwang #ifndef _SYS_MSG_H_
24a9643ea8Slogwang #define _SYS_MSG_H_
25a9643ea8Slogwang 
26a9643ea8Slogwang #include <sys/cdefs.h>
27a9643ea8Slogwang #include <sys/_types.h>
28*22ce4affSfengbojiang #ifdef _WANT_SYSVMSG_INTERNALS
29*22ce4affSfengbojiang #define	_WANT_SYSVIPC_INTERNALS
30*22ce4affSfengbojiang #endif
31a9643ea8Slogwang #include <sys/ipc.h>
32a9643ea8Slogwang 
33a9643ea8Slogwang /*
34a9643ea8Slogwang  * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
35a9643ea8Slogwang  * are as defined by the SV API Intel 386 Processor Supplement.
36a9643ea8Slogwang  */
37a9643ea8Slogwang 
38a9643ea8Slogwang #define MSG_NOERROR	010000		/* don't complain about too long msgs */
39a9643ea8Slogwang 
40a9643ea8Slogwang typedef	unsigned long	msglen_t;
41a9643ea8Slogwang typedef	unsigned long	msgqnum_t;
42a9643ea8Slogwang 
43a9643ea8Slogwang #ifndef _PID_T_DECLARED
44a9643ea8Slogwang typedef	__pid_t		pid_t;
45a9643ea8Slogwang #define	_PID_T_DECLARED
46a9643ea8Slogwang #endif
47a9643ea8Slogwang 
48a9643ea8Slogwang #ifndef _SIZE_T_DECLARED
49a9643ea8Slogwang typedef	__size_t	size_t;
50a9643ea8Slogwang #define	_SIZE_T_DECLARED
51a9643ea8Slogwang #endif
52a9643ea8Slogwang 
53a9643ea8Slogwang #ifndef _SSIZE_T_DECLARED
54a9643ea8Slogwang typedef	__ssize_t	ssize_t;
55a9643ea8Slogwang #define	_SSIZE_T_DECLARED
56a9643ea8Slogwang #endif
57a9643ea8Slogwang 
58a9643ea8Slogwang #ifndef _TIME_T_DECLARED
59a9643ea8Slogwang typedef	__time_t	time_t;
60a9643ea8Slogwang #define	_TIME_T_DECLARED
61a9643ea8Slogwang #endif
62a9643ea8Slogwang 
63a9643ea8Slogwang #if defined(COMPAT_FREEBSD4) || defined(COMPAT_FREEBSD5) || \
64a9643ea8Slogwang     defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD7)
65a9643ea8Slogwang struct msqid_ds_old {
66a9643ea8Slogwang 	struct	ipc_perm_old msg_perm;	/* msg queue permission bits */
67*22ce4affSfengbojiang 	struct	msg *__msg_first;	/* first message in the queue */
68*22ce4affSfengbojiang 	struct	msg *__msg_last;	/* last message in the queue */
69a9643ea8Slogwang 	msglen_t msg_cbytes;	/* number of bytes in use on the queue */
70a9643ea8Slogwang 	msgqnum_t msg_qnum;	/* number of msgs in the queue */
71a9643ea8Slogwang 	msglen_t msg_qbytes;	/* max # of bytes on the queue */
72a9643ea8Slogwang 	pid_t	msg_lspid;	/* pid of last msgsnd() */
73a9643ea8Slogwang 	pid_t	msg_lrpid;	/* pid of last msgrcv() */
74a9643ea8Slogwang 	time_t	msg_stime;	/* time of last msgsnd() */
75a9643ea8Slogwang 	long	msg_pad1;
76a9643ea8Slogwang 	time_t	msg_rtime;	/* time of last msgrcv() */
77a9643ea8Slogwang 	long	msg_pad2;
78a9643ea8Slogwang 	time_t	msg_ctime;	/* time of last msgctl() */
79a9643ea8Slogwang 	long	msg_pad3;
80a9643ea8Slogwang 	long	msg_pad4[4];
81a9643ea8Slogwang };
82a9643ea8Slogwang #endif
83a9643ea8Slogwang 
84a9643ea8Slogwang /*
85a9643ea8Slogwang  * XXX there seems to be no prefix reserved for this header, so the name
86a9643ea8Slogwang  * "msg" in "struct msg" and the names of all of the nonstandard members
87*22ce4affSfengbojiang  * are namespace pollution.
88a9643ea8Slogwang  */
89a9643ea8Slogwang 
90a9643ea8Slogwang struct msqid_ds {
91a9643ea8Slogwang 	struct	ipc_perm msg_perm;	/* msg queue permission bits */
92*22ce4affSfengbojiang 	struct	msg *__msg_first;	/* first message in the queue */
93*22ce4affSfengbojiang 	struct	msg *__msg_last;	/* last message in the queue */
94a9643ea8Slogwang 	msglen_t msg_cbytes;	/* number of bytes in use on the queue */
95a9643ea8Slogwang 	msgqnum_t msg_qnum;	/* number of msgs in the queue */
96a9643ea8Slogwang 	msglen_t msg_qbytes;	/* max # of bytes on the queue */
97a9643ea8Slogwang 	pid_t	msg_lspid;	/* pid of last msgsnd() */
98a9643ea8Slogwang 	pid_t	msg_lrpid;	/* pid of last msgrcv() */
99a9643ea8Slogwang 	time_t	msg_stime;	/* time of last msgsnd() */
100a9643ea8Slogwang 	time_t	msg_rtime;	/* time of last msgrcv() */
101a9643ea8Slogwang 	time_t	msg_ctime;	/* time of last msgctl() */
102a9643ea8Slogwang };
103a9643ea8Slogwang 
104a9643ea8Slogwang #ifdef _KERNEL
105a9643ea8Slogwang struct msg {
106a9643ea8Slogwang 	struct	msg *msg_next;  /* next msg in the chain */
107a9643ea8Slogwang 	long	msg_type; 	/* type of this message */
108a9643ea8Slogwang 				/* >0 -> type of this message */
109a9643ea8Slogwang 				/* 0 -> free header */
110a9643ea8Slogwang 	u_short	msg_ts;		/* size of this message */
111a9643ea8Slogwang 	short	msg_spot;	/* location of start of msg in buffer */
112a9643ea8Slogwang 	struct	label *label;	/* MAC Framework label */
113a9643ea8Slogwang };
114*22ce4affSfengbojiang #endif
115a9643ea8Slogwang 
116*22ce4affSfengbojiang #if defined(_KERNEL) || defined(_WANT_SYSVMSG_INTERNALS)
117a9643ea8Slogwang /*
118a9643ea8Slogwang  * Based on the configuration parameters described in an SVR2 (yes, two)
119a9643ea8Slogwang  * config(1m) man page.
120a9643ea8Slogwang  *
121a9643ea8Slogwang  * Each message is broken up and stored in segments that are msgssz bytes
122a9643ea8Slogwang  * long.  For efficiency reasons, this should be a power of two.  Also,
123a9643ea8Slogwang  * it doesn't make sense if it is less than 8 or greater than about 256.
124a9643ea8Slogwang  * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
125a9643ea8Slogwang  * two between 8 and 1024 inclusive (and panic's if it isn't).
126a9643ea8Slogwang  */
127a9643ea8Slogwang struct msginfo {
128*22ce4affSfengbojiang 	int	msgmax;		/* max chars in a message */
129*22ce4affSfengbojiang 	int	msgmni;		/* max message queue identifiers */
130*22ce4affSfengbojiang 	int	msgmnb;		/* max chars in a queue */
131*22ce4affSfengbojiang 	int	msgtql;		/* max messages in system */
132*22ce4affSfengbojiang 	int	msgssz;		/* size of a message segment (see note) */
133*22ce4affSfengbojiang 	int	msgseg;		/* number of message segments */
134a9643ea8Slogwang };
135a9643ea8Slogwang 
136a9643ea8Slogwang /*
137a9643ea8Slogwang  * Kernel wrapper for the user-level structure.
138a9643ea8Slogwang  */
139a9643ea8Slogwang struct msqid_kernel {
140a9643ea8Slogwang 	/*
141a9643ea8Slogwang 	 * Data structure exposed to user space.
142a9643ea8Slogwang 	 */
143a9643ea8Slogwang 	struct	msqid_ds u;
144a9643ea8Slogwang 
145a9643ea8Slogwang 	/*
146a9643ea8Slogwang 	 * Kernel-private components of the message queue.
147a9643ea8Slogwang 	 */
148a9643ea8Slogwang 	struct	label *label;	/* MAC label */
149a9643ea8Slogwang 	struct	ucred *cred;	/* creator's credentials */
150a9643ea8Slogwang };
151*22ce4affSfengbojiang #endif
152a9643ea8Slogwang 
153*22ce4affSfengbojiang #ifdef _KERNEL
154*22ce4affSfengbojiang extern struct msginfo	msginfo;
155a9643ea8Slogwang 
156*22ce4affSfengbojiang #else /* _KERNEL */
157*22ce4affSfengbojiang 
158a9643ea8Slogwang __BEGIN_DECLS
159a9643ea8Slogwang int msgctl(int, int, struct msqid_ds *);
160a9643ea8Slogwang int msgget(key_t, int);
161*22ce4affSfengbojiang ssize_t msgrcv(int, void *, size_t, long, int);
162a9643ea8Slogwang int msgsnd(int, const void *, size_t, int);
163a9643ea8Slogwang #if __BSD_VISIBLE
164a9643ea8Slogwang int msgsys(int, ...);
165a9643ea8Slogwang #endif
166a9643ea8Slogwang __END_DECLS
167*22ce4affSfengbojiang #endif /* !_KERNEL */
168a9643ea8Slogwang 
169a9643ea8Slogwang #endif /* !_SYS_MSG_H_ */
170