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