williamr@2
|
1 |
/* $FreeBSD: src/sys/sys/msg.h,v 1.20 2005/01/07 02:29:23 imp Exp $ */
|
williamr@2
|
2 |
/* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */
|
williamr@2
|
3 |
|
williamr@2
|
4 |
/*-
|
williamr@2
|
5 |
* SVID compatible msg.h file
|
williamr@2
|
6 |
*
|
williamr@2
|
7 |
* Author: Daniel Boulet
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
*© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
williamr@2
|
10 |
* Copyright 1993 Daniel Boulet and RTMX Inc.
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* This system call was implemented by Daniel Boulet under contract from RTMX.
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* Redistribution and use in source forms, with and without modification,
|
williamr@2
|
15 |
* are permitted provided that this entire comment appears intact.
|
williamr@2
|
16 |
*
|
williamr@2
|
17 |
* Redistribution in binary form may occur without any restrictions.
|
williamr@2
|
18 |
* Obviously, it would be nice if you gave credit where credit is due
|
williamr@2
|
19 |
* but requiring it would be too onerous.
|
williamr@2
|
20 |
*
|
williamr@2
|
21 |
* This software is provided ``AS IS'' without any warranties of any kind.
|
williamr@2
|
22 |
*/
|
williamr@2
|
23 |
|
williamr@2
|
24 |
#ifndef _SYS_MSG_H_
|
williamr@2
|
25 |
#define _SYS_MSG_H_
|
williamr@2
|
26 |
|
williamr@2
|
27 |
#include <sys/cdefs.h>
|
williamr@2
|
28 |
#include <sys/_types.h>
|
williamr@2
|
29 |
#include <sys/ipc.h>
|
williamr@2
|
30 |
|
williamr@2
|
31 |
/*
|
williamr@2
|
32 |
* The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
|
williamr@2
|
33 |
* are as defined by the SV API Intel 386 Processor Supplement.
|
williamr@2
|
34 |
*/
|
williamr@2
|
35 |
|
williamr@2
|
36 |
#define MSG_NOERROR 010000 /* don't complain about too long msgs */
|
williamr@2
|
37 |
|
williamr@2
|
38 |
typedef unsigned long msglen_t;
|
williamr@2
|
39 |
typedef unsigned long msgqnum_t;
|
williamr@2
|
40 |
|
williamr@2
|
41 |
#ifndef _PID_T_DECLARED
|
williamr@2
|
42 |
typedef __pid_t pid_t;
|
williamr@2
|
43 |
#define _PID_T_DECLARED
|
williamr@2
|
44 |
#endif
|
williamr@2
|
45 |
|
williamr@2
|
46 |
#ifndef _SIZE_T_DECLARED
|
williamr@2
|
47 |
typedef __size_t size_t;
|
williamr@2
|
48 |
#define _SIZE_T_DECLARED
|
williamr@2
|
49 |
#endif
|
williamr@2
|
50 |
|
williamr@2
|
51 |
#ifndef _SSIZE_T_DECLARED
|
williamr@2
|
52 |
typedef __ssize_t ssize_t;
|
williamr@2
|
53 |
#define _SSIZE_T_DECLARED
|
williamr@2
|
54 |
#endif
|
williamr@2
|
55 |
|
williamr@2
|
56 |
#ifndef _TIME_T_DECLARED
|
williamr@2
|
57 |
typedef __time_t time_t;
|
williamr@2
|
58 |
#define _TIME_T_DECLARED
|
williamr@2
|
59 |
#endif
|
williamr@2
|
60 |
|
williamr@2
|
61 |
/*
|
williamr@2
|
62 |
* XXX there seems to be no prefix reserved for this header, so the name
|
williamr@2
|
63 |
* "msg" in "struct msg" and the names of all of the nonstandard members
|
williamr@2
|
64 |
* (mainly "msg_pad*) are namespace pollution.
|
williamr@2
|
65 |
*/
|
williamr@2
|
66 |
|
williamr@2
|
67 |
struct msqid_ds {
|
williamr@2
|
68 |
struct ipc_perm msg_perm; /* msg queue permission bits */
|
williamr@2
|
69 |
struct msg *msg_first; /* first message in the queue */
|
williamr@2
|
70 |
struct msg *msg_last; /* last message in the queue */
|
williamr@2
|
71 |
msglen_t msg_cbytes; /* number of bytes in use on the queue */
|
williamr@2
|
72 |
msgqnum_t msg_qnum; /* number of msgs in the queue */
|
williamr@2
|
73 |
msglen_t msg_qbytes; /* max # of bytes on the queue */
|
williamr@2
|
74 |
pid_t msg_lspid; /* pid of last msgsnd() */
|
williamr@2
|
75 |
pid_t msg_lrpid; /* pid of last msgrcv() */
|
williamr@2
|
76 |
time_t msg_stime; /* time of last msgsnd() */
|
williamr@2
|
77 |
long msg_pad1;
|
williamr@2
|
78 |
time_t msg_rtime; /* time of last msgrcv() */
|
williamr@2
|
79 |
long msg_pad2;
|
williamr@2
|
80 |
time_t msg_ctime; /* time of last msgctl() */
|
williamr@2
|
81 |
long msg_pad3;
|
williamr@2
|
82 |
long msg_pad4[4];
|
williamr@2
|
83 |
};
|
williamr@2
|
84 |
|
williamr@2
|
85 |
#if __BSD_VISIBLE
|
williamr@2
|
86 |
/*
|
williamr@2
|
87 |
* Structure describing a message. The SVID doesn't suggest any
|
williamr@2
|
88 |
* particular name for this structure. There is a reference in the
|
williamr@2
|
89 |
* msgop man page that reads "The structure mymsg is an example of what
|
williamr@2
|
90 |
* this user defined buffer might look like, and includes the following
|
williamr@2
|
91 |
* members:". This sentence is followed by two lines equivalent
|
williamr@2
|
92 |
* to the mtype and mtext field declarations below. It isn't clear
|
williamr@2
|
93 |
* if "mymsg" refers to the name of the structure type or the name of an
|
williamr@2
|
94 |
* instance of the structure...
|
williamr@2
|
95 |
*/
|
williamr@2
|
96 |
struct mymsg {
|
williamr@2
|
97 |
long mtype; /* message type (+ve integer) */
|
williamr@2
|
98 |
char mtext[1]; /* message body */
|
williamr@2
|
99 |
};
|
williamr@2
|
100 |
#endif
|
williamr@2
|
101 |
|
williamr@2
|
102 |
#ifdef _KERNEL
|
williamr@2
|
103 |
|
williamr@2
|
104 |
struct msg {
|
williamr@2
|
105 |
struct msg *msg_next; /* next msg in the chain */
|
williamr@2
|
106 |
long msg_type; /* type of this message */
|
williamr@2
|
107 |
/* >0 -> type of this message */
|
williamr@2
|
108 |
/* 0 -> free header */
|
williamr@2
|
109 |
u_short msg_ts; /* size of this message */
|
williamr@2
|
110 |
short msg_spot; /* location of start of msg in buffer */
|
williamr@2
|
111 |
struct label *label; /* MAC Framework label */
|
williamr@2
|
112 |
};
|
williamr@2
|
113 |
|
williamr@2
|
114 |
/*
|
williamr@2
|
115 |
* Based on the configuration parameters described in an SVR2 (yes, two)
|
williamr@2
|
116 |
* config(1m) man page.
|
williamr@2
|
117 |
*
|
williamr@2
|
118 |
* Each message is broken up and stored in segments that are msgssz bytes
|
williamr@2
|
119 |
* long. For efficiency reasons, this should be a power of two. Also,
|
williamr@2
|
120 |
* it doesn't make sense if it is less than 8 or greater than about 256.
|
williamr@2
|
121 |
* Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
|
williamr@2
|
122 |
* two between 8 and 1024 inclusive (and panic's if it isn't).
|
williamr@2
|
123 |
*/
|
williamr@2
|
124 |
struct msginfo {
|
williamr@2
|
125 |
int msgmax, /* max chars in a message */
|
williamr@2
|
126 |
msgmni, /* max message queue identifiers */
|
williamr@2
|
127 |
msgmnb, /* max chars in a queue */
|
williamr@2
|
128 |
msgtql, /* max messages in system */
|
williamr@2
|
129 |
msgssz, /* size of a message segment (see notes above) */
|
williamr@2
|
130 |
msgseg; /* number of message segments */
|
williamr@2
|
131 |
};
|
williamr@2
|
132 |
extern struct msginfo msginfo;
|
williamr@2
|
133 |
|
williamr@2
|
134 |
/*
|
williamr@2
|
135 |
* Kernel wrapper for the user-level structure.
|
williamr@2
|
136 |
*/
|
williamr@2
|
137 |
struct msqid_kernel {
|
williamr@2
|
138 |
/*
|
williamr@2
|
139 |
* Data structure exposed to user space.
|
williamr@2
|
140 |
*/
|
williamr@2
|
141 |
struct msqid_ds u;
|
williamr@2
|
142 |
|
williamr@2
|
143 |
/*
|
williamr@2
|
144 |
* Kernel-private components of the message queue.
|
williamr@2
|
145 |
*/
|
williamr@2
|
146 |
struct label *label; /* MAC label */
|
williamr@2
|
147 |
};
|
williamr@2
|
148 |
|
williamr@2
|
149 |
#else /* !_KERNEL */
|
williamr@2
|
150 |
|
williamr@2
|
151 |
/* Template for struct to be used as argument for `msgsnd' and `msgrcv'. */
|
williamr@2
|
152 |
struct msgbuf
|
williamr@2
|
153 |
{
|
williamr@2
|
154 |
long int mtype; /* type of received/sent message */
|
williamr@2
|
155 |
char mtext[1]; /* text of the message */
|
williamr@2
|
156 |
};
|
williamr@2
|
157 |
|
williamr@2
|
158 |
// FUNCTION PROTOTYPES
|
williamr@2
|
159 |
|
williamr@2
|
160 |
|
williamr@2
|
161 |
// FORWARD DECLARATIONS
|
williamr@2
|
162 |
|
williamr@2
|
163 |
|
williamr@2
|
164 |
// CLASS/STRUCT/FUNCTION DECLARATION
|
williamr@2
|
165 |
__BEGIN_DECLS
|
williamr@2
|
166 |
|
williamr@2
|
167 |
/*
|
williamr@2
|
168 |
* Get the message queue identifier using the IPC key generated by ftok.
|
williamr@2
|
169 |
*/
|
williamr@2
|
170 |
|
williamr@2
|
171 |
IMPORT_C int msgget(key_t key, int msgflg);
|
williamr@2
|
172 |
|
williamr@2
|
173 |
/*
|
williamr@2
|
174 |
* Used to send a message to the queue associated with the message identifier specified by msqid.
|
williamr@2
|
175 |
*/
|
williamr@2
|
176 |
|
williamr@2
|
177 |
IMPORT_C int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
|
williamr@2
|
178 |
|
williamr@2
|
179 |
/*
|
williamr@2
|
180 |
* Reads a message from the queue associated with the message queue identifier.
|
williamr@2
|
181 |
*/
|
williamr@2
|
182 |
|
williamr@2
|
183 |
IMPORT_C ssize_t msgrcv(int msqid, void* msgp, size_t msgsz, long msgtyp, int msgflg);
|
williamr@2
|
184 |
|
williamr@2
|
185 |
/*
|
williamr@2
|
186 |
* Provides an interface to control message queue and control operations as specified by cmd.
|
williamr@2
|
187 |
*/
|
williamr@2
|
188 |
|
williamr@2
|
189 |
IMPORT_C int msgctl(int msqid, int cmd, struct msqid_ds* buf);
|
williamr@2
|
190 |
|
williamr@2
|
191 |
|
williamr@2
|
192 |
__END_DECLS
|
williamr@2
|
193 |
|
williamr@2
|
194 |
#endif /* !_KERNEL */
|
williamr@2
|
195 |
|
williamr@2
|
196 |
#endif // _SYS_MSG_H_
|
williamr@2
|
197 |
|
williamr@2
|
198 |
// End of File
|