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