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