1 /* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */ 2 3 /*- 4 * SVID compatible msg.h file 5 * 6 * Author: Daniel Boulet 7 * 8 * Copyright 1993 Daniel Boulet and RTMX Inc. 9 * 10 * This system call was implemented by Daniel Boulet under contract from RTMX. 11 * 12 * Redistribution and use in source forms, with and without modification, 13 * are permitted provided that this entire comment appears intact. 14 * 15 * Redistribution in binary form may occur without any restrictions. 16 * Obviously, it would be nice if you gave credit where credit is due 17 * but requiring it would be too onerous. 18 * 19 * This software is provided ``AS IS'' without any warranties of any kind. 20 */ 21 22 #ifndef _SYS_MSG_H_ 23 #define _SYS_MSG_H_ 24 25 #include <sys/cdefs.h> 26 #include <sys/_types.h> 27 #ifdef _WANT_SYSVMSG_INTERNALS 28 #define _WANT_SYSVIPC_INTERNALS 29 #endif 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 39 typedef unsigned long msglen_t; 40 typedef unsigned long msgqnum_t; 41 42 #ifndef _PID_T_DECLARED 43 typedef __pid_t pid_t; 44 #define _PID_T_DECLARED 45 #endif 46 47 #ifndef _SIZE_T_DECLARED 48 typedef __size_t size_t; 49 #define _SIZE_T_DECLARED 50 #endif 51 52 #ifndef _SSIZE_T_DECLARED 53 typedef __ssize_t ssize_t; 54 #define _SSIZE_T_DECLARED 55 #endif 56 57 #ifndef _TIME_T_DECLARED 58 typedef __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) 64 struct 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 * are namespace pollution. 87 */ 88 89 struct 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 #ifdef _KERNEL 104 struct msg { 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 */ 112 }; 113 #endif 114 115 #if defined(_KERNEL) || defined(_WANT_SYSVMSG_INTERNALS) 116 /* 117 * Based on the configuration parameters described in an SVR2 (yes, two) 118 * config(1m) man page. 119 * 120 * Each message is broken up and stored in segments that are msgssz bytes 121 * long. For efficiency reasons, this should be a power of two. Also, 122 * it doesn't make sense if it is less than 8 or greater than about 256. 123 * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of 124 * two between 8 and 1024 inclusive (and panic's if it isn't). 125 */ 126 struct msginfo { 127 int msgmax; /* max chars in a message */ 128 int msgmni; /* max message queue identifiers */ 129 int msgmnb; /* max chars in a queue */ 130 int msgtql; /* max messages in system */ 131 int msgssz; /* size of a message segment (see note) */ 132 int msgseg; /* number of message segments */ 133 }; 134 135 /* 136 * Kernel wrapper for the user-level structure. 137 */ 138 struct msqid_kernel { 139 /* 140 * Data structure exposed to user space. 141 */ 142 struct msqid_ds u; 143 144 /* 145 * Kernel-private components of the message queue. 146 */ 147 struct label *label; /* MAC label */ 148 struct ucred *cred; /* creator's credentials */ 149 }; 150 #endif 151 152 #ifdef _KERNEL 153 extern struct msginfo msginfo; 154 155 int kern_get_msqids(struct thread *td, struct msqid_kernel **res, 156 size_t *sz); 157 158 #else /* _KERNEL */ 159 160 __BEGIN_DECLS 161 int msgctl(int, int, struct msqid_ds *); 162 int msgget(key_t, int); 163 ssize_t msgrcv(int, void *, size_t, long, int); 164 int msgsnd(int, const void *, size_t, int); 165 __END_DECLS 166 #endif /* !_KERNEL */ 167 168 #endif /* !_SYS_MSG_H_ */ 169